Example usage for android.opengl GLES20 GL_LINK_STATUS

List of usage examples for android.opengl GLES20 GL_LINK_STATUS

Introduction

In this page you can find the example usage for android.opengl GLES20 GL_LINK_STATUS.

Prototype

int GL_LINK_STATUS

To view the source code for android.opengl GLES20 GL_LINK_STATUS.

Click Source Link

Usage

From source file:Main.java

private static int linkProgram(int program) {
    int[] status = new int[1];
    GLES20.glLinkProgram(program);//from w w  w .j a v  a  2 s.com
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, status, 0);
    if (status[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Error linking program: " + GLES20.glGetProgramInfoLog(program));
        return 0;
    }
    return 1;
}

From source file:Main.java

public static int createProgram(int vsh, int fsh, String... attributes) {
    int[] status = new int[1];
    int ph = GLES20.glCreateProgram();
    if (ph <= 0) {
        throw new RuntimeException("Could not create program");
    }// w w  w  .j  a  v a2s . co m
    GLES20.glAttachShader(ph, vsh);
    GLES20.glAttachShader(ph, fsh);
    for (int i = 0; i < attributes.length; ++i) {
        GLES20.glBindAttribLocation(ph, i, attributes[i]);
    }
    GLES20.glLinkProgram(ph);
    GLES20.glGetProgramiv(ph, GLES20.GL_LINK_STATUS, status, 0);
    if (status[0] == 0) {
        GLES20.glDeleteProgram(ph);
        throw new RuntimeException("Could not link program");
    }

    return ph;
}

From source file:Main.java

public static int setupProgram(String vxShaderCode, String frShaderCode) {
    int mProgram;
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vxShaderCode);
    int fragmentShader = loadShader(GLES20.GL_FRAGMENT_SHADER, frShaderCode);
    if (vertexShader == 0 || fragmentShader == 0) {
        throw new RuntimeException("shader not loaded");
    }/* w ww. ja v  a  2 s  . c o  m*/
    mProgram = GLES20.glCreateProgram(); // create empty OpenGL ES Program
    GLES20.glAttachShader(mProgram, vertexShader); // add the vertex shader
    // to program
    GLES20.glAttachShader(mProgram, fragmentShader); // add the fragment
    // shader to program
    GLES20.glLinkProgram(mProgram);

    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(mProgram, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e("jay", "Could not link program: ");
        Log.e("jay", GLES20.glGetProgramInfoLog(mProgram));
        GLES20.glDeleteProgram(mProgram);
        mProgram = 0;
    }

    return mProgram;
}

From source file:Main.java

public static int createProgramFromShaderSrc(String vertexShaderSrc, String fragmentShaderSrc) {
    int vertShader = initShader(GLES20.GL_VERTEX_SHADER, vertexShaderSrc);
    int fragShader = initShader(GLES20.GL_FRAGMENT_SHADER, fragmentShaderSrc);

    if (vertShader == 0 || fragShader == 0)
        return 0;

    int program = GLES20.glCreateProgram();
    if (program != 0) {
        GLES20.glAttachShader(program, vertShader);
        checkGLError("glAttchShader(vert)");

        GLES20.glAttachShader(program, fragShader);
        checkGLError("glAttchShader(frag)");

        GLES20.glLinkProgram(program);/*  w  w w . j  a  v  a2s . c om*/
        int[] glStatusVar = { GLES20.GL_FALSE };
        GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, glStatusVar, 0);
        if (glStatusVar[0] == GLES20.GL_FALSE) {
            Log.e(LOGTAG, "Could NOT link program : " + GLES20.glGetProgramInfoLog(program));
            GLES20.glDeleteProgram(program);
            program = 0;
        }
    }

    return program;
}

From source file:Main.java

public static int loadProgram(final String strVSource, final String strFSource) {
    int iVShader;
    int iFShader;
    int iProgId;//from w w  w .j  a v a  2s . c o m
    int[] link = new int[1];
    iVShader = loadShader(strVSource, GLES20.GL_VERTEX_SHADER);
    if (iVShader == 0) {
        Log.d("Load Program", "Vertex Shader Failed");
        return 0;
    }
    iFShader = loadShader(strFSource, GLES20.GL_FRAGMENT_SHADER);
    if (iFShader == 0) {
        Log.d("Load Program", "Fragment Shader Failed");
        return 0;
    }

    iProgId = GLES20.glCreateProgram();

    GLES20.glAttachShader(iProgId, iVShader);
    GLES20.glAttachShader(iProgId, iFShader);

    GLES20.glLinkProgram(iProgId);

    GLES20.glGetProgramiv(iProgId, GLES20.GL_LINK_STATUS, link, 0);
    if (link[0] <= 0) {
        Log.d("Load Program", "Linking Failed");
        return 0;
    }
    GLES20.glDeleteShader(iVShader);
    GLES20.glDeleteShader(iFShader);
    return iProgId;
}

From source file:Main.java

/**
 * Helper function to compile and link a program.
 *
 * @param vertexShaderHandle   An OpenGL handle to an already-compiled vertex shader.
 * @param fragmentShaderHandle An OpenGL handle to an already-compiled fragment shader.
 * @param attributes           Attributes that need to be bound to the program.
 * @return An OpenGL handle to the program.
 *//*from   ww  w . j av  a  2 s.c  o m*/
public static int createAndLinkProgram(final int vertexShaderHandle, final int fragmentShaderHandle,
        final String[] attributes) {
    int programHandle = GLES20.glCreateProgram();

    if (programHandle != 0) {
        // Bind the vertex shader to the program.
        GLES20.glAttachShader(programHandle, vertexShaderHandle);

        // Bind the fragment shader to the program.
        GLES20.glAttachShader(programHandle, fragmentShaderHandle);

        // Bind attributes
        if (attributes != null) {
            final int size = attributes.length;
            for (int i = 0; i < size; i++) {
                GLES20.glBindAttribLocation(programHandle, i, attributes[i]);
            }
        }

        // Link the two shaders together into a program.
        GLES20.glLinkProgram(programHandle);

        // Get the link status.
        final int[] linkStatus = new int[1];
        GLES20.glGetProgramiv(programHandle, GLES20.GL_LINK_STATUS, linkStatus, 0);

        // If the link failed, delete the program.
        if (linkStatus[0] == 0) {
            Log.e(TAG, "Error compiling program: " + GLES20.glGetProgramInfoLog(programHandle));
            GLES20.glDeleteProgram(programHandle);
            programHandle = 0;
        }
    }

    if (programHandle == 0) {
        throw new RuntimeException("Error creating program.");
    }

    return programHandle;
}

From source file:Main.java

/**
 * Creates a new program from the supplied vertex and fragment shaders.
 *
 * @return A handle to the program, or 0 on failure.
 *//*  ww  w  . ja v  a2  s.  c  om*/
public static int createProgram(String vertexSource, String fragmentSource) {
    int vertexShader = loadShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    if (vertexShader == 0) {
        return 0;
    }
    int pixelShader = loadShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    if (pixelShader == 0) {
        return 0;
    }

    int program = GLES20.glCreateProgram();
    checkGlError("glCreateProgram");
    if (program == 0) {
        Log.e(TAG, "Could not create program");
    }
    GLES20.glAttachShader(program, vertexShader);
    checkGlError("glAttachShader");
    GLES20.glAttachShader(program, pixelShader);
    checkGlError("glAttachShader");
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[1];
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    return program;
}