Skip to content

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.

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.

ReturnsSignatureSummary
ShaderProgram()Creates a program, for a subclass.

ReturnsSignatureSummary
voiddelete()Frees the shader on the GPU; the next use creates it again.
voidbind()Binds the shader when it is available.
voidunbind()Unbinds the shader.
IShadergetShader()Returns the shader of the render bridge, created on the first call, or null when the sources could not be loaded or compiled.
booleancanDraw()Returns isAvailable() and, when it is false, warns once in dev mode that what the shader draws is skipped.
booleanisAvailable()If true, the shader is created and active on the current render bridge.
voidgradient(ColorGradient gradient, BoundingBox canvas)Sends gradient to the gradient uniforms of the shader, spread over canvas.
voiduse(Runnable bind, Runnable body) protectedRuns 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.
voiduniformGradient(IShader shader, ColorGradient gradient, float x1, float y1, float x2, float y2) staticSets u_HasGradient to 1 and the gradient uniforms of shader from gradient, spread over the box x1, y1, x2, y2.
voiduniformGradient(IShader shader, Point startPoint, Point endPoint, Color startColor, Color endColor, float x1, float y1, float x2, float y2) staticSets 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.
ReturnsSignatureSummary
voidload(Object vertexShader, Object fragmentShader) hook protectedReads the vertex and fragment sources from anything Asset.of accepts; the shader is created later, at its first use.

ShaderProgram()

Creates a program, for a subclass.

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. Does nothing when the shader is unavailable.

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

Report a problem with this page