Class ShaderPrograms

java.lang.Object
dev.cammiescorner.velvet.api.util.ShaderPrograms

public final class ShaderPrograms extends Object
This class consists exclusively of static methods that operate on OpenGL shader program objects.
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    bindAdditionalTextures(int program, net.minecraft.resources.ResourceLocation... textures)
    Binds any number of additional textures to be used by the current shader.
    static int
    getUniformLocation(int program, String uniformName)
    getUniformLocation returns an integer that represents the location of a specific uniform variable within a program object.
    static void
    setAttribValue(int program, String attribName, IntConsumer operation)
    Sets the value of an attribute from the current shader program using the given operation.
    static void
    setUniform(int program, String uniformName, float value)
    Sets the value of a float uniform field from the current shader program
    static void
    setUniform(int program, String uniformName, int value)
    Sets the value of an int uniform from the current shader program
    static void
    setUniform(int program, String uniformName, FloatBuffer mat4)
    Sets the value of a mat4 uniform in the current shader
    static void
    setUniformValue(int program, String uniformName, IntConsumer operation)
    Sets the value of a uniform from the current shader program using the given operation.
    static void
    useShader(int program)
    Sets the currently used program.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • useShader

      @API(status=MAINTAINED) public static void useShader(int program)
      Sets the currently used program.

      If shaders are disallowed in the current game instance, this method returns immediately with no side effect.

      Parameters:
      program - the reference to the desired shader (0 to remove any current shader)
    • setAttribValue

      @API(status=EXPERIMENTAL) public static void setAttribValue(int program, String attribName, IntConsumer operation)
      Sets the value of an attribute from the current shader program using the given operation.

      operation will only be called if shaders are enabled and an attribute with the given name exists in the current program. It should call one of GL20 attrib functions (eg. GL20.glBindAttribLocation(int, int, ByteBuffer)).

      Parameters:
      program - OpenGL shader program object
      attribName - the name of the attribute field in the shader source file
      operation - a gl operation to apply to this uniform
    • setUniformValue

      @API(status=EXPERIMENTAL) public static void setUniformValue(int program, String uniformName, IntConsumer operation)
      Sets the value of a uniform from the current shader program using the given operation.

      operation will only be called if shaders are enabled and a uniform with the given name exists in the current program. It should call one of GL20 uniform functions (eg. GL20.glUniform1iv(int, IntBuffer)).

      Parameters:
      program - OpenGL shader program object
      uniformName - the name of the uniform field in the shader source file
      operation - a gl operation to apply to this uniform
    • setUniform

      @API(status=STABLE) public static void setUniform(int program, String uniformName, int value)
      Sets the value of an int uniform from the current shader program
      Parameters:
      program - OpenGL shader program object
      uniformName - the name of the uniform field in the shader source file
      value - an int value for this uniform
    • setUniform

      @API(status=EXPERIMENTAL) public static void setUniform(int program, String uniformName, float value)
      Sets the value of a float uniform field from the current shader program
      Parameters:
      program - OpenGL shader program object
      uniformName - the name of the uniform field in the shader source file
      value - float value of the uniform
    • setUniform

      @API(status=EXPERIMENTAL) public static void setUniform(int program, String uniformName, FloatBuffer mat4)
      Sets the value of a mat4 uniform in the current shader
      Parameters:
      program - OpenGL shader program object
      uniformName - the name of the uniform field in the shader source file
      mat4 - a raw array of float values
    • getUniformLocation

      @API(status=MAINTAINED) public static int getUniformLocation(int program, String uniformName)
      getUniformLocation returns an integer that represents the location of a specific uniform variable within a program object.

      name must be a string that contains no white space. name must be an active uniform variable name in program that is not a structure, an array of structures, or a subcomponent of a vector or a matrix.

      This function returns -1 if name does not correspond to an active uniform variable in program or if name starts with the reserved prefix "gl_".

      Uniform locations obtained through this method are cached, limiting performance loss from consecutive calls.

      Parameters:
      program - program object to be queried
      uniformName - string containing the name of the uniform variable whose location is to be queried
      Returns:
      an integer that represents the location of a specific uniform variable within a program object
    • bindAdditionalTextures

      @API(status=EXPERIMENTAL) public static void bindAdditionalTextures(int program, net.minecraft.resources.ResourceLocation... textures)
      Binds any number of additional textures to be used by the current shader.

      The default texture (0) is unaffected. Shaders can access these textures by using uniforms named "textureN" with N being the index of the additional texture, starting at 1.

      Example: The call bindAdditionalTextures(rl1, rl2, rl3) will let the shader access those textures via the uniforms
      
       uniform sampler2D texture;   // the texture that's currently being drawn
       uniform sampler2D texture1;  // the texture designated by rl1
       uniform sampler2D texture2;  // the texture designated by rl2
       uniform sampler2D texture3;  // the texture designated by rl3