VBO Example

I wanted to play with vertex arrary buffers so I took a look at the VBO example code.
It only setup a single vertex array and I wanted to know how to specify normals or texture coordinates

I updated it to use a vertex array, normal array, texture array, and color array.

I then started wondering about dynamically updating the VBO so I added some methods to update the VBO from both the source array with the BufferData call and with getting and modifying the data from the VBO using MapBuffer.

I have uploaded the source if anyone is interested or if it would be good to have in the OpenTK examples.

As for performance, what do people suggest for updating an existing VBO? Copying over new data with BufferData or updating the data with MapBuffer? With MapBuffer you get an IntPtr back so I ended up wrapping it in unsafe so that I could work with the data.

AttachmentSize
T08_VBO.cs18.33 KB
Cube.cs2.64 KB

Comments

Re: VBO Example
posted by nythrix

Nice example there! However, I have a question related to VBOs. How would I go about specifying multiple normals (hard edges) or texcoord sets per vertex while using DrawElements? So far I've come up with the idea of specifying the given vertex multiple times like so:

vertex buffer: V1 V2 V3 V1 V4
normal buffer: N1 N2 N3 N4 N5

so V1 is bound with two different normals during its processing with DrawElements. Any other thoughts?

Re: VBO Example
posted by JTalton

You are correct in that you have to specify the vertex position multiple times, each with their own corresponding normal.

Example:
Cube without hard edges would only need 8 vertices.
Cube with hard edges would need 4 * 6 = 24 vertices so that they could have corresponding normals for each vertex.

Of course this only applies to hard edges.

The same also applies to texture coordinates where the face vertices happen to not be sharing the same texture coordinate.

Re: VBO Example
posted by nythrix

I didn't search for this technique it just came to me. So, I was thinking someone smarter might know more.
It isn't perfect but I'm left with no other choice, I guess.

Thanks for the help.