I am using this vertex information as input to a GL_POINTS geometry shader.
struct Vertex
{
glm::mat4 transform;
glm::vec3 colour;
};
Vertex points [] = {...};
When setting up the colour attribute, the following code works (with m_location = glGetAttribLocation(...)
):
void Attribute::point_to_vec3 (GLsizei stride, const void * offset)
{
glVertexAttribPointer (
m_location,
3,
GL_FLOAT,
GL_FALSE,
stride,
offset);
}
glEnableVertexAttribArray (m_location);
The naive version for a mat4
doesn't work because apparently it has to be sent as 4 sets of 4 floats. I wrote this
void Attribute::point_to_mat4 (GLsizei size, const void * offset)
{
auto o = static_cast <const std::uint8_t *> (offset);
for (int i = 0; i < 4; ++i)
{
glVertexAttribPointer (
m_location + i,
4,
GL_FLOAT,
GL_FALSE,
size,
o + (4 * i * sizeof (GLfloat)));
glEnableVertexAttribArray (m_location + i);
glVertexAttribDivisor (m_location + i, 1);
}
}
This is adapted from someone else's code, and having read the API documentation, I am still unsure if I'm doing this correctly. The matrix is behaving oddly in the shader.
Can someone please clarify what's going on with the multiple locations, and glVertexAttribDivisor
?
Is the above code correct?