OpenGL:如果无论如何都必须绑定目标,"named" 缓冲区函数有什么意义?
OpenGL: What's the point of the "named" buffer functions if you have to bind a target anyway?
例如当我这样做时
glBindBuffer(GL_ARRAY_BUFFER, _id);
glNamedBufferData(_id, size, data, static_cast<GLenum>(usage));
然后程序按预期运行。但是如果我删除第一行,我的程序就会崩溃并打印:
ERROR 1282 in glNamedBufferData
同样,如果我这样做
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();
}
它工作正常,但如果我删除 glBindVertexArray
然后它不起作用并打印:
ERROR 1282 in glVertexArrayAttribFormat
ERROR 1282 in glEnableVertexArrayAttrib
ERROR 1282 in glVertexArrayAttribBinding
我认为通过在调用这些函数时“命名”VBO 或 VAO,我就不必事先绑定它。但是,如果我无论如何都必须绑定,那么这些需要额外名称参数的函数有什么好处?
glGen*
函数创建一个表示对象的整数名称,但它们不会创建对象状态本身(好吧,它们中的大多数都不会)。只有当您绑定这些对象时,它们才会获得它们的状态,并且只有在它们具有状态之后才能调用任何需要它们具有状态的函数。特别是 direct state access functions.
这就是 ARB_direct_state_access
还 包含 glCreate*
函数的原因。这些函数创建一个整数名称 和 对象的状态数据。因此,您不必绑定任何东西来操作直接状态访问函数,只要您事先正确地创建了对象。
例如当我这样做时
glBindBuffer(GL_ARRAY_BUFFER, _id);
glNamedBufferData(_id, size, data, static_cast<GLenum>(usage));
然后程序按预期运行。但是如果我删除第一行,我的程序就会崩溃并打印:
ERROR 1282 in glNamedBufferData
同样,如果我这样做
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();
}
它工作正常,但如果我删除 glBindVertexArray
然后它不起作用并打印:
ERROR 1282 in glVertexArrayAttribFormat
ERROR 1282 in glEnableVertexArrayAttrib
ERROR 1282 in glVertexArrayAttribBinding
我认为通过在调用这些函数时“命名”VBO 或 VAO,我就不必事先绑定它。但是,如果我无论如何都必须绑定,那么这些需要额外名称参数的函数有什么好处?
glGen*
函数创建一个表示对象的整数名称,但它们不会创建对象状态本身(好吧,它们中的大多数都不会)。只有当您绑定这些对象时,它们才会获得它们的状态,并且只有在它们具有状态之后才能调用任何需要它们具有状态的函数。特别是 direct state access functions.
这就是 ARB_direct_state_access
还 包含 glCreate*
函数的原因。这些函数创建一个整数名称 和 对象的状态数据。因此,您不必绑定任何东西来操作直接状态访问函数,只要您事先正确地创建了对象。