X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Finternal%2Fupdate%2Frendering%2Fscene-graph-renderer.cpp;h=2fd1cfb632c5f4cc0a52e2b1314a179a23d0a3a5;hb=ad06250b0131a81ad28ae63c7e063f3d291d3060;hp=3f4ad490ba09b07132d1ffa498095965dd7bf796;hpb=86d50396aaa49828f4f0e3b333f0211e8765cb4f;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/internal/update/rendering/scene-graph-renderer.cpp b/dali/internal/update/rendering/scene-graph-renderer.cpp index 3f4ad49..2fd1cfb 100644 --- a/dali/internal/update/rendering/scene-graph-renderer.cpp +++ b/dali/internal/update/rendering/scene-graph-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. @@ -17,20 +17,17 @@ // CLASS HEADER #include "scene-graph-renderer.h" -// INTERNAL HEADERS +// INTERNAL INCLUDES #include #include #include -#include -#include +#include #include -#include #include -#include #include -#include #include #include +#include namespace // unnamed namespace @@ -40,6 +37,9 @@ const unsigned int UNIFORM_MAP_READY = 0; const unsigned int COPY_UNIFORM_MAP = 1; const unsigned int REGENERATE_UNIFORM_MAP = 2; +//Memory pool used to allocate new renderers. Memory used by this pool will be released when shutting down DALi +Dali::Internal::MemoryPoolObjectAllocator gRendererMemoryPool; + void AddMappings( Dali::Internal::SceneGraph::CollectedUniformMap& localMap, const Dali::Internal::SceneGraph::UniformMap& uniformMap ) { // Iterate thru uniformMap. @@ -82,10 +82,35 @@ void AddMappings( Dali::Internal::SceneGraph::CollectedUniformMap& localMap, con const Dali::Internal::SceneGraph::UniformPropertyMapping* map = (*iter); localMap.PushBack( map ); } - //@todo MESH_REWORK Use memcpy to copy ptrs from one array to the other } } -} + +// Flags for re-sending data to renderer. +enum Flags +{ + RESEND_DATA_PROVIDER = 1 << 0, + RESEND_GEOMETRY = 1 << 1, + RESEND_FACE_CULLING_MODE = 1 << 2, + RESEND_BLEND_COLOR = 1 << 3, + RESEND_BLEND_BIT_MASK = 1 << 4, + RESEND_PREMULTIPLIED_ALPHA = 1 << 5, + RESEND_INDEXED_DRAW_FIRST_ELEMENT = 1 << 6, + RESEND_INDEXED_DRAW_ELEMENTS_COUNT = 1 << 7, + RESEND_DEPTH_WRITE_MODE = 1 << 8, + RESEND_DEPTH_TEST_MODE = 1 << 9, + RESEND_DEPTH_FUNCTION = 1 << 10, + RESEND_STENCIL_MODE = 1 << 11, + RESEND_STENCIL_FUNCTION = 1 << 12, + RESEND_STENCIL_FUNCTION_MASK = 1 << 13, + RESEND_STENCIL_FUNCTION_REFERENCE = 1 << 14, + RESEND_STENCIL_MASK = 1 << 15, + RESEND_STENCIL_OPERATION_ON_FAIL = 1 << 16, + RESEND_STENCIL_OPERATION_ON_Z_FAIL = 1 << 17, + RESEND_STENCIL_OPERATION_ON_Z_PASS = 1 << 18, + RESEND_WRITE_TO_COLOR_BUFFER = 1 << 19 +}; + +} // Anonymous namespace namespace Dali { @@ -94,22 +119,37 @@ namespace Internal namespace SceneGraph { +Renderer* Renderer::New() +{ + return new ( gRendererMemoryPool.AllocateRawThreadSafe() ) Renderer(); +} + Renderer::Renderer() -:mSceneController(0), - mRenderer(NULL), - mMaterial(NULL), - mGeometry(NULL), - mReferenceCount(0), - mRegenerateUniformMap(0), - mResendDataProviders(false), - mResendGeometry(false), - mHasUntrackedResources(false), - mFinishedResourceAcquisition(false), - mResourcesReady(false), - mDepthIndex(0) -{ - mUniformMapChanged[0]=false; - mUniformMapChanged[1]=false; +: mSceneController( 0 ), + mRenderer( NULL ), + mTextureSet( NULL ), + mGeometry( NULL ), + mShader( NULL ), + mBlendColor( NULL ), + mStencilParameters( StencilMode::AUTO, StencilFunction::ALWAYS, 0xFF, 0x00, 0xFF, StencilOperation::KEEP, StencilOperation::KEEP, StencilOperation::KEEP ), + mIndexedDrawFirstElement( 0u ), + mIndexedDrawElementsCount( 0u ), + mBlendBitmask( 0u ), + mRegenerateUniformMap( 0u ), + mResendFlag( 0u ), + mDepthFunction( DepthFunction::LESS ), + mFaceCullingMode( FaceCullingMode::NONE ), + mBlendMode( BlendMode::AUTO ), + mDepthWriteMode( DepthWriteMode::AUTO ), + mDepthTestMode( DepthTestMode::AUTO ), + mWriteToColorBuffer( true ), + mResourcesReady( false ), + mFinishedResourceAcquisition( false ), + mPremultipledAlphaEnabled( false ), + mDepthIndex( 0 ) +{ + mUniformMapChanged[0] = false; + mUniformMapChanged[1] = false; // Observe our own PropertyOwner's uniform map AddUniformMapObserver( *this ); @@ -117,26 +157,47 @@ Renderer::Renderer() Renderer::~Renderer() { - if (mMaterial) + if (mTextureSet) { - mMaterial->RemoveConnectionObserver(*this); - mMaterial=NULL; + mTextureSet->RemoveObserver(this); + mTextureSet=NULL; } - if (mGeometry) + if( mShader ) { - mGeometry->RemoveConnectionObserver(*this); - mGeometry=NULL; + mShader->RemoveConnectionObserver(*this); + mShader=NULL; } } +void Renderer::operator delete( void* ptr ) +{ + gRendererMemoryPool.FreeThreadSafe( static_cast( ptr ) ); +} + + void Renderer::PrepareRender( BufferIndex updateBufferIndex ) { - mMaterial->PrepareRender( updateBufferIndex ); + mResourcesReady = false; + mFinishedResourceAcquisition = false; + + // Can only be considered ready when all the scene graph objects are connected to the renderer + if( mGeometry && mShader ) + { + if( mTextureSet ) + { + mTextureSet->GetResourcesStatus( mResourcesReady, mFinishedResourceAcquisition ); + } + else + { + mResourcesReady = true; + mFinishedResourceAcquisition = true; + } + } if( mRegenerateUniformMap > UNIFORM_MAP_READY ) { - DALI_ASSERT_DEBUG( mGeometry != NULL && "No geometry available in DoPrepareRender()" ); - DALI_ASSERT_DEBUG( mMaterial != NULL && "No geometry available in DoPrepareRender()" ); + DALI_ASSERT_DEBUG( mGeometry != NULL && "No geometry available in PrepareRender()" ); + DALI_ASSERT_DEBUG( mShader != NULL && "No shader available in PrepareRender()" ); if( mRegenerateUniformMap == REGENERATE_UNIFORM_MAP) { @@ -146,10 +207,10 @@ void Renderer::PrepareRender( BufferIndex updateBufferIndex ) const UniformMap& rendererUniformMap = PropertyOwner::GetUniformMap(); AddMappings( localMap, rendererUniformMap ); - AddMappings( localMap, mMaterial->GetUniformMap() ); - AddMappings( localMap, mMaterial->GetShader()->GetUniformMap() ); - AddMappings( localMap, mGeometry->GetUniformMap() ); - + if( mShader ) + { + AddMappings( localMap, mShader->GetUniformMap() ); + } } else if( mRegenerateUniformMap == COPY_UNIFORM_MAP ) { @@ -170,59 +231,193 @@ void Renderer::PrepareRender( BufferIndex updateBufferIndex ) mRegenerateUniformMap--; } - if( mResendDataProviders ) + if( mResendFlag != 0 ) { - RenderDataProvider* dataProvider = NewRenderDataProvider(); + if( mResendFlag & RESEND_DATA_PROVIDER ) + { + RenderDataProvider* dataProvider = NewRenderDataProvider(); - // Tell renderer about a new provider - // @todo MESH_REWORK Should we instead create a new renderer when these change? + typedef MessageValue1< Render::Renderer, OwnerPointer > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetRenderDataProvider, dataProvider ); + } - typedef MessageValue1< Render::Renderer, OwnerPointer > DerivedType; - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - new (slot) DerivedType( mRenderer, &Render::Renderer::SetRenderDataProvider, dataProvider ); - mResendDataProviders = false; - } + if( mResendFlag & RESEND_GEOMETRY ) + { + typedef MessageValue1< Render::Renderer, Render::Geometry* > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); - if( mResendGeometry ) - { - // The first call to GetRenderGeometry() creates the geometry and sends it in a message - RenderGeometry* geometry = mGeometry->GetRenderGeometry( mSceneController ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetGeometry, mGeometry ); + } + + if( mResendFlag & RESEND_FACE_CULLING_MODE ) + { + typedef MessageValue1< Render::Renderer, FaceCullingMode::Type > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetFaceCullingMode, mFaceCullingMode ); + } + + if( mResendFlag & RESEND_BLEND_BIT_MASK ) + { + typedef MessageValue1< Render::Renderer, unsigned int > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetBlendingBitMask, mBlendBitmask ); + } + + if( mResendFlag & RESEND_BLEND_COLOR ) + { + typedef MessageValue1< Render::Renderer, const Vector4* > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetBlendColor, mBlendColor ); + } + + if( mResendFlag & RESEND_PREMULTIPLIED_ALPHA ) + { + typedef MessageValue1< Render::Renderer, bool > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::EnablePreMultipliedAlpha, mPremultipledAlphaEnabled ); + } + + if( mResendFlag & RESEND_INDEXED_DRAW_FIRST_ELEMENT ) + { + typedef MessageValue1< Render::Renderer, size_t > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetIndexedDrawFirstElement, mIndexedDrawFirstElement ); + } + + if( mResendFlag & RESEND_INDEXED_DRAW_ELEMENTS_COUNT ) + { + typedef MessageValue1< Render::Renderer, size_t > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetIndexedDrawElementsCount, mIndexedDrawElementsCount ); + } + + if( mResendFlag & RESEND_DEPTH_WRITE_MODE ) + { + typedef MessageValue1< Render::Renderer, DepthWriteMode::Type > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetDepthWriteMode, mDepthWriteMode ); + } - typedef MessageValue1< Render::Renderer, RenderGeometry* > DerivedType; - unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + if( mResendFlag & RESEND_DEPTH_TEST_MODE ) + { + typedef MessageValue1< Render::Renderer, DepthTestMode::Type > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetDepthTestMode, mDepthTestMode ); + } + + if( mResendFlag & RESEND_DEPTH_FUNCTION ) + { + typedef MessageValue1< Render::Renderer, DepthFunction::Type > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetDepthFunction, mDepthFunction ); + } + + if( mResendFlag & RESEND_STENCIL_MODE ) + { + typedef MessageValue1< Render::Renderer, StencilMode::Type > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetStencilMode, mStencilParameters.stencilMode ); + } + + if( mResendFlag & RESEND_STENCIL_FUNCTION ) + { + typedef MessageValue1< Render::Renderer, StencilFunction::Type > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetStencilFunction, mStencilParameters.stencilFunction ); + } + + if( mResendFlag & RESEND_STENCIL_FUNCTION_MASK ) + { + typedef MessageValue1< Render::Renderer, int > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetStencilFunctionMask, mStencilParameters.stencilFunctionMask ); + } + + if( mResendFlag & RESEND_STENCIL_FUNCTION_REFERENCE ) + { + typedef MessageValue1< Render::Renderer, int > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetStencilFunctionReference, mStencilParameters.stencilFunctionReference ); + } + + if( mResendFlag & RESEND_STENCIL_MASK ) + { + typedef MessageValue1< Render::Renderer, int > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetStencilMask, mStencilParameters.stencilMask ); + } + + if( mResendFlag & RESEND_STENCIL_OPERATION_ON_FAIL ) + { + typedef MessageValue1< Render::Renderer, StencilOperation::Type > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetStencilOperationOnFail, mStencilParameters.stencilOperationOnFail ); + } + + if( mResendFlag & RESEND_STENCIL_OPERATION_ON_Z_FAIL ) + { + typedef MessageValue1< Render::Renderer, StencilOperation::Type > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetStencilOperationOnZFail, mStencilParameters.stencilOperationOnZFail ); + } + + if( mResendFlag & RESEND_STENCIL_OPERATION_ON_Z_PASS ) + { + typedef MessageValue1< Render::Renderer, StencilOperation::Type > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetStencilOperationOnZPass, mStencilParameters.stencilOperationOnZPass ); + } - new (slot) DerivedType( mRenderer, &Render::Renderer::SetGeometry, geometry ); - mResendGeometry = false; + if( mResendFlag & RESEND_WRITE_TO_COLOR_BUFFER ) + { + typedef MessageValue1< Render::Renderer, bool > DerivedType; + unsigned int* slot = mSceneController->GetRenderQueue().ReserveMessageSlot( updateBufferIndex, sizeof( DerivedType ) ); + new (slot) DerivedType( mRenderer, &Render::Renderer::SetWriteToColorBuffer, mWriteToColorBuffer ); + } + + mResendFlag = 0; } } -void Renderer::SetMaterial( BufferIndex bufferIndex, Material* material) +void Renderer::SetTextures( TextureSet* textureSet ) { - DALI_ASSERT_DEBUG( material != NULL && "Material pointer is NULL" ); + DALI_ASSERT_DEBUG( textureSet != NULL && "Texture set pointer is NULL" ); - mMaterial = material; - mMaterial->AddConnectionObserver( *this ); - mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; + if( mTextureSet ) + { + mTextureSet->RemoveObserver(this); + } - mResendDataProviders = true; + mTextureSet = textureSet; + mTextureSet->AddObserver( this ); + mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; + mResendFlag |= RESEND_DATA_PROVIDER; } -void Renderer::SetGeometry( BufferIndex bufferIndex, Geometry* geometry) +void Renderer::SetShader( Shader* shader ) { - DALI_ASSERT_DEBUG( geometry != NULL && "Geometry pointer is NULL"); - if( mGeometry) + DALI_ASSERT_DEBUG( shader != NULL && "Shader pointer is NULL" ); + + if( mShader ) { - mGeometry->RemoveConnectionObserver(*this); - mGeometry->OnRendererDisconnect(); + mShader->RemoveConnectionObserver(*this); } - mGeometry = geometry; - mGeometry->AddConnectionObserver( *this ); // Observe geometry connections / uniform mapping changes + mShader = shader; + mShader->AddConnectionObserver( *this ); mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; + mResendFlag |= RESEND_DATA_PROVIDER; +} + +void Renderer::SetGeometry( Render::Geometry* geometry ) +{ + DALI_ASSERT_DEBUG( geometry != NULL && "Geometry pointer is NULL"); + mGeometry = geometry; if( mRenderer ) { - mResendGeometry = true; + mResendFlag |= RESEND_GEOMETRY; } } @@ -231,35 +426,128 @@ void Renderer::SetDepthIndex( int depthIndex ) mDepthIndex = depthIndex; } -//Called when a node with this renderer is added to the stage -void Renderer::OnStageConnect() +void Renderer::SetFaceCullingMode( FaceCullingMode::Type faceCullingMode ) { - ++mReferenceCount; - if( !mRenderer) - { - RenderDataProvider* dataProvider = NewRenderDataProvider(); + mFaceCullingMode = faceCullingMode; + mResendFlag |= RESEND_FACE_CULLING_MODE; +} - RenderGeometry* renderGeometry = mGeometry->GetRenderGeometry(mSceneController); - mRenderer = Render::Renderer::New( dataProvider, renderGeometry ); - mSceneController->GetRenderMessageDispatcher().AddRenderer( *mRenderer ); - mResendDataProviders = false; - mResendGeometry = false; +void Renderer::SetBlendMode( BlendMode::Type blendingMode ) +{ + mBlendMode = blendingMode; +} + +void Renderer::SetBlendingOptions( unsigned int options ) +{ + if( mBlendBitmask != options) + { + mBlendBitmask = options; + mResendFlag |= RESEND_BLEND_BIT_MASK; } } -//Called when the node with this renderer has gone out of the stage -void Renderer::OnStageDisconnect() +void Renderer::SetBlendColor( const Vector4& blendColor ) { - --mReferenceCount; - if( mReferenceCount == 0 ) + if( !mBlendColor ) { - mSceneController->GetRenderMessageDispatcher().RemoveRenderer( *mRenderer ); - if( mGeometry ) - { - mGeometry->OnRendererDisconnect(); - } - mRenderer = NULL; + mBlendColor = new Vector4( blendColor ); + } + else + { + *mBlendColor = blendColor; } + + mResendFlag |= RESEND_BLEND_COLOR; +} + +void Renderer::SetIndexedDrawFirstElement( size_t firstElement ) +{ + mIndexedDrawFirstElement = firstElement; + mResendFlag |= RESEND_INDEXED_DRAW_FIRST_ELEMENT; +} + +void Renderer::SetIndexedDrawElementsCount( size_t elementsCount ) +{ + mIndexedDrawElementsCount = elementsCount; + mResendFlag |= RESEND_INDEXED_DRAW_ELEMENTS_COUNT; +} + +void Renderer::EnablePreMultipliedAlpha( bool preMultipled ) +{ + mPremultipledAlphaEnabled = preMultipled; + mResendFlag |= RESEND_PREMULTIPLIED_ALPHA; +} + +void Renderer::SetDepthWriteMode( DepthWriteMode::Type depthWriteMode ) +{ + mDepthWriteMode = depthWriteMode; + mResendFlag |= RESEND_DEPTH_WRITE_MODE; +} + +void Renderer::SetDepthTestMode( DepthTestMode::Type depthTestMode ) +{ + mDepthTestMode = depthTestMode; + mResendFlag |= RESEND_DEPTH_TEST_MODE; +} + +void Renderer::SetDepthFunction( DepthFunction::Type depthFunction ) +{ + mDepthFunction = depthFunction; + mResendFlag |= RESEND_DEPTH_FUNCTION; +} + +void Renderer::SetStencilMode( StencilMode::Type mode ) +{ + mStencilParameters.stencilMode = mode; + mResendFlag |= RESEND_STENCIL_MODE; +} + +void Renderer::SetStencilFunction( StencilFunction::Type stencilFunction ) +{ + mStencilParameters.stencilFunction = stencilFunction; + mResendFlag |= RESEND_STENCIL_FUNCTION; +} + +void Renderer::SetStencilFunctionMask( int stencilFunctionMask ) +{ + mStencilParameters.stencilFunctionMask = stencilFunctionMask; + mResendFlag |= RESEND_STENCIL_FUNCTION_MASK; +} + +void Renderer::SetStencilFunctionReference( int stencilFunctionReference ) +{ + mStencilParameters.stencilFunctionReference = stencilFunctionReference; + mResendFlag |= RESEND_STENCIL_FUNCTION_REFERENCE; +} + +void Renderer::SetStencilMask( int stencilMask ) +{ + mStencilParameters.stencilMask = stencilMask; + mResendFlag |= RESEND_STENCIL_MASK; +} + +void Renderer::SetStencilOperationOnFail( StencilOperation::Type stencilOperationOnFail ) +{ + mStencilParameters.stencilOperationOnFail = stencilOperationOnFail; + mResendFlag |= RESEND_STENCIL_OPERATION_ON_FAIL; +} + +void Renderer::SetStencilOperationOnZFail( StencilOperation::Type stencilOperationOnZFail ) +{ + mStencilParameters.stencilOperationOnZFail = stencilOperationOnZFail; + mResendFlag |= RESEND_STENCIL_OPERATION_ON_Z_FAIL; +} + +void Renderer::SetStencilOperationOnZPass( StencilOperation::Type stencilOperationOnZPass ) +{ + mStencilParameters.stencilOperationOnZPass = stencilOperationOnZPass; + mResendFlag |= RESEND_STENCIL_OPERATION_ON_Z_PASS; +} + +void Renderer::SetWriteToColorBuffer( bool writeToColorBuffer ) +{ + mWriteToColorBuffer = writeToColorBuffer; + mResendFlag |= RESEND_WRITE_TO_COLOR_BUFFER; } //Called when SceneGraph::Renderer is added to update manager ( that happens when an "event-thread renderer" is created ) @@ -267,8 +555,13 @@ void Renderer::ConnectToSceneGraph( SceneController& sceneController, BufferInde { mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; mSceneController = &sceneController; -} + RenderDataProvider* dataProvider = NewRenderDataProvider(); + mRenderer = Render::Renderer::New( dataProvider, mGeometry, mBlendBitmask, mBlendColor, static_cast< FaceCullingMode::Type >( mFaceCullingMode ), + mPremultipledAlphaEnabled, mDepthWriteMode, mDepthTestMode, mDepthFunction, mStencilParameters, mWriteToColorBuffer ); + + mSceneController->GetRenderMessageDispatcher().AddRenderer( *mRenderer ); +} //Called just before destroying the scene-graph renderer ( when the "event-thread renderer" is no longer referenced ) void Renderer::DisconnectFromSceneGraph( SceneController& sceneController, BufferIndex bufferIndex ) @@ -278,25 +571,36 @@ void Renderer::DisconnectFromSceneGraph( SceneController& sceneController, Buffe { mSceneController->GetRenderMessageDispatcher().RemoveRenderer( *mRenderer ); mRenderer = NULL; - mSceneController = NULL; } + mSceneController = NULL; } RenderDataProvider* Renderer::NewRenderDataProvider() { RenderDataProvider* dataProvider = new RenderDataProvider(); - dataProvider->mMaterialDataProvider = mMaterial; dataProvider->mUniformMapDataProvider = this; - dataProvider->mShader = mMaterial->GetShader(); + dataProvider->mShader = mShader; - size_t textureCount( mMaterial->GetTextureCount() ); - dataProvider->mTextures.resize( textureCount ); - for( unsigned int i(0); imTextures[i] = Render::Texture( mMaterial->GetTextureUniformName(i), - mMaterial->GetTextureId(i), - mMaterial->GetTextureSampler(i)); + size_t textureCount( mTextureSet->GetTextureCount() ); + dataProvider->mTextures.resize( textureCount ); + dataProvider->mSamplers.resize( textureCount ); + for( unsigned int i(0); imTextures[i] = Render::Texture( mTextureSet->GetTextureId(i),0); + dataProvider->mSamplers[i] = mTextureSet->GetTextureSampler(i); + } + + textureCount = mTextureSet->GetNewTextureCount(); + dataProvider->mNewTextures.resize( textureCount ); + dataProvider->mSamplers.resize( textureCount ); + for( unsigned int i(0); imNewTextures[i] = mTextureSet->GetNewTexture(i); + dataProvider->mSamplers[i] = mTextureSet->GetTextureSampler(i); + } } return dataProvider; @@ -310,156 +614,61 @@ Render::Renderer& Renderer::GetRenderer() const CollectedUniformMap& Renderer::GetUniformMap( BufferIndex bufferIndex ) const { return mCollectedUniformMap[bufferIndex]; -}; +} -void Renderer::PrepareResources( BufferIndex updateBufferIndex, ResourceManager& resourceManager ) +void Renderer::GetReadyAndComplete( bool& ready, bool& complete ) const { - mHasUntrackedResources = false; - mTrackedResources.Clear(); // Resource trackers are only needed if not yet completea - - DALI_ASSERT_DEBUG( mSceneController ); - - CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager(); - mResourcesReady = false; + ready = mResourcesReady; + complete = mFinishedResourceAcquisition; +} - mFinishedResourceAcquisition = false; +Renderer::Opacity Renderer::GetOpacity( BufferIndex updateBufferIndex, const Node& node ) const +{ + Renderer::Opacity opacity = Renderer::OPAQUE; - // Can only be considered ready when all the scene graph objects are connected to the renderer - if( ( mGeometry ) && ( mGeometry->GetVertexBuffers().Count() > 0 ) && - ( mMaterial ) && ( mMaterial->GetShader() != NULL ) ) + switch( mBlendMode ) { - unsigned int completeCount = 0; - unsigned int neverCount = 0; - unsigned int frameBufferCount = 0; - - size_t textureCount( mMaterial->GetTextureCount() ); - if( textureCount > 0 ) + case BlendMode::ON: // If the renderer should always be use blending + { + opacity = Renderer::TRANSLUCENT; + break; + } + case BlendMode::AUTO: { - unsigned int opaqueCount = 0; - for( unsigned int i(0); iHintEnabled( Dali::Shader::HINT_OUTPUT_IS_TRANSPARENT ) ); + if( shaderRequiresBlending || ( mTextureSet && mTextureSet->HasAlpha() ) ) { - ResourceId textureId = mMaterial->GetTextureId(i); - BitmapMetadata metaData = resourceManager.GetBitmapMetadata( textureId ); - if( metaData.IsFullyOpaque() ) + opacity = Renderer::TRANSLUCENT; + } + else // renderer should determine opacity using the actor color + { + float alpha = node.GetWorldColor( updateBufferIndex ).a; + if( alpha <= FULLY_TRANSPARENT ) { - ++opaqueCount; + opacity = TRANSPARENT; } - - switch( completeStatusManager.GetStatus( textureId ) ) + else if( alpha <= FULLY_OPAQUE ) { - case CompleteStatusManager::NOT_READY: - { - if( metaData.GetIsFramebuffer() ) - { - frameBufferCount++; - } - if( completeStatusManager.FindResourceTracker(textureId) != NULL ) - { - bool found = false; - std::size_t numTrackedResources = mTrackedResources.Count(); - for( size_t i=0; i < numTrackedResources; ++i ) - { - if(mTrackedResources[i] == textureId) - { - found = true; - break; - } - } - if( ! found ) - { - mTrackedResources.PushBack( textureId ); - } - } - else - { - mHasUntrackedResources = true; - } - } - break; - - case CompleteStatusManager::COMPLETE: - { - completeCount++; - } - break; - - case CompleteStatusManager::NEVER: - { - neverCount++; - } - break; + opacity = TRANSLUCENT; } } - mMaterial->SetTexturesRequireBlending( opaqueCount != textureCount ); + break; } - - // We are ready if all samplers are complete, or those that aren't are framebuffers - // We are complete if all samplers are either complete or will nmResendGeometryever complete - mResourcesReady = ( completeCount + frameBufferCount >= textureCount ) ; - mFinishedResourceAcquisition = ( completeCount + neverCount >= textureCount ); - } -} - -void Renderer::GetReadyAndComplete(bool& ready, bool& complete) const -{ - ready = mResourcesReady; - complete = false; - - CompleteStatusManager& completeStatusManager = mSceneController->GetCompleteStatusManager(); - - std::size_t numTrackedResources = mTrackedResources.Count(); - if( mHasUntrackedResources || numTrackedResources == 0 ) - { - complete = mFinishedResourceAcquisition; - } - else - { - // If there are tracked resources and no untracked resources, test the trackers - bool trackersComplete = true; - for( size_t i=0; i < numTrackedResources; ++i ) + case BlendMode::OFF: // the renderer should never use blending + default: { - ResourceId id = mTrackedResources[i]; - ResourceTracker* tracker = completeStatusManager.FindResourceTracker(id); - if( tracker && ! tracker->IsComplete() ) - { - trackersComplete = false; - break; - } + opacity = Renderer::OPAQUE; + break; } - - complete = mFinishedResourceAcquisition || trackersComplete; } -} -// Called by ProcessRenderTasks after DoPrepareRender -bool Renderer::IsFullyOpaque( BufferIndex updateBufferIndex, const Node& node ) const -{ - bool opaque = false; - if( mMaterial != NULL ) - { - Material::BlendPolicy blendPolicy = mMaterial->GetBlendPolicy(); - switch( blendPolicy ) - { - case Material::OPAQUE: - { - opaque = true; - break; - } - case Material::TRANSPARENT: - { - opaque = false; - break; - } - case Material::USE_ACTOR_COLOR: - { - opaque = node.GetWorldColor( updateBufferIndex ).a >= FULLY_OPAQUE; - break; - } - } - } + return opacity; +} - return opaque; +void Renderer::TextureSetChanged() +{ + mResendFlag |= RESEND_DATA_PROVIDER; } void Renderer::ConnectionsChanged( PropertyOwner& object ) @@ -469,7 +678,7 @@ void Renderer::ConnectionsChanged( PropertyOwner& object ) mRegenerateUniformMap = REGENERATE_UNIFORM_MAP; // Ensure the child object pointers get re-sent to the renderer - mResendDataProviders = true; + mResendFlag |= RESEND_DATA_PROVIDER; } void Renderer::ConnectedUniformMapChanged() @@ -485,13 +694,13 @@ void Renderer::UniformMappingsChanged( const UniformMap& mappings ) void Renderer::ObservedObjectDestroyed(PropertyOwner& owner) { - if( reinterpret_cast(mGeometry) == &owner ) + if( reinterpret_cast(mTextureSet) == &owner ) { - mGeometry = NULL; + mTextureSet = NULL; } - else if( reinterpret_cast(mMaterial) == &owner ) + else if( reinterpret_cast(mShader) == &owner ) { - mMaterial = NULL; + mShader = NULL; } }