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.
Description
Section titled “Description”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.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
ShaderSource | from(ShaderStage stage, String code) factory | Parses a source from its code. |
ShaderSource | read(ShaderStage stage, Object handle) factory | Reads and parses a source from anything that Asset.of opens: a File, an InputStream such as a classpath resource, a URL, an Asset. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
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. |
ShaderStage | getStage() | Returns the stage that the source was parsed for. |
String | getBody() | Returns the code without the #version line and without the declarations. |
boolean | isLine() | If true, the source comes from toLine(). |
Creation details
Section titled “Creation details”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.
Method details
Section titled “Method details”getInputs
Section titled “getInputs”List<ShaderVariable> getInputs()
Returns the in variables that a fragment source declares, in their order.
getBuiltins
Section titled “getBuiltins”Set<ShaderBuiltin> getBuiltins()
Returns the built-in attributes, uniforms and outputs that the code uses, found by name outside the comments.
getFeatures
Section titled “getFeatures”Set<ShaderFeature> getFeatures()
Returns the GLSL features beyond the baseline that the code and its declarations use.
getOutputs
Section titled “getOutputs”List<ShaderVariable> getOutputs()
Returns the out variables that a vertex source declares, in their order.
getUniforms
Section titled “getUniforms”List<ShaderVariable> getUniforms()
Returns the uniform variables that are not samplers, in their order.
getSamplers
Section titled “getSamplers”List<ShaderVariable> getSamplers()
Returns the sampler uniforms, in their order.
toLine
Section titled “toLine”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.
getStage
Section titled “getStage”ShaderStage getStage()
Returns the stage that the source was parsed for.
getBody
Section titled “getBody”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.
isLine
Section titled “isLine”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
