PDA

View Full Version : Array of constants



V-man
04-02-2005, 11:23 PM
How are we suppose to do an array of constants?

I thought it was

const vec2 myarray[2]=
{
vec2(3.0, 2.0),
vec2(4.0, 2.0)
};

sqrt[-1]
04-03-2005, 12:00 AM
I needed that recently as well.
I could not find a solution besides creating the array and assigning each element on startup. (and hoping that the compiler was smart and ultimately directly resolved all lookups to direct constants..)

ZbuffeR
04-03-2005, 12:12 AM
The spec for GLSL 1.10,59 says that

There is no mechanism for initializing arrays at declaration time from within a shader.

guyinhell
04-03-2005, 04:54 AM
to define a const array is not possible at the moment.
i have the same problem, in great need of a constant array. i assigned the values outside, then passed it as a normal. it might make things slow. but if you assigned the values one by one in the shader, its also slow.

jra101
04-03-2005, 01:19 PM
This is supported by NVIDIA's GLSL implementation.

V-man
04-03-2005, 05:13 PM
How does it work in NV?

My other guesses were
const vec2 myarray[2]= vec2[](
vec2(3.0, 2.0),
vec2(4.0, 2.0)
);

const vec2 myarray[2]= vec2[2](
vec2(3.0, 2.0),
vec2(4.0, 2.0)
);

const vec2 myarray[2]= vec2[](
3.0, 2.0,
4.0, 2.0
);

Something like the last one is better cause it avoids typing vec2 many times.

jra101
04-04-2005, 07:51 AM
It works just like the example you showed in your first post.

Java Cool Dude
04-19-2005, 05:39 PM
yup works on NV the following way

const vec4 stuff[2] = { vec4(x,x,x,x), vec4(s,s,s,s) };

John Kessenich
04-19-2005, 07:57 PM
Does declaring the array as a uniform, and setting it from the application work? Should be high performing. The language supports indirect indexing into uniform arrays.

V-man
04-21-2005, 03:58 AM
Yes, using a uniform array works fine.
I didn't do a performance test on this. I have big fillrate performance problem for the moment.