Class ShaderProgramImpl

java.lang.Object
foundry.veil.impl.client.render.shader.ShaderProgramImpl
All Implemented Interfaces:
MutableUniformAccess, ShaderProgram, TextureUniformAccess, UniformAccess, AutoCloseable, org.lwjgl.system.NativeResource

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

    • ShaderProgramImpl

      public ShaderProgramImpl(net.minecraft.resources.ResourceLocation id)
  • Method Details

    • compile

      public void compile(ShaderCompiler.Context context, ShaderCompiler compiler) throws Exception
      Description copied from interface: ShaderProgram
      Compiles this shader based on the specified definition.
      Specified by:
      compile in interface ShaderProgram
      Parameters:
      context - The context to use when compiling shaders
      compiler - The compiler to use
      Throws:
      Exception - If an error occurs while compiling or linking shaders
    • 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
    • getDefinitionDependencies

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

      public net.minecraft.resources.ResourceLocation getId()
      Specified by:
      getId in interface ShaderProgram
      Returns:
      The id 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.
      • Only Uniform.set(Matrix3f) and Uniform.set(Matrix4f) will be able to set matrix values. All other matrix methods 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
    • 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
    • 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
    • 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
    • applyShaderSamplers

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

      public void addSamplerListener(TextureUniformAccess.SamplerListener listener)
      Description copied from interface: TextureUniformAccess
      Adds a listener for sampler updates.
      Specified by:
      addSamplerListener in interface TextureUniformAccess
      Parameters:
      listener - The listener instance
    • removeSamplerListener

      public void removeSamplerListener(TextureUniformAccess.SamplerListener listener)
      Description copied from interface: TextureUniformAccess
      Removes a listener from sampler updates.
      Specified by:
      removeSamplerListener in interface TextureUniformAccess
      Parameters:
      listener - The listener instance
    • addSampler

      public void addSampler(CharSequence name, int textureId)
      Description copied from interface: TextureUniformAccess
      Adds a texture that is dynamically bound and sets texture units.
      Specified by:
      addSampler 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
    • 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