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
53 static NewRenderer* New( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders );
56 * @param[in] nodeDataProvider The node data provider
57 * @param[in] dataProviders The data providers for the renderer
59 NewRenderer( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders );
61 virtual ~NewRenderer();
64 * Change the data providers of the renderer
65 * @param[in] dataProviders The data providers
67 void SetRenderDataProvider( RenderDataProvider* dataProviders );
69 public: // Implementation of Renderer
71 * @copydoc SceneGraph::Renderer::RequiresDepthTest()
73 virtual bool RequiresDepthTest() const;
76 * @copydoc SceneGraph::Renderer::CheckResources()
78 virtual bool CheckResources();
81 * @copydoc SceneGraph::Renderer::ResolveGeometryTypes()
83 virtual void ResolveGeometryTypes( BufferIndex bufferIndex,
84 GeometryType& outType,
85 ShaderSubTypes& outSubType );
88 * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
90 virtual bool IsOutsideClipSpace( Context& context,
91 const Matrix& modelMatrix,
92 const Matrix& modelViewProjectionMatrix );
95 * @copydoc SceneGraph::Renderer::DoSetUniforms()
97 virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType );
100 * @copydoc SceneGraph::Renderer::DoSetCullFaceMode
102 virtual void DoSetCullFaceMode(Context& context, BufferIndex bufferIndex );
105 * @copydoc SceneGraph::Renderer::DoSetBlending
107 virtual void DoSetBlending(Context& context, BufferIndex bufferIndex );
110 * @copydoc SceneGraph::Renderer::DoRender()
112 virtual void DoRender( Context& context,
113 TextureCache& textureCache,
114 BufferIndex bufferIndex,
116 const Matrix& modelViewMatrix,
117 const Matrix& viewMatrix );
119 public: // Implementation of GlResourceOwner
122 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
124 virtual void GlContextDestroyed();
127 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
129 virtual void GlCleanup();
132 struct UniformIndexMap;
135 * Set the uniforms from properties according to the uniform map
136 * @param[in] program The shader program on which to set the uniforms.
138 void SetUniforms( BufferIndex bufferIndex, Program& program );
141 * Set the program uniform in the map from the mapped property
143 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
146 * Bind the material textures in the samplers and setup the samplers
147 * @param[in] textureCache The texture cache
148 * @param[in] bufferIndex The buffer index
149 * @param[in] program The shader program
150 * @param[in] samplers The samplers to bind
152 void BindTextures( TextureCache& textureCache,
153 BufferIndex bufferIndex,
155 const RenderDataProvider::Samplers& samplers );
158 * Bind a material texture to a texture unit, and set the sampler's texture uniform
159 * to that texture unit.
160 * @param[in] textureCache The texture cache
161 * @param[in] program The shader program
162 * @param[in] id The resource id of the texture to bind
163 * @param[in] texture The texture to bind
164 * @param[in] textureUnit The texture unit index to use
165 * @param[in] nameIndex The index of the texture uniform in the program
167 void BindTexture( TextureCache& textureCache,
171 TextureUnit textureUnit,
172 unsigned int nameIndex );
175 * Apply the sampler modes to the texture.
176 * @param[in] bufferIndex The current buffer index
177 * @param[in] texture The texture to which to apply the sampler modes
178 * @param[in] textureUnit The texture unit of the texture
179 * @param[in] sampler The sampler from which to get the modes.
181 void ApplySampler( BufferIndex bufferIndex,
183 TextureUnit textureUnit,
184 const SamplerDataProvider& sampler );
187 * Get the texture uniform index of the name sampler in the program.
188 * If not already registered in the program, then this performs the registration
189 * @param[in] program The shader program
190 * @param[in] sampler The sampler holding a texture unit uniform name to search for
191 * @return The texture uniform index in the program
193 unsigned int GetTextureUnitUniformIndex( Program& program,
194 const SamplerDataProvider& sampler );
196 public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer
197 OwnerPointer< RenderDataProvider > mRenderDataProvider;
200 RenderGeometry mRenderGeometry;
202 struct TextureUnitUniformIndex
204 const SamplerDataProvider* sampler;
208 typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
209 TextureUnitUniforms mTextureUnitUniforms;
211 struct UniformIndexMap
213 unsigned int uniformIndex; // The index of the cached location in the Program
214 const PropertyInputImpl* propertyValue;
217 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
218 UniformIndexMappings mUniformIndexMap;
226 #endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__