1 #ifndef __DALI_INTERNAL_RENDER_RENDERER_H__
2 #define __DALI_INTERNAL_RENDER_RENDERER_H__
5 * Copyright (c) 2016 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/public-api/rendering/texture-set.h>
25 #include <dali/internal/common/blending-options.h>
26 #include <dali/internal/common/message.h>
27 #include <dali/internal/common/type-abstraction-enums.h>
28 #include <dali/internal/event/common/property-input-impl.h>
29 #include <dali/internal/event/effects/shader-declarations.h>
30 #include <dali/internal/render/data-providers/render-data-provider.h>
31 #include <dali/internal/render/gl-resources/gl-resource-owner.h>
32 #include <dali/internal/render/renderers/render-geometry.h>
33 #include <dali/internal/update/manager/prepare-render-instructions.h>
34 #include <dali/integration-api/debug.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] depthTestMode Depth buffer test mode
87 * @param[in] depthFunction Depth function
89 static Renderer* New( SceneGraph::RenderDataProvider* dataProviders,
90 Render::Geometry* geometry,
91 unsigned int blendingBitmask,
92 const Vector4* blendColor,
93 FaceCullingMode::Type faceCullingMode,
94 bool preMultipliedAlphaEnabled,
95 DepthWriteMode::Type depthWriteMode,
96 DepthTestMode::Type depthTestMode,
97 DepthFunction::Type depthFunction );
101 * @param[in] dataProviders The data providers for the renderer
102 * @param[in] geometry The geometry for the renderer
103 * @param[in] blendingBitmask A bitmask of blending options.
104 * @param[in] blendColor The blend color to pass to GL
105 * @param[in] faceCullingMode The face-culling mode.
106 * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied.
107 * @param[in] depthWriteMode Depth buffer write mode
108 * @param[in] depthTestMode Depth buffer test mode
109 * @param[in] depthFunction Depth function
111 Renderer( SceneGraph::RenderDataProvider* dataProviders,
112 Render::Geometry* geometry,
113 unsigned int blendingBitmask,
114 const Vector4* blendColor,
115 FaceCullingMode::Type faceCullingMode,
116 bool preMultipliedAlphaEnabled,
117 DepthWriteMode::Type depthWriteMode,
118 DepthTestMode::Type depthTestMode,
119 DepthFunction::Type depthFunction );
122 * Change the data providers of the renderer
123 * @param[in] dataProviders The data providers
125 void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
128 * Change the geometry used by the renderer
129 * @param[in] geometry The new geometry
131 void SetGeometry( Render::Geometry* geometry );
133 * Second-phase construction.
134 * This is called when the renderer is inside render thread
135 * @param[in] context to use
136 * @param[in] textureCache to use
137 * @param[in] uniformNameCache to use
139 void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
147 * Set the face-culling mode.
148 * @param[in] mode The face-culling mode.
150 void SetFaceCullingMode( FaceCullingMode::Type mode );
153 * Set the bitmask for blending options
154 * @param[in] bitmask A bitmask of blending options.
156 void SetBlendingBitMask( unsigned int bitmask );
159 * Set the blend color for blending options
160 * @param[in] blendColor The blend color to pass to GL
162 void SetBlendColor( const Vector4* color );
165 * Set the first element index to draw by the indexed draw
166 * @param[in] firstElement index of first element to draw
168 void SetIndexedDrawFirstElement( size_t firstElement );
171 * Set the number of elements to draw by the indexed draw
172 * @param[in] elementsCount number of elements to draw
174 void SetIndexedDrawElementsCount( size_t elementsCount );
177 * @brief Set whether the Pre-multiplied Alpha Blending is required
179 * @param[in] preMultipled whether alpha is pre-multiplied.
181 void EnablePreMultipliedAlpha( bool preMultipled );
184 * Sets the depth write mode
185 * @param[in] depthWriteMode The depth write mode
187 void SetDepthWriteMode( DepthWriteMode::Type depthWriteMode );
190 * Query the Renderer's depth write mode
191 * @return The renderer depth write mode
193 DepthWriteMode::Type GetDepthWriteMode() const;
196 * Sets the depth test mode
197 * @param[in] depthTestMode The depth test mode
199 void SetDepthTestMode( DepthTestMode::Type depthTestMode );
202 * Query the Renderer's depth test mode
203 * @return The renderer depth test mode
205 DepthTestMode::Type GetDepthTestMode() const;
208 * Sets the depth function
209 * @param[in] depthFunction The depth function
211 void SetDepthFunction( DepthFunction::Type depthFunction );
214 * Query the Renderer's depth function
215 * @return The renderer depth function
217 DepthFunction::Type GetDepthFunction() const;
220 * Called to render during RenderManager::Render().
221 * @param[in] context The context used for rendering
222 * @param[in] textureCache The texture cache used to get textures
223 * @param[in] bufferIndex The index of the previous update buffer.
224 * @param[in] node The node using this renderer
225 * @param[in] defaultShader in case there is no custom shader
226 * @param[in] modelViewMatrix The model-view matrix.
227 * @param[in] viewMatrix The view matrix.
228 * @param[in] projectionMatrix The projection matrix.
230 void Render( Context& context,
231 SceneGraph::TextureCache& textureCache,
232 BufferIndex bufferIndex,
233 const SceneGraph::NodeDataProvider& node,
234 SceneGraph::Shader& defaultShader,
235 const Matrix& modelMatrix,
236 const Matrix& modelViewMatrix,
237 const Matrix& viewMatrix,
238 const Matrix& projectionMatrix,
243 * Write the renderer's sort attributes to the passed in reference
245 * @param[in] bufferIndex The current update buffer index.
246 * @param[out] sortAttributes
248 void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
252 struct UniformIndexMap;
255 Renderer( const Renderer& );
258 Renderer& operator=( const Renderer& rhs );
261 * Sets blending options
262 * @param context to use
263 * @param blend Wheter blending should be enabled or not
265 void SetBlending( Context& context, bool blend );
268 * Set the uniforms from properties according to the uniform map
269 * @param[in] bufferIndex The index of the previous update buffer.
270 * @param[in] node The node using the renderer
271 * @param[in] size The size of the renderer
272 * @param[in] program The shader program on which to set the uniforms.
274 void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program );
277 * Set the program uniform in the map from the mapped property
278 * @param[in] bufferIndex The index of the previous update buffer.
279 * @param[in] program The shader program
280 * @param[in] map The uniform
282 void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
285 * Bind the textures and setup the samplers
286 * @param[in] context The GL context
287 * @param[in] textureCache The texture cache
288 * @param[in] program The shader program
289 * @return False if create or bind failed, true if success.
291 bool BindTextures( Context& context, SceneGraph::TextureCache& textureCache, Program& program );
295 OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
298 SceneGraph::TextureCache* mTextureCache;
299 Render::UniformNameCache* mUniformNameCache;
300 Render::Geometry* mGeometry;
302 struct UniformIndexMap
304 unsigned int uniformIndex; // The index of the cached location in the Program
305 const PropertyInputImpl* propertyValue;
308 typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
309 UniformIndexMappings mUniformIndexMap;
311 Vector<GLint> mAttributesLocation;
313 BlendingOptions mBlendingOptions; /// Blending options including blend color, blend func and blend equation
314 FaceCullingMode::Type mFaceCullingMode; /// Mode of face culling
315 DepthFunction::Type mDepthFunction; /// Depth function
317 size_t mIndexedDrawFirstElement; /// Offset of first element to draw
318 size_t mIndexedDrawElementsCount; /// Number of elements to draw
320 DepthWriteMode::Type mDepthWriteMode:2; /// Depth write mode
321 DepthTestMode::Type mDepthTestMode:2; /// Depth test mode
323 bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed
324 bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
327 } // namespace SceneGraph
329 } // namespace Internal
333 #endif // __DALI_INTERNAL_RENDER_RENDERER_H__