-#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.
*
*/
-#include <dali/integration-api/resource-declarations.h> // For resource id
-#include <dali/internal/common/owner-pointer.h>
+// 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/gl-resources/texture-units.h>
-#include <dali/internal/render/renderers/scene-graph-renderer.h>
#include <dali/internal/render/renderers/render-geometry.h>
namespace Dali
{
+
namespace Internal
{
-class PropertyInputImpl;
+class Context;
+class Texture;
+class Program;
namespace SceneGraph
{
+class SceneController;
+class Shader;
+class TextureCache;
+class NodeDataProvider;
+}
+
+
+namespace Render
+{
+class UniformNameCache;
/**
- * 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:
+ /**
+ * @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
*/
- static NewRenderer* New( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders );
+ 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] 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
*/
- NewRenderer( NodeDataProvider& nodeDataProvider, RenderDataProvider* dataProviders );
-
- virtual ~NewRenderer();
+ 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( RenderDataProvider* dataProviders );
+ void SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProviders );
/**
- * Set flag that says that Geometry has been updated.
+ * Change the geometry used by the renderer
+ * @param[in] geometry The new geometry
*/
- void SetGeometryUpdated();
+ void SetGeometry( Render::Geometry* geometry );
+ /**
+ * 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
+ */
+ void Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache );
-public: // Implementation of Renderer
/**
- * @copydoc SceneGraph::Renderer::RequiresDepthTest()
+ * Destructor
*/
- virtual bool RequiresDepthTest() const;
+ ~Renderer();
/**
- * @copydoc SceneGraph::Renderer::CheckResources()
+ * Set the face-culling mode.
+ * @param[in] mode The face-culling mode.
*/
- virtual bool CheckResources();
+ void SetFaceCullingMode( Dali::Renderer::FaceCullingMode mode );
/**
- * @copydoc SceneGraph::Renderer::ResolveGeometryTypes()
+ * Set the bitmask for blending options
+ * @param[in] bitmask A bitmask of blending options.
*/
- virtual void ResolveGeometryTypes( BufferIndex bufferIndex,
- GeometryType& outType,
- ShaderSubTypes& outSubType );
+ 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, ShaderSubTypes subType );
+ 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()
+ * Query the Renderer's depth write mode
+ * @return The renderer depth write mode
*/
- virtual void DoRender( Context& context,
- TextureCache& textureCache,
- BufferIndex bufferIndex,
- Program& program,
- const Matrix& modelViewMatrix,
- const Matrix& viewMatrix );
+ Dali::Renderer::DepthWriteMode GetDepthWriteMode() const;
-public: // Implementation of GlResourceOwner
+ /**
+ * Sets the depth write mode
+ * @param[in] depthWriteMode The depth write mode
+ */
+ void SetDepthWriteMode( Dali::Renderer::DepthWriteMode depthWriteMode );
/**
- * @copydoc Dali::Internal::GlResourceOwner::GlContextDestroyed()
+ * 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.
*/
- virtual void GlContextDestroyed();
+ void Render( Context& context,
+ SceneGraph::TextureCache& textureCache,
+ BufferIndex bufferIndex,
+ const SceneGraph::NodeDataProvider& node,
+ SceneGraph::Shader& defaultShader,
+ const Matrix& modelViewMatrix,
+ const Matrix& viewMatrix,
+ const Matrix& projectionMatrix,
+ const Vector3& size,
+ bool blend);
/**
- * @copydoc Dali::Internal::GlResourceOwner::GlCleanup()
+ * Write the renderer's sort attributes to the passed in reference
+ *
+ * @param[in] bufferIndex The current update buffer index.
+ * @param[out] sortAttributes
*/
- virtual void GlCleanup();
+ void SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const;
private:
+
struct UniformIndexMap;
- /**
- * Set the uniforms from properties according to the uniform map
- * @param[in] program The shader program on which to set the uniforms.
- */
- void SetUniforms( BufferIndex bufferIndex, Program& program );
+ // Undefined
+ Renderer( const Renderer& );
- /**
- * Set the program uniform in the map from the mapped property
- */
- void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
+ // Undefined
+ Renderer& operator=( const Renderer& rhs );
/**
- * 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
+ * Sets blending options
+ * @param context to use
+ * @param blend Wheter blending should be enabled or not
*/
- void BindTextures( TextureCache& textureCache,
- BufferIndex bufferIndex,
- Program& program,
- const RenderDataProvider::Samplers& samplers );
+ void SetBlending( Context& context, bool blend );
/**
- * 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
+ * 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 BindTexture( TextureCache& textureCache,
- Program& program,
- ResourceId id,
- Texture* texture,
- TextureUnit textureUnit,
- unsigned int nameIndex );
+ void SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program );
/**
- * 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 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
*/
- void ApplySampler( BufferIndex bufferIndex,
- Texture* texture,
- TextureUnit textureUnit,
- const SamplerDataProvider& sampler );
+ void SetUniformFromProperty( BufferIndex bufferIndex, Program& program, UniformIndexMap& map );
/**
- * Get the texture uniform index of the name sampler in the program.
- * If not already registered in the program, then this performs the registration
+ * Bind the textures and setup the samplers
+ * @param[in] textureCache The texture cache
* @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
+ * @return False if create or bind failed, true if success.
*/
- unsigned int GetTextureUnitUniformIndex( Program& program,
- const SamplerDataProvider& sampler );
-
-public: //@todo MESH_REWORK make private after merge with SceneGraph::Renderer
- OwnerPointer< RenderDataProvider > mRenderDataProvider;
+ bool BindTextures( SceneGraph::TextureCache& textureCache, 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;
+ SceneGraph::TextureCache* mTextureCache;
+ Render::UniformNameCache* mUniformNameCache;
+ Render::Geometry* mGeometry;
struct UniformIndexMap
{
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
+
+ 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__