OGRE  2.0
Object-Oriented Graphics Rendering Engine
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
OgreHlms.h
Go to the documentation of this file.
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OGRE
4  (Object-oriented Graphics Rendering Engine)
5 For the latest info, see http://www.ogre3d.org/
6 
7 Copyright (c) 2000-2014 Torus Knot Software Ltd
8 
9 Permission is hereby granted, free of charge, to any person obtaining a copy
10 of this software and associated documentation files (the "Software"), to deal
11 in the Software without restriction, including without limitation the rights
12 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 copies of the Software, and to permit persons to whom the Software is
14 furnished to do so, subject to the following conditions:
15 
16 The above copyright notice and this permission notice shall be included in
17 all copies or substantial portions of the Software.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 THE SOFTWARE.
26 -----------------------------------------------------------------------------
27 */
28 #ifndef _OgreHlms_H_
29 #define _OgreHlms_H_
30 
31 #include "OgreStringVector.h"
32 #include "OgreHlmsCommon.h"
33 #include "OgreHeaderPrefix.h"
34 
35 namespace Ogre
36 {
37  class CompositorShadowNode;
38 
46  class _OgreExport Hlms : public PassAlloc
47  {
49  {
55  NumShaderTypes
56  };
57 
58  protected:
61 
62  typedef std::map<IdString, String> PiecesMap;
65 
67  StringVector mPieceFiles[5];
68  //HlmsManager *mHlmsManager;
69 
73  void setCommonProperties();
74 
83  void enumeratePieceFiles(void);
84 
85  void setProperty( IdString key, int32 value );
86  int32 getProperty( IdString key, int32 defaultVal=0 ) const;
87 
89  {
92  EXPR_OBJECT, //(...)
93  EXPR_VAR
94  };
95 
96  struct Expression
97  {
98  bool result;
99  bool negated;
101  std::vector<Expression> children;
103 
104  Expression() : result( false ), negated( false ), type( EXPR_VAR ) {}
105  };
106 
107  typedef std::vector<Expression> ExpressionVec;
108 
109  static void copy( String &outBuffer, const SubStringRef &inSubString, size_t length );
110  static void repeat( String &outBuffer, const SubStringRef &inSubString, size_t length,
111  size_t passNum, const String &counterVar );
112  bool parseForEach( const String &inBuffer, String &outBuffer ) const;
113  bool parseProperties( String &inBuffer, String &outBuffer ) const;
114  bool collectPieces( const String &inBuffer, String &outBuffer );
115  bool insertPieces( String &inBuffer, String &outBuffer ) const;
116  bool parseCounter( const String &inBuffer, String &outBuffer );
117  bool parse( const String &inBuffer, String &outBuffer ) const;
118 
126  static size_t findNextCharacter( const String &buffer, size_t startPos, char character );
127 
128  static void findBlockEnd( SubStringRef &outSubString , bool &syntaxError );
129 
130  bool evaluateExpression( SubStringRef &outSubString, bool &outSyntaxError ) const;
131  bool evaluateExpressionRecursive( ExpressionVec &expression, bool &outSyntaxError ) const;
132  static size_t evaluateExpressionEnd( const SubStringRef &outSubString );
133 
134  static void evaluateParamArgs( SubStringRef &outSubString, StringVector &outArgs,
135  bool &outSyntaxError );
136 
137  static size_t calculateLineCount(const String &buffer, size_t idx );
138  static size_t calculateLineCount( const SubStringRef &subString );
139 
140  void addRenderableCache( uint32 hash, const HlmsPropertyVec &renderableSetProperties );
141  const HlmsCache* getRenderableCache( uint32 hash ) const;
142  const HlmsCache* addShaderCache( uint32 hash, GpuProgramPtr &vertexShader,
143  GpuProgramPtr &geometryShader,
144  GpuProgramPtr &tesselationHullShader,
145  GpuProgramPtr &tesselationDomainShader,
146  GpuProgramPtr &pixelShader );
147  const HlmsCache* getShaderCache( uint32 hash ) const;
148  const HlmsCache* createShaderCacheEntry( uint32 renderableHash, const HlmsCache &passCache,
149  uint32 finalHash );
150 
158  static bool findParamInVec( const HlmsParamVec &paramVec, IdString key, String &inOut );
159 
161  virtual uint32 calculateRenderableHash(void) const;
162 
163  public:
164  Hlms( Archive *dataFolder );
165  virtual ~Hlms();
166 
176  virtual void calculateHashFor( Renderable *renderable, const HlmsParamVec &params,
177  uint32 &outHash, uint32 &outCasterHash );
178 
189  virtual HlmsCache preparePassHash( const Ogre::CompositorShadowNode *shadowNode,
190  bool casterPass, bool dualParaboloid,
191  SceneManager *sceneManager );
192 
209  const HlmsCache* getMaterial( const HlmsCache &passCache, Renderable *renderable,
210  MovableObject *movableObject, bool casterPass );
211 
213  void _setProperty( IdString key, int32 value ) { setProperty( key, value ); }
214  };
218 }
219 
220 #include "OgreHeaderSuffix.h"
221 
222 #endif
HlmsPropertyVec mSetProperties
Definition: OgreHlms.h:63
unsigned int uint32
Definition: OgrePlatform.h:420
#define _OgreExport
Definition: OgrePlatform.h:255
vector< HlmsCache >::type HlmsCacheVec
vector< std::pair< IdString, String > >::type HlmsParamVec
Manages the organisation and rendering of a 'scene' i.e.
ExpressionType
Definition: OgreHlms.h:88
HLMS stands for "High Level Material System".
Definition: OgreHlms.h:46
HlmsCacheVec mShaderCache
Definition: OgreHlms.h:60
PiecesMap mPieces
Definition: OgreHlms.h:64
Abstract class defining a movable object in a scene.
std::vector< Expression > children
Definition: OgreHlms.h:101
Abstract class defining the interface all renderable objects must implement.
HlmsCacheVec mRenderableCache
Definition: OgreHlms.h:59
Archive * mDataFolder
Definition: OgreHlms.h:66
ExpressionType type
Definition: OgreHlms.h:100
Superclass for all objects that wish to use custom memory allocators when their new / delete operator...
Hashed string.
Definition: OgreIdString.h:94
vector< String >::type StringVector
void _setProperty(IdString key, int32 value)
For debugging stuff. I.e. the Command line uses it for testing manually set properties.
Definition: OgreHlms.h:213
std::map< IdString, String > PiecesMap
Definition: OgreHlms.h:62
vector< HlmsProperty >::type HlmsPropertyVec
Archive-handling class.
Definition: OgreArchive.h:86
int int32
Definition: OgrePlatform.h:423
_StringBase String
Definition: OgreCommon.h:53
Shadow Nodes are special nodes (not to be confused with.
std::vector< Expression > ExpressionVec
Definition: OgreHlms.h:107