Hi there,
I have a VAO with a shader that renders a circular shape.
When I’m setting up my VAO I have the following working code that works:
glGenVertexArrays(1, &m_vao_id);
glGenBuffers(1, &m_radius_id);
GLint rad_attrib = glGetAttribLocation(m_prog_id, "radius");
. . .
glBindVertexArray(m_vao_id);
. . .
glBindBuffer(GL_ARRAY_BUFFER, m_radius_id);
glBufferData(GL_ARRAY_BUFFER, sizeof(m_radii[0]) * m_num_vertices, m_radii, GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(rad_attrib);
glVertexAttribPointer(rad_attrib, 1, GL_FLOAT, GL_FALSE, 0, 0);
However when I replace it with the following code it does not work.
glGenVertexArrays(1, &m_vao_id);
glGenBuffers(1, &m_radius_id);
GLint rad_attrib = glGetAttribLocation(m_prog_id, "radius");
. . .
glBindVertexArray(m_vao_id);
. . .
glBindBuffer(GL_SHADER_STORAGE_BUFFER, m_radius_id);
glBufferData(GL_SHADER_STORAGE_BUFFER, sizeof(m_radius_vtx[0]) * m_num_vertices, nullptr, GL_DYNAMIC_DRAW);
glEnableVertexAttribArray(rad_attrib);
glVertexAttribPointer(rad_attrib, 1, GL_FLOAT, GL_FALSE, 0, 0);
GLuint accessMask = GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_BUFFER_BIT;
float *rad =
(float *)glMapBufferRange(GL_SHADER_STORAGE_BUFFER, 0, m_num_vertices*sizeof(m_radii[0]), accessMask);
// temporary hack: radius set to 0.1
for (int i = 0; i < m_num_vertices; ++i)
rad[i] = 0.1;//m_radii[i];
glUnmapBuffer(GL_SHADER_STORAGE_BUFFER);
m_radii is a float array.
So naturally I’m probably doing something wrong so asking you if you can see something obviously wrong here.
Best Regards,
David