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/common/owner-pointer.h>
23 #include <dali/internal/render/data-providers/render-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;
38 * The new geometry renderer.
40 * @todo MESH_REWORK It will be merged into the base class eventually
42 class NewRenderer : public Renderer
45 typedef Integration::ResourceId ResourceId;
49 * Create a new renderer instance
50 * @param[in] nodeDataProvider The node data provider
51 * @param[in] dataProviders The data providers for the renderer
52 * @param[in] renderGeometry The geometry for the renderer
54 static NewRenderer* New( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders, RenderGeometry* renderGeometry );
57 * @param[in] nodeDataProvider The node data provider
58 * @param[in] dataProviders The data providers for the renderer
59 * @param[in] renderGeometry The geometry for the renderer
61 NewRenderer( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders, RenderGeometry* renderGeometry );
63 virtual ~NewRenderer();
66 * Change the data providers of the renderer
67 * @param[in] dataProviders The data providers
69 void SetRenderDataProvider( RenderDataProvider* dataProviders );
72 * Change the geometry used by the renderer
73 * @param[in] renderGeometry The new geometry
75 void SetGeometry( RenderGeometry* renderGeometry );
77 public: // Implementation of Renderer
79 * @copydoc SceneGraph::Renderer::RequiresDepthTest()
81 virtual bool RequiresDepthTest() const;
84 * @copydoc SceneGraph::Renderer::CheckResources()
86 virtual bool CheckResources();
89 * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
91 virtual bool IsOutsideClipSpace( Context& context,
92 const Matrix& modelMatrix,
93 const Matrix& modelViewProjectionMatrix );
96 * @copydoc SceneGraph::Renderer::DoSetUniforms()
98 virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex );
101 * @copydoc SceneGraph::Renderer::DoSetCullFaceMode
103 virtual void DoSetCullFaceMode(Context& context, BufferIndex bufferIndex );
106 * @copydoc SceneGraph::Renderer::DoSetBlending
108 virtual void DoSetBlending(Context& context, BufferIndex bufferIndex );
111 * @copydoc SceneGraph::Renderer::DoRender()
113 virtual void DoRender( Context& context,
114 TextureCache& textureCache,
115 BufferIndex bufferIndex,
117 const Matrix& modelViewMatrix,
118 const Matrix& viewMatrix );
120 public: // Implementation of GlResourceOwner
123 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
125 virtual void GlContextDestroyed();
128 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
130 virtual void GlCleanup();
133 struct UniformIndexMap;
136 * Set the uniforms from properties according to the uniform map
137 * @param[in] program The shader program on which to set the uniforms.
139 void SetUniforms( BufferIndex bufferIndex, Program& program );
142 * Set the program uniform in the map from the mapped property
144 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
147 * Bind the material textures in the samplers and setup the samplers
148 * @param[in] textureCache The texture cache
149 * @param[in] bufferIndex The buffer index
150 * @param[in] program The shader program
151 * @param[in] samplers The samplers to bind
153 void BindTextures( TextureCache& textureCache,
154 BufferIndex bufferIndex,
156 const RenderDataProvider::Samplers& samplers );
159 * Bind a material texture to a texture unit, and set the sampler's texture uniform
160 * to that texture unit.
161 * @param[in] textureCache The texture cache
162 * @param[in] program The shader program
163 * @param[in] id The resource id of the texture to bind
164 * @param[in] texture The texture to bind
165 * @param[in] textureUnit The texture unit index to use
166 * @param[in] nameIndex The index of the texture uniform in the program
168 void BindTexture( TextureCache& textureCache,
172 TextureUnit textureUnit,
173 unsigned int nameIndex );
176 * Apply the sampler modes to the texture.
177 * @param[in] bufferIndex The current buffer index
178 * @param[in] texture The texture to which to apply the sampler modes
179 * @param[in] textureUnit The texture unit of the texture
180 * @param[in] sampler The sampler from which to get the modes.
182 void ApplySampler( BufferIndex bufferIndex,
184 TextureUnit textureUnit,
185 const SamplerDataProvider& sampler );
188 * Get the texture uniform index of the name sampler in the program.
189 * If not already registered in the program, then this performs the registration
190 * @param[in] program The shader program
191 * @param[in] sampler The sampler holding a texture unit uniform name to search for
192 * @return The texture uniform index in the program
194 unsigned int GetTextureUnitUniformIndex( Program& program,
195 const SamplerDataProvider& sampler );
197 public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer
198 OwnerPointer< RenderDataProvider > mRenderDataProvider;
201 RenderGeometry* mRenderGeometry;
203 struct TextureUnitUniformIndex
205 const SamplerDataProvider* sampler;
209 typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
210 TextureUnitUniforms mTextureUnitUniforms;
212 struct UniformIndexMap
214 unsigned int uniformIndex; // The index of the cached location in the Program
215 const PropertyInputImpl* propertyValue;
218 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
219 UniformIndexMappings mUniformIndexMap;
221 Vector<GLint> mAttributesLocation;
222 bool mUpdateAttributesLocation;
224 bool mUseBlend:1; ///< True if blending should be enabled, 1 bit is enough
232 #endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__