VBO question

I am converting some glBegin() / glEnd() code into using VBOs instead.

While reading various articles about VBOs, I found it rather confusing.
Some examples used element arrays to index into the buffer, some did not.
Some examples used VAOs, some did not.
Some used a vertex shader, some did not.
So it became difficult to wrap my mind around VBOs.

I got a sample working with just a simple dataset.
No element array of indexes. Since my data is already formatted for triangle strips and fans.
The index array would just be dumb list of
[0] = 0;
[1] = 1;
[2] = 2;
etc…
My buffer was not interleaved. It just had a block of a bunch of vertices in the first half and a bunch of color values in the second half of the block. A couple calls to glVertexPointer() and glColorPointer() told it where to look for those things in the buffer.
Then I just called glDrawArrays() and it worked.

Now I am trying to get it setup so that it works with interleaved data. (Where color would be included with the vertex on every point in the list. Rather than being 2 seperate lists)

For interleaved, what things are required and why?
Do you have to use a shader?
Do you have to use an element array?
Do you have to use VAOs?

[QUOTE=CRasterImage;1243706]I am converting some glBegin() / glEnd() code into using VBOs instead.

While reading various articles about VBOs, I found it rather confusing.[/QUOTE]
“Vertex buffer objects” (VBOs) are just vertex arrays in driver memory (server-side memory).
Whereas “client arrays” are just vertex arrays in application memory (client-side memory).

Some examples used element arrays to index into the buffer, some did not.

Sure. Sometimes you want glDrawElements. Sometimes you want glDrawArrays. If the latter, you don’t need an index list.

Some examples used VAOs, some did not.
Some used a vertex shader, some did not.

Yeah, those are side issues. Totally separate from the where you store your vertex attribute arrays.

Now I am trying to get it setup so that it works with interleaved data…

For interleaved, what things are required and why?

Not a lot is required. As before, you provide the Pointer calls a pointer to the first element in each vertex attribute array. And you specify a stride value != 0 so the GPU knows how to skip over the other attributes for this vertex to the next attribute value for this vtx attribute for the next vertex.

More on pointer to the first element: 1) In the case of interleaved vtx attribute arrays in client arrays, you’d specify the actual starting CPU address of each vertex attribute for the pointer attribute. 2) In the case of interleaved vtx attribute arrays in VBOs, you’d specify the byte offset into the VBO for each vertex attribute for the pointer attribute (e.g. 0 = vertex, 12 = normal, etc.). and 3) In the case of NV bindless VBOs, you’d specify the GPU address for each vertex attribute for the pointer attribute.

Do you have to use a shader?

Nope.

Do you have to use an element array?

Nope. glDrawArrays*() calls work just fine without one. If you’re using glDrawElements(), then you should however.

Do you have to use VAOs?

Nope.

Above I’m assuming a compatibility profile (the default). If you’re allocating a core profile, then the answers are Yes/No/Yes IIRC (as the core profile obsoletes the fixed-function pipeline and requires use of VAOs).

Could you explain what “core profile” means?

I will post my code later, with: no VAO, no element array and no shader.
Maybe someone will see what I am missing.

Could you explain what “core profile” means?

The very first hit on a Google search for “OpenGL core profile”.

When you use glVertexAttribPointer() doesn’t the first parameter have to be an attribute taken from a vertex shader?
Or is there some predefined attribute numbers for vertices, colors, texture coords, etc… ?

No, it can either by linker generated or explicit:


// explicit attribute index
layout(location = 0) in vec4 Position;

Yes, there are two ways to connect the shader to the glVertexAttribPointer() function.
But I was questioning the claim that there is no requirement for shaders in order to do an interleaved VBO.

The shader doesn’t care what the semantics of the attribs are. You define what your attribs’ values are going to be used for.

Edit: BTW, if your attribs are interleaved or not is decided on the application level when you define the layout of your VBO’s data store and the attrib pointers. The shader still doesn’t know how the data is organized, it will simply receive data from enabled arrays and make it accessible via the inputs associated with a specific index.

Edit: I think I might have misread your question slightly. Yes, you to use a specific index. The only question is if this index is generated by the linker or by you using an explicit declaration. However, no matter how the index is determined, there is no semantics associated with an index - at all. That’s because the indices refer generic vertex attributes.

I think you are missing the real question I was asking:

“the claim that there is no requirement for shaders in order to do an interleaved VBO”

Earlier in the thread, I had asked what was required for an interleaved VBO.
VAOs? Element Arrays? Shaders?

I got a no for all 3.

But now it appears, if I am understanding it properly, that shaders are required.

These are your questions:

For interleaved, what things are required and why?
Do you have to use a shader?
Do you have to use an element array?
Do you have to use VAOs?

Can you understand that interleaved data has no effect on the choice of either shaders or and element array buffer or VAO?

Interleaving simply means organizing your data in a certain way. What you need is a VBO unless you’re using a compatibility context in which case you could also use client-side vertex arrays.

You don’t need an element array buffer, i.e. a buffer holding indices because interleaving doesn’t necessitate indexing. You can render an interleaved buffer using glDrawArrays() just fine.

You don’t need a VAO as a consequence of interleaving you data, you are mandated to use a VAO if you’re using core OpenGL 3.2 or higher. A VAO has nothing to do with the data stored in the VAO as a VAO is simply a container object storing a reference to a VBO.

You don’t need a shader if you’re using a compatibility context. You absolutely need a shader as soon as you’re using a core context.

What you do need in any case is to use glVertexAttribPointer() or, with a compatibility context, glVertexPointer(), glNormalPointer() and so on.

In conclusion: What you need to use depends on what kind of context and OpenGL version you use (because depending on the version some stuff simply might not be available). Interleaving data by itself does not place restrictions or requirements on you other than passing the correct values to functions defining vertex arrays, i.e. glVertexAttribPointer() and so on.

Got it now?

Ah, I see.

I thought you had to use glVertexAttribPointer() if you were using interleaved data.
I thought glVertexPointer() and the others were only for contiguous data. (I didn’t notice the stride parameter)

Thanks!
It is working now.