If you call glBufferData after you already call it in the buffer, is there a memory leak?

Since I thought that this would have to place a buffer, if you call it twice, the old one is deleted, or is there a memory leak?

I am trying to solve the best option for frequently resizing the buffer as needed. Best to use glBufferData? I think so, there is no leak.

+7
opengl
source share
3 answers

The OGL documentation says: "glBufferData creates and initializes a new data store. Any pre-existing data store associated with the destination buffer will be deleted." See: http://www.opengl.org/sdk/docs/man/xhtml/glBufferData.xml

Thus, when glBufferData is called, there will be no memory leaks. Of course, null298 was right, and you should call glDeleteBuffer to finally free up memory allocated for the target.

+11
source share

glBufferData (...) will create a new data store, and any command queuing in the pipeline that used the old data store is implicitly protected by GL. That is, until all the commands that used the old VBO data are finished, GL is not allowed to delete the old data stores. This is an important concept, as it can be useful for the β€œorphan buffer” method, where you redistribute VBO when it sends new data to reduce the GL synchronization overhead when updating data in VBO, which is currently used for drawing.

Nothing will happen, and in some special cases (for example, streaming a buffer), reallocating the data store for the VBO used may be more efficient than updating it. The ability to map and deselect buffer ranges in newer versions of GL has greatly softened this optimization strategy, but still needs to be considered.

+3
source share

Call glDeleteBuffers glDeleteBuffers API

However, I would not recommend changing the buffer size frequently. Instead, if you need to change the data in the buffer, just select the large buffer, pack it with the necessary data, and note that you can dereference the buffer safely and use only those parts of the buffer.

Constant allocation and deletion of the OpenGL buffer is slow. I would suggest that this is much slower than just adjusting your data, since you must have a circular trip from the GPU to the CPU to give you a new buffer pointer on the GPU, and then you should send the data back to the GPU and THEN , you must send another round-trip call to delete the buffer. So 3 rides!

I mean, every time you allocate arrays in C ++, are you constantly new and delete array every time you fill it or recycle it?

+2
source share

All Articles