0

I have this code:

String vertexShaderText = 
            "void main()\n"
            + "{\n"
            + "}\n";
    int vertexShader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vertexShader, vertexShaderText);
    GLES20.glCompileShader(vertexShader);
    int[] err = new int[1];
    err[0] = 555;
    GLES20.glGetShaderiv(vertexShader, GLES20.GL_COMPILE_STATUS, err, 0);

And err[0] never changes. If comment line "err[0] = 555;", value err[0] will be 0.

vertexShader have value 43(not null) and this code from override function

@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) 
{}

Maybe I have problems with device's video card? Thanks!


the same problem. I don't have compile error. Just function glGetShaderiv not returning result. Here I have err[0] == 0

String vertexShaderText = 
            "void main()"
            + "{"
            + "     gl_Position = vec4(0.0, 0.0, 0.0, 0.0);"
            + "}";
    int vertexShader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vertexShader, vertexShaderText);
    GLES20.glCompileShader(vertexShader);
    int[] err = new int[1];
    GLES20.glGetShaderiv(vertexShader, GLES20.GL_COMPILE_STATUS, err, 0);
Dmitry
  • 31
  • 5
  • What device are you running on? Can you try calling `glGetError()` both before and after the `glGetShaderiv()` call, and see if it returns an error? For example, it's technically allowed for ES 2.0 implementations to not support shader compilation. – Reto Koradi Jun 28 '15 at 18:31
  • Reto Koradi, thanks, Alex T. solving my problem. I had to call setEGLContextVersion(2) for GLSurfaceView – Dmitry Jun 28 '15 at 18:34

1 Answers1

0

You need to write a value back out to gl_Position.

In your main body, write gl_Position = vec4(0.0f,0.0f,0.0f,0.0f);; this should allow the shader to compile.

You must also ensure that you inform Dalvik you wish to use the OpenGL ES 2.0 context; this is done by calling setEGLContextVersion(2).

Mapsy
  • 4,192
  • 1
  • 37
  • 43
  • But I can't check compile result. This is my problem. My glGetShaderiv not change values in input integer array. `If an error is generated, no change is made to the contents of params.` https://www.khronos.org/opengles/sdk/docs/man/xhtml/glGetShaderiv.xml – Dmitry Jun 28 '15 at 18:02
  • What is the value of err[0] after executing the code above? – Mapsy Jun 28 '15 at 18:06
  • Also does your card support GL ES 2.0? – Mapsy Jun 28 '15 at 18:07
  • err[0] == 0 before and after the function – Dmitry Jun 28 '15 at 18:08
  • That indicates an error. What is the integer assigned to the vertex shader? – Mapsy Jun 28 '15 at 18:11
  • I'm trying code from this thread http://stackoverflow.com/questions/9198293/is-there-a-way-to-check-if-android-device-supports-opengl-es-2-0 and have boolean supportsEs2 == true. 43 assigned to the vertex shader. Always 43 – Dmitry Jun 28 '15 at 18:17
  • Have you called setEGLContextVersion(2)? – Mapsy Jun 28 '15 at 18:21
  • Aside from missing the topic of the question, this code would actually be invalid with ES 2.0. Integers aren't converted to floats automatically. – Reto Koradi Jun 28 '15 at 18:23
  • @RetoKoradi I have no trouble compiling that. – Mapsy Jun 28 '15 at 18:24
  • Alex T., Thank you very much! setEGLContextVersion(2) solved this problem! – Dmitry Jun 28 '15 at 18:31
  • No worries dude, glad I could help. If you're just getting started, I really recommend the book OpenGL ES 2 for Android. – Mapsy Jun 28 '15 at 18:33
  • 1
    It's unfortunate when the question gets edited. But as far as I can tell, it was always asking why the compile status does not change, which it should even if the shader code is invalid. The code in your answer will compile on some devices, but not on others. For example, I've seen devices with Qualcomm GPUs fail to give an error in this case, even though the code is illegal based on the specs. It will fail to compile for example on devices with Imagination GPUs. – Reto Koradi Jun 28 '15 at 18:40