Class ShaderProgramImpl
java.lang.Object
foundry.veil.impl.client.render.shader.program.ShaderProgramImpl
- All Implemented Interfaces:
MutableUniformAccess
,ShaderProgram
,TextureUniformAccess
,UniformAccess
,AutoCloseable
,org.lwjgl.system.NativeResource
- Direct Known Subclasses:
DynamicShaderProgramImpl
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final record
static final record
static class
static class
static class
Nested classes/interfaces inherited from interface foundry.veil.api.client.render.shader.program.TextureUniformAccess
TextureUniformAccess.SamplerListener
-
Field Summary
Fields inherited from interface foundry.veil.api.client.render.shader.program.MutableUniformAccess
DIRECTIONS
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addSampler
(CharSequence name, int textureId, int samplerId) Adds a texture that is dynamically bound and sets texture units.void
Adds a listener for sampler updates.void
addShaderBlock
(String name, ShaderBlock<?> block) protected void
Links and applies the specified shader program.protected void
attachShaders
(ShaderProgramImpl.CompiledProgram compiledProgram, ShaderSourceSet sourceSet, ShaderCompiler compiler) void
bind()
Binds this program for use.void
bindSamplers
(ShaderTextureSource.Context context, int samplerStart) Loads the samplers set byTextureUniformAccess.addSampler(CharSequence, int)
into the shader.void
Clears all samplers.void
void
compile
(int activeBuffers, ShaderSourceSet sourceSet, @Nullable ProgramDefinition definition, ShaderCompiler compiler) void
free()
@Nullable ProgramDefinition
@Nullable com.mojang.blaze3d.vertex.VertexFormat
net.minecraft.resources.ResourceLocation
getName()
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.boolean
hasStorageBlock
(CharSequence name) Checks if the specified storage block exists in the shader.boolean
hasUniform
(CharSequence name) Checks if the specified uniform exists in the shader.boolean
hasUniformBlock
(CharSequence name) Checks if the specified uniform block exists in the shader.void
recompile
(int activeBuffers, ShaderSourceSet sourceSet, ShaderCompiler compiler) void
removeSampler
(CharSequence name) Removes the specified sampler binding.void
Removes a listener from sampler updates.boolean
setActiveBuffers
(int activeBuffers) Sets the active buffers for this shaderWraps this shader with a vanilla Minecraft shader instance wrapper.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
setMatrix, setMatrix, setMatrix, setMatrix, setMatrix, 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
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, setVector, setVector, setVector, setVectorI, setVectorI, setVectorI, setVectors, setVectors, setVectors, setVectors, setVectors, setVectors
Methods inherited from interface foundry.veil.api.client.render.shader.program.TextureUniformAccess
addSampler, bindSamplers, setFramebufferSamplers
-
Field Details
-
DUMMY_FRAGMENT_SHADER
-
-
Constructor Details
-
ShaderProgramImpl
public ShaderProgramImpl(net.minecraft.resources.ResourceLocation name)
-
-
Method Details
-
applyProgram
Links and applies the specified shader program.- Parameters:
program
- The program to apply- Throws:
ShaderException
- If there is any problem linking the shader
-
attachShaders
protected void attachShaders(ShaderProgramImpl.CompiledProgram compiledProgram, ShaderSourceSet sourceSet, ShaderCompiler compiler) throws ShaderException, IOException - Throws:
ShaderException
IOException
-
compile
public void compile(int activeBuffers, ShaderSourceSet sourceSet, @Nullable @Nullable ProgramDefinition definition, ShaderCompiler compiler) throws ShaderException, IOException - Throws:
ShaderException
IOException
-
recompile
public void recompile(int activeBuffers, ShaderSourceSet sourceSet, ShaderCompiler compiler) throws ShaderException, IOException - Throws:
ShaderException
IOException
-
setActiveBuffers
Sets the active buffers for this shader- Parameters:
activeBuffers
- The new active buffers- Returns:
- Whether this shader needs to be scheduled for a recompilation
- Throws:
ShaderException
- If there is any problem linking the shader
-
bind
public void bind()Description copied from interface:ShaderProgram
Binds this program for use.- Specified by:
bind
in interfaceShaderProgram
-
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
-
getFormat
@Nullable public @Nullable com.mojang.blaze3d.vertex.VertexFormat getFormat()- Specified by:
getFormat
in interfaceShaderProgram
- Returns:
- A guess at the best vertex format for this program
-
getDefinitionDependencies
- Specified by:
getDefinitionDependencies
in interfaceShaderProgram
- Returns:
- All shader definitions this program depends on
-
getName
public net.minecraft.resources.ResourceLocation getName()- Specified by:
getName
in interfaceShaderProgram
- Returns:
- The name 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
.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
-
hasUniform
Description copied from interface:UniformAccess
Checks if the specified uniform exists in the shader.- Specified by:
hasUniform
in interfaceUniformAccess
- Parameters:
name
- The name of the uniform to check- Returns:
- Whether that uniform can be set
-
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
-
hasUniformBlock
Description copied from interface:UniformAccess
Checks if the specified uniform block exists in the shader.- Specified by:
hasUniformBlock
in interfaceUniformAccess
- Parameters:
name
- The name of the uniform block to check- Returns:
- Whether that uniform block can be set
-
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
-
hasStorageBlock
Description copied from interface:UniformAccess
Checks if the specified storage block exists in the shader.- Specified by:
hasStorageBlock
in interfaceUniformAccess
- Parameters:
name
- The name of the storage block to check- Returns:
- Whether that storage block can be set
-
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
-
bindSamplers
Description copied from interface:TextureUniformAccess
Loads the samplers set byTextureUniformAccess.addSampler(CharSequence, int)
into the shader.- Specified by:
bindSamplers
in interfaceTextureUniformAccess
- Parameters:
context
- The context for setting built-in shader samplers ornull
to ignore normal samplerssamplerStart
- The sampler to start binding to
-
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 unitsamplerId
- The id of the sampler 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
-
addShaderBlock
-
clearShaderBlocks
public void clearShaderBlocks()
-