UniformBlock
final class UniformBlock
Package: dev.joid.lib.bridge.render.shader.uniform · Module: core · Source: UniformBlock.java
Holds every uniform value of a shader at its std140 offset, tracks which ones changed, and packs or hands them to the backend before a draw.
Description
Section titled “Description”Each Shader owns one block, created by GlslShaderTranslator.createBlock from the uniforms of both stages.
IShader.uniform writes the values of the shader author, Shader.builtins writes those of JOID, and the backend sends them as its UniformLayout requires.
Learn more
Section titled “Learn more”Creation
Section titled “Creation”| Returns | Signature | Summary |
|---|---|---|
UniformBlock | create(List | Lays out the variables one after the other with the std140 rules and allocates the buffer, rounded up to a multiple of 16 bytes and at least 16 bytes. |
Methods
Section titled “Methods”| Returns | Signature | Summary |
|---|---|---|
this | value(String name, boolean value) fluent | Writes a boolean into the member name. |
this | value(String name, int… values) fluent | Writes integers into the member name; a float member receives them as floats. |
this | value(String name, float… values) fluent | Writes floats into the member name. |
boolean | pack() | Copies the changed members into getData() at their offsets, matrix columns and array elements on their strides, and marks them as sent. |
this | upload(Consumer | Gives each changed member to uploader, then marks it as sent. |
int | getSize() | Returns the size of the std140 buffer in bytes, a multiple of 16. |
Map<String,UniformMember> | getMemberMap() | Returns the members by name, in block order, as a view that cannot be changed. |
UniformMember | getMember(String name) | Returns the member called name, or null when the block has none. |
UniformMember | requireMember(String name) | Returns the member called name. |
ByteBuffer | getData() | Returns the std140 buffer, in native byte order, that pack() fills. |
Creation details
Section titled “Creation details”create
Section titled “create”UniformBlock create(List<ShaderVariable> variables, String code) factory
Lays out the variables one after the other with the std140 rules and allocates the buffer, rounded up to a multiple of 16 bytes and at least 16 bytes.
code is the GLSL of both stages, where JOID reads the #define that gives an array length written as a name.
Throws IllegalArgumentException for a type outside UniformType or a length that is neither a number nor a #define.
Method details
Section titled “Method details”this value(String name, boolean value) fluent
Writes a boolean into the member name.
Throws IllegalArgumentException when the block has no such member, or when the member is not a single bool or int.
this value(String name, int... values) fluent
Writes integers into the member name; a float member receives them as floats.
Throws IllegalArgumentException when the block has no such member, or when the count does not fit its type.
this value(String name, float... values) fluent
Writes floats into the member name.
Throws IllegalArgumentException when the block has no such member, when the member stores integers, or when the count does not fit its type.
boolean pack()
Copies the changed members into getData() at their offsets, matrix columns and array elements on their strides, and marks them as sent.
Returns true when at least one member changed, so that the backend knows whether to upload the buffer again.
upload
Section titled “upload”this upload(Consumer<UniformMember> uploader) fluent
Gives each changed member to uploader, then marks it as sent.
getSize
Section titled “getSize”int getSize()
Returns the size of the std140 buffer in bytes, a multiple of 16.
getMemberMap
Section titled “getMemberMap”Map<String,UniformMember> getMemberMap()
Returns the members by name, in block order, as a view that cannot be changed.
getMember
Section titled “getMember”UniformMember getMember(String name)
Returns the member called name, or null when the block has none.
requireMember
Section titled “requireMember”UniformMember requireMember(String name)
Throws:
IllegalArgumentException: The shader declares no builtin uniform …: JOID declares its joid_ uniforms only where they are used, translate the shader with stencil(…) for the stencil ones (uniforms: …)IllegalArgumentException: The shader declares no uniform …, declare it in the shader source or fix its name (uniforms: …)
Returns the member called name.
Throws IllegalArgumentException with the names of the block when it has none.
getData
Section titled “getData”ByteBuffer getData()
Returns the std140 buffer, in native byte order, that pack() fills.
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
