#define DALI_INTERNAL_RENDER_RENDERER_H
/*
- * Copyright (c) 2016 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.
#include <dali/internal/common/message.h>
#include <dali/internal/common/type-abstraction-enums.h>
#include <dali/internal/event/common/property-input-impl.h>
-#include <dali/internal/event/effects/shader-declarations.h>
#include <dali/internal/render/data-providers/render-data-provider.h>
#include <dali/internal/render/gl-resources/gl-resource-owner.h>
#include <dali/internal/render/renderers/render-geometry.h>
-#include <dali/internal/update/manager/prepare-render-instructions.h>
+#include <dali/internal/update/manager/render-instruction-processor.h>
#include <dali/integration-api/debug.h>
namespace Dali
{
class SceneController;
class Shader;
-class TextureCache;
class NodeDataProvider;
-}
+class RenderInstruction; //for relfection effect
+}
namespace Render
{
-class UniformNameCache;
/**
* Renderers are used to render meshes
*/
struct StencilParameters
{
- StencilParameters( StencilMode::Type stencilMode, StencilFunction::Type stencilFunction, int stencilFunctionMask,
+ 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 ),
- stencilMode ( stencilMode )
+ stencilOperationOnZPass ( stencilOperationOnZPass )
{
}
int stencilFunctionMask; ///< The stencil function mask
int stencilFunctionReference; ///< The stencil function reference
int stencilMask; ///< The stencil mask
- 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
- StencilMode::Type stencilMode:2; ///< The stencil mode
+ 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();
+ void GlContextDestroyed() override;
/**
* @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
*/
- void GlCleanup();
+ void GlCleanup() override;
/**
* Create a new renderer instance
* @param[in] depthTestMode Depth buffer test mode
* @param[in] depthFunction Depth function
* @param[in] stencilParameters Struct containing all stencil related options
- * @param[in] writeToColorBuffer Set to True to write to the color buffer
*/
static Renderer* New( SceneGraph::RenderDataProvider* dataProviders,
Render::Geometry* geometry,
- unsigned int blendingBitmask,
- const Vector4* blendColor,
+ uint32_t blendingBitmask,
+ const Vector4& blendColor,
FaceCullingMode::Type faceCullingMode,
bool preMultipliedAlphaEnabled,
DepthWriteMode::Type depthWriteMode,
DepthTestMode::Type depthTestMode,
DepthFunction::Type depthFunction,
- StencilParameters& stencilParameters,
- bool writeToColorBuffer );
+ StencilParameters& stencilParameters );
/**
* Constructor.
* @param[in] depthTestMode Depth buffer test mode
* @param[in] depthFunction Depth function
* @param[in] stencilParameters Struct containing all stencil related options
- * @param[in] writeToColorBuffer Set to True to write to the color buffer
*/
Renderer( SceneGraph::RenderDataProvider* dataProviders,
Render::Geometry* geometry,
- unsigned int blendingBitmask,
- const Vector4* blendColor,
+ uint32_t blendingBitmask,
+ const Vector4& blendColor,
FaceCullingMode::Type faceCullingMode,
bool preMultipliedAlphaEnabled,
DepthWriteMode::Type depthWriteMode,
DepthTestMode::Type depthTestMode,
DepthFunction::Type depthFunction,
- StencilParameters& stencilParameters,
- bool writeToColorBuffer );
-
- /**
- * Change the data providers of the renderer
- * @param[in] dataProviders The data providers
- */
- void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
+ StencilParameters& stencilParameters );
/**
* Change the geometry used by the renderer
*/
void SetGeometry( Render::Geometry* geometry );
+ void SetDrawCommands( Dali::DevelRenderer::DrawCommand* pDrawCommands, uint32_t size );
+
/**
- * Retrieves the geometry used by the renderer
- * @return The geometry used by the renderer
+ * @brief Returns a reference to an array of draw commands
+ * @return Valid array of draw commands (may be empty)
*/
- Render::Geometry* GetGeometry() const
+ const std::vector<Dali::DevelRenderer::DrawCommand>& GetDrawCommands() const
{
- return mGeometry;
+ return mDrawCommands;
}
/**
* Second-phase construction.
* This is called when the renderer is inside render thread
* @param[in] context Context used by the renderer
- * @param[in] textureCache The texture cache to use
- * @param[in] uniformNameCache Cache of uniform names to use
*/
- void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
+ void Initialize( Context& context );
/**
* Destructor
*/
- ~Renderer();
+ ~Renderer() override;
/**
* Set the face-culling mode.
* Set the bitmask for blending options
* @param[in] bitmask A bitmask of blending options.
*/
- void SetBlendingBitMask( unsigned int bitmask );
+ 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 );
+ 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( size_t firstElement );
+ 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( size_t elementsCount );
+ void SetIndexedDrawElementsCount( uint32_t elementsCount );
/**
* @brief Set whether the Pre-multiplied Alpha Blending is required
DepthFunction::Type GetDepthFunction() const;
/**
- * Sets the stencil mode
- * @param[in] stencilMode The stencil function
+ * Sets the render mode
+ * @param[in] renderMode The render mode
*/
- void SetStencilMode( StencilMode::Type stencilMode );
+ void SetRenderMode( RenderMode::Type mode );
/**
- * Gets the stencil mode
- * @return The stencil function
+ * Gets the render mode
+ * @return The render mode
*/
- StencilMode::Type GetStencilMode() const;
+ RenderMode::Type GetRenderMode() const;
/**
* Sets the stencil function
StencilOperation::Type GetStencilOperationOnZPass() const;
/**
- * Sets whether or not to write to the color buffer
- * @param[in] writeToColorBuffer True to write to the color buffer
+ * Called to upload during RenderManager::Render().
+ * @param[in] context The context used for uploading
*/
- void SetWriteToColorBuffer( bool writeToColorBuffer );
-
- /**
- * Gets whether or not to write to the color buffer
- * @return True to write to the color buffer
- */
- bool GetWriteToColorBuffer() const;
-
- /**
- * Sets batching mode on the renderer
- * @param[in] batchingEnabled batching state
- */
- void SetBatchingEnabled( bool batchingEnabled );
+ 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] size Size of the render item
- * @param[in] externalGeometry Optional external geometry, if set the original geometry is ignored. If NULL, original geometry will be drawn as normal.
* @param[in] blend If true, blending is enabled
+ * @param[in] boundTextures The textures bound for rendering
+ * @param[in] instruction. for use case like reflection where CullFace needs to be adjusted
+
*/
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,
const Vector3& size,
- Render::Geometry* externalGeometry,
- bool blend);
+ bool blend,
+ Vector<GLuint>& boundTextures,
+ const Dali::Internal::SceneGraph::RenderInstruction& instruction,
+ uint32_t queueIndex );
/**
* Write the renderer's sort attributes to the passed in reference
* @param[in] bufferIndex The current update buffer index.
* @param[out] sortAttributes
*/
- void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
+ void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RenderInstructionProcessor::SortAttributes& sortAttributes ) const;
+
+ /**
+ * Sets the flag indicating whether shader changed.
+ *
+ * @param[in] value True if shader changed
+ */
+ void SetShaderChanged( bool value );
+
+ /**
+ * Check if the renderer attributes/uniforms are updated and returns the flag
+ *
+ * @param[in] bufferIndex The current update buffer index.
+ * @param[in] node The node using this renderer
+ */
+ bool Updated(BufferIndex bufferIndex, const SceneGraph::NodeDataProvider* node);
private:
/**
* Bind the textures and setup the samplers
* @param[in] context The GL context
- * @param[in] textureCache The texture cache
* @param[in] program The shader program
+ * @param[in] boundTextures The textures bound for rendering
* @return False if create or bind failed, true if success.
*/
- bool BindTextures( Context& context, SceneGraph::TextureCache& textureCache, Program& program );
+ bool BindTextures( Context& context, Program& program, Vector<GLuint>& boundTextures );
private:
OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
Context* mContext;
- SceneGraph::TextureCache* mTextureCache;
- Render::UniformNameCache* mUniformNameCache;
Render::Geometry* mGeometry;
struct UniformIndexMap
{
- unsigned int uniformIndex; ///< The index of the cached location in the Program
+ uint32_t uniformIndex; ///< The index of the cached location in the Program
const PropertyInputImpl* propertyValue;
};
- typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
+ using UniformIndexMappings = Dali::Vector<UniformIndexMap>;
+
UniformIndexMappings mUniformIndexMap;
Vector<GLint> mAttributesLocation;
+ uint64_t mUniformsHash;
+
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
+ uint32_t mIndexedDrawFirstElement; ///< Offset of first element to draw
+ uint32_t mIndexedDrawElementsCount; ///< Number of elements to draw
- DepthFunction::Type mDepthFunction:3; ///< The depth function
- FaceCullingMode::Type mFaceCullingMode:2; ///< The mode of face culling
- BlendMode::Type mBlendMode:2; ///< The mode of blending
- DepthWriteMode::Type mDepthWriteMode:2; ///< The depth write mode
- DepthTestMode::Type mDepthTestMode:2; ///< The depth test mode
- bool mWriteToColorBuffer:1; ///< True if we are writing to the color buffer
+ 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
- bool mBatchingEnabled:1; ///< Flag indicating if the renderer is batchable
+ bool mShaderChanged:1; ///< Flag indicating the shader changed and uniform maps have to be updated
+ bool mUpdated:1;
+
+
+ std::vector<Dali::DevelRenderer::DrawCommand> mDrawCommands; // Devel stuff
};
} // namespace SceneGraph