[Solved]GL ES don't support 'switch' keyword in shader program

Problems building or running the engine, queries about how to use features etc.
Post Reply
motif
Kobold
Posts: 32
Joined: Sun Mar 06, 2005 5:16 pm

[Solved]GL ES don't support 'switch' keyword in shader program

Post by motif »

Ogre Version: :1.12.11:
Operating System: :Android:
Render System: :OpenGL ES 2.0:

Hi, I am doing an Android port of my project using Ogre 1.12.11. I have added RTSS to the scene manager in order to get material scripts to compile under GL ES. In one particular mesh that use material with alpha channel, the script failed to compile with the following error:

Code: Select all

E/OGRE: Program 'ccd77c2b4d566d088768d7ba9ee68733_FS' is not supported: 'ccd77c2b4d566d088768d7ba9ee68733_FS' ERROR: 17:20: 'switch' : Illegal use of reserved word
    ERROR: 17:20: 'switch' : syntax error
E/OGRE: Error: RTSS - creating GpuPrograms for pass 0 of 'Plant/OakA' failed
A/libc: /buildbot/src/android/ndk-release-r21/external/libcxx/../../external/libcxxabi/src/abort_message.cpp:72: abort_message: assertion "terminating with uncaught exception of type Ogre::RuntimeAssertionException: RuntimeAssertionException: gpu program could not be created in createGpuPrograms at ogre-1.12.11/Components/RTShaderSystem/src/OgreShaderProgramManager.cpp (line 259)" failed
    Fatal signal 6 (SIGABRT), code -1 (SI_QUEUE) in tid 6278 (pperstudio.gtd3), pid 6248 (pperstudio.gtd3)
On debugging the Ogre::RTShader::ProgramManager, I found that the generated script 'ccd77c2b4d566d088768d7ba9ee68733_FS':

Code: Select all

#version 100
precision highp float;
precision highp int;
//-----------------------------------------------------------------------------
// Program Type: Fragment shader
// Language: glsles
// Created by Ogre RT Shader Generator. All rights reserved.
//-----------------------------------------------------------------------------
    
//-----------------------------------------------------------------------------
//                         PROGRAM DEPENDENCIES
//-----------------------------------------------------------------------------
#include <OgreUnifiedShader.h>
#include "SGXLib_PerPixelLighting.glsl"
#include "FFPLib_Common.glsl"
#include "FFPLib_Texturing.glsl"
#include "FFPLib_AlphaTest.glsl"
compiled using the language 'glsles' include an alpha test GLSL script that has an Alpha_Func using the 'switch' keyword:

Code: Select all

bool Alpha_Func(in int func, in float alphaRef, in float alphaValue)
{
    bool result = true;
    switch (func)
    {
        case 0:// - CMPF_ALWAYS_FAIL,
            result = false;
        break;
        case 1: //- CMPF_ALWAYS_PASS,
            result = true;
        break;
        case 2: //- CMPF_LESS,
            result = alphaValue < alphaRef;
        break;
        case 3: //- CMPF_LESS_EQUAL,
            result = alphaValue <= alphaRef;
        break;
        case 4: //- CMPF_EQUAL,
            result = alphaValue == alphaRef;
        break;
        case 5: //- CMPF_NOT_EQUAL,
            result = alphaValue != alphaRef;
        break;
        case 6: //- CMPF_GREATER_EQUAL,
            result = alphaValue >= alphaRef;
        break;
        case 7: //- CMPF_GREATER
            result = alphaValue > alphaRef;
        break;
    }
    return result;
}
I workaround the problem by using the if-else if statements:

Code: Select all

    if (func == 0) // - CMPF_ALWAYS_FAIL,
        result = false;
    else if (func == 1) //- CMPF_ALWAYS_PASS,
        result = true;
    else if (func == 2) //- CMPF_LESS,
        result = alphaValue < alphaRef;
    else if (func == 3) //- CMPF_LESS_EQUAL,
        result = alphaValue <= alphaRef;
    else if (func == 4) //- CMPF_EQUAL,
        result = alphaValue == alphaRef;
    else if (func == 5) //- CMPF_NOT_EQUAL,
        result = alphaValue != alphaRef;
    else if (func == 6) //- CMPF_GREATER_EQUAL,
        result = alphaValue >= alphaRef;
    else if (func == 7) //- CMPF_GREATER
        result = alphaValue > alphaRef;
This problem doesn't exist when using the Open GL render system where the RTShader is not required to be added to the scene manager.
Last edited by motif on Tue Mar 16, 2021 2:01 pm, edited 1 time in total.
paroj
OGRE Team Member
OGRE Team Member
Posts: 1994
Joined: Sun Mar 30, 2014 2:51 pm
x 1074
Contact:

Re: GL ES don't support 'switch' keyword in shader program

Post by paroj »

will be fixed with this:
https://github.com/OGRECave/ogre/pull/1924

feel free to directly open a pull-request next time.
motif
Kobold
Posts: 32
Joined: Sun Mar 06, 2005 5:16 pm

Re: [Solved]GL ES don't support 'switch' keyword in shader program

Post by motif »

Ok, thanks.
Post Reply