Example usage for org.lwjgl.opengl GL20 glGetShaderi

List of usage examples for org.lwjgl.opengl GL20 glGetShaderi

Introduction

In this page you can find the example usage for org.lwjgl.opengl GL20 glGetShaderi.

Prototype

@NativeType("void")
public static int glGetShaderi(@NativeType("GLuint") int shader, @NativeType("GLenum") int pname) 

Source Link

Document

Returns a parameter from a shader object.

Usage

From source file:com.opengrave.og.resources.ShaderProgram.java

License:Open Source License

public static int loadShader(String source, int type) {
    Util.checkErr();/*from w  ww  . j  a  v a 2s  . co  m*/
    int i = GL20.glCreateShader(type);
    Util.checkErr();
    GL20.glShaderSource(i, source);
    Util.checkErr();
    GL20.glCompileShader(i);
    Util.checkErr();
    if (GL20.glGetShaderi(i, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        new DebugExceptionHandler(new Exception(), annotate(source), GL20.glGetShaderInfoLog(i, 2000));
    }
    Util.checkErr();
    return i;
}

From source file:com.redthirddivision.quad.rendering.shaders.Shader.java

License:Apache License

private int loadShader(String file, int type) {
    System.out.println("Loading shader <" + file + ">");
    StringBuilder source = new StringBuilder();
    BufferedReader reader = null;
    try {//from w ww. j  a va 2  s  .  co  m
        reader = new BufferedReader(new FileReader(file));
        String line = null;
        while ((line = reader.readLine()) != null)
            source.append(line).append("\n");
    } catch (IOException e) {
        e.printStackTrace();
        System.err.println("Error: Could not read shader file: " + file);
        System.exit(1);
    } finally {
        if (reader != null)
            try {
                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
    }

    int shaderID = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderID, source);
    GL20.glCompileShader(shaderID);
    if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.err.println("Error: Could not comple shader");
        System.err.println(GL20.glGetShaderInfoLog(shaderID, 500));
        System.exit(1);
    }

    return shaderID;
}

From source file:com.samrj.devil.gl.Shader.java

/**
 * Loads shader sources from the given input stream and then compiles this
 * shader. Buffers the source in native memory.
 * // w w  w .java  2 s  .  c  o  m
 * @param in The input stream to load sources from.
 * @return This shader.
 * @throws IOException If an I/O error occurs.
 */
