Can't initialize an array with a single element?


why do I get a shader compile error when I try to put this code in my vertex shader:

vec3 lightColor[1] = vec3;

but this works:

vec3 lightColor[2] = vec3;

If GLSL doesn’t allow me to initialize my single-element array this way, how can I do it?


Actually, this works for me.

But why would you want a single element array, why can’t you just use a standard vec3?
vec3 lightColor = vec3(1,1,1);

why do I get a shader compile error

What vendor? What error? This should work:

This implies that single-element arrays are legal.

Also, does it change anything when you provide an explicit size on the right hand-side of the initialization

vec3 lightColor[1] = vec3[1](vec3(1,1,1));

or when you leave explicit size out of the state in general

vec3 lightColor[] = vec3[](vec3(1,1,1));


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