java.lang.Object
net.ixdarklord.coolcatcanvas.internal.client.effect.ShaderProgram
All Implemented Interfaces:
AutoCloseable

public final class ShaderProgram extends Object implements AutoCloseable
A GL program linked from assets/<namespace>/shaders/<path>.vsh and .fsh, for screen effects and sky layers. Vanilla's own shader classes only read the minecraft namespace and can't import includes into effect programs, so these are compiled here: #moj_import <namespace:file.glsl> reads assets/<namespace>/shaders/include/file.glsl (minecraft without a namespace), and #moj_import "file.glsl" a file next to the shader.

Uniforms are plain GLSL 150 uniforms, set by name; setting one the program lacks does nothing. Only use it from the render thread. Programs don't touch vanilla's cached shader state: vanilla rebinds its program for every draw.

  • Method Details

    • compile

      public static ShaderProgram compile(net.minecraft.server.packs.resources.ResourceProvider resources, net.minecraft.resources.ResourceLocation vertexShader, net.minecraft.resources.ResourceLocation fragmentShader, List<String> defines, List<String> attributes) throws IOException
      Compiles and links a program.
      Parameters:
      defines - #defines added after the #version line of both shaders
      attributes - vertex attribute names, bound to locations 0, 1, ... in order (as vanilla's vertex formats expect)
      Throws:
      IOException - if a shader is missing or fails to compile or link, with the driver's log
    • name

      public String name()
    • use

      public void use()
    • release

      public static void release()
      Unbinds any program, after drawing with these.
    • location

      public int location(String uniform)
      The uniform's location, or -1 if the program has none by that name.
    • has

      public boolean has(String uniform)
    • setFloat

      public void setFloat(String uniform, float value)
    • setVec2

      public void setVec2(String uniform, float x, float y)
    • setVec4

      public void setVec4(String uniform, float x, float y, float z, float w)
    • setVec4Array

      public void setVec4Array(String uniform, float[] values)
      Sets a vec4[] from its components, 4 per element.
    • setInt

      public void setInt(String uniform, int value)
    • setMatrix

      public void setMatrix(String uniform, org.joml.Matrix4f value)
    • setSampler

      public void setSampler(String uniform, int unit)
      Points a sampler at a texture unit.
    • set

      public void set(String uniform, ScreenEffectDefinition.UniformType type, float[] v)
      Sets a uniform of a definition's type from its components (a matrix column-major); missing components are 0, floats are truncated for int types.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable