I want to know how to restore all attribute binding as we unbound and rebound a program. As far as I know if I am using a VAO, it is as simple as rebounding the VAO, but I am not sure when I am not using the VAO. I am creating VBO but not VAO.
If I do the following
glUseProgram(shader1);
// Now set uniforms.
glUniformMatrix4fv(matrix_handdle, 1, false, matrix);
glBindBuffer(GL_ARRAY_BUFFER, bufferIndex);
glEnableVertexAttribArray(m_attributes[position_1]);
glVertexAttribPointer(m_attributes[POSITION_HANDLE], 3, GL_FLOAT, false, 3 * sizeof(GLfloat), 0);
Now save the current program, vbo binded. Then use second program
glUseProgram(shader2);
//bind some new vbo, set some uniform, vertex attribute variable.
element.draw();
Then again use the first shader program. Rebind the vbo
glUseProgram(shader1); //Here, do the attributes set in first shader program remain?
element.draw();
I think I need to get the vertex attribute values using glGetVertexAttrib() function for size, stride , type, normalize flag, buffer binding and array pointer of all vertex attribute and save them. Then when I rebind the program, I will set the vertex attribute values. I think I need to get the Max attributes for a shader program by using GL_MAX_VERTEX_ATTRIBS and then save/ restore values of all attribute locations.Is it correct or I am wrong somewhere ?