So what’s the status on constant arrays in GLSL? When I do something like this:
const int TEXMODE_OFF = 0;
...
const int TEX_MODE[ MAX_TEX_UNITS ]
= int[]( TEXMODE_OFF, TEXMODE_OFF, TEXMODE_OFF,
TEXMODE_OFF, TEXMODE_OFF, TEXMODE_OFF );
I get this from NVidia:
error C7516: OpenGL does not allow constant arrays
Fortunately NVidia’s compiler is aggressive and, if I just remove the const from the array, will recognize the elements and size are constant and fold them into the shader (collapsing ifs/for iterations/etc.).
But it’d be nice for clarity sake to have the const’s on there, and to protect against less aggressive GLSL compilers.
ATI compilers are even more aggressive. afaik writing doubles as integers is an error (according to GLSL spec) where nvidia is fine with it. but if you receive this error you should try to remove the const then. recommend taking a look at GLSL specs .
I also never managed to get constant arrays either, even with “#version 120” on Nvidia. I eventually did the same thing as you which is to use a non-constant array.
declared as const the compiler can use that hint as an optimization. i would think the compiler will see if something is modified or not even without const and use it internally as const (placing in special registers or something, dont know). const seems to be obsolete to me these days with compilers that have crazy optimizations. anyone any comments on this?