Example usage for org.lwjgl.opengl GL20 glGetUniformLocation

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

Introduction

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

Prototype

@NativeType("GLint")
public static int glGetUniformLocation(@NativeType("GLuint") int program,
        @NativeType("GLchar const *") CharSequence name) 

Source Link

Document

Returns the location of a uniform variable.

Usage

From source file:com.opengrave.og.Util.java

License:Open Source License

public static void setUniformMat44(int pID, String string, FloatBuffer matrix44) {
    // System.out.println("Program "+pID);
    Util.checkErr();//from ww  w  .j a v  a 2s  . co m
    int i = GL20.glGetUniformLocation(pID, string);
    Util.checkErr();
    if (i == -1) {
        // System.out.println("Cannot find uniform '"+string+"'");
        // Thread.dumpStack();
    } else {
        GL20.glUniformMatrix4fv(i, false, matrix44);
        Util.checkErr();
    }
}

From source file:com.opengrave.og.Util.java

License:Open Source License

public static void setUniformMat33(int pID, String string, FloatBuffer matrix33) {
    // System.out.println("Program "+pID);
    Util.checkErr();/*from ww  w  .  j  a  va 2 s.  c  o  m*/
    int i = GL20.glGetUniformLocation(pID, string);
    Util.checkErr();
    if (i == -1) {
        // System.out.println("Cannot find uniform '"+string+"'");
        // Thread.dumpStack();
    } else {
        GL20.glUniformMatrix3fv(i, false, matrix33);
        Util.checkErr();
    }
}

From source file:com.opengrave.og.Util.java

License:Open Source License

public static void setUniform(int pID, String string, Vector4f color) {
    // System.out.println("Program "+pID);
    Util.checkErr();//from  w  w  w.ja  va  2 s  .c  o m
    int i = GL20.glGetUniformLocation(pID, string);
    Util.checkErr();
    if (i == -1) {
        // System.out.println("Cannot find uniform '"+string+"'");
        // Thread.dumpStack();
    } else {
        GL20.glUniform4f(i, color.x, color.y, color.z, color.w);
        Util.checkErr();
    }
}

From source file:com.opengrave.og.Util.java

License:Open Source License

public static void loadMaterials(MaterialList matList, int pID) {
    int i = 0;//  w w w  . j ava  2s . c o  m
    for (Material m : matList.all()) {
        int locCol1 = GL20.glGetUniformLocation(pID, "material[" + i + "].colour");
        int locTex = GL20.glGetUniformLocation(pID, "material[" + i + "].textureindex");
        int locDTex = GL20.glGetUniformLocation(pID, "material[" + i + "].texturedataindex");

        /*
         * if (locCol == -1) { throw new
         * RuntimeException("No Material Colour location"); } if (locTex ==
         * -1) { throw new RuntimeException("No Material Texture location");
         * }
         */
        GL20.glUniform4f(locCol1, m.getColour().x, m.getColour().y, m.getColour().z, m.getColour().w);
        GL20.glUniform1f(locTex, (float) m.getTextureIndex());
        GL20.glUniform1f(locDTex, (float) m.getTextureDataIndex());

        i++;
    }
}

From source file:com.opengrave.og.Util.java

License:Open Source License

public static void setRenderStyle(int pID, RenderStyle style) {
    int i = 0;//from   w w w .  j a  v a  2s.co  m
    if (style == RenderStyle.GRAYSCALE) {
        i = 1;
    } else if (style == RenderStyle.SEPIA) {
        i = 2;
    } else if (style == RenderStyle.HALO) {
        i = 3;
    }
    GL20.glUniform1i(GL20.glGetUniformLocation(pID, "renderStyle"), i);

}

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

License:Apache License

protected int getUniformLocation(String name) {
    if (name.equals("yes"))
        System.out.println(GL20.glGetUniformLocation(programID, name));
    return GL20.glGetUniformLocation(programID, name);
}

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

License:Open Source License

/**
 * Returns the location of the uniform with the given name, or -1 if none
 * with the given name exists./*from  w  w  w .jav  a 2s  .  c  om*/
 * 
 * @param name The name of the uniform to find.
 * @return The location of a uniform.
 */
public int getUniformLocation(String name) {
    if (DGL.currentProgram() != this)
        throw new IllegalStateException("Program must be in use.");
    return GL20.glGetUniformLocation(id, name);
}

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

License:Open Source License

/**
 * Specifies the value of a uniform variable for this program. Program must
 * be in use. Returns true if and only if the uniform exists and is active.
 * //w  w  w .  j  ava 2  s.  co  m
 * @param name The name of the uniform to specify.
 * @param x The value to set the uniform to.
 * @return Whether or not the uniform exists and is active.
 */
public boolean uniform1i(String name, int x) {
    if (DGL.currentProgram() != this)
        throw new IllegalStateException("Program must be in use.");
    int loc = GL20.glGetUniformLocation(id, name);
    if (loc < 0)
        return false;
    GL20.glUniform1i(loc, x);
    return true;
}

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

License:Open Source License

/**
 * Specifies the values of a uniform variable array for this program. Must
 * be in use. Returns true if and only if the uniform exists and is active.
 * /*  w  w  w  . j  a va 2  s  . c o  m*/
 * @param name The name of the uniform array to specify.
 * @param array An array of values to set the uniform to.
 * @return Whether or not the uniform exists and is active.
 */
public boolean uniform1iv(String name, int... array) {
    if (DGL.currentProgram() != this)
        throw new IllegalStateException("Program must be in use.");
    int loc = GL20.glGetUniformLocation(id, name);
    if (loc < 0)
        return false;

    long address = MemStack.wrapi(array);
    GL20.nglUniform1iv(loc, array.length, address);
    MemStack.pop();
    return true;
}

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

License:Open Source License

/**
 * Specifies the value of a uniform variable for this program. Program must
 * be in use. Returns true if and only if the uniform exists and is active.
 * /* w ww . jav  a2  s .  c o m*/
 * @param name The name of the uniform to specify.
 * @param x The value to set the uniform to.
 * @return Whether or not the uniform exists and is active.
 */
public boolean uniform1f(String name, float x) {
    if (DGL.currentProgram() != this)
        throw new IllegalStateException("Program must be in use.");
    int loc = GL20.glGetUniformLocation(id, name);
    if (loc < 0)
        return false;
    GL20.glUniform1f(loc, x);
    return true;
}