0
votes

I have a very strange problem with my problem on android 2.3.3 - I try to compile a basic fragment shader, but the compiler gives back a 0 as compileStatus.

Here is my shader compile snippet:

    if (fragmentShaderHandle != 0) {

        // Pass in the shader source.
        GLES20.glShaderSource(fragmentShaderHandle, fragmentShader);

        // Compile the shader.
        GLES20.glCompileShader(fragmentShaderHandle);

        // Get the compilation status.
        final int[] compileStatus = new int[1];
        GLES20.glGetShaderiv(fragmentShaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

        // If the compilation failed, delete the shader.
        if (compileStatus[0] == 0) {

            ErrorLog = GLES20.glGetShaderInfoLog(fragmentShaderHandle);

            GLES20.glDeleteShader(fragmentShaderHandle); 
            fragmentShaderHandle = 0;
        }           
    }

    if (fragmentShaderHandle == 0) {

        throw new RuntimeException("Error creating fragment shader. Error: " + ErrorLog);
    }

The strangest thing, that the glGetShaderInfoLog gives back an empty string as an error - I dont get any information, other then "Error creating fragment shader." which is my error message. If I skip that line, then the program binding will give an error, as the fragment shader is not existing.

I tried every shader (if there is the error) but even the simplest shader dont run (simplest shader: void main { gl_FragmentColor = vec4(1.0f, 1.0f, 1.0f, 1.0f) } this give the same error without any error message).

But: this code will run flawlesly on android 4.0 (my friend tried it, and its work in the emulator as well). I asked some other friend with android 2.3 - but everyone got the same error with no error message.

The telephone support OpenGL 2.0 ES - if I dont load shader, just clear the screen, it works just fine.

Anybody have any idea where should I start looking? Without error message, its pretty hard to hunt down where I messed up :|

Thank you!

EDIT:

1) It sucessfully compile the vertexShader, and, if I dont load any shader, I can clear the screen using the GLES20.glClear(...) command, and it run succesfully on any tested device.

2) I added a check to see if the device compatible with the openGL 2.0 - each tested device said everything is ok:

boolean supportsEs2 = configurationInfo.reqGlEsVersion >= 0x20000;

3) I tried out the int glError = GLES20.glGetError(); - it returns a zero, like the was no error (as I get no error message either) - my shader still cant compile :(

1
How do you know that your device supports OpenGL ES 2.0 as that was optional in Android 2.3. Check the value of fragmentShaderHandler after every call.Morrison Chang
Oops didn't see the outer fragementShaderHandler conditional.Morrison Chang
Have you tried calling glGetError()? I wonder if something might be so messed up that it doesn't even try to compile your shader. For example, fragmentShaderHandle being invalid for some reason.Reto Koradi
I updated my question - the device support openGL ES 2.0. And the glGEtError() return 0. I have no freaking idea whats wrong :(Gabriel Butcher

1 Answers

1
votes

Not sure why you're not getting an error string from glGetShaderInfoLog(), but your "simplest fragment shader" contains multiple errors:

void main { gl_FragmentColor = vec4(1.0f, 1.0f, 1.0f, 1.0f) }
  • Needs precision qualifier for floats.
  • Needs empty parentheses after main.
  • The predefined output variable is gl_FragColor, not gl_FragmentColor.
  • 1.0f is not a valid constant in ES 2.0. Must be 1.0.
  • Semicolon missing after statement.

The correct version would be:

precision mediump float;
void main() { gl_FragColor = vec4(1.0, 1.0, 1.0, 1.0); }