VAO and element array buffer state

前端 未结 4 2029
刺人心
刺人心 2020-12-24 13:56

I was recently writing some OpenGL 3.3 code with Vertex Array Objects (VAO) and tested it later on Intel graphics adapter where I found, to my disappointment, that element

4条回答
  •  春和景丽
    2020-12-24 14:45

    I can imagine the ELEMENT buffer not being cached; if you do:

    glBindBuffer(GL_ARRAY_BUFFER, n_vertex_buffer_object);
    glEnableVertexAttribArray(0);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), p_OffsetInVBO(0));
    

    It is like saying:

    gBoundBuffer_GL_ARRAY_BUFFER=n_vertex_buffer_object;
    currentVAO->enable|=(1<<0);
    currentVAO->vertexBuffer=IndexToPointer(gBoundBuffer_GL_ARRAY_BUFFER);
    

    In other words, glBindBuffer() doesn't do anything but set the value of GL_ARRAY_BUFFER. It is at glVertexAttribPointer() where you modify the VAO.

    So when you do:

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, p_index_buffer_object_list[0]);
    glBindVertexArray(0);
    

    You really do:

    gBoundBuffer_GL_ELEMENT_ARRAY_BUFFER=p_index_buffer_object_list[0];
    currentVAO=0;
    

    Where it makes sense that the GL_ELEMENT_ARRAY_BUFFER binding is not doing anything. I'm not sure if there is a glVertexAttribPointer()-like variant for elements though (like glElementPointer()), which would actually act on the VAO.

提交回复
热议问题