| Modifier and Type | Field and Description |
|---|---|
static boolean |
DEBUG_CODE |
static String |
DISABLE
Behavior for GLSL extension directive, see
createExtensionDirective(String, String), value "disable". |
static String |
ENABLE
Behavior for GLSL extension directive, see
createExtensionDirective(String, String), value "enable". |
static String |
es2_default_precision_fp
Default precision of
ES2 for fragment-shader: "\nprecision mediump float;\nprecision mediump int;\n/*precision lowp sampler2D;*/\n/*precision lowp samplerCube;*/\n" |
static String |
es2_default_precision_vp
Default precision of
ES2 for vertex-shader: "\nprecision highp float;\nprecision highp int;\n/*precision lowp sampler2D;*/\n/*precision lowp samplerCube;*/\n" |
static String |
es3_default_precision_fp
Default precision of
ES3 for fragment-shader: "\nprecision mediump float;\nprecision mediump int;\n/*precision lowp sampler2D;*/\n/*precision lowp samplerCube;*/\n" |
static String |
es3_default_precision_vp
Default precision of
ES3 for vertex-shader: "\nprecision highp float;\nprecision highp int;\n/*precision lowp sampler2D;*/\n/*precision lowp samplerCube;*/\n" |
static String |
gl3_default_precision_fp
Default precision of GLSL ≥ 1.30 as required until < 1.50 for
fragment-shader: "\nprecision highp float;\nprecision mediump int;\n/*precision mediump sampler2D;*/\n". |
static String |
gl3_default_precision_vp_gp
Default precision of GLSL ≥ 1.30 as required until < 1.50 for
vertex-shader or geometry-shader: "\nprecision highp float;\nprecision highp int;\n". |
static String |
REQUIRE
Behavior for GLSL extension directive, see
createExtensionDirective(String, String), value "require". |
static String |
SUB_PATH_NVIDIA
Unique relative path for binary shader resources for
NVIDIA: nvidia |
static String |
SUFFIX_FRAGMENT_BINARY
Unique resource suffix for
GL2ES2.GL_FRAGMENT_SHADER in binary: bfp |
static String |
SUFFIX_FRAGMENT_SOURCE
Unique resource suffix for
GL2ES2.GL_FRAGMENT_SHADER in source code: fp |
static String |
SUFFIX_GEOMETRY_BINARY
Unique resource suffix for
GL3.GL_GEOMETRY_SHADER in binary: bgp |
static String |
SUFFIX_GEOMETRY_SOURCE
Unique resource suffix for
GL3.GL_GEOMETRY_SHADER in source code: gp |
static String |
SUFFIX_VERTEX_BINARY
Unique resource suffix for
GL2ES2.GL_VERTEX_SHADER in binary: bvp |
static String |
SUFFIX_VERTEX_SOURCE
Unique resource suffix for
GL2ES2.GL_VERTEX_SHADER in source code: vp |
static String |
WARN
Behavior for GLSL extension directive, see
createExtensionDirective(String, String), value "warn". |
| Constructor and Description |
|---|
ShaderCode(int type,
int count,
CharSequence[][] source) |
ShaderCode(int type,
int count,
int binFormat,
Buffer binary) |
| Modifier and Type | Method and Description |
|---|---|
int |
addDefaultShaderPrecision(GL2ES2 gl,
int pos)
Adds default precision to source code at given position if required, i.e.
|
int |
addGLSLVersion(GL2ES2 gl)
Add GLSL version at the head of this shader source code.
|
boolean |
compile(GL2ES2 gl) |
boolean |
compile(GL2ES2 gl,
PrintStream verboseOut) |
static ShaderCode |
create(GL2ES2 gl,
int type,
Class<?> context,
String srcRoot,
String binRoot,
String basename,
boolean mutableStringBuilder)
Simplified variation of
#create(GL2ES2, int, int, Class, String, String[], String, String). |
static ShaderCode |
create(GL2ES2 gl,
int type,
int count,
Class<?> context,
String[] sourceFiles,
boolean mutableStringBuilder)
Creates a complete
ShaderCode object while reading all shader source of sourceFiles,
which location is resolved using the context class, see #readShaderSource(Class, String). |
static ShaderCode |
create(GL2ES2 gl,
int type,
int count,
Class<?> context,
String srcRoot,
String[] srcBasenames,
String binRoot,
String binBasename,
boolean mutableStringBuilder)
Convenient creation method for instantiating a complete
ShaderCode object
either from source code using #create(GL2ES2, int, int, Class, String[]),
or from a binary code using create(int, int, Class, int, String),
whatever is available first. |
static ShaderCode |
create(int type,
int count,
Class<?> context,
int binFormat,
String binaryFile)
Creates a complete
ShaderCode object while reading the shader binary of binaryFile,
which location is resolved using the context class, see readShaderBinary(Class, String). |
static String |
createExtensionDirective(String extensionName,
String behavior)
Creates a GLSL extension directive.
|
int |
defaultShaderCustomization(GL2ES2 gl,
boolean preludeVersion,
boolean addDefaultPrecision)
Default customization of this shader source code.
|
int |
defaultShaderCustomization(GL2ES2 gl,
boolean preludeVersion,
String esDefaultPrecision)
Default customization of this shader source code.
|
void |
destroy(GL2ES2 gl) |
void |
dumpShaderSource(PrintStream out) |
boolean |
equals(Object obj) |
static String |
getBinarySubPath(int binFormat)
Returns a unique relative path for binary shader resources as follows:
NVIDIA: SUB_PATH_NVIDIA
|
static String |
getFileSuffix(boolean binary,
int type)
Returns a unique suffix for shader resources as follows:
Source
vertex: SUFFIX_VERTEX_SOURCE
fragment: SUFFIX_FRAGMENT_SOURCE
geometry: SUFFIX_GEOMETRY_SOURCE
Binary
vertex: SUFFIX_VERTEX_BINARY
fragment: SUFFIX_FRAGMENT_BINARY
geometry: SUFFIX_GEOMETRY_BINARY
|
int |
hashCode() |
int |
id()
returns the uniq shader id as an integer
|
int |
insertShaderSource(int shaderIdx,
int position,
CharSequence data)
Adds
data at position in shader source for shader shaderIdx. |
int |
insertShaderSource(int shaderIdx,
int position,
Class<?> context,
String path)
Adds shader source located in
path,
either relative to the context class or absolute as-is
at position in shader source for shader shaderIdx. |
int |
insertShaderSource(int shaderIdx,
String tag,
int fromIndex,
CharSequence data)
Adds
data after the line containing tag. |
boolean |
isValid() |
static ByteBuffer |
readShaderBinary(Class<?> context,
String path)
Reads shader binary located in
path,
either relative to the context class or absolute as-is. |
static CharSequence |
readShaderSource(Class<?> context,
String path,
boolean mutableStringBuilder)
Reads shader source located in
path,
either relative to the context class or absolute as-is. |
static void |
readShaderSource(Class<?> context,
URLConnection conn,
StringBuilder result) |
int |
replaceInShaderSource(String oldName,
String newName)
Replaces
oldName with newName in all shader sources. |
static boolean |
requiresDefaultPrecision(GL2ES2 gl)
Returns true, if GLSL version requires default precision, i.e.
|
static boolean |
requiresGL3DefaultPrecision(GL2ES2 gl)
Returns true, if GL3 GLSL version requires default precision, i.e.
|
IntBuffer |
shader() |
Buffer |
shaderBinary() |
int |
shaderBinaryFormat() |
CharSequence[][] |
shaderSource() |
int |
shaderType() |
String |
shaderTypeStr() |
static String |
shaderTypeStr(int type) |
String |
toString() |
public static final boolean DEBUG_CODE
public static final String SUFFIX_VERTEX_SOURCE
GL2ES2.GL_VERTEX_SHADER in source code: vppublic static final String SUFFIX_VERTEX_BINARY
GL2ES2.GL_VERTEX_SHADER in binary: bvppublic static final String SUFFIX_GEOMETRY_SOURCE
GL3.GL_GEOMETRY_SHADER in source code: gppublic static final String SUFFIX_GEOMETRY_BINARY
GL3.GL_GEOMETRY_SHADER in binary: bgppublic static final String SUFFIX_FRAGMENT_SOURCE
GL2ES2.GL_FRAGMENT_SHADER in source code: fppublic static final String SUFFIX_FRAGMENT_BINARY
GL2ES2.GL_FRAGMENT_SHADER in binary: bfppublic static final String SUB_PATH_NVIDIA
NVIDIA: nvidiapublic static final String es2_default_precision_vp
ES2 for vertex-shader: "\nprecision highp float;\nprecision highp int;\n/*precision lowp sampler2D;*/\n/*precision lowp samplerCube;*/\n"public static final String es2_default_precision_fp
ES2 for fragment-shader: "\nprecision mediump float;\nprecision mediump int;\n/*precision lowp sampler2D;*/\n/*precision lowp samplerCube;*/\n"public static final String es3_default_precision_vp
ES3 for vertex-shader: "\nprecision highp float;\nprecision highp int;\n/*precision lowp sampler2D;*/\n/*precision lowp samplerCube;*/\n"public static final String es3_default_precision_fp
ES3 for fragment-shader: "\nprecision mediump float;\nprecision mediump int;\n/*precision lowp sampler2D;*/\n/*precision lowp samplerCube;*/\n"public static final String gl3_default_precision_vp_gp
vertex-shader or geometry-shader: "\nprecision highp float;\nprecision highp int;\n". See GLSL Spec 1.30-1.50 Section 4.5.3.public static final String gl3_default_precision_fp
fragment-shader: "\nprecision highp float;\nprecision mediump int;\n/*precision mediump sampler2D;*/\n". See GLSL Spec 1.30-1.50 Section 4.5.3.public static final String REQUIRE
createExtensionDirective(String, String), value "require".public static final String ENABLE
createExtensionDirective(String, String), value "enable".public static final String DISABLE
createExtensionDirective(String, String), value "disable".public static final String WARN
createExtensionDirective(String, String), value "warn".public ShaderCode(int type,
int count,
CharSequence[][] source)
type - either GL2ES2.GL_VERTEX_SHADER, GL2ES2.GL_FRAGMENT_SHADER or GL3.GL_GEOMETRY_SHADERcount - number of shaderssource - CharSequence array containing the shader sources, organized as source[count][strings-per-shader].
May be either an immutable String - or mutable StringBuilder array.IllegalArgumentException - if count and source.length do not matchpublic ShaderCode(int type,
int count,
int binFormat,
Buffer binary)
type - either GL2ES2.GL_VERTEX_SHADER, GL2ES2.GL_FRAGMENT_SHADER or GL3.GL_GEOMETRY_SHADERcount - number of shadersbinary - binary buffer containing the shader binaries,public static ShaderCode create(GL2ES2 gl, int type, int count, Class<?> context, String[] sourceFiles, boolean mutableStringBuilder)
ShaderCode object while reading all shader source of sourceFiles,
which location is resolved using the context class, see #readShaderSource(Class, String).gl - current GL object to determine whether a shader compiler is available. If null, no validation is performed.type - either GL2ES2.GL_VERTEX_SHADER, GL2ES2.GL_FRAGMENT_SHADER or GL3.GL_GEOMETRY_SHADERcount - number of shaderscontext - class used to help resolving the source locationsourceFiles - array of source locations, organized as sourceFiles[count]mutableStringBuilder - if true method returns a mutable StringBuilder instance
which can be edited later on at the costs of a String conversion when passing to
GL2ES2.glShaderSource(int, int, String[], IntBuffer).
If false method returns an immutable String instance,
which can be passed to GL2ES2.glShaderSource(int, int, String[], IntBuffer)
at no additional costs.IllegalArgumentException - if count and sourceFiles.length do not match#readShaderSource(Class, String)public static ShaderCode create(int type, int count, Class<?> context, int binFormat, String binaryFile)
ShaderCode object while reading the shader binary of binaryFile,
which location is resolved using the context class, see readShaderBinary(Class, String).type - either GL2ES2.GL_VERTEX_SHADER, GL2ES2.GL_FRAGMENT_SHADER or GL3.GL_GEOMETRY_SHADERcount - number of shaderscontext - class used to help resolving the source locationbinFormat - a valid native binary format as they can be queried by ShaderUtil.getShaderBinaryFormats(GL).sourceFiles - array of source locations, organized as sourceFiles[count]readShaderBinary(Class, String),
ShaderUtil.getShaderBinaryFormats(GL)public static String getFileSuffix(boolean binary, int type)
binary - true for a binary resource, false for a source resourcetype - either GL2ES2.GL_VERTEX_SHADER, GL2ES2.GL_FRAGMENT_SHADER or GL3.GL_GEOMETRY_SHADERGLException - if type is not supportedcreate(GL2ES2, int, Class, String, String, String, boolean)public static String getBinarySubPath(int binFormat)
GLException - if binFormat is not supportedcreate(GL2ES2, int, Class, String, String, String, boolean)public static ShaderCode create(GL2ES2 gl, int type, int count, Class<?> context, String srcRoot, String[] srcBasenames, String binRoot, String binBasename, boolean mutableStringBuilder)
ShaderCode object
either from source code using #create(GL2ES2, int, int, Class, String[]),
or from a binary code using create(int, int, Class, int, String),
whatever is available first.
The source and binary location names are expected w/o suffixes which are
resolved and appended using getFileSuffix(boolean, int).
Additionally, the binary resource is expected within a subfolder of binRoot
which reflects the vendor specific binary format, see getBinarySubPath(int).
All ShaderUtil.getShaderBinaryFormats(GL) are being iterated
using the binary subfolder, the first existing resource is being used.
Your std JVM layout (plain or within a JAR):
org/test/glsl/MyShaderTest.class
org/test/glsl/shader/vertex.vp
org/test/glsl/shader/fragment.fp
org/test/glsl/shader/bin/nvidia/vertex.bvp
org/test/glsl/shader/bin/nvidia/fragment.bfp
Your Android APK layout:
classes.dex
assets/org/test/glsl/shader/vertex.vp
assets/org/test/glsl/shader/fragment.fp
assets/org/test/glsl/shader/bin/nvidia/vertex.bvp
assets/org/test/glsl/shader/bin/nvidia/fragment.bfp
...
Your invocation in org/test/glsl/MyShaderTest.java:
ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, 1, this.getClass(),
"shader", new String[] { "vertex" }, "shader/bin", "vertex");
ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, 1, this.getClass(),
"shader", new String[] { "vertex" }, "shader/bin", "fragment");
ShaderProgram sp0 = new ShaderProgram();
sp0.add(gl, vp0, System.err);
sp0.add(gl, fp0, System.err);
st.attachShaderProgram(gl, sp0, true);
A simplified entry point is create(GL2ES2, int, Class, String, String, String, boolean).
The location is finally being resolved using the context class, see readShaderBinary(Class, String).
gl - current GL object to determine whether a shader compiler is available (if source is used),
or to determine the shader binary format (if binary is used).type - either GL2ES2.GL_VERTEX_SHADER, GL2ES2.GL_FRAGMENT_SHADER or GL3.GL_GEOMETRY_SHADERcount - number of shaderscontext - class used to help resolving the source and binary locationsrcRoot - relative root path for srcBasenames optionalsrcBasenames - basenames w/o path or suffix relative to srcRoot for the shader's source codebinRoot - relative root path for binBasenamesbinBasename - basename w/o path or suffix relative to binRoot for the shader's binary codemutableStringBuilder - if true method returns a mutable StringBuilder instance
which can be edited later on at the costs of a String conversion when passing to
GL2ES2.glShaderSource(int, int, String[], IntBuffer).
If false method returns an immutable String instance,
which can be passed to GL2ES2.glShaderSource(int, int, String[], IntBuffer)
at no additional costs.IllegalArgumentException - if count and srcBasenames.length do not match#create(GL2ES2, int, int, Class, String[]),
create(int, int, Class, int, String),
#readShaderSource(Class, String),
getFileSuffix(boolean, int),
ShaderUtil.getShaderBinaryFormats(GL),
getBinarySubPath(int)public static ShaderCode create(GL2ES2 gl, int type, Class<?> context, String srcRoot, String binRoot, String basename, boolean mutableStringBuilder)
#create(GL2ES2, int, int, Class, String, String[], String, String).
Your std JVM layout (plain or within a JAR):
org/test/glsl/MyShaderTest.class
org/test/glsl/shader/vertex.vp
org/test/glsl/shader/fragment.fp
org/test/glsl/shader/bin/nvidia/vertex.bvp
org/test/glsl/shader/bin/nvidia/fragment.bfp
Your Android APK layout:
classes.dex
assets/org/test/glsl/shader/vertex.vp
assets/org/test/glsl/shader/fragment.fp
assets/org/test/glsl/shader/bin/nvidia/vertex.bvp
assets/org/test/glsl/shader/bin/nvidia/fragment.bfp
...
Your invocation in org/test/glsl/MyShaderTest.java:
ShaderCode vp0 = ShaderCode.create(gl, GL2ES2.GL_VERTEX_SHADER, this.getClass(),
"shader", "shader/bin", "vertex");
ShaderCode fp0 = ShaderCode.create(gl, GL2ES2.GL_FRAGMENT_SHADER, this.getClass(),
"shader", "shader/bin", "fragment");
ShaderProgram sp0 = new ShaderProgram();
sp0.add(gl, vp0, System.err);
sp0.add(gl, fp0, System.err);
st.attachShaderProgram(gl, sp0, true);
gl - current GL object to determine whether a shader compiler is available (if source is used),
or to determine the shader binary format (if binary is used).type - either GL2ES2.GL_VERTEX_SHADER, GL2ES2.GL_FRAGMENT_SHADER or GL3.GL_GEOMETRY_SHADERcontext - class used to help resolving the source and binary locationsrcRoot - relative root path for basename optionalbinRoot - relative root path for basenamemutableStringBuilder - TODObasenames - basename w/o path or suffix relative to srcRoot and binRoot
for the shader's source and binary code.mutableStringBuilder - if true method returns a mutable StringBuilder instance
which can be edited later on at the costs of a String conversion when passing to
GL2ES2.glShaderSource(int, int, String[], IntBuffer).
If false method returns an immutable String instance,
which can be passed to GL2ES2.glShaderSource(int, int, String[], IntBuffer)
at no additional costs.IllegalArgumentException - if count is not 1#create(GL2ES2, int, int, Class, String, String[], String, String)public int id()
public int shaderType()
public String shaderTypeStr()
public static String shaderTypeStr(int type)
public int shaderBinaryFormat()
public Buffer shaderBinary()
public CharSequence[][] shaderSource()
public boolean isValid()
public IntBuffer shader()
public boolean compile(GL2ES2 gl)
public boolean compile(GL2ES2 gl, PrintStream verboseOut)
public void destroy(GL2ES2 gl)
public void dumpShaderSource(PrintStream out)
public int insertShaderSource(int shaderIdx,
String tag,
int fromIndex,
CharSequence data)
data after the line containing tag.
Note: The shader source to be edit must be created using a mutable StringBuilder.
shaderIdx - the shader index to be used.tag - search stringfromIndex - start search tag begininig with this indexdata - the text to be inserted. Shall end with an EOL '\n' character.dataIllegalStateException - if the shader source's CharSequence is immutable, i.e. not of type StringBuilderpublic int replaceInShaderSource(String oldName, String newName)
oldName with newName in all shader sources.
In case oldName and newName are equal, no action is performed.
Note: The shader source to be edit must be created using a mutable StringBuilder.
oldName - the to be replace stringnewName - the replacement stringIllegalStateException - if the shader source's CharSequence is immutable, i.e. not of type StringBuilderpublic int insertShaderSource(int shaderIdx,
int position,
CharSequence data)
data at position in shader source for shader shaderIdx.
Note: The shader source to be edit must be created using a mutable StringBuilder.
shaderIdx - the shader index to be used.position - in shader source segments of shader shaderIdx, -1 will append datadata - the text to be inserted. Shall end with an EOL '\n' characterdataIllegalStateException - if the shader source's CharSequence is immutable, i.e. not of type StringBuilderpublic int insertShaderSource(int shaderIdx,
int position,
Class<?> context,
String path)
throws IOException
path,
either relative to the context class or absolute as-is
at position in shader source for shader shaderIdx.
Final location lookup is performed via ClassLoader.getResource(String) and ClassLoader.getSystemResource(String),
see IOUtil.getResource(Class, String).
Note: The shader source to be edit must be created using a mutable StringBuilder.
shaderIdx - the shader index to be used.position - in shader source segments of shader shaderIdx, -1 will append datacontext - class used to help resolve the source locationpath - location of shader sourceIOExceptionIllegalStateException - if the shader source's CharSequence is immutable, i.e. not of type StringBuilderIOUtil.getResource(Class, String)public static void readShaderSource(Class<?> context, URLConnection conn, StringBuilder result) throws IOException
context - conn - result - IOExceptionpublic static CharSequence readShaderSource(Class<?> context, String path, boolean mutableStringBuilder) throws IOException
path,
either relative to the context class or absolute as-is.
Final location lookup is performed via ClassLoader.getResource(String) and ClassLoader.getSystemResource(String),
see IOUtil.getResource(Class, String).
context - class used to help resolve the source locationpath - location of shader sourcemutableStringBuilder - if true method returns a mutable StringBuilder instance
which can be edited later on at the costs of a String conversion when passing to
GL2ES2.glShaderSource(int, int, String[], IntBuffer).
If false method returns an immutable String instance,
which can be passed to GL2ES2.glShaderSource(int, int, String[], IntBuffer)
at no additional costs.IOExceptionIOUtil.getResource(Class, String)public static ByteBuffer readShaderBinary(Class<?> context, String path) throws IOException
path,
either relative to the context class or absolute as-is.
Final location lookup is perfomed via ClassLoader.getResource(String) and ClassLoader.getSystemResource(String),
see IOUtil.getResource(Class, String).
context - class used to help resolve the source locationpath - location of shader binaryIOExceptionIOUtil.getResource(Class, String)public static String createExtensionDirective(String extensionName, String behavior)
public final int addGLSLVersion(GL2ES2 gl)
Note: The shader source to be edit must be created using a mutable StringBuilder.
gl - a GL context, which must have been made current oncepublic final int addDefaultShaderPrecision(GL2ES2 gl, int pos)
es2_default_precision_vp, es2_default_precision_fp,
gl3_default_precision_vp_gp, gl3_default_precision_fp or none,
depending on the GLSL version being used.
Note: The shader source to be edit must be created using a mutable StringBuilder.
gl - a GL context, which must have been made current oncepos - position within this mutable shader source.public static final boolean requiresDefaultPrecision(GL2ES2 gl)
public static final boolean requiresGL3DefaultPrecision(GL2ES2 gl)
public final int defaultShaderCustomization(GL2ES2 gl, boolean preludeVersion, boolean addDefaultPrecision)
Note: The shader source to be edit must be created using a mutable StringBuilder.
gl - a GL context, which must have been made current oncepreludeVersion - if true GLContext.getGLSLVersionString() is preluded, otherwise not.addDefaultPrecision - if true default precision source code line(s) are added, i.e.
es2_default_precision_vp, es2_default_precision_fp,
gl3_default_precision_vp_gp, gl3_default_precision_fp or none,
depending on the GLSL version being used.addGLSLVersion(GL2ES2),
addDefaultShaderPrecision(GL2ES2, int)public final int defaultShaderCustomization(GL2ES2 gl, boolean preludeVersion, String esDefaultPrecision)
Note: The shader source to be edit must be created using a mutable StringBuilder.
gl - a GL context, which must have been made current oncepreludeVersion - if true GLContext.getGLSLVersionString() is preluded, otherwise not.esDefaultPrecision - optional default precision source code line(s) preluded if not null and if GLBase.isGLES().
You may use es2_default_precision_fp for fragment shader and es2_default_precision_vp for vertex shader.addGLSLVersion(GL2ES2),
addDefaultShaderPrecision(GL2ES2, int)Copyright 2010 JogAmp Community.