Sign in to follow this  
spock83

Necessary to unbind and delete buffers?

Recommended Posts

Most examples I have seen on buffer usage (PBO, FBO, VBO) unbinds the buffer after usage. E.g.

glBindBuffer(..., buffer1);
...
glBindBuffer(..., 0);
...
glBindBuffer(..., buffer2);

The second glBindBuffer() seems redundant. Is it OK and advisable to skip the second glBindBuffer()? As long as I'm aware that the buffer1 is still bound until I bind buffer2, there is no need to unbind buffer1 right?

Also, is it necessary to delete buffers when my program exits? The OS or GPU driver should automatically clean it up right?

Share this post


Link to post
Share on other sites
Quote:
Original post by spock83
Most examples I have seen on buffer usage (PBO, FBO, VBO) unbinds the buffer after usage. E.g.

glBindBuffer(..., buffer1);
...
glBindBuffer(..., 0);
...
glBindBuffer(..., buffer2);

The second glBindBuffer() seems redundant. Is it OK and advisable to skip the second glBindBuffer()? As long as I'm aware that the buffer1 is still bound until I bind buffer2, there is no need to unbind buffer1 right?

There's no need to unbind a buffer before binding a new one, no. Except for within a local context, I would personally advise against leaving with a different state than when you entered. Thus, restore what you set before you leave to ensure there are no settings being in a conceptually undefined state in some other place in your program.

Quote:
Original post by spock83
Also, is it necessary to delete buffers when my program exits? The OS or GPU driver should automatically clean it up right?

If your question is whether you're not going to free what you allocate just because you don't have to, then I my personal advise is to ensure that resources clean up after themselves so you don't have to worry about it in the first place.

This question really isn't only about what to do when exiting the program. Technically, yes, your resources will be freed. But from a design point of view, you will have the same problem when, for example, loading a new level. Will the resources automatically be freed if you exit the previous level and load a new one? No, they will leak. If you handle that problem properly, you will also handle the problem of freeing your resources when exiting automatically. Destructors in C++ for example can automatically free your resources.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this