Example usage for org.lwjgl.opengl GL20 glGetProgrami

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

Introduction

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

Prototype

@NativeType("void")
public static int glGetProgrami(@NativeType("GLuint") int program, @NativeType("GLenum") int pname) 

Source Link

Document

Returns a parameter from a program object.

Usage

From source file:ar.com.quark.backend.lwjgl.opengl.DesktopGLES20.java

License:Apache License

/**
 * {@inheritDoc}//from  w w  w .j  a  v a 2 s .c o  m
 */
@Override
public int glGetProgram(int name, int property) {
    return GL20.glGetProgrami(name, property);
}

From source file:com.flowpowered.caustic.lwjgl.gl20.GL20Program.java

License:MIT License

@Override
public void link() {
    checkCreated();/*from   w  ww  .  j ava2  s  .  c o m*/
    // Add the attribute layouts to the program state
    final TObjectIntIterator<String> iterator = attributeLayouts.iterator();
    while (iterator.hasNext()) {
        iterator.advance();
        // Bind the index to the name
        GL20.glBindAttribLocation(id, iterator.value(), iterator.key());
    }
    // Link program
    GL20.glLinkProgram(id);
    // Check program link status
    if (GL20.glGetProgrami(id, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
        throw new IllegalStateException("Program could not be linked\n" + GL20.glGetProgramInfoLog(id, 1000));
    }
    if (CausticUtil.isDebugEnabled()) {
        // Validate program
        GL20.glValidateProgram(id);
        // Check program validation status
        if (GL20.glGetProgrami(id, GL20.GL_VALIDATE_STATUS) == GL11.GL_FALSE) {
            final Logger logger = CausticUtil.getCausticLogger();
            logger.log(Level.WARNING,
                    "Program validation failed. This doesn''t mean it won''t work, so you maybe able to ignore it\n{0}",
                    GL20.glGetProgramInfoLog(id, 1000));
        }
    }
    // Load uniforms
    uniforms.clear();
    final int uniformCount = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORMS);
    final int maxLength = GL20.glGetProgrami(id, GL20.GL_ACTIVE_UNIFORM_MAX_LENGTH);
    final IntBuffer lengthBuffer = CausticUtil.createIntBuffer(1);
    final IntBuffer ignored1 = CausticUtil.createIntBuffer(1);
    final IntBuffer ignored2 = CausticUtil.createIntBuffer(1);
    final ByteBuffer nameBuffer = CausticUtil.createByteBuffer(maxLength);
    final byte[] nameBytes = new byte[maxLength];
    for (int i = 0; i < uniformCount; i++) {
        lengthBuffer.clear();
        ignored1.clear();
        ignored2.clear();
        nameBuffer.clear();
        GL20.glGetActiveUniform(id, i, lengthBuffer, ignored1, ignored2, nameBuffer);
        final int length = lengthBuffer.get();
        nameBuffer.get(nameBytes, 0, length);
        // Simplify array names
        final String name = new String(nameBytes, 0, length).replaceFirst("\\[\\d+\\]", "");
        uniforms.put(name, GL20.glGetUniformLocation(id, name));
        uniformValues.put(name, UNSET);
    }
    // Check for errors
    LWJGLUtil.checkForGLError();
}

From source file:com.github.ryancwilliams.WJ3dPL.graphics.GLUtils.ShaderProgram.java

License:Apache License

/**
 * Creates a new shader program with the provided vertex and fragment 
 * shader source code.//  w  w  w .  j  a  v a2  s .c  o m
 * The provided attributes are linked to this program.
 * @param vertexShaderSource the source code of the vertex shader.
 * @param fragmentShaderSource the source code of the fragment shader.
 * @param attributes The Vertex Attributes to bind to this shader program.
 * @throws LWJGLException If their is a issue compiling the shaders or 
 * creating or binding the program.  
 */
