+ Rect<int32_t> surfaceRect = mImpl->defaultSurfaceRect;
+ int surfaceOrientation = mImpl->defaultSurfaceOrientation;
+ Vector4 backgroundColor = mImpl->backgroundColor;
+ Integration::DepthBufferAvailable depthBufferAvailable = mImpl->depthBufferAvailable;
+ Integration::StencilBufferAvailable stencilBufferAvailable = mImpl->stencilBufferAvailable;
+ Integration::PartialUpdateAvailable partialUpdateAvailable = mImpl->partialUpdateAvailable;
+
+ Render::SurfaceFrameBuffer* surfaceFrameBuffer = nullptr;
+ if ( instruction.mFrameBuffer != 0 )
+ {
+ if ( instruction.mFrameBuffer->IsSurfaceBacked() )
+ {
+ 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() ) );
+ backgroundColor = surfaceFrameBuffer->GetBackgroundColor();
+ }
+ else
+ {
+ // Switch to shared context for off-screen buffer
+ mImpl->currentContext = &mImpl->context;
+
+ if ( mImpl->currentContext->IsSurfacelessContextSupported() )
+ {
+ mImpl->glContextHelperAbstraction.MakeSurfacelessContextCurrent();
+ }
+ }
+ }
+
+ DALI_ASSERT_DEBUG( mImpl->currentContext->IsGlContextCreated() );