1 #ifndef DALI_INTERNAL_RENDERER_H
2 #define DALI_INTERNAL_RENDERER_H
5 * Copyright (c) 2018 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/internal/common/blending-options.h>
26 #include <dali/internal/event/common/object-connector.h> // Dali::Internal::ObjectConnector
27 #include <dali/internal/event/common/object-impl.h> // Dali::Internal::Object
28 #include <dali/internal/event/rendering/texture-set-impl.h> // Dali::Internal::TextureSet
29 #include <dali/internal/event/rendering/geometry-impl.h> // Dali::Internal::Geometry
30 #include <dali/internal/render/renderers/render-renderer.h> // Dali::Render::Renderer::StencilParameters
42 typedef IntrusivePtr<Renderer> RendererPtr;
45 * Renderer is an object that can be used to show content by combining a Geometry with a shader and textures.
47 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,
116 BlendFactor::Type srcFactorAlpha, BlendFactor::Type destFactorAlpha );
119 * @copydoc Dali::Renderer::GetBlendFunc()
121 void GetBlendFunc( BlendFactor::Type& srcFactorRgb, BlendFactor::Type& destFactorRgb,
122 BlendFactor::Type& srcFactorAlpha, BlendFactor::Type& destFactorAlpha ) const;
125 * @copydoc Dali::Renderer::SetBlendEquation()
127 void SetBlendEquation( BlendEquation::Type equationRgba );
130 * @copydoc Dali::Renderer::SetBlendEquation()
132 void SetBlendEquation( BlendEquation::Type equationRgb, BlendEquation::Type equationAlpha );
135 * @copydoc Dali::Renderer::GetBlendEquation()
137 void GetBlendEquation( BlendEquation::Type& equationRgb, BlendEquation::Type& equationAlpha ) const;
140 * @copydoc Dali::Renderer::SetIndexedDrawFirstElement
142 void SetIndexedDrawFirstElement( uint32_t firstElement );
145 * @copydoc Dali::Renderer::SetIndexedDrawElementsCount
147 void SetIndexedDrawElementsCount( uint32_t elementsCount );
150 * @brief Set whether the Pre-multiplied Alpha Blending is required
152 * @param[in] preMultipled whether alpha is pre-multiplied.
154 void EnablePreMultipliedAlpha( bool preMultipled );
157 * @brief Query whether alpha is pre-multiplied.
159 * @return True is alpha is pre-multiplied, false otherwise.
161 bool IsPreMultipliedAlphaEnabled() const;
164 * @brief Get the scene graph object
166 * @return the scene object
168 const SceneGraph::Renderer& GetRendererSceneObject() const;
170 public: // Default property extensions from Object
173 * @copydoc Dali::Internal::Object::SetDefaultProperty()
175 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
178 * @copydoc Dali::Internal::Object::GetDefaultProperty()
180 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
183 * @copydoc Dali::Internal::Object::GetDefaultPropertyCurrentValue()
185 virtual Property::Value GetDefaultPropertyCurrentValue( Property::Index index ) const;
188 * @copydoc Dali::Internal::Object::OnNotifyDefaultPropertyAnimation()
190 virtual void OnNotifyDefaultPropertyAnimation( Animation& animation, Property::Index index, const Property::Value& value, Animation::Type animationType );
193 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
195 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
198 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
200 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
202 private: // implementation
205 * @brief Constructor.
207 * @param sceneObject the scene graph renderer
209 Renderer( const SceneGraph::Renderer* sceneObject );
212 * @brief Sets the blend color.
213 * @param[in] blendColor The blend color to set.
215 void SetBlendColor( const Vector4& blendColor );
218 * @brief Retrieves the blend-color.
219 * @return A const reference to the blend-color
221 const Vector4& GetBlendColor() const;
224 * @brief Retrieves the cached event side value of a default property.
225 * @param[in] index The index of the property
226 * @param[out] value Is set with the cached value of the property if found.
227 * @return True if value set, false otherwise.
229 bool GetCachedPropertyValue( Property::Index index, Property::Value& value ) const;
232 * @brief Retrieves the current value of a default property from the scene-graph.
233 * @param[in] index The index of the property
234 * @param[out] value Is set with the current scene-graph value of the property
235 * @return True if value set, false otherwise.
237 bool GetCurrentPropertyValue( Property::Index index, Property::Value& value ) const;
241 * A reference counted object may only be deleted by calling Unreference()
245 private: // unimplemented methods
246 Renderer( const Renderer& );
247 Renderer& operator=( const Renderer& );
251 GeometryPtr mGeometry; ///< Intrusive pointer to the geometry used by this renderer
252 TextureSetPtr mTextureSet; ///< Intrusive pointer to the texture set used by this renderer
253 ShaderPtr mShader; ///< Intrusive pointer to the shader used by this renderer
257 uint32_t mIndexedDrawFirstElement; ///< Offset of first element to draw from bound index buffer
258 uint32_t mIndexedDrawElementCount; ///< Number of elements to draw
260 Render::Renderer::StencilParameters mStencilParameters; ///< Struct containing all stencil related options
261 BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
263 float mOpacity; ///< Local copy of the opacity
264 DepthFunction::Type mDepthFunction:4; ///< Local copy of the depth function
265 FaceCullingMode::Type mFaceCullingMode:3; ///< Local copy of the mode of face culling
266 BlendMode::Type mBlendMode:3; ///< Local copy of the mode of blending
267 DepthWriteMode::Type mDepthWriteMode:3; ///< Local copy of the depth write mode
268 DepthTestMode::Type mDepthTestMode:3; ///< Local copy of the depth test mode
269 bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
272 } // namespace Internal
274 // Helpers for public-api forwarding methods
275 inline Internal::Renderer& GetImplementation( Dali::Renderer& handle )
277 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
279 BaseObject& object = handle.GetBaseObject();
281 return static_cast<Internal::Renderer&>(object);
284 inline const Internal::Renderer& GetImplementation( const Dali::Renderer& handle )
286 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
288 const BaseObject& object = handle.GetBaseObject();
290 return static_cast<const Internal::Renderer&>(object);
295 #endif // DALI_INTERNAL_RENDERER_H