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( const Matrix& modelMatrix,
116 const Matrix& modelViewProjectionMatrix );
119 * @copydoc SceneGraph::Renderer::DoSetUniforms()
121 virtual void DoSetUniforms(Shader* shader, Context* context, Program* program, BufferIndex bufferIndex, unsigned int programIndex, ShaderSubTypes subType );
124 * @copydoc SceneGraph::Renderer::DoRender()
126 virtual void DoRender( BufferIndex bufferIndex,
128 const Matrix& modelViewMatrix,
129 const Matrix& viewMatrix );
131 public: // Implementation of GlResourceOwner
134 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
136 virtual void GlContextDestroyed();
139 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
141 virtual void GlCleanup();
145 * Set the uniforms from properties according to the uniform map
146 * @param[in] program The shader program on which to set the uniforms.
148 void SetUniforms( BufferIndex bufferIndex, Program& program );
151 * Set the program uniform in the map from the mapped property
153 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
156 * Bind the material textures in the samplers and setup the samplers
157 * @param[in] bufferIndex The buffer index
158 * @param[in] program The shader program
159 * @param[in] samplers The samplers to bind
161 void BindTextures( BufferIndex bufferIndex,
163 const MaterialDataProvider::Samplers& samplers );
166 * Bind a material texture to a texture unit, and set the sampler's texture uniform
167 * to that texture unit.
168 * @param[in] program The shader program
169 * @param[in] id The resource id of the texture to bind
170 * @param[in] texture The texture to bind
171 * @param[in] textureUnit The texture unit index to use
172 * @param[in] nameIndex The index of the texture uniform in the program
174 void BindTexture( Program& program,
177 TextureUnit textureUnit,
178 unsigned int nameIndex );
181 * Apply the sampler modes to the texture.
182 * @param[in] bufferIndex The current buffer index
183 * @param[in] texture The texture to which to apply the sampler modes
184 * @param[in] textureUnit The texture unit of the texture
185 * @param[in] sampler The sampler from which to get the modes.
187 void ApplySampler( BufferIndex bufferIndex,
189 TextureUnit textureUnit,
190 const SamplerDataProvider& sampler );
193 * Get the texture uniform index of the name sampler in the program.
194 * If not already registered in the program, then this performs the registration
195 * @param[in] program The shader program
196 * @param[in] sampler The sampler holding a texture unit uniform name to search for
197 * @return The texture uniform index in the program
199 unsigned int GetTextureUnitUniformIndex( Program& program,
200 const SamplerDataProvider& sampler );
204 // @todo MESH_REWORK Make private - add getters
205 //const NodeDataProvider& mNodeDataProvider;
206 //const ShaderDataProvider& mShaderDataProvider;
207 const UniformMapDataProvider& mUniformMapDataProvider;
208 const MaterialDataProvider* mMaterialDataProvider;
209 const GeometryDataProvider* mGeometryDataProvider;
213 RenderGeometry mRenderGeometry;
215 struct TextureUnitUniformIndex
217 const SamplerDataProvider* sampler;
221 typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
222 TextureUnitUniforms mTextureUnitUniforms;
224 struct UniformIndexMap
226 unsigned int uniformIndex; // The index of the cached location in the Program
227 const PropertyInputImpl* propertyValue;
230 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
231 UniformIndexMappings mUniformIndexMap;
239 #endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__