SeismicSquall
SeismicSquall

Reputation: 378

How to declare a function that returns an array in glsl es (version 100)

The following shader method:

float[1] GetArray()
{
    float array[1];
    array[0] = 1.0;
    return array;
}

Gives me: ERROR: 0:1: 'GetArray' : syntax error: Array size must appear after variable name

Upvotes: 10

Views: 5298

Answers (1)

SeismicSquall
SeismicSquall

Reputation: 378

I found a way to work around this limitation. You can return an array by modifying the passed in array by reference. Here is a sample fragment shader:

void GetArray(inout vec4 array[1])
{
    array[0] = vec4(.5,.2,.1,1.0);
} 

void main()
{
    vec4 test[1];
    GetArray(test);
    gl_FragColor = test[0];
}

Upvotes: 12

Related Questions