glsl-optimizer icon indicating copy to clipboard operation
glsl-optimizer copied to clipboard

Spurious error: initializer of const variable must be a constant expression

Open karlhendrikse opened this issue 7 years ago • 0 comments

The compiler won't accept a constant if it's initialized with an expression that calls a built-in function, but it should.

Example fragment shader code:

const float x = sqrt(2.0);

void main()
{
  gl_FragColor = vec4(x);
}

Expected result:

No errors, since sqrt(2.0) is a constant expression according to the GLSL spec section 4.3.3. The example code above compiles correctly on Android and Windows.

"A constant expression is one of" ... "the value returned by a built-in function call whose arguments are all constant expressions, with the exception of the texture lookup functions and the noise functions".

Observed result:

Error: (1,17): error: initializer of const variable `x' must be a constant expression

karlhendrikse avatar Nov 17 '16 10:11 karlhendrikse