- _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
- level, zoffset);
+ if (attachment == GL_DEPTH_ATTACHMENT &&
+ texObj == fb->Attachment[BUFFER_STENCIL].Texture) {
+ /* The texture object is already attached to the stencil attachment
+ * point. Don't create a new renderbuffer; just reuse the stencil
+ * attachment's. This is required to prevent a GL error in
+ * glGetFramebufferAttachmentParameteriv(GL_DEPTH_STENCIL).
+ */
+ reuse_framebuffer_texture_attachment(fb, BUFFER_DEPTH,
+ BUFFER_STENCIL);
+ } else if (attachment == GL_STENCIL_ATTACHMENT &&
+ texObj== fb->Attachment[BUFFER_DEPTH].Texture) {
+ /* As above, but with depth and stencil juxtasposed. */
+ reuse_framebuffer_texture_attachment(fb, BUFFER_STENCIL,
+ BUFFER_DEPTH);
+ } else {
+ _mesa_set_texture_attachment(ctx, fb, att, texObj, textarget,
+ level, zoffset);
+ if (attachment == GL_DEPTH_STENCIL_ATTACHMENT) {
+ /* Above we created a new renderbuffer and attached it to the
+ * depth attachment point. Now attach it to the stencil attachment
+ * point too.
+ */
+ assert(att == &fb->Attachment[BUFFER_DEPTH]);
+ reuse_framebuffer_texture_attachment(fb,BUFFER_STENCIL,
+ BUFFER_DEPTH);
+ }
+ }
+