Example usage for org.lwjgl.opengl GL20 glUniform1f

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

Introduction

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

Prototype

public static void glUniform1f(@NativeType("GLint") int location, @NativeType("GLfloat") float v0) 

Source Link

Document

Specifies the value of a float uniform variable for the current program object.

Usage

From source file:fr.ign.cogit.geoxygene.util.gl.GLProgram.java

License:Open Source License

/**
 * @param value/*from ww  w  .ja va2  s.  c  o  m*/
 * @param uniformLocation
 */
private void setUniform1f(int uniformLocation, float value) {
    GL20.glUniform1f(uniformLocation, value);
}

From source file:io.root.gfx.glutils.GL.java

License:Apache License

public static void glUniform1f(int location, float x) {
    GL20.glUniform1f(location, x);
}

From source file:jpcsp.graphics.RE.RenderingEngineLwjgl.java

License:Open Source License

@Override
public void setUniform(int id, float value) {
    GL20.glUniform1f(id, value);
}

From source file:kubex.gui.FinalDrawManager.java

License:Creative Commons License

/**
 * Uploads to the deferred shader the uniforms it needs. For it, consults the shader capabilities.
 *//*  www  . ja  va  2 s  .co  m*/
protected void uploadToShader(DeferredShaderProgram DSP, Matrix4f viewMatrix, Matrix4f projectionMatrix,
        float xres, float yres) {
    //Those uniforms are universal for all deferred shaders, they will be uploaded for each one of them
    MatrixHelper.uploadMatrix(viewMatrix, glGetUniformLocation(DSP.getID(), "viewMatrix"));
    MatrixHelper.uploadMatrix(projectionMatrix, glGetUniformLocation(DSP.getID(), "projectionMatrix"));
    glUniform1i(glGetUniformLocation(DSP.getID(), "colorTex"), DSP.colorTexLocation()); //The color texture of the shader can vary
    glUniform1i(glGetUniformLocation(DSP.getID(), "liquidLayersTex"), KubexGame.LIQUIDLAYERS_TEXTURE_LOCATION);
    glUniform1i(glGetUniformLocation(DSP.getID(), "baseFboDepthTex"), KubexGame.BASEFBO_DEPTH_TEXTURE_LOCATION);
    glUniform1i(glGetUniformLocation(DSP.getID(), "brightnessNormalTex"),
            KubexGame.BASEFBO_NORMALS_BRIGHTNESS_TEXTURE_LOCATION);
    glUniform1i(glGetUniformLocation(DSP.getID(), "liquidLayersTexLength"), this.liquidRenderer.getNumLayers());
    if (DSP.miscTexLocation() != -1)
        glUniform1i(glGetUniformLocation(DSP.getID(), "miscTex"), DSP.miscTexLocation()); //Deferred shaders support up to 2 "misc" textures, if requested.
    if (DSP.miscTex2Location() != -1)
        glUniform1i(glGetUniformLocation(DSP.getID(), "miscTex2"), DSP.miscTex2Location()); //they are called misc to generalize them and upload them in different shaders
    //with different purposes each.
    glUniform1f(glGetUniformLocation(DSP.getID(), "cfar"), cfar);
    glUniform1f(glGetUniformLocation(DSP.getID(), "cnear"), cnear);
    glUniform1f(glGetUniformLocation(DSP.getID(), "cwidth"), xres);
    glUniform1f(glGetUniformLocation(DSP.getID(), "cheight"), yres);

    glUniform1f(glGetUniformLocation(DSP.getID(), "time"),
            (float) (System.currentTimeMillis() % 1000000) / 1000); //Uploads current time to the shaders, for them to do things like water flow.
    //The value can't grow forever as the float precission is moderate, so it will be truncated
    //to 1.000 sec maximum, moment in which the time will reset to 0 and the flow in the scene will blink
    //it will not be very noticeable and it will happen once each 20 min.
    //with one 0 more it will hapen once each 3 hours, but im scared of the float precision errors.

    GL20.glUniform1f(glGetUniformLocation(DSP.getID(), "daylightAmount"), this.world.getDaylightAmount());
    Vector3f sunNormal = this.sky.getSunNormal();
    GL20.glUniform3f(glGetUniformLocation(DSP.getID(), "sunNormal"), sunNormal.x, sunNormal.y, sunNormal.z);

    if (DSP.supportWorldPosition()) //If the shader needs to know the world position of the camera, upload it truncating it to a 500 val max, to avoid floating precision errors.
    {
        GL20.glUniform3f(glGetUniformLocation(DSP.getID(), "WorldPosition"),
                (float) (this.world.getCameraCenter().x % 500), (float) (this.world.getCameraCenter().y % 500),
                (float) (this.world.getCameraCenter().z % 500));
    }

    //if shadows supported, upload the needed uniforms
    if (DSP.supportShadows()) {
        GL20.glUniform1i(glGetUniformLocation(DSP.getID(), "shadowMap"), KubexGame.SHADOW_TEXTURE_LOCATION);

        float[] dsplits = this.shadowsManager.getSplitDistances();
        int splitDistances = glGetUniformLocation(DSP.getID(), "splitDistances");
        switch (this.shadowsManager.getNumberSplits()) {
        case 1:
            GL20.glUniform4f(splitDistances, dsplits[1], 0, 0, 0);
            break;
        case 2:
            GL20.glUniform4f(splitDistances, dsplits[1], dsplits[2], 0, 0);
            break;
        case 3:
            GL20.glUniform4f(splitDistances, dsplits[1], dsplits[2], dsplits[3], 0);
            break;
        case 4:
            GL20.glUniform4f(splitDistances, dsplits[1], dsplits[2], dsplits[3], dsplits[4]);
            break;
        }

        int shadowMatrixes = glGetUniformLocation(DSP.getID(), "shadowMatrixes");
        for (int i = 0; i < this.shadowsManager.getNumberSplits(); i++) {
            MatrixHelper.uploadMatrix(this.shadowsManager.getOrthoProjectionForSplitScreenAdjusted(i),
                    shadowMatrixes + (i));
        }
    }

    if (DSP.supportSkyParameters()) //if sky supported, upload all sky parameters
    {
        this.sky.uploadToShader(DSP);
    }
    if (DSP.supportPlayerLighting()) //If player lighting supported, upload players average lighting surrounding him.
    {
        int currentLightLoc = glGetUniformLocation(DSP.getID(), "currentLight");
        GL20.glUniform1f(currentLightLoc, this.world.getAverageLightExposed());
    }
}

