summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/util
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2012-04-09 06:04:25 +0200
committerSven Gothel <[email protected]>2012-04-09 06:04:25 +0200
commit00390c099a9683b0dc1c822ba29853658004a671 (patch)
tree49e03e3a85ff908041b04f7c0a9179b3f4370575 /src/jogl/classes/com/jogamp/opengl/util
parentca14c6b3d5e53f6eda31ab6112b6b1705c5b31e5 (diff)
ShaderUtil: Remove 'Impl' redirection, we already have GL OO hierarchy.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java602
1 files changed, 246 insertions, 356 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java
index bd4ba45c4..d8aa1aa7f 100644
--- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java
+++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderUtil.java
@@ -42,431 +42,321 @@ import javax.media.opengl.*;
import com.jogamp.common.nio.Buffers;
public class ShaderUtil {
- static abstract class Impl {
- public abstract String getShaderInfoLog(GL gl, int shaderObj);
- public abstract String getProgramInfoLog(GL gl, int programObj);
- public abstract boolean isShaderStatusValid(GL gl, int shaderObj, int name, PrintStream verboseOut);
- public abstract boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name, PrintStream verboseOut);
- public abstract boolean isProgramStatusValid(GL gl, int programObj, int name);
- public abstract boolean isProgramLinkStatusValid(GL gl, int programObj, PrintStream verboseOut);
- public abstract boolean isProgramExecStatusValid(GL gl, int programObj, PrintStream verboseOut);
- public abstract void createShader(GL gl, int type, IntBuffer shaders);
- public abstract Set<Integer> getShaderBinaryFormats(GL gl);
- public abstract boolean isShaderCompilerAvailable(GL gl);
- public abstract void shaderSource(GL gl, int shader, java.lang.String[] source);
- public abstract void shaderSource(GL gl, IntBuffer shaders, java.lang.String[][] sources);
- public abstract void shaderBinary(GL gl, IntBuffer shaders, int binFormat, java.nio.Buffer bin);
- public abstract void compileShader(GL gl, IntBuffer shaders);
- public abstract void attachShader(GL gl, int program, IntBuffer shaders);
- public abstract void detachShader(GL gl, int program, IntBuffer shaders);
- public abstract void deleteShader(GL gl, IntBuffer shaders);
-
- public abstract boolean createAndLoadShader(GL gl, IntBuffer shader, int shaderType,
- int binFormat, java.nio.Buffer bin,
- PrintStream verboseOut);
-
- public abstract boolean createAndCompileShader(GL gl, IntBuffer shader, int shaderType,
- java.lang.String[][] sources,
- PrintStream verboseOut);
- }
-
- static class GL2ES2Impl extends Impl {
- public String getShaderInfoLog(GL _gl, int shaderObj) {
- GL2ES2 gl = _gl.getGL2ES2();
- int[] infoLogLength=new int[1];
- gl.glGetShaderiv(shaderObj, GL2ES2.GL_INFO_LOG_LENGTH, infoLogLength, 0);
+ public static String getShaderInfoLog(GL _gl, int shaderObj) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ int[] infoLogLength=new int[1];
+ gl.glGetShaderiv(shaderObj, GL2ES2.GL_INFO_LOG_LENGTH, infoLogLength, 0);
- if(infoLogLength[0]==0) {
- return "(no info log)";
- }
- int[] charsWritten=new int[1];
- byte[] infoLogBytes = new byte[infoLogLength[0]];
- gl.glGetShaderInfoLog(shaderObj, infoLogLength[0], charsWritten, 0, infoLogBytes, 0);
-
- return new String(infoLogBytes, 0, charsWritten[0]);
+ if(infoLogLength[0]==0) {
+ return "(no info log)";
}
+ int[] charsWritten=new int[1];
+ byte[] infoLogBytes = new byte[infoLogLength[0]];
+ gl.glGetShaderInfoLog(shaderObj, infoLogLength[0], charsWritten, 0, infoLogBytes, 0);
- public String getProgramInfoLog(GL _gl, int programObj) {
- GL2ES2 gl = _gl.getGL2ES2();
- int[] infoLogLength=new int[1];
- gl.glGetProgramiv(programObj, GL2ES2.GL_INFO_LOG_LENGTH, infoLogLength, 0);
+ return new String(infoLogBytes, 0, charsWritten[0]);
+ }
- if(infoLogLength[0]==0) {
- return "(no info log)";
- }
- int[] charsWritten=new int[1];
- byte[] infoLogBytes = new byte[infoLogLength[0]];
- gl.glGetProgramInfoLog(programObj, infoLogLength[0], charsWritten, 0, infoLogBytes, 0);
+ public static String getProgramInfoLog(GL _gl, int programObj) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ int[] infoLogLength=new int[1];
+ gl.glGetProgramiv(programObj, GL2ES2.GL_INFO_LOG_LENGTH, infoLogLength, 0);
- return new String(infoLogBytes, 0, charsWritten[0]);
+ if(infoLogLength[0]==0) {
+ return "(no info log)";
}
+ int[] charsWritten=new int[1];
+ byte[] infoLogBytes = new byte[infoLogLength[0]];
+ gl.glGetProgramInfoLog(programObj, infoLogLength[0], charsWritten, 0, infoLogBytes, 0);
+
+ return new String(infoLogBytes, 0, charsWritten[0]);
+ }
- public boolean isShaderStatusValid(GL _gl, int shaderObj, int name, PrintStream verboseOut) {
- GL2ES2 gl = _gl.getGL2ES2();
- int[] ires = new int[1];
- gl.glGetShaderiv(shaderObj, name, ires, 0);
+ public static boolean isShaderStatusValid(GL _gl, int shaderObj, int name, PrintStream verboseOut) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ int[] ires = new int[1];
+ gl.glGetShaderiv(shaderObj, name, ires, 0);
- boolean res = ires[0]==1;
- if(!res && null!=verboseOut) {
- verboseOut.println("Shader status invalid: "+ getShaderInfoLog(gl, shaderObj));
- }
- return res;
+ boolean res = ires[0]==1;
+ if(!res && null!=verboseOut) {
+ verboseOut.println("Shader status invalid: "+ getShaderInfoLog(gl, shaderObj));
}
+ return res;
+ }
- public boolean isShaderStatusValid(GL _gl, IntBuffer shaders, int name, PrintStream verboseOut) {
- boolean res = true;
- for (int i = shaders.position(); i < shaders.limit(); i++) {
- res = isShaderStatusValid(_gl, shaders.get(i), name, verboseOut) && res;
- }
- return res;
+ public static boolean isShaderStatusValid(GL _gl, IntBuffer shaders, int name, PrintStream verboseOut) {
+ boolean res = true;
+ for (int i = shaders.position(); i < shaders.limit(); i++) {
+ res = isShaderStatusValid(_gl, shaders.get(i), name, verboseOut) && res;
}
+ return res;
+ }
- public boolean isProgramStatusValid(GL _gl, int programObj, int name) {
- GL2ES2 gl = _gl.getGL2ES2();
- int[] ires = new int[1];
- gl.glGetProgramiv(programObj, name, ires, 0);
+ public static boolean isProgramStatusValid(GL _gl, int programObj, int name) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ int[] ires = new int[1];
+ gl.glGetProgramiv(programObj, name, ires, 0);
- return ires[0]==1;
- }
+ return ires[0]==1;
+ }
- public boolean isProgramLinkStatusValid(GL _gl, int programObj, PrintStream verboseOut) {
- GL2ES2 gl = _gl.getGL2ES2();
- if(!gl.glIsProgram(programObj)) {
- if(null!=verboseOut) {
- verboseOut.println("Program name invalid: "+programObj);
- }
- return false;
+ public static boolean isProgramLinkStatusValid(GL _gl, int programObj, PrintStream verboseOut) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ if(!gl.glIsProgram(programObj)) {
+ if(null!=verboseOut) {
+ verboseOut.println("Program name invalid: "+programObj);
}
- if(!isProgramStatusValid(gl, programObj, GL2ES2.GL_LINK_STATUS)) {
- if(null!=verboseOut) {
- verboseOut.println("Program link failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj));
- }
- return false;
+ return false;
+ }
+ if(!isProgramStatusValid(gl, programObj, GL2ES2.GL_LINK_STATUS)) {
+ if(null!=verboseOut) {
+ verboseOut.println("Program link failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj));
}
- return true;
+ return false;
}
-
- public boolean isProgramExecStatusValid(GL _gl, int programObj, PrintStream verboseOut) {
- GL2ES2 gl = _gl.getGL2ES2();
- gl.glValidateProgram(programObj);
- if(!isProgramStatusValid(gl, programObj, GL2ES2.GL_VALIDATE_STATUS)) {
- if(null!=verboseOut) {
- verboseOut.println("Program validation failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj));
- }
- return false;
+ return true;
+ }
+
+ /**
+ * Performs {@link GL2ES2#glValidateProgram(int)}
+ * <p>
+ * One shall only call this method while debugging and only if all required
+ * resources by the shader are set.
+ * </p>
+ * <p>
+ * Note: It is possible that a working shader program will fail validation.
+ * This has been experienced on NVidia APX2500 and Tegra2.
+ * </p>
+ * @see GL2ES2#glValidateProgram(int)
+ **/
+ public static boolean isProgramExecStatusValid(GL _gl, int programObj, PrintStream verboseOut) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ gl.glValidateProgram(programObj);
+ if(!isProgramStatusValid(gl, programObj, GL2ES2.GL_VALIDATE_STATUS)) {
+ if(null!=verboseOut) {
+ verboseOut.println("Program validation failed: "+programObj+"\n\t"+ getProgramInfoLog(gl, programObj));
}
- return true;
+ return false;
}
+ return true;
+ }
- public void createShader(GL _gl, int type, IntBuffer shaders) {
- GL2ES2 gl = _gl.getGL2ES2();
- for (int i = shaders.position(); i < shaders.limit(); i++) {
- shaders.put(i, gl.glCreateShader(type));
- }
+ public static void createShader(GL _gl, int type, IntBuffer shaders) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ for (int i = shaders.position(); i < shaders.limit(); i++) {
+ shaders.put(i, gl.glCreateShader(type));
}
+ }
- private Boolean shaderCompilerAvailable = null;
- private Set<Integer> shaderBinaryFormats = null;
-
- public Set<Integer> getShaderBinaryFormats(GL _gl) {
- GL2ES2 gl = _gl.getGL2ES2();
- if(null==shaderBinaryFormats) {
- gl.getContext().validateCurrent();
-
- int[] param = new int[1];
- shaderBinaryFormats = new HashSet<Integer>();
-
- if (gl.isGLES2Compatible()) {
- gl.glGetIntegerv(GL2ES2.GL_NUM_SHADER_BINARY_FORMATS, param, 0);
- int numFormats = param[0];
- if(numFormats>0) {
- int[] formats = new int[numFormats];
- gl.glGetIntegerv(GL2ES2.GL_SHADER_BINARY_FORMATS, formats, 0);
- for(int i=0; i<numFormats; i++) {
- shaderBinaryFormats.add(new Integer(formats[i]));
- }
+ /**
+ * If supported, queries the natively supported shader binary formats using
+ * {@link GL2ES2#GL_NUM_SHADER_BINARY_FORMATS} and {@link GL2ES2#GL_SHADER_BINARY_FORMATS}
+ * via {@link GL2ES2#glGetIntegerv(int, int[], int)}.
+ */
+ public static Set<Integer> getShaderBinaryFormats(GL _gl) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ final ProfileInformation info = getProfileInformation(gl);
+ if(null == info.shaderBinaryFormats) {
+ info.shaderBinaryFormats = new HashSet<Integer>();
+ if (gl.isGLES2Compatible()) {
+ final int[] param = new int[1];
+ gl.glGetIntegerv(GL2ES2.GL_NUM_SHADER_BINARY_FORMATS, param, 0);
+ int numFormats = param[0];
+ if(numFormats>0) {
+ int[] formats = new int[numFormats];
+ gl.glGetIntegerv(GL2ES2.GL_SHADER_BINARY_FORMATS, formats, 0);
+ for(int i=0; i<numFormats; i++) {
+ info.shaderBinaryFormats.add(new Integer(formats[i]));
}
}
}
- return shaderBinaryFormats;
}
+ return info.shaderBinaryFormats;
+ }
-
- public boolean isShaderCompilerAvailable(GL _gl) {
- GL2ES2 gl = _gl.getGL2ES2();
- if(null==shaderCompilerAvailable) {
- gl.getContext().validateCurrent();
- Set<Integer> bfs = getShaderBinaryFormats(gl);
- if(gl.isGLES2()) {
- byte[] param = new byte[1];
- gl.glGetBooleanv(GL2ES2.GL_SHADER_COMPILER, param, 0);
- boolean v = param[0]!=(byte)0x00;
- if(!v && bfs.size()==0) {
+ /** Returns true if a hader compiler is available, otherwise false. */
+ public static boolean isShaderCompilerAvailable(GL _gl) {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ final ProfileInformation info = getProfileInformation(gl);
+ if(null==info.shaderCompilerAvailable) {
+ if(gl.isGLES2()) {
+ final byte[] param = new byte[1];
+ gl.glGetBooleanv(GL2ES2.GL_SHADER_COMPILER, param, 0);
+ boolean v = param[0]!=(byte)0x00;
+ if(!v) {
+ final Set<Integer> bfs = getShaderBinaryFormats(gl);
+ if(bfs.size()==0) {
// no supported binary formats, hence a compiler must be available!
v = true;
}
- shaderCompilerAvailable = new Boolean(v);
- } else if( gl.isGL2ES2() ) {
- shaderCompilerAvailable = new Boolean(true);
- } else {
- throw new GLException("Invalid OpenGL profile");
}
+ info.shaderCompilerAvailable = new Boolean(v);
+ } else if( gl.isGL2ES2() ) {
+ info.shaderCompilerAvailable = new Boolean(true);
+ } else {
+ throw new GLException("Invalid OpenGL profile");
}
- return shaderCompilerAvailable.booleanValue();
}
+ return info.shaderCompilerAvailable.booleanValue();
+ }
- public void shaderSource(GL _gl, int shader, java.lang.String[] source)
- {
- GL2ES2 gl = _gl.getGL2ES2();
- if(!isShaderCompilerAvailable(_gl)) {
- throw new GLException("No compiler is available");
- }
-
- int count = (null!=source)?source.length:0;
- if(count==0) {
- throw new GLException("No sources specified");
- }
-
- IntBuffer lengths = Buffers.newDirectIntBuffer(count);
- for(int i=0; i<count; i++) {
- lengths.put(i, source[i].length());
- }
- gl.glShaderSource(shader, count, source, lengths);
+ public static void shaderSource(GL _gl, int shader, java.lang.String[] source)
+ {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ if(!isShaderCompilerAvailable(_gl)) {
+ throw new GLException("No compiler is available");
}
- public void shaderSource(GL _gl, IntBuffer shaders, java.lang.String[][] sources)
- {
- int sourceNum = (null!=sources)?sources.length:0;
- int shaderNum = (null!=shaders)?shaders.remaining():0;
- if(shaderNum<=0 || sourceNum<=0 || shaderNum!=sourceNum) {
- throw new GLException("Invalid number of shaders and/or sources: shaders="+
- shaderNum+", sources="+sourceNum);
- }
- for(int i=0; i<sourceNum; i++) {
- shaderSource(_gl, shaders.get(shaders.position() + i), sources[i]);
- }
+ int count = (null!=source)?source.length:0;
+ if(count==0) {
+ throw new GLException("No sources specified");
}
- public void shaderBinary(GL _gl, IntBuffer shaders, int binFormat, java.nio.Buffer bin)
- {
- GL2ES2 gl = _gl.getGL2ES2();
- if(getShaderBinaryFormats(gl).size()<=0) {
- throw new GLException("No binary formats are supported");
- }
-
- int shaderNum = shaders.remaining();
- if(shaderNum<=0) {
- throw new GLException("No shaders specified");
- }
- if(null==bin) {
- throw new GLException("Null shader binary");
- }
- int binLength = bin.remaining();
- if(0>=binLength) {
- throw new GLException("Empty shader binary (remaining == 0)");
- }
- gl.glShaderBinary(shaderNum, shaders, binFormat, bin, binLength);
+ IntBuffer lengths = Buffers.newDirectIntBuffer(count);
+ for(int i=0; i<count; i++) {
+ lengths.put(i, source[i].length());
}
+ gl.glShaderSource(shader, count, source, lengths);
+ }
- public void compileShader(GL _gl, IntBuffer shaders)
- {
- GL2ES2 gl = _gl.getGL2ES2();
- for (int i = shaders.position(); i < shaders.limit(); i++) {
- gl.glCompileShader(shaders.get(i));
- }
+ public static void shaderSource(GL _gl, IntBuffer shaders, java.lang.String[][] sources)
+ {
+ int sourceNum = (null!=sources)?sources.length:0;
+ int shaderNum = (null!=shaders)?shaders.remaining():0;
+ if(shaderNum<=0 || sourceNum<=0 || shaderNum!=sourceNum) {
+ throw new GLException("Invalid number of shaders and/or sources: shaders="+
+ shaderNum+", sources="+sourceNum);
}
-
- public void attachShader(GL _gl, int program, IntBuffer shaders)
- {
- GL2ES2 gl = _gl.getGL2ES2();
- for (int i = shaders.position(); i < shaders.limit(); i++) {
- gl.glAttachShader(program, shaders.get(i));
- }
+ for(int i=0; i<sourceNum; i++) {
+ shaderSource(_gl, shaders.get(shaders.position() + i), sources[i]);
}
+ }
- public void detachShader(GL _gl, int program, IntBuffer shaders)
- {
- GL2ES2 gl = _gl.getGL2ES2();
- for (int i = shaders.position(); i < shaders.limit(); i++) {
- gl.glDetachShader(program, shaders.get(i));
- }
+ public static void shaderBinary(GL _gl, IntBuffer shaders, int binFormat, java.nio.Buffer bin)
+ {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ if(getShaderBinaryFormats(gl).size()<=0) {
+ throw new GLException("No binary formats are supported");
}
- public void deleteShader(GL _gl, IntBuffer shaders)
- {
- GL2ES2 gl = _gl.getGL2ES2();
- for (int i = shaders.position(); i < shaders.limit(); i++) {
- gl.glDeleteShader(shaders.get(i));
-
- }
+ int shaderNum = shaders.remaining();
+ if(shaderNum<=0) {
+ throw new GLException("No shaders specified");
}
-
- public boolean createAndLoadShader(GL _gl, IntBuffer shader, int shaderType,
- int binFormat, java.nio.Buffer bin,
- PrintStream verboseOut)
- {
- GL2ES2 gl = _gl.getGL2ES2();
- int err = gl.glGetError(); // flush previous errors ..
- if(err!=GL.GL_NO_ERROR && null!=verboseOut) {
- verboseOut.println("createAndLoadShader: Pre GL Error: 0x"+Integer.toHexString(err));
- }
-
- createShader(gl, shaderType, shader);
- err = gl.glGetError();
- if(err!=GL.GL_NO_ERROR) {
- throw new GLException("createAndLoadShader: CreateShader failed, GL Error: 0x"+Integer.toHexString(err));
- }
-
- shaderBinary(gl, shader, binFormat, bin);
-
- err = gl.glGetError();
- if(err!=GL.GL_NO_ERROR && null!=verboseOut) {
- verboseOut.println("createAndLoadShader: ShaderBinary failed, GL Error: 0x"+Integer.toHexString(err));
- }
- return err == GL.GL_NO_ERROR;
+ if(null==bin) {
+ throw new GLException("Null shader binary");
}
-
- public boolean createAndCompileShader(GL _gl, IntBuffer shader, int shaderType,
- java.lang.String[][] sources,
- PrintStream verboseOut)
- {
- GL2ES2 gl = _gl.getGL2ES2();
- int err = gl.glGetError(); // flush previous errors ..
- if(err!=GL.GL_NO_ERROR && null!=verboseOut) {
- verboseOut.println("createAndCompileShader: Pre GL Error: 0x"+Integer.toHexString(err));
- }
-
- createShader(gl, shaderType, shader);
- err = gl.glGetError();
- if(err!=GL.GL_NO_ERROR) {
- throw new GLException("createAndCompileShader: CreateShader failed, GL Error: 0x"+Integer.toHexString(err));
- }
-
- shaderSource(gl, shader, sources);
- err = gl.glGetError();
- if(err!=GL.GL_NO_ERROR) {
- throw new GLException("createAndCompileShader: ShaderSource failed, GL Error: 0x"+Integer.toHexString(err));
- }
-
- compileShader(gl, shader);
- err = gl.glGetError();
- if(err!=GL.GL_NO_ERROR && null!=verboseOut) {
- verboseOut.println("createAndCompileShader: CompileShader failed, GL Error: 0x"+Integer.toHexString(err));
- }
-
- return isShaderStatusValid(gl, shader, GL2ES2.GL_COMPILE_STATUS, verboseOut) && err == GL.GL_NO_ERROR;
+ int binLength = bin.remaining();
+ if(0>=binLength) {
+ throw new GLException("Empty shader binary (remaining == 0)");
}
-
+ gl.glShaderBinary(shaderNum, shaders, binFormat, bin, binLength);
}
- public static String getShaderInfoLog(GL gl, int shaderObj) {
- return getImpl(gl).getShaderInfoLog(gl, shaderObj);
- }
-
- public static String getProgramInfoLog(GL gl, int programObj) {
- return getImpl(gl).getProgramInfoLog(gl, programObj);
- }
-
- public static boolean isShaderStatusValid(GL gl, int shaderObj, int name, PrintStream verboseOut) {
- return getImpl(gl).isShaderStatusValid(gl, shaderObj, name, verboseOut);
- }
-
- public static boolean isShaderStatusValid(GL gl, IntBuffer shaders, int name, PrintStream verboseOut) {
- return getImpl(gl).isShaderStatusValid(gl, shaders, name, verboseOut);
- }
-
- public static boolean isProgramStatusValid(GL gl, int programObj, int name) {
- return getImpl(gl).isProgramStatusValid(gl, programObj, name);
+ public static void compileShader(GL _gl, IntBuffer shaders)
+ {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ for (int i = shaders.position(); i < shaders.limit(); i++) {
+ gl.glCompileShader(shaders.get(i));
+ }
}
- public static boolean isProgramLinkStatusValid(GL gl, int programObj, PrintStream verboseOut) {
- return getImpl(gl).isProgramLinkStatusValid(gl, programObj, verboseOut);
- }
-
- /**
- * Performs {@link GL2ES2#glValidateProgram(int)}
- * <p>
- * One shall only call this method while debugging and only if all required
- * resources by the shader are set.
- * </p>
- * <p>
- * Note: It is possible that a working shader program will fail validation.
- * This has been experienced on NVidia APX2500 and Tegra2.
- * </p>
- * @see GL2ES2#glValidateProgram(int)
- **/
- public static boolean isProgramExecStatusValid(GL gl, int programObj, PrintStream verboseOut) {
- return getImpl(gl).isProgramExecStatusValid(gl, programObj, verboseOut);
+ public static void attachShader(GL _gl, int program, IntBuffer shaders)
+ {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ for (int i = shaders.position(); i < shaders.limit(); i++) {
+ gl.glAttachShader(program, shaders.get(i));
+ }
}
- public static void createShader(GL gl, int type, IntBuffer shaders) {
- getImpl(gl).createShader(gl, type, shaders);
+ public static void detachShader(GL _gl, int program, IntBuffer shaders)
+ {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ for (int i = shaders.position(); i < shaders.limit(); i++) {
+ gl.glDetachShader(program, shaders.get(i));
+ }
}
+ public static void deleteShader(GL _gl, IntBuffer shaders)
+ {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ for (int i = shaders.position(); i < shaders.limit(); i++) {
+ gl.glDeleteShader(shaders.get(i));
- /**
- * If supported, queries the natively supported shader binary formats using
- * {@link GL2ES2#GL_NUM_SHADER_BINARY_FORMATS} and {@link GL2ES2#GL_SHADER_BINARY_FORMATS}
- * via {@link GL2ES2#glGetIntegerv(int, int[], int)}.
- */
- public static Set<Integer> getShaderBinaryFormats(GL gl) {
- return getImpl(gl).getShaderBinaryFormats(gl);
- }
-
- /** Returns true if a hader compiler is available, otherwise false. */
- public static boolean isShaderCompilerAvailable(GL gl) {
- return getImpl(gl).isShaderCompilerAvailable(gl);
+ }
}
- public static void shaderSource(GL gl, int shader, java.lang.String[] source) {
- getImpl(gl).shaderSource(gl, shader, source);
- }
+ public static boolean createAndLoadShader(GL _gl, IntBuffer shader, int shaderType,
+ int binFormat, java.nio.Buffer bin,
+ PrintStream verboseOut)
+ {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ int err = gl.glGetError(); // flush previous errors ..
+ if(err!=GL.GL_NO_ERROR && null!=verboseOut) {
+ verboseOut.println("createAndLoadShader: Pre GL Error: 0x"+Integer.toHexString(err));
+ }
- public static void shaderSource(GL gl, IntBuffer shaders, java.lang.String[][] sources) {
- getImpl(gl).shaderSource(gl, shaders, sources);
- }
+ createShader(gl, shaderType, shader);
+ err = gl.glGetError();
+ if(err!=GL.GL_NO_ERROR) {
+ throw new GLException("createAndLoadShader: CreateShader failed, GL Error: 0x"+Integer.toHexString(err));
+ }
- public static void shaderBinary(GL gl, IntBuffer shaders, int binFormat, java.nio.Buffer bin) {
- getImpl(gl).shaderBinary(gl, shaders, binFormat, bin);
- }
+ shaderBinary(gl, shader, binFormat, bin);
- public static void compileShader(GL gl, IntBuffer shaders) {
- getImpl(gl).compileShader(gl, shaders);
+ err = gl.glGetError();
+ if(err!=GL.GL_NO_ERROR && null!=verboseOut) {
+ verboseOut.println("createAndLoadShader: ShaderBinary failed, GL Error: 0x"+Integer.toHexString(err));
+ }
+ return err == GL.GL_NO_ERROR;
}
- public static void attachShader(GL gl, int program, IntBuffer shaders) {
- getImpl(gl).attachShader(gl, program, shaders);
- }
+ public static boolean createAndCompileShader(GL _gl, IntBuffer shader, int shaderType,
+ java.lang.String[][] sources,
+ PrintStream verboseOut)
+ {
+ final GL2ES2 gl = _gl.getGL2ES2();
+ int err = gl.glGetError(); // flush previous errors ..
+ if(err!=GL.GL_NO_ERROR && null!=verboseOut) {
+ verboseOut.println("createAndCompileShader: Pre GL Error: 0x"+Integer.toHexString(err));
+ }
- public static void detachShader(GL gl, int program, IntBuffer shaders) {
- getImpl(gl).detachShader(gl, program, shaders);
- }
+ createShader(gl, shaderType, shader);
+ err = gl.glGetError();
+ if(err!=GL.GL_NO_ERROR) {
+ throw new GLException("createAndCompileShader: CreateShader failed, GL Error: 0x"+Integer.toHexString(err));
+ }
- public static void deleteShader(GL gl, IntBuffer shaders) {
- getImpl(gl).deleteShader(gl, shaders);
- }
+ shaderSource(gl, shader, sources);
+ err = gl.glGetError();
+ if(err!=GL.GL_NO_ERROR) {
+ throw new GLException("createAndCompileShader: ShaderSource failed, GL Error: 0x"+Integer.toHexString(err));
+ }
- public static boolean createAndLoadShader(GL gl, IntBuffer shader, int shaderType,
- int binFormat, java.nio.Buffer bin,
- PrintStream verboseOut) {
- return getImpl(gl).createAndLoadShader(gl, shader, shaderType, binFormat, bin, verboseOut);
- }
+ compileShader(gl, shader);
+ err = gl.glGetError();
+ if(err!=GL.GL_NO_ERROR && null!=verboseOut) {
+ verboseOut.println("createAndCompileShader: CompileShader failed, GL Error: 0x"+Integer.toHexString(err));
+ }
- public static boolean createAndCompileShader(GL gl, IntBuffer shader, int shaderType,
- java.lang.String[][] sources,
- PrintStream verboseOut) {
- return getImpl(gl).createAndCompileShader(gl, shader, shaderType, sources, verboseOut);
+ return isShaderStatusValid(gl, shader, GL2ES2.GL_COMPILE_STATUS, verboseOut) && err == GL.GL_NO_ERROR;
}
-
- private static Impl getImpl(GL _gl) {
- GL2ES2 gl = _gl.getGL2ES2();
- GLContext context = gl.getContext();
- Impl impl = (Impl) context.getAttachedObject(implObjectKey);
- if (impl == null) {
- impl = new GL2ES2Impl();
- context.attachObject(implObjectKey, impl);
+
+ private static final String implObjectKey = "com.jogamp.opengl.util.glsl.ShaderUtil" ;
+
+ private static class ProfileInformation {
+ Boolean shaderCompilerAvailable = null;
+ Set<Integer> shaderBinaryFormats = null;
+ }
+
+ private static ProfileInformation getProfileInformation(GL gl) {
+ final GLContext context = gl.getContext();
+ context.validateCurrent();
+ ProfileInformation data = (ProfileInformation) context.getAttachedObject(implObjectKey);
+ if (data == null) {
+ data = new ProfileInformation();
+ context.attachObject(implObjectKey, data);
}
- return impl;
+ return data;
}
- private static final String implObjectKey = "jogamp.opengl.glsl.ShaderUtilImpl" ;
}