0
votes

I've a question about how OpenGL handles works with buffer data, especially with animated meshes.

I'm writing a VBO class and I have this function:

void VertexBufferObject::AddData(void* p_ptr_data, UINT p_dataSize)
{
  g_data = *static_cast<std::vector<BYTE>*>(p_ptr_data);
  g_dataSize = p_dataSize;
}

...which I pass a reference to a vector of either aiVector3D or aiVector2D, depending on whether I'm passing vertex or texture coordinates. At the moment I'm using one VBO for each of my vertices, textures, normals, bones, and indices (more on this later). Anyway, VBO has a global vector of BYTEs which is uploaded to the GPU:

void VertexBufferObject::UploadDataToGPU(int p_drawingHint)
{
    glBufferData(g_bufferType, g_data.size() * g_dataSize , &g_data[0], p_drawingHint);
    g_dataUploaded = true;
    g_data.clear();
}

Now, my first question is this: I'm passing a vector of BYTEs to glBufferData, obviously if I do a watch on the contents of g_data, each element is gibberish, such as '\0', as they've been cast to BYTEs. Is it fine to pass this vector of BYTEs to glBufferData? Can OpenGL translate that?

My second question relates to the interleaving of the data I'm passing in and how OpenGL handles that for drawing with glDrawElementsBaseVertex. If I want to interleave my vertex information (vertex, UV, normal), do I also need to interleave bone information with that or can I have a second VBO for the bone information?

1
glBufferData doesn't care what "type" your pointer is as long as it points to a valid piece of memory with size length. - dari

1 Answers

0
votes

To answer your first question: Yes OpenGL can translate your buffer data back to a sensible type. You give it this information when you call (e.g.) glVertexAttribPointer.

To answer your second question: Yes, you can interleave some vertex information and store bone weights/indices in another VBO. You would just bind the second buffer before calling glVertexAttribPointer for your bone attributes.

It is generally considered best practice to interleave all vertex attributes, but there may be reasons not to (perhaps some attributes are shared among different meshes while others are unique), and the performance may not differ noticeably.