+ // switch rendering to adaptor provided (default) buffer
+ mImpl->context.BindFramebuffer( GL_FRAMEBUFFER, 0 );
+
+ mImpl->context.Viewport( mImpl->defaultSurfaceRect.x,
+ mImpl->defaultSurfaceRect.y,
+ mImpl->defaultSurfaceRect.width,
+ mImpl->defaultSurfaceRect.height );
+
+ mImpl->context.ClearColor( mImpl->backgroundColor.r,
+ mImpl->backgroundColor.g,
+ mImpl->backgroundColor.b,
+ mImpl->backgroundColor.a );
+
+ mImpl->context.ClearStencil( 0 );
+
+ // Clear the entire color, depth and stencil buffers for the default framebuffer.
+ // It is important to clear all 3 buffers, for performance on deferred renderers like Mali
+ // 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->context.SetScissorTest( false );
+ mImpl->context.ColorMask( true );
+ mImpl->context.DepthMask( true );
+ mImpl->context.StencilMask( 0xFF ); // 8 bit stencil mask, all 1's
+ mImpl->context.Clear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, Context::FORCE_CLEAR );
+
+ // 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();
+
+ size_t count = mImpl->instructions.Count( mImpl->renderBufferIndex );
+ for ( size_t i = 0; i < count; ++i )