PDA

View Full Version : Drawing parts of a VBO



Elurahu
09-25-2011, 07:01 AM
I'm trying to get setup so that I can keep several LODs of a given mesh in a single VBO. I'm having some issues getting both glDrawArrays and glDrawElements to behave as I expect them to.

Say I have a VBO setup containing Position(vec3)/Color(vec3) attributes interleaved:
- Mesh 1 Vertex 0 - 100 (0 - 2400 bytes)
- Mesh 2 Vertex 100 - 300 (2400 - 7200 bytes)

A VAO has been setup enabling both attributes and pointing to their respective starting offsets of vertex 0.

Now if I wanted to draw mesh 1 and 2 I would expect I could just use:

glDrawArrays(GL_PRIM, 0, 100)
glDrawArrays(GL_PRIM, 100, 100)

this does however not work. It looks like changing the "first" param doesn't do anything.

I'm having some issues figuring out glDrawElements as well as I'm also having problems with that. Say the VAO has an IBO activated as well.

I would expect:
glDrawElements(GL_PRIM, 100, GL_TYPE, sizeof(GL_TYPE) * 100) to render mesh 2 however it doesn't.

Could anyone confirm that there are nothing wrong with my assumptions on how this works? I'm primarily a DX guy.

Elurahu
09-25-2011, 07:42 AM
Ok I have figured out what I did wrong with the glDrawArrays call. I had the stride param of the glVertexAttribPointer call set to zero. Setting that to the correct stride fixed the issue. I just don't get why. The specs tells you that if you set the stride to 0 it will assume the vertex arrays are tightly packed. Does that only count if it is a single attribute array? Mine consists of a vec3 position followed by a vec3 color for each vertex.

mhagain
09-25-2011, 08:19 AM
Does that only count if it is a single attribute array?

Yup, that's correct. When you're interleaving you need to specify the full size of the struct.

Elurahu
09-25-2011, 11:29 AM
All problems solved - Turned out that was causes both problems.