PDA

View Full Version : GLES compile errors under Marshmallow



TG1234
06-21-2016, 07:03 PM
Since I updated to Marshmallow a lot of my previously OK shaders now give compile errors.

"Global variable initializer must be a constant expression"

Simple example shader code to trigger it is

uniform float time;

float time2=time*0.4;

Error on the second line.

Is there any quick fix to get these shaders going?

Here is the full code that works OK still under glslsandbox
glslsandbox . com / e#33548.0
(Sorry had to obfuscate the url it to get past first time post restrictions, just remove all the spaces for the url)

The error is also under a Samsung Galaxy Note 5 if that matters. I can test on some other devices later tonight.

Any help will be greatly appreciated.

Alfonse Reinheart
06-21-2016, 07:45 PM
The answer is simple: initialize `time2` inside `main`, not as a global.

GLSL is not like C++; initializers outside of `main` don't get executed before `main`. They get executed by the compiler. And the compiler cannot know the contents of `time`, since it's a user-provided `uniform`.

TG1234
06-21-2016, 07:53 PM
The answer is simple: initialize `time2` inside `main`, not as a global.

GLSL is not like C++; initializers outside of `main` don't get executed before `main`. They get executed by the compiler. And the compiler cannot know the contents of `time`, since it's a user-provided `uniform`.

Well that sucks. I have a lot of shader code to fix now. Some will be simple move a line of code into main, some will be more complex. A load of shader code from glslsandbox has these same issues now. So it is most likely that the previous compiler accepted this error, but the new one under marshmallow is more strict and reports an error.