+ // 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();