public class GLSLParser extends VariableBasedLanguageParser implements LineBasedParser
| Modifier and Type | Field and Description |
|---|---|
static String |
CUSTOM_TOKEN_IMPORT
CUSTOM TOKEN.
|
static String |
CUSTOM_TOKEN_INCLUDE
CUSTOM TOKEN.
|
static String |
INCLUDE_DIRECTORY
The parser will look into this directory, in order to include
files.
|
static org.slf4j.Logger |
LOGGER |
static String |
TOKEN_ATTRIBUTE
The attribute token used in the GLSL language
(attribute type name)
|
static String |
TOKEN_END_STATEMENT
The character used to end a line or a statement.
|
static String |
TOKEN_SINGLE_LINE_COMMENT |
static String |
TOKEN_SPACE
Just a space character to safe some memory, when generating code.
|
static String |
TOKEN_STRUCT
The struct token used in the GLSL language
(struct name {...})
|
static String |
TOKEN_UNIFORM
The uniform token used in the GLSL language
(uniform type name)
|
| Constructor and Description |
|---|
GLSLParser() |
| Modifier and Type | Method and Description |
|---|---|
static List<String> |
expandUniform(Variable uniform,
GLSLStruct main,
List<GLSLStruct> structs)
Expand a uniform
If a uniform's type is a custom struct, OpenGL
expects you to expand it.
|
static List<String> |
expendVariable(Variable variable,
GLSLStruct main,
List<GLSLStruct> structs)
Expand a variable
If a uniform's type is a custom struct, OpenGL
expects you to expand it.
|
protected static List<Variable> |
filterPrimitives(List<Variable> variables)
Just iterates over the list and adds primitves to a new list
|
protected static GLSLStruct |
findNameInList(String name,
List<GLSLStruct> structs)
Just iterates over the list and returns the first one with a matching name.
|
List<Variable> |
getAttributes(String text)
Just a wrapper for getVariables(text, TOKEN_ATTRIBUTE);
|
List<Uniform> |
getExpandedUniforms(String text,
List<Variable> uniforms,
List<GLSLStruct> structs)
Expands all uniforms for adding to the shader programm
|
List<GLSLStruct> |
getStructs(String text)
Parses all structs out of the supplied shader source
|
static List<Variable> |
getVariables(String text,
String token)
Scans through the shader source and extracts variables which
are "flagged" with a specific token.
|
protected static boolean |
isPrimitive(Variable v)
Check if the given variable is primitiv.
|
String |
parse(String line)
GLSLParser currently only works on include statements
|
protected static void |
printStructs(List<GLSLStruct> structs)
Prints a list of GLSLStruct s in an XML like format:
(Only if trace logging is enabled!)
|
GLSLScript |
process(GLSLScript script)
Processes a
GLSLScript. |
getNames, getTypespublic static final org.slf4j.Logger LOGGER
public static final String CUSTOM_TOKEN_INCLUDE
#include "file.ext"
// or
#include
// or even
#include $file.ext$
// You could also use two spaces..
public static final String CUSTOM_TOKEN_IMPORT
CUSTOM_TOKEN_INCLUDE,
Constant Field Valuespublic static final String TOKEN_SPACE
public static final String TOKEN_UNIFORM
public static final String TOKEN_ATTRIBUTE
public static final String TOKEN_STRUCT
public static final String TOKEN_END_STATEMENT
vec3 name = vec3(...);
public static final String TOKEN_SINGLE_LINE_COMMENT
public static final String INCLUDE_DIRECTORY
public String parse(String line) throws Exception
parse in interface LineBasedParserline - The line to loadExceptionLineBasedParser.parse(String)public List<GLSLStruct> getStructs(String text)
text - shader sourcepublic GLSLScript process(GLSLScript script)
GLSLScript.
Adds uniforms, expanded uniforms, attributes and all structs in the source.
Marks script as processed via GLSLScript#setProcessed(boolean)script - The script to processpublic List<Uniform> getExpandedUniforms(String text, List<Variable> uniforms, List<GLSLStruct> structs)
text - shader sourceuniforms - List of uniformsstructs - A list of GLSLStructspublic List<Variable> getAttributes(String text)
text - Shader sourcepublic static List<Variable> getVariables(String text, String token)
text - Shader sourcetoken - The token which will be used to filter statements of variables.public static List<String> expandUniform(Variable uniform, GLSLStruct main, List<GLSLStruct> structs)
uniform - The uniform to expandmain - The main struct (top-level) of the uniformstructs - A list of GLSLStructspublic static List<String> expendVariable(Variable variable, GLSLStruct main, List<GLSLStruct> structs)
variable - The uniform to expandmain - The main struct (top-level) of the uniformstructs - A list of GLSLStructsprotected static List<Variable> filterPrimitives(List<Variable> variables)
variables - All variablesprotected static boolean isPrimitive(Variable v)
v - The variable to checkprotected static GLSLStruct findNameInList(String name, List<GLSLStruct> structs)
name - The name to search forstructs - A list of GLSLStructsprotected static void printStructs(List<GLSLStruct> structs)
Struct Foo
{
float x;
vec4 y;
};
will yield
x
y
structs - A list of GLSLStructs to printCopyright © 2014. All rights reserved.