[Mesa-dev] [PATCH 2/2] mesa: Fix glFramebufferTexture(attachment=GL_DEPTH_STENCIL_ATTACHMENT)

Chad Versace chad at chad-versace.us
Tue Nov 1 18:34:28 PDT 2011


Mesa attached the texture only to the depth attachment point
    gl_framebuffer::Attachment[BUFFER_DEPTH]
and failed to attach it to the stencil attachment point
    gl_framebuffer::Attachment[BUFFER_STENCIL]

Fixes Piglit test ARB_framebuffer_object/same-attachment-glFramebufferTexture2D-GL_DEPTH_STENCIL

Signed-off-by: Chad Versace <chad at chad-versace.us>
---
 src/mesa/main/fbobject.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)

diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c
index c56062a..8d69fdf 100644
--- a/src/mesa/main/fbobject.c
+++ b/src/mesa/main/fbobject.c
@@ -2043,6 +2043,25 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
    if (texObj) {
       _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
                                    level, zoffset);
+
+      if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
+	 /* Above we attached the texture to the depth attachment; now attach
+	  * to the stencil attachment. Don't use  _mesa_set_texture_attachment(),
+	  * because it creates a new renderbuffer.
+	  */
+	 struct gl_renderbuffer_attachment *s_att =
+	    &fb->Attachment[BUFFER_STENCIL];
+	 assert(att == &fb->Attachment[BUFFER_DEPTH]);
+	 s_att = &fb->Attachment[BUFFER_STENCIL];
+	 _mesa_remove_attachment(ctx, s_att);
+	 _mesa_reference_texobj(&s_att->Texture, att->Texture);
+	 _mesa_reference_renderbuffer(&s_att->Renderbuffer, att->Renderbuffer);
+	 s_att->Type = att->Type;
+	 s_att->Complete = att->Complete;
+	 s_att->TextureLevel = att->TextureLevel;
+	 s_att->Zoffset = att->Zoffset;
+      }
+
       /* Set the render-to-texture flag.  We'll check this flag in
        * glTexImage() and friends to determine if we need to revalidate
        * any FBOs that might be rendering into this texture.
@@ -2055,6 +2074,10 @@ framebuffer_texture(struct gl_context *ctx, const char *caller, GLenum target,
    }
    else {
       _mesa_remove_attachment(ctx, att);
+      if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
+	 assert(att == &fb->Attachment[BUFFER_DEPTH]);
+	 _mesa_remove_attachment(ctx, &fb->Attachment[BUFFER_STENCIL]);
+      }
    }
 
    invalidate_framebuffer(fb);
-- 
1.7.7



More information about the mesa-dev mailing list