+
+ 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 );
+
+ if ( !instruction.mFrameBuffer->IsSurfaceBacked() )
+ {
+ // For each offscreen buffer, update the dependency list with the new texture id used by this frame buffer.
+ Render::TextureFrameBuffer* textureFrameBuffer = static_cast<Render::TextureFrameBuffer*>( instruction.mFrameBuffer );
+ mImpl->textureDependencyList.PushBack( textureFrameBuffer->GetTextureId() );
+ }
+ }
+ else
+ {
+ mImpl->currentContext->BindFramebuffer( GL_FRAMEBUFFER, 0u );
+ }
+
+
+ if( surfaceFrameBuffer &&
+ partialUpdateAvailable == Integration::PartialUpdateAvailable::TRUE )
+ {
+ const RenderListContainer::SizeType renderListCount = instruction.RenderListCount();
+ // Iterate through each render list.
+ if( surfaceFrameBuffer->IsPartialUpdateEnabled() )
+ {
+ isPartialUpdate = GetDamagedRect( surfaceRect, instruction, damagedRect ) ;
+ }
+
+ if( !isPartialUpdate )
+ {
+ damagedRect = surfaceRect;
+ }
+
+ mergedRect = surfaceFrameBuffer->SetDamagedRect( damagedRect );
+
+ if( mergedRect.IsEmpty() )
+ {
+ isPartialUpdate = false;
+ }
+ else
+ {
+ scissorBox.x = mergedRect.x;
+ scissorBox.y = mergedRect.y;
+ scissorBox.width = mergedRect.width;
+ scissorBox.height = mergedRect.height;
+ }
+ }
+
+ if ( surfaceFrameBuffer )
+ {
+ 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 );
+
+ if( isPartialUpdate )
+ {
+ mImpl->currentContext->SetScissorTest( true );
+ mImpl->currentContext->Scissor( scissorBox.x, scissorBox.y, scissorBox.width, scissorBox.height );
+ }
+
+ 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)