1 #ifndef __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__
2 #define __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
21 #include <dali/integration-api/resource-declarations.h> // For resource id
22 #include <dali/internal/render/data-providers/material-data-provider.h>
23 #include <dali/internal/render/data-providers/uniform-map-data-provider.h>
24 #include <dali/internal/render/gl-resources/texture-units.h>
25 #include <dali/internal/render/renderers/scene-graph-renderer.h>
26 #include <dali/internal/render/renderers/render-geometry.h>
32 class PropertyInputImpl;
36 class GeometryDataProvider;
37 class MaterialDataProvider;
38 class NodeDataProvider;
40 class SamplerDataProvider;
41 class ShaderDataProvider;
42 class UniformMapDataProvider;
45 * The new geometry renderer.
47 * @todo MESH_REWORK It will be merged into the base class eventually
49 class NewRenderer : public Renderer
52 struct UniformIndexMap;
55 typedef Integration::ResourceId ResourceId;
58 * Create a new renderer instance
59 * @param[in] nodeDataProvider The node data provider
60 * @param[in] uniformMapDataProvider The uniform map data provider
61 * @param[in] geometryDataProvider The geometry data provider
62 * @param[in] materialDataProvider The material data provider
64 static NewRenderer* New( NodeDataProvider& nodeDataProvider,
65 const UniformMapDataProvider& uniformMapDataProvider,
66 const GeometryDataProvider* geometryDataProvider,
67 const MaterialDataProvider* materialDataProvider );
70 * @param[in] nodeDataProvider The node data provider
71 * @param[in] uniformMapDataProvider The uniform map data provider
72 * @param[in] geometryDataProvider The geometry data provider
73 * @param[in] materialDataProvider The material data provider
75 NewRenderer( NodeDataProvider& nodeDataProvider,
76 const UniformMapDataProvider& uniformMapDataProvider,
77 const GeometryDataProvider* geometryDataProvider,
78 const MaterialDataProvider* materialDataProvider );
80 virtual ~NewRenderer();
83 * Change the geometry data provider of the renderer
84 * @param[in] geoemtryDataProvider The geometry data provider
86 void SetGeometryDataProvider( const GeometryDataProvider* geometryDataProvider );
89 * Change the material data provider of the renderer
90 * @param[in] materialDataProvider The material data provider
92 void SetMaterialDataProvider( const MaterialDataProvider* materialDataProvider );
94 public: // Implementation of Renderer
96 * @copydoc SceneGraph::Renderer::RequiresDepthTest()
98 virtual bool RequiresDepthTest() const;
101 * @copydoc SceneGraph::Renderer::CheckResources()
103 virtual bool CheckResources();
106 * @copydoc SceneGraph::Renderer::ResolveGeometryTypes()
108 virtual void ResolveGeometryTypes( BufferIndex bufferIndex,
109 GeometryType& outType,
110 ShaderSubTypes& outSubType );
113 * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
115 virtual bool IsOutsideClipSpace( Context& context,
116 const Matrix& modelMatrix,
117 const Matrix& modelViewProjectionMatrix );
120 * @copydoc SceneGraph::Renderer::DoSetUniforms()
122 virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType );
125 * @copydoc SceneGraph::Renderer::DoRender()
127 virtual void DoRender( Context& context,
128 TextureCache& textureCache,
129 BufferIndex bufferIndex,
131 const Matrix& modelViewMatrix,
132 const Matrix& viewMatrix );
134 public: // Implementation of GlResourceOwner
137 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
139 virtual void GlContextDestroyed();
142 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
144 virtual void GlCleanup();
148 * Set the uniforms from properties according to the uniform map
149 * @param[in] program The shader program on which to set the uniforms.
151 void SetUniforms( BufferIndex bufferIndex, Program& program );
154 * Set the program uniform in the map from the mapped property
156 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
159 * Bind the material textures in the samplers and setup the samplers
160 * @param[in] textureCache The texture cache
161 * @param[in] bufferIndex The buffer index
162 * @param[in] program The shader program
163 * @param[in] samplers The samplers to bind
165 void BindTextures( TextureCache& textureCache,
166 BufferIndex bufferIndex,
168 const MaterialDataProvider::Samplers& samplers );
171 * Bind a material texture to a texture unit, and set the sampler's texture uniform
172 * to that texture unit.
173 * @param[in] textureCache The texture cache
174 * @param[in] program The shader program
175 * @param[in] id The resource id of the texture to bind
176 * @param[in] texture The texture to bind
177 * @param[in] textureUnit The texture unit index to use
178 * @param[in] nameIndex The index of the texture uniform in the program
180 void BindTexture( TextureCache& textureCache,
184 TextureUnit textureUnit,
185 unsigned int nameIndex );
188 * Apply the sampler modes to the texture.
189 * @param[in] bufferIndex The current buffer index
190 * @param[in] texture The texture to which to apply the sampler modes
191 * @param[in] textureUnit The texture unit of the texture
192 * @param[in] sampler The sampler from which to get the modes.
194 void ApplySampler( BufferIndex bufferIndex,
196 TextureUnit textureUnit,
197 const SamplerDataProvider& sampler );
200 * Get the texture uniform index of the name sampler in the program.
201 * If not already registered in the program, then this performs the registration
202 * @param[in] program The shader program
203 * @param[in] sampler The sampler holding a texture unit uniform name to search for
204 * @return The texture uniform index in the program
206 unsigned int GetTextureUnitUniformIndex( Program& program,
207 const SamplerDataProvider& sampler );
211 // @todo MESH_REWORK Make private - add getters
212 //const NodeDataProvider& mNodeDataProvider;
213 //const ShaderDataProvider& mShaderDataProvider;
214 const UniformMapDataProvider& mUniformMapDataProvider;
215 const MaterialDataProvider* mMaterialDataProvider;
216 const GeometryDataProvider* mGeometryDataProvider;
220 RenderGeometry mRenderGeometry;
222 struct TextureUnitUniformIndex
224 const SamplerDataProvider* sampler;
228 typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
229 TextureUnitUniforms mTextureUnitUniforms;
231 struct UniformIndexMap
233 unsigned int uniformIndex; // The index of the cached location in the Program
234 const PropertyInputImpl* propertyValue;
237 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
238 UniformIndexMappings mUniformIndexMap;
246 #endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__