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
86 * @param[in] depthFunction Depth function
88 static Renderer* New( SceneGraph::RenderDataProvider* dataProviders,
89 Render::Geometry* geometry,
90 unsigned int blendingBitmask,
91 const Vector4* blendColor,
92 FaceCullingMode::Type faceCullingMode,
93 bool preMultipliedAlphaEnabled,
94 DepthWriteMode::Type depthWriteMode,
95 DepthFunction::Type depthFunction );
99 * @param[in] dataProviders The data providers for the renderer
100 * @param[in] geometry The geometry for the renderer
101 * @param[in] blendingBitmask A bitmask of blending options.
102 * @param[in] blendColor The blend color to pass to GL
103 * @param[in] faceCullingMode The face-culling mode.
104 * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
105 * @param[in] depthWriteMode Depth buffer write mode
106 * @param[in] depthFunction Depth function
108 Renderer( SceneGraph::RenderDataProvider* dataProviders,
109 Render::Geometry* geometry,
110 unsigned int blendingBitmask,
111 const Vector4* blendColor,
112 FaceCullingMode::Type faceCullingMode,
113 bool preMultipliedAlphaEnabled,
114 DepthWriteMode::Type depthWriteMode,
115 DepthFunction::Type depthFunction );
118 * Change the data providers of the renderer
119 * @param[in] dataProviders The data providers
121 void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
124 * Change the geometry used by the renderer
125 * @param[in] geometry The new geometry
127 void SetGeometry( Render::Geometry* geometry );
129 * Second-phase construction.
130 * This is called when the renderer is inside render thread
131 * @param[in] context to use
132 * @param[in] textureCache to use
133 * @param[in] uniformNameCache to use
135 void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
143 * Set the face-culling mode.
144 * @param[in] mode The face-culling mode.
146 void SetFaceCullingMode( FaceCullingMode::Type mode );
149 * Set the bitmask for blending options
150 * @param[in] bitmask A bitmask of blending options.
152 void SetBlendingBitMask( unsigned int bitmask );
155 * Set the blend color for blending options
156 * @param[in] blendColor The blend color to pass to GL
158 void SetBlendColor( const Vector4* color );
161 * Set the first element index to draw by the indexed draw
162 * @param[in] firstElement index of first element to draw
164 void SetIndexedDrawFirstElement( size_t firstElement );
167 * Set the number of elements to draw by the indexed draw
168 * @param[in] elementsCount number of elements to draw
170 void SetIndexedDrawElementsCount( size_t elementsCount );
173 * @brief Set whether the Pre-multiplied Alpha Blending is required
175 * @param[in] preMultipled whether alpha is pre-multiplied.
177 void EnablePreMultipliedAlpha( bool preMultipled );
180 * Sets the depth write mode
181 * @param[in] depthWriteMode The depth write mode
183 void SetDepthWriteMode( DepthWriteMode::Type depthWriteMode );
186 * Query the Renderer's depth write mode
187 * @return The renderer depth write mode
189 DepthWriteMode::Type GetDepthWriteMode() const;
192 * Sets the depth function
193 * @param[in] depthFunction The depth function
195 void SetDepthFunction( DepthFunction::Type depthFunction );
198 * Query the Renderer's depth function
199 * @return The renderer depth function
201 DepthFunction::Type GetDepthFunction() const;
204 * Called to render during RenderManager::Render().
205 * @param[in] context The context used for rendering
206 * @param[in] textureCache The texture cache used to get textures
207 * @param[in] bufferIndex The index of the previous update buffer.
208 * @param[in] node The node using this renderer
209 * @param[in] defaultShader in case there is no custom shader
210 * @param[in] modelViewMatrix The model-view matrix.
211 * @param[in] viewMatrix The view matrix.
212 * @param[in] projectionMatrix The projection matrix.
214 void Render( Context& context,
215 SceneGraph::TextureCache& textureCache,
216 BufferIndex bufferIndex,
217 const SceneGraph::NodeDataProvider& node,
218 SceneGraph::Shader& defaultShader,
219 const Matrix& modelMatrix,
220 const Matrix& modelViewMatrix,
221 const Matrix& viewMatrix,
222 const Matrix& projectionMatrix,
227 * Write the renderer's sort attributes to the passed in reference
229 * @param[in] bufferIndex The current update buffer index.
230 * @param[out] sortAttributes
232 void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
236 struct UniformIndexMap;
239 Renderer( const Renderer& );
242 Renderer& operator=( const Renderer& rhs );
245 * Sets blending options
246 * @param context to use
247 * @param blend Wheter blending should be enabled or not
249 void SetBlending( Context& context, bool blend );
252 * Set the uniforms from properties according to the uniform map
253 * @param[in] bufferIndex The index of the previous update buffer.
254 * @param[in] node The node using the renderer
255 * @param[in] size The size of the renderer
256 * @param[in] program The shader program on which to set the uniforms.
258 void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program );
261 * Set the program uniform in the map from the mapped property
262 * @param[in] bufferIndex The index of the previous update buffer.
263 * @param[in] program The shader program
264 * @param[in] map The uniform
266 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
269 * Bind the textures and setup the samplers
270 * @param[in] context The GL context
271 * @param[in] textureCache The texture cache
272 * @param[in] program The shader program
273 * @return False if create or bind failed, true if success.
275 bool BindTextures( Context& context, SceneGraph::TextureCache& textureCache, Program& program );
279 OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
282 SceneGraph::TextureCache* mTextureCache;
283 Render::UniformNameCache* mUniformNameCache;
284 Render::Geometry* mGeometry;
286 struct UniformIndexMap
288 unsigned int uniformIndex; // The index of the cached location in the Program
289 const PropertyInputImpl* propertyValue;
292 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
293 UniformIndexMappings mUniformIndexMap;
295 Vector<GLint> mAttributesLocation;
297 BlendingOptions mBlendingOptions; /// Blending options including blend color, blend func and blend equation
298 FaceCullingMode::Type mFaceCullingMode; /// Mode of face culling
299 DepthWriteMode::Type mDepthWriteMode; /// Depth write mode
300 DepthFunction::Type mDepthFunction; /// Depth function
302 size_t mIndexedDrawFirstElement; /// Offset of first element to draw
303 size_t mIndexedDrawElementsCount; /// Number of elements to draw
305 bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed
306 bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
309 } // namespace SceneGraph
311 } // namespace Internal
315 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__