ShaderProgram
abstract class ShaderProgram
Known subtypes: BlurShader, BorderShader, CircleShader, GradientShader, RoundedShader, ShadowShader
Package: dev.joid.lib.shader.impl · Module: core · Source: ShaderProgram.java
Base class of a shader of your own, loaded from JOID GLSL sources and created on the render bridge the first time it is used.
Description
Section titled “Description”Extend it with a singleton, load the sources in the constructor, and draw through use so that the previous shader and blending come back afterwards (Write a shader).
A source that cannot be read or compiled warns once and makes the shader unavailable: what it draws is skipped instead of failing the frame. Create and use it on the render thread.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| ShaderProgram() | Creates a program, for a subclass. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
void | delete() | Frees the shader on the GPU; the next use creates it again. |
void | bind() | Binds the shader when it is available. |
void | unbind() | Unbinds the shader. |
IShader | getShader() | Returns the shader of the render bridge, created on the first call, or null when the sources could not be loaded or compiled. |
boolean | canDraw() | Returns isAvailable() and, when it is false, warns once in dev mode that what the shader draws is skipped. |
boolean | isAvailable() | If true, the shader is created and active on the current render bridge. |
void | gradient(ColorGradient gradient, BoundingBox canvas) | Sends gradient to the gradient uniforms of the shader, spread over canvas. |
void | use(Runnable bind, Runnable body) protected | Runs bind, which binds the shader and sets its uniforms, then body, which draws; then unbinds the shader and restores the previous shader and blending, even when body throws. |
void | uniformGradient(IShader shader, ColorGradient gradient, float x1, float y1, float x2, float y2) static | Sets u_HasGradient to 1 and the gradient uniforms of shader from gradient, spread over the box x1, y1, x2, y2. |
void | uniformGradient(IShader shader, Point startPoint, Point endPoint, Color startColor, Color endColor, float x1, float y1, float x2, float y2) static | Sets the gradient uniforms of shader (u_GradientStart, u_GradientEnd, u_GradientStartPos, u_GradientEndPos, u_GradientCanvas) from two stops and two points on 1, resolving animated colors, spread over the box x1, y1, x2, y2. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
void | load(Object vertexShader, Object fragmentShader) hook protected | Reads the vertex and fragment sources from anything Asset.of accepts; the shader is created later, at its first use. |
Creation details
Section titled “Creation details”ShaderProgram
Section titled “ShaderProgram”ShaderProgram()
Creates a program, for a subclass.
Method details
Section titled “Method details”delete
Section titled “delete”void delete()
Frees the shader on the GPU; the next use creates it again.
void bind()
Binds the shader when it is available.
unbind
Section titled “unbind”void unbind()
Unbinds the shader.
getShader
Section titled “getShader”IShader getShader()
Returns the shader of the render bridge, created on the first call, or null when the sources could not be loaded or compiled.
canDraw
Section titled “canDraw”boolean canDraw()
Returns isAvailable() and, when it is false, warns once in dev mode that what the shader draws is skipped.
isAvailable
Section titled “isAvailable”boolean isAvailable()
If true, the shader is created and active on the current render bridge.
gradient
Section titled “gradient”void gradient(ColorGradient gradient, BoundingBox canvas)
Sends gradient to the gradient uniforms of the shader, spread over canvas.
void use(Runnable bind, Runnable body) protected
Runs bind, which binds the shader and sets its uniforms, then body, which draws; then unbinds the shader and restores the previous shader and blending, even when body throws.
Does nothing when the shader is unavailable.
uniformGradient
Section titled “uniformGradient”void uniformGradient(IShader shader, ColorGradient gradient, float x1, float y1, float x2, float y2) static
Sets u_HasGradient to 1 and the gradient uniforms of shader from gradient, spread over the box x1, y1, x2, y2.
void uniformGradient(IShader shader, Point startPoint, Point endPoint, Color startColor, Color endColor, float x1, float y1, float x2, float y2) static
Sets the gradient uniforms of shader (u_GradientStart, u_GradientEnd, u_GradientStartPos, u_GradientEndPos, u_GradientCanvas) from two stops and two points on 1, resolving animated colors, spread over the box x1, y1, x2, y2.
void load(Object vertexShader, Object fragmentShader) hook protected
Reads the vertex and fragment sources from anything Asset.of accepts; the shader is created later, at its first use.
A source that cannot be read warns with the cause and leaves the shader unavailable.
fluent returns the instance, typed for chaining · factory creates an instance · signal also accepts a value that follows signals, as a signal, an expression or a lambda (When does JOID compute this value again?) · hook called by JOID, override it · abstract you implement it · default interface method with a body · static called on the class · protected visible to subclasses
