e.g. when I do
glBindBuffer(GL_ARRAY_BUFFER, _id);
glNamedBufferData(_id, size, data, static_cast<GLenum>(usage));
then program works as expected. But if I delete that first line, my program crashes and prints:
ERROR 1282 in glNamedBufferData
Likewise, if I do
glBindVertexArray(_id);
GLuint attribIndex = 0;
GLuint offset = 0;
for(const GlslType type : layout) {
const auto& attrib = GLSL_TYPES.at(type);
glVertexArrayAttribFormat(_id, attribIndex, attrib.size, static_cast<GLenum>(attrib.type), GL_FALSE, offset);
glEnableVertexArrayAttrib(_id, attribIndex);
glVertexArrayAttribBinding(_id, attribIndex, 0);
offset = attrib.size_bytes();
}
It works fine, but if I delete the glBindVertexArray
then it doesn't work and prints:
ERROR 1282 in glVertexArrayAttribFormat
ERROR 1282 in glEnableVertexArrayAttrib
ERROR 1282 in glVertexArrayAttribBinding
I figured that by "naming" the VBO or VAO when calling those functions then I wouldn't have to bind it beforehand. But if I have to bind regardless, what's the benefit of these functions that require the extra name argument?
CodePudding user response:
The glGen*
functions create a integer name representing an object, but they don't create the object state itself (well, most of them don't). It is only when you bind those objects do they gain their state, and only after they have state can any function be called which requires them to have state. In particular, the direct state access functions.
This is why ARB_direct_state_access
also includes the glCreate*
functions. These functions create an integer name and the state data for objects. Therefore, you don't have to bind anything to manipulate direct state access functions, so long as you properly created the object beforehand.