Let's say I am not using VAOs. I have an array of vertex positions in memory that I want to send to the shader. I do the following (assume I have enabled the corresponding vertex attrib arrays):
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, vertexDataAsFloats);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 0, textureData);
glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 0, someOtherData);
glDrawArrays(...);
This works well and I see the mesh with proper textures. someOtherData
is sent to the shader correctly as well. Now I decide to put the vertexDataAsFloats
and textureData
in VBOs
:
BindVAO(1); // binds the VAO with a handle generated from glGenVertexArrays()
glBindBuffer(GL_ARRAY_BUFFER, vertexDataBufferObject);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0);
glBindBuffer(GL_ARRAY_BUFFER, textureData);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, 0);
UnBindVAO();
Later, before drawing:
glVertexAttribPointer(2, 1, GL_FLOAT, GL_FALSE, 0, someOtherData);
BindVAO(1);
glDrawArrays(...);
UnBindVAO();
Can I mix the calls to glVertexAttribPointer
and VAO
before the draw call, where someOtherData
is not in a VBO
? Currently, this approach is not working as I am not receiving valid data for someOtherData
in the shader.
I realize that someOtherData
should go in a VBO
as well and bound with the VAO
. There is some legacy code that I have to work with which does not use VBOs
. In any case, I would like to know if the above is legal in OpenGL.