Advertisement

second glBufferStorage fails

Started by July 31, 2018 03:54 AM
3 comments, last by _Flame_ 6 years, 6 months ago

Hello.

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);
            glDeleteSync(m_syncs[m_buffer_id]);
        }

        glUnmapBuffer(GL_ARRAY_BUFFER);
        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)
        {
            glDeleteSync(sync);
            sync = 0;
        }
    }

 

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.

https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferStorage.xhtml

View my game dev blog here!

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

https://www.khronos.org/registry/OpenGL-Refpages/gl4/html/glBufferStorage.xhtml

Definitely not first case. What does second case mean?

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!

This topic is closed to new replies.

Advertisement