1 #ifndef DALI_INTERNAL_RENDERER_H
2 #define DALI_INTERNAL_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/common/dali-common.h> // DALI_ASSERT_ALWAYS
23 #include <dali/public-api/common/intrusive-ptr.h> // Dali::IntrusivePtr
24 #include <dali/devel-api/rendering/renderer.h> // Dali::Renderer
25 #include <dali/internal/common/blending-options.h>
26 #include <dali/internal/event/common/connectable.h> // Dali::Internal::Connectable
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
43 typedef IntrusivePtr<Renderer> RendererPtr;
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 Geometry* GetGeometry() const;
69 * @copydoc Dali::Renderer::SetTextures()
71 void SetTextures( TextureSet& textureSet );
74 * @copydoc Dali::Renderer::GetTextures()
76 TextureSet* GetTextures() const;
79 * @copydoc Dali::Renderer::SetShader()
81 void SetShader( Shader& shader );
84 * @copydoc Dali::Renderer::GetShader()
86 Shader* GetShader() const;
89 * @copydoc Dali::Renderer::SetDepthIndex()
91 void SetDepthIndex( int depthIndex );
94 * @copydoc Dali::Renderer::GetDepthIndex()
96 int GetDepthIndex() const;
99 * @copydoc Dali::Renderer::SetFaceCullingMode()
101 void SetFaceCullingMode( FaceCullingMode::Type cullingMode );
104 * @copydoc Dali::Renderer::GetFaceCullingMode()
106 FaceCullingMode::Type GetFaceCullingMode();
109 * @copydoc Dali::Renderer::SetBlendMode()
111 void SetBlendMode( BlendMode::Type mode );
114 * @copydoc Dali::Renderer::GetBlendMode()
116 BlendMode::Type GetBlendMode() const;
119 * @copydoc Dali::Renderer::SetBlendFunc()
121 void SetBlendFunc( BlendFactor::Type srcFactorRgba, BlendFactor::Type destFactorRgba );
124 * @copydoc Dali::Renderer::SetBlendFunc()
126 void SetBlendFunc( BlendFactor::Type srcFactorRgb, BlendFactor::Type destFactorRgb,
127 BlendFactor::Type srcFactorAlpha, BlendFactor::Type destFactorAlpha );
130 * @copydoc Dali::Renderer::GetBlendFunc()
132 void GetBlendFunc( BlendFactor::Type& srcFactorRgb, BlendFactor::Type& destFactorRgb,
133 BlendFactor::Type& srcFactorAlpha, BlendFactor::Type& destFactorAlpha ) const;
136 * @copydoc Dali::Renderer::SetBlendEquation()
138 void SetBlendEquation( BlendEquation::Type equationRgba );
141 * @copydoc Dali::Renderer::SetBlendEquation()
143 void SetBlendEquation( BlendEquation::Type equationRgb, BlendEquation::Type equationAlpha );
146 * @copydoc Dali::Renderer::GetBlendEquation()
148 void GetBlendEquation( BlendEquation::Type& equationRgb, BlendEquation::Type& equationAlpha ) const;
151 * @copydoc Dali::Renderer::SetBlendColor()
153 void SetBlendColor( const Vector4& color );
156 * @copydoc Dali::Renderer::GetBlendColor()
158 Vector4 GetBlendColor() const;
161 * @copydoc Dali::Renderer::SetIndexedDrawFirstElement
163 void SetIndexedDrawFirstElement( size_t firstElement );
166 * @copydoc Dali::Renderer::SetIndexedDrawElementsCount
168 void SetIndexedDrawElementsCount( size_t elementsCount );
171 * @brief Set whether the Pre-multiplied Alpha Blending is required
173 * @param[in] preMultipled whether alpha is pre-multiplied.
175 void EnablePreMultipliedAlpha( bool preMultipled );
178 * @brief Query whether alpha is pre-multiplied.
180 * @return True is alpha is pre-multiplied, false otherwise.
182 bool IsPreMultipliedAlphaEnabled() const;
185 * @brief Get the scene graph object
187 * @return the scene object
189 SceneGraph::Renderer* GetRendererSceneObject();
191 public: // Default property extensions from Object
194 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
196 virtual unsigned int GetDefaultPropertyCount() const;
199 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
201 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
204 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
206 virtual const char* GetDefaultPropertyName(Property::Index index) const;
209 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
211 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
214 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
216 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
219 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
221 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
224 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
226 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
229 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
231 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
234 * @copydoc Dali::Internal::Object::SetDefaultProperty()
236 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
239 * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
241 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
244 * @copydoc Dali::Internal::Object::GetDefaultProperty()
246 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
249 * @copydoc Dali::Internal::Object::GetPropertyOwner()
251 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
254 * @copydoc Dali::Internal::Object::GetSceneObject()
256 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
259 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
261 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
264 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
266 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
269 * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
271 virtual int GetPropertyComponentIndex( Property::Index index ) const;
273 public: // Functions from Connectable
275 * @copydoc Dali::Internal::Connectable::OnStage()
277 virtual bool OnStage() const;
280 * @copydoc Dali::Internal::Connectable::Connect()
282 virtual void Connect();
285 * @copydoc Dali::Internal::Connectable::Disconnect()
287 virtual void Disconnect();
289 private: // implementation
296 * A reference counted object may only be deleted by calling Unreference()
300 private: // unimplemented methods
301 Renderer( const Renderer& );
302 Renderer& operator=( const Renderer& );
305 SceneGraph::Renderer* mSceneObject;
306 Vector4* mBlendColor; ///< Local copy of blend color, pointer only as its rarely used
307 GeometryPtr mGeometry; ///< Connector that holds the geometry used by this renderer
308 ObjectConnector<TextureSet> mTextureSetConnector; ///< Connector that holds the texture set used by this renderer
309 IntrusivePtr<Shader> mShader; ///< Connector that holds the shader used by this renderer
314 size_t mIndexedDrawFirstElement; ///< Offset of first element to draw from bound index buffer
315 size_t mIndexedDrawElementCount; ///< Number of elements to draw
317 Dali::FaceCullingMode::Type mFaceCullingMode; ///< Local copy of face culling mode
318 BlendMode::Type mBlendMode; ///< Local copy of blending mode
319 BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
320 Dali::DepthWriteMode::Type mDepthWriteMode; ///< Local copy of depth write mode
321 Dali::DepthFunction::Type mDepthFunction; ///< Local copy of depth function
323 bool mPremultipledAlphaEnabled : 1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
326 } // namespace Internal
328 // Helpers for public-api forwarding methods
329 inline Internal::Renderer& GetImplementation( Dali::Renderer& handle )
331 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
333 BaseObject& object = handle.GetBaseObject();
335 return static_cast<Internal::Renderer&>(object);
338 inline const Internal::Renderer& GetImplementation( const Dali::Renderer& handle )
340 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
342 const BaseObject& object = handle.GetBaseObject();
344 return static_cast<const Internal::Renderer&>(object);
349 #endif // DALI_INTERNAL_RENDERER_H