Shader
abstract class Shader
Implements: IShader
Known subtypes: GlShader, VulkanShader
Package: dev.joid.lib.bridge.render.shader · Module: core · Source: Shader.java
The base class of a shader of a render bridge, which translates the two stages, lays out the uniforms and compiles the program at the first use.
Description
Section titled “Description”The constructor compiles nothing: compileProgram runs at the first isActive(), once the fields of the subclass are set.
With the dev jar, a stage that uses a feature beyond GLSL 1.20 prints a warning.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
| Shader(RenderBridge bridge, GlslShaderTranslator translator, ShaderSource vertex, ShaderSource fragment, BlendState blend) protected | Builds the uniform block and the samplers of the two stages and translates them with the translator of your API. |
Methods
Section titled “Methods”Reactivity
Section titled “Reactivity”| Returns | Signature | Summary |
|---|---|---|
void | bind() | Makes the shader and its blend state the current ones of the render state, remembering the previous blend state. |
void | unbind() | Removes the shader from the render state and puts the previous blend state back. |
Queries
Section titled “Queries”| Returns | Signature | Summary |
|---|---|---|
boolean | isActive() | Compiles the program on the first call, then returns isProgramActive(). |
IShader | getLineShader() | Returns the variant that draws wide lines as triangles, created on first use, with the current uniform values and samplers copied into it. |
Map<String,UniformSampler> | getSamplerMap() | Returns the samplers of the shader by name, read-only, each with its texture unit from 1. |
BlendState | getBlend() | Returns the blend state that bind() applies. |
RenderBridge | getBridge() | Returns the render bridge. |
ShaderSource | getVertex() | Returns the parsed vertex stage. |
ShaderSource | getFragment() | Returns the parsed fragment stage. |
UniformBlock | getBlock() | Returns the uniform block, which a subclass sends at each draw. |
ShaderTranslation | getTranslation() | Returns the translated sources that compileProgram receives. |
boolean | isBound() | If true, the shader is bound. |
boolean | isCompiled() | If true, compileProgram has run. |
BlendState | getPreviousBlend() | Returns the blend state that unbind() puts back, or null while unbound. |
Actions
Section titled “Actions”| Returns | Signature | Summary |
|---|---|---|
void | delete() | Deletes the line variant, then the program when it was compiled. |
IShader | uniform(String name, boolean value) | Sets a bool uniform of the block. |
IShader | uniform(String name, int… values) | Sets an integer uniform of the block. |
IShader | uniform(String name, float… values) | Sets a float uniform of the block. |
IShader | sampler(String name, ITexture texture, TextureFilter filter, TextureWrap wrap) | Sets the texture of a sampler, with its filter and wrap. |
UniformBlock | builtins(RenderState state, VertexBuffer buffer, float[] projection, MatrixStack modelView) | Writes the built-in uniforms of a draw into the block: matrices, lighting, alpha test, line width and viewport, vertex colors, current color and border emulation; returns the block. |
For subclasses
Section titled “For subclasses”| Returns | Signature | Summary |
|---|---|---|
boolean | isProgramActive() hook abstract protected | Returns true when the program compiled and links; JOID calls it from isActive(). |
void | compileProgram(ShaderTranslation translation) hook abstract protected | JOID calls it once, at the first isActive(). |
void | deleteProgram() hook abstract protected | JOID calls it from delete() when the program was compiled. |
Creation details
Section titled “Creation details”Shader
Section titled “Shader”Shader(RenderBridge bridge, GlslShaderTranslator translator, ShaderSource vertex, ShaderSource fragment, BlendState blend) protected
Builds the uniform block and the samplers of the two stages and translates them with the translator of your API.
Turns on the emulation of CLAMP_TO_BORDER when the bridge refuses that wrap.
Method details
Section titled “Method details”void bind()
Makes the shader and its blend state the current ones of the render state, remembering the previous blend state.
unbind
Section titled “unbind”void unbind()
Removes the shader from the render state and puts the previous blend state back.
isActive
Section titled “isActive”boolean isActive()
Compiles the program on the first call, then returns isProgramActive().
getLineShader
Section titled “getLineShader”IShader getLineShader()
Returns the variant that draws wide lines as triangles, created on first use, with the current uniform values and samplers copied into it.
getSamplerMap
Section titled “getSamplerMap”Map<String,UniformSampler> getSamplerMap()
Returns the samplers of the shader by name, read-only, each with its texture unit from 1.
getBlend
Section titled “getBlend”BlendState getBlend()
Returns the blend state that bind() applies.
getBridge
Section titled “getBridge”RenderBridge getBridge()
Returns the render bridge.
getVertex
Section titled “getVertex”ShaderSource getVertex()
Returns the parsed vertex stage.
getFragment
Section titled “getFragment”ShaderSource getFragment()
Returns the parsed fragment stage.
getBlock
Section titled “getBlock”UniformBlock getBlock()
Returns the uniform block, which a subclass sends at each draw.
getTranslation
Section titled “getTranslation”ShaderTranslation getTranslation()
Returns the translated sources that compileProgram receives.
isBound
Section titled “isBound”boolean isBound()
If true, the shader is bound.
isCompiled
Section titled “isCompiled”boolean isCompiled()
If true, compileProgram has run.
getPreviousBlend
Section titled “getPreviousBlend”BlendState getPreviousBlend()
Returns the blend state that unbind() puts back, or null while unbound.
delete
Section titled “delete”void delete()
Deletes the line variant, then the program when it was compiled.
uniform
Section titled “uniform”IShader uniform(String name, boolean value)
Sets a bool uniform of the block.
IShader uniform(String name, int... values)
Sets an integer uniform of the block.
IShader uniform(String name, float... values)
Sets a float uniform of the block.
sampler
Section titled “sampler”IShader sampler(String name, ITexture texture, TextureFilter filter, TextureWrap wrap)
Throws:
IllegalArgumentException: The shader declares no sampler …, declare it in the shader source or fix its name (samplers: …)
Sets the texture of a sampler, with its filter and wrap.
Throws an IllegalArgumentException that lists the samplers when the shader declares no sampler of that name.
builtins
Section titled “builtins”UniformBlock builtins(RenderState state, VertexBuffer buffer, float[] projection, MatrixStack modelView)
Writes the built-in uniforms of a draw into the block: matrices, lighting, alpha test, line width and viewport, vertex colors, current color and border emulation; returns the block.
isProgramActive
Section titled “isProgramActive”boolean isProgramActive() hook abstract protected
Returns true when the program compiled and links; JOID calls it from isActive().
compileProgram
Section titled “compileProgram”void compileProgram(ShaderTranslation translation) hook abstract protected
JOID calls it once, at the first isActive().
Compile and link the translated sources; on failure, print one warning that starts with [JOID] and leave the program inactive, without throwing.
deleteProgram
Section titled “deleteProgram”void deleteProgram() hook abstract protected
JOID calls it from delete() when the program was compiled.
Release the program.
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
