Interface ShaderProgram

All Superinterfaces:
AutoCloseable, MutableUniformAccess, org.lwjgl.system.NativeResource, TextureUniformAccess, UniformAccess
All Known Implementing Classes:
ShaderProgramImpl

public interface ShaderProgram extends org.lwjgl.system.NativeResource, MutableUniformAccess, TextureUniformAccess
Represents a usable shader program with shaders attached.
  • Method Details

    • setup

      default void setup()
      Binds this program for use and prepares for rendering.
    • bind

      default void bind()
      Binds this program for use.
    • unbind

      static void unbind()
      Unbinds the currently bound shader program.
    • compile

      void compile(ShaderCompiler.Context context, ShaderCompiler compiler) throws Exception
      Compiles this shader based on the specified definition.
      Parameters:
      context - The context to use when compiling shaders
      compiler - The compiler to use
      Throws:
      Exception - If an error occurs while compiling or linking shaders
    • getProgram

      int getProgram()
      Returns:
      The OpenGL id of this program
    • getFloat

      default float getFloat(CharSequence name)
      Description copied from interface: UniformAccess
      Retrieves a single float by the specified name.
      Specified by:
      getFloat in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      Returns:
      The float value of that uniform
    • getInt

      default int getInt(CharSequence name)
      Description copied from interface: UniformAccess
      Retrieves a single integer by the specified name.
      Specified by:
      getInt in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      Returns:
      The int value of that uniform
    • getFloats

      default void getFloats(CharSequence name, float[] values)
      Description copied from interface: UniformAccess
      Retrieves an array of floats by the specified name.
      Specified by:
      getFloats in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      values - The values to set
    • getVector

      default void getVector(CharSequence name, org.joml.Vector2f... values)
      Description copied from interface: UniformAccess
      Retrieves an array of vectors by the specified name.
      Specified by:
      getVector in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      values - The values to set
    • getVector

      default void getVector(CharSequence name, org.joml.Vector3f... values)
      Description copied from interface: UniformAccess
      Retrieves an array of vectors by the specified name.
      Specified by:
      getVector in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      values - The values to set
    • getVector

      default void getVector(CharSequence name, org.joml.Vector4f... values)
      Description copied from interface: UniformAccess
      Retrieves an array of vectors by the specified name.
      Specified by:
      getVector in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      values - The values to set
    • getInts

      default void getInts(CharSequence name, int[] values)
      Description copied from interface: UniformAccess
      Retrieves an array of integers by the specified name.
      Specified by:
      getInts in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      values - The values to set
    • getVector

      default void getVector(CharSequence name, org.joml.Vector2i... values)
      Description copied from interface: UniformAccess
      Retrieves an array of vectors by the specified name.
      Specified by:
      getVector in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      values - The values to set
    • getVector

      default void getVector(CharSequence name, org.joml.Vector3i... values)
      Description copied from interface: UniformAccess
      Retrieves an array of vectors by the specified name.
      Specified by:
      getVector in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      values - The values to set
    • getVector

      default void getVector(CharSequence name, org.joml.Vector4i... values)
      Description copied from interface: UniformAccess
      Retrieves an array of vectors by the specified name.
      Specified by:
      getVector in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      values - The values to set
    • getMatrix

      default void getMatrix(CharSequence name, org.joml.Matrix2f value)
      Description copied from interface: UniformAccess
      Retrieves a matrix2x2 by the specified name
      Specified by:
      getMatrix in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      value - The value to set
    • getMatrix

      default void getMatrix(CharSequence name, org.joml.Matrix3f value)
      Description copied from interface: UniformAccess
      Retrieves a matrix3x3 by the specified name
      Specified by:
      getMatrix in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      value - The value to set
    • getMatrix

      default void getMatrix(CharSequence name, org.joml.Matrix3x2f value)
      Description copied from interface: UniformAccess
      Retrieves a matrix3x2 by the specified name
      Specified by:
      getMatrix in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      value - The value to set
    • getMatrix

      default void getMatrix(CharSequence name, org.joml.Matrix4f value)
      Description copied from interface: UniformAccess
      Retrieves a matrix4x4 by the specified name
      Specified by:
      getMatrix in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      value - The value to set
    • getMatrix

      default void getMatrix(CharSequence name, org.joml.Matrix4x3f value)
      Description copied from interface: UniformAccess
      Retrieves a matrix4x3 by the specified name
      Specified by:
      getMatrix in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      value - The value to set
    • setUniformBlock

      default void setUniformBlock(CharSequence name, int binding)
      Description copied from interface: MutableUniformAccess
      Sets the binding to use for the specified uniform block.
      Specified by:
      setUniformBlock in interface MutableUniformAccess
      Parameters:
      name - The name of the block to set
      binding - The binding to use for that block
    • setStorageBlock

      default void setStorageBlock(CharSequence name, int binding)
      Description copied from interface: MutableUniformAccess
      Sets the binding to use for the specified storage block.
      Specified by:
      setStorageBlock in interface MutableUniformAccess
      Parameters:
      name - The name of the block to set
      binding - The binding to use for that block
    • setFloat

      default void setFloat(CharSequence name, float value)
      Description copied from interface: MutableUniformAccess
      Sets a float in the shader.
      Specified by:
      setFloat in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      value - The value to set
    • setVector

      default void setVector(CharSequence name, float x, float y)
      Description copied from interface: MutableUniformAccess
      Sets a vector in the shader.
      Specified by:
      setVector in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      x - The x component of the vector
      y - The y component of the vector
    • setVector

      default void setVector(CharSequence name, float x, float y, float z)
      Description copied from interface: MutableUniformAccess
      Sets a vector in the shader.
      Specified by:
      setVector in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      x - The x component of the vector
      y - The y component of the vector
      z - The z component of the vector
    • setVector

      default void setVector(CharSequence name, float x, float y, float z, float w)
      Description copied from interface: MutableUniformAccess
      Sets a vector in the shader.
      Specified by:
      setVector in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      x - The x component of the vector
      y - The y component of the vector
      z - The z component of the vector
      w - The w component of the vector
    • setInt

      default void setInt(CharSequence name, int value)
      Description copied from interface: MutableUniformAccess
      Sets an integer in the shader.
      Specified by:
      setInt in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      value - The value to set
    • setVectorI

      default void setVectorI(CharSequence name, int x, int y)
      Description copied from interface: MutableUniformAccess
      Sets an integer vector in the shader.
      Specified by:
      setVectorI in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      x - The x component of the vector
      y - The y component of the vector
    • setVectorI

      default void setVectorI(CharSequence name, int x, int y, int z)
      Description copied from interface: MutableUniformAccess
      Sets an integer vector in the shader.
      Specified by:
      setVectorI in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      x - The x component of the vector
      y - The y component of the vector
      z - The z component of the vector
    • setVectorI

      default void setVectorI(CharSequence name, int x, int y, int z, int w)
      Description copied from interface: MutableUniformAccess
      Sets an integer vector in the shader.
      Specified by:
      setVectorI in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      x - The x component of the vector
      y - The y component of the vector
      z - The z component of the vector
      w - The w component of the vector
    • setFloats

      default void setFloats(CharSequence name, float... values)
      Description copied from interface: MutableUniformAccess
      Sets an array of floats in the shader.
      Specified by:
      setFloats in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      values - The values to set in order
    • setVectors

      default void setVectors(CharSequence name, org.joml.Vector2fc... values)
      Description copied from interface: MutableUniformAccess
      Sets an array of vectors in the shader.
      Specified by:
      setVectors in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      values - The values to set in order
    • setVectors

      default void setVectors(CharSequence name, org.joml.Vector3fc... values)
      Description copied from interface: MutableUniformAccess
      Sets an array of vectors in the shader.
      Specified by:
      setVectors in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      values - The values to set in order
    • setVectors

      default void setVectors(CharSequence name, org.joml.Vector4fc... values)
      Description copied from interface: MutableUniformAccess
      Sets an array of vectors in the shader.
      Specified by:
      setVectors in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      values - The values to set in order
    • setInts

      default void setInts(CharSequence name, int... values)
      Description copied from interface: MutableUniformAccess
      Sets an array of integers in the shader.
      Specified by:
      setInts in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      values - The values to set in order
    • setVectors

      default void setVectors(CharSequence name, org.joml.Vector2ic... values)
      Description copied from interface: MutableUniformAccess
      Sets an array of integer vectors in the shader.
      Specified by:
      setVectors in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      values - The values to set in order
    • setVectors

      default void setVectors(CharSequence name, org.joml.Vector3ic... values)
      Description copied from interface: MutableUniformAccess
      Sets an array of integer vectors in the shader.
      Specified by:
      setVectors in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      values - The values to set in order
    • setVectors

      default void setVectors(CharSequence name, org.joml.Vector4ic... values)
      Description copied from interface: MutableUniformAccess
      Sets an array of integer vectors in the shader.
      Specified by:
      setVectors in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      values - The values to set in order
    • setMatrix

      default void setMatrix(CharSequence name, org.joml.Matrix2fc value)
      Description copied from interface: MutableUniformAccess
      Sets a matrix in the shader.
      Specified by:
      setMatrix in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      value - The value to set
    • setMatrix

      default void setMatrix(CharSequence name, org.joml.Matrix3fc value)
      Description copied from interface: MutableUniformAccess
      Sets a matrix in the shader.
      Specified by:
      setMatrix in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      value - The value to set
    • setMatrix

      default void setMatrix(CharSequence name, org.joml.Matrix3x2fc value)
      Description copied from interface: MutableUniformAccess
      Sets a matrix in the shader.
      Specified by:
      setMatrix in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      value - The value to set
    • setMatrix

      default void setMatrix(CharSequence name, org.joml.Matrix4fc value)
      Description copied from interface: MutableUniformAccess
      Sets a matrix in the shader.
      Specified by:
      setMatrix in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      value - The value to set
    • setMatrix

      default void setMatrix(CharSequence name, org.joml.Matrix4x3fc value)
      Description copied from interface: MutableUniformAccess
      Sets a matrix in the shader.
      Specified by:
      setMatrix in interface MutableUniformAccess
      Parameters:
      name - The name of the uniform to set
      value - The value to set
    • getDefinition

      @Nullable @Nullable ProgramDefinition getDefinition()
      Returns:
      The definition used to compile the latest version of this shader
    • getShaders

      it.unimi.dsi.fastutil.ints.Int2ObjectMap<CompiledShader> getShaders()
      Returns:
      The shaders attached to this program
    • isCompute

      default boolean isCompute()
      Returns:
      Whether this program has the compute stage
    • hasGeometry

      default boolean hasGeometry()
      Returns:
      Whether this program has the geometry stage
    • hasTesselation

      default boolean hasTesselation()
      Returns:
      Whether this program has the tesselation stage
    • getDefinitionDependencies

      Set<String> getDefinitionDependencies()
      Returns:
      All shader definitions this program depends on
    • getId

      net.minecraft.resources.ResourceLocation getId()
      Returns:
      The id of this program
    • toShaderInstance

      net.minecraft.client.renderer.ShaderInstance toShaderInstance()

      Wraps this shader with a vanilla Minecraft shader instance wrapper. There are a few special properties about the shader wrapper.

      • The shader instance cannot be used to free the shader program. NativeResource.free() must be called separately. If the shader is loaded through ShaderManager then there is no need to free the shader.
      • Calling Uniform.upload() will do nothing since the values are uploaded when the appropriate methods are called
      • Uniforms are lazily wrapped and will not crash when the wrong method is called.
      • Uniform.set(int, float) is not supported and will throw an UnsupportedOperationException.
      • Only Uniform.set(Matrix3f) and Uniform.set(Matrix4f) will be able to set matrix values. All other matrix methods will throw an UnsupportedOperationException.
      • Uniform.set(float[]) only works for 1, 2, 3, and 4 float elements. Any other size will throw an UnsupportedOperationException.
      Returns:
      A lazily loaded shader instance wrapper for this program
    • create

      static ShaderProgram create(net.minecraft.resources.ResourceLocation id)
      Creates a new shader program with the specified id.
      Parameters:
      id - The id of the program
      Returns:
      A new shader program