PDA

View Full Version : reallocation buffer without clearing it



john_connor
06-14-2016, 07:34 PM
hi,

i have a buffer and i dont know from the beginning how much data it will need
so i decided to dynamically allocate / reallocate it with a little bit more (50%) of the (currently) requested size
but i've figured out that every time i realllocate the buffer, opengl clears its previous content

how can i solve this problem without manually copying all te previous data back and forth ???

Alfonse Reinheart
06-14-2016, 09:18 PM
1: You could keep all the previous data stored locally.

2: You could stop doing this entirely. It's always best to allocate what you need up-front. If you're not sure how much that will be, allocate as much as you reasonably think you'll ever use. And if you need to use more than that... then have the application terminate.

Most high-performance applications pick #2 whenever possible.

mhagain
06-15-2016, 03:19 AM
If the buffer is used for storing more than 1 object, option 3 is to just allocate another buffer.

john_connor
06-15-2016, 05:05 AM
ok, thx for your answers, i'll go for #1, soring temporarily all vertices ...
it just happens once at initialization, when i load all the models (and i dont know how much / big they are)

mhagain
06-15-2016, 06:33 AM
it just happens once at initialization, when i load all the models (and i dont know how much / big they are)

This is a problem that you should solve in how you load your models rather than how you put your data into a buffer. For example, as you load each model, you load it's data to system memory and accumulate a total size, then when done you allocate a buffer object big enough, copy them over, then free the system memory copies. In other words it's two passes through your models rather than one, but doing so gives you the info you need to allocate an appropriately sized buffer object.