From fd104a84591ae854c5d6adc81e2dc31ef6ab9e8a Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Sat, 24 Dec 2011 08:54:25 -0700 Subject: swrast: do depth/stencil clearing with Map/UnmapRenderbuffer() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Another step toward getting rid of the renderbuffer PutRow/etc functions. v2: fix assorted depth/stencil clear bugs found by Eric Reviewed-by: José Fonseca --- src/mesa/swrast/s_clear.c | 49 +++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) (limited to 'src/mesa/swrast/s_clear.c') diff --git a/src/mesa/swrast/s_clear.c b/src/mesa/swrast/s_clear.c index 851f6d16567..35663700535 100644 --- a/src/mesa/swrast/s_clear.c +++ b/src/mesa/swrast/s_clear.c @@ -195,6 +195,8 @@ clear_color_buffers(struct gl_context *ctx) void _swrast_Clear(struct gl_context *ctx, GLbitfield buffers) { + const GLbitfield BUFFER_DS = BUFFER_BIT_DEPTH | BUFFER_BIT_STENCIL; + #ifdef DEBUG_FOO { const GLbitfield legalBits = @@ -216,24 +218,39 @@ _swrast_Clear(struct gl_context *ctx, GLbitfield buffers) if (SWRAST_CONTEXT(ctx)->NewState) _swrast_validate_derived(ctx); - swrast_render_start(ctx); + if ((buffers & BUFFER_BITS_COLOR) + && (ctx->DrawBuffer->_NumColorDrawBuffers > 0)) { + /* XXX remove the swrast_render_start/finish() calls after + * clear_color_buffers() is converted to use Map/UnmapRenderbuffer() + * The other clearing functions don't need these calls. + */ + swrast_render_start(ctx); + clear_color_buffers(ctx); + swrast_render_finish(ctx); + } - /* do software clearing here */ - if (buffers) { - if ((buffers & BUFFER_BITS_COLOR) - && (ctx->DrawBuffer->_NumColorDrawBuffers > 0)) { - clear_color_buffers(ctx); - } - if (buffers & BUFFER_BIT_DEPTH) { - _swrast_clear_depth_buffer(ctx, ctx->DrawBuffer->_DepthBuffer); - } - if (buffers & BUFFER_BIT_ACCUM) { - _mesa_clear_accum_buffer(ctx); + if (buffers & BUFFER_BIT_ACCUM) { + _mesa_clear_accum_buffer(ctx); + } + + if (buffers & BUFFER_DS) { + struct gl_renderbuffer *depthRb = + ctx->DrawBuffer->Attachment[BUFFER_DEPTH].Renderbuffer; + struct gl_renderbuffer *stencilRb = + ctx->DrawBuffer->Attachment[BUFFER_STENCIL].Renderbuffer; + + if ((buffers & BUFFER_DS) == BUFFER_DS && depthRb == stencilRb) { + /* clear depth and stencil together */ + _swrast_clear_depth_stencil_buffer(ctx); } - if (buffers & BUFFER_BIT_STENCIL) { - _swrast_clear_stencil_buffer(ctx, ctx->DrawBuffer->_StencilBuffer); + else { + /* clear depth, stencil separately */ + if (buffers & BUFFER_BIT_DEPTH) { + _swrast_clear_depth_buffer(ctx); + } + if (buffers & BUFFER_BIT_STENCIL) { + _swrast_clear_stencil_buffer(ctx); + } } } - - swrast_render_finish(ctx); } -- cgit v1.2.3