1 #ifndef DALI_INTERNAL_RENDERER_H
2 #define DALI_INTERNAL_RENDERER_H
5 * Copyright (c) 2022 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/devel-api/rendering/renderer-devel.h>
23 #include <dali/internal/common/blending-options.h>
24 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
25 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
26 #include <dali/internal/event/rendering/geometry-impl.h> // Dali::Internal::Geometry
27 #include <dali/internal/event/rendering/texture-set-impl.h> // Dali::Internal::TextureSet
28 #include <dali/internal/render/renderers/render-renderer.h> // Dali::Render::Renderer::StencilParameters
29 #include <dali/public-api/common/dali-common.h> // DALI_ASSERT_ALWAYS
30 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
31 #include <dali/public-api/rendering/renderer.h> // Dali::Renderer
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
52 * Create a new Renderer.
53 * @return A smart-pointer to the newly allocated Renderer.
55 static RendererPtr New();
58 * @copydoc Dali::Renderer::SetGeometry()
60 void SetGeometry(Geometry& geometry);
63 * @copydoc Dali::Renderer::GetGeometry()
65 GeometryPtr GetGeometry() const;
68 * @copydoc Dali::Renderer::SetTextures()
70 void SetTextures(TextureSet& textureSet);
73 * @copydoc Dali::Renderer::GetTextures()
75 TextureSetPtr GetTextures() const;
78 * @copydoc Dali::Renderer::SetShader()
80 void SetShader(Shader& shader);
83 * @copydoc Dali::Renderer::GetShader()
85 ShaderPtr GetShader() const;
88 * @copydoc Dali::Renderer::SetDepthIndex()
90 void SetDepthIndex(int32_t depthIndex);
93 * @copydoc Dali::Renderer::GetDepthIndex()
95 int32_t GetDepthIndex() const;
98 * @copydoc Dali::Renderer::SetBlendMode()
100 void SetBlendMode(BlendMode::Type mode);
103 * @copydoc Dali::Renderer::GetBlendMode()
105 BlendMode::Type GetBlendMode() const;
108 * @copydoc Dali::Renderer::SetBlendFunc()
110 void SetBlendFunc(BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba);
113 * @copydoc Dali::Renderer::SetBlendFunc()
115 void SetBlendFunc(BlendFactor::Type srcFactorRgb, BlendFactor::Type destFactorRgb, BlendFactor::Type srcFactorAlpha, BlendFactor::Type destFactorAlpha);
118 * @copydoc Dali::Renderer::GetBlendFunc()
120 void GetBlendFunc(BlendFactor::Type& srcFactorRgb, BlendFactor::Type& destFactorRgb, BlendFactor::Type& srcFactorAlpha, BlendFactor::Type& destFactorAlpha) const;
123 * @brief Set same Blend Equation for the RGB and alpha
125 void SetBlendEquation(DevelBlendEquation::Type equationRgba);
128 * @brief Set Blend Equation separately for the RGB and alpha
130 void SetBlendEquation(DevelBlendEquation::Type equationRgb, DevelBlendEquation::Type equationAlpha);
133 * @brief Get Blend Equation of rgb and alpha
135 void GetBlendEquation(DevelBlendEquation::Type& equationRgb, DevelBlendEquation::Type& equationAlpha) const;
138 * @copydoc Dali::Renderer::SetIndexedDrawFirstElement
140 void SetIndexedDrawFirstElement(uint32_t firstElement);
143 * @copydoc Dali::Renderer::SetIndexedDrawElementsCount
145 void SetIndexedDrawElementsCount(uint32_t elementsCount);
148 * @brief Set whether the Pre-multiplied Alpha Blending is required
150 * @param[in] preMultipled whether alpha is pre-multiplied.
152 void EnablePreMultipliedAlpha(bool preMultipled);
155 * @brief Query whether alpha is pre-multiplied.
157 * @return True is alpha is pre-multiplied, false otherwise.
159 bool IsPreMultipliedAlphaEnabled() const;
162 * @brief Query whether Blend Equation Advanced is used in this renderer
164 * @return True is Blend Equation Advanced is used, false otherwise.
166 bool IsAdvancedBlendEquationApplied() const;
169 * @brief Get the scene graph object
171 * @return the scene object
173 const SceneGraph::Renderer& GetRendererSceneObject() const;
175 public: // Default property extensions from Object
177 * @copydoc Dali::Internal::Object::SetDefaultProperty()
179 void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue) override;
182 * @copydoc Dali::Internal::Object::GetDefaultProperty()
184 Property::Value GetDefaultProperty(Property::Index index) const override;
187 * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
189 Property::Value GetDefaultPropertyCurrentValue(Property::Index index) const override;
192 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
194 void OnNotifyDefaultPropertyAnimation(Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType) override;
197 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
199 const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty(Property::Index index) const override;
202 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
204 const PropertyInputImpl* GetSceneObjectInputProperty(Property::Index index) const override;
207 * @brief Adds a draw command to the Renderer.
208 * DrawCommands override Renderer's default behaviour.
210 * @param[in] command Valid reference to a DrawCommand objects
212 void AddDrawCommand(const Dali::DevelRenderer::DrawCommand& command);
214 protected: // implementation
216 * @brief Constructor.
218 * @param sceneObject the scene graph renderer
220 Renderer(const SceneGraph::Renderer* sceneObject);
223 * A reference counted object may only be deleted by calling Unreference()
225 ~Renderer() override;
228 Renderer(const Renderer&) = delete; ///< Deleted copy constructor
229 Renderer& operator=(const Renderer&) = delete; ///< Deleted assignment operator
232 * @brief Retrieves the cached event side value of a default property.
233 * @param[in] index The index of the property
234 * @param[out] value Is set with the cached value of the property if found.
235 * @return True if value set, false otherwise.
237 bool GetCachedPropertyValue(Property::Index index, Property::Value& value) const;
240 * @brief Retrieves the current value of a default property from the scene-graph.
241 * @param[in] index The index of the property
242 * @param[out] value Is set with the current scene-graph value of the property
243 * @return True if value set, false otherwise.
245 bool GetCurrentPropertyValue(Property::Index index, Property::Value& value) const;
248 * @brief Sets the blend color.
249 * @param[in] blendColor The blend color to set.
251 void SetBlendColor(const Vector4& blendColor);
254 * @brief Retrieves the blend-color.
255 * @return A const reference to the blend-color
257 const Vector4& GetBlendColor() const;
260 GeometryPtr mGeometry; ///< Intrusive pointer to the geometry used by this renderer
261 TextureSetPtr mTextureSet; ///< Intrusive pointer to the texture set used by this renderer
262 ShaderPtr mShader; ///< Intrusive pointer to the shader used by this renderer
266 uint32_t mIndexedDrawFirstElement; ///< Offset of first element to draw from bound index buffer
267 uint32_t mIndexedDrawElementCount; ///< Number of elements to draw
269 Render::Renderer::StencilParameters mStencilParameters; ///< Struct containing all stencil related options
270 BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
272 float mOpacity; ///< Local copy of the opacity
273 DepthFunction::Type mDepthFunction : 4; ///< Local copy of the depth function
274 FaceCullingMode::Type mFaceCullingMode : 3; ///< Local copy of the mode of face culling
275 BlendMode::Type mBlendMode : 3; ///< Local copy of the mode of blending
276 DepthWriteMode::Type mDepthWriteMode : 3; ///< Local copy of the depth write mode
277 DepthTestMode::Type mDepthTestMode : 3; ///< Local copy of the depth test mode
278 DevelRenderer::Rendering::Type mRenderingBehavior : 2; ///< The rendering behavior
279 bool mPremultipledAlphaEnabled : 1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
282 std::vector<Dali::DevelRenderer::DrawCommand> mDrawCommands; ///< list of draw commands
285 } // namespace Internal
287 // Helpers for public-api forwarding methods
288 inline Internal::Renderer& GetImplementation(Dali::Renderer& handle)
290 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
292 BaseObject& object = handle.GetBaseObject();
294 return static_cast<Internal::Renderer&>(object);
297 inline const Internal::Renderer& GetImplementation(const Dali::Renderer& handle)
299 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
301 const BaseObject& object = handle.GetBaseObject();
303 return static_cast<const Internal::Renderer&>(object);
308 #endif // DALI_INTERNAL_RENDERER_H