Skip to content

ShaderSource

final class ShaderSource
Package: dev.joid.lib.bridge.render.shader.source · Module: core · Source: ShaderSource.java

One stage of a shader written in JOID GLSL, parsed so that every backend can translate it.

A source is a GLSL body in the dialect of JOID: Write JOID GLSL gives its rules and its built-in names. Parsing drops the #version line and the in, out and uniform declarations, which the translator writes again for each backend, and notes the built-in names and the ShaderFeatures that the code uses. A ShaderProgram reads both of its stages for you.

ReturnsSignatureSummary
ShaderSourcefrom(ShaderStage stage, String code) factoryParses a source from its code.
ShaderSourceread(ShaderStage stage, Object handle) factoryReads and parses a source from anything that Asset.of opens: a File, an InputStream such as a classpath resource, a URL, an Asset.

ReturnsSignatureSummary
List<ShaderVariable>getInputs()Returns the in variables that a fragment source declares, in their order.
Set<ShaderBuiltin>getBuiltins()Returns the built-in attributes, uniforms and outputs that the code uses, found by name outside the comments.
Set<ShaderFeature>getFeatures()Returns the GLSL features beyond the baseline that the code and its declarations use.
List<ShaderVariable>getOutputs()Returns the out variables that a vertex source declares, in their order.
List<ShaderVariable>getUniforms()Returns the uniform variables that are not samplers, in their order.
List<ShaderVariable>getSamplers()Returns the sampler uniforms, in their order.
ShaderSourcetoLine()Returns the line variant of a vertex source: the same code, run twice per vertex by a wrapper that widens each segment into a quad of the line width.
ShaderStagegetStage()Returns the stage that the source was parsed for.
StringgetBody()Returns the code without the #version line and without the declarations.
booleanisLine()If true, the source comes from toLine().

ShaderSource from(ShaderStage stage, String code) factory

Parses a source from its code. Throws IllegalArgumentException when a vertex source declares an in variable (read the built-in attributes instead) or a fragment source declares an out variable (write the color to fragColor).

ShaderSource read(ShaderStage stage, Object handle) factory

Throws:

  • UncheckedIOException: …

Reads and parses a source from anything that Asset.of opens: a File, an InputStream such as a classpath resource, a URL, an Asset. Throws UncheckedIOException when the source cannot be read, and IllegalArgumentException as from does.

List<ShaderVariable> getInputs()

Returns the in variables that a fragment source declares, in their order.

Set<ShaderBuiltin> getBuiltins()

Returns the built-in attributes, uniforms and outputs that the code uses, found by name outside the comments.

Set<ShaderFeature> getFeatures()

Returns the GLSL features beyond the baseline that the code and its declarations use.

List<ShaderVariable> getOutputs()

Returns the out variables that a vertex source declares, in their order.

List<ShaderVariable> getUniforms()

Returns the uniform variables that are not samplers, in their order.

List<ShaderVariable> getSamplers()

Returns the sampler uniforms, in their order.

ShaderSource toLine()

Returns the line variant of a vertex source: the same code, run twice per vertex by a wrapper that widens each segment into a quad of the line width. The core calls it to build the line shader of a shader; your own shaders never need it.

ShaderStage getStage()

Returns the stage that the source was parsed for.

String getBody()

Returns the code without the #version line and without the declarations. Each removed line stays as an empty line, so the line numbers of a compiler error match the source.

boolean isLine()

If true, the source comes from toLine().


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