user3685312
user3685312

Reputation: 11

Optimizing interleaved VBO

I've hopefully understood the following correct:
When making different VBO:s in OpenGL for vertices, normals and indices I can use less memory because of reusing but it isn't as effective.

When using interleaved VBO:s the normal routine is that the same vertices and normals will be written more than once, right?

My question is if the use of more memory is something people just accept for the gain in speed, or is it worth it to do some kind of trick to "reuse" already given data with indices or something similar?

Upvotes: 0

Views: 619

Answers (1)

ratchet freak
ratchet freak

Reputation: 48216

interleaved VBO holds essentially a array of structs:

struct vertexAttr{
    GLfloat posX, posY, posZ;
    GLfloat normX, normY, normZ;
}

glBindBuffer(GL_ARRAY_BUFFER, vert);
vertexAttr* verts = new vertexAttr[numVerts];
//fill verts
glBuffer(GL_ARRAY_BUFFER, numVerts, verts, GL_STATIC_DRAW​);
delete[] verts;

glBindProgram(prog);
glVertexAttribPointer(posAttr, 3, GL_FLOAT, false, sizeof(vertexAttr), 0);
glVertexAttribPointer(normAttr, 3, GL_FLOAT, false, sizeof(vertexAttr), offsetof(vertexAttr, normX));

you still need to use a separate buffer for the indexes.

Upvotes: 2

Related Questions