1 #ifndef DALI_INTERNAL_RENDERER_H
2 #define DALI_INTERNAL_RENDERER_H
5 * Copyright (c) 2020 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/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/public-api/rendering/renderer.h> // Dali::Renderer
25 #include <dali/devel-api/rendering/renderer-devel.h>
26 #include <dali/internal/common/blending-options.h>
27 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
28 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
29 #include <dali/internal/event/rendering/texture-set-impl.h> // Dali::Internal::TextureSet
30 #include <dali/internal/event/rendering/geometry-impl.h> // Dali::Internal::Geometry
31 #include <dali/internal/render/renderers/render-renderer.h> // Dali::Render::Renderer::StencilParameters
43 using RendererPtr = IntrusivePtr<Renderer>;
46 * Renderer is an object that can be used to show content by combining a Geometry with a shader and textures.
48 class Renderer : public Object
53 * Create a new Renderer.
54 * @return A smart-pointer to the newly allocated Renderer.
56 static RendererPtr New();
59 * @copydoc Dali::Renderer::SetGeometry()
61 void SetGeometry( Geometry& geometry );
64 * @copydoc Dali::Renderer::GetGeometry()
66 GeometryPtr GetGeometry() const;
69 * @copydoc Dali::Renderer::SetTextures()
71 void SetTextures( TextureSet& textureSet );
74 * @copydoc Dali::Renderer::GetTextures()
76 TextureSetPtr GetTextures() const;
79 * @copydoc Dali::Renderer::SetShader()
81 void SetShader( Shader& shader );
84 * @copydoc Dali::Renderer::GetShader()
86 ShaderPtr GetShader() const;
89 * @copydoc Dali::Renderer::SetDepthIndex()
91 void SetDepthIndex( int32_t depthIndex );
94 * @copydoc Dali::Renderer::GetDepthIndex()
96 int32_t GetDepthIndex() const;
99 * @copydoc Dali::Renderer::SetBlendMode()
101 void SetBlendMode( BlendMode::Type mode );
104 * @copydoc Dali::Renderer::GetBlendMode()
106 BlendMode::Type GetBlendMode() const;
109 * @copydoc Dali::Renderer::SetBlendFunc()
111 void SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba );
114 * @copydoc Dali::Renderer::SetBlendFunc()
116 void SetBlendFunc( BlendFactor::Type srcFactorRgb, BlendFactor::Type destFactorRgb,
117 BlendFactor::Type srcFactorAlpha, BlendFactor::Type destFactorAlpha );
120 * @copydoc Dali::Renderer::GetBlendFunc()
122 void GetBlendFunc( BlendFactor::Type& srcFactorRgb, BlendFactor::Type& destFactorRgb,
123 BlendFactor::Type& srcFactorAlpha, BlendFactor::Type& destFactorAlpha ) const;
126 * @brief Set same Blend Equation for the RGB and alpha
128 void SetBlendEquation( DevelBlendEquation::Type equationRgba );
131 * @brief Set Blend Equation separately for the RGB and alpha
133 void SetBlendEquation( DevelBlendEquation::Type equationRgb, DevelBlendEquation::Type equationAlpha );
136 * @brief Get Blend Equation of rgb and alpha
138 void GetBlendEquation( DevelBlendEquation::Type& equationRgb, DevelBlendEquation::Type& equationAlpha ) const;
141 * @copydoc Dali::Renderer::SetIndexedDrawFirstElement
143 void SetIndexedDrawFirstElement( uint32_t firstElement );
146 * @copydoc Dali::Renderer::SetIndexedDrawElementsCount
148 void SetIndexedDrawElementsCount( uint32_t elementsCount );
151 * @brief Set whether the Pre-multiplied Alpha Blending is required
153 * @param[in] preMultipled whether alpha is pre-multiplied.
155 void EnablePreMultipliedAlpha( bool preMultipled );
158 * @brief Query whether alpha is pre-multiplied.
160 * @return True is alpha is pre-multiplied, false otherwise.
162 bool IsPreMultipliedAlphaEnabled() const;
165 * @brief Query whether Blend Equation Advanced is used in this renderer
167 * @return True is Blend Equation Advanced is used, false otherwise.
169 bool IsAdvancedBlendEquationApplied() const;
172 * @brief Get the scene graph object
174 * @return the scene object
176 const SceneGraph::Renderer& GetRendererSceneObject() const;
178 public: // Default property extensions from Object
181 * @copydoc Dali::Internal::Object::SetDefaultProperty()
183 void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
186 * @copydoc Dali::Internal::Object::GetDefaultProperty()
188 Property::Value GetDefaultProperty( Property::Index index ) const override;
191 * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
193 Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const override;
196 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
198 void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType ) override;
201 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
203 const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const override;
206 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
208 const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const override;
211 * @brief Adds a draw command to the Renderer.
212 * DrawCommands override Renderer's default behaviour.
214 * @param[in] command Valid reference to a DrawCommand objects
216 void AddDrawCommand( const Dali::DevelRenderer::DrawCommand& command );
218 private: // implementation
221 * @brief Constructor.
223 * @param sceneObject the scene graph renderer
225 Renderer( const SceneGraph::Renderer* sceneObject );
228 * @brief Sets the blend color.
229 * @param[in] blendColor The blend color to set.
231 void SetBlendColor( const Vector4& blendColor );
234 * @brief Retrieves the blend-color.
235 * @return A const reference to the blend-color
237 const Vector4& GetBlendColor() const;
240 * @brief Retrieves the cached event side value of a default property.
241 * @param[in] index The index of the property
242 * @param[out] value Is set with the cached value of the property if found.
243 * @return True if value set, false otherwise.
245 bool GetCachedPropertyValue( Property::Index index, Property::Value& value ) const;
248 * @brief Retrieves the current value of a default property from the scene-graph.
249 * @param[in] index The index of the property
250 * @param[out] value Is set with the current scene-graph value of the property
251 * @return True if value set, false otherwise.
253 bool GetCurrentPropertyValue( Property::Index index, Property::Value& value ) const;
257 * A reference counted object may only be deleted by calling Unreference()
259 ~Renderer() override;
261 private: // unimplemented methods
262 Renderer( const Renderer& );
263 Renderer& operator=( const Renderer& );
267 GeometryPtr mGeometry; ///< Intrusive pointer to the geometry used by this renderer
268 TextureSetPtr mTextureSet; ///< Intrusive pointer to the texture set used by this renderer
269 ShaderPtr mShader; ///< Intrusive pointer to the shader used by this renderer
273 uint32_t mIndexedDrawFirstElement; ///< Offset of first element to draw from bound index buffer
274 uint32_t mIndexedDrawElementCount; ///< Number of elements to draw
276 Render::Renderer::StencilParameters mStencilParameters; ///< Struct containing all stencil related options
277 BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
279 float mOpacity; ///< Local copy of the opacity
280 DepthFunction::Type mDepthFunction:4; ///< Local copy of the depth function
281 FaceCullingMode::Type mFaceCullingMode:3; ///< Local copy of the mode of face culling
282 BlendMode::Type mBlendMode:3; ///< Local copy of the mode of blending
283 DepthWriteMode::Type mDepthWriteMode:3; ///< Local copy of the depth write mode
284 DepthTestMode::Type mDepthTestMode:3; ///< Local copy of the depth test mode
285 DevelRenderer::Rendering::Type mRenderingBehavior:2; ///< The rendering behavior
286 bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
288 std::vector<Dali::DevelRenderer::DrawCommand> mDrawCommands; ///< list of draw commands
291 } // namespace Internal
293 // Helpers for public-api forwarding methods
294 inline Internal::Renderer& GetImplementation( Dali::Renderer& handle )
296 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
298 BaseObject& object = handle.GetBaseObject();
300 return static_cast<Internal::Renderer&>(object);
303 inline const Internal::Renderer& GetImplementation( const Dali::Renderer& handle )
305 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
307 const BaseObject& object = handle.GetBaseObject();
309 return static_cast<const Internal::Renderer&>(object);
314 #endif // DALI_INTERNAL_RENDERER_H