O-BL
O-BL

Reputation: 325

usage of glbufferdata in OpenGL

let's say that I have the vbo id stored in an int, and I want to resize that buffer; what would I do?
1st choice: use glbufferdata function after binding the buffer.
2nd choice:.use gldeletebuffers then regenerate the buffer and use glbufferdata function after binding the buffer.

So my question is does glbufferdata deallocate the buffer by it self or it didn't?

Upvotes: 1

Views: 1151

Answers (2)

Nicol Bolas
Nicol Bolas

Reputation: 473397

Is it legal OpenGL to re-allocate the storage of a buffer object with a different size? Yes. Is it a good idea? Well, consider this.

OpenGL has a new(ish) way to allocate storage for a buffer: glBufferStorage. It allocates "immutable" storage. So called because, once allocated, you cannot re-allocate it.

The people behind OpenGL would not have added this immutable buffer allocation method if they thought that reallocating the storage of a buffer object was a good idea.

Upvotes: 1

Dietrich Epp
Dietrich Epp

Reputation: 213328

Just call glBufferData. The glDeleteBuffers / glGenBuffers calls are unnecessary.

Think about it this way: glBufferData creates a new buffer. The glGenBuffers function creates a new name (integer) for a bufffer.

You don't need to deallocate the buffer yourself… not that OpenGL gives you a way to do that. Your OpenGL implementation will do that for you after it is done using the data in the buffer, as long as you don't hold a reference to it.

Upvotes: 1

Related Questions