X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;ds=sidebyside;f=dali%2Finternal%2Frender%2Frenderers%2Frender-renderer.cpp;h=cbad8bb8ebd4b4c362ee1424d842b5030c40b4fc;hb=2b10280985738c74efa2aa0fb956a837c69acee6;hp=07baac41d28327c9925057c07dca42a1212eed5c;hpb=468b1a9ac8e6436b7210d8e1023a37ea28dca66e;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/render/renderers/render-renderer.cpp b/dali/internal/render/renderers/render-renderer.cpp index 07baac4..cbad8bb 100644 --- a/dali/internal/render/renderers/render-renderer.cpp +++ b/dali/internal/render/renderers/render-renderer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2016 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,17 +18,17 @@ // CLASS HEADER #include - // INTERNAL INCLUDES #include #include +#include #include #include #include #include -#include #include #include +#include namespace Dali { @@ -110,24 +110,61 @@ namespace Render { 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, + StencilParameters& stencilParameters, + bool writeToColorBuffer ) { - return new Renderer( dataProvider, renderGeometry); + return new Renderer( dataProvider, geometry, blendingBitmask, blendColor, + faceCullingMode, preMultipliedAlphaEnabled, depthWriteMode, depthTestMode, + depthFunction, stencilParameters, writeToColorBuffer ); } 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, + StencilParameters& stencilParameters, + bool writeToColorBuffer ) : mRenderDataProvider( dataProvider ), - mContext(NULL), + mContext( NULL), mTextureCache( NULL ), mUniformNameCache( NULL ), - mRenderGeometry( renderGeometry ), + mGeometry( geometry ), mUniformIndexMap(), mAttributesLocation(), - mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ), + mStencilParameters( stencilParameters ), + mBlendingOptions(), + mIndexedDrawFirstElement( 0 ), + mIndexedDrawElementsCount( 0 ), + mDepthFunction( depthFunction ), + mFaceCullingMode( faceCullingMode ), + mDepthWriteMode( depthWriteMode ), + mDepthTestMode( depthTestMode ), + mWriteToColorBuffer( writeToColorBuffer ), 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 ) @@ -147,29 +184,19 @@ void Renderer::SetRenderDataProvider( SceneGraph::RenderDataProvider* dataProvid 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 ); @@ -179,29 +206,28 @@ void Renderer::SetBlending( Context& context, bool blend ) 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" ); @@ -262,7 +288,6 @@ void Renderer::SetUniforms( BufferIndex bufferIndex, const SceneGraph::NodeDataP GLint sizeLoc = program.GetUniformLocation( Program::UNIFORM_SIZE ); if( -1 != sizeLoc ) { - Vector3 size = node.GetRenderSize( bufferIndex ); program.SetSizeUniform3f( sizeLoc, size.x, size.y, size.z ); } } @@ -336,65 +361,215 @@ void Renderer::SetUniformFromProperty( BufferIndex bufferIndex, Program& program } } -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& samplers( mRenderDataProvider->GetSamplers() ); std::vector& textures( mRenderDataProvider->GetTextures() ); - for( size_t i(0); iGetSamplerUniformUniqueIndex( 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& newTextures( mRenderDataProvider->GetNewTextures() ); + for( size_t i(0); result && iBind(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::SetIndexedDrawFirstElement( size_t firstElement ) +{ + mIndexedDrawFirstElement = firstElement; +} + +void Renderer::SetIndexedDrawElementsCount( size_t elementsCount ) +{ + 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::SetCullFace( Dali::Material::FaceCullingMode mode ) +void Renderer::SetStencilMode( StencilMode::Type stencilMode ) { - DALI_ASSERT_DEBUG( mode >= Dali::Material::NONE && mode <= Dali::Material::CULL_BACK_AND_FRONT ); - mCullFaceMode = mode; + mStencilParameters.stencilMode = stencilMode; } -void Renderer::SetSampler( unsigned int samplerBitfield ) +StencilMode::Type Renderer::GetStencilMode() const { - mSamplerBitfield = samplerBitfield; + return mStencilParameters.stencilMode; +} + +void Renderer::SetStencilFunction( StencilFunction::Type stencilFunction ) +{ + mStencilParameters.stencilFunction = stencilFunction; +} + +StencilFunction::Type Renderer::GetStencilFunction() const +{ + return mStencilParameters.stencilFunction; +} + +void Renderer::SetStencilFunctionMask( int stencilFunctionMask ) +{ + mStencilParameters.stencilFunctionMask = stencilFunctionMask; +} + +int Renderer::GetStencilFunctionMask() const +{ + return mStencilParameters.stencilFunctionMask; +} + +void Renderer::SetStencilFunctionReference( int stencilFunctionReference ) +{ + mStencilParameters.stencilFunctionReference = stencilFunctionReference; +} + +int Renderer::GetStencilFunctionReference() const +{ + return mStencilParameters.stencilFunctionReference; +} + +void Renderer::SetStencilMask( int stencilMask ) +{ + mStencilParameters.stencilMask = stencilMask; +} + +int Renderer::GetStencilMask() const +{ + return mStencilParameters.stencilMask; +} + +void Renderer::SetStencilOperationOnFail( StencilOperation::Type stencilOperationOnFail ) +{ + mStencilParameters.stencilOperationOnFail = stencilOperationOnFail; +} + +StencilOperation::Type Renderer::GetStencilOperationOnFail() const +{ + return mStencilParameters.stencilOperationOnFail; +} + +void Renderer::SetStencilOperationOnZFail( StencilOperation::Type stencilOperationOnZFail ) +{ + mStencilParameters.stencilOperationOnZFail = stencilOperationOnZFail; +} + +StencilOperation::Type Renderer::GetStencilOperationOnZFail() const +{ + return mStencilParameters.stencilOperationOnZFail; +} + +void Renderer::SetStencilOperationOnZPass( StencilOperation::Type stencilOperationOnZPass ) +{ + mStencilParameters.stencilOperationOnZPass = stencilOperationOnZPass; +} + +StencilOperation::Type Renderer::GetStencilOperationOnZPass() const +{ + return mStencilParameters.stencilOperationOnZPass; +} + +void Renderer::SetWriteToColorBuffer( bool writeToColorBuffer ) +{ + mWriteToColorBuffer = writeToColorBuffer; +} + +bool Renderer::GetWriteToColorBuffer() const +{ + return mWriteToColorBuffer; } void Renderer::Render( Context& context, @@ -402,10 +577,11 @@ 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: @@ -417,13 +593,13 @@ void Renderer::Render( Context& context, DALI_ASSERT_DEBUG( program && "Default shader should always have a program available." ); if( !program ) { - DALI_LOG_ERROR( "Failed to get program for shader at address %p.", (void*)&mRenderDataProvider->GetShader() ); + DALI_LOG_ERROR( "Failed to get program for shader at address %p.\n", (void*)&mRenderDataProvider->GetShader() ); return; } } //Set cull face mode - context.CullFace( mRenderDataProvider->GetMaterial().GetFaceCullingMode() ); + context.CullFace( mFaceCullingMode ); //Set blending mode SetBlending( context, blend ); @@ -431,30 +607,38 @@ void Renderer::Render( Context& context, // 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 @@ -470,7 +654,7 @@ void Renderer::SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererW sortAttributes.textureResourceId = Integration::InvalidResourceId; } - sortAttributes.geometry = mRenderGeometry; + sortAttributes.geometry = mGeometry; } } // namespace SceneGraph