I need to transfer several variable length arrays to the shader. So I build up a rather complicated data structure in glsl, which contains multiple image1D. But I cannot successfully transfer the data to the shader now.
Fragment Shader:
struct HoleArea {
bool clipping;
int mesh_object_id;
layout (rgba32f) image1D anchor_points;
layout (rgba32f) image1D clip_planes;
};
layout (binding = 2) uniform HoleArea hole_area[10];
And the C++ code:
// set the anchor_points in hole_area[0]
glBindBuffer(GL_TEXTURE_BUFFER, m_anchorPointBuffer);
glBufferData(GL_TEXTURE_BUFFER, m_anchorPointPos.size() * sizeof(FLOAT4), &m_anchorPointPos[0], GL_STATIC_DRAW);
glBindBuffer(GL_TEXTURE_BUFFER, 0);
glBindTexture(GL_TEXTURE_BUFFER, m_anchorPointTexture);
glTextureBuffer(m_anchorPointTexture, GL_RGBA32F, m_anchorPointBuffer);
glBindTexture(GL_TEXTURE_BUFFER, 0);
glBindImageTexture(2, m_anchorPointTexture, 0, GL_TRUE, 0, GL_READ_ONLY, GL_RGBA32F);
So here is my question:
What's the difference between image1D and imageBuffer? When I need to transfer a 1D glm::vec4 array into the shader, it seems that both image1D and imageBuffer can meet the requirement.
As for an image format, there are r32f, rg32f and rgba32f. Why there isn't a rgb32f format to save the glm::vec3 data?
For the code above, how should I set the anchor_points and clip_planes for each hole_area (hole_area[0], hole_area[1]...). In other words, how should I set the first variable (index of an image unit) in glBindImageTexture for each image1D.
I would be very thankful if somebody could answer my questions, thanks!