Global array with initialization


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 :slight_smile:

Yes it is, but you need to do this

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

I think it is only available in the latest GLSL 1.2 specs, so you may have to update your driver.

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?

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.


Oops my bad, I have the 97.02 driver and a 8800GTX. :slight_smile:

Thanks. Then I will probably wait :slight_smile: 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?

Yes that is valid.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.