Class CanvasProgram
java.lang.Object
net.ixdarklord.coolcatcanvas.internal.client.render.CanvasProgram
- All Implemented Interfaces:
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;
compile(ResourceManager, String, ResourceLocation, ResourceLocation, List, List) binds more.
Kept out of vanilla's program caches, so its names never collide with vanilla's and reloading vanilla's shaders
never frees it. Binding one tells vanilla its own shader is no longer bound (use()). Uniform locations and the
values last uploaded are remembered, so setting a uniform to the value it already has (samplers, matrices that
didn't change, every frame) costs no GL call. Render thread only.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static CanvasProgramcompile(net.minecraft.server.packs.resources.ResourceManager resources, String name, net.minecraft.resources.ResourceLocation vertex, net.minecraft.resources.ResourceLocation fragment, List<String> defines) static CanvasProgramcompile(net.minecraft.server.packs.resources.ResourceManager resources, String name, net.minecraft.resources.ResourceLocation vertex, net.minecraft.resources.ResourceLocation fragment, List<String> defines, List<String> attributes) booleanintid()intThe uniform's location, or -1 if the program doesn't use it.name()voidvoidvoidvoidvoidvoidvoidsetVec4Array(String uniform, float[] values) Avec4[], from 4 floats per element.static voidunuse()voiduse()Binds the program.
-
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.vshfragment- the fragment shader's full pathdefines- names to#definein both shaders- Throws:
IOException- if a file is missing, or a shader doesn't compile or link
-
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, List<String> attributes) throws IOException - Parameters:
attributes- vertex attribute names, bound to locations 0, 1, ... in order (as the vertex format's elements)- Throws:
IOException
-
name
-
id
public int id() -
use
public void use()Binds the program. Vanilla remembers the core and post shaders it bound last and skips binding the same one again, so binding this one behind its back would have its next draw with that shader run this program instead (or none, afterunuse()), with its uniforms uploaded to the wrong program. Its records are cleared here, so it binds its own again. -
unuse
public static void unuse() -
location
The uniform's location, or -1 if the program doesn't use it. -
has
-
setInt
-
setFloat
-
setVec2
-
setVec4
-
setVec4
-
setVec4Array
Avec4[], from 4 floats per element. -
setMat4
-
close
public void close()- Specified by:
closein interfaceAutoCloseable
-