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

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

Introduction

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

Prototype

public void glShaderSource(int shader, String string);

Source Link

Usage

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

License:Apache License

private int loadShader(int type, String source) {
    GL20 gl = Gdx.gl20;
    IntBuffer intbuf = BufferUtils.newIntBuffer(1);

    int shader = gl.glCreateShader(type);
    if (shader == 0)
        return -1;

    gl.glShaderSource(shader, source);
    gl.glCompileShader(shader);/*from  w w w. jav  a 2  s.  c  o  m*/
    gl.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, intbuf);

    int compiled = intbuf.get(0);
    if (compiled == 0) {
        // gl.glGetShaderiv(shader, GL20.GL_INFO_LOG_LENGTH, intbuf);
        // int infoLogLength = intbuf.get(0);
        // if (infoLogLength > 1) {
        String infoLog = gl.glGetShaderInfoLog(shader);

        IntMap<String> typeString = new IntMap<String>();
        typeString.put(GL20.GL_VERTEX_SHADER, "Vertex shader");
        typeString.put(GL20.GL_FRAGMENT_SHADER, "Vertex shader");
        typeString.put(GL_GEOMETRY_SHADER, "Geometry shader");
        typeString.put(GL_TESS_CONTROL_SHADER, "Tess control shader");
        typeString.put(GL_TESS_EVALUATION_SHADER, "Tess evaluation shader");

        log += typeString.get(type) + "\n";
        log += infoLog;
        // }
        return -1;
    }

    return shader;
}