+ surfaceRect = Rect<int32_t>( 0, 0, static_cast<int32_t>( scene.GetSize().width ), static_cast<int32_t>( scene.GetSize().height ) );
+ }
+
+ 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 );
+
+ // For each offscreen buffer, update the dependency list with the new texture id used by this frame buffer.
+ for (unsigned int i0 = 0, i1 = instruction.mFrameBuffer->GetColorAttachmentCount(); i0 < i1; ++i0)
+ {
+ mImpl->textureDependencyList.PushBack( instruction.mFrameBuffer->GetTextureId(i0) );
+ }
+ }
+ else
+ {
+ mImpl->currentContext->BindFramebuffer( GL_FRAMEBUFFER, 0u );
+ }
+
+ if ( !instruction.mFrameBuffer )
+ {
+ mImpl->currentContext->Viewport( surfaceRect.x,
+ surfaceRect.y,
+ surfaceRect.width,
+ surfaceRect.height );
+ }
+
+ // 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.
+ 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;
+ }
+
+ if( !instruction.mIgnoreRenderToFbo && ( instruction.mFrameBuffer != 0 ) )
+ {
+ // Offscreen buffer rendering
+ if ( instruction.mIsViewportSet )
+ {
+ // 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 );
+ }
+ else
+ {
+ viewportRect.Set( 0, 0, instruction.mFrameBuffer->GetWidth(), instruction.mFrameBuffer->GetHeight() );
+ }
+ surfaceOrientation = 0;
+ }
+ else // No Offscreen frame buffer rendering