X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Frenderers%2Frender-renderer.h;h=9157d725feea671ac6875b78ca8c5ed9ba861388;hb=0b21b1cdb38fd603e92722185ba9bfc180741f21;hp=6aa3d0782c79617851340665e3cff0857e80e8f0;hpb=e08344153585f4f6e0623bdf7b16b469d26bcbb3;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/renderers/render-renderer.h b/dali/internal/render/renderers/render-renderer.h old mode 100644 new mode 100755 index 6aa3d07..9157d72 --- a/dali/internal/render/renderers/render-renderer.h +++ b/dali/internal/render/renderers/render-renderer.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_RENDER_RENDERER_H__ -#define __DALI_INTERNAL_RENDER_RENDERER_H__ +#ifndef DALI_INTERNAL_RENDER_RENDERER_H +#define DALI_INTERNAL_RENDER_RENDERER_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,13 +21,16 @@ // INTERNAL INCLUDES #include #include +#include #include #include -#include +#include +#include +#include #include +#include +#include #include -#include -#include namespace Dali { @@ -42,15 +45,11 @@ namespace SceneGraph { class SceneController; class Shader; -class TextureCache; class NodeDataProvider; } - namespace Render { -class UniformNameCache; -class NewRenderer; /** * Renderers are used to render meshes @@ -62,65 +61,307 @@ class Renderer : public GlResourceOwner public: /** - * Second-phase construction. - * This is called when the renderer is inside render thread - * @param[in] context to use - * @param[in] textureCache to use - * @param[in] uniformNameCache to use + * @brief Struct to encapsulate stencil parameters required for control of the stencil buffer. + */ + struct StencilParameters + { + StencilParameters( RenderMode::Type renderMode, StencilFunction::Type stencilFunction, int stencilFunctionMask, + int stencilFunctionReference, int stencilMask, StencilOperation::Type stencilOperationOnFail, + StencilOperation::Type stencilOperationOnZFail, StencilOperation::Type stencilOperationOnZPass ) + : stencilFunctionMask ( stencilFunctionMask ), + stencilFunctionReference ( stencilFunctionReference ), + stencilMask ( stencilMask ), + renderMode ( renderMode ), + stencilFunction ( stencilFunction ), + stencilOperationOnFail ( stencilOperationOnFail ), + stencilOperationOnZFail ( stencilOperationOnZFail ), + stencilOperationOnZPass ( stencilOperationOnZPass ) + { + } + + int stencilFunctionMask; ///< The stencil function mask + int stencilFunctionReference; ///< The stencil function reference + int stencilMask; ///< The stencil mask + RenderMode::Type renderMode:4; ///< The render mode + StencilFunction::Type stencilFunction:4; ///< The stencil function + StencilOperation::Type stencilOperationOnFail:4; ///< The stencil operation for stencil test fail + StencilOperation::Type stencilOperationOnZFail:4; ///< The stencil operation for depth test fail + StencilOperation::Type stencilOperationOnZPass:4; ///< The stencil operation for depth test pass + }; + + /** + * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed() + */ + void GlContextDestroyed(); + + /** + * @copydoc Dali::Internal::GlResourceOwner::GlCleanup() + */ + void GlCleanup(); + + /** + * Create a new renderer instance + * @param[in] dataProviders The data providers for the renderer + * @param[in] geometry The geometry for the renderer + * @param[in] blendingBitmask A bitmask of blending options. + * @param[in] blendColor The blend color to pass to GL + * @param[in] faceCullingMode The face-culling mode. + * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied. + * @param[in] depthWriteMode Depth buffer write mode + * @param[in] depthTestMode Depth buffer test mode + * @param[in] depthFunction Depth function + * @param[in] stencilParameters Struct containing all stencil related options + */ + static Renderer* New( SceneGraph::RenderDataProvider* dataProviders, + Render::Geometry* geometry, + uint32_t blendingBitmask, + const Vector4& blendColor, + FaceCullingMode::Type faceCullingMode, + bool preMultipliedAlphaEnabled, + DepthWriteMode::Type depthWriteMode, + DepthTestMode::Type depthTestMode, + DepthFunction::Type depthFunction, + StencilParameters& stencilParameters ); + + /** + * Constructor. + * @param[in] dataProviders The data providers for the renderer + * @param[in] geometry The geometry for the renderer + * @param[in] blendingBitmask A bitmask of blending options. + * @param[in] blendColor The blend color to pass to GL + * @param[in] faceCullingMode The face-culling mode. + * @param[in] preMultipliedAlphaEnabled whether alpha is pre-multiplied. + * @param[in] depthWriteMode Depth buffer write mode + * @param[in] depthTestMode Depth buffer test mode + * @param[in] depthFunction Depth function + * @param[in] stencilParameters Struct containing all stencil related options + */ + Renderer( SceneGraph::RenderDataProvider* dataProviders, + Render::Geometry* geometry, + uint32_t blendingBitmask, + const Vector4& blendColor, + FaceCullingMode::Type faceCullingMode, + bool preMultipliedAlphaEnabled, + DepthWriteMode::Type depthWriteMode, + DepthTestMode::Type depthTestMode, + DepthFunction::Type depthFunction, + StencilParameters& stencilParameters ); + + /** + * Change the geometry used by the renderer + * @param[in] geometry The new geometry */ - void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache ); + void SetGeometry( Render::Geometry* geometry ); /** - * Virtual destructor + * Second-phase construction. + * This is called when the renderer is inside render thread + * @param[in] context Context used by the renderer */ - virtual ~Renderer(); + void Initialize( Context& context ); /** - * Set the Shader used to render. - * @param[in] shader The shader used to render. + * Destructor */ - void SetShader( SceneGraph::Shader* shader ); + ~Renderer(); /** * Set the face-culling mode. * @param[in] mode The face-culling mode. */ - void SetCullFace( CullFaceMode mode ); + void SetFaceCullingMode( FaceCullingMode::Type mode ); + + /** + * Set the bitmask for blending options + * @param[in] bitmask A bitmask of blending options. + */ + void SetBlendingBitMask( uint32_t bitmask ); + + /** + * Set the blend color for blending options + * @param[in] blendColor The blend color to pass to GL + */ + void SetBlendColor( const Vector4& color ); + + /** + * Set the first element index to draw by the indexed draw + * @param[in] firstElement index of first element to draw + */ + void SetIndexedDrawFirstElement( uint32_t firstElement ); + + /** + * Set the number of elements to draw by the indexed draw + * @param[in] elementsCount number of elements to draw + */ + void SetIndexedDrawElementsCount( uint32_t elementsCount ); + + /** + * @brief Set whether the Pre-multiplied Alpha Blending is required + * + * @param[in] preMultipled whether alpha is pre-multiplied. + */ + void EnablePreMultipliedAlpha( bool preMultipled ); + + /** + * Sets the depth write mode + * @param[in] depthWriteMode The depth write mode + */ + void SetDepthWriteMode( DepthWriteMode::Type depthWriteMode ); + + /** + * Query the Renderer's depth write mode + * @return The renderer depth write mode + */ + DepthWriteMode::Type GetDepthWriteMode() const; + + /** + * Sets the depth test mode + * @param[in] depthTestMode The depth test mode + */ + void SetDepthTestMode( DepthTestMode::Type depthTestMode ); + + /** + * Query the Renderer's depth test mode + * @return The renderer depth test mode + */ + DepthTestMode::Type GetDepthTestMode() const; + + /** + * Sets the depth function + * @param[in] depthFunction The depth function + */ + void SetDepthFunction( DepthFunction::Type depthFunction ); + + /** + * Query the Renderer's depth function + * @return The renderer depth function + */ + DepthFunction::Type GetDepthFunction() const; + + /** + * Sets the render mode + * @param[in] renderMode The render mode + */ + void SetRenderMode( RenderMode::Type mode ); + + /** + * Gets the render mode + * @return The render mode + */ + RenderMode::Type GetRenderMode() const; + + /** + * Sets the stencil function + * @param[in] stencilFunction The stencil function + */ + void SetStencilFunction( StencilFunction::Type stencilFunction ); + + /** + * Gets the stencil function + * @return The stencil function + */ + StencilFunction::Type GetStencilFunction() const; + + /** + * Sets the stencil function mask + * @param[in] stencilFunctionMask The stencil function mask + */ + void SetStencilFunctionMask( int stencilFunctionMask ); + + /** + * Gets the stencil function mask + * @return The stencil function mask + */ + int GetStencilFunctionMask() const; + + /** + * Sets the stencil function reference + * @param[in] stencilFunctionReference The stencil function reference + */ + void SetStencilFunctionReference( int stencilFunctionReference ); + + /** + * Gets the stencil function reference + * @return The stencil function reference + */ + int GetStencilFunctionReference() const; + + /** + * Sets the stencil mask + * @param[in] stencilMask The stencil mask + */ + void SetStencilMask( int stencilMask ); + + /** + * Gets the stencil mask + * @return The stencil mask + */ + int GetStencilMask() const; + + /** + * Sets the stencil operation for when the stencil test fails + * @param[in] stencilOperationOnFail The stencil operation + */ + void SetStencilOperationOnFail( StencilOperation::Type stencilOperationOnFail ); + + /** + * Gets the stencil operation for when the stencil test fails + * @return The stencil operation + */ + StencilOperation::Type GetStencilOperationOnFail() const; + + /** + * Sets the stencil operation for when the depth test fails + * @param[in] stencilOperationOnZFail The stencil operation + */ + void SetStencilOperationOnZFail( StencilOperation::Type stencilOperationOnZFail ); /** - * Set the sampler used to render the set texture. - * @param[in] samplerBitfield The packed sampler options used to render. + * Gets the stencil operation for when the depth test fails + * @return The stencil operation */ - void SetSampler( unsigned int samplerBitfield ); + StencilOperation::Type GetStencilOperationOnZFail() const; /** - * Query whether the derived type of Renderer requires depth testing. - * @return True if the renderer requires depth testing. + * Sets the stencil operation for when the depth test passes + * @param[in] stencilOperationOnZPass The stencil operation */ - virtual bool RequiresDepthTest() const = 0; + void SetStencilOperationOnZPass( StencilOperation::Type stencilOperationOnZPass ); + + /** + * Gets the stencil operation for when the depth test passes + * @return The stencil operation + */ + StencilOperation::Type GetStencilOperationOnZPass() const; + + /** + * Called to upload during RenderManager::Render(). + * @param[in] context The context used for uploading + */ + void Upload( Context& context ); /** * Called to render during RenderManager::Render(). * @param[in] context The context used for rendering - * @param[in] textureCache The texture cache used to get textures * @param[in] bufferIndex The index of the previous update buffer. * @param[in] node The node using this renderer - * @param[in] defaultShader in case there is no custom shader * @param[in] modelViewMatrix The model-view matrix. * @param[in] viewMatrix The view matrix. * @param[in] projectionMatrix The projection matrix. - * @param[in] cull Whether to frustum cull this renderer + * @param[in] size Size of the render item + * @param[in] blend If true, blending is enabled + * @param[in] boundTextures The textures bound for rendering */ void Render( Context& context, - SceneGraph::TextureCache& textureCache, BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, - SceneGraph::Shader& defaultShader, + const Matrix& modelMatrix, const Matrix& modelViewMatrix, const Matrix& viewMatrix, const Matrix& projectionMatrix, - bool cull, - bool blend); + const Vector3& size, + bool blend, + Vector& boundTextures ); /** * Write the renderer's sort attributes to the passed in reference @@ -128,17 +369,12 @@ public: * @param[in] bufferIndex The current update buffer index. * @param[out] sortAttributes */ - virtual void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const; - -protected: - /** - * Protected constructor; only derived classes can be instantiated. - * @param dataprovider for rendering - */ - Renderer(); + void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes ) const; private: + struct UniformIndexMap; + // Undefined Renderer( const Renderer& ); @@ -146,61 +382,69 @@ private: Renderer& operator=( const Renderer& rhs ); /** - * @return NewRenderer or NULL if this is an old renderer + * Sets blending options + * @param context to use + * @param blend Wheter blending should be enabled or not */ - virtual NewRenderer* GetNewRenderer() - { - return NULL; - } + void SetBlending( Context& context, bool blend ); /** - * Checks if renderer's resources are ready to be used. - * - * @return \e true if they are. Otherwise \e false. + * Set the uniforms from properties according to the uniform map + * @param[in] bufferIndex The index of the previous update buffer. + * @param[in] node The node using the renderer + * @param[in] size The size of the renderer + * @param[in] program The shader program on which to set the uniforms. */ - virtual bool CheckResources() = 0; + void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program ); /** - * Called from Render prior to DoRender(). - * @todo MESH_REWORK Remove after merge + * Set the program uniform in the map from the mapped property + * @param[in] bufferIndex The index of the previous update buffer. + * @param[in] program The shader program + * @param[in] map The uniform */ - virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program ); + void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map ); /** - * Called from Render prior to DoRender(). Default method to set CullFaceMode - * @param context to use - * @param bufferIndex to use + * Bind the textures and setup the samplers + * @param[in] context The GL context + * @param[in] program The shader program + * @param[in] boundTextures The textures bound for rendering + * @return False if create or bind failed, true if success. */ - virtual void DoSetCullFaceMode( Context& context, BufferIndex bufferIndex ); + bool BindTextures( Context& context, Program& program, Vector& boundTextures ); - /** - * Called from Render prior to DoRender(). Default method to set blending options - * @param context to use - */ - virtual void DoSetBlending( Context& context ) = 0; +private: - /** - * Called from Render; implemented in derived classes. - * @param[in] context The context used for rendering - * @param[in] textureCache The texture cache used to get textures - * @param[in] bufferIndex The index of the previous update buffer. - * @param[in] program to use. - * @param[in] modelViewMatrix The model-view matrix. - * @param[in] viewMatrix The view matrix. - */ - virtual void DoRender( Context& context, SceneGraph::TextureCache& textureCache, const SceneGraph::NodeDataProvider& node, BufferIndex bufferIndex, Program& program, const Matrix& modelViewMatrix, const Matrix& viewMatrix ) = 0; + OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider; -protected: + Context* mContext; + Render::Geometry* mGeometry; - Context* mContext; - SceneGraph::TextureCache* mTextureCache; - Render::UniformNameCache* mUniformNameCache; - SceneGraph::Shader* mShader; - unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering + struct UniformIndexMap + { + uint32_t uniformIndex; ///< The index of the cached location in the Program + const PropertyInputImpl* propertyValue; + }; -private: + typedef Dali::Vector< UniformIndexMap > UniformIndexMappings; + + UniformIndexMappings mUniformIndexMap; + Vector mAttributesLocation; + + StencilParameters mStencilParameters; ///< Struct containing all stencil related options + BlendingOptions mBlendingOptions; ///< Blending options including blend color, blend func and blend equation + + uint32_t mIndexedDrawFirstElement; ///< Offset of first element to draw + uint32_t mIndexedDrawElementsCount; ///< Number of elements to draw + + DepthFunction::Type mDepthFunction:4; ///< The depth function + FaceCullingMode::Type mFaceCullingMode:3; ///< The mode of face culling + DepthWriteMode::Type mDepthWriteMode:3; ///< The depth write mode + DepthTestMode::Type mDepthTestMode:3; ///< The depth test mode + bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed + bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required - CullFaceMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough }; } // namespace SceneGraph @@ -209,4 +453,4 @@ private: } // namespace Dali -#endif // __DALI_INTERNAL_RENDER_RENDERER_H__ +#endif // DALI_INTERNAL_RENDER_RENDERER_H