1 #ifndef __DALI_INTERNAL_RENDER_NEW_RENDERER_H__
2 #define __DALI_INTERNAL_RENDER_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/render-renderer.h>
26 #include <dali/internal/render/renderers/render-geometry.h>
27 #include <dali/internal/update/manager/prepare-render-instructions.h>
33 class PropertyInputImpl;
39 * The new geometry renderer.
41 * @todo MESH_REWORK It will be merged into the base class eventually
43 class NewRenderer : public Renderer
46 typedef Integration::ResourceId ResourceId;
50 * Create a new renderer instance
51 * @param[in] dataProviders The data providers for the renderer
52 * @param[in] renderGeometry The geometry for the renderer
54 static NewRenderer* New( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
58 * @param[in] dataProviders The data providers for the renderer
59 * @param[in] renderGeometry The geometry for the renderer
61 NewRenderer( SceneGraph::RenderDataProvider* dataProviders, SceneGraph::RenderGeometry* renderGeometry );
63 virtual ~NewRenderer();
66 * Change the data providers of the renderer
67 * @param[in] dataProviders The data providers
69 void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
72 * Change the geometry used by the renderer
73 * @param[in] renderGeometry The new geometry
75 void SetGeometry( SceneGraph::RenderGeometry* renderGeometry );
78 * Write the renderer's sort attributes to the passed in reference.
79 * @param[in] bufferIndex The buffer index
80 * @param[out] sortAttributes
82 void SetSortAttributes( SceneGraph::RendererWithSortAttributes& sortAttributes ) const
84 sortAttributes.shader = &(mRenderDataProvider->GetShader());
85 sortAttributes.material = &(mRenderDataProvider->GetMaterial());
86 sortAttributes.geometry = mRenderGeometry;
89 public: // Implementation of Renderer
91 * @copydoc SceneGraph::Renderer::RequiresDepthTest()
93 virtual bool RequiresDepthTest() const;
96 * @copydoc SceneGraph::Renderer::CheckResources()
98 virtual bool CheckResources();
101 * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
103 virtual bool IsOutsideClipSpace( Context& context,
104 const Matrix& modelViewProjectionMatrix );
107 * @copydoc SceneGraph::Renderer::DoSetUniforms()
109 virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program, unsigned int programIndex );
112 * @copydoc SceneGraph::Renderer::DoSetCullFaceMode
114 virtual void DoSetCullFaceMode(Context& context, BufferIndex bufferIndex );
117 * @copydoc SceneGraph::Renderer::DoSetBlending
119 virtual void DoSetBlending(Context& context, BufferIndex bufferIndex, bool blend );
122 * @copydoc SceneGraph::Renderer::DoRender()
124 virtual void DoRender( Context& context,
125 SceneGraph::TextureCache& textureCache,
126 const SceneGraph::NodeDataProvider& node,
127 BufferIndex bufferIndex,
129 const Matrix& modelViewMatrix,
130 const Matrix& viewMatrix );
132 public: // Implementation of GlResourceOwner
135 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
137 virtual void GlContextDestroyed();
140 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
142 virtual void GlCleanup();
145 struct UniformIndexMap;
148 * Set the uniforms from properties according to the uniform map
149 * @param[in] node The node using the renderer
150 * @param[in] program The shader program on which to set the uniforms.
152 void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program );
155 * Set the program uniform in the map from the mapped property
157 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
160 * Bind the material textures in the samplers and setup the samplers
161 * @param[in] textureCache The texture cache
162 * @param[in] bufferIndex The buffer index
163 * @param[in] program The shader program
164 * @param[in] samplers The samplers to bind
166 void BindTextures( SceneGraph::TextureCache& textureCache,
167 BufferIndex bufferIndex,
169 const SceneGraph::RenderDataProvider::Samplers& samplers );
172 * Bind a material texture to a texture unit, and set the sampler's texture uniform
173 * to that texture unit.
174 * @param[in] textureCache The texture cache
175 * @param[in] program The shader program
176 * @param[in] id The resource id of the texture to bind
177 * @param[in] texture The texture to bind
178 * @param[in] textureUnit The texture unit index to use
179 * @param[in] nameIndex The index of the texture uniform in the program
181 void BindTexture( SceneGraph::TextureCache& textureCache,
185 TextureUnit textureUnit,
186 unsigned int nameIndex );
189 * Apply the sampler modes to the texture.
190 * @param[in] bufferIndex The current buffer index
191 * @param[in] texture The texture to which to apply the sampler modes
192 * @param[in] textureUnit The texture unit of the texture
193 * @param[in] sampler The sampler from which to get the modes.
195 void ApplySampler( BufferIndex bufferIndex,
197 TextureUnit textureUnit,
198 const SceneGraph::SamplerDataProvider& sampler );
201 * Get the texture uniform index of the name sampler in the program.
202 * If not already registered in the program, then this performs the registration
203 * @param[in] program The shader program
204 * @param[in] sampler The sampler holding a texture unit uniform name to search for
205 * @return The texture uniform index in the program
207 unsigned int GetTextureUnitUniformIndex( Program& program,
208 const SceneGraph::SamplerDataProvider& sampler );
212 public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer
213 OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
216 SceneGraph::RenderGeometry* mRenderGeometry;
218 struct TextureUnitUniformIndex
220 const SceneGraph::SamplerDataProvider* sampler;
224 typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
225 TextureUnitUniforms mTextureUnitUniforms;
227 struct UniformIndexMap
229 unsigned int uniformIndex; // The index of the cached location in the Program
230 const PropertyInputImpl* propertyValue;
233 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
234 UniformIndexMappings mUniformIndexMap;
236 Vector<GLint> mAttributesLocation;
237 bool mUpdateAttributesLocation;
246 #endif // __DALI_INTERNAL_RENDER_NEW_RENDERER_H__