[Mesa-dev] [RFC][PATCH] vbo: do not restore all the arrayobj stuff if the bufobj is deleted

Brian Paul brianp at vmware.com
Thu Sep 29 08:58:18 PDT 2011

On 09/29/2011 03:43 AM, Yuanhan Liu wrote:
> I hope I can find something from OpenGL spec to support this. Badly, I
> didn't make it with a simply searching.
> Basically, it's an issue that should we restore all the arrayobj stuff
> if the bufobj is deleted? Say, in a following case:
>      glGenBuffersARB(2, bufname);
>      glBindBufferARB(GL_ARRAY_BUFFER_ARB, bufname[1]);
>      glBindBufferARB(GL_ARRAY_BUFFER_ARB, bufname[0]);
>      glVertexPointer(2, GL_INT, 0, NULL);
>      glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
>      glDeleteBuffersARB(1, bufname);  /* This would delete bufname[0] */
>      glPopClientAttrib();
> Then what's the expected value of the following two queries:
>      glGetIntegerv(GL_ARRAY_BUFFER_BINDING_ARB,&val1);
>      glGetIntegerv(GL_VERTEX_ARRAY_BUFFER_BINDING_ARB,&val2);
> The old code would make val1 and val2 both to be bufname[0]. Well, this
> patch keep the val1 but let the val2 to be 0.
> I know this patch is ugly, but I'd heard about your comments?

Buffer objects are reference counted so the glDeleteBuffersARB() call 
wouldn't really delete the buffer since it should be referenced by 
something saved by glPushClientAttrib().

Looking at attrib.c, we're fudging the reference counts but it's not 
handling the case of deleting the buffer object between 
glPushClientAttrib() and the Pop() because while we're decrementing 
the refcounts in Pop(), we're not freeing the arrays if the refcount 
hits zero.

I'm attaching the beginnings of a patch to do the reference counting 
properly.  Maybe you can take this and do the rest?

I'm also attaching a simple piglit test.  It passes with NVIDIA's 
driver but fails with Mesa.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: attrib.c.patch
Type: application/pgp-keys
Size: 2600 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110929/f4f44a98/attachment.key>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bufferobj-push-pop.c
Type: text/x-csrc
Size: 831 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20110929/f4f44a98/attachment.c>

More information about the mesa-dev mailing list