1 #ifndef __DALI_INTERNAL_RENDER_RENDERER_H__
2 #define __DALI_INTERNAL_RENDER_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.
22 #include <dali/public-api/math/matrix.h>
23 #include <dali/public-api/math/vector4.h>
24 #include <dali/devel-api/rendering/texture-set.h>
25 #include <dali/internal/common/blending-options.h>
26 #include <dali/internal/common/message.h>
27 #include <dali/internal/event/common/property-input-impl.h>
28 #include <dali/internal/event/effects/shader-declarations.h>
29 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
30 #include <dali/integration-api/debug.h>
31 #include <dali/internal/common/type-abstraction-enums.h>
32 #include <dali/internal/update/manager/prepare-render-instructions.h>
33 #include <dali/internal/render/data-providers/render-data-provider.h>
34 #include <dali/internal/render/renderers/render-geometry.h>
47 class SceneController;
50 class NodeDataProvider;
56 class UniformNameCache;
59 * Renderers are used to render meshes
60 * These objects are used during RenderManager::Render(), so properties modified during
61 * the Update must either be double-buffered, or set via a message added to the RenderQueue.
63 class Renderer : public GlResourceOwner
68 * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
70 void GlContextDestroyed();
73 * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
78 * Create a new renderer instance
79 * @param[in] dataProviders The data providers for the renderer
80 * @param[in] geometry The geometry for the renderer
81 * @param[in] blendingBitmask A bitmask of blending options.
82 * @param[in] blendColor The blend color to pass to GL
83 * @param[in] faceCullingMode The face-culling mode.
84 * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
85 * @param[in] depthWriteMode Depth buffer write mode
87 static Renderer* New( SceneGraph::RenderDataProvider* dataProviders,
88 Render::Geometry* geometry,
89 unsigned int blendingBitmask,
90 const Vector4* blendColor,
91 Dali::Renderer::FaceCullingMode faceCullingMode,
92 bool preMultipliedAlphaEnabled,
93 Dali::Renderer::DepthWriteMode depthWriteMode );
97 * @param[in] dataProviders The data providers for the renderer
98 * @param[in] geometry The geometry for the renderer
99 * @param[in] blendingBitmask A bitmask of blending options.
100 * @param[in] blendColor The blend color to pass to GL
101 * @param[in] faceCullingMode The face-culling mode.
102 * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
103 * @param[in] depthWriteMode Depth buffer write mode
105 Renderer( SceneGraph::RenderDataProvider* dataProviders,
106 Render::Geometry* geometry,
107 unsigned int blendingBitmask,
108 const Vector4* blendColor,
109 Dali::Renderer::FaceCullingMode faceCullingMode,
110 bool preMultipliedAlphaEnabled,
111 Dali::Renderer::DepthWriteMode depthWriteMode );
114 * Change the data providers of the renderer
115 * @param[in] dataProviders The data providers
117 void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
120 * Change the geometry used by the renderer
121 * @param[in] geometry The new geometry
123 void SetGeometry( Render::Geometry* geometry );
125 * Second-phase construction.
126 * This is called when the renderer is inside render thread
127 * @param[in] context to use
128 * @param[in] textureCache to use
129 * @param[in] uniformNameCache to use
131 void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
139 * Set the face-culling mode.
140 * @param[in] mode The face-culling mode.
142 void SetFaceCullingMode( Dali::Renderer::FaceCullingMode mode );
145 * Set the bitmask for blending options
146 * @param[in] bitmask A bitmask of blending options.
148 void SetBlendingBitMask( unsigned int bitmask );
151 * Set the blend color for blending options
152 * @param[in] blendColor The blend color to pass to GL
154 void SetBlendColor( const Vector4* color );
157 * Set the first element index to draw by the indexed draw
158 * @param[in] firstElement index of first element to draw
160 void SetIndexedDrawFirstElement( size_t firstElement );
163 * Set the number of elements to draw by the indexed draw
164 * @param[in] elementsCount number of elements to draw
166 void SetIndexedDrawElementsCount( size_t elementsCount );
169 * @brief Set whether the Pre-multiplied Alpha Blending is required
171 * @param[in] preMultipled whether alpha is pre-multiplied.
173 void EnablePreMultipliedAlpha( bool preMultipled );
176 * Query the Renderer's depth write mode
177 * @return The renderer depth write mode
179 Dali::Renderer::DepthWriteMode GetDepthWriteMode() const;
182 * Sets the depth write mode
183 * @param[in] depthWriteMode The depth write mode
185 void SetDepthWriteMode( Dali::Renderer::DepthWriteMode depthWriteMode );
188 * Called to render during RenderManager::Render().
189 * @param[in] context The context used for rendering
190 * @param[in] textureCache The texture cache used to get textures
191 * @param[in] bufferIndex The index of the previous update buffer.
192 * @param[in] node The node using this renderer
193 * @param[in] defaultShader in case there is no custom shader
194 * @param[in] modelViewMatrix The model-view matrix.
195 * @param[in] viewMatrix The view matrix.
196 * @param[in] projectionMatrix The projection matrix.
198 void Render( Context& context,
199 SceneGraph::TextureCache& textureCache,
200 BufferIndex bufferIndex,
201 const SceneGraph::NodeDataProvider& node,
202 SceneGraph::Shader& defaultShader,
203 const Matrix& modelViewMatrix,
204 const Matrix& viewMatrix,
205 const Matrix& projectionMatrix,
210 * Write the renderer's sort attributes to the passed in reference
212 * @param[in] bufferIndex The current update buffer index.
213 * @param[out] sortAttributes
215 void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
219 struct UniformIndexMap;
222 Renderer( const Renderer& );
225 Renderer& operator=( const Renderer& rhs );
228 * Sets blending options
229 * @param context to use
230 * @param blend Wheter blending should be enabled or not
232 void SetBlending( Context& context, bool blend );
235 * Set the uniforms from properties according to the uniform map
236 * @param[in] bufferIndex The index of the previous update buffer.
237 * @param[in] node The node using the renderer
238 * @param[in] size The size of the renderer
239 * @param[in] program The shader program on which to set the uniforms.
241 void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program );
244 * Set the program uniform in the map from the mapped property
245 * @param[in] bufferIndex The index of the previous update buffer.
246 * @param[in] program The shader program
247 * @param[in] map The uniform
249 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
252 * Bind the textures and setup the samplers
253 * @param[in] textureCache The texture cache
254 * @param[in] program The shader program
255 * @return False if create or bind failed, true if success.
257 bool BindTextures( SceneGraph::TextureCache& textureCache, Program& program );
261 OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
264 SceneGraph::TextureCache* mTextureCache;
265 Render::UniformNameCache* mUniformNameCache;
266 Render::Geometry* mGeometry;
268 struct UniformIndexMap
270 unsigned int uniformIndex; // The index of the cached location in the Program
271 const PropertyInputImpl* propertyValue;
274 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
275 UniformIndexMappings mUniformIndexMap;
277 Vector<GLint> mAttributesLocation;
279 BlendingOptions mBlendingOptions; /// Blending options including blend color, blend func and blend equation
280 Dali::Renderer::FaceCullingMode mFaceCullingMode; /// Mode of face culling
281 Dali::Renderer::DepthWriteMode mDepthWriteMode; /// Depth write mode
283 size_t mIndexedDrawFirstElement; /// Offset of first element to draw
284 size_t mIndexedDrawElementsCount; /// Number of elements to draw
286 bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed
287 bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
290 } // namespace SceneGraph
292 } // namespace Internal
296 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__