public Shader source(InputStream in) throws IOException {
    if (state != State.NEW)
        throw new IllegalStateException("Shader must be new.");

    //Source to memory
    int sourceLength = in.available();
    Memory sourceBlock = new Memory(sourceLength);
    ByteBuffer sourceBuffer = sourceBlock.buffer;
    for (int i = 0; i < sourceLength; i++)
        sourceBuffer.put((byte) in.read());

    //Pointer to pointer to memory
    long pointer = MemStack.wrapl(sourceBlock.address);

    //Pointer to length of memory
    long length = MemStack.wrapi(sourceLength);

    //Load shader source
    GL20.nglShaderSource(id, 1, pointer, length);

    //Free allocated memory
    MemStack.pop(2);
    sourceBlock.free();

    //Compile
    GL20.glCompileShader(id);

    //Check for errors
    if (GL20.glGetShaderi(id, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        int logLength = GL20.glGetShaderi(id, GL20.GL_INFO_LOG_LENGTH);
        String log = GL20.glGetShaderInfoLog(id, logLength);
        throw new ShaderException(path != null ? path + " " + log : log);
    }

    state = State.COMPILED;
    return this;
}

From source file:com.timvisee.voxeltex.module.shader.raw.RawShader.java

License:Open Source License

@Override
public int compile() {
    // Show a status message
    System.out.print("Compiling shader... ");

    // Create a new OpenGL shader program
    int program = GL20.glCreateProgram();

    // Shader IDs
    int vertexId = 0;
    int fragmentId = 0;

    // Compile the vertex shader if available
    if (hasVertexShader()) {
        // Create the vertex shader
        vertexId = GL20.glCreateShader(GL20.GL_VERTEX_SHADER);

        // Attach the vertex shader source and compile it
        GL20.glShaderSource(vertexId, vertexSource);
        GL20.glCompileShader(vertexId);//from   ww  w  . j a va  2 s.c o m

        // Check for compiling errors
        if (GL20.glGetShaderi(vertexId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
            // Show an error message
            System.out.println("FAIL\nFailed to compile the vertex shader");
            System.out.println(GL20.glGetShaderInfoLog(vertexId));

            // Delete the shader before returning
            GL20.glDeleteShader(vertexId);
            throw new RuntimeException("Failed to compile the vertex shader");
        }
    }

    // Compile the fragment shader if available
    if (hasFragmentShader()) {
        // Create the fragment shader
        fragmentId = GL20.glCreateShader(GL20.GL_FRAGMENT_SHADER);

        // Attach the fragment shader source and compile it
        GL20.glShaderSource(fragmentId, fragmentSource);
        GL20.glCompileShader(fragmentId);

        // Check for compiling errors
        if (GL20.glGetShaderi(fragmentId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
            // Show an error message
            System.out.println("FAIL\nFailed to compile the fragment shader");
            System.out.println(GL20.glGetShaderInfoLog(fragmentId));

            // Delete the shader before returning
            GL20.glDeleteShader(fragmentId);
            throw new RuntimeException("Failed to compile the vertex shader");
        }
    }

    // Attach all compiled shaders
    if (hasVertexShader())
        GL20.glAttachShader(program, vertexId);
    if (hasFragmentShader())
        GL20.glAttachShader(program, fragmentId);

    // Link the shader program to OpenGL and link it
    GL20.glLinkProgram(program);
    GL20.glValidateProgram(program);

    // Shaders have been attached to the program, delete their compiled sources to save memory
    if (hasVertexShader())
        GL20.glDeleteShader(vertexId);
    if (hasFragmentShader())
        GL20.glDeleteShader(fragmentId);

    // Show a status message
    System.out.println("OK");

    // Return the created OpenGL shader program
    return program;
}

From source file:com.voxelplugineering.voxelsniper.util.GLSLUtilities.java

License:Open Source License

public static int loadShader(String filename, int type) {
    StringBuilder shaderSource = new StringBuilder();
    int shaderID = 0;

    try {//from  w  ww.  ja  v a2  s  . c om
        BufferedReader reader = new BufferedReader(new FileReader(filename));
        String line;
        while ((line = reader.readLine()) != null) {
            shaderSource.append(line).append("\n");
        }
        reader.close();
    } catch (IOException e) {
        System.err.println("Could not read file.");
        e.printStackTrace();
        System.exit(-1);
    }

    shaderID = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderID, shaderSource);
    GL20.glCompileShader(shaderID);

    if (GL20.glGetShaderi(shaderID, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.err.println("Could not compile shader.");
        System.err.println(GL20.glGetShaderInfoLog(shaderID, 1024));
        System.exit(-1);
    }

    OpenGLUtilities.checkGLError("loadShader");

    return shaderID;
}

From source file:com.wicpar.sinkingsimulatorclassic.graphics.Shader.java

License:Open Source License

public Shader compile() {
    if (ID == null) {
        delete();//from  www  .ja  va  2  s. com
        ID = GL20.glCreateShader(type);
    }
    GL20.glShaderSource(ID, source);
    GL20.glCompileShader(ID);
    if (GL20.glGetShaderi(ID, GL20.GL_COMPILE_STATUS) != GL11.GL_TRUE) {
        logger.error("failed to compile shader: \n" + GL20.glGetShaderInfoLog(ID));
    }
    return this;
}

From source file:com.xrbpowered.gl.res.shaders.Shader.java

License:Open Source License

public static int loadShader(String path, int type) {
    if (path == null)
        return 0;
    int shaderId = 0;
    String shaderSource;//w  w  w  .j av  a 2  s  .com
    try {
        shaderSource = AssetManager.defaultAssets.loadString(path);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    shaderId = GL20.glCreateShader(type);
    GL20.glShaderSource(shaderId, shaderSource);
    GL20.glCompileShader(shaderId);

    if (GL20.glGetShaderi(shaderId, GL20.GL_COMPILE_STATUS) == GL11.GL_FALSE) {
        System.err.println("Could not compile shader " + path);
        System.err.println(GL20.glGetShaderInfoLog(shaderId, 8000));
        System.exit(-1); // FIXME handle this exception!!
    }

    return shaderId;
}

From source file:cuchaz.jfxgl.prism.JFXGLContext.java

License:Open Source License

@Override
public int compileShader(String source, boolean isVertex) {

    int type;/*from w  w  w  .jav a 2 s.co m*/
    if (isVertex) {
        type = GL20.GL_VERTEX_SHADER;
    } else {
        type = GL20.GL_FRAGMENT_SHADER;
    }

    int id = GL20.glCreateShader(type);
    GL20.glShaderSource(id, source);
    GL20.glCompileShader(id);

    boolean isSuccess = GL20.glGetShaderi(id, GL20.GL_COMPILE_STATUS) != GL11.GL_FALSE;
    if (!isSuccess) {

        // get debug info
        StringBuilder buf = new StringBuilder();
        buf.append("Shader did not compile\n");

        // show the compiler log
        buf.append("\nCOMPILER LOG:\n");
        buf.append(GL20.glGetShaderInfoLog(id, 4096));

        // show the source with correct line numbering
        buf.append("\nSOURCE:\n");
        String[] lines = source.split("\\n");
        for (int i = 0; i < lines.length; i++) {
            buf.append(String.format("%4d: ", i + 1));
            buf.append(lines[i]);
            buf.append("\n");
        }

        throw new RuntimeException(buf.toString());
    }

    return id;
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLHardcodedShader.java

License:Open Source License

private static void validateCompilation(int shaderId) {
    int compileStatus = GL20.glGetShaderi(shaderId, GL20.GL_COMPILE_STATUS);
    int error = GL11.glGetError();

    if (error != GL11.GL_NO_ERROR) {
        ML.f(String.format("Error getting compilation status: 0x%x", error));
    } else if (compileStatus == GL11.GL_FALSE) {
        int logLength = GL20.glGetShaderi(shaderId, GL20.GL_INFO_LOG_LENGTH);
        String log = GL20.glGetShaderInfoLog(shaderId, logLength);
        ML.f(String.format("Error compiling shader: %s", log));
    }//from  w w  w  .  java 2s.c o m
}

From source file:de.ikosa.mars.viewer.glviewer.engine.GLShaderBuilder.java

License:Open Source License

private void validateCompilation(int shaderId) {
    int compileStatus = GL20.glGetShaderi(shaderId, GL20.GL_COMPILE_STATUS);
    int error = GL11.glGetError();

    if (error != GL11.GL_NO_ERROR) {
        ML.f(String.format("Error getting compilation status: 0x%x", error));
    } else if (compileStatus == GL11.GL_FALSE) {
        int logLength = GL20.glGetShaderi(shaderId, GL20.GL_INFO_LOG_LENGTH);
        String log = GL20.glGetShaderInfoLog(shaderId, logLength);
        ML.f(String.format("Error compiling shader: %s", log));
    }/*from  w w w  .  ja  v  a  2 s.co m*/
}