1

I was trying to use this feature, here is what I did:

glGenBuffers(1, &m_vbo_id);
glGenVertexArrays(1, &m_vao_id);

glBindBuffer(GL_ARRAY_BUFFER, m_vbo_id);
glBindVertexArray(m_vao_id);

glEnableVertexAttribArray(0);  // Vertices
glEnableVertexAttribArray(1);  // Color
glEnableVertexAttribArray(2);  // Texture coordinates

glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
glVertexAttribBinding(0, m_vbo_id);
glVertexAttribFormat(1, 4, GL_FLOAT, GL_FALSE, 24* sizeof(float));
glVertexAttribBinding(1, m_vbo_id);
glVertexAttribFormat(2, 2, GL_FLOAT, GL_FALSE, 42* sizeof(float));
glVertexAttribBinding(2, m_vbo_id);

glBindVertexBuffer(m_vbo_id, m_buffer_data[00], 54*sizeof(float), 0);
glBindVertexBuffer(m_vbo_id, m_buffer_data[18], 54*sizeof(float), 0);
glBindVertexBuffer(m_vbo_id, m_buffer_data[42], 54*sizeof(float), 0);

m_bufferdata is a std::array<float, 54>, containing all the floats, which is rebuilt every frame. This will generate a GL_INVALID_OPERATION. Can anyone tell me why or how I correctly order the calls?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
TuxStash.de
  • 187
  • 1
  • 8

1 Answers1

1

The second argument of glVertexAttribBinding is not the buffer object, but the binding index.
The arguments of glBindVertexBuffer are the binding index, the buffer object, the offset and the stride. Stride is (3+4+2)*sizeof(float) for a tightly packed buffer:

int bindingindex = 0;

glVertexAttribFormat(0, 3, GL_FLOAT, GL_FALSE, 0);
glVertexAttribBinding(0, bindingindex);
glVertexAttribFormat(1, 4, GL_FLOAT, GL_FALSE, 24* sizeof(float));
glVertexAttribBinding(1, bindingindex);
glVertexAttribFormat(2, 2, GL_FLOAT, GL_FALSE, 42* sizeof(float));
glVertexAttribBinding(2, bindingindex);

glBindVertexBuffer(bindingindex, m_vbo_id, 0, 9*sizeof(float));
Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • First, thanks for your answer. Second, could you explain what binding index is or represents? – TuxStash.de Mar 16 '21 at 10:41
  • @TuxStash.de See [Separate attribute format](https://www.khronos.org/opengl/wiki/Vertex_Specification#Separate_attribute_format) – Rabbid76 Mar 16 '21 at 10:48