Skip to content

Commit e0c0125

Browse files
committed
Add VeilRenderBridge#toShaderProgram
1 parent 790e34b commit e0c0125

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

common/src/main/java/foundry/veil/api/client/render/VeilRenderBridge.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import net.minecraft.client.renderer.culling.Frustum;
2121
import net.minecraft.resources.ResourceLocation;
2222
import org.jetbrains.annotations.ApiStatus;
23+
import org.jetbrains.annotations.Nullable;
2324

2425
import java.util.function.Supplier;
2526

@@ -35,9 +36,11 @@ public interface VeilRenderBridge {
3536
* <ul>
3637
* <li>The shader instance cannot be used to free the shader program. {@link ShaderProgram#free()} must be called separately.
3738
* If the shader is loaded through {@link ShaderManager} then there is no need to free the shader.</li>
39+
* <li>{@link ShaderInstance#attachToProgram()} is unsupported</li>
3840
* <li>Calling {@link Uniform#upload()} will do nothing since the values are uploaded when the appropriate methods are called</li>
3941
* <li>Uniforms are lazily wrapped and will not crash when the wrong method is called.</li>
4042
* <li>{@link Uniform#set(int, float)} is not supported and will throw an {@link UnsupportedOperationException}.</li>
43+
* <li>{@link Uniform#setMat4x2(float, float, float, float, float, float, float, float)} is not supported and will throw an {@link UnsupportedOperationException}.</li>
4144
* <li>{@link Uniform#set(float[])} only works for 1, 2, 3, and 4 float elements. Any other size will throw an {@link UnsupportedOperationException}.</li>
4245
* </ul>
4346
*
@@ -48,6 +51,18 @@ static ShaderInstance toShaderInstance(ShaderProgram program) {
4851
return ((ShaderProgramImpl) program).toShaderInstance();
4952
}
5053

54+
55+
/**
56+
* Attempts to convert a vanilla Minecraft shader instance into a Veil shader. Only works if the shader instance is wrapped with {@link #toShaderInstance(ShaderProgram)}.
57+
*
58+
* @param instance The program to convert
59+
* @return The wrapped shader program or <code>null</code> if the program is not a wrapped Veil shader
60+
* @since 3.4.0
61+
*/
62+
static @Nullable ShaderProgram toShaderProgram(ShaderInstance instance) {
63+
return instance instanceof ShaderProgramImpl.Wrapper wrapper ? wrapper.program() : null;
64+
}
65+
5166
/**
5267
* Creates a cull frustum helper from the specified vanilla frustum.
5368
*

0 commit comments

Comments
 (0)