Android OpenGL ES 2.0: Is "switch-case" syntax possible in GLSL fragment shader on Samsung Galaxy S2?

Navigateur picture Navigateur · Apr 14, 2013 · Viewed 10.9k times · Source

Does anybody know how to do switch case syntax in the fragment shader on the Samsung Galaxy S2? I get the compilation error: Expected literal or '(', got 'switch'.

My syntax is as follows:

switch(i){
    case 0: x = alphas[0]; break;
    case 1: //...etc.
}

This works fine on the Nexus 7, but on the Galaxy S2 I get the above error. Are switch case instructions simply impossible on the Galaxy S2? The reason why I want to use them is they appear to give a performance improvement over if else on the Nexus 7. If they are impossible on the Galaxy S2, is there a way to query the device and use switch case if available, and if else otherwise?

Answer

Kimi picture Kimi · Apr 14, 2013

switch statement is not supported in OpenGL ES 2.0. From the OpenGL ES Shading Language 1.0.17 spec 3.7:

The following are the keywords reserved for future use. Using them will result in an error:

asm class union enum typedef template this packed goto switch default ...