X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Frender%2Frenderers%2Frender-renderer.cpp;h=cbad8bb8ebd4b4c362ee1424d842b5030c40b4fc;hb=2b10280985738c74efa2aa0fb956a837c69acee6;hp=cdd87528390ce8dabbce87d9d380f8c795703079;hpb=7a2a26a067225660d71bda7c10ed042c5e58fb1d;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 cdd8752..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,31 +110,49 @@ namespace Render { Renderer* Renderer::New( SceneGraph::RenderDataProvider* dataProvider, - SceneGraph::RenderGeometry* renderGeometry, + Render::Geometry* geometry, unsigned int blendingBitmask, const Vector4* blendColor, - Dali::Renderer::FaceCullingMode faceCullingMode, - bool preMultipliedAlphaEnabled ) + FaceCullingMode::Type faceCullingMode, + bool preMultipliedAlphaEnabled, + DepthWriteMode::Type depthWriteMode, + DepthTestMode::Type depthTestMode, + DepthFunction::Type depthFunction, + StencilParameters& stencilParameters, + bool writeToColorBuffer ) { - return new Renderer( dataProvider, renderGeometry, blendingBitmask, blendColor, faceCullingMode, preMultipliedAlphaEnabled ); + 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, - Dali::Renderer::FaceCullingMode faceCullingMode, - bool preMultipliedAlphaEnabled) + 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(), + mStencilParameters( stencilParameters ), mBlendingOptions(), - mFaceCullingMode( faceCullingMode ), - mSamplerBitfield( ImageSampler::PackBitfield( FilterMode::DEFAULT, FilterMode::DEFAULT ) ), + mIndexedDrawFirstElement( 0 ), + mIndexedDrawElementsCount( 0 ), + mDepthFunction( depthFunction ), + mFaceCullingMode( faceCullingMode ), + mDepthWriteMode( depthWriteMode ), + mDepthTestMode( depthTestMode ), + mWriteToColorBuffer( writeToColorBuffer ), mUpdateAttributesLocation( true ), mPremultipledAlphaEnabled( preMultipliedAlphaEnabled ) { @@ -166,20 +184,12 @@ 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 ); @@ -210,14 +220,14 @@ void Renderer::SetBlending( Context& context, bool blend ) 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" ); @@ -278,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 ); } } @@ -352,57 +361,68 @@ 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 = program.GetSamplerUniformLocation( uniqueIndex, textureMapping.GetUniformName() ); - if( Program::UNIFORM_UNKNOWN != uniformLocation ) + if( result ) { - program.SetUniform1i( uniformLocation, textureUnit ); - } + GLint uniformLocation; - 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; + //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; + } } + } + } - texture->ApplySampler( (TextureUnit)textureUnit, samplerBitfield ); + std::vector& newTextures( mRenderDataProvider->GetNewTextures() ); + for( size_t i(0); result && iBind(context, textureUnit, samplers[i] ); - ++textureUnit; + if( result ) + { + program.SetUniform1i( uniformLocation, textureUnit ); + ++textureUnit; + } } } + + return result; } -void Renderer::SetFaceCullingMode( Dali::Renderer::FaceCullingMode mode ) +void Renderer::SetFaceCullingMode( FaceCullingMode::Type mode ) { mFaceCullingMode = mode; } @@ -417,14 +437,139 @@ 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::SetSampler( unsigned int samplerBitfield ) +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::SetStencilMode( StencilMode::Type stencilMode ) +{ + mStencilParameters.stencilMode = stencilMode; +} + +StencilMode::Type Renderer::GetStencilMode() const +{ + return mStencilParameters.stencilMode; +} + +void Renderer::SetStencilFunction( StencilFunction::Type stencilFunction ) +{ + mStencilParameters.stencilFunction = stencilFunction; +} + +StencilFunction::Type Renderer::GetStencilFunction() const { - mSamplerBitfield = samplerBitfield; + 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, @@ -432,9 +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, + const Vector3& size, bool blend ) { // Get the program to use: @@ -446,7 +593,7 @@ 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; } } @@ -460,37 +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 ); - if( mPremultipledAlphaEnabled ) - { - program->SetUniform4f( loc, color.r*color.a, color.g*color.a, color.b*color.a, color.a ); - } - else + // 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 ) { - program->SetUniform4f( loc, color.r, color.g, color.b, color.a ); + 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 @@ -506,7 +654,7 @@ void Renderer::SetSortAttributes( BufferIndex bufferIndex, SceneGraph::RendererW sortAttributes.textureResourceId = Integration::InvalidResourceId; } - sortAttributes.geometry = mRenderGeometry; + sortAttributes.geometry = mGeometry; } } // namespace SceneGraph