Advertisement Jump to content
Sign in to follow this  

OpenGL second glBufferStorage fails

Recommended Posts


For some reason if I call glBufferStorage only once when everything works just fine.

I want to recreate a buffer by calling glBufferStorage second time(and more) if its size is not enough but this second call generates GL_INVALID_OPERATION error.

After that glMapBufferRange return nullptr and that's it.

Has anyone had similar problem before?

This is how I create/recreate buffer:

const auto vertex_buffer_size = CYCLES * sizeof(Vertex) * VERTICES_PER_QUAD * m_total_text_length;

    GLint current_vertices_size;
    glGetBufferParameteriv(GL_ARRAY_BUFFER, GL_BUFFER_SIZE, &current_vertices_size);

    if (vertex_buffer_size > current_vertices_size)
        if (m_syncs[m_buffer_id] != 0)
            glClientWaitSync(m_syncs[m_buffer_id], GL_SYNC_FLUSH_COMMANDS_BIT, -1);

        GLuint error = glGetError();
        glBufferStorage(GL_ARRAY_BUFFER, vertex_buffer_size, 0, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT |  GL_MAP_COHERENT_BIT);

        GLuint error2 = glGetError();
        m_vertices = static_cast<Vertex*>(glMapBufferRange(GL_ARRAY_BUFFER, 0, vertex_buffer_size, GL_MAP_WRITE_BIT | GL_MAP_PERSISTENT_BIT | GL_MAP_COHERENT_BIT));
        m_buffer_id = 0;       

        for (auto& sync : m_syncs)
            sync = 0;


Edited by _Flame_

Share this post

Link to post
Share on other sites
13 hours ago, Solid_Spy said:

According to the Khronos website, GL_INVALID_OPERATION occurs for glBufferStorage for 2 reasons:

Either the bound reserve buffer object target has a value of 0, or if the GL_BUFFER_IMMUTABLE_STORAGE  flag is enabled for the bound buffer using GL_TRUE.

Definitely not first case. What does second case mean?

Share this post

Link to post
Share on other sites

I have found the root cause. Looks like it's indeed GL_BUFFER_IMMUTABLE_STORAGE. 

Since a buffer created by glBufferStorage is immutable that it's not allowed to call glBufferStorage for it again. So it's necessary to delete a buffer, create it again by glGenBuffers, bind it and now we can call glBufferStorage!

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!