public ShaderProgram(String vertexShaderSource, String fragmentShaderSource, List<VertexAttribute> attributes)
        throws LWJGLException {
    //Check if any of the sourcecode paramaters are null
    if (fragmentShaderSource == null || fragmentShaderSource == null) {
        //If any of the sourcecode paramaters were null
        //throw a exception
        throw new IllegalArgumentException("Shader source may not be null");
    }
    //Check if shaders are not supported
    if (!ShaderProgram.isSupported()) {
        //If shaders are not supported
        //throw a exception
        throw new LWJGLException("Shaders are not supported on this device");
    }

    //Compile the shaders
    int vertexShader = ShaderProgram.compileShader(GL20.GL_VERTEX_SHADER, vertexShaderSource);
    int fragmentShader = ShaderProgram.compileShader(GL20.GL_FRAGMENT_SHADER, fragmentShaderSource);

    //Create the program
    this.program = GL20.glCreateProgram();

    //Bind the attrib locations
    //Check if attributes were provided
    if (attributes != null) {
        //For each attribute
        for (VertexAttribute attribute : attributes) {
            //Check if the attribute is not null
            if (attribute != null) {
                //bind the attribute
                GL20.glBindAttribLocation(this.program, attribute.index, attribute.name);
            }
        }
    }

    //Attach the shaders
    GL20.glAttachShader(this.program, vertexShader);
    GL20.glAttachShader(this.program, fragmentShader);

    //Link the program
    GL20.glLinkProgram(this.program);

    //Get if the program link was good
    boolean programLink = GL20.glGetProgrami(this.program, GL20.GL_LINK_STATUS) == GL11.GL_TRUE;

    //Get the log
    String infoLog = GL20.glGetProgramInfoLog(this.program,
            GL20.glGetProgrami(this.program, GL20.GL_INFO_LOG_LENGTH));

    //Log the log if a log is present
    if (infoLog != null && infoLog.trim().length() != 0) {
        Logger.getLogger(ShaderProgram.class.getName()).log(Level.FINEST, infoLog);
    }

    //Check if program link is bad
    if (programLink == false) {
        throw new LWJGLException("Failure in linking program. Error log:\n" + infoLog);
    }

    //detach and delete the shaders which are no longer needed
    GL20.glDetachShader(this.program, vertexShader);
    GL20.glDetachShader(this.program, fragmentShader);
    GL20.glDeleteShader(vertexShader);
    GL20.glDeleteShader(fragmentShader);
}

From source file:com.google.gapid.glviewer.gl.Shader.java

License:Apache License

private boolean link() {
    GL20.glLinkProgram(handle);/* w ww .  j  a v a2s  .c  om*/
    if (GL20.glGetProgrami(handle, GL20.GL_LINK_STATUS) != GL11.GL_TRUE) {
        LOG.log(WARNING, "Failed to link program:\n" + GL20.glGetProgramInfoLog(handle));
        return false;
    }
    return true;
}

From source file:com.google.gapid.glviewer.gl.Shader.java

License:Apache License

private static int[] getAttachedShaders(int program) {
    int numShaders = GL20.glGetProgrami(program, GL20.GL_ATTACHED_SHADERS);
    if (numShaders > 0) {
        int[] shaders = new int[numShaders], count = new int[1];
        GL20.glGetAttachedShaders(program, count, shaders);
        return shaders;
    }/*from  ww  w  .ja  v  a  2  s  .co  m*/
    return new int[0];
}

From source file:com.google.gapid.glviewer.gl.Shader.java

License:Apache License

private static Attribute[] getActiveAttributes(int program) {
    int maxAttribNameLength = GL20.glGetProgrami(program, GL20.GL_ACTIVE_ATTRIBUTE_MAX_LENGTH);
    int numAttributes = GL20.glGetProgrami(program, GL20.GL_ACTIVE_ATTRIBUTES);
    IntBuffer size = createIntBuffer(1), type = createIntBuffer(1);

    Attribute[] result = new Attribute[numAttributes];
    for (int i = 0; i < numAttributes; i++) {
        String name = GL20.glGetActiveAttrib(program, i, maxAttribNameLength, size, type);
        result[i] = new Attribute(GL20.glGetAttribLocation(program, name), name, type.get(0));
    }/*  w  w  w  .j  a  v  a 2s.c  o m*/
    return result;
}

