// INTERNAL INCLUDES
#include <dali/internal/common/image-sampler.h>
#include <dali/internal/render/gl-resources/context.h>
+#include <dali/internal/render/renderers/render-sampler.h>
#include <dali/internal/render/shaders/scene-graph-shader.h>
#include <dali/internal/render/shaders/program.h>
#include <dali/internal/render/data-providers/node-data-provider.h>
#include <dali/internal/render/data-providers/uniform-name-cache.h>
-#include <dali/internal/render/gl-resources/texture.h>
#include <dali/internal/render/gl-resources/texture-cache.h>
#include <dali/public-api/actors/blending.h>
+#include <dali/internal/render/gl-resources/gl-texture.h>
namespace Dali
{
{
Renderer* Renderer::New( SceneGraph::RenderDataProvider* dataProvider,
- SceneGraph::RenderGeometry* renderGeometry )
+ Render::Geometry* geometry,
+ unsigned int blendingBitmask,
+ const Vector4* blendColor,
+ FaceCullingMode::Type faceCullingMode,
+ bool preMultipliedAlphaEnabled,
+ DepthWriteMode::Type depthWriteMode,
+ DepthTestMode::Type depthTestMode,
+ DepthFunction::Type depthFunction )
{
- return new Renderer( dataProvider, renderGeometry);
+ return new Renderer( dataProvider, geometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, depthFunction );
}
Renderer::Renderer( SceneGraph::RenderDataProvider* dataProvider,
- SceneGraph::RenderGeometry* renderGeometry )
+ Render::Geometry* geometry,
+ unsigned int blendingBitmask,
+ const Vector4* blendColor,
+ FaceCullingMode::Type faceCullingMode,
+ bool preMultipliedAlphaEnabled,
+ DepthWriteMode::Type depthWriteMode,
+ DepthTestMode::Type depthTestMode,
+ DepthFunction::Type depthFunction )
: mRenderDataProvider( dataProvider ),
mContext(NULL),
mTextureCache( NULL ),
mUniformNameCache( NULL ),
- mRenderGeometry( renderGeometry ),
+ mGeometry( geometry ),
mUniformIndexMap(),
mAttributesLocation(),
- mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ),
+ mBlendingOptions(),
+ mFaceCullingMode( faceCullingMode ),
+ mDepthFunction( depthFunction ),
+ mIndexedDrawFirstElement( 0 ),
+ mIndexedDrawElementsCount( 0 ),
+ mDepthWriteMode( depthWriteMode ),
+ mDepthTestMode( depthTestMode ),
mUpdateAttributesLocation( true ),
- mCullFaceMode( Dali::Material::NONE )
+ mPremultipledAlphaEnabled( preMultipliedAlphaEnabled )
{
+ if( blendingBitmask != 0u )
+ {
+ mBlendingOptions.SetBitmask( blendingBitmask );
+ }
+
+ if( blendColor )
+ {
+ mBlendingOptions.SetBlendColor( *blendColor );
+ }
}
void Renderer::Initialize( Context& context, SceneGraph::TextureCache& textureCache, Render::UniformNameCache& uniformNameCache )
mUpdateAttributesLocation = true;
}
-void Renderer::SetGeometry( SceneGraph::RenderGeometry* renderGeometry )
+void Renderer::SetGeometry( Render::Geometry* geometry )
{
- mRenderGeometry = renderGeometry;
+ mGeometry = geometry;
mUpdateAttributesLocation = true;
}
-// Note - this is currently called from UpdateThread, PrepareRenderInstructions,
-// as an optimisation.
-// @todo MESH_REWORK Should use Update thread objects only in PrepareRenderInstructions.
-bool Renderer::RequiresDepthTest() const
-{
- return mRenderGeometry->RequiresDepthTest();
-}
-
void Renderer::SetBlending( Context& context, bool blend )
{
context.SetBlend( blend );
if( blend )
{
- const SceneGraph::MaterialDataProvider& material = mRenderDataProvider->GetMaterial();
-
// Blend color is optional and rarely used
- Vector4* blendColor = material.GetBlendColor();
+ const Vector4* blendColor = mBlendingOptions.GetBlendColor();
if( blendColor )
{
context.SetCustomBlendColor( *blendColor );
context.SetDefaultBlendColor();
}
- const BlendingOptions& blending = material.GetBlendingOptions();
// Set blend source & destination factors
- context.BlendFuncSeparate( blending.GetBlendSrcFactorRgb(),
- blending.GetBlendDestFactorRgb(),
- blending.GetBlendSrcFactorAlpha(),
- blending.GetBlendDestFactorAlpha() );
+ context.BlendFuncSeparate( mBlendingOptions.GetBlendSrcFactorRgb(),
+ mBlendingOptions.GetBlendDestFactorRgb(),
+ mBlendingOptions.GetBlendSrcFactorAlpha(),
+ mBlendingOptions.GetBlendDestFactorAlpha() );
// Set blend equations
- context.BlendEquationSeparate( blending.GetBlendEquationRgb(),
- blending.GetBlendEquationAlpha() );
+ context.BlendEquationSeparate( mBlendingOptions.GetBlendEquationRgb(),
+ mBlendingOptions.GetBlendEquationAlpha() );
}
}
void Renderer::GlContextDestroyed()
{
- mRenderGeometry->GlContextDestroyed();
+ mGeometry->GlContextDestroyed();
}
void Renderer::GlCleanup()
{
}
-void Renderer::SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, Program& program )
+void Renderer::SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataProvider& node, const Vector3& size, Program& program )
{
// Check if the map has changed
DALI_ASSERT_DEBUG( mRenderDataProvider && "No Uniform map data provider available" );
GLint sizeLoc = program.GetUniformLocation( Program::UNIFORM_SIZE );
if( -1 != sizeLoc )
{
- Vector3 size = node.GetRenderSize( bufferIndex );
program.SetSizeUniform3f( sizeLoc, size.x, size.y, size.z );
}
}
}
}
-void Renderer::BindTextures( SceneGraph::TextureCache& textureCache, Program& program )
+bool Renderer::BindTextures( Context& context, SceneGraph::TextureCache& textureCache, Program& program )
{
- int textureUnit = 0;
+ unsigned int textureUnit = 0;
+ bool result = true;
+
+ std::vector<Render::Sampler*>& samplers( mRenderDataProvider->GetSamplers() );
std::vector<Render::Texture>& textures( mRenderDataProvider->GetTextures() );
- for( size_t i(0); i<textures.size(); ++i )
+ GLint uniformLocation(-1);
+ for( size_t i(0); result && i<textures.size(); ++i )
{
ResourceId textureId = textures[i].GetTextureId();
Internal::Texture* texture = textureCache.GetTexture( textureId );
if( texture )
{
- textureCache.BindTexture( texture, textureId, GL_TEXTURE_2D, (TextureUnit)textureUnit );
+ result = textureCache.BindTexture( texture, textureId, GL_TEXTURE_2D, (TextureUnit)textureUnit );
- Render::Texture& textureMapping = textures[i];
- // Set sampler uniform location for the texture
- int32_t uniqueIndex = textureMapping.GetUniformUniqueIndex();
- if( Render::Texture::NOT_INITIALIZED == uniqueIndex )
+ if( result )
{
- uniqueIndex = mUniformNameCache->GetSamplerUniformUniqueIndex( textureMapping.GetUniformName() );
- textureMapping.SetUniformUniqueIndex( uniqueIndex );
+ GLint uniformLocation;
+
+ //TODO : This is a bug, result variable is being shadowed. Fix it!
+ bool result = program.GetSamplerUniformLocation( i, uniformLocation );
+ if( result && Program::UNIFORM_UNKNOWN != uniformLocation )
+ {
+ program.SetUniform1i( uniformLocation, textureUnit );
+
+ unsigned int samplerBitfield(ImageSampler::DEFAULT_BITFIELD);
+ const Render::Sampler* sampler( samplers[i] );
+ if( sampler )
+ {
+ samplerBitfield = sampler->mBitfield;
+ }
+
+ texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
+
+ ++textureUnit;
+ }
}
- GLint uniformLocation = program.GetSamplerUniformLocation( uniqueIndex, textureMapping.GetUniformName() );
- if( Program::UNIFORM_UNKNOWN != uniformLocation )
+ }
+ }
+
+ std::vector<Render::NewTexture*>& newTextures( mRenderDataProvider->GetNewTextures() );
+ for( size_t i(0); result && i<newTextures.size(); ++i )
+ {
+ if( newTextures[i] )
+ {
+ result = program.GetSamplerUniformLocation( i, uniformLocation ) &&
+ newTextures[i]->Bind(context, textureUnit, samplers[i] );
+
+ if( result )
{
program.SetUniform1i( uniformLocation, textureUnit );
+ ++textureUnit;
}
+ }
+ }
- unsigned int samplerBitfield(0);
- const Render::Sampler* sampler( textureMapping.GetSampler() );
- if( sampler )
- {
- samplerBitfield = ImageSampler::PackBitfield(
- static_cast< FilterMode::Type >(sampler->GetMinifyFilterMode()),
- static_cast< FilterMode::Type >(sampler->GetMagnifyFilterMode()),
- static_cast< WrapMode::Type >(sampler->GetUWrapMode()),
- static_cast< WrapMode::Type >(sampler->GetVWrapMode())
- );
- }
- else
- {
- samplerBitfield = ImageSampler::DEFAULT_BITFIELD;
- }
+ return result;
+}
- texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield );
+void Renderer::SetFaceCullingMode( FaceCullingMode::Type mode )
+{
+ mFaceCullingMode = mode;
+}
- ++textureUnit;
- }
- }
+void Renderer::SetBlendingBitMask( unsigned int bitmask )
+{
+ mBlendingOptions.SetBitmask( bitmask );
+}
+
+void Renderer::SetBlendColor( const Vector4* color )
+{
+ mBlendingOptions.SetBlendColor( *color );
}
-void Renderer::SetCullFace( Dali::Material::FaceCullingMode mode )
+void Renderer::SetIndexedDrawFirstElement( size_t firstElement )
{
- DALI_ASSERT_DEBUG( mode >= Dali::Material::NONE && mode <= Dali::Material::CULL_BACK_AND_FRONT );
- mCullFaceMode = mode;
+ mIndexedDrawFirstElement = firstElement;
}
-void Renderer::SetSampler( unsigned int samplerBitfield )
+void Renderer::SetIndexedDrawElementsCount( size_t elementsCount )
{
- mSamplerBitfield = samplerBitfield;
+ mIndexedDrawElementsCount = elementsCount;
+}
+
+void Renderer::EnablePreMultipliedAlpha( bool enable )
+{
+ mPremultipledAlphaEnabled = enable;
+}
+
+void Renderer::SetDepthWriteMode( DepthWriteMode::Type depthWriteMode )
+{
+ mDepthWriteMode = depthWriteMode;
+}
+
+void Renderer::SetDepthTestMode( DepthTestMode::Type depthTestMode )
+{
+ mDepthTestMode = depthTestMode;
+}
+
+DepthWriteMode::Type Renderer::GetDepthWriteMode() const
+{
+ return mDepthWriteMode;
+}
+
+DepthTestMode::Type Renderer::GetDepthTestMode() const
+{
+ return mDepthTestMode;
+}
+
+void Renderer::SetDepthFunction( DepthFunction::Type depthFunction )
+{
+ mDepthFunction = depthFunction;
+}
+
+DepthFunction::Type Renderer::GetDepthFunction() const
+{
+ return mDepthFunction;
}
void Renderer::Render( Context& context,
BufferIndex bufferIndex,
const SceneGraph::NodeDataProvider& node,
SceneGraph::Shader& defaultShader,
+ const Matrix& modelMatrix,
const Matrix& modelViewMatrix,
const Matrix& viewMatrix,
const Matrix& projectionMatrix,
- bool cull,
+ const Vector3& size,
bool blend )
{
// Get the program to use:
}
//Set cull face mode
- context.CullFace( mRenderDataProvider->GetMaterial().GetFaceCullingMode() );
+ context.CullFace( mFaceCullingMode );
//Set blending mode
SetBlending( context, blend );
// Take the program into use so we can send uniforms to it
program->Use();
- // set projection and view matrix if program has not yet received them yet this frame
- SetMatrices( *program, node.GetModelMatrix( bufferIndex ), viewMatrix, projectionMatrix, modelViewMatrix );
-
- // set color uniform
- GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR );
- if( Program::UNIFORM_UNKNOWN != loc )
+ if( DALI_LIKELY( BindTextures( context, textureCache, *program ) ) )
{
- const Vector4& color = node.GetRenderColor( bufferIndex );
- program->SetUniform4f( loc, color.r, color.g, color.b, color.a );
- }
+ // Only set up and draw if we have textures and they are all valid
+
+ // set projection and view matrix if program has not yet received them yet this frame
+ SetMatrices( *program, modelMatrix, viewMatrix, projectionMatrix, modelViewMatrix );
+
+ // set color uniform
+ GLint loc = program->GetUniformLocation( Program::UNIFORM_COLOR );
+ if( Program::UNIFORM_UNKNOWN != loc )
+ {
+ const Vector4& color = node.GetRenderColor( bufferIndex );
+ if( mPremultipledAlphaEnabled )
+ {
+ program->SetUniform4f( loc, color.r*color.a, color.g*color.a, color.b*color.a, color.a );
+ }
+ else
+ {
+ program->SetUniform4f( loc, color.r, color.g, color.b, color.a );
+ }
+ }
- //Bind textures
- BindTextures( textureCache, *program );
+ SetUniforms( bufferIndex, node, size, *program );
- //Set uniforms
- SetUniforms( bufferIndex, node, *program );
+ if( mUpdateAttributesLocation || mGeometry->AttributesChanged() )
+ {
+ mGeometry->GetAttributeLocationFromProgram( mAttributesLocation, *program, bufferIndex );
+ mUpdateAttributesLocation = false;
+ }
- if( mUpdateAttributesLocation || mRenderGeometry->AttributesChanged() )
- {
- mRenderGeometry->GetAttributeLocationFromProgram( mAttributesLocation, *program, bufferIndex );
- mUpdateAttributesLocation = false;
+ mGeometry->UploadAndDraw( context, bufferIndex, mAttributesLocation, mIndexedDrawFirstElement, mIndexedDrawElementsCount );
}
-
- mRenderGeometry->UploadAndDraw( context, bufferIndex, mAttributesLocation );
}
void Renderer::SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererWithSortAttributes& sortAttributes ) const
sortAttributes.textureResourceId = Integration::InvalidResourceId;
}
- sortAttributes.geometry = mRenderGeometry;
+ sortAttributes.geometry = mGeometry;
}
} // namespace SceneGraph