Skip to content

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.

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.

ReturnsSignatureSummary
UniformBlockcreate(List variables, String code) factoryLays 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.

ReturnsSignatureSummary
thisvalue(String name, boolean value) fluentWrites a boolean into the member name.
thisvalue(String name, int… values) fluentWrites integers into the member name; a float member receives them as floats.
thisvalue(String name, float… values) fluentWrites floats into the member name.
booleanpack()Copies the changed members into getData() at their offsets, matrix columns and array elements on their strides, and marks them as sent.
thisupload(Consumer uploader) fluentGives each changed member to uploader, then marks it as sent.
intgetSize()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.
UniformMembergetMember(String name)Returns the member called name, or null when the block has none.
UniformMemberrequireMember(String name)Returns the member called name.
ByteBuffergetData()Returns the std140 buffer, in native byte order, that pack() fills.

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.

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.

this upload(Consumer<UniformMember> uploader) fluent

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)

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.

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

Report a problem with this page