Schnulla
07-21-2010, 11:04 AM
Hi,
ok to make it short this is what I want to do:
1. I have an array of structs on client side (c++):
struct LightSource
{
float Position[3];
float Ambient[4];
float Diffuse[4];
float Specular[4];
};
LightSource LightSources[12];
2. I want to upload this array as fast as possible
to a similar uniform array structure in the shader.
What is the best way to do this? Will these uniform buffer
objects do the trick? Something like this:
layout(std140) uniform LightSourceBlock
{
vec3 Position;
vec4 Ambient;
vec4 Diffuse;
vec4 Specular;
} LightSources[12];
So that I can use glBufferData to upload the whole
stuff with a single API call? What about the byte alignment/
padding of the client struct. I guess there are some things
that could go wrong?
Or should I use separate uniform arrays for the light source
components and then call glUniformXfv for each array?
Your opinions are really welcome!
If you think UBOs can do this job maybe you could also
share some code snippets for the use with array (I already
know the code examples for uploading a single uniform block).
Thank you! :)
ok to make it short this is what I want to do:
1. I have an array of structs on client side (c++):
struct LightSource
{
float Position[3];
float Ambient[4];
float Diffuse[4];
float Specular[4];
};
LightSource LightSources[12];
2. I want to upload this array as fast as possible
to a similar uniform array structure in the shader.
What is the best way to do this? Will these uniform buffer
objects do the trick? Something like this:
layout(std140) uniform LightSourceBlock
{
vec3 Position;
vec4 Ambient;
vec4 Diffuse;
vec4 Specular;
} LightSources[12];
So that I can use glBufferData to upload the whole
stuff with a single API call? What about the byte alignment/
padding of the client struct. I guess there are some things
that could go wrong?
Or should I use separate uniform arrays for the light source
components and then call glUniformXfv for each array?
Your opinions are really welcome!
If you think UBOs can do this job maybe you could also
share some code snippets for the use with array (I already
know the code examples for uploading a single uniform block).
Thank you! :)