javajoglcompute-shadershader-storage-bufferbuffer-objects

Having trouble with SSBO in JOGL


I've been trying to initialize an SSBO and pass it to a a compute shader.

int ssbo = glGenBuffers();

FloatBuffer buff = BufferUtils.createFloatBuffer(4);
buff.put(0.1f);
buff.put(0.4f);
buff.put(1.5f);
buff.put(0.2f);

glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssbo);
glBufferData(GL_SHADER_STORAGE_BUFFER, buff, GL_DYNAMIC_READ);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0);

int block_index = glGetProgramResourceIndex(programID, GL_SHADER_STORAGE_BLOCK, "shader_data");
System.out.println(block_index);

int ssbo_binding_point_index = 1;
glShaderStorageBlockBinding(programID, block_index, ssbo_binding_point_index);


int binding_point_index = 1;
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, binding_point_index, ssbo);

and in the shader I have:

layout(binding = 1) buffer shader_data {
    vec4 sph;
};

When I run this, sph is filled with 0-s. I tried to read the data from the buffer:

FloatBuffer a = BufferUtils.createFloatBuffer(4);
glGetBufferSubData(GL_SHADER_STORAGE_BUFFER, 0, a);
System.out.println(glGetError());

//and then print a...

And this gets me Error 1281, aka 0 + a.size() > the size of the ssbo. Then I checked the actual size of the SSBO:

IntBuffer b = BufferUtils.createIntBuffer(1);
glGetBufferParameteriv(GL_SHADER_STORAGE_BUFFER, GL_BUFFER_SIZE, b);
System.out.println("buffer size: " + b.get(0));

And this gives me 0. I've used this article. I'm pretty new to OpenGL so there might be a really obvious mistake in my code and that's why I included so much of it here.

Thanks in advice!

Edit: LWJGL version is 3.2.1 build 12


Solution

  • Just flipping the buffer after filling it with data works.