1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_RENDER_MATERIAL_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_RENDER_MATERIAL_H__
4 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
21 #include <dali/public-api/math/vector4.h>
22 #include <dali/internal/common/message.h>
23 #include <dali/internal/event/effects/shader-declarations.h>
24 #include <dali/internal/render/shaders/custom-uniform.h>
25 #include <dali/internal/render/gl-resources/texture-observer.h>
26 #include <dali/internal/render/shaders/program.h>
43 * Helper class to manage uniforms for RenderMaterial. There is a 1-1
44 * correspondance between a helper object and a Renderer instance,
45 * whereas there is a 1-many relationship between RenderMaterial and
48 class RenderMaterialUniforms
52 * If the owner's program changes, then this should be called to reset the uniform locations
54 void ResetCustomUniforms();
57 * Set the uniform values from the renderMaterial onto the program
58 * @param[in] renderMaterial The material from which to get the values
59 * @param[in] program The program for which to set the values
60 * @param[in] shaderType The sub type of shader program
62 void SetUniforms( const RenderMaterial& renderMaterial, Program& program, ShaderSubTypes shaderType );
65 static const unsigned int mNumberOfCustomUniforms = 6; ///< Number of material uniforms
66 mutable CustomUniform mCustomUniform[SHADER_SUBTYPE_LAST][ mNumberOfCustomUniforms ]; ///< The uniform locations
71 * Holds values to be stored into uniforms by the renderer
72 * Holds texture pointers for binding by the renderer
74 class RenderMaterial : public TextureObserver
85 virtual ~RenderMaterial();
88 * Secondary stage initialization
89 * @param[in] textureCache The GL Texture cache
91 void Initialize(TextureCache& textureCache);
96 * Set the diffuse texture resource id
97 * @param[in] textureId The resource id of the texture
99 void SetDiffuseTextureId( unsigned int textureId );
102 * Set the opacity texture id
103 * @param[in] textureId The resource id of the texture
105 void SetOpacityTextureId( unsigned int textureId );
108 * Set the normal / height map texture id
109 * @param[in] textureId The resource id of the texture
111 void SetNormalMapTextureId( unsigned int textureId );
115 * @param[in] opacity The opacity
117 void SetOpacity(float opacity);
121 * @param[in] shininess The shininess
123 void SetShininess(float shininess);
126 * Set the ambient color
127 * @param[in] color The color
129 void SetAmbientColor( const Vector4& color );
132 * Set the diffuse color
133 * @param[in] color The color
135 void SetDiffuseColor( const Vector4& color );
138 * Set the specular color
139 * @param[in] color The color
141 void SetSpecularColor( const Vector4& color );
144 * Set the emissive color
145 * @param[in] color The color
147 void SetEmissiveColor( const Vector4& color );
150 * @return true if a texture has been set on this material, false otherwise
152 bool HasTexture() const;
157 * Set the uniform values for the locations defined in the uniforms structure.
158 * @param[in] uniforms The material uniforms
159 * @param[in] program The shader program for which to set the uniform values
160 * @param[in] shaderType The shader type
162 void SetUniforms( RenderMaterialUniforms& uniforms, Program& program, ShaderSubTypes shaderType ) const;
165 * Bind all the valid textures. Will also store valid texture pointer
166 * @param[in] program The shader program with which to bind the textures
168 void BindTextures( Program& program );
170 protected: // TextureObserver implementation
172 * @copydoc Dali::Internal::TextureObserver::TextureDiscarded()
174 virtual void TextureDiscarded( unsigned int textureId );
179 * @param[in] program The shader program with which to bind the texture
180 * @param[in] textureId the texture id to bind
181 * @param[in] texture The texture to bind
182 * @param[in] textureUnit Texture unit ( should be a value between 0 and the max number of samplers - 1 )
183 * @param[in] samplerIndex The index of the uniform to bind the texture sampler
185 void BindTexture( Program& program, unsigned int textureId, Texture* texture, unsigned int textureUnit, Program::UniformType samplerIndex ) const;
188 TextureCache* mTextureCache; ///< Texture cache of GL resources
190 unsigned int mDiffuseTextureId; ///< Diffuse texture id
191 unsigned int mOpacityTextureId; ///< opacity texture id
192 unsigned int mNormalMapTextureId; ///< Normal/Height map texture id
194 Texture* mDiffuseTexture; ///< Pointer to ready texture
195 Texture* mOpacityTexture; ///< Pointer to ready texture
196 Texture* mNormalMapTexture; ///< Pointer to ready texture
198 float mOpacity; ///< opacity (0 = transparent, 1 = opaque)
199 float mShininess; ///< value between 0 and 128
201 Vector4 mAmbientColor; ///< Ambient color
202 Vector4 mDiffuseColor; ///< Diffuse color
203 Vector4 mSpecularColor; ///< Specular color
204 Vector4 mEmissiveColor; ///< Emissive color
206 friend class RenderMaterialUniforms;
215 #endif // __DALI_INTERNAL_SCENE_GRAPH_RENDER_MATERIAL_H__