PDA

View Full Version : ARB_vertex_array_object usage pattern



addmx
07-21-2009, 04:55 AM
Hi
What is the valid usage pattern of vertex array object ?
I'm generating ID glGenVertexArrays then bind it (glBindVertexArray).
Now I'm setting some states, for example:

glEnableClientState (GL_VERTEX_ARRAY);
glVertexPointer (3, GL_FLOAT, sizeof(c_OBJ_VERTEX), offsetof(c_OBJ_VERTEX, pos.x));

glClientActiveTexture(GL_TEXTURE1);
glEnableClientState (GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer (3, GL_FLOAT, sizeof(c_OBJ_VERTEX), offsetof(c_OBJ_VERTEX, normal.x));

now do glBindVertexArray(0);

1st question: Should I disable GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY at this point or they are disabled like befor VAO ?

Now i want to use my VAO:


glBindVertexArray(...)
glBindBuffer(GL_ARRAY_BUFFER, ...)

glDrawRangeElements(...);

--> Now i got nice crash in glDrawRangeElements :p (GF 280GTX, latest nvidia drivers, vista x64 sp2)

I have lots of vertex buffers to draw (> 100) and they are in on of 4 formats,
so I want to have 4 VAOs, each of them holding state bindings to reduce number of gl* calls,
just like vertex declarations in DX.
This is the valid usage pattern ?
If Yes - where is the error ? ;)

If i do something like this:

glGenVertexArrays(1, &SomeID);
glBindVertexArray(SomeID)
glBindBuffer(GL_ARRAY_BUFFER, SomeID_VB)
glVertexPointer and others now

then when comes to rendering:
glBindVertexArray(SomeID)
glBindBuffer(GL_ARRAY_BUFFER, SomeID_VB)

glDrawRangeElements(...)

all is fine - but this way i need one VAO per one vertex buffer - with IMHO is not right ?

Ps. is there any WORKING example (with source code) of vertex array object ? :>

DmitryM
07-21-2009, 06:06 AM
This might be helpful:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=260782#Post2607 82

and this especially:
http://www.opengl.org/discussion_boards/ubbthreads.php?ubb=showflat&Number=258699#Post2586 99

there are a lot of not-exact-correctly info there, but the reading worth it anyway

zeoverlord
07-21-2009, 07:32 AM
Once you have created the VAO bound buffers and all that and your about to render all you need to do is call glBindVertexArray and not glBindBuffer, calling glBindBuffer without glVertexPointer(or the like) confuses openGL and causes an error, the reason it works with it already bound one is because if you bind anything more than once in a row it just disregards all but the first.

you do not need to disable GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY as long as all your VAOs use the same form.
Besides, if your pondering using openGL 3.1 and glsl 1.4 you wouldn't need glEnableClientState, glVertexPointer, glTexCoordPointer and so on.