View Full Version : Question for VBOs.

09-29-2010, 11:48 AM
Hello to everyone.

All day now I have been reading tutorials on VBOs and I was trying to render some particles in my screen. I finally managed it. (yeah !!!) But since most tutorials I found were only for exposition reasons and not performance I still have some questions for them. So If you could give some hints, would be much appreciated.

Well I first initialize my particles and their colors.

particles = (cData*) calloc(DIM*DIM, sizeof(cData));
colors = (GLubyte*)calloc(DIM*DIM*4, sizeof(GLubyte));

initParticles(DIM, DIM);
Secondly I generate 2 buffers for them and I fill the buffers with the info.

glGenBuffersARB(nBUFFERS, vbo);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(cData) * DIM*DIM, particles, GL_DYNAMIC_DRAW_ARB);
glVertexPointer(2, GL_FLOAT, 0, NULL);

// Addition.
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(GLubyte) * DIM*DIM *4, colors, GL_DYNAMIC_DRAW_ARB);
glColorPointer(4, GL_UNSIGNED_BYTE, 0, NULL);


I do not render them at that point. But I noticed that when I want to render them, all I have is simple to enable the vertex/color arrays, bind the vertex buffer only and then render them.


// glVertexPointer(2, GL_FLOAT, 0, NULL);
// glColorPointer(4, GL_UNSIGNED_BYTE, 0, NULL);
glDrawArrays(GL_POINTS, 0, DIM*DIM);


If you see from my comments you will notice that I bind only the Vertex buffer. Well apart from the fact that it is working fine, my first question is whether this is correct. Don't I have to explicitly redefine the way this buffer is going to be read with

glVertexPointer(2, GL_FLOAT, 0, NULL);

Secondly I noticed that I don't have to rebind the color buffer and after that to redefine the way it will be read with.

glColorPointer(4, GL_UNSIGNED_BYTE, 0, NULL);

Is all this correct ? Is this happening for performance reasons ? Or it's just that I am using the same buffers, and if I try to create and render another vbo I will face unknown behaviour.

Thanx in advance for any kind of help.

P.s. If my post doesn't make much sense, I will try to repost it a bit later because after 12 hours of work, there aren't left many brain cells.

Dark Photon
09-29-2010, 05:42 PM
That's correct. gl*Pointer latches the currently bound ARRAY_ELEMENT buffer to that vertex attribute. That buffer binding is stored off in GL state in the appropriate GL vertex attribute bind point (e.g. VERTEX_ARRAY_BUFFER_BINDING, COLOR_ARRAY_BUFFER_BINDING, etc.)

So after you bind your buffer to ARRAY_ELEMENT, and then call your gl*Pointer call, you can rebind ARRAY_ELEMENT to anything you want and it won't mess up your vertex attribute bindings. It's just a staging area used to latch VBOs to vertex attributes.

In fact, you shouldn't have had to bind anything to ARRAY_ELEMENT right before your DrawArrays like you did. Try commenting it out, and it should work (AFAIK).

09-30-2010, 10:44 AM
Yes, that's true.

All I have to do is enable the appropriate client states, and draw my VBO.

Thank you Dark Photon.