Mesa (7.9): meta: Mask Stencil.Clear against stencilMax in _mesa_meta_Clear
Brian Paul
brianp at kemper.freedesktop.org
Wed Nov 24 19:18:47 UTC 2010
Module: Mesa
Branch: 7.9
Commit: 54047fcd8d769b66fff089972eb4a05e1e9e959c
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=54047fcd8d769b66fff089972eb4a05e1e9e959c
Author: Brian Paul <brianp at vmware.com>
Date: Wed Nov 24 12:16:44 2010 -0700
meta: Mask Stencil.Clear against stencilMax in _mesa_meta_Clear
This fixes incorrect behaviour when the stencil clear value exceeds
the size of the stencil buffer, for example, when set with:
glClearStencil (~1); /* Set a bit pattern of 111...11111110 */
glClear (GL_STENCIL_BUFFER_BIT);
The clear value needs to be masked by the value 2^m - 1, where m is the
number of bits in the stencil buffer. Previously, we passed the value
masked with 0x7fffffff to _mesa_StencilFuncSeparate which then clamps,
NOT masks the value to the range 0 to 2^m - 1.
The result would be clearing the stencil buffer to 0xff, rather than 0xfe.
Signed-off-by: Peter Clifton <pcjc2 at cam.ac.uk>
Signed-off-by: Brian Paul <brianp at vmware.com>
(cherry picked from commit ee88727df8b133e99608e5d30cbd50fb6e11628a)
---
src/mesa/drivers/common/meta.c | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
index a03cb68..20dda5f 100644
--- a/src/mesa/drivers/common/meta.c
+++ b/src/mesa/drivers/common/meta.c
@@ -1385,6 +1385,7 @@ _mesa_meta_Clear(GLcontext *ctx, GLbitfield buffers)
struct vertex verts[4];
/* save all state but scissor, pixel pack/unpack */
GLbitfield metaSave = META_ALL - META_SCISSOR - META_PIXEL_STORE;
+ const GLuint stencilMax = (1 << ctx->DrawBuffer->Visual.stencilBits) - 1;
if (buffers & BUFFER_BITS_COLOR) {
/* if clearing color buffers, don't save/restore colormask */
@@ -1440,7 +1441,7 @@ _mesa_meta_Clear(GLcontext *ctx, GLbitfield buffers)
_mesa_StencilOpSeparate(GL_FRONT_AND_BACK,
GL_REPLACE, GL_REPLACE, GL_REPLACE);
_mesa_StencilFuncSeparate(GL_FRONT_AND_BACK, GL_ALWAYS,
- ctx->Stencil.Clear & 0x7fffffff,
+ ctx->Stencil.Clear & stencilMax,
ctx->Stencil.WriteMask[0]);
}
else {
More information about the mesa-commit
mailing list