0

As Of now, I'm pushing Vertices and Indices data to their respective buffers all together when I create the Object initially, like this:

glBindVertexArray(VAO);    
glBindBuffer(GL_ARRAY_BUFFER, VBO);

glBufferData(GL_ARRAY_BUFFER, VertexCount, &Vertices[0], GL_STATIC_DRAW);

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, IndicesCount, &Indices[0], GL_STATIC_DRAW);

But as the size of the vertices array increases, the time needed to bind them increases as well, and I got to the point where I need up to 10 seconds to bind a mesh. Since OpenGL operations cannot be done on another thread,

I've looked into batch rendering (For example this: https://www.youtube.com/watch?v=5df3NvQNzUs) but If I understood correctly It readds the vertices and indices every frame. This is good for animated meshes for example, but I don't think that it is useful for large static meshes (that will not change).

Is there a way to add for example 10 faces with their respective indices to the preexisting buffers every time the render function is called on the main thread?

Fabrizio
  • 1,138
  • 4
  • 18
  • 41
  • It is not possible to change the size of a buffer object. But you can create a buffer with a size that is large enough and update a subset of the buffer object's data store later by [`glBufferSubData `](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferSubData.xhtml) or buffer [mapping](https://www.khronos.org/opengl/wiki/Buffer_Object#Mapping). Note [`glBufferData`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferData.xhtml) creates a new buffer and is a very time consuming operation. – Rabbid76 May 02 '20 at 11:02
  • Thanks for the help! I think that is the solution used in the video, but with that, I'm not bound to rebind the data every time the frame renders, am I? – Fabrizio May 02 '20 at 11:04
  • What do you mean by "not bound to rebind"? If you want to change the content of a buffer then you have to bind the buffer or you have to use direct state access operations like [`glNamedBufferSubData`](https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferSubData.xhtml) – Rabbid76 May 02 '20 at 11:06
  • I mean, by defining the buffer as dynamic (GL_DYNAMIC_DRAW) when I create it, should I rebind the data every time (So every time I draw it) I need it even if I already bound it? – Fabrizio May 02 '20 at 11:10
  • You do not need to bind any buffer when you draw a mesh. All you have to do is to bind the [Vertex Array Object](https://www.khronos.org/opengl/wiki/Vertex_Specification#Vertex_Array_Object). the buffer references are stored in the VAO. – Rabbid76 May 02 '20 at 11:12

0 Answers0