Archive 17/01/2023.

Glsl array

ghidra

This might be more of a glsl question than a urho one.
I’m trying to create an array in glsl.
in a function

int myarray[8] = int[](0, 32, 8, 40, 2, 34, 10, 42);

I’m getting this error:

error: array constructors forbidden in GLSL 1.10 (GLSL 1.20 or GLSL ES 3.00 required)

Is there no way to achieve this?
Thank you.

ghidra

UPDATE:

I managed to get my Framerates back up, with a silly hack. Maybe that is just the nature of glsl, I dont know.
Before I was calling a function that had that origional int array, and set the values. This was being run on every fragment.
Instead, I make a global int array, and set the length. then before doing anything else i call a function that builds that array, so in theroy it only calls once when the shader is run on the object, saving a lot of setting.

psuedo code:

int array[64];
build_array(){
     array[0]=0;array[1]=1;array[3]=3;...."61 more values"
}
PS(){
     build_array();
     "now everything else"
}

Still seems hacky to me. When trying to do anything i found from the web on how to set arrays in glsl, i got errors.
I tried:

int array[64] = int[64]{...};
int array[64] = int[]{...};
const length = 64;
int array[length] = {...};
etc..

errors were:

error: C-style initialization requires the GL_ARB_shading_language_420pack extension
-or-
error: array constructors forbidden in GLSL 1.10 (GLSL 1.20 or GLSL ES 3.00 required)

Should I consider my work around the solve for this, as acording to the errors, we cant declare arrays with values?