diff options
author | Michael Bien <[email protected]> | 2009-08-08 21:43:30 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2009-08-08 21:43:30 +0200 |
commit | 8ef9d7364a942c19ec5e1f306e08193e83f4fea6 (patch) | |
tree | 6dcf95825d2933992199a7062b15e38d3f721c95 /src/jogl/classes/com/sun/opengl/util | |
parent | 2a8e9876ca4567de3b08813c280d006f9b2c32e6 (diff) | |
parent | fb3e50b4e7e11df911a83ab7966cf8f293c20da2 (diff) |
Merge branch 'master' of ssh://[email protected]/jogl~jogl-git
Diffstat (limited to 'src/jogl/classes/com/sun/opengl/util')
6 files changed, 148 insertions, 77 deletions
diff --git a/src/jogl/classes/com/sun/opengl/util/GLArrayDataClient.java b/src/jogl/classes/com/sun/opengl/util/GLArrayDataClient.java index e05a77226..ec4c5e393 100644 --- a/src/jogl/classes/com/sun/opengl/util/GLArrayDataClient.java +++ b/src/jogl/classes/com/sun/opengl/util/GLArrayDataClient.java @@ -27,13 +27,13 @@ public class GLArrayDataClient extends GLArrayDataWrapper implements GLArrayData }) != null; /** - * @arg index The GL array index - * @arg name The optional custom name for the GL array index, maybe null. + * @param index The GL array index + * @param name The optional custom name for the GL array index, maybe null. * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'. * This name might be used as the shader attribute name. - * @arg comps The array component number - * @arg dataType The array index GL data type - * @arg normalized Wheather the data shall be normalized + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Wheather the data shall be normalized * * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) */ diff --git a/src/jogl/classes/com/sun/opengl/util/GLArrayDataServer.java b/src/jogl/classes/com/sun/opengl/util/GLArrayDataServer.java index e9a5e2754..dc233ce36 100644 --- a/src/jogl/classes/com/sun/opengl/util/GLArrayDataServer.java +++ b/src/jogl/classes/com/sun/opengl/util/GLArrayDataServer.java @@ -21,13 +21,13 @@ public class GLArrayDataServer extends GLArrayDataClient implements GLArrayDataE * EnableVertexAttribArray and VertexAttribPointer calls, * and a predefined vertex attribute variable name will be choosen. * - * @arg index The GL array index - * @arg name The optional custom name for the GL array index, maybe null. + * @param index The GL array index + * @param name The optional custom name for the GL array index, maybe null. * If null, the default name mapping will be used, see 'getPredefinedArrayIndexName(int)'. * This name might be used as the shader attribute name. - * @arg comps The array component number - * @arg dataType The array index GL data type - * @arg normalized Wheather the data shall be normalized + * @param comps The array component number + * @param dataType The array index GL data type + * @param normalized Wheather the data shall be normalized * * @see javax.media.opengl.GLContext#getPredefinedArrayIndexName(int) */ diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java index 6e7512e6a..606d2e1b5 100644 --- a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java @@ -3,13 +3,18 @@ package com.sun.opengl.util.glsl; import javax.media.opengl.*; import com.sun.opengl.util.*; +import com.sun.opengl.impl.Debug; import java.util.*; import java.nio.*; import java.io.*; import java.net.*; +import java.security.*; public class ShaderCode { + public static final boolean DEBUG = Debug.debug("GLSLCode"); + public static final boolean DEBUG_CODE = Debug.isPropertyDefined("jogl.debug.GLSLCode", true, AccessController.getContext()); + public static final String SUFFIX_VERTEX_SOURCE = "vp" ; public static final String SUFFIX_VERTEX_BINARY = "bvp" ; public static final String SUFFIX_FRAGMENT_SOURCE = "fp" ; @@ -31,6 +36,11 @@ public class ShaderCode { shaderType = type; shader = BufferUtil.newIntBuffer(number); id = getNextID(); + + if(DEBUG_CODE) { + System.out.println("Created: "+toString()); + dumpShaderSource(System.out); + } } public ShaderCode(int type, int number, int binFormat, Buffer binary) { @@ -134,61 +144,6 @@ public class ShaderCode { return res; } - public static boolean createAndLoadShader(GL2ES2 gl, IntBuffer shader, int shaderType, - int binFormat, java.nio.Buffer bin, - PrintStream verboseOut) - { - 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)); - } - - ShaderUtil.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)); - } - - - ShaderUtil.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; - } - - public static boolean createAndCompileShader(GL2ES2 gl, IntBuffer shader, int shaderType, - java.lang.String[][] sources, - PrintStream verboseOut) - { - 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)); - } - - ShaderUtil.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)); - } - - ShaderUtil.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)); - } - - ShaderUtil.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 ShaderUtil.isShaderStatusValid(gl, shader, gl.GL_COMPILE_STATUS, verboseOut) && err == GL.GL_NO_ERROR; - } - /** * returns the uniq shader id as an integer * @see #key() @@ -231,11 +186,11 @@ public class ShaderCode { // Create & Compile the vertex/fragment shader objects if(null!=shaderSource) { - valid=createAndCompileShader(gl, shader, shaderType, - shaderSource, verboseOut); + valid=ShaderUtil.createAndCompileShader(gl, shader, shaderType, + shaderSource, verboseOut); } else if(null!=shaderBinary) { - valid=createAndLoadShader(gl, shader, shaderType, - shaderBinaryFormat, shaderBinary, verboseOut); + valid=ShaderUtil.createAndLoadShader(gl, shader, shaderType, + shaderBinaryFormat, shaderBinary, verboseOut); } else { throw new GLException("no code (source or binary)"); } @@ -282,6 +237,31 @@ public class ShaderCode { return buf.toString(); } + public void dumpShaderSource(PrintStream out) { + if(null==shaderSource) { + out.println("<no shader source>"); + return; + } + int sourceNum = (null!=shaderSource)?shaderSource.length:0; + int shaderNum = (null!=shader)?shader.capacity():0; + for(int i=0; i<shaderNum; i++) { + out.println(""); + out.println("Shader #"+i+"/"+shaderNum+" name "+shader.get(i)); + out.println("--------------------------------------------------------------"); + if(i>=sourceNum) { + out.println("<no shader source>"); + } else { + String[] src = shaderSource[i]; + for(int j=0; j<src.length; j++) { + out.println("Segment "+j+"/"+src.length+" :"); + out.println(src[j]); + out.println(""); + } + } + out.println("--------------------------------------------------------------"); + } + } + public static void readShaderSource(ClassLoader context, String path, URL url, StringBuffer result) { try { BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java index bab9ef4f3..8712ac7e2 100644 --- a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java +++ b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderState.java @@ -3,14 +3,17 @@ package com.sun.opengl.util.glsl; import javax.media.opengl.*; import com.sun.opengl.util.*; +import com.sun.opengl.impl.Debug; import java.util.HashMap; import java.util.HashSet; import java.util.Iterator; import java.nio.*; import java.io.PrintStream; +import java.security.*; public class ShaderState { + public static final boolean DEBUG = Debug.isPropertyDefined("jogl.debug.GLSLState", true, AccessController.getContext()); public ShaderState() { } @@ -77,8 +80,10 @@ public class ShaderState { int curId = (null!=shaderProgram)?shaderProgram.id():-1; int newId = (null!=prog)?prog.id():-1; System.err.println("Info: attachShaderProgram: "+curId+" -> "+newId+"\n\t"+shaderProgram+"\n\t"+prog); - Throwable tX = new Throwable("Info: attachShaderProgram: Trace"); - tX.printStackTrace(); + if(verbose) { + Throwable tX = new Throwable("Info: attachShaderProgram: Trace"); + tX.printStackTrace(); + } } if(null!=shaderProgram) { if(shaderProgram.equals(prog)) { @@ -313,7 +318,7 @@ public class ShaderState { * Even if the attribute is not found in the current shader, * it is stored in this state. * - * @arg data the GLArrayData's name must match the attributes one, + * @param data the GLArrayData's name must match the attributes one, * it's index will be set with the attribute's location, * if found. * @@ -544,7 +549,7 @@ public class ShaderState { * Even if the uniform is not found in the current shader, * it is stored in this state. * - * @arg data the GLUniforms's name must match the uniform one, + * @param data the GLUniforms's name must match the uniform one, * it's index will be set with the uniforms's location, * if found. * @@ -635,7 +640,6 @@ public class ShaderState { return buf.toString(); } - protected static final boolean DEBUG = false; protected boolean verbose = false; protected ShaderProgram shaderProgram=null; protected HashMap attribMap2Idx = new HashMap(); diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java index d1bb8b32b..390fb27c7 100644 --- a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java +++ b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderUtil.java @@ -60,6 +60,14 @@ public class ShaderUtil { 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 { @@ -307,6 +315,64 @@ public class ShaderUtil { } } + + 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; + } + + 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, gl.GL_COMPILE_STATUS, verboseOut) && err == GL.GL_NO_ERROR; + } + } public static String getShaderInfoLog(GL gl, int shaderObj) { @@ -385,6 +451,18 @@ public class ShaderUtil { getImpl(gl).deleteShader(gl, shaders); } + 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); + } + + 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); + } + private static Impl getImpl(GL _gl) { GL2ES2 gl = _gl.getGL2ES2(); GLContext context = gl.getContext(); diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java index 9c8a65173..4149aec69 100644 --- a/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java +++ b/src/jogl/classes/com/sun/opengl/util/glsl/fixedfunc/FixedFuncUtil.java @@ -14,12 +14,12 @@ import com.sun.opengl.util.glsl.fixedfunc.impl.*; */ public class FixedFuncUtil { /** - * @return If gl is a GL2ES1, return the type cast object, + * @return If gl is a GL2ES1 and force is false, return the type cast object, * otherwise create a fixed function emulation pipeline with the GL2ES2 impl. * @throws GLException if the GL object is neither GL2ES1 nor GL2ES2 */ - public static final GL2ES1 getFixedFuncImpl(GL gl) { - if(gl.isGL2ES1()) { + public static final GL2ES1 getFixedFuncImpl(GL gl, boolean force) { + if(!force && gl.isGL2ES1()) { return gl.getGL2ES1(); } else if(gl.isGL2ES2()) { GL2ES2 es2 = gl.getGL2ES2(); @@ -32,6 +32,15 @@ public class FixedFuncUtil { } /** + * @return If gl is a GL2ES1, return the type cast object, + * otherwise create a fixed function emulation pipeline with the GL2ES2 impl. + * @throws GLException if the GL object is neither GL2ES1 nor GL2ES2 + */ + public static final GL2ES1 getFixedFuncImpl(GL gl) { + return getFixedFuncImpl(gl, false); + } + + /** * Mapping fixed function (client) array indices to * GLSL array attribute names. * |