View Full Version : global array with initialization

12-10-2006, 03:33 AM

in HLSL it's possible to do something like

vec2 array[] = { (0.0, 1.0), (2.0, 3.0) }I don't really care so much about the {-brackets but if it is somehow possible to declare an global array and assign values to it.

So I can call from every function array[1] and get vec2(0.0, 1.0).

Is this possible?

thanks :)

12-10-2006, 02:52 PM
Yes it is, but you need to do this

vec2 array[] = { vec2(0.0, 1.0), vec2(2.0, 3.0) };

12-10-2006, 04:37 PM
I think it is only available in the latest GLSL 1.2 specs, so you may have to update your driver.

12-11-2006, 01:28 AM
Thank you both! When I tried the
vec2 array[] = { vec2(0.0, 1.0), vec2(2.0, 3.0) };
this didn't work and the GLSL Syntax Validator reported an error. Does anyone know since which driver version GLSL 1.2 is supported by the ATI and nVidia cards?

12-11-2006, 04:33 AM
The 97 series drivers from NVIDIA support version 1.2 in beta form. It can be enabled under Windows with NVEmulate, and under unix-like operating systems by editing a config file (see the GLSL release notes). The links to NVemulate and the GLSL release notes are below:


GLSL Release notes

As a quick note of caution, NVIDIA has not yet released a 97 series driver for pre-8800 cards on Windows, and with special branches it might be possible to run across a 97 series driver without the beta 1.2 support. The GLSL release notes point out the versions recommended for use at this time.


12-11-2006, 08:00 AM
Oops my bad, I have the 97.02 driver and a 8800GTX. :)

12-12-2006, 01:07 AM
Thanks. Then I will probably wait :) Only have an 6800GT.

Is it possible to do something like thing in an uniform array? Calculate the values on the CPU and pass an array of the sort:
uniform vec2 uarray[100];
to the glsl shaders?

12-12-2006, 04:15 PM
Yes that is valid.