From be3d7e5c1cf5d4d0342da36c3ab3eae91da51ec1 Mon Sep 17 00:00:00 2001 From: Kenneth Russel Date: Fri, 22 May 2009 22:21:29 +0000 Subject: Refactored shader-related utility routines from core GL2ES2 class into ShaderUtil class. Added GLContext.getAttachedObject(String) and putAttachedObject(String, Object) to allow arbitrarily named objects to be attached to GLContext. Removed explicitly defined toString() operations on GL implementations which were problematic and which would have required downward references into com.sun.opengl.util.glsl package after this refactoring. git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1909 232f8b59-042b-4e1e-8c03-345bb8c30851 --- .../classes/com/sun/opengl/util/glsl/ShaderCode.java | 20 ++++++++++---------- .../com/sun/opengl/util/glsl/ShaderProgram.java | 12 ++++++------ 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'src/jogl/classes/com/sun/opengl') 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 cba5f91b3..6e7512e6a 100644 --- a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderCode.java @@ -50,7 +50,7 @@ public class ShaderCode { } public static ShaderCode create(GL2ES2 gl, int type, int number, Class context, String[] sourceFiles) { - if(!gl.glShaderCompilerAvailable()) return null; + if(!ShaderUtil.isShaderCompilerAvailable(gl)) return null; String[][] shaderSources = null; if(null!=sourceFiles) { @@ -108,7 +108,7 @@ public class ShaderCode { String srcFileName = null; String binFileName = null; - if(gl.glShaderCompilerAvailable()) { + if(ShaderUtil.isShaderCompilerAvailable(gl)) { String srcPath[] = new String[1]; srcFileName = srcRoot + '/' + basename + "." + getFileSuffix(false, type); srcPath[0] = srcFileName; @@ -117,7 +117,7 @@ public class ShaderCode { return res; } } - Set binFmts = gl.glGetShaderBinaryFormats(); + Set binFmts = ShaderUtil.getShaderBinaryFormats(gl); for(Iterator iter=binFmts.iterator(); null==res && iter.hasNext(); ) { int bFmt = ((Integer)(iter.next())).intValue(); String bFmtPath = getBinarySubPath(bFmt); @@ -143,14 +143,14 @@ public class ShaderCode { verboseOut.println("createAndLoadShader: Pre GL Error: 0x"+Integer.toHexString(err)); } - gl.glCreateShader(shaderType, shader); + 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)); } - gl.glShaderBinary(shader, binFormat, bin); + ShaderUtil.shaderBinary(gl, shader, binFormat, bin); err = gl.glGetError(); if(err!=GL.GL_NO_ERROR && null!=verboseOut) { @@ -168,25 +168,25 @@ public class ShaderCode { verboseOut.println("createAndCompileShader: Pre GL Error: 0x"+Integer.toHexString(err)); } - gl.glCreateShader(shaderType, shader); + 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)); } - gl.glShaderSource(shader, sources); + 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)); } - gl.glCompileShader(shader); + 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 gl.glIsShaderStatusValid(shader, gl.GL_COMPILE_STATUS, verboseOut) && err == GL.GL_NO_ERROR; + return ShaderUtil.isShaderStatusValid(gl, shader, gl.GL_COMPILE_STATUS, verboseOut) && err == GL.GL_NO_ERROR; } /** @@ -245,7 +245,7 @@ public class ShaderCode { public void destroy(GL2ES2 gl) { if(isValid()) { if(null!=gl) { - gl.glDeleteShader(shader()); + ShaderUtil.deleteShader(gl, shader()); } valid=false; } diff --git a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderProgram.java b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderProgram.java index 7973c471f..c06eae383 100644 --- a/src/jogl/classes/com/sun/opengl/util/glsl/ShaderProgram.java +++ b/src/jogl/classes/com/sun/opengl/util/glsl/ShaderProgram.java @@ -65,7 +65,7 @@ public class ShaderProgram { glUseProgram(gl, false); for(Iterator iter=shaderMap.values().iterator(); iter.hasNext(); ) { ShaderCode shaderCode = (ShaderCode) iter.next(); - gl.glDetachShader(shaderProgram, shaderCode.shader()); + ShaderUtil.detachShader(gl, shaderProgram, shaderCode.shader()); if(releaseShaderToo) { shaderCode.destroy(gl); } @@ -125,14 +125,14 @@ public class ShaderProgram { if(oldShaderID>=0) { ShaderCode oldShader = (ShaderCode) shaderMap.remove(new Integer(oldShaderID)); if(null!=oldShader) { - gl.glDetachShader(shaderProgram, oldShader.shader()); + ShaderUtil.detachShader(gl, shaderProgram, oldShader.shader()); } } add(newShader); - gl.glAttachShader(shaderProgram, newShader.shader()); + ShaderUtil.attachShader(gl, shaderProgram, newShader.shader()); gl.glLinkProgram(shaderProgram); - if ( ! gl.glIsProgramValid(shaderProgram, System.err) ) { + if ( ! ShaderUtil.isProgramValid(gl, shaderProgram, System.err) ) { return false; } @@ -154,13 +154,13 @@ public class ShaderProgram { if(!shaderCode.compile(gl, verboseOut)) { return false; } - gl.glAttachShader(shaderProgram, shaderCode.shader()); + ShaderUtil.attachShader(gl, shaderProgram, shaderCode.shader()); } // Link the program gl.glLinkProgram(shaderProgram); - programLinked = gl.glIsProgramValid(shaderProgram, System.err); + programLinked = ShaderUtil.isProgramValid(gl, shaderProgram, System.err); return programLinked; } -- cgit v1.2.3