Class Shaders
java.lang.Object
org.openpatch.scratch.extensions.shader.Shaders
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionAdds a shader.Returns a shader by name.Returns the shader currently drawn with.intReturns the position of the current shader.Returns the name of the current shader.voidnext()Switches to the next shader, in the order they were added.voidreset()Stops drawing with a shader, so the sprite or stage looks as it does without one.voidswitchTo(double index) Switches to the shader at the given position.voidSwitches to the shader with the given name, or with the given position in the order the shaders were added.
-
Constructor Details
-
Shaders
Creates an empty set of shaders.- Parameters:
owner- what the shaders belong to, used in error messages: "sprite" or "stage"
-
Shaders
-
-
Method Details
-
add
Adds a shader. If a shader with the given name already exists, that one is returned instead.The first shader added is drawn with right away; the ones after it wait until
switchTo(String)ornext()picks them.The vertex shader is usually
null, which uses Processing's default one. In the browser any other vertex shader is ignored.- Parameters:
name- a unique namefragmentShaderPath- the path to the fragment shadervertexShaderPath- the path to the vertex shader, may be null- Returns:
- the shader
-
get
-
switchTo
Switches to the shader with the given name, or with the given position in the order the shaders were added. A name that is not there leaves the current shader and prints which ones there are.- 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, in the order they were added. After the last one comes the first one again. -
reset
public void reset()Stops drawing with a shader, so the sprite or stage looks as it does without one. The shaders are kept:switchTo(String)ornext()brings one back. -
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
Returns the name of the current shader.- Returns:
- the name, or null if no shader is in use
-