glBufferData doubt

#1
Hello. I am following a tutorial that when calls to glBufferData() are made, its third argument, a const void * pointer, is used to point to a static const GLfloat [] or to a static const GLint which represents the vertices and its indices. 

So, is there no use to keep already made triangles? By triangles I mean an Object that is made of three Vec3f objects (which are three floats) that represent the vertices, another Vec3f that represents normal and a couple methods that operate over it.

Can I throw all that away and instead focus into copying the data contained into two c++ vectors, that stored all vertices and all the faces index before the triangles creation to a permanent and more suitable format that glBufferData can interpret? (dynamically allocated GLfloat and GLint I guess…)

Thanks for the attention.

#2

The data you provide to populate an OpenGL buffer object (e.g. via glBufferData()) is just an array of bytes. There is no type information communicated to OpenGL at this point. So you can store it on your side of the API using whatever types you want.

You tell OpenGL the types and organization of data stored in this buffer object though other calls you make, when you direct OpenGL to actually read from (or write to) content stored within this buffer object. For instance, through glVertexAtttribPointer() calls (for vertex attributes) or glDrawElements() (for the index list).

#3

From the specifications of glBindBuffer and glBufferData one have to specify if you are sending a bunch of of vertices with GL_ARRAY_BUFFER or a bunch of indices with GL_ELEMENT_ARRAY_BUFFER as the first argument. That’s why I am not comprehending the idea that it has no notion of the data organization.

#4

The target is only used to identify which buffer is being modified. So far as glBufferData is concerned, you’re just transferring bytes. To copy data to a buffer, you need to bind it to a target then issue a glBufferData command for that target; it doesn’t matter which target you use.

Commands which use the data stored in buffers use specific targets (except for the DSA-based APIs added in 4.5). E.g. glVertexAtttribPointer records the buffer bound to GL_ARRAY_BUFFER at the time of the call, glDrawElements uses the buffer bound to GL_ELEMENT_ARRAY_BUFFER, glTexImage* uses the buffer bound to GL_PIXEL_UNPACK_BUFFER (if any), etc. And they impose an interpretation on the buffer’s contents. But the buffer itself doesn’t have any structure beyond being an array of bytes.

A buffer object is very much like a dynamic array created by malloc in C. You create it, you store data in it, you pass it to functions which use that data, you delete it. The data needs to be compatible with the functions which use the data, but the buffer itself doesn’t care.