Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: Updating VAO data every frame not working

  1. #1
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    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,
    Code :
    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,
    Code :
    //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
    Code :
    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.
    Regards,
    Mobeen

  2. #2
    Junior Member Regular Contributor
    Join Date
    Mar 2009
    Posts
    151

    Re: Updating VAO data every frame not working

    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.

  3. #3
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: Updating VAO data every frame not working

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

    Thanks for the help. It works fine now
    Regards,
    Mobeen

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: Updating VAO data every frame not working

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

  5. #5
    Senior Member OpenGL Guru
    Join Date
    May 2009
    Posts
    4,726

    Re: Updating VAO data every frame not working

    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.

  6. #6
    Advanced Member Frequent Contributor
    Join Date
    Mar 2009
    Location
    Singapore
    Posts
    802

    Re: Updating VAO data every frame not working

    Thanks Alfonse.
    Regards,
    Mobeen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •