X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Frenderers%2Frender-renderer.h;h=9c6b5b4595ccf56b4f27d2a3549123423f6bb03a;hb=45e368e0ac84c31187a3812afca3d73268154559;hp=997dba4655840b4bdaaad5ac0fd0ee0cfcaf1df0;hpb=7882128f66bc91dbca9573caddd312115be440c4;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 index 997dba4..6e1a1f7 100644 --- a/dali/internal/render/renderers/render-renderer.h +++ b/dali/internal/render/renderers/render-renderer.h @@ -1,8 +1,8 @@ -#ifndef __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__ -#define __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__ +#ifndef DALI_INTERNAL_RENDER_RENDERER_H +#define DALI_INTERNAL_RENDER_RENDERER_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2018 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. @@ -18,207 +18,430 @@ * */ -#include // For resource id -#include +// INTERNAL INCLUDES +#include +#include +#include +#include +#include +#include +#include #include -#include -#include +#include #include +#include +#include namespace Dali { + namespace Internal { -class PropertyInputImpl; +class Context; +class Texture; +class Program; namespace SceneGraph { +class SceneController; +class Shader; +class NodeDataProvider; +} + +namespace Render +{ /** - * The new geometry renderer. - * - * @todo MESH_REWORK It will be merged into the base class eventually + * Renderers are used to render meshes + * These objects are used during RenderManager::Render(), so properties modified during + * the Update must either be double-buffered, or set via a message added to the RenderQueue. */ -class NewRenderer : public Renderer +class Renderer : public GlResourceOwner { public: - typedef Integration::ResourceId ResourceId; -public: + /** + * @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:3; ///< The render mode + StencilFunction::Type stencilFunction:3; ///< The stencil function + StencilOperation::Type stencilOperationOnFail:3; ///< The stencil operation for stencil test fail + StencilOperation::Type stencilOperationOnZFail:3; ///< The stencil operation for depth test fail + StencilOperation::Type stencilOperationOnZPass:3; ///< 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] nodeDataProvider The node data provider * @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 NewRenderer* New( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders ); + static Renderer* New( SceneGraph::RenderDataProvider* dataProviders, + Render::Geometry* geometry, + unsigned int blendingBitmask, + const Vector4& blendColor, + FaceCullingMode::Type faceCullingMode, + bool preMultipliedAlphaEnabled, + DepthWriteMode::Type depthWriteMode, + DepthTestMode::Type depthTestMode, + DepthFunction::Type depthFunction, + StencilParameters& stencilParameters ); + /** * Constructor. - * @param[in] nodeDataProvider The node data provider * @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 */ - NewRenderer( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders ); + Renderer( SceneGraph::RenderDataProvider* dataProviders, + Render::Geometry* geometry, + unsigned int blendingBitmask, + const Vector4& blendColor, + FaceCullingMode::Type faceCullingMode, + bool preMultipliedAlphaEnabled, + DepthWriteMode::Type depthWriteMode, + DepthTestMode::Type depthTestMode, + DepthFunction::Type depthFunction, + StencilParameters& stencilParameters ); - virtual ~NewRenderer(); + /** + * Change the geometry used by the renderer + * @param[in] geometry The new geometry + */ + void SetGeometry( Render::Geometry* geometry ); /** - * Change the data providers of the renderer - * @param[in] dataProviders The data providers + * Second-phase construction. + * This is called when the renderer is inside render thread + * @param[in] context Context used by the renderer */ - void SetRenderDataProvider( RenderDataProvider* dataProviders ); + void Initialize( Context& context ); /** - * Set flag that says that Geometry has been updated. + * Destructor */ - void SetGeometryUpdated(); + ~Renderer(); -public: // Implementation of Renderer /** - * @copydoc SceneGraph::Renderer::RequiresDepthTest() + * Set the face-culling mode. + * @param[in] mode The face-culling mode. */ - virtual bool RequiresDepthTest() const; + void SetFaceCullingMode( FaceCullingMode::Type mode ); /** - * @copydoc SceneGraph::Renderer::CheckResources() + * Set the bitmask for blending options + * @param[in] bitmask A bitmask of blending options. */ - virtual bool CheckResources(); + void SetBlendingBitMask( unsigned int bitmask ); /** - * @copydoc SceneGraph::Renderer::IsOutsideClipSpace() + * Set the blend color for blending options + * @param[in] blendColor The blend color to pass to GL */ - virtual bool IsOutsideClipSpace( Context& context, - const Matrix& modelMatrix, - const Matrix& modelViewProjectionMatrix ); + void SetBlendColor( const Vector4& color ); /** - * @copydoc SceneGraph::Renderer::DoSetUniforms() + * Set the first element index to draw by the indexed draw + * @param[in] firstElement index of first element to draw */ - virtual void DoSetUniforms( Context& context, BufferIndex bufferIndex, Shader* shader, Program* program, unsigned int programIndex ); + void SetIndexedDrawFirstElement( size_t firstElement ); /** - * @copydoc SceneGraph::Renderer::DoSetCullFaceMode + * Set the number of elements to draw by the indexed draw + * @param[in] elementsCount number of elements to draw */ - virtual void DoSetCullFaceMode(Context& context, BufferIndex bufferIndex ); + void SetIndexedDrawElementsCount( size_t elementsCount ); /** - * @copydoc SceneGraph::Renderer::DoSetBlending + * @brief Set whether the Pre-multiplied Alpha Blending is required + * + * @param[in] preMultipled whether alpha is pre-multiplied. */ - virtual void DoSetBlending(Context& context, BufferIndex bufferIndex ); + void EnablePreMultipliedAlpha( bool preMultipled ); /** - * @copydoc SceneGraph::Renderer::DoRender() + * Sets the depth write mode + * @param[in] depthWriteMode The depth write mode */ - virtual void DoRender( Context& context, - TextureCache& textureCache, - BufferIndex bufferIndex, - Program& program, - const Matrix& modelViewMatrix, - const Matrix& viewMatrix ); + void SetDepthWriteMode( DepthWriteMode::Type depthWriteMode ); -public: // Implementation of GlResourceOwner + /** + * Query the Renderer's depth write mode + * @return The renderer depth write mode + */ + DepthWriteMode::Type GetDepthWriteMode() const; /** - * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed() + * Sets the depth test mode + * @param[in] depthTestMode The depth test mode */ - virtual void GlContextDestroyed(); + void SetDepthTestMode( DepthTestMode::Type depthTestMode ); /** - * @copydoc Dali::Internal::GlResourceOwner::GlCleanup() + * Query the Renderer's depth test mode + * @return The renderer depth test mode */ - virtual void GlCleanup(); + DepthTestMode::Type GetDepthTestMode() const; -private: - struct UniformIndexMap; + /** + * Sets the depth function + * @param[in] depthFunction The depth function + */ + void SetDepthFunction( DepthFunction::Type depthFunction ); /** - * Set the uniforms from properties according to the uniform map - * @param[in] program The shader program on which to set the uniforms. + * Query the Renderer's depth function + * @return The renderer depth function */ - void SetUniforms( BufferIndex bufferIndex, Program& program ); + DepthFunction::Type GetDepthFunction() const; /** - * Set the program uniform in the map from the mapped property + * Sets the render mode + * @param[in] renderMode The render mode */ - void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map ); + void SetRenderMode( RenderMode::Type mode ); /** - * Bind the material textures in the samplers and setup the samplers - * @param[in] textureCache The texture cache - * @param[in] bufferIndex The buffer index - * @param[in] program The shader program - * @param[in] samplers The samplers to bind + * Gets the render mode + * @return The render mode */ - void BindTextures( TextureCache& textureCache, - BufferIndex bufferIndex, - Program& program, - const RenderDataProvider::Samplers& samplers ); + RenderMode::Type GetRenderMode() const; /** - * Bind a material texture to a texture unit, and set the sampler's texture uniform - * to that texture unit. - * @param[in] textureCache The texture cache - * @param[in] program The shader program - * @param[in] id The resource id of the texture to bind - * @param[in] texture The texture to bind - * @param[in] textureUnit The texture unit index to use - * @param[in] nameIndex The index of the texture uniform in the program + * 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 ); + + /** + * Gets the stencil operation for when the depth test fails + * @return The stencil operation + */ + StencilOperation::Type GetStencilOperationOnZFail() const; + + /** + * Sets the stencil operation for when the depth test passes + * @param[in] stencilOperationOnZPass The stencil operation + */ + 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 render during RenderManager::Render(). + * @param[in] context The context used for rendering + * @param[in] bufferIndex The index of the previous update buffer. + * @param[in] node The node using this renderer + * @param[in] modelViewMatrix The model-view matrix. + * @param[in] viewMatrix The view matrix. + * @param[in] projectionMatrix The projection matrix. + * @param[in] size Size of the render item + * @param[in] blend If true, blending is enabled + */ + void Render( Context& context, + BufferIndex bufferIndex, + const SceneGraph::NodeDataProvider& node, + const Matrix& modelMatrix, + const Matrix& modelViewMatrix, + const Matrix& viewMatrix, + const Matrix& projectionMatrix, + const Vector3& size, + bool blend ); + + /** + * Write the renderer's sort attributes to the passed in reference + * + * @param[in] bufferIndex The current update buffer index. + * @param[out] sortAttributes */ - void BindTexture( TextureCache& textureCache, - Program& program, - ResourceId id, - Texture* texture, - TextureUnit textureUnit, - unsigned int nameIndex ); + void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes ) const; + +private: + + struct UniformIndexMap; + + // Undefined + Renderer( const Renderer& ); + + // Undefined + Renderer& operator=( const Renderer& rhs ); + + /** + * Sets blending options + * @param context to use + * @param blend Wheter blending should be enabled or not + */ + void SetBlending( Context& context, bool blend ); /** - * Apply the sampler modes to the texture. - * @param[in] bufferIndex The current buffer index - * @param[in] texture The texture to which to apply the sampler modes - * @param[in] textureUnit The texture unit of the texture - * @param[in] sampler The sampler from which to get the modes. + * 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. */ - void ApplySampler( BufferIndex bufferIndex, - Texture* texture, - TextureUnit textureUnit, - const SamplerDataProvider& sampler ); + void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program ); /** - * Get the texture uniform index of the name sampler in the program. - * If not already registered in the program, then this performs the registration + * 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] sampler The sampler holding a texture unit uniform name to search for - * @return The texture uniform index in the program + * @param[in] map The uniform */ - unsigned int GetTextureUnitUniformIndex( Program& program, - const SamplerDataProvider& sampler ); + void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map ); -public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer - OwnerPointer< RenderDataProvider > mRenderDataProvider; + /** + * Bind the textures and setup the samplers + * @param[in] context The GL context + * @param[in] program The shader program + * @return False if create or bind failed, true if success. + */ + bool BindTextures( Context& context, Program& program ); private: - RenderGeometry mRenderGeometry; - struct TextureUnitUniformIndex - { - const SamplerDataProvider* sampler; - unsigned int index; - }; + OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider; - typedef Dali::Vector< TextureUnitUniformIndex > TextureUnitUniforms; - TextureUnitUniforms mTextureUnitUniforms; + Context* mContext; + Render::Geometry* mGeometry; struct UniformIndexMap { - unsigned int uniformIndex; // The index of the cached location in the Program - const PropertyInputImpl* propertyValue; + unsigned int uniformIndex; ///< The index of the cached location in the Program + const PropertyInputImpl* propertyValue; }; typedef Dali::Vector< UniformIndexMap > UniformIndexMappings; - UniformIndexMappings mUniformIndexMap; + + UniformIndexMappings mUniformIndexMap; + Vector mAttributesLocation; + + StencilParameters mStencilParameters; ///< Struct containing all stencil related options + BlendingOptions mBlendingOptions; ///< Blending options including blend color, blend func and blend equation + + size_t mIndexedDrawFirstElement; ///< Offset of first element to draw + size_t mIndexedDrawElementsCount; ///< Number of elements to draw + + DepthFunction::Type mDepthFunction:3; ///< The depth function + FaceCullingMode::Type mFaceCullingMode:2; ///< The mode of face culling + DepthWriteMode::Type mDepthWriteMode:2; ///< The depth write mode + DepthTestMode::Type mDepthTestMode:2; ///< 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 + }; +} // namespace SceneGraph + +} // namespace Internal -} // SceneGraph -} // Internal -} // Dali +} // namespace Dali -#endif // __DALI_INTERNAL_SCENE_GRAPH_NEW_RENDERER_H__ +#endif // DALI_INTERNAL_RENDER_RENDERER_H