Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

Diff Revisions 167 vs 168 for /trunk/Source Code/Geometry/Material/Headers/Material.h

Diff revisions: vs.
  @@ -47,15 +47,15 @@
47 47 I32 _textureCount;
48 48
49 49 ShaderData() : _textureCount(0),
50 - _ambient(vec4<F32>(vec3<F32>(1.0f,1.0f,1.0f)/5.0f,1)),
51 - _diffuse(vec4<F32>(vec3<F32>(1.0f,1.0f,1.0f)/1.5f,1)),
50 + _ambient(vec4<F32>(vec3<F32>(1.0f)/5.0f,1)),
51 + _diffuse(vec4<F32>(vec3<F32>(1.0f)/1.5f,1)),
52 52 _specular(0.8f,0.8f,0.8f,1.0f),
53 53 _emissive(0.6f,0.6f,0.6f,1.0f),
54 54 _shininess(5),
55 55 _opacity(1.0f) {}
56 56 };
57 57
58 - enum BumpMethod{
58 + enum BumpMethod {
59 59 BUMP_NONE = 0, //<Use phong
60 60 BUMP_NORMAL = 1, //<Normal mapping
61 61 BUMP_PARALLAX = 2,
  @@ -63,20 +63,13 @@
63 63 BUMP_PLACEHOLDER = 4
64 64 };
65 65
66 - enum TextureUsage{
67 - TEXTURE_BASE = 0,
68 - TEXTURE_BUMP = 1,
69 - TEXTURE_NORMALMAP = 2,
70 - TEXTURE_SECOND = 3,
71 - TEXTURE_OPACITY = 4,
72 - TEXTURE_SPECULAR = 5,
73 - TEXTURE_DISPLACEMENT = 6,
74 - TEXTURE_EMISSIVE = 7,
75 - TEXTURE_AMBIENT = 8,
76 - TEXTURE_SHININESS = 9,
77 - TEXTURE_MIRROR = 10,
78 - TEXTURE_LIGHTMAP = 11
66 + enum TextureUsage {
67 + TEXTURE_NORMALMAP = 0,
68 + TEXTURE_OPACITY = 1,
69 + TEXTURE_SPECULAR = 2,
70 + TEXTURE_UNIT0 = 3
79 71 };
72 +
80 73 /// How should each texture be added
81 74 enum TextureOperation {
82 75 TextureOperation_Multiply = 0x0,
  @@ -107,24 +100,12 @@
107 100 SHADING_FRESNEL = 0xa
108 101 };
109 102
110 - enum TextureUnit{
111 - FIRST_TEXTURE_UNIT = 0,
112 - SECOND_TEXTURE_UNIT = 1,
113 - BUMP_TEXTURE_UNIT = 2,
114 - OPACITY_TEXTURE_UNIT = 3,
115 - SPECULAR_TEXTURE_UNIT = 4,
116 - PLACEHOLDER_TEXTURE_UNIT = 5
117 - };
118 -
119 - typedef Unordered_map<TextureUsage, Texture2D*> textureMap;
120 - typedef Unordered_map<TextureUsage, TextureOperation> textureOperation;
121 -
122 103 public:
123 104 Material();
124 105 ~Material();
125 106
126 107 bool unload();
127 -
108 + inline void setTriangleStripInput(const bool state) {_dirty = true; _useStripInput = state;}
128 109 inline void setHardwareSkinning(const bool state) {_dirty = true; _hardwareSkinning = state;}
129 110 inline void setAmbient(const vec4<F32>& value) {_dirty = true; _shaderData._ambient = value; _materialMatrix.setCol(0,value);}
130 111 inline void setDiffuse(const vec4<F32>& value) {_dirty = true; _shaderData._diffuse = value; _materialMatrix.setCol(1,value);}
  @@ -140,31 +121,36 @@
140 121 _shaderData._emissive.z));
141 122 }
142 123
143 - inline void setShadingMode(const ShadingMode& mode) {_shadingMode = mode;}
144 - void setCastsShadows(const bool state);
145 - void setReceivesShadows(const bool state);
146 - void setDoubleSided(const bool state);
147 - void setTexture(const TextureUsage& textureUsage,
148 - Texture2D* const texture,
149 - const TextureOperation& op = TextureOperation_Replace);
150 - ///Set the desired bump mapping method. If force == true, the shader is updated immediately
151 - void setBumpMethod(const BumpMethod& newBumpMethod,const bool force = false);
152 - void setBumpMethod(U32 newBumpMethod,const bool force = false);
153 - ///Shader modifiers add tokens to the end of the shader name.
154 - ///Add as many tokens as needed but separate them with a ".". i.e: "Tree.NoWind.Glow"
155 - void addShaderModifier(const std::string& shaderModifier,const bool force = false);
156 - ///Shader defines, separated by commas, are added to the generated shader
157 - ///The shader generator appends "#define " to the start of each define
158 - ///For example, to define max light count and max shadow casters add this string:
159 - ///"MAX_LIGHT_COUNT 4, MAX_SHADOW_CASTERS 2"
160 - ///The above strings becomes, in the shader:
161 - ///#define MAX_LIGHT COUNT 4
162 - ///#define MAX_SHADOW_CASTERS 2
163 - void addShaderDefines(const std::string& shaderDefines,const bool force = false);
164 - ///toggle multi-threaded shader loading on or off for this material
165 - inline void setShaderLoadThreaded(const bool state) {_shaderThreadedLoad = state;}
166 - ShaderProgram* setShaderProgram(const std::string& shader, const RenderStage& renderStage = FINAL_STAGE);
167 - RenderStateBlock* setRenderStateBlock(const RenderStateBlockDescriptor& descriptor,const RenderStage& renderStage);
124 + inline void setShadingMode(const ShadingMode& mode) {_shadingMode = mode;}
125 + void setCastsShadows(const bool state);
126 + void setReceivesShadows(const bool state);
127 + void setDoubleSided(const bool state);
128 + void setTexture(U32 textureUsageSlot,
129 + Texture2D* const texture,
130 + const TextureOperation& op = TextureOperation_Replace);
131 + ///Set the desired bump mapping method. If force == true, the shader is updated immediately
132 + void setBumpMethod(const BumpMethod& newBumpMethod,const bool force = false);
133 + void setBumpMethod(U32 newBumpMethod,const bool force = false);
134 + ///Shader modifiers add tokens to the end of the shader name.
135 + ///Add as many tokens as needed but separate them with a ".". i.e: "Tree.NoWind.Glow"
136 + void addShaderModifier(const std::string& shaderModifier,const bool force = false);
137 + ///Shader defines, separated by commas, are added to the generated shader
138 + ///The shader generator appends "#define " to the start of each define
139 + ///For example, to define max light count and max shadow casters add this string:
140 + ///"MAX_LIGHT_COUNT 4, MAX_SHADOW_CASTERS 2"
141 + ///The above strings becomes, in the shader:
142 + ///#define MAX_LIGHT COUNT 4
143 + ///#define MAX_SHADOW_CASTERS 2
144 + void addShaderDefines(U8 shaderId, const std::string& shaderDefines,const bool force = false);
145 + inline void addShaderDefines(const std::string& shaderDefines,const bool force = false) {
146 + addShaderDefines(0, shaderDefines,force);
147 + addShaderDefines(1, shaderDefines,force);
148 + }
149 +
150 + ///toggle multi-threaded shader loading on or off for this material
151 + inline void setShaderLoadThreaded(const bool state) {_shaderThreadedLoad = state;}
152 + ShaderProgram* setShaderProgram(const std::string& shader, const RenderStage& renderStage = FINAL_STAGE);
153 + RenderStateBlock* setRenderStateBlock(const RenderStateBlockDescriptor& descriptor,const RenderStage& renderStage);
168 154
169 155 inline const mat4<F32>& getMaterialMatrix() const {return _materialMatrix;}
170 156
  @@ -173,36 +159,40 @@
