Simple curiosity about OpenGL VBO allocation -


i have written simple graphic engine using opengl , glsl. until here, when needed create new mesh scene node created vao, vbo , ibo each mesh. loaded vertex attributes each mesh way:

glbufferdata(gl_array_buffer, this->getverticesbytesize(vertex_position)         + this->getverticesbytesize(vertex_texture) + this->getverticesbytesize(vertex_normal), null, this->m_usage);     glbuffersubdata(gl_array_buffer, 0, this->getverticesbytesize(vertex_position), &this->m_vertexbuffer[vertex_position][0]);     if (!this->m_vertexbuffer[vertex_texture].empty())         glbuffersubdata(gl_array_buffer, this->getverticesbytesize(vertex_position),             this->getverticesbytesize(vertex_texture), &this->m_vertexbuffer[vertex_texture][0]);     if (!this->m_vertexbuffer[vertex_normal].empty())         glbuffersubdata(gl_array_buffer, this->getverticesbytesize(             vertex_position) + this->getverticesbytesize(vertex_texture),                 this->getverticesbytesize(vertex_normal), &this->m_vertexbuffer[vertex_normal][0]); 

but if scene composed lot of meshes it's not correct performance (too many state changes). so, decided create unique vao, vbo , ibo (singleton classes) geometry of scene.

the way following :

load vertex attributes in specific class (let's call 'vertexattributes') each mesh. after meshes loaded can allocate big vertex buffer in unique vbo. above call in first function 'glbufferdata' allocate whole memory size of vertex attributes in scene , after call function 'glbuffersubdata' each kind of vertex attribute in loop.

but possible call glbufferdata several times (for each mesh) , fill vbo during scene loading (step step each mesh). looks realloc. possible opengl or first method 1 ?

but possible call glbufferdata several times (for each mesh) , fill vbo during scene loading (step step each mesh). looks realloc. possible opengl or first method 1 ?

no. whenever call glbufferdata, new data storage (with new size created, , previous contents lost.

however, combining multiple objects in same vbo still valid strategy in many cases, if many of objects drawn together.

you cannot dynamically resizes buffer objects. can pre-allocate bigger buffers , update parts of it. having bunch of reasonably-sized buffers available , dynamically fill can viable strategy. note there gl_arb_copy_buffer (in core since gl 3.1, available) allow quite efficient server-side copies, , can emulate "realloc" behavior allocating new buffer , copying old contents over.

which strategy best depend on situation. if load or destroy objects dynamically, using complex buffer allocation , management strategies might pay off.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -