PDA

View Full Version : Updating VAO data every frame not working



mobeen
02-12-2011, 05:13 AM
Hi all,
I am doing a simple texture slicer. At the initialization, i setup the slicing direction and setup my vao/vbo as follows,


glGenVertexArrays(1, &vaoID);
glGenBuffers (1, &vboID);
glBindVertexArray(vaoID);
glBindBuffer (GL_ARRAY_BUFFER, vboID);
glBufferData (GL_ARRAY_BUFFER, sizeof(vTextureSlicer), &(vTextureSlicer[0].x), GL_STREAM_COPY);
glEnableVertexAttribArray(shader["vVertex"]);
glVertexAttribPointer (shader["vVertex"], 3, GL_FLOAT, GL_FALSE, sizeof(Vertex),0);
glBindVertexArray(0);

I passed GL_STREAM_COPY since my data is changed each frame. Based on the current viewing direction the slicing is carried out and the data is updated as follows,


//render code and modelview setup

//vTextureSlicer contains new positions
CalcNewData(viewDir, vTextureSlicer);

glBindVertexArray(vaoID);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vTextureSlicer), &(vTextureSlicer[0].x));

and then follow it with a draw call


glDrawArrays(GL_TRIANGLES,0, sizeof(vTextureSlicer)/sizeof(vTextureSlicer[0]));

however it does not draw anything. If i remove the per frame data update part, it renders fine? what may be causing this. I have tried GL_DYNAMIC_[DRAW/COPY] and GL_STREAM_[COPY/DRAW] to no avail.

randall
02-12-2011, 05:35 AM
You should call this:

glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vTextureSlicer), &(vTextureSlicer[0].x));

not this:

glBindVertexArray(vaoID);
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vTextureSlicer), &(vTextureSlicer[0].x));

VAO do not have to be bound. You are updating the buffer not the vao.

mobeen
02-12-2011, 05:43 AM
Yeah I knew it was something simple. How could i miss this?

Thanks for the help. It works fine now

mobeen
02-12-2011, 06:08 AM
One more question, so the vbo binding determines which vbo to modify and not the vao binding?

Alfonse Reinheart
02-12-2011, 09:38 AM
One more question, so the vbo binding determines which vbo to modify and not the vao binding?

Of course; that's what buffer object bindings are for. And after all, VAOs can use multiple buffer objects.

The only buffer object binding affected by the VAO's state is the ELEMENT_ARRAY_BUFFER binding.

mobeen
02-12-2011, 10:25 AM
Thanks Alfonse.