I am using glVertexAttribDivisor to specify the instancing data storage. All the instance specific data is stored in 2nd vertex buffer at vertex buffer binding index 1 (vertex buffer at binding index 0 stores data used for all instances) used as instance specific data.
This is how I specify vertex format.
glCreateVertexArrays(1, &mVertexArray);
glBindVertexArray(mVertexArray);
for (auto& vertexAttrib : vertexFormat->mVertexAttributeList)
{
glVertexAttribFormat(vertexAttrib.mLocation, vertexAttrib.mChannel,
OpenGLShaderAttributeType[int(vertexAttrib.mType)],
vertexAttrib.mNormalized, vertexAttrib.mOffset);
glVertexAttribBinding(vertexAttrib.mLocation, vertexAttrib.mBindingIndex);
if (vertexAttrib.mDivision != 0)
{
glVertexAttribDivisor(vertexAttrib.mLocation, vertexAttrib.mDivision);
}
glEnableVertexAttribArray(vertexAttrib.mLocation);
}
glBindVertexArray(0);
This is how I enable vertex buffer for 2 vertex buffer.
glBindVertexBuffer(bindingIndex, mBuffer, offset, stride);
The problem is that when I used glVertexAttribDivisor, the glDrawArraysInstanced crashs as memory read violation. Can anyone provide a hint for potential problem for this situation? Thank you.