Example usage for com.badlogic.gdx.graphics GL20 glAttachShader

List of usage examples for com.badlogic.gdx.graphics GL20 glAttachShader

Introduction

In this page you can find the example usage for com.badlogic.gdx.graphics GL20 glAttachShader.

Prototype

public void glAttachShader(int program, int shader);

Source Link

Usage

From source file:net.mgsx.game.examples.gpu.utils.ShaderProgramEx.java

License:Apache License

private int linkProgram(int program) {
    GL20 gl = Gdx.gl20;
    if (program == -1)
        return -1;

    gl.glAttachShader(program, vertexShaderHandle);
    gl.glAttachShader(program, fragmentShaderHandle);
    if (geometryShaderHandle >= 0)
        gl.glAttachShader(program, geometryShaderHandle);
    if (tcsHandle >= 0)
        gl.glAttachShader(program, tcsHandle);
    if (tesHandle >= 0)
        gl.glAttachShader(program, tesHandle);

    gl.glLinkProgram(program);//from   www . ja  v  a2 s .c  o  m

    ByteBuffer tmp = ByteBuffer.allocateDirect(4);
    tmp.order(ByteOrder.nativeOrder());
    IntBuffer intbuf = tmp.asIntBuffer();

    gl.glGetProgramiv(program, GL20.GL_LINK_STATUS, intbuf);
    int linked = intbuf.get(0);
    if (linked == 0) {
        // Gdx.gl20.glGetProgramiv(program, GL20.GL_INFO_LOG_LENGTH, intbuf);
        // int infoLogLength = intbuf.get(0);
        // if (infoLogLength > 1) {
        log = Gdx.gl20.glGetProgramInfoLog(program);
        // }
        return -1;
    }

    return program;
}