I was trying to enable instanced rendering of a mesh. I extracted the relevant code snippets. I did some debugging and it’s seems that the instanced position data transforms the vertices instead of each individual mesh. Which makes me believe that OpenGL is setting the divisor for second buffer as zero instead of one. I tried everything but can’t seem to understand why this is happening. Appreciate any help.
//load first vertex buffer
index = 0;
size = 3;
offset = 0;
bindingIndex = 0;
glVertexArrayAttribFormat(mVao, index, size, GL_FLOAT, GL_FALSE, offset);
glEnableVertexArrayAttrib(mVao, index);
glVertexArrayAttribBinding(mVao, index, bindingIndex);
//load second buffer for instancing using vec3 positions
index = 10;
size = 3;
offset = 0;
bindingIndex = 1;
glVertexArrayAttribFormat(mVao, index, size, GL_FLOAT, GL_FALSE, offset);
glEnableVertexArrayAttrib(mVao, index);
glVertexArrayAttribBinding(mVao, index, bindingIndex);
glVertexArrayBindingDivisor(mVao, index, 1);
Vertex shader
layout (location = 0) in vec3 v_in_pos;
layout (location = 10) in vec3 v_in_inst_pos;
uniform mat4 u_M = mat4(1);
uniform mat4 u_PV = mat4(1);
void main() {
gl_Position = u_PV*u_M*vec4(v_in_inst_pos+v_in_pos, 1.0);
}