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

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

Introduction

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

Prototype

public void glLinkProgram(int program);

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);

    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);
        // }//from   w ww  .ja  v  a 2s.  c  o m
        return -1;
    }

    return program;
}