java.lang.Object
org.openpatch.scratch.extensions.shader.Shaders

public class Shaders extends Object
The shaders belonging to one sprite or stage, and which of them is currently drawn with.

Reached through getShaders(), so that shader handling does not take up room in the everyday API of a sprite:


 this.getShaders().add("blur", "blur.frag", null);
 this.getShaders().switchTo("blur");
 
  • Constructor Details

    • Shaders

      public Shaders(String owner)
      Creates an empty set of shaders.
      Parameters:
      owner - what the shaders belong to, used in error messages: "sprite" or "stage"
    • Shaders

      public Shaders(Shaders s)
      Copies a set of shaders.
      Parameters:
      s - the shaders to copy
  • Method Details

    • add

      public Shader add(String name, String fragmentShaderPath, String vertexShaderPath)
      Adds a shader. If a shader with the given name already exists, that one is returned instead.
      Parameters:
      name - a unique name
      fragmentShaderPath - the path to the fragment shader
      vertexShaderPath - the path to the vertex shader, may be null
      Returns:
      the shader
    • get

      public Shader get(String name)
      Returns a shader by name.
      Parameters:
      name - the name of the shader
      Returns:
      the shader, or null if there is none with that name
    • switchTo

      public void switchTo(String name)
      Switches to the shader with the given name.
      Parameters:
      name - the name of the shader
    • switchTo

      public void switchTo(double index)
      Switches to the shader at the given position.
      Parameters:
      index - the position of the shader
    • next

      public void next()
      Switches to the next shader.
    • reset

      public void reset()
      Stops drawing with a shader.
    • getCurrent

      public Shader getCurrent()
      Returns the shader currently drawn with.
      Returns:
      the current shader, or null if there is none
    • getCurrentIndex

      public int getCurrentIndex()
      Returns the position of the current shader.
      Returns:
      the position, or -1 if no shader is in use
    • getCurrentName

      public String getCurrentName()
      Returns the name of the current shader.
      Returns:
      the name, or null if no shader is in use