From d0f13fa7d70c57e698cce9fbde399e80f7afcf47 Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Wed, 21 Jan 2009 11:17:45 -0700 Subject: mesa: fix some renderbuffer/framebuffer delete semantics Need to unbind buffers if referenced by the current read/draw pointers when being deleted. --- src/mesa/main/fbobject.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'src/mesa') diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c index 73f891d5328..85e15a6e94b 100644 --- a/src/mesa/main/fbobject.c +++ b/src/mesa/main/fbobject.c @@ -683,6 +683,26 @@ _mesa_BindRenderbufferEXT(GLenum target, GLuint renderbuffer) } +/** + * If the given renderbuffer is anywhere attached to the framebuffer, detach + * the renderbuffer. + * This is used when a renderbuffer object is deleted. + * The spec calls for unbinding. + */ +static void +detach_renderbuffer(GLcontext *ctx, + struct gl_framebuffer *fb, + struct gl_renderbuffer *rb) +{ + GLuint i; + for (i = 0; i < BUFFER_COUNT; i++) { + if (fb->Attachment[i].Renderbuffer == rb) { + _mesa_remove_attachment(ctx, &fb->Attachment[i]); + } + } +} + + void GLAPIENTRY _mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers) { @@ -704,6 +724,13 @@ _mesa_DeleteRenderbuffersEXT(GLsizei n, const GLuint *renderbuffers) _mesa_BindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0); } + if (ctx->DrawBuffer->Name) { + detach_renderbuffer(ctx, ctx->DrawBuffer, rb); + } + if (ctx->ReadBuffer->Name && ctx->ReadBuffer != ctx->DrawBuffer) { + detach_renderbuffer(ctx, ctx->ReadBuffer, rb); + } + /* Remove from hash table immediately, to free the ID. * But the object will not be freed until it's no longer * referenced anywhere else. @@ -1201,7 +1228,12 @@ _mesa_DeleteFramebuffersEXT(GLsizei n, const GLuint *framebuffers) if (fb == ctx->DrawBuffer) { /* bind default */ ASSERT(fb->RefCount >= 2); - _mesa_BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); + _mesa_BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0); + } + if (fb == ctx->ReadBuffer) { + /* bind default */ + ASSERT(fb->RefCount >= 2); + _mesa_BindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0); } /* remove from hash table immediately, to free the ID */ -- cgit v1.2.3