OpenGL ES 2.0着色器 - 哪一行是错误的?

时间:2014-11-07 17:25:55

标签: android opengl-es

在Android OpenGL ES 2.0着色器中,如果您有错误,如何找出错误所在的着色器哪一行?我有一些像这样的代码:

public static int loadShader(int type, String shaderCode){

        int shader = GLES20.glCreateShader(type);
        // add the source code to the shader and compile it
        GLES20.glShaderSource(shader, shaderCode);
        GLES20.glCompileShader(shader);

        final int[] compileStatus = new int[1];
        GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

        if (compileStatus[0] != 1) { // 1 is normal output
            if (type == GLES20.GL_VERTEX_SHADER) {
                System.out.println("vertex -- ");
            }
            else if (type == GLES20.GL_FRAGMENT_SHADER)  {
                System.out.println("fragment -- ");
            }
            System.out.println(type + " error " + compileStatus[0]);
            if (compileStatus[0] == GLES20.GL_TRUE) System.out.println("true");
        }

        return shader;
    }

它总是说我的着色器是正确的。与此同时,我稍后运行此代码:

    System.out.println(GLES20.glGetShaderInfoLog(mProgramHandle));

它说我有错误。这是错误消息:

W/Adreno-ES20﹕ <core_glGetShaderiv:443>: GL_INVALID_OPERATION

如何找出违规行???

编辑:我可能应该包含此代码。这里我使用加载着色器代码。此GL着色器集在一台设备上运行,而不是在另一台设备上运行。

private int prepGLShader() {

        int mProgramHandle = 0;
        mProgramHandle = GLES20.glCreateProgram();             // create empty OpenGL ES Program

        String vertex = readTextFileFromRawResource(context, R.raw.vert_mask);
        String fragment = readTextFileFromRawResource(context, R.raw.frag_mask);

        mVertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertex);
        mFragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragment);

        GLES20.glAttachShader(mProgramHandle, mVertexShader);   // add the vertex shader to program
        GLES20.glAttachShader(mProgramHandle, mFragmentShader); // add the fragment shader to program

        GLES20.glBindAttribLocation(mProgramHandle, 0, "a_Position");
        GLES20.glBindAttribLocation(mProgramHandle, 1, "a_TexCoordinate");


        GLES20.glLinkProgram(mProgramHandle);



        return mProgramHandle;
    }

0 个答案:

没有答案