Advertisement

glBindVertexBuffer and INVALID_OPERATION(0x502)

Started by April 07, 2019 08:05 AM
3 comments, last by _Flame_ 5 years, 10 months ago

Hello.
From documentation: 

Quote

GL_INVALID_OPERATION is generated by glBindVertexBuffer if no vertex array object is bound.

But I bind VAO before calling glBindVertexBuffer.

Initialization:


    glGenVertexArrays(1, &m_VAO);

    glBindVertexArray(m_VAO);
    glVertexAttribFormat(0, 3, GL_FLOAT, false, offsetof(vertex, coords)); 
    glVertexAttribBinding(0, 0);
    glEnableVertexAttribArray(0);

    glVertexAttribFormat(1, 3, GL_FLOAT, false, offsetof(vertex, color)); 
    glVertexAttribBinding(1, 0);
    glEnableVertexAttribArray(1);

    glVertexAttribFormat(2, 2, GL_FLOAT, false, offsetof(vertex, tex_coords)); 
    glVertexAttribBinding(2, 0);
    glEnableVertexAttribArray(2);

    glVertexAttribFormat(3, 3, GL_FLOAT, false, offsetof(vertex, normal_coords)); 
    glVertexAttribBinding(3, 0);
    glEnableVertexAttribArray(3);

    glBindVertexArray(0);

    glGenBuffers(1, &m_VBO);
    glGenBuffers(1, &m_EBO);

    glBindBuffer(GL_ARRAY_BUFFER, m_VBO);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);

    glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(vertex), vertices.data(), GL_STATIC_DRAW);
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices.size() * sizeof(unsigned), indices.data(), GL_STATIC_DRAW);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

rendering:


    glBindVertexArray(m_VAO);
    glBindVertexBuffer(0, m_VBO, 0, sizeof(vertex));
    int error = glGetError(); // INVALID_OPERATION(0x502)

    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO);
    glDrawElements(GL_TRIANGLES, m_indexCount, GL_UNSIGNED_INT, 0); //crash

 

Remember, OpenGL errors are sticky - that GL_INVALID_OPERATION may not be from you calling glBindVertexBuffer.

From the glGetError documentation:

glGetError returns the value of the error flag. Each detectable error is assigned a numeric code and symbolic name. When an error occurs, the error flag is set to the appropriate error code value. No other errors are recorded until glGetError is called, the error code is returned, and the flag is reset to GL_NO_ERROR. If a call to glGetError returns GL_NO_ERROR, there has been no detectable error since the last call to glGetError, or since the GL was initialized.

Check the the value returned by glGetError immediately before you call glBindVertexBuffer. You might need to sprinkle calls to glGetError about your code to identify which function is generating the error.

Advertisement
24 minutes ago, dave j said:

Remember, OpenGL errors are sticky - that GL_INVALID_OPERATION may not be from you calling glBindVertexBuffer.

From the glGetError documentation:

 

Check the the value returned by glGetError immediately before you call glBindVertexBuffer. You might need to sprinkle calls to glGetError about your code to identify which function is generating the error.

You are right but glGetError before glBindVertexBuffer returns 0.

But what is interesting that glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_EBO); also returns GL_INVALID_OPERATION.

I found the root cause. Rookie mistake.

I kept my mesh in std::vector and buffers were destroyed during copy/assignment process. :)

This topic is closed to new replies.

Advertisement