+ 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)
+ {
+ 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( isPartialUpdate )
+ {
+ mImpl->currentContext->SetScissorTest( false );
+ }
+
+
+ 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
+ {
+ 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
+ {