简体   繁体   English

在OpenGL中创建不可变的缓冲区

[英]Creating an immutable buffer in OpenGL

I read somewhere that immutable buffers introduced by OpenGL 4.4 can be faster so I'm trying to learn to use them. 我在某处读到,OpenGL 4.4引入的不可变缓冲区可以更快,因此我试图学习使用它们。 I'm trying to create an immutable index buffer like this: 我正在尝试创建一个不可变的索引缓冲区,如下所示:

glGenBuffers( 1, &iboId );
glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, iboId );
GLbitfield flags = GL_MAP_WRITE_BIT |
    GL_MAP_PERSISTENT_BIT |
    GL_MAP_COHERENT_BIT;
glBufferStorage( GL_ELEMENT_ARRAY_BUFFER, faceCount * sizeof( Face ), faces, flags );

However, I get an OpenGL error on the last line: 但是,我在最后一行收到OpenGL错误:

GL_INVALID_OPERATION error generated. Cannot modify immutable buffer.

How do I create an immutable index buffer and provide indices to it? 如何创建不可变的索引缓冲区并为其提供索引? Or am I misunderstanding the whole point of the feature? 还是我误解了功能的全部内容?

I solved this as explained in a comment: 我按照评论中的说明解决了这个问题:

I tried to use the same iboId twice in my application when loading multiple meshes from the same file. 从同一文件加载多个网格物体时,我尝试在我的应用程序中两次使用相同的iboId。 The code in this question is correct, it's slightly different in my application due to caching which caused the error. 这个问题中的代码是正确的,由于导致错误的缓存,因此在我的应用程序中略有不同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM