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/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 Geometry* GetGeometry() const;
68 * @copydoc Dali::Renderer::SetTextures()
70 void SetTextures( TextureSet& textureSet );
73 * @copydoc Dali::Renderer::GetTextures()
75 TextureSet* GetTextures() const;
78 * @copydoc Dali::Renderer::SetShader()
80 void SetShader( Shader& shader );
83 * @copydoc Dali::Renderer::GetShader()
85 Shader* GetShader() const;
88 * @copydoc Dali::Renderer::SetDepthIndex()
90 void SetDepthIndex( int depthIndex );
93 * @copydoc Dali::Renderer::GetDepthIndex()
95 int 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::SetBlendColor()
142 void SetBlendColor( const Vector4& color );
145 * @copydoc Dali::Renderer::GetBlendColor()
147 Vector4 GetBlendColor() const;
150 * @copydoc Dali::Renderer::SetIndexedDrawFirstElement
152 void SetIndexedDrawFirstElement( size_t firstElement );
155 * @copydoc Dali::Renderer::SetIndexedDrawElementsCount
157 void SetIndexedDrawElementsCount( size_t elementsCount );
160 * @brief Set whether the Pre-multiplied Alpha Blending is required
162 * @param[in] preMultipled whether alpha is pre-multiplied.
164 void EnablePreMultipliedAlpha( bool preMultipled );
167 * @brief Query whether alpha is pre-multiplied.
169 * @return True is alpha is pre-multiplied, false otherwise.
171 bool IsPreMultipliedAlphaEnabled() const;
174 * Returns state of batching mode
175 * @return batching mode state ( true if enabled )
177 bool IsBatchingEnabled() const;
180 * @brief Get the scene graph object
182 * @return the scene object
184 SceneGraph::Renderer* GetRendererSceneObject();
186 public: // Default property extensions from Object
189 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
191 virtual unsigned int GetDefaultPropertyCount() const;
194 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
196 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
199 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
201 virtual const char* GetDefaultPropertyName(Property::Index index) const;
204 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
206 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
209 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
211 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
214 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
216 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
219 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
221 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
224 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
226 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
229 * @copydoc Dali::Internal::Object::SetDefaultProperty()
231 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
234 * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
236 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
239 * @copydoc Dali::Internal::Object::GetDefaultProperty()
241 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
244 * @copydoc Dali::Internal::Object::GetPropertyOwner()
246 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
249 * @copydoc Dali::Internal::Object::GetSceneObject()
251 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
254 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
256 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
259 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
261 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
264 * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
266 virtual int GetPropertyComponentIndex( Property::Index index ) const;
268 private: // implementation
275 * A reference counted object may only be deleted by calling Unreference()
279 private: // unimplemented methods
280 Renderer( const Renderer& );
281 Renderer& operator=( const Renderer& );
284 SceneGraph::Renderer* mSceneObject;
285 Vector4* mBlendColor; ///< Local copy of blend color, pointer only as its rarely used
286 GeometryPtr mGeometry; ///< Connector that holds the geometry used by this renderer
287 TextureSetPtr mTextureSet; ///< Connector that holds the texture set used by this renderer
288 ShaderPtr mShader; ///< Connector that holds the shader used by this renderer
292 size_t mIndexedDrawFirstElement; ///< Offset of first element to draw from bound index buffer
293 size_t mIndexedDrawElementCount; ///< Number of elements to draw
295 Render::Renderer::StencilParameters mStencilParameters; ///< Struct containing all stencil related options
296 BlendingOptions mBlendingOptions; ///< Local copy of blending options bitmask
298 DepthFunction::Type mDepthFunction:3; ///< Local copy of the depth function
299 FaceCullingMode::Type mFaceCullingMode:2; ///< Local copy of the mode of face culling
300 BlendMode::Type mBlendMode:2; ///< Local copy of the mode of blending
301 DepthWriteMode::Type mDepthWriteMode:2; ///< Local copy of the depth write mode
302 DepthTestMode::Type mDepthTestMode:2; ///< Local copy of the depth test mode
303 bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
304 bool mBatchingEnabled : 1; ///< Flag indicating whether render is batchable or not
307 } // namespace Internal
309 // Helpers for public-api forwarding methods
310 inline Internal::Renderer& GetImplementation( Dali::Renderer& handle )
312 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
314 BaseObject& object = handle.GetBaseObject();
316 return static_cast<Internal::Renderer&>(object);
319 inline const Internal::Renderer& GetImplementation( const Dali::Renderer& handle )
321 DALI_ASSERT_ALWAYS(handle && "Renderer handle is empty");
323 const BaseObject& object = handle.GetBaseObject();
325 return static_cast<const Internal::Renderer&>(object);
330 #endif // DALI_INTERNAL_RENDERER_H