Added _mesa_remove_renderbuffer() as a counterpart to _mesa_add_renderbuffer().
authorBrian Paul <brian.paul@tungstengraphics.com>
Sat, 20 May 2006 15:07:32 +0000 (15:07 +0000)
committerBrian Paul <brian.paul@tungstengraphics.com>
Sat, 20 May 2006 15:07:32 +0000 (15:07 +0000)
Added _mesa_dereference_renderbuffer() to encapsulate renderbuffer
reference count decrement, delete, locking.

src/mesa/main/renderbuffer.c
src/mesa/main/renderbuffer.h

index 0999ed595447231251226234a1365eb8cf4ee759..6b18d60baffa787bf13b9f43fccfbbda2609d294 100644 (file)
@@ -1511,7 +1511,7 @@ _mesa_new_renderbuffer(GLcontext *ctx, GLuint name)
 
 /**
  * Delete a gl_framebuffer.
- * This is the default function for framebuffer->Delete().
+ * This is the default function for renderbuffer->Delete().
  */
 void
 _mesa_delete_renderbuffer(struct gl_renderbuffer *rb)
@@ -2070,9 +2070,58 @@ _mesa_add_renderbuffer(struct gl_framebuffer *fb,
    fb->Attachment[bufferName].Type = GL_RENDERBUFFER_EXT;
    fb->Attachment[bufferName].Complete = GL_TRUE;
    fb->Attachment[bufferName].Renderbuffer = rb;
+
+   rb->RefCount++;
+}
+
+
+/**
+ * Remove the named renderbuffer from the given framebuffer.
+ */
+void
+_mesa_remove_renderbuffer(struct gl_framebuffer *fb, GLuint bufferName)
+{
+   struct gl_renderbuffer *rb;
+
+   assert(bufferName < BUFFER_COUNT);
+
+   rb = fb->Attachment[bufferName].Renderbuffer;
+   if (!rb)
+      return;
+
+   _mesa_dereference_renderbuffer(&rb);
+
+   fb->Attachment[bufferName].Renderbuffer = NULL;
 }
 
 
+/**
+ * Decrement the reference count on a renderbuffer and delete it when
+ * the refcount hits zero.
+ * Note: we pass the address of a pointer and set it to NULL if we delete it.
+ */
+void
+_mesa_dereference_renderbuffer(struct gl_renderbuffer **rb)
+{
+   GLboolean deleteFlag = GL_FALSE;
+
+   _glthread_LOCK_MUTEX((*rb)->Mutex);
+   {
+      ASSERT((*rb)->RefCount > 0);
+      (*rb)->RefCount--;
+      deleteFlag = ((*rb)->RefCount == 0);
+   }
+   _glthread_UNLOCK_MUTEX((*rb)->Mutex);
+
+   if (deleteFlag) {
+      (*rb)->Delete(*rb);
+      *rb = NULL;
+   }
+}
+
+
+
+
 /**
  * Create a new combined depth/stencil renderbuffer for implementing
  * the GL_EXT_packed_depth_stencil extension.
index d8358e213cb4039eac085f10146737cfdbc51864..74ca43c57abf769abbe08db140d3dc912e4f3deb 100644 (file)
@@ -95,6 +95,11 @@ extern void
 _mesa_add_renderbuffer(struct gl_framebuffer *fb,
                        GLuint bufferName, struct gl_renderbuffer *rb);
 
+extern void
+_mesa_remove_renderbuffer(struct gl_framebuffer *fb, GLuint bufferName);
+
+extern void
+_mesa_dereference_renderbuffer(struct gl_renderbuffer **rb);
 
 extern struct gl_renderbuffer *
 _mesa_new_depthstencil_renderbuffer(GLcontext *ctx, GLuint name);