+ clearFullFrameRect = ( surfaceRect == viewportRect );
+ }
+
+ mImpl->currentContext->Viewport(viewportRect.x, viewportRect.y, viewportRect.width, viewportRect.height);
+
+ if( instruction.mIsClearColorSet )
+ {
+ mImpl->currentContext->ClearColor( clearColor.r,
+ clearColor.g,
+ clearColor.b,
+ clearColor.a );
+
+ if( !clearFullFrameRect )
+ {
+ mImpl->currentContext->SetScissorTest( true );
+ 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,
+ mImpl->boundTextures,
+ surfaceOrientation );
+
+ // 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 )
+ {
+ // 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
+ {
+ // 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 )
+ {
+ // This will create a sync object every frame this render tracker
+ // is alive (though it should be now be created only for
+ // render-once render tasks)
+ instruction.mRenderTracker->CreateSyncObject( mImpl->glSyncAbstraction );
+ instruction.mRenderTracker = nullptr; // Only create once.
+ }
+
+ if ( renderToFbo )
+ {
+ mImpl->currentContext->Flush();