PDA

View Full Version : reading data back from compute shader



driver
11-10-2013, 08:11 AM
Hi

I am trying to read back data and print it. I use glMapBuffer and woud like my returned data to be mapped to an array of structs. I would then loop over the array and print out the struct members.

In the below code, I want to avoid creating a struct for every int,float pair if possible.



struct A{
int a;
float b;

};


struct A *download;
download=(struct A*) glMapBuffer(GL_ARRAY_BUFFER,GL_READ_ONLY);
if(download!=(struct A*)NULL{
for(int k=0;k<numElements;k++){
//struct A a; //do byte offset copying into struct members here ....
printf("%d %0.2f",download[k].a,dowload[k].b);
}
}


And suppose if there was no other way except to create a struct for every int,float pair, what is the most elegant way to do it? I'm using C++.

thanks

carsten neumann
11-10-2013, 01:09 PM
In the below code, I want to avoid creating a struct for every int,float pair if possible.


Sorry, not sure what you mean. In the code you posted the only place you created a variable of type A is commented out, the rest just casts the pointer returned by glMapBuffer to A* and uses that to access the buffer contents.

driver
11-10-2013, 06:04 PM
Hi there

I commented it out to show that this is where the line to create a struct would go.

Right now, with just the casting of bytes to struct, I don't think it is possible to say download[k].a,download[k].b and get int and float values appearing in pairs, just as if I had an array of struct A and I was looping over the array and printing a.a , a.b . that's why I am also getting values printed out that I was not expecting to see currently.

carsten neumann
11-12-2013, 12:03 PM
It should, provided you make sure that the struct has a layout that matches whatever you write into the buffer.