Updating VAO data every frame not working

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.

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.

Yeah I knew it was something simple. How could i miss this?

Thanks for the help. It works fine now

One more question, so the vbo binding determines which vbo to modify and not the vao binding?

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.

Thanks Alfonse.