[mutter] cogl/clip-stack-gl: Set glStencilMask correctly for clip regions



commit 216bb7f96014a140a0659db6c7bbaddc6b8335db
Author: Daniel van Vugt <daniel van vugt canonical com>
Date:   Thu May 20 17:39:44 2021 +0800

    cogl/clip-stack-gl: Set glStencilMask correctly for clip regions
    
    Previously we were using a mask of 0x1 for the lifetime of the stencil.
    This was wrong for two reasons:
    
      * The intersection algorithm needs to count up to a maximum 2, so a
        mask of 1 would clamp to 1 instead. Then decrementing all pixels
        resulted in all pixels being zero even though we want some to be 1.
        So the stencil then blocked some color buffer pixels being rendered.
    
      * The lifetime of the mask was too long. By leaving it non-zero at
        the end of the function we could accidentally end up modifying the
        stencil contents during our later color buffer paints.
    
    This fixes faulty rendering of some actors seen in gnome-shell with
    test case: `env COGL_DEBUG=stencilling`
    
    Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1873>

 cogl/cogl/driver/gl/cogl-clip-stack-gl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/cogl/cogl/driver/gl/cogl-clip-stack-gl.c b/cogl/cogl/driver/gl/cogl-clip-stack-gl.c
index c2cccf0ee0..a693903b3c 100644
--- a/cogl/cogl/driver/gl/cogl-clip-stack-gl.c
+++ b/cogl/cogl/driver/gl/cogl-clip-stack-gl.c
@@ -158,6 +158,7 @@ add_stencil_clip_region (CoglFramebuffer *framebuffer,
 
   GE( ctx, glColorMask (FALSE, FALSE, FALSE, FALSE) );
   GE( ctx, glDepthMask (FALSE) );
+  GE( ctx, glStencilMask (0x3) );
 
   if (merge)
     {
@@ -167,7 +168,6 @@ add_stencil_clip_region (CoglFramebuffer *framebuffer,
   else
     {
       GE( ctx, glEnable (GL_STENCIL_TEST) );
-      GE( ctx, glStencilMask (0x1) );
 
       /* Initially disallow everything */
       GE( ctx, glClearStencil (0) );
@@ -240,6 +240,7 @@ add_stencil_clip_region (CoglFramebuffer *framebuffer,
   /* Restore the stencil mode */
   GE (ctx, glDepthMask (TRUE));
   GE (ctx, glColorMask (TRUE, TRUE, TRUE, TRUE));
+  GE( ctx, glStencilMask (0x0) );
   GE( ctx, glStencilFunc (GL_EQUAL, 0x1, 0x1) );
   GE( ctx, glStencilOp (GL_KEEP, GL_KEEP, GL_KEEP) );
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]