Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class ShaderEmitter

  1. Object
  2. ShaderEmitter

Prints ShaderNode graphs as statements of one shading language. This is the part of a backend’s shader generator that custom materials need; applications do not call it.

A backend creates one emitter per shader stage, calls emit for each hook it splices in, and uses the returned expression where the engine’s own value would have gone. Every node that is not a constant or an input becomes one temporary, so a node shared by several hooks is computed once.

Nested types

enum ShaderEmitter.DialectThe shading languages a graph prints as.
interface ShaderEmitter.InputsSupplies the backend’s spelling of the inputs a graph reads.

Constructors

public ShaderEmitter(ShaderEmitter.Dialect dialect, ShaderMaterial material, ShaderEmitter.Inputs inputs, StringBuilder out, String indent, String prefix)Creates an emitter that appends statements to out.

Methods

public String emit(ShaderNode node)Declares whatever temporaries node needs and returns the expression that holds its value.
public static String literal(float v)Returns a float literal every dialect reads the same way.
public String typeName(ShaderType t)Returns the dialect’s name of a type.
public static String typeName(ShaderEmitter.Dialect d, ShaderType t)Returns a dialect’s name of a type.
public static boolean uses(ShaderMaterial material, boolean fragment, String builtin)Returns true if any hook of the given stage reads the built-in input.
public static boolean uses(ShaderMaterial material, String builtin)Returns true if any hook of either stage reads the built-in input.
public static void describe(ShaderNode root, StringBuilder sb)Appends a structural description of a graph: equal for two graphs that print the same program.

Inherited methods

Constructor details

ShaderEmitter

public ShaderEmitter(ShaderEmitter.Dialect dialect, ShaderMaterial material, ShaderEmitter.Inputs inputs, StringBuilder out, String indent, String prefix)
Creates an emitter that appends statements to out.

Parameters

dialect ShaderEmitter.Dialect
the language to print
material ShaderMaterial
the material whose uniforms and textures the graphs read
inputs ShaderEmitter.Inputs
the backend’s spelling of the inputs
out StringBuilder
where the temporaries are declared
indent String
the indentation of each statement
prefix String
a prefix for temporary names, distinct per stage

Method details

emit

public String emit(ShaderNode node)
Declares whatever temporaries node needs and returns the expression that holds its value.

Parameters

node ShaderNode
the graph

Returns

an expression of the node’s type

literal

public static String literal(float v)
Returns a float literal every dialect reads the same way.

Parameters

v float
a finite value

Returns

the literal

typeName

public String typeName(ShaderType t)
Returns the dialect’s name of a type.

Parameters

t ShaderType
the type

Returns

the type name

typeName

public static String typeName(ShaderEmitter.Dialect d, ShaderType t)
Returns a dialect’s name of a type.

Parameters

d ShaderEmitter.Dialect
the dialect
t ShaderType
the type

Returns

the type name

uses

public static boolean uses(ShaderMaterial material, boolean fragment, String builtin)
Returns true if any hook of the given stage reads the built-in input.

Parameters

material ShaderMaterial
the material, or null
fragment boolean
true for the fragment stage
builtin String
the built-in’s name, such as worldPos

Returns

true if it is read

uses

public static boolean uses(ShaderMaterial material, String builtin)
Returns true if any hook of either stage reads the built-in input.

Parameters

material ShaderMaterial
the material, or null
builtin String
the built-in’s name

Returns

true if it is read

describe

public static void describe(ShaderNode root, StringBuilder sb)
Appends a structural description of a graph: equal for two graphs that print the same program. Shared nodes are written once and then referred to by number.

Parameters

root ShaderNode
the graph
sb StringBuilder
where to append