java.lang.Object
net.ixdarklord.coolcatcanvas.internal.client.render.CanvasProgram
All Implemented Interfaces:
AutoCloseable

public final class CanvasProgram extends Object implements AutoCloseable
A GLSL program linked from a vertex and a fragment shader in resources. Sources go through vanilla's preprocessor, with namespaced imports: #moj_import <namespace:file.glsl> reads assets/<namespace>/shaders/include/, #moj_import "file.glsl" a path next to the importing shader. Extra #defines go right after #version. The Position attribute is bound to location 0, where 1.20.1's vertex formats put it.

Kept out of vanilla's program caches, so its names never collide with vanilla's and reloading vanilla's shaders never frees it. Render thread only.

  • Method Details

    • compile

      public static CanvasProgram compile(net.minecraft.server.packs.resources.ResourceManager resources, String name, net.minecraft.resources.ResourceLocation vertex, net.minecraft.resources.ResourceLocation fragment, List<String> defines) throws IOException
      Parameters:
      vertex - the vertex shader's full path, e.g. minecraft:shaders/program/sobel.vsh
      fragment - the fragment shader's full path
      defines - names to #define in both shaders
      Throws:
      IOException - if a file is missing, or a shader doesn't compile or link
    • name

      public String name()
    • id

      public int id()
    • use

      public void use()
    • unuse

      public static void unuse()
    • location

      public int location(String uniform)
      The uniform's location, or -1 if the program doesn't use it.
    • has

      public boolean has(String uniform)
    • setInt

      public void setInt(String uniform, int value)
    • 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)
    • setVec4

      public void setVec4(String uniform, float[] xyzw)
    • setVec4Array

      public void setVec4Array(String uniform, float[] values)
      A vec4[], from 4 floats per element.
    • setMat4

      public void setMat4(String uniform, org.joml.Matrix4fc matrix)
    • close

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