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

@Internal public class ShaderProgramImpl extends Object implements ShaderProgram
  • Field Details

    • DUMMY_FRAGMENT_SHADER

      public static final VeilShaderSource 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 with restoreBlendState().
      Parameters:
      saveEquation - Whether the blend equation needs to be reset after
    • restoreBlendState

      public static void restoreBlendState()
      Restores the previously saved blend state.
    • applyProgram

      protected void applyProgram(ShaderProgramImpl.CompiledProgram program) throws ShaderException
      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

      public boolean setActiveBuffers(int activeBuffers) throws ShaderException
      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 interface ShaderProgram
    • setDefaultUniforms

      public void setDefaultUniforms(com.mojang.blaze3d.vertex.VertexFormat.Mode mode, org.joml.Matrix4fc modelViewMatrix, org.joml.Matrix4fc projectionMatrix)
      Description copied from interface: ShaderProgram
      Sets the default uniforms in this shader.
      Specified by:
      setDefaultUniforms in interface ShaderProgram
      Parameters:
      mode - The expected draw mode
      modelViewMatrix - The view matrix transform
      projectionMatrix - The projection matrix transform
    • free

      public void free()
      Specified by:
      free in interface org.lwjgl.system.NativeResource
    • getShaders

      public it.unimi.dsi.fastutil.ints.Int2ObjectMap<CompiledShader> getShaders()
      Specified by:
      getShaders in interface ShaderProgram
      Returns:
      The shaders attached to this program
    • getFormat

      @Nullable public @Nullable com.mojang.blaze3d.vertex.VertexFormat getFormat()
      Specified by:
      getFormat in interface ShaderProgram
      Returns:
      A guess at the best vertex format for this program
    • getDefinitionDependencies

      public Set<String> getDefinitionDependencies()
      Specified by:
      getDefinitionDependencies in interface ShaderProgram
      Returns:
      All shader definitions this program depends on
    • getName

      public net.minecraft.resources.ResourceLocation getName()
      Specified by:
      getName in interface ShaderProgram
      Returns:
      The name of this program
    • toShaderInstance

      public ShaderProgramImpl.Wrapper 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 through ShaderManager 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 an UnsupportedOperationException.
      • Uniform.set(float[]) only works for 1, 2, 3, and 4 float elements. Any other size will throw an UnsupportedOperationException.
      Specified by:
      toShaderInstance in interface ShaderProgram
      Returns:
      A lazily loaded shader instance wrapper for this program
    • getUniform

      public int getUniform(CharSequence name)
      Description copied from interface: UniformAccess
      Retrieves the location of a uniform.
      Specified by:
      getUniform in interface UniformAccess
      Parameters:
      name - The name of the uniform to get
      Returns:
      The location of that uniform or -1 if not found
    • hasUniform

      public boolean hasUniform(CharSequence name)
      Description copied from interface: UniformAccess
      Checks if the specified uniform exists in the shader.
      Specified by:
      hasUniform in interface UniformAccess
      Parameters:
      name - The name of the uniform to check
      Returns:
      Whether that uniform can be set
    • getUniformBlock

      public int getUniformBlock(CharSequence name)
      Description copied from interface: UniformAccess
      Retrieves the location of a uniform block.
      Specified by:
      getUniformBlock in interface UniformAccess
      Parameters:
      name - The name of the uniform block to get
      Returns:
      The location of that uniform block or -1 if not found
    • hasUniformBlock

      public boolean hasUniformBlock(CharSequence name)
      Description copied from interface: UniformAccess
      Checks if the specified uniform block exists in the shader.
      Specified by:
      hasUniformBlock in interface UniformAccess
      Parameters:
      name - The name of the uniform block to check
      Returns:
      Whether that uniform block can be set
    • getStorageBlock

      public int getStorageBlock(CharSequence name)
      Description copied from interface: UniformAccess
      Retrieves the location of a storage block.
      Specified by:
      getStorageBlock in interface UniformAccess
      Parameters:
      name - The name of the storage block to get
      Returns:
      The location of that storage block or -1 if not found
    • hasStorageBlock

      public boolean hasStorageBlock(CharSequence name)
      Description copied from interface: UniformAccess
      Checks if the specified storage block exists in the shader.
      Specified by:
      hasStorageBlock in interface UniformAccess
      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 interface ShaderProgram
      Returns:
      The OpenGL id of this program
    • getDefinition

      @Nullable public @Nullable ProgramDefinition getDefinition()
      Specified by:
      getDefinition in interface ShaderProgram
      Returns:
      The definition used to compile the latest version of this shader
    • bindSamplers

      public void bindSamplers(@Nullable ShaderTextureSource.Context context, int samplerStart)
      Description copied from interface: TextureUniformAccess
      Loads the samplers set by TextureUniformAccess.setSampler(CharSequence, int) into the shader.
      Specified by:
      bindSamplers in interface TextureUniformAccess
      Parameters:
      context - The context for setting built-in shader samplers or null to ignore normal samplers
      samplerStart - The sampler to start binding to
    • setSampler

      public void setSampler(CharSequence name, int textureId, int samplerId)
      Description copied from interface: TextureUniformAccess
      Adds a texture that is dynamically bound and sets texture units.
      Specified by:
      setSampler in interface TextureUniformAccess
      Parameters:
      name - The name of the texture to set
      textureId - The id of the texture to bind and assign a texture unit
      samplerId - The id of the sampler assign a texture unit
    • removeSampler

      public void removeSampler(CharSequence name)
      Description copied from interface: TextureUniformAccess
      Removes the specified sampler binding.
      Specified by:
      removeSampler in interface TextureUniformAccess
      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 interface TextureUniformAccess
    • addShaderBlock

      public void addShaderBlock(String name, ShaderBlock<?> block)
    • clearShaderBlocks

      public void clearShaderBlocks()