// INTERNAL INCLUDES
#include <dali/public-api/math/matrix.h>
#include <dali/public-api/math/vector4.h>
+#include <dali/devel-api/rendering/texture-set.h>
#include <dali/internal/common/blending-options.h>
#include <dali/internal/common/message.h>
+#include <dali/internal/event/common/property-input-impl.h>
#include <dali/internal/event/effects/shader-declarations.h>
#include <dali/internal/render/gl-resources/gl-resource-owner.h>
#include <dali/integration-api/debug.h>
#include <dali/internal/common/type-abstraction-enums.h>
#include <dali/internal/update/manager/prepare-render-instructions.h>
+#include <dali/internal/render/data-providers/render-data-provider.h>
+#include <dali/internal/render/renderers/render-geometry.h>
namespace Dali
{
namespace Render
{
class UniformNameCache;
-class NewRenderer;
/**
* Renderers are used to render meshes
public:
/**
+ * @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
+ */
+ static Renderer* New( SceneGraph::RenderDataProvider* dataProviders,
+ Render::Geometry* geometry,
+ unsigned int blendingBitmask,
+ const Vector4* blendColor,
+ Dali::Renderer::FaceCullingMode faceCullingMode,
+ bool preMultipliedAlphaEnabled,
+ Dali::Renderer::DepthWriteMode depthWriteMode );
+
+ /**
+ * 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
+ */
+ Renderer( SceneGraph::RenderDataProvider* dataProviders,
+ Render::Geometry* geometry,
+ unsigned int blendingBitmask,
+ const Vector4* blendColor,
+ Dali::Renderer::FaceCullingMode faceCullingMode,
+ bool preMultipliedAlphaEnabled,
+ Dali::Renderer::DepthWriteMode depthWriteMode );
+
+ /**
+ * Change the data providers of the renderer
+ * @param[in] dataProviders The data providers
+ */
+ void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
+
+ /**
+ * Change the geometry used by the renderer
+ * @param[in] geometry The new geometry
+ */
+ void SetGeometry( Render::Geometry* geometry );
+ /**
* Second-phase construction.
* This is called when the renderer is inside render thread
* @param[in] context to use
void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
/**
- * Virtual destructor
+ * Destructor
*/
- virtual ~Renderer();
+ ~Renderer();
/**
- * Set the Shader used to render.
- * @param[in] shader The shader used to render.
+ * Set the face-culling mode.
+ * @param[in] mode The face-culling mode.
*/
- void SetShader( SceneGraph::Shader* shader );
+ void SetFaceCullingMode( Dali::Renderer::FaceCullingMode mode );
/**
- * Set the face-culling mode.
- * @param[in] mode The face-culling mode.
+ * Set the bitmask for blending options
+ * @param[in] bitmask A bitmask of blending options.
*/
- void SetCullFace( CullFaceMode mode );
+ void SetBlendingBitMask( unsigned int bitmask );
/**
- * Set the sampler used to render the set texture.
- * @param[in] samplerBitfield The packed sampler options used to render.
+ * Set the blend color for blending options
+ * @param[in] blendColor The blend color to pass to GL
*/
- void SetSampler( unsigned int samplerBitfield );
+ void SetBlendColor( const Vector4* color );
/**
- * Query whether the derived type of Renderer requires depth testing.
- * @return True if the renderer requires depth testing.
+ * Set the first element index to draw by the indexed draw
+ * @param[in] firstElement index of first element to draw
*/
- virtual bool RequiresDepthTest() const = 0;
+ void SetIndexedDrawFirstElement( size_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 );
+
+ /**
+ * @brief Set whether the Pre-multiplied Alpha Blending is required
+ *
+ * @param[in] preMultipled whether alpha is pre-multiplied.
+ */
+ void EnablePreMultipliedAlpha( bool preMultipled );
+
+ /**
+ * Query the Renderer's depth write mode
+ * @return The renderer depth write mode
+ */
+ Dali::Renderer::DepthWriteMode GetDepthWriteMode() const;
+
+ /**
+ * Sets the depth write mode
+ * @param[in] depthWriteMode The depth write mode
+ */
+ void SetDepthWriteMode( Dali::Renderer::DepthWriteMode depthWriteMode );
/**
* Called to render during RenderManager::Render().
* @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
*/
void Render( Context& context,
SceneGraph::TextureCache& textureCache,
const Matrix& modelViewMatrix,
const Matrix& viewMatrix,
const Matrix& projectionMatrix,
- bool cull,
+ const Vector3& size,
bool blend);
/**
* @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::RendererWithSortAttributes& sortAttributes ) const;
private:
+ struct UniformIndexMap;
+
// Undefined
Renderer( const Renderer& );
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.
- */
- virtual bool CheckResources() = 0;
-
- /**
- * Called from Render prior to DoRender().
- * @todo MESH_REWORK Remove after merge
+ * 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 void DoSetUniforms( Context& context, BufferIndex bufferIndex, SceneGraph::Shader* shader, Program* program );
+ void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program );
/**
- * Called from Render prior to DoRender(). Default method to set CullFaceMode
- * @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 DoSetCullFaceMode( Context& context, BufferIndex bufferIndex );
+ void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
/**
- * Called from Render prior to DoRender(). Default method to set blending options
- * @todo MESH_REWORK Remove after merge
+ * Bind the textures and setup the samplers
+ * @param[in] textureCache The texture cache
+ * @param[in] program The shader program
+ * @return False if create or bind failed, true if success.
*/
- virtual void DoSetBlending( Context& context, BufferIndex bufferIndex, bool blend ) = 0;
+ bool BindTextures( SceneGraph::TextureCache& textureCache, Program& program );
- /**
- * 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;
+private:
-protected:
+ OwnerPointer< SceneGraph::RenderDataProvider > mRenderDataProvider;
Context* mContext;
SceneGraph::TextureCache* mTextureCache;
Render::UniformNameCache* mUniformNameCache;
- SceneGraph::Shader* mShader;
- unsigned int mSamplerBitfield; ///< Sampler options used for texture filtering
+ Render::Geometry* mGeometry;
-private:
+ struct UniformIndexMap
+ {
+ unsigned int uniformIndex; // The index of the cached location in the Program
+ const PropertyInputImpl* propertyValue;
+ };
+
+ typedef Dali::Vector< UniformIndexMap > UniformIndexMappings;
+ UniformIndexMappings mUniformIndexMap;
+
+ Vector<GLint> mAttributesLocation;
+
+ BlendingOptions mBlendingOptions; /// Blending options including blend color, blend func and blend equation
+ Dali::Renderer::FaceCullingMode mFaceCullingMode; /// Mode of face culling
+ Dali::Renderer::DepthWriteMode mDepthWriteMode; /// Depth write mode
+
+ size_t mIndexedDrawFirstElement; /// Offset of first element to draw
+ size_t mIndexedDrawElementsCount; /// Number of elements to draw
- CullFaceMode mCullFaceMode:3; ///< cullface enum, 3 bits is enough
+ bool mUpdateAttributesLocation:1; ///< Indicates attribute locations have changed
+ bool mPremultipledAlphaEnabled:1; ///< Flag indicating whether the Pre-multiplied Alpha Blending is required
};
} // namespace SceneGraph