简体   繁体   中英

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. 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:

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. The code in this question is correct, it's slightly different in my application due to caching which caused the error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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