opengl - Will memory leak if do multiple glBindBuffers on same buffer object, before call glDeleteBuffers? -


update discovered question duplicate of if call glbufferdata after calling on buffer, there memory leak?

hopefully question still useful someone, give code samples, rather merely mentioning gl function calls, in q&a.


i don't understand relationship between glgenbuffers / glbindbuffer / glbufferdata , gldeletebuffers.

consider drawing sequence of lines (a line strip). original sequence drawn on number of frames, new user input increases number of lines.

my first thought re-use buffer object name assigned glgenbuffers, when size changes. since buffer size needs larger, can't use existing buffer as-is.

note: @ time, rather not assume "maximum size", allocate that, , sub-data calls size need.

consider code based on example: when should call gldeletebuffers()?

if had done these lines in initialization function before drawing first frame (code may not compile -- i'm concerned call sequence, not exact parameters pass -- i'm working in c# under xamarin using opentk access opengl es 2.0, easier find examples in c++ using opengl):

gluint vbo;  void init(int size, float* data) {     glgenbuffers(1, &vbo);     glbindbuffer(gl_array_buffer, vbo);     glbufferdata(gl_array_buffer, size, data, gl_static_draw); } 

which many frames later (or when app exits) released via:

void destroy() {     gldeletebuffers(1, &vbo); } 

but want have "re_init" function allocates different size, need do?

i re-assign new vbo buffer name:

void re_init(newsize, newdata) {     destroy();     init(newsize, newdata); } 

but seems overkill. minimum work can do? , more efficient brute-force destroy/create-a-new-one above?

it seems set of calls works, don't know whether result leaking memory or not. need learn how test memory leaks in environment in, right want theory right, in hopes write code both efficient , non-leaking.

will leak memory?

void re_init(newsize, newdata) {     glbindbuffer(gl_array_buffer, vbo);     glbufferdata(gl_array_buffer, newsize, newdata, gl_static_draw); } 

that is, haven't done gldeletebuffers on old buffer, because doing freed vbo buffer name, , trying find out how not so.

one question whether there way re-use vbo buffer name, data of different size?

or better off sticking simple model of freeing buffer and name every time need change buffer size? (that gldeletebuffers seems do.)

glbufferdata replace content of buffer object - indicated spec/doc, "while creating new storage, pre-existing data store deleted" - won't leak memory.

for efficiency, there many factors consider, , no universal guidelines - suggest profile in application, once have real use case data.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -