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
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final recordstatic classstatic classstatic class -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddShaderBlock(String name, ShaderBlock<?> block) protected voidLinks and applies the specified shader program.protected voidattachShaders(ShaderProgramImpl.CompiledProgram compiledProgram, ShaderSourceSet sourceSet, ShaderCompiler compiler) voidbind()Binds this program for use.voidbindSamplers(ShaderTextureSource.Context context, int samplerStart) Loads the samplers set byTextureUniformAccess.setSampler(CharSequence, int)into the shader.voidClears all samplers.voidvoidcompile(int activeBuffers, ShaderSourceSet sourceSet, @Nullable ProgramDefinition definition, ShaderCompiler compiler) voidfree()voidint@Nullable ProgramDefinition@Nullable com.mojang.blaze3d.vertex.VertexFormatnet.minecraft.resources.ResourceLocationgetName()Retrieves a uniform by name or creates a reference to one that may exist in the future.intit.unimi.dsi.fastutil.ints.Int2ObjectMap<CompiledShader> intgetStorageBlock(CharSequence name) Retrieves the location of a storage block.@Nullable ShaderUniformImplgetUniform(CharSequence name) Retrieves a uniform by name.intgetUniformBlock(CharSequence name) Retrieves the location of a uniform block.intRetrieves the location of a uniform.getUniformSafe(CharSequence name) Retrieves a uniform by name.booleanhasStorageBlock(CharSequence name) Checks if the specified storage block exists in the shader.booleanhasUniform(CharSequence name) Checks if the specified uniform exists in the shader.booleanhasUniformBlock(CharSequence name) Checks if the specified uniform block exists in the shader.booleanisValid()voidrecompile(int activeBuffers, ShaderSourceSet sourceSet, ShaderCompiler compiler) voidremoveSampler(CharSequence name) Removes the specified sampler binding.static voidRestores the previously saved blend state.static voidsaveBlendState(boolean saveEquation) Saves the current blend state to be restored later withrestoreBlendState().booleansetActiveBuffers(int activeBuffers) Sets the active buffers for this shadervoidsetDefaultUniforms(com.mojang.blaze3d.vertex.VertexFormat.Mode mode, org.joml.Matrix4fc modelViewMatrix, org.joml.Matrix4fc projectionMatrix) Sets the default uniforms in this shader.voidsetSampler(CharSequence name, int textureId, int samplerId) Adds a texture that is dynamically bound and sets texture units.Wraps 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, waitMethods inherited from interface org.lwjgl.system.NativeResource
closeMethods inherited from interface foundry.veil.api.client.render.shader.program.ShaderProgram
hasFragment, hasGeometry, hasTesselation, hasVertex, isCompute, setDefaultUniforms, setStorageBlock, setUniformBlockMethods inherited from interface foundry.veil.api.client.render.shader.program.TextureUniformAccess
bindSamplers, setFramebufferSamplers, setSampler
-
Field Details
-
DUMMY_FRAGMENT_SHADER
-
-
Constructor Details
-
ShaderProgramImpl
public ShaderProgramImpl(net.minecraft.resources.ResourceLocation name)
-
-
Method Details
-
saveBlendState
public static void saveBlendState(boolean saveEquation) Saves the current blend state to be restored later withrestoreBlendState().- Parameters:
saveEquation- Whether the blend equation needs to be reset after
-
restoreBlendState
public static void restoreBlendState()Restores the previously saved blend state. -
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:
ShaderExceptionIOException
-
compile
public void compile(int activeBuffers, ShaderSourceSet sourceSet, @Nullable @Nullable ProgramDefinition definition, ShaderCompiler compiler) throws ShaderException, IOException - Throws:
ShaderExceptionIOException
-
recompile
public void recompile(int activeBuffers, ShaderSourceSet sourceSet, ShaderCompiler compiler) throws ShaderException, IOException - Throws:
ShaderExceptionIOException
-
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:ShaderProgramBinds this program for use.- Specified by:
bindin interfaceShaderProgram
-
setDefaultUniforms
public void setDefaultUniforms(com.mojang.blaze3d.vertex.VertexFormat.Mode mode, org.joml.Matrix4fc modelViewMatrix, org.joml.Matrix4fc projectionMatrix) Description copied from interface:ShaderProgramSets the default uniforms in this shader.- Specified by:
setDefaultUniformsin interfaceShaderProgram- Parameters:
mode- The expected draw modemodelViewMatrix- The view matrix transformprojectionMatrix- The projection matrix transform
-
freeInternal
public void freeInternal() -
free
public void free()- Specified by:
freein interfaceorg.lwjgl.system.NativeResource
-
getShaders
- Specified by:
getShadersin interfaceShaderProgram- Returns:
- The shaders attached to this program
-
isValid
public boolean isValid()- Specified by:
isValidin interfaceShaderProgram- Returns:
- Whether this program has a valid compiled shader
-
getRequiredFeatures
- Specified by:
getRequiredFeaturesin interfaceShaderProgram- Returns:
- The features this program needs to function
-
getFormat
@Nullable public @Nullable com.mojang.blaze3d.vertex.VertexFormat getFormat()- Specified by:
getFormatin interfaceShaderProgram- Returns:
- A guess at the best vertex format for this program
-
getDefinitionDependencies
- Specified by:
getDefinitionDependenciesin interfaceShaderProgram- Returns:
- All shader definitions this program depends on
-
getName
public net.minecraft.resources.ResourceLocation getName()- Specified by:
getNamein interfaceShaderProgram- Returns:
- The name of this program
-
toShaderInstance
Description copied from interface:ShaderProgramWraps 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 throughShaderManagerthen 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:
toShaderInstancein interfaceShaderProgram- Returns:
- A lazily loaded shader instance wrapper for this program
- The shader instance cannot be used to free the shader program.
-
getUniformLocation
Description copied from interface:UniformAccessRetrieves the location of a uniform.- Specified by:
getUniformLocationin interfaceUniformAccess- Parameters:
name- The name of the uniform to get- Returns:
- The location of that uniform or
-1if not found
-
getUniform
Description copied from interface:UniformAccessRetrieves a uniform by name.- Specified by:
getUniformin interfaceShaderProgram- Specified by:
getUniformin interfaceUniformAccess- Parameters:
name- The name of the uniform to get- Returns:
- The uniform with that name or
nullif the uniform does not exist
-
getUniformSafe
Description copied from interface:UniformAccessRetrieves a uniform by name.- Specified by:
getUniformSafein interfaceUniformAccess- Parameters:
name- The name of the uniform to get- Returns:
- The uniform with that name
-
getOrCreateUniform
Description copied from interface:UniformAccessRetrieves a uniform by name or creates a reference to one that may exist in the future.- Specified by:
getOrCreateUniformin interfaceShaderProgram- Specified by:
getOrCreateUniformin interfaceUniformAccess- Parameters:
name- The name of the uniform to get- Returns:
- The uniform instance
-
hasUniform
Description copied from interface:UniformAccessChecks if the specified uniform exists in the shader.- Specified by:
hasUniformin interfaceUniformAccess- Parameters:
name- The name of the uniform to check- Returns:
- Whether that uniform can be set
-
getUniformBlock
Description copied from interface:UniformAccessRetrieves the location of a uniform block.- Specified by:
getUniformBlockin 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:UniformAccessChecks if the specified uniform block exists in the shader.- Specified by:
hasUniformBlockin interfaceUniformAccess- Parameters:
name- The name of the uniform block to check- Returns:
- Whether that uniform block can be set
-
getStorageBlock
Description copied from interface:UniformAccessRetrieves the location of a storage block.- Specified by:
getStorageBlockin 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:UniformAccessChecks if the specified storage block exists in the shader.- Specified by:
hasStorageBlockin 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:
getProgramin interfaceShaderProgram- Returns:
- The OpenGL id of this program
-
getActiveDynamicBuffers
public int getActiveDynamicBuffers()- Specified by:
getActiveDynamicBuffersin interfaceShaderProgram- Returns:
- The active buffers in the compiled program
-
getDefinition
- Specified by:
getDefinitionin interfaceShaderProgram- Returns:
- The definition used to compile the latest version of this shader
-
bindSamplers
Description copied from interface:TextureUniformAccessLoads the samplers set byTextureUniformAccess.setSampler(CharSequence, int)into the shader.- Specified by:
bindSamplersin interfaceTextureUniformAccess- Parameters:
context- The context for setting built-in shader samplers ornullto ignore normal samplerssamplerStart- The sampler to start binding to
-
setSampler
Description copied from interface:TextureUniformAccessAdds a texture that is dynamically bound and sets texture units.- Specified by:
setSamplerin 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:TextureUniformAccessRemoves the specified sampler binding.- Specified by:
removeSamplerin interfaceTextureUniformAccess- Parameters:
name- The name of the sampler to remove
-
clearSamplers
public void clearSamplers()Description copied from interface:TextureUniformAccessClears all samplers.- Specified by:
clearSamplersin interfaceTextureUniformAccess
-
addShaderBlock
-
clearShaderBlocks
public void clearShaderBlocks()
-