public override void ClearFrameBuffer( FrameBufferType buffers, ColorEx color, float depth, int stencil )
{
bool colorMask = !_colorWrite[ 0 ] || !_colorWrite[ 1 ] || !_colorWrite[ 2 ] || !_colorWrite[ 3 ];
int flags = 0;
if ( ( buffers & FrameBufferType.Color ) != 0 )
{
flags |= (int)All.ColorBufferBit;
// Enable buffer for writing if it isn't
if ( colorMask )
{
OpenGL.ColorMask( true, true, true, true );
GLESConfig.GlCheckError( this );
}
OpenGL.ClearColor( color.r, color.g, color.b, color.a );
GLESConfig.GlCheckError( this );
}
if ( ( buffers & FrameBufferType.Depth ) != 0 )
{
flags |= (int)All.DepthBufferBit;
// Enable buffer for writing if it isn't
if ( !depthWrite )
{
OpenGL.DepthMask( true );
GLESConfig.GlCheckError( this );
}
OpenGL.ClearDepth( depth );
GLESConfig.GlCheckError( this );
}
if ( ( buffers & FrameBufferType.Stencil ) != 0 )
{
flags |= (int)All.StencilBufferBit;
// Enable buffer for writing if it isn't
OpenGL.StencilMask( 0xFFFFFFFF );
GLESConfig.GlCheckError( this );
OpenGL.ClearStencil( stencil );
GLESConfig.GlCheckError( this );
}
// Should be enable scissor test due the clear region is
// relied on scissor box bounds.
bool scissorTestEnabled = OpenGL.IsEnabled( All.ScissorTest );
GLESConfig.GlCheckError( this );
if ( !scissorTestEnabled )
{
OpenGL.Enable( All.ScissorTest );
GLESConfig.GlCheckError( this );
}
// Sets the scissor box as same as viewport
unsafe
{
int[] viewport = new int[ 4 ];
int[] scissor = new int[ 4 ];
//OpenGL.GetInteger(All.Viewport, viewport);
GLESConfig.GlCheckError( this );
//OpenGL.GetInteger(All.ScissorBox, scissor);
GLESConfig.GlCheckError( this );
bool scissorBoxDifference =
viewport[ 0 ] != scissor[ 0 ] || viewport[ 1 ] != scissor[ 1 ] ||
viewport[ 2 ] != scissor[ 2 ] || viewport[ 3 ] != scissor[ 3 ];
if ( scissorBoxDifference )
{
OpenGL.Scissor( viewport[ 0 ], viewport[ 1 ], viewport[ 2 ], viewport[ 3 ] );
GLESConfig.GlCheckError( this );
}
//clear buffers
OpenGL.Clear( flags );
GLESConfig.GlCheckError( this );
//restore scissor box
if ( scissorBoxDifference )
{
OpenGL.Scissor( scissor[ 0 ], scissor[ 1 ], scissor[ 2 ], scissor[ 3 ] );
GLESConfig.GlCheckError( this );
}
}
// Restore scissor test
if ( !scissorTestEnabled )
{
OpenGL.Disable( All.ScissorTest );
GLESConfig.GlCheckError( this );
}
// Reset buffer write state
if ( !depthWrite && ( ( buffers & FrameBufferType.Depth ) != 0 ) )
{
OpenGL.DepthMask( false );
GLESConfig.GlCheckError( this );
}
if ( colorMask && ( ( buffers & FrameBufferType.Color ) != 0 ) )
{
OpenGL.ColorMask( _colorWrite[ 0 ], _colorWrite[ 1 ], _colorWrite[ 2 ], _colorWrite[ 3 ] );
GLESConfig.GlCheckError( this );
}
if ( ( buffers & FrameBufferType.Stencil ) != 0 )
{
OpenGL.StencilMask( _stencilMask );
GLESConfig.GlCheckError( this );
}
}