Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final class ShaderEmitter
- Object
- 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.Dialect | The shading languages a graph prints as. |
interface ShaderEmitter.Inputs | Supplies the backend’s spelling of the inputs a graph reads. |
Constructors
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
dialectShaderEmitter.Dialect- the language to print
materialShaderMaterial- the material whose uniforms and textures the graphs read
inputsShaderEmitter.Inputs- the backend’s spelling of the inputs
outStringBuilder- where the temporaries are declared
indentString- the indentation of each statement
prefixString- 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
nodeShaderNode- 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
vfloat- a finite value
Returns
the literal
typeName
public String typeName(ShaderType t)Returns the dialect’s name of a type.
Parameters
tShaderType- 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
dShaderEmitter.Dialect- the dialect
tShaderType- 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
materialShaderMaterial- the material, or null
fragmentboolean- true for the fragment stage
builtinString- 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
materialShaderMaterial- the material, or null
builtinString- 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
rootShaderNode- the graph
sbStringBuilder- where to append