Class ShaderProgram

java.lang.Object
engine.shaders.ShaderProgram
Direct Known Subclasses:
EntityShader, FontShader, GuiShader, SelectorShader, TerrainShader

public abstract class ShaderProgram extends Object
Abstract class from which all shaders inherit.
  • Constructor Summary

    Constructors
    Constructor
    Description
    ShaderProgram(String vertexFile, String fragmentFile)
    Receives the file name of the vertex and fragment GLSL file for a shader.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected void
    bindAttribute(int attribute, String variableName)
    Binds the attributes to the Shader
    protected abstract void
    Binds all attributes on a per shader program basis
    void
    Detaches and deletes the program from the GPU
    protected abstract void
    Gets all uniform loactions on a per shader program basis.
    protected int
    Finds the uniform variables in the shader
    protected void
    load2DVector(int location, org.joml.Vector2f vector)
    Loads a Vector2f into the shader
    protected void
    loadBoolean(int location, boolean value)
    Loads a boolean value into the shader.
    protected void
    loadFloat(int location, float value)
    Loads a float value into the shader.
    protected void
    loadMatrix(int location, org.joml.Matrix4f matrix)
    Loads a Matrix4f into the shader
    protected void
    loadVector(int location, org.joml.Vector3f vector)
    Loads a Vector3f into the shader.
    void
    Starts the program
    void
    Stops the program

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ShaderProgram

      public ShaderProgram(String vertexFile, String fragmentFile)
      Receives the file name of the vertex and fragment GLSL file for a shader. Proceeds to load the shader file from the method below and then create a shader program which runs on the GPU. Shader program is attached and linked to the GPU and all attributes are bind as well as all uniform locations are found.
      Parameters:
      vertexFile -
      fragmentFile -
  • Method Details

    • start

      public void start()
      Starts the program
    • stop

      public void stop()
      Stops the program
    • cleanUp

      public void cleanUp()
      Detaches and deletes the program from the GPU
    • bindAttribute

      protected void bindAttribute(int attribute, String variableName)
      Binds the attributes to the Shader
      Parameters:
      attribute -
      variableName -
    • getUniformLocation

      protected int getUniformLocation(String uniformName)
      Finds the uniform variables in the shader
      Parameters:
      uniformName -
      Returns:
    • loadFloat

      protected void loadFloat(int location, float value)
      Loads a float value into the shader.
      Parameters:
      location -
      value -
    • loadVector

      protected void loadVector(int location, org.joml.Vector3f vector)
      Loads a Vector3f into the shader.
      Parameters:
      location -
      vector -
    • load2DVector

      protected void load2DVector(int location, org.joml.Vector2f vector)
      Loads a Vector2f into the shader
      Parameters:
      location -
      vector -
    • loadBoolean

      protected void loadBoolean(int location, boolean value)
      Loads a boolean value into the shader.
      Parameters:
      location -
      value -
    • loadMatrix

      protected void loadMatrix(int location, org.joml.Matrix4f matrix)
      Loads a Matrix4f into the shader
      Parameters:
      location -
      matrix -
    • bindAttributes

      protected abstract void bindAttributes()
      Binds all attributes on a per shader program basis
    • getAllUniformLocations

      protected abstract void getAllUniformLocations()
      Gets all uniform loactions on a per shader program basis.