PDA

View Full Version : Is bind/map array alone when part of vao ok?



doug65536
10-11-2011, 08:39 PM
I have a VAO with the vertex array, element array, and an attribute array.

In my world render, I do visibility determination, and populate the element array with visible elements.

My question is: is it okay to bind and map the element array by itself (without using the VAO) when populating the element array, unmap, unbind, then later in the actual batch render code, bind the VAO and render?

A shorter way of asking is, is it okay to bind and map a buffer that is part of a VAO (without binding the VAO) as long as I unmap/unbind the VBO before I bind the VAO?

I'm guessing it is okay, but I'm getting some funny behavior and (very intermittent) AV's when accessing the mapped VBO and thought I'd ask.

Thanks!

aqnuep
10-12-2011, 12:20 AM
Mapping and modifying a data in the same frame where it is used is not the best idea in most cases, though it has nothing to do with VAOs. VAOs encapsulate actually just pointers and formats for the arrays, it does not prevent you in any way to manipulate the underlying buffer objects separately.

doug65536
10-12-2011, 02:31 AM
I see what you mean about modifying data to close (in time) to the render - if it has to copy data from system memory (assuming the driver decided to give me a system memory pointer), it might block the render pipeline until it has been copied into video memory.

My vague understanding is, if I specified the buffer as GL_STREAM_DRAW_ARB, then the driver was likely to give me a memory mapping that writes directly to the video memory (likely using write-combining memory type for efficiency), or at least a memory region the video card can DMA the data from. Expecially when I "orphan" the last mapping with glBufferData with a null data pointer.

Is this not typically what really happens? Or are you implying that the DMA operation is way too slow for it to not block the pipeline, and/or that it will never (in real life) map the video memory straight into my process's view.

V-man
10-12-2011, 04:26 AM
I think that it is a error to bind a VBO or IBO without having a bound VAO in GL 3.2 and above.

It is one of the legacies of GL 1.0 = bind something to modify it.

kyle_
10-12-2011, 11:51 AM
I think that it is a error to bind a VBO or IBO without having a bound VAO in GL 3.2 and above.

Only element array binding point is part of VAO.
Binding to other targets should work regardless of VAO/no-VAO.

doug65536
10-13-2011, 07:18 AM
I *knew* it wasn't OpenGL's fault.

I found some bad pointer arithmetic in the code that fills the VBO.

I guess lesson learned is: if you have a bad pointer in a mapped VBO, *really* weird stuff will probably happen.

Just to give an idea of how weird it was: turning off v-sync (swap_interval = 0) caused the render to go crazy with bad triangles, turning it on caused a lot of geometry to disappear, and no bad triangles.