Skip to content

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.

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.

ReturnsSignatureSummary
Shader(RenderBridge bridge, GlslShaderTranslator translator, ShaderSource vertex, ShaderSource fragment, BlendState blend) protectedBuilds the uniform block and the samplers of the two stages and translates them with the translator of your API.

ReturnsSignatureSummary
voidbind()Makes the shader and its blend state the current ones of the render state, remembering the previous blend state.
voidunbind()Removes the shader from the render state and puts the previous blend state back.
ReturnsSignatureSummary
booleanisActive()Compiles the program on the first call, then returns isProgramActive().
IShadergetLineShader()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.
BlendStategetBlend()Returns the blend state that bind() applies.
RenderBridgegetBridge()Returns the render bridge.
ShaderSourcegetVertex()Returns the parsed vertex stage.
ShaderSourcegetFragment()Returns the parsed fragment stage.
UniformBlockgetBlock()Returns the uniform block, which a subclass sends at each draw.
ShaderTranslationgetTranslation()Returns the translated sources that compileProgram receives.
booleanisBound()If true, the shader is bound.
booleanisCompiled()If true, compileProgram has run.
BlendStategetPreviousBlend()Returns the blend state that unbind() puts back, or null while unbound.
ReturnsSignatureSummary
voiddelete()Deletes the line variant, then the program when it was compiled.
IShaderuniform(String name, boolean value)Sets a bool uniform of the block.
IShaderuniform(String name, int… values)Sets an integer uniform of the block.
IShaderuniform(String name, float… values)Sets a float uniform of the block.
IShadersampler(String name, ITexture texture, TextureFilter filter, TextureWrap wrap)Sets the texture of a sampler, with its filter and wrap.
UniformBlockbuiltins(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.
ReturnsSignatureSummary
booleanisProgramActive() hook abstract protectedReturns true when the program compiled and links; JOID calls it from isActive().
voidcompileProgram(ShaderTranslation translation) hook abstract protectedJOID calls it once, at the first isActive().
voiddeleteProgram() hook abstract protectedJOID calls it from delete() when the program was compiled.

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.

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.

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.

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)

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.

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.

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(). Compile and link the translated sources; on failure, print one warning that starts with [JOID] and leave the program inactive, without throwing.

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

Report a problem with this page