From source file:com.google.gapid.glviewer.gl.Shader.java

License:Apache License

private static Uniform[] getActiveUniforms(int program) {
    int maxUniformNameLength = GL20.glGetProgrami(program, GL20.GL_ACTIVE_UNIFORM_MAX_LENGTH);
    int numUniforms = GL20.glGetProgrami(program, GL20.GL_ACTIVE_UNIFORMS);
    IntBuffer size = createIntBuffer(1), type = createIntBuffer(1);

    Uniform[] result = new Uniform[numUniforms];
    for (int i = 0; i < numUniforms; i++) {
        String name = GL20.glGetActiveUniform(program, i, maxUniformNameLength, size, type);
        if (name.endsWith("[0]")) {
            name = name.substring(0, name.length() - 3);
        }/*from  w w  w.j  ava  2 s .com*/
        result[i] = new Uniform(GL20.glGetUniformLocation(program, name), name, type.get(0));
    }
    return result;
}

From source file:com.google.gapid.glviewer.gl.Util.java

License:Apache License

public static int getProgramiv(int program, int name) {
    return GL20.glGetProgrami(program, name);
}

From source file:com.kauridev.lunarfever.graphics.ShaderProgram.java

License:Open Source License

private void linkProgram(List<VertexAttribute> attribLocations) {
    if (!isValid()) {
        throw new RuntimeException();
    }/*from   w w  w .  j  a va 2s  . c om*/

    if (attribLocations != null) {
        for (VertexAttribute a : attribLocations) {
            if (a != null) {
                GL20.glBindAttribLocation(program, a.location, a.name);
            }
        }
    }

    attachShaders();
    GL20.glLinkProgram(program);
    int comp = GL20.glGetProgrami(program, GL20.GL_LINK_STATUS);
    int len = GL20.glGetProgrami(program, GL20.GL_INFO_LOG_LENGTH);

    if (comp == GL11.GL_FALSE) {
        throw new RuntimeException(GL20.glGetProgramInfoLog(program, len));
    }
}

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

License:Open Source License

public void compile() {
    Util.checkErr();/*  w w  w . j  a  v  a  2s. c om*/

    PID = GL20.glCreateProgram();
    Util.checkErr();

    vert = loadShader(sfv.getSource(), GL20.GL_VERTEX_SHADER);
    Util.checkErr();

    frag = loadShader(sff.getSource(), GL20.GL_FRAGMENT_SHADER);
    Util.checkErr();

    GL20.glAttachShader(PID, vert);
    Util.checkErr();

    GL20.glAttachShader(PID, frag);
    Util.checkErr();

    GL20.glLinkProgram(PID);
    Util.checkErr();

    System.out.println(GL20.glGetProgramInfoLog(PID, 2000));
    Util.checkErr();

    GL20.glValidateProgram(PID);
    Util.checkErr();

    // System.out.println("Compiled " + label + " as number " + PID);
    if (GL20.glGetProgrami(PID, GL20.GL_LINK_STATUS) == GL11.GL_FALSE) {
        new DebugExceptionHandler(new Exception(), label, GL20.glGetShaderInfoLog(PID, 2000),
                GL20.glGetProgramInfoLog(PID, 2000));
        // System.out.println("Failed to link " + label);
        // System.out.println(sfv.getSource());
        // System.out.println(sff.getSource());

        // Util.checkErr();

        // printShaderLogs();
    }
    Util.checkErr();

    GL20.glDetachShader(PID, vert);
    Util.checkErr();

    GL20.glDetachShader(PID, frag);
    GL20.glDeleteShader(vert);
    Util.checkErr();

    GL20.glDeleteShader(frag);
    Util.checkErr();
}