gpt4 book ai didi

c++ - 如果我们有 glBindBuffer, "glGenBuffers"真的很重要吗?

转载 作者:行者123 更新时间:2023-12-04 19:49:49 27 4
gpt4 key购买 nike

好吧,我从 OpenGL 开始,通过阅读有关 glBindBuffer 的文档,我有点困惑。

"glBindBuffer binds a buffer object to the specified buffer binding point. Calling glBindBuffer with target set to one of the accepted symbolic constants and buffer set to the name of a buffer object binds that buffer object name to the target. If no buffer object with name buffer exists, one is created with that name. When a buffer object is bound to a target, the previous binding for that target is automatically broken." Source: http://docs.gl/gl4/glBindBuffer



这是否意味着如果我不创建具有“foo”名称的缓冲区对象,但我调用 glBindBuffer,它会为我创建一个具有该名称(“foo”)的缓冲区对象?

如果是这样,以下代码应该可以正常工作:
GLuint bar = 70;
glBindBuffer(GL_ARRAY_BUFFER, bar);

-> 创建缓冲区对象,将其与 bar (70) “连接”并将其绑定(bind)到 GL_ARRAY_BUFFER。

最佳答案

不,此代码仅适用于兼容性配置文件上下文(或 OpenGL ES)。

OpenGL 4.6 API Core Profile Specification - 2.6.1 Object Management- page 28

[...] the command GenBuffers returns one or more previously unused buffer object names.
Generated names are marked by the GL as used, for the purpose of name generation only. Object names marked in this fashion will not be returned by additional calls to generate names of the same type until the names are marked unused again by deleting them [...]



这意味着 glGenBuffers除了保留名称(值)之外什么都不做。进一步调用 glGenBuffers不会返回相同的值。
如果 glGenBuffers总是用于获取缓冲区对象的名称值,那么您可以确定该值尚未用于其他缓冲区对象。

但是在桌面 OpenGL 核心配置文件规范中,不允许使用 glBindBuffer 的名称。 ,未由 glGenBuffers 保留(返回) .

OpenGL 4.6 API Core Profile Specification - 6.1 Creating and Binding Buffer Objects - page 62

An INVALID_OPERATION error is generated if buffer is not zero or a name returned from a previous call to GenBuffers, or if such a name has since been deleted with DeleteBuffers.



OpenGL 4.6 API Compatibility Profile Specification - 6.1 Creating and Binding Buffer Objects - page 62 中缺少规范的这一部分

这有点令人困惑,但这就是规范。

此行为可以通过您问题的代码进行验证。以下代码使用兼容性配置文件上下文不返回错误,但返回 GL_INVALID_OPERATION使用核心配置文件上下文:

GLuint bar = 70;
glBindBuffer(GL_ARRAY_BUFFER, bar);
GLenum error = glGetError();

关于c++ - 如果我们有 glBindBuffer, "glGenBuffers"真的很重要吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55552932/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com