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 struct UniformIndexMap;
48 typedef Integration::ResourceId ResourceId;
51 * Create a new renderer instance
52 * @param[in] nodeDataProvider The node data provider
53 * @param[in] dataProviders The data providers for the renderer
55 static NewRenderer* New( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders );
58 * @param[in] nodeDataProvider The node data provider
59 * @param[in] dataProviders The data providers for the renderer
61 NewRenderer( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders );
63 virtual ~NewRenderer();
66 * Change the data providers of the renderer
67 * @param[in] dataProviders The data providers
69 void SetRenderDataProvider( RenderDataProvider* dataProviders );
71 public: // Implementation of Renderer
73 * @copydoc SceneGraph::Renderer::RequiresDepthTest()
75 virtual bool RequiresDepthTest() const;
78 * @copydoc SceneGraph::Renderer::CheckResources()
80 virtual bool CheckResources();
83 * @copydoc SceneGraph::Renderer::ResolveGeometryTypes()
85 virtual void ResolveGeometryTypes( BufferIndex bufferIndex,
86 GeometryType& outType,
87 ShaderSubTypes& outSubType );
90 * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
92 virtual bool IsOutsideClipSpace( Context& context,
93 const Matrix& modelMatrix,
94 const Matrix& modelViewProjectionMatrix );
97 * @copydoc SceneGraph::Renderer::DoSetUniforms()
99 virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex, ShaderSubTypes subType );
102 * @copydoc SceneGraph::Renderer::DoRender()
104 virtual void DoRender( Context& context,
105 TextureCache& textureCache,
106 BufferIndex bufferIndex,
108 const Matrix& modelViewMatrix,
109 const Matrix& viewMatrix );
111 public: // Implementation of GlResourceOwner
114 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
116 virtual void GlContextDestroyed();
119 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
121 virtual void GlCleanup();
125 * Set the uniforms from properties according to the uniform map
126 * @param[in] program The shader program on which to set the uniforms.
128 void SetUniforms( BufferIndex bufferIndex, Program& program );
131 * Set the program uniform in the map from the mapped property
133 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
136 * Bind the material textures in the samplers and setup the samplers
137 * @param[in] textureCache The texture cache
138 * @param[in] bufferIndex The buffer index
139 * @param[in] program The shader program
140 * @param[in] samplers The samplers to bind
142 void BindTextures( TextureCache& textureCache,
143 BufferIndex bufferIndex,
145 const RenderDataProvider::Samplers& samplers );
148 * Bind a material texture to a texture unit, and set the sampler's texture uniform
149 * to that texture unit.
150 * @param[in] textureCache The texture cache
151 * @param[in] program The shader program
152 * @param[in] id The resource id of the texture to bind
153 * @param[in] texture The texture to bind
154 * @param[in] textureUnit The texture unit index to use
155 * @param[in] nameIndex The index of the texture uniform in the program
157 void BindTexture( TextureCache& textureCache,
161 TextureUnit textureUnit,
162 unsigned int nameIndex );
165 * Apply the sampler modes to the texture.
166 * @param[in] bufferIndex The current buffer index
167 * @param[in] texture The texture to which to apply the sampler modes
168 * @param[in] textureUnit The texture unit of the texture
169 * @param[in] sampler The sampler from which to get the modes.
171 void ApplySampler( BufferIndex bufferIndex,
173 TextureUnit textureUnit,
174 const SamplerDataProvider& sampler );
177 * Get the texture uniform index of the name sampler in the program.
178 * If not already registered in the program, then this performs the registration
179 * @param[in] program The shader program
180 * @param[in] sampler The sampler holding a texture unit uniform name to search for
181 * @return The texture uniform index in the program
183 unsigned int GetTextureUnitUniformIndex( Program& program,
184 const SamplerDataProvider& sampler );
186 public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer
187 OwnerPointer< RenderDataProvider > mRenderDataProvider;
190 RenderGeometry mRenderGeometry;
192 struct TextureUnitUniformIndex
194 const SamplerDataProvider* sampler;
198 typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
199 TextureUnitUniforms mTextureUnitUniforms;
201 struct UniformIndexMap
203 unsigned int uniformIndex; // The index of the cached location in the Program
204 const PropertyInputImpl* propertyValue;
207 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
208 UniformIndexMappings mUniformIndexMap;
216 #endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__