173 159 inline bool getReceivesShadows() const {return _receiveShadows;}
174 160 inline F32 getOpacityValue() const {return _shaderData._opacity;}
175 161 inline U8 getTextureCount() const {return _shaderData._textureCount;}
176 - inline U32 getBumpMethod() const {return _bumpMethodTable[_bumpMethod];}
177 - inline ShadingMode getShadingMode() const {return _shadingMode;}
178 - inline RenderStateBlock* getRenderState(RenderStage currentStage) {return _defaultRenderStates[currentStage];}
179 - inline U32 getTextureOperation(TextureUsage textureUsage) {return _textureOperationTable[_operations[textureUsage]];}
180 - inline Texture2D* const getTexture(TextureUsage textureUsage) {return _textures[textureUsage];}
181 162
182 - ShaderProgram* const getShaderProgram(RenderStage renderStage = FINAL_STAGE);
183 - inline const ShaderData& getShaderData() const {return _shaderData;}
163 +
164 + inline RenderStateBlock* getRenderState(RenderStage currentStage) {return _defaultRenderStates[currentStage];}
165 + inline Texture2D* const getTexture(U32 textureUsage) {return _textures[textureUsage];}
166 + ShaderProgram* const getShaderProgram(RenderStage renderStage = FINAL_STAGE);
167 +
168 + inline const TextureOperation& getTextureOperation(U32 textureUsage) const {
169 + return _operations[textureUsage >= TEXTURE_UNIT0 ? textureUsage - TEXTURE_UNIT0 : 0];
170 + }
171 +
172 + inline const ShaderData& getShaderData() const {return _shaderData;}
173 + inline const ShadingMode& getShadingMode() const {return _shadingMode;}
174 + inline const BumpMethod& getBumpMethod() const {return _bumpMethod;}
184 175
185 176 void clean();
186 177 inline bool isDirty() const {return _dirty;}
187 178 inline bool isDoubleSided() const {return _doubleSided;}
188 179 bool isTranslucent();
189 180
190 - TextureOperation getTextureOperation(U32 op);
191 -
192 181 void computeShader(bool force = false,const RenderStage& renderStage = FINAL_STAGE); //Set shaders;
193 - inline void dumpToXML() {XML::dumpMaterial(this);}
182 + inline void dumpToXML() {XML::dumpMaterial(*this);}
194 183
195 184 private:
196 185
197 186 mat4<F32> _materialMatrix; /* all properties bundled togheter */
198 187 ShadingMode _shadingMode;
199 188 std::string _shaderModifier; //<use for special shader tokens, such as "Tree"
200 - vectorImpl<std::string > _shaderDefines; //<Add shader preprocessor defines;
189 + vectorImpl<std::string > _shaderDefines[2]; //<Add shader preprocessor defines;
201 190 bool _dirty;
202 191 bool _doubleSided;
203 192 bool _castsShadows;
204 193 bool _receiveShadows;
205 194 bool _hardwareSkinning; ///< Use shaders that have bone transforms implemented
195 + bool _useStripInput; ///< Use triangle strip as geometry shader input
206 196 Unordered_map<RenderStage, ShaderProgram* > _shaderRef;
207 197 ///Used to render geometry without materials.
208 198 ///Should emmulate the basic fixed pipeline functions (no lights, just color and texture)
  @@ -217,12 +207,9 @@
217 207 /// 3 render state's: Normal, reflection and shadow
218 208 Unordered_map<RenderStage, RenderStateBlock* > _defaultRenderStates;
219 209 /// use this map to add textures to the material
220 - textureMap _textures;
210 + Texture2D* _textures[Config::MAX_TEXTURE_STORAGE];
221 211 /// use the bellow map to define texture operation
222 - textureOperation _operations;
223 - /// Map texture operation to values the shader understands
224 - U32 _textureOperationTable[TextureOperation_PLACEHOLDER];
225 - U32 _bumpMethodTable[BUMP_PLACEHOLDER];
212 + TextureOperation _operations[Config::MAX_TEXTURE_STORAGE - TEXTURE_UNIT0];
226 213
227 214 BumpMethod _bumpMethod;
228 215