Class ShaderProgramImpl
java.lang.Object
foundry.veil.impl.client.render.shader.ShaderProgramImpl
- All Implemented Interfaces:
MutableUniformAccess
,ShaderProgram
,TextureUniformAccess
,UniformAccess
,AutoCloseable
,org.lwjgl.system.NativeResource
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
Nested classes/interfaces inherited from interface foundry.veil.api.client.render.shader.program.TextureUniformAccess
TextureUniformAccess.SamplerListener
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addSampler
(CharSequence name, int textureId) Adds a texture that is dynamically bound and sets texture units.void
Adds a listener for sampler updates.int
applyShaderSamplers
(ShaderTextureSource.Context context, int sampler) Loads the samplers set byTextureUniformAccess.addSampler(CharSequence, int)
into the shader.void
Clears all samplers.void
compile
(ShaderCompiler.Context context, ShaderCompiler compiler) Compiles this shader based on the specified definition.void
free()
@Nullable ProgramDefinition
net.minecraft.resources.ResourceLocation
getId()
int
it.unimi.dsi.fastutil.ints.Int2ObjectMap
<CompiledShader> int
getStorageBlock
(CharSequence name) Retrieves the location of a storage block.int
getUniform
(CharSequence name) Retrieves the location of a uniform.int
getUniformBlock
(CharSequence name) Retrieves the location of a uniform block.void
removeSampler
(CharSequence name) Removes the specified sampler binding.void
Removes a listener from sampler updates.boolean
setActiveBuffers
(int activeBuffers) Wraps this shader with a vanilla Minecraft shader instance wrapper.void
updateActiveBuffers
(ShaderCompiler.Context context, ShaderCompiler compiler) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface foundry.veil.api.client.render.shader.program.MutableUniformAccess
applyRenderSystem, setVector, setVector, setVector, setVector, setVectorI, setVectorI, setVectorI
Methods inherited from interface org.lwjgl.system.NativeResource
close
Methods inherited from interface foundry.veil.api.client.render.shader.program.ShaderProgram
bind, getFloat, getFloats, getInt, getInts, getMatrix, getMatrix, getMatrix, getMatrix, getMatrix, getVector, getVector, getVector, getVector, getVector, getVector, hasGeometry, hasTesselation, isCompute, setFloat, setFloats, setInt, setInts, setMatrix, setMatrix, setMatrix, setMatrix, setMatrix, setStorageBlock, setUniformBlock, setup, setVector, setVector, setVector, setVectorI, setVectorI, setVectorI, setVectors, setVectors, setVectors, setVectors, setVectors, setVectors
Methods inherited from interface foundry.veil.api.client.render.shader.program.TextureUniformAccess
addRenderSystemTextures, applyShaderSamplers, setFramebufferSamplers
Methods inherited from interface foundry.veil.api.client.render.shader.program.UniformAccess
hasStorageBlock, hasUniform, hasUniformBlock
-
Constructor Details
-
ShaderProgramImpl
public ShaderProgramImpl(net.minecraft.resources.ResourceLocation id)
-
-
Method Details
-
compile
public void compile(ShaderCompiler.Context context, ShaderCompiler compiler) throws ShaderException, IOException Description copied from interface:ShaderProgram
Compiles this shader based on the specified definition.- Specified by:
compile
in interfaceShaderProgram
- Parameters:
context
- The context to use when compiling shaderscompiler
- The compiler to use- Throws:
ShaderException
- If an error occurs while compiling or linking shadersIOException
- If an error occurs while loading shaders
-
setActiveBuffers
- Throws:
ShaderException
-
updateActiveBuffers
public void updateActiveBuffers(ShaderCompiler.Context context, ShaderCompiler compiler) throws ShaderException, IOException - Throws:
ShaderException
IOException
-
free
public void free()- Specified by:
free
in interfaceorg.lwjgl.system.NativeResource
-
getShaders
- Specified by:
getShaders
in interfaceShaderProgram
- Returns:
- The shaders attached to this program
-
getDefinitionDependencies
- Specified by:
getDefinitionDependencies
in interfaceShaderProgram
- Returns:
- All shader definitions this program depends on
-
getId
public net.minecraft.resources.ResourceLocation getId()- Specified by:
getId
in interfaceShaderProgram
- Returns:
- The id of this program
-
toShaderInstance
Description copied from interface:ShaderProgram
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 throughShaderManager
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 anUnsupportedOperationException
.- Only
Uniform.set(Matrix3f)
andUniform.set(Matrix4f)
will be able to set matrix values. All other matrix methods will throw anUnsupportedOperationException
. Uniform.set(float[])
only works for 1, 2, 3, and 4 float elements. Any other size will throw anUnsupportedOperationException
.
- Specified by:
toShaderInstance
in interfaceShaderProgram
- Returns:
- A lazily loaded shader instance wrapper for this program
- The shader instance cannot be used to free the shader program.
-
getUniform
Description copied from interface:UniformAccess
Retrieves the location of a uniform.- Specified by:
getUniform
in interfaceUniformAccess
- Parameters:
name
- The name of the uniform to get- Returns:
- The location of that uniform or
-1
if not found
-
getUniformBlock
Description copied from interface:UniformAccess
Retrieves the location of a uniform block.- Specified by:
getUniformBlock
in interfaceUniformAccess
- Parameters:
name
- The name of the uniform block to get- Returns:
- The location of that uniform block or -1 if not found
-
getStorageBlock
Description copied from interface:UniformAccess
Retrieves the location of a storage block.- Specified by:
getStorageBlock
in interfaceUniformAccess
- Parameters:
name
- The name of the storage block to get- Returns:
- The location of that storage block or -1 if not found
-
getProgram
public int getProgram()- Specified by:
getProgram
in interfaceShaderProgram
- Returns:
- The OpenGL id of this program
-
getDefinition
- Specified by:
getDefinition
in interfaceShaderProgram
- Returns:
- The definition used to compile the latest version of this shader
-
applyShaderSamplers
Description copied from interface:TextureUniformAccess
Loads the samplers set byTextureUniformAccess.addSampler(CharSequence, int)
into the shader.- Specified by:
applyShaderSamplers
in interfaceTextureUniformAccess
- Parameters:
context
- The context for setting built-in shader samplers ornull
to ignore normal samplerssampler
- The sampler to start binding to- Returns:
- The next available sampler
-
addSamplerListener
Description copied from interface:TextureUniformAccess
Adds a listener for sampler updates.- Specified by:
addSamplerListener
in interfaceTextureUniformAccess
- Parameters:
listener
- The listener instance
-
removeSamplerListener
Description copied from interface:TextureUniformAccess
Removes a listener from sampler updates.- Specified by:
removeSamplerListener
in interfaceTextureUniformAccess
- Parameters:
listener
- The listener instance
-
addSampler
Description copied from interface:TextureUniformAccess
Adds a texture that is dynamically bound and sets texture units.- Specified by:
addSampler
in interfaceTextureUniformAccess
- Parameters:
name
- The name of the texture to settextureId
- The id of the texture to bind and assign a texture unit
-
removeSampler
Description copied from interface:TextureUniformAccess
Removes the specified sampler binding.- Specified by:
removeSampler
in interfaceTextureUniformAccess
- Parameters:
name
- The name of the sampler to remove
-
clearSamplers
public void clearSamplers()Description copied from interface:TextureUniformAccess
Clears all samplers.- Specified by:
clearSamplers
in interfaceTextureUniformAccess
-