From: Brian Paul Date: Mon, 26 Sep 2005 23:06:01 +0000 (+0000) Subject: glDraw/CopyPixels of stencil data didn't obey the stencil write mask. Fixed. X-Git-Tag: 062012170305~21954 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=70c3bebcde336c4cc282bc5dbd33d4180b92771c;p=profile%2Fivi%2Fmesa.git glDraw/CopyPixels of stencil data didn't obey the stencil write mask. Fixed. --- diff --git a/src/mesa/swrast/s_stencil.c b/src/mesa/swrast/s_stencil.c index b465b5a..2c484d5 100644 --- a/src/mesa/swrast/s_stencil.c +++ b/src/mesa/swrast/s_stencil.c @@ -1085,7 +1085,8 @@ _swrast_read_stencil_span(GLcontext *ctx, struct gl_renderbuffer *rb, /** - * Write a span of stencil values to the stencil buffer. + * Write a span of stencil values to the stencil buffer. This function + * applies the stencil write mask when needed. * Used for glDraw/CopyPixels * Input: n - how many pixels * x, y - location of first pixel @@ -1097,6 +1098,8 @@ _swrast_write_stencil_span(GLcontext *ctx, GLint n, GLint x, GLint y, { struct gl_framebuffer *fb = ctx->DrawBuffer; struct gl_renderbuffer *rb = fb->Attachment[BUFFER_STENCIL].Renderbuffer; + const GLuint stencilMax = (1 << fb->Visual.stencilBits) - 1; + const GLuint stencilMask = ctx->Stencil.WriteMask[0]; if (y < 0 || y >= rb->Height || x + n <= 0 || x >= rb->Width) { /* span is completely outside framebuffer */ @@ -1116,7 +1119,20 @@ _swrast_write_stencil_span(GLcontext *ctx, GLint n, GLint x, GLint y, return; } - rb->PutRow(ctx, rb, n, x, y, stencil, NULL); + if ((stencilMask & stencilMax) != stencilMax) { + /* need to apply writemask */ + GLstencil destVals[MAX_WIDTH], newVals[MAX_WIDTH]; + GLint i; + rb->GetRow(ctx, rb, n, x, y, destVals); + for (i = 0; i < n; i++) { + newVals[i] + = (stencil[i] & stencilMask) | (destVals[i] & ~stencilMask); + } + rb->PutRow(ctx, rb, n, x, y, newVals, NULL); + } + else { + rb->PutRow(ctx, rb, n, x, y, stencil, NULL); + } }