+#endif
+
+ surfaceRect = Rect<int32_t>( 0, 0, static_cast<int32_t>( surfaceFrameBuffer->GetWidth() ), static_cast<int32_t>( surfaceFrameBuffer->GetHeight() ) );
+ backgroundColor = surfaceFrameBuffer->GetBackgroundColor();
+ }
+
+ DALI_ASSERT_DEBUG( mImpl->currentContext->IsGlContextCreated() );
+
+ // reset the program matrices for all programs once per frame
+ // this ensures we will set view and projection matrix once per program per camera
+ mImpl->programController.ResetProgramMatrices();
+
+ if( instruction.mFrameBuffer )
+ {
+ instruction.mFrameBuffer->Bind( *mImpl->currentContext );
+ }
+
+ 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 );
+
+ if( depthBufferAvailable == Integration::DepthBufferAvailable::TRUE )
+ {
+ mImpl->currentContext->DepthMask( true );
+ clearMask |= GL_DEPTH_BUFFER_BIT;
+ }
+
+ if( stencilBufferAvailable == Integration::StencilBufferAvailable::TRUE)
+ {
+ mImpl->currentContext->ClearStencil( 0 );
+ mImpl->currentContext->StencilMask( 0xFF ); // 8 bit stencil mask, all 1's
+ clearMask |= GL_STENCIL_BUFFER_BIT;
+ }
+
+ mImpl->currentContext->Clear( clearMask, Context::FORCE_CLEAR );
+
+ if( !instruction.mIgnoreRenderToFbo && ( instruction.mFrameBuffer != 0 ) )
+ {
+ if ( instruction.mFrameBuffer->IsSurfaceBacked() ) // Surface rendering
+ {
+ if ( instruction.mIsViewportSet )
+ {
+ // 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 );
+ }
+ else
+ {
+ viewportRect = surfaceRect;
+ }
+ }
+ else // Offscreen buffer rendering