I’m currently trying to write 4 values to an SSBO in a compute shader using this code:
float[] data = { 1.0f, 2.0f, 3.0f, 4.0f };
ssbo = glGenBuffer();
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);glBufferData(GL_SHADER_STORAGE_BUFFER, data.Length * sizeof(float), data, GL_DYNAMIC_DRAW);
Which is then rendered with this code:
glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glUseProgram(computeProgram);
glBindImageTexture(0, texture.Handle, 0, false, 0, GL_READ_WRITE, GL_RGBA32F);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texture.Handle);
glDispatchCompute((uint)Width / 8, (uint)Height / 8, 1);
glMemoryBarrier(GL_SHADER_IMAGE_ACCESS_BARRIER_BIT);
I’m using the compute shader below:
#version 460 core
layout (local_size_x = 8, local_size_y = 8, local_size_z = 1) in;
layout (rgba32f) uniform image2D imgOutput;
layout(std430, binding = 0) buffer VertexData
{
float vertexData[];
};
void main()
{
vec4 value = vec4(0.1, 0.1, 0.1, 1.0);
ivec2 texelCoord = ivec2(gl_GlobalInvocationID.xy);
if (vertexData.length() == 0)
imageStore(imgOutput, texelCoord, vec4(1));
else
imageStore(imgOutput, texelCoord, vec4(0, 1, 0, 1));
}
The screen always shows as white, indicating that there are no values in the vertexData
array. There are no error codes thrown during this code, why doesn’t the buffer receive any of the data?