From source file:lessur.util.shader.ShaderManager.java

License:GNU General Public License

/**
 * /*from  ww  w  .  j  av  a2s. c  om*/
 * @param program ID/index of the program
 * @param name Name of the variable
 * @param value Value to set the variable
 */
public void setUniform1(int program, String name, float value) {
    if (has_opengl2) {
        int loc = GL20.glGetUniformLocation(program, name);
        checkVariableLocation(loc, name);
        GL20.glUniform1f(loc, value);
    } else if (has_arb) {
        int loc = ARBShaderObjects.glGetUniformLocationARB(program, name);
        checkVariableLocation(loc, name);
        ARBShaderObjects.glUniform1fARB(loc, value);
    }
}

From source file:lessur.util.shader.ShaderManager.java

License:GNU General Public License

/**
 * /*from   w  w w. j  a  v  a2 s.  c o m*/
 * @param program ID/index of the program
 * @param name Name of the variable
 * @param value Value to set the variable
 */
public void setUniformFloat(int program, String name, float value) {
    if (has_opengl2) {
        int loc = GL20.glGetUniformLocation(program, name);
        checkVariableLocation(loc, name);
        GL20.glUniform1f(loc, value);
    } else if (has_arb) {
        int loc = ARBShaderObjects.glGetUniformLocationARB(program, name);
        checkVariableLocation(loc, name);
        ARBShaderObjects.glUniform1fARB(loc, value);
    }
}

From source file:lessur.util.shader.ShaderManager.java

License:GNU General Public License

/**
 * /*from   w  w w  . j  av  a 2s  .co  m*/
 * @param program ID/index of the program
 * @param name Name of the variable
 * @param value Value to set the variable
 */
public void setUniformFloatArray(int program, String name, float values[]) {
    if (has_opengl2) {
        int loc = GL20.glGetUniformLocation(program, name);
        checkVariableLocation(loc, name);
        if (values.length == 1)
            GL20.glUniform1f(loc, values[0]);
        if (values.length == 2)
            GL20.glUniform2f(loc, values[0], values[1]);
        else if (values.length == 3)
            GL20.glUniform3f(loc, values[0], values[1], values[2]);
        else if (values.length == 4)
            GL20.glUniform4f(loc, values[0], values[1], values[2], values[3]);
    } else if (has_arb) {
        int loc = ARBShaderObjects.glGetUniformLocationARB(program, name);
        checkVariableLocation(loc, name);
        if (values.length == 1)
            ARBShaderObjects.glUniform1fARB(loc, values[0]);
        if (values.length == 2)
            ARBShaderObjects.glUniform2fARB(loc, values[0], values[1]);
        else if (values.length == 3)
            ARBShaderObjects.glUniform3fARB(loc, values[0], values[1], values[2]);
        else if (values.length == 4)
            ARBShaderObjects.glUniform4fARB(loc, values[0], values[1], values[2], values[3]);
    }
}

From source file:me.thehutch.fusion.engine.render.opengl.gl20.OpenGL20Program.java

License:Open Source License

@Override
public void setUniform(String name, float f) {
    final int loc = uniforms.get(name);
    if (loc >= 0) {
        GL20.glUniform1f(loc, f);
    }/*from  ww  w. java2s  .co m*/
}

From source file:net.betabears.the2dlibrary.graphics.shader.Uniform1f.java

@Override
public void apply(int location) {
    GL20.glUniform1f(location, f0);
}

From source file:net.neilcsmith.praxis.video.opengl.internal.ShaderProgram.java

License:Apache License

/** Sets the uniform with the given name. Throws an IllegalArgumentException in case it is not called in between a
 * {@link #begin()}/{@link #end()} block.
 * //w  w w. ja  v  a2 s . co  m
 * @param name the name of the uniform
 * @param value the value */
public void setUniformf(String name, float value) {
    checkContext();
    int location = fetchUniformLocation(name);
    GL20.glUniform1f(location, value);
}