c++ - OpenGL 4.5 - Shader storage buffer objects layout -


i'm trying hand @ shader storage buffer objects (aka buffer blocks) , there couple of things don't grasp. i'm trying store (simplified) data of indeterminate number of lights n in them, shader can iterate through them , perform calculations.

let me start saying correct results, , no errors opengl. however, bothers me not know why is working.

so, in shader, got following:

struct pointlight {   vec3 pos;   float intensity; };  layout (std430, binding = 0) buffer pointlights {   pointlight pointlights[]; };  void main() {   pointlight light;   (int = 0; < pointlights.length(); i++) {     light = pointlights[i];     // etc   } } 

and in application:

struct pointlightdata {   glm::vec3 pos;   float intensity; };  class pointlight {   //  ...   pointlightdata data;   // ... };  std::vector<pointlight*> pointlights;  glgenbuffers(1, &bbo); glbindbuffer(gl_shader_storage_buffer, bbo); glnamedbufferstorage(bbo, n * sizeof(pointlightdata), null, gl_dynamic_storage_bit); glbindbufferbase(gl_shader_storage_buffer, 0, bbo);  ...  (unsigned int = 0; < pointlights.size(); i++) {   glnamedbuffersubdata(bbo, * sizeof(pointlightdata), sizeof(pointlightdata), &(pointlights[i]->data)); } 

in last loop i'm storing pointlightdata struct offset equal size times number of them i've stored (so offset 0 first one).

so, said, seems correct. binding points correctly set zeroeth, have enough memory allocated objects, etc. graphical results ok.

now questions. using std430 layout - in fact, if change std140 did breaks. why that? hypothesis layout generated std430 shader's pointlights buffer block happily matches generated compiler application's pointlightdata struct (as can see in loop i'm blindingly storing 1 after other). think that's case?

now, assuming i'm correct in assumption, obvious solution mapping sizes , offsets myself, querying opengl glgetuniformindices , glgetactiveuniformsiv (the latter called gl_uniform_size , gl_uniform_offset), got sneaking suspicion these 2 guys work uniform blocks , not buffer blocks i'm trying do. @ least, when following opengl throws tantrum, gives me 1281 error , returns weird number indices (something 3432898282 or whatever):

const char * names[2] = {    "pos", "intensity" };  gluint indices[2]; glint size[2]; glint offset[2];  glgetuniformindices(shaderprogram->id, 2, names, indices); glgetactiveuniformsiv(shaderprogram->id, 2, indices, gl_uniform_size, size); glgetactiveuniformsiv(shaderprogram->id, 2, indices, gl_uniform_offset, offset); 

am correct in saying glgetuniformindices , glgetactiveuniformsiv not apply buffer blocks?

if not, or fact it's working imagine coincidence, how mapping manually? checked appendix h of programming guide , wording array of structures confusing. if can't query opengl sizes/offsets i'm tryind do, guess compute them manually (cumbersome is) i'd appreciate in there, too.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -