Moving float array between compute shader and OF

I have a hard time finding any basic information about this topic.

I would like to move a float array from OF to a compute shader, calculate something and return a float array, but how do I get the array from ofBufferObject?

My compute shader looks like this

#version 440

struct SomeType {
float a;

layout(local_size_x = 100) in;

layout (std430, binding = 0) buffer FloatInput {
readonly SomeType data[];
} floatInput;

layout (std430, binding = 1) buffer FloatOutput {
writeonly SomeType data[];
} floatOutput;

void main(){
uint ident = gl_GlobalInvocationID.x;

// Some random function for demonstration[ident].a =[ident].a * 0.5f;

This is how I load the data to the shader from OF

void ofApp::setup(){

compute.setupShaderFromFile(GL_COMPUTE_SHADER, “compute.glsl”);


for (auto & f : shaderInput) {
f.a = ofRandom(0.0f, 0.9f);

floatBufferInput.allocate(shaderInput, GL_FLOAT);
floatBufferOutput.allocate(shaderInput, GL_FLOAT);
floatBufferInput.bindBase(GL_SHADER_STORAGE_BUFFER, 0);
floatBufferOutput.bindBase(GL_SHADER_STORAGE_BUFFER, 1);

void ofApp::update(){

compute.dispatchCompute(100, 1, 1);

// Tried a lot of thing here :slight_smile:

to read back an ofBufferObject you can use map which will return a pointer to the buffer memory, copy it somewhere or use it and then useunmap when you are done

Can you give me a hint?

I am doing this:

SomeType* floatArray =;

But my pointer is null.

Haha it deletes my brackets :slightly_smiling:


SomeType* floatArray =<SomeType>(GL_READ_ONLY);

SomeType* floatArray =<SomeType>(GL_READ_ONLY);
// do something with floatArray

Thanks Arturo

It turns out that I used the wrong enum for allocating the buffers

Documentation for allocating can be found here: