sleap
06-15-2011, 03:38 AM
Hi,
There seems to be very little information on this or maybe I'm looking in the wrong places. It's now possible to declare a struct in GLSL and an array of that type. This array can map to global video memory - a texture buffer object for example. However I'm finding it slower to use an array of structs than a big chunk of floats which I look up manually.
eg.
//particle_header.h
struct Particle
{
vec4 position;
vec4 velocity;
};
//shader.frag
#include "particle_header.h" //inserted in shader loading code
Particle* particles;
void main()
{
int index = ...
particles[index].position += ...
discard;
}
This data can also be accessed CPU side via glMapBuffer:
#include "particle_header.h"
...
Particle* particles = glMapBuffer(...);
particles[123].position = ...
I really like the idea of this functionality but as mentioned I have found it much slower than say "vec4* particles;". Additionally, GLSL will pack the struct differently to g++. I've attempted to manually pad the struct but I'd like a cleaner way to do it. At the very least some definite rules that GLSL follows to pack structs.
Some indication is given here:
http://msdn.microsoft.com/en-us/library/bb509632(v=vs.85).aspx
Is there a standard way to use structs in GLSL which is both modular (easy to access from both GPU and CPU) and fast?
Thanks in advance
There seems to be very little information on this or maybe I'm looking in the wrong places. It's now possible to declare a struct in GLSL and an array of that type. This array can map to global video memory - a texture buffer object for example. However I'm finding it slower to use an array of structs than a big chunk of floats which I look up manually.
eg.
//particle_header.h
struct Particle
{
vec4 position;
vec4 velocity;
};
//shader.frag
#include "particle_header.h" //inserted in shader loading code
Particle* particles;
void main()
{
int index = ...
particles[index].position += ...
discard;
}
This data can also be accessed CPU side via glMapBuffer:
#include "particle_header.h"
...
Particle* particles = glMapBuffer(...);
particles[123].position = ...
I really like the idea of this functionality but as mentioned I have found it much slower than say "vec4* particles;". Additionally, GLSL will pack the struct differently to g++. I've attempted to manually pad the struct but I'd like a cleaner way to do it. At the very least some definite rules that GLSL follows to pack structs.
Some indication is given here:
http://msdn.microsoft.com/en-us/library/bb509632(v=vs.85).aspx
Is there a standard way to use structs in GLSL which is both modular (easy to access from both GPU and CPU) and fast?
Thanks in advance