jmasterx
jmasterx

Reputation: 54103

Does this cause a memory leak?

I create my VBO like this:

glGenBuffersARB(1,&polyvbo);

    glBindBufferARB(GL_ARRAY_BUFFER_ARB,polyvbo);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB,sizeof(GLfloat) * tempvct.size(),&tempvct[0],GL_DYNAMIC_COPY);

Then to update it I just do the same thing:

    glBindBufferARB(GL_ARRAY_BUFFER_ARB,polyvbo);
    glBufferDataARB(GL_ARRAY_BUFFER_ARB,sizeof(GLfloat) * tempvct.size(),&tempvct[0],GL_DYNAMIC_COPY);

(needless to say, the data in tempvct changes)

I'm just wondering if the above produces a memory leak. do I need to delete the vbo and recreate it, or will it automatically delete the old and update?

Thanks

Upvotes: 3

Views: 469

Answers (3)

shoosh
shoosh

Reputation: 78914

It doesn't cause a memory leak because the buffer is not reallocated.

But why not use glBufferSubData()? it will probably be much faster and does basically the same thing.

Upvotes: 4

Secure
Secure

Reputation: 4368

I've entered "glBufferDataARB" into Google and found this as the first hit:

http://www.songho.ca/opengl/gl_vbo.html

I suggest you read it. As I understand it, glGenBuffersARB creates the buffer objects and glDeleteBuffersARB destroys them, so the other two functions simply reuse the existing buffer without modifying its allocation.

Upvotes: 0

Related Questions