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
floatOutput.data[ident].a = floatInput.data[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”);
compute.linkProgram();
shaderInput.resize(100);
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.begin();
compute.dispatchCompute(100, 1, 1);
compute.end();
// Tried a lot of thing here
}