// CLASS HEADER
#include <dali/internal/render/common/render-manager.h>
+// EXTERNAL INCLUDES
+#include <memory.h>
+
// INTERNAL INCLUDES
#include <dali/public-api/actors/sampling.h>
#include <dali/public-api/common/dali-common.h>
#include <dali/public-api/common/stage.h>
#include <dali/public-api/render-tasks/render-task.h>
+#include <dali/devel-api/threading/thread-pool.h>
#include <dali/integration-api/debug.h>
#include <dali/integration-api/core.h>
+#include <dali/integration-api/gl-context-helper-abstraction.h>
#include <dali/internal/common/owner-pointer.h>
#include <dali/internal/render/common/render-algorithms.h>
#include <dali/internal/render/common/render-debug.h>
namespace SceneGraph
{
+#if defined(DEBUG_ENABLED)
+namespace
+{
+Debug::Filter* gLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_RENDER_MANAGER" );
+} // unnamed namespace
+#endif
+
+namespace
+{
+const float partialUpdateRatio = 0.8f; // If the partial update area exceeds 80%, change to full update.
+
+/**
+ * @brief Find the intersection of two AABB rectangles.
+ * This is a logical AND operation. IE. The intersection is the area overlapped by both rectangles.
+ * @param[in] aabbA Rectangle A
+ * @param[in] aabbB Rectangle B
+ * @return The intersection of rectangle A & B (result is a rectangle)
+ */
+inline ClippingBox IntersectAABB( const ClippingBox& aabbA, const ClippingBox& aabbB )
+{
+ ClippingBox intersectionBox;
+
+ // First calculate the largest starting positions in X and Y.
+ intersectionBox.x = std::max( aabbA.x, aabbB.x );
+ intersectionBox.y = std::max( aabbA.y, aabbB.y );
+
+ // Now calculate the smallest ending positions, and take the largest starting
+ // positions from the result, to get the width and height respectively.
+ // If the two boxes do not intersect at all, then we need a 0 width and height clipping area.
+ // We use max here to clamp both width and height to >= 0 for this use-case.
+ intersectionBox.width = std::max( std::min( aabbA.x + aabbA.width, aabbB.x + aabbB.width ) - intersectionBox.x, 0 );
+ intersectionBox.height = std::max( std::min( aabbA.y + aabbA.height, aabbB.y + aabbB.height ) - intersectionBox.y, 0 );
+
+ return intersectionBox;
+}
+
+}
+
/**
* Structure to contain internal data
*/
{
Impl( Integration::GlAbstraction& glAbstraction,
Integration::GlSyncAbstraction& glSyncAbstraction,
+ Integration::GlContextHelperAbstraction& glContextHelperAbstraction,
Integration::DepthBufferAvailable depthBufferAvailableParam,
- Integration::StencilBufferAvailable stencilBufferAvailableParam )
- : context( glAbstraction ),
+ Integration::StencilBufferAvailable stencilBufferAvailableParam,
+ Integration::PartialUpdateAvailable partialUpdateAvailableParam )
+ : context( glAbstraction, &surfaceContextContainer ),
currentContext( &context ),
glAbstraction( glAbstraction ),
glSyncAbstraction( glSyncAbstraction ),
+ glContextHelperAbstraction( glContextHelperAbstraction ),
renderQueue(),
instructions(),
renderAlgorithms(),
- backgroundColor( Dali::Stage::DEFAULT_BACKGROUND_COLOR ),
frameCount( 0u ),
renderBufferIndex( SceneGraphBuffers::INITIAL_UPDATE_BUFFER_INDEX ),
defaultSurfaceRect(),
lastFrameWasRendered( false ),
programController( glAbstraction ),
depthBufferAvailable( depthBufferAvailableParam ),
- stencilBufferAvailable( stencilBufferAvailableParam )
+ stencilBufferAvailable( stencilBufferAvailableParam ),
+ partialUpdateAvailable( partialUpdateAvailableParam ),
+ defaultSurfaceOrientation( 0 )
{
+ // Create thread pool with just one thread ( there may be a need to create more threads in the future ).
+ threadPool = std::unique_ptr<Dali::ThreadPool>( new Dali::ThreadPool() );
+ threadPool->Initialize( 1u );
}
~Impl()
{
+ threadPool.reset( nullptr ); // reset now to maintain correct destruction order
}
void AddRenderTracker( Render::RenderTracker* renderTracker )
OwnerContainer< Context* > surfaceContextContainer; ///< List of owned contexts holding the GL state per surface
Integration::GlAbstraction& glAbstraction; ///< GL abstraction
Integration::GlSyncAbstraction& glSyncAbstraction; ///< GL sync abstraction
+ Integration::GlContextHelperAbstraction& glContextHelperAbstraction; ///< GL context helper abstraction
RenderQueue renderQueue; ///< A message queue for receiving messages from the update-thread.
// Render instructions describe what should be rendered during RenderManager::Render()
RenderInstructionContainer instructions;
Render::RenderAlgorithms renderAlgorithms; ///< The RenderAlgorithms object is used to action the renders required by a RenderInstruction
- Vector4 backgroundColor; ///< The glClear color used at the beginning of each frame.
-
uint32_t frameCount; ///< The current frame count
BufferIndex renderBufferIndex; ///< The index of the buffer to read from; this is opposite of the "update" buffer
Integration::DepthBufferAvailable depthBufferAvailable; ///< Whether the depth buffer is available
Integration::StencilBufferAvailable stencilBufferAvailable; ///< Whether the stencil buffer is available
+ Integration::PartialUpdateAvailable partialUpdateAvailable; ///< Whether the partial update is available
+
+ std::unique_ptr<Dali::ThreadPool> threadPool; ///< The thread pool
+ Vector<GLuint> boundTextures; ///< The textures bound for rendering
+ Vector<GLuint> textureDependencyList; ///< The dependency list of binded textures
+ int defaultSurfaceOrientation; ///< defaultSurfaceOrientation for the default surface we are rendering to
};
RenderManager* RenderManager::New( Integration::GlAbstraction& glAbstraction,
Integration::GlSyncAbstraction& glSyncAbstraction,
+ Integration::GlContextHelperAbstraction& glContextHelperAbstraction,
Integration::DepthBufferAvailable depthBufferAvailable,
- Integration::StencilBufferAvailable stencilBufferAvailable )
+ Integration::StencilBufferAvailable stencilBufferAvailable,
+ Integration::PartialUpdateAvailable partialUpdateAvailable )
{
RenderManager* manager = new RenderManager;
manager->mImpl = new Impl( glAbstraction,
glSyncAbstraction,
+ glContextHelperAbstraction,
depthBufferAvailable,
- stencilBufferAvailable );
+ stencilBufferAvailable,
+ partialUpdateAvailable );
return manager;
}
return mImpl->instructions;
}
-void RenderManager::SetBackgroundColor( const Vector4& color )
+void RenderManager::SetDefaultSurfaceRect(const Rect<int32_t>& rect)
{
- mImpl->backgroundColor = color;
+ mImpl->defaultSurfaceRect = rect;
}
-void RenderManager::SetDefaultSurfaceRect(const Rect<int32_t>& rect)
+void RenderManager::SetDefaultSurfaceOrientation( int orientation )
{
- mImpl->defaultSurfaceRect = rect;
+ mImpl->defaultSurfaceOrientation = orientation;
}
void RenderManager::AddRenderer( OwnerPointer< Render::Renderer >& renderer )
sampler->mTWrapMode = static_cast<Dali::WrapMode::Type>(tWrapMode);
}
-void RenderManager::AddFrameBuffer( Render::FrameBuffer* frameBuffer )
+void RenderManager::AddFrameBuffer( OwnerPointer< Render::FrameBuffer >& frameBuffer )
{
- mImpl->frameBufferContainer.PushBack( frameBuffer );
- if ( frameBuffer->IsSurfaceBacked() )
+ Render::FrameBuffer* frameBufferPtr = frameBuffer.Release();
+ mImpl->frameBufferContainer.PushBack( frameBufferPtr );
+ if ( frameBufferPtr->IsSurfaceBacked() )
{
- frameBuffer->Initialize( *mImpl->CreateSurfaceContext() );
+ frameBufferPtr->Initialize( *mImpl->CreateSurfaceContext() );
}
else
{
- frameBuffer->Initialize( mImpl->context );
+ frameBufferPtr->Initialize( mImpl->context );
}
}
return &(mImpl->programController);
}
-void RenderManager::Render( Integration::RenderStatus& status, bool forceClear )
+void RenderManager::Render( Integration::RenderStatus& status, bool forceClear, bool uploadOnly )
{
DALI_PRINT_RENDER_START( mImpl->renderBufferIndex );
const uint32_t count = mImpl->instructions.Count( mImpl->renderBufferIndex );
const bool haveInstructions = count > 0u;
+ DALI_LOG_INFO( gLogFilter, Debug::General,
+ "Render: haveInstructions(%s) || mImpl->lastFrameWasRendered(%s) || forceClear(%s)\n",
+ haveInstructions ? "true" : "false",
+ mImpl->lastFrameWasRendered ? "true" : "false",
+ forceClear ? "true" : "false" );
+
// Only render if we have instructions to render, or the last frame was rendered (and therefore a clear is required).
if( haveInstructions || mImpl->lastFrameWasRendered || forceClear )
{
- // Mark that we will require a post-render step to be performed (includes swap-buffers).
- status.SetNeedsPostRender( true );
+ DALI_LOG_INFO( gLogFilter, Debug::General, "Render: Processing\n" );
+
+ if ( !uploadOnly )
+ {
+ // Mark that we will require a post-render step to be performed (includes swap-buffers).
+ status.SetNeedsPostRender( true );
+ }
// Switch to the shared context
if ( mImpl->currentContext != &mImpl->context )
{
mImpl->currentContext = &mImpl->context;
+
+ if ( mImpl->currentContext->IsSurfacelessContextSupported() )
+ {
+ mImpl->glContextHelperAbstraction.MakeSurfacelessContextCurrent();
+ }
+
// Clear the current cached program when the context is switched
mImpl->programController.ClearCurrentProgram();
}
-
// Upload the geometries
for( uint32_t i = 0; i < count; ++i )
{
}
}
- for( uint32_t i = 0; i < count; ++i )
+ if ( !uploadOnly )
{
- RenderInstruction& instruction = mImpl->instructions.At( mImpl->renderBufferIndex, i );
+ for( uint32_t i = 0; i < count; ++i )
+ {
+ RenderInstruction& instruction = mImpl->instructions.At( mImpl->renderBufferIndex, i );
- DoRender( instruction );
- }
+ DoRender( instruction );
+ }
- GLenum attachments[] = { GL_DEPTH, GL_STENCIL };
- mImpl->context.InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
- for ( auto&& context : mImpl->surfaceContextContainer )
- {
- context->InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
+ if ( mImpl->currentContext->IsSurfacelessContextSupported() )
+ {
+ mImpl->glContextHelperAbstraction.MakeSurfacelessContextCurrent();
+ }
+
+ GLenum attachments[] = { GL_DEPTH, GL_STENCIL };
+ mImpl->context.InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
+ for ( auto&& context : mImpl->surfaceContextContainer )
+ {
+ context->InvalidateFramebuffer(GL_FRAMEBUFFER, 2, attachments);
+ }
}
//Notify RenderGeometries that rendering has finished
iter->OnRenderFinished();
}
}
+ else
+ {
+ DALI_LOG_RELEASE_INFO( "RenderManager::Render: Skip rendering [%d, %d, %d]\n", haveInstructions, mImpl->lastFrameWasRendered, forceClear );
+ }
mImpl->UpdateTrackers();
DALI_PRINT_RENDER_END();
}
+bool GetDamagedRect( Rect<int32_t> &viewportRect, RenderInstruction& instruction, Rect<int32_t> &damagedRect )
+{
+ // merge bounding
+ int dx1 = viewportRect.width, dx2 = 0, dy1 = viewportRect.height, dy2 = 0;
+ int checkWidth = static_cast<int>( static_cast<float>( viewportRect.width ) * partialUpdateRatio );
+ int checkHeight = static_cast<int>( static_cast<float>( viewportRect.height ) * partialUpdateRatio );
+ Rect<int32_t> screenRect;
+
+ bool isPartialUpdate = false;
+
+ const RenderListContainer::SizeType renderListCount = instruction.RenderListCount();
+ // Iterate through each render list.
+
+ for( RenderListContainer::SizeType index = 0; index < renderListCount; ++index )
+ {
+ const RenderList* renderList = instruction.GetRenderList( index );
+
+ if( renderList && !renderList->IsEmpty() && renderList->IsPartialUpdateEnabled() )
+ {
+ const std::size_t itemCount = renderList->Count();
+ for( uint32_t itemIndex = 0u; itemIndex < itemCount; ++itemIndex )
+ {
+ const RenderItem& item = renderList->GetItem( itemIndex );
+
+ if( item.mPartialUpdateEnabled )
+ {
+ isPartialUpdate = true;
+
+ screenRect = item.CalculateViewportSpaceAABB( viewportRect.width, viewportRect.height, true );
+
+ dx1 = std::min( screenRect.x, dx1 );
+ dx2 = std::max( screenRect.x + screenRect.width, dx2);
+ dy1 = std::min( screenRect.y, dy1 );
+ dy2 = std::max( screenRect.y + screenRect.height, dy2 );
+
+ if( ( dx2 - dx1 ) > checkWidth && ( dy2 - dy1 ) > checkHeight )
+ {
+ return false;
+ }
+ }
+ }
+ }
+ }
+
+ if( isPartialUpdate )
+ {
+ if( dx1 < 0.0f )
+ {
+ dx1 = 0.0f;
+ }
+ if( dy1 < 0.0f )
+ {
+ dy1 = 0.0f;
+ }
+ if( dx2 > viewportRect.width )
+ {
+ dx2 = viewportRect.width;
+ }
+ if( dy2 > viewportRect.height )
+ {
+ dy2 = viewportRect.height;
+ }
+
+ damagedRect.x = dx1;
+ damagedRect.y = dy1;
+ damagedRect.width = dx2 - dx1;
+ damagedRect.height = dy2 - dy1;
+ }
+
+ return isPartialUpdate;
+}
+
void RenderManager::DoRender( RenderInstruction& instruction )
{
Rect<int32_t> viewportRect;
Vector4 clearColor;
+ bool isPartialUpdate = false;
+ Dali::DamagedRect damagedRect;
+ Dali::DamagedRect mergedRect;
+ Dali::ClippingBox scissorBox;
+ Dali::ClippingBox intersectRect;
if ( instruction.mIsClearColorSet )
{
}
Rect<int32_t> surfaceRect = mImpl->defaultSurfaceRect;
- Vector4 backgroundColor = mImpl->backgroundColor;
+ int surfaceOrientation = mImpl->defaultSurfaceOrientation;
Integration::DepthBufferAvailable depthBufferAvailable = mImpl->depthBufferAvailable;
Integration::StencilBufferAvailable stencilBufferAvailable = mImpl->stencilBufferAvailable;
+ Integration::PartialUpdateAvailable partialUpdateAvailable = mImpl->partialUpdateAvailable;
Render::SurfaceFrameBuffer* surfaceFrameBuffer = nullptr;
- if ( ( instruction.mFrameBuffer != 0 ) && instruction.mFrameBuffer->IsSurfaceBacked() )
+ if ( instruction.mFrameBuffer != 0 )
{
- surfaceFrameBuffer = static_cast<Render::SurfaceFrameBuffer*>( instruction.mFrameBuffer );
-
-#if DALI_GLES_VERSION >= 30
- Context* surfaceContext = surfaceFrameBuffer->GetContext();
- if ( mImpl->currentContext != surfaceContext )
+ if ( instruction.mFrameBuffer->IsSurfaceBacked() )
{
- // Switch the correct context if rendering to a surface
- mImpl->currentContext = surfaceContext;
- // Clear the current cached program when the context is switched
- mImpl->programController.ClearCurrentProgram();
+ surfaceFrameBuffer = static_cast<Render::SurfaceFrameBuffer*>( instruction.mFrameBuffer );
+
+ if ( !surfaceFrameBuffer->IsSurfaceValid() )
+ {
+ // Skip rendering the frame buffer if the render surface becomes invalid
+ return;
+ }
+
+ if ( mImpl->currentContext->IsSurfacelessContextSupported() )
+ {
+ Context* surfaceContext = surfaceFrameBuffer->GetContext();
+ if ( mImpl->currentContext != surfaceContext )
+ {
+ // Switch the correct context if rendering to a surface
+ mImpl->currentContext = surfaceContext;
+ surfaceFrameBuffer->MakeContextCurrent();
+
+ // Clear the current cached program when the context is switched
+ mImpl->programController.ClearCurrentProgram();
+ }
+ }
+
+ surfaceRect = Rect<int32_t>( 0, 0, static_cast<int32_t>( surfaceFrameBuffer->GetWidth() ), static_cast<int32_t>( surfaceFrameBuffer->GetHeight() ) );
}
-#endif
+ else
+ {
+ // Switch to shared context for off-screen buffer
+ mImpl->currentContext = &mImpl->context;
- surfaceRect = Rect<int32_t>( 0, 0, static_cast<int32_t>( surfaceFrameBuffer->GetWidth() ), static_cast<int32_t>( surfaceFrameBuffer->GetHeight() ) );
- backgroundColor = surfaceFrameBuffer->GetBackgroundColor();
+ if ( mImpl->currentContext->IsSurfacelessContextSupported() )
+ {
+ mImpl->glContextHelperAbstraction.MakeSurfacelessContextCurrent();
+ }
+ }
}
DALI_ASSERT_DEBUG( mImpl->currentContext->IsGlContextCreated() );
if( instruction.mFrameBuffer )
{
instruction.mFrameBuffer->Bind( *mImpl->currentContext );
+
+ if ( !instruction.mFrameBuffer->IsSurfaceBacked() )
+ {
+ // For each offscreen buffer, update the dependency list with the new texture id used by this frame buffer.
+ Render::TextureFrameBuffer* textureFrameBuffer = static_cast<Render::TextureFrameBuffer*>( instruction.mFrameBuffer );
+ for (unsigned int i0 = 0, i1 = textureFrameBuffer->GetColorAttachmentCount(); i0 < i1; ++i0)
+ {
+ mImpl->textureDependencyList.PushBack( textureFrameBuffer->GetTextureId(i0) );
+ }
+ }
}
else
{
mImpl->currentContext->BindFramebuffer( GL_FRAMEBUFFER, 0u );
}
+
+ if( surfaceFrameBuffer &&
+ partialUpdateAvailable == Integration::PartialUpdateAvailable::TRUE )
+ {
+ // Iterate through each render list.
+ if( surfaceFrameBuffer->IsPartialUpdateEnabled() )
+ {
+ isPartialUpdate = GetDamagedRect( surfaceRect, instruction, damagedRect ) ;
+ }
+
+ if( !isPartialUpdate )
+ {
+ damagedRect = surfaceRect;
+ }
+
+ surfaceFrameBuffer->SetDamagedRect( damagedRect, mergedRect );
+
+ if( mergedRect.IsEmpty() )
+ {
+ isPartialUpdate = false;
+ }
+ else
+ {
+ scissorBox.x = mergedRect.x;
+ scissorBox.y = mergedRect.y;
+ scissorBox.width = mergedRect.width;
+ scissorBox.height = mergedRect.height;
+ }
+ }
+
if ( surfaceFrameBuffer )
{
mImpl->currentContext->Viewport( surfaceRect.x,
surfaceRect.y,
surfaceRect.width,
surfaceRect.height );
-
- mImpl->currentContext->ClearColor( backgroundColor.r,
- backgroundColor.g,
- backgroundColor.b,
- backgroundColor.a );
}
// Clear the entire color, depth and stencil buffers for the default framebuffer, if required.
// It is important to clear all 3 buffers when they are being used, for performance on deferred renderers
// e.g. previously when the depth & stencil buffers were NOT cleared, it caused the DDK to exceed a "vertex count limit",
// and then stall. That problem is only noticeable when rendering a large number of vertices per frame.
-
- mImpl->currentContext->SetScissorTest( false );
-
GLbitfield clearMask = GL_COLOR_BUFFER_BIT;
mImpl->currentContext->ColorMask( true );
clearMask |= GL_STENCIL_BUFFER_BIT;
}
- mImpl->currentContext->Clear( clearMask, Context::FORCE_CLEAR );
-
if( !instruction.mIgnoreRenderToFbo && ( instruction.mFrameBuffer != 0 ) )
{
if ( instruction.mFrameBuffer->IsSurfaceBacked() ) // Surface rendering
// For glViewport the lower-left corner is (0,0)
// For glViewport the lower-left corner is (0,0)
const int32_t y = ( surfaceRect.height - instruction.mViewport.height ) - instruction.mViewport.y;
- viewportRect.Set( instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height );
+ viewportRect.Set( instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height );
}
else
{
{
viewportRect.Set( 0, 0, instruction.mFrameBuffer->GetWidth(), instruction.mFrameBuffer->GetHeight() );
}
+ surfaceOrientation = 0;
}
}
else // No Offscreen frame buffer rendering
{
// For glViewport the lower-left corner is (0,0)
const int32_t y = ( instruction.mFrameBuffer->GetHeight() - instruction.mViewport.height ) - instruction.mViewport.y;
- viewportRect.Set( instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height );
+ viewportRect.Set( instruction.mViewport.x, y, instruction.mViewport.width, instruction.mViewport.height );
}
else
{
}
}
+ bool clearFullFrameRect = true;
+ if( instruction.mFrameBuffer != 0 )
+ {
+ Viewport frameRect( 0, 0, instruction.mFrameBuffer->GetWidth(), instruction.mFrameBuffer->GetHeight() );
+ clearFullFrameRect = ( frameRect == viewportRect );
+ }
+ else
+ {
+ clearFullFrameRect = ( surfaceRect == viewportRect );
+ }
+
+ if ( surfaceOrientation == 90 || surfaceOrientation == 270 )
+ {
+ int temp = viewportRect.width;
+ viewportRect.width = viewportRect.height;
+ viewportRect.height = temp;
+ }
+
mImpl->currentContext->Viewport(viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height);
- if ( instruction.mIsClearColorSet )
+ if( instruction.mIsClearColorSet )
{
mImpl->currentContext->ClearColor( clearColor.r,
clearColor.g,
clearColor.b,
clearColor.a );
- // Clear the viewport area only
- mImpl->currentContext->SetScissorTest( true );
- mImpl->currentContext->Scissor( viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height );
- mImpl->currentContext->ColorMask( true );
- mImpl->currentContext->Clear( GL_COLOR_BUFFER_BIT , Context::CHECK_CACHED_VALUES );
- mImpl->currentContext->SetScissorTest( false );
+ if( !clearFullFrameRect )
+ {
+ mImpl->currentContext->SetScissorTest( true );
+ if( isPartialUpdate )
+ {
+ intersectRect = IntersectAABB( scissorBox, viewportRect );
+ mImpl->currentContext->Scissor( intersectRect.x, intersectRect.y, intersectRect.width, intersectRect.height );
+ }
+ else
+ {
+ mImpl->currentContext->Scissor( viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height );
+ }
+ mImpl->currentContext->Clear( clearMask, Context::FORCE_CLEAR );
+ mImpl->currentContext->SetScissorTest( false );
+ }
+ else
+ {
+ mImpl->currentContext->SetScissorTest( false );
+ mImpl->currentContext->Clear( clearMask, Context::FORCE_CLEAR );
+ }
}
+ // Clear the list of bound textures
+ mImpl->boundTextures.Clear();
+
mImpl->renderAlgorithms.ProcessRenderInstruction(
instruction,
*mImpl->currentContext,
mImpl->renderBufferIndex,
depthBufferAvailable,
- stencilBufferAvailable );
+ stencilBufferAvailable,
+ mImpl->boundTextures,
+ surfaceOrientation,
+ scissorBox );
+
+ // Synchronise the FBO/Texture access when there are multiple contexts
+ if ( mImpl->currentContext->IsSurfacelessContextSupported() )
+ {
+ // Check whether any binded texture is in the dependency list
+ bool textureFound = false;
+
+ if ( mImpl->boundTextures.Count() > 0u && mImpl->textureDependencyList.Count() > 0u )
+ {
+ for ( auto textureId : mImpl->textureDependencyList )
+ {
+
+ textureFound = std::find_if( mImpl->boundTextures.Begin(), mImpl->boundTextures.End(),
+ [textureId]( GLuint id )
+ {
+ return textureId == id;
+ } ) != mImpl->boundTextures.End();
+ }
+ }
+
+ if ( textureFound )
+ {
+
+ if ( !instruction.mFrameBuffer || !instruction.mFrameBuffer->IsSurfaceBacked() )
+ {
+ // For off-screen buffer
+
+ // Wait until all rendering calls for the currently context are executed
+ mImpl->glContextHelperAbstraction.WaitClient();
+
+ // Clear the dependency list
+ mImpl->textureDependencyList.Clear();
+ }
+ else
+ {
+ // For surface-backed frame buffer
+
+ // Worker thread lambda function
+ auto& glContextHelperAbstraction = mImpl->glContextHelperAbstraction;
+ auto workerFunction = [&glContextHelperAbstraction]( int workerThread )
+ {
+ // Switch to the shared context in the worker thread
+ glContextHelperAbstraction.MakeSurfacelessContextCurrent();
+
+ // Wait until all rendering calls for the shared context are executed
+ glContextHelperAbstraction.WaitClient();
+
+ // Must clear the context in the worker thread
+ // Otherwise the shared context cannot be switched to from the render thread
+ glContextHelperAbstraction.MakeContextNull();
+ };
+
+ auto future = mImpl->threadPool->SubmitTask( 0u, workerFunction );
+ if ( future )
+ {
+ mImpl->threadPool->Wait();
+
+ // Clear the dependency list
+ mImpl->textureDependencyList.Clear();
+ }
+ }
+ }
+ }
if( instruction.mRenderTracker && ( instruction.mFrameBuffer != 0 ) )
{
{
surfaceFrameBuffer->PostRender();
}
+ else
+ {
+ mImpl->currentContext->Flush();
+ }
}
} // namespace SceneGraph