opengl - Getting data back from compute shader -
i'm new opengl , found myself in situation need data compute shader miss critical knowledge can't work. came here, maybe can give me hints.
say have compute shader this:
#version 430 core struct rmtriangle { vec4 probecenter; vec4 triangles[3]; }; layout(std430, binding=9) buffer trianglebuffer { rmtriangle triangles[]; }trbuffer; //other uniforms, variables , stuff void main() { //here make computations , assign values //trbuffer's triangles array }
now use trbuffer's data in application. told make shader storage buffer did:
private int ssbo; gl.glgenbuffers(1, &ssbo); gl.glbindbuffer(gl_shader_storage_buffer, ssbo); //just allocate enough amount of memory gl.glbufferdata(gl_shader_storage_buffer, max_triangles * sizeof_triangle, null, gl_dynamic_read);
then this:
int blockindex = gl.glgetprogramresourceindex(program,gl_shader_storage_block, name.getbytes(), 0); if (blockindex != gl_invalid_index) { gl.glshaderstorageblockbinding(program, blockindex, index); } else { system.err.println("warning: binding " + name + " not found"); }
where name = "trianglebuffer" , index = 9
i know how access ssbo created in application. don't know how assign/transfer triangebuffer data ssbo.
add glbindbufferbase(gl_shader_storage_buffer, 9, ssbo);
also, when fetch data ssbo
s glmapbufferrange
, memcpy
stuff need.
Comments
Post a Comment