If you have multiple vertex buffer objects, is it possible to access them simultaneously in the geometry shader? I’m having difficulty with this, and I’ve successfully accessed a single vertex buffer object in the geometry shader by making a texture buffer object and binding it to an active texture unit and setting the samplerbuffer to that unit, but accessing a second texturebuffer on a different texture unit doesn’t work for me.
I’ve populated the buffer and generated textures below
// coordinates
glGenBuffers(1, &coord_id);
glBindBuffer(GL_ARRAY_BUFFER, coord_id);
glBufferData(GL_ARRAY_BUFFER, 3* num_coords * sizeof(float), coord_buff, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glActiveTexture(GL_TEXTURE10);
glGenTextures(1, &coord_tex_id);
glBindTexture(GL_TEXTURE_BUFFER, coord_tex_id);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, coord_id);
glBindBuffer(GL_TEXTURE_BUFFER, 0);
glActiveTexture(0);
// displacements
glGenBuffers(1, &disp_id);
glBindBuffer(GL_ARRAY_BUFFER, disp_id);
glBufferData(GL_ARRAY_BUFFER, 3* num_disps * sizeof(float), disp_buff, GL_STATIC_DRAW);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glActiveTexture(GL_TEXTURE11);
glGenTextures(1, &disp_tex_id);
glBindTexture(GL_TEXTURE_BUFFER, disp_tex_id);
glTexBuffer(GL_TEXTURE_BUFFER, GL_RGB32F, disp_id);
glBindBuffer(GL_TEXTURE_BUFFER, 0);
glActiveTexture(0);
The output works as expected when accessing this data in the vertex shader (position = coordinates + displacements), but when I try to access the coordinates and displacements in a geometry shader, I’m only able to get valid data from the coordinate sampler and not the displacement sampler. I’m binding/drawing as follows:
// Bind
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, conn_id);
glBindBuffer(GL_ARRAY_BUFFER, coord_id);
glEnableVertexAttribArray(coord_attrib);
glVertexAttribPointer(coord_attrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
glActiveTexture(GL_TEXTURE10);
glBindTexture(GL_TEXTURE_BUFFER, coord_texture_id);
glBindBuffer(GL_ARRAY_BUFFER, disp_id);
glEnableVertexAttribArray(disp_attrib);
glVertexAttribPointer(disp_attrib, 3, GL_FLOAT, GL_FALSE, 0, 0);
glActiveTexture(GL_TEXTURE11);
glBindTexture(GL_TEXTURE_BUFFER, disp_texture_id);
// Draw
glDrawElements(GL_TRIANGLES, conn_size, GL_UNSIGNED_INT, 0);
// Unbind...
I’m not sure why/how to properly set this up so I can access both the coordinates and displacements via a samplerbuffer in the geometry shader (only the coordinate sampler gives me any data).
I appreciate any help you may have for this!