Transform data received on shader looks different than data sent
-
I am getting an issue where the transform data being sent to the shader for use in Instanced Draw calls looks different than the data that is actually being received.
I am sending an array of floats.
The number of floats in the array is a multiple of 16 (every 16 floats represents a transform).
Right now I am just sending a bunch of identity transforms but when I view the array on render doc, the set of 4 vectors that each instance of the draw call is using does not match expectations.
This is the data each instance is using in render doc
I am expecting the data to be like this:
1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1
How my data looks like in my debugger:
But the first 16 floats looks like this in the render doc (each row contains 16 floats, only 11 are shown here:
1 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0
This is the code I use to allocate the data to the shader. (This is a qt creator c++ project. Qt has their own opengl function bindings)
m_transformbo.create(); m_transformbo.setUsagePattern(QOpenGLBuffer::DynamicDraw); m_transformbo.bind(); m_transformbo.allocate(m_listOfTransforms.data(), m_listOfTransforms.size() * sizeof(float)); if (m_listOfTransforms.size() > 0) { for (int i = 0; i < 4; i++) { m_view->shaderProgram()->enableAttributeArray(m_shader_locs.transforms + i); int shaderLocation = m_shader_locs.transforms + i; int offset = i * sizeof(float); int stride = 16 * sizeof(float); int tupleSize = 4; m_view->shaderProgram()->setAttributeBuffer(shaderLocation, GL_FLOAT, offset, tupleSize,stride); m_view->glVertexAttribDivisor(shaderLocation, 1); } }
-
I figured it out, my
int offset = i * sizeof(float);
should have been
int offset = i * sizeof(float) * 4;
This makes sense since the offset should be every 4 floats
-