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( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const
84 sortAttributes.shader = &( mRenderDataProvider->GetShader() );
85 const SceneGraph::RenderDataProvider::Samplers& samplers = mRenderDataProvider->GetSamplers();
87 sortAttributes.textureResourceId = samplers.Empty() ? Integration::InvalidResourceId : samplers[ 0 ]->GetTextureId( bufferIndex );
88 sortAttributes.geometry = mRenderGeometry;
91 public: // Implementation of Renderer
93 * @copydoc SceneGraph::Renderer::RequiresDepthTest()
95 virtual bool RequiresDepthTest() const;
98 * @copydoc SceneGraph::Renderer::CheckResources()
100 virtual bool CheckResources();
103 * @copydoc SceneGraph::Renderer::IsOutsideClipSpace()
105 virtual bool IsOutsideClipSpace( Context& context,
106 const Matrix& modelViewProjectionMatrix );
109 * @copydoc SceneGraph::Renderer::DoSetUniforms()
111 virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program, unsigned int programIndex );
114 * @copydoc SceneGraph::Renderer::DoSetCullFaceMode
116 virtual void DoSetCullFaceMode(Context& context, BufferIndex bufferIndex );
119 * @copydoc SceneGraph::Renderer::DoSetBlending
121 virtual void DoSetBlending(Context& context, BufferIndex bufferIndex, bool blend );
124 * @copydoc SceneGraph::Renderer::DoRender()
126 virtual void DoRender( Context& context,
127 SceneGraph::TextureCache& textureCache,
128 const SceneGraph::NodeDataProvider& node,
129 BufferIndex bufferIndex,
131 const Matrix& modelViewMatrix,
132 const Matrix& viewMatrix );
134 public: // Implementation of GlResourceOwner
137 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
139 virtual void GlContextDestroyed();
142 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
144 virtual void GlCleanup();
147 struct UniformIndexMap;
150 * Set the uniforms from properties according to the uniform map
151 * @param[in] node The node using the renderer
152 * @param[in] program The shader program on which to set the uniforms.
154 void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program );
157 * Set the program uniform in the map from the mapped property
159 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
162 * Bind the material textures in the samplers and setup the samplers
163 * @param[in] textureCache The texture cache
164 * @param[in] bufferIndex The buffer index
165 * @param[in] program The shader program
166 * @param[in] samplers The samplers to bind
168 void BindTextures( SceneGraph::TextureCache& textureCache,
169 BufferIndex bufferIndex,
171 const SceneGraph::RenderDataProvider::Samplers& samplers );
174 * Bind a material texture to a texture unit, and set the sampler's texture uniform
175 * to that texture unit.
176 * @param[in] textureCache The texture cache
177 * @param[in] program The shader program
178 * @param[in] id The resource id of the texture to bind
179 * @param[in] texture The texture to bind
180 * @param[in] textureUnit The texture unit index to use
181 * @param[in] nameIndex The index of the texture uniform in the program
183 void BindTexture( SceneGraph::TextureCache& textureCache,
187 TextureUnit textureUnit,
188 unsigned int nameIndex );
191 * Apply the sampler modes to the texture.
192 * @param[in] bufferIndex The current buffer index
193 * @param[in] texture The texture to which to apply the sampler modes
194 * @param[in] textureUnit The texture unit of the texture
195 * @param[in] sampler The sampler from which to get the modes.
197 void ApplySampler( BufferIndex bufferIndex,
199 TextureUnit textureUnit,
200 const SceneGraph::SamplerDataProvider& sampler );
203 * Get the texture uniform index of the name sampler in the program.
204 * If not already registered in the program, then this performs the registration
205 * @param[in] program The shader program
206 * @param[in] sampler The sampler holding a texture unit uniform name to search for
207 * @return The texture uniform index in the program
209 unsigned int GetTextureUnitUniformIndex( Program& program,
210 const SceneGraph::SamplerDataProvider& sampler );
214 public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer
215 OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
218 SceneGraph::RenderGeometry* mRenderGeometry;
220 struct TextureUnitUniformIndex
222 const SceneGraph::SamplerDataProvider* sampler;
226 typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms;
227 TextureUnitUniforms mTextureUnitUniforms;
229 struct UniformIndexMap
231 unsigned int uniformIndex; // The index of the cached location in the Program
232 const PropertyInputImpl* propertyValue;
235 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
236 UniformIndexMappings mUniformIndexMap;
238 Vector<GLint> mAttributesLocation;
239 bool mUpdateAttributesLocation;
248 #endif // __DALI_INTERNAL_RENDER_NEW_RENDERER_H__