diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp')
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java | 69 | ||||
-rw-r--r-- | src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java | 36 |
2 files changed, 58 insertions, 47 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java index 85e288638..eec055ed4 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderCode.java @@ -295,39 +295,43 @@ public class ShaderCode { } } - private static int readShaderSource(Class<?> context, URL url, StringBuffer result, int lineno) { + private static int readShaderSource(Class<?> context, URL url, StringBuffer result, int lineno) { try { if(DEBUG_CODE) { System.err.printf("%3d: // %s\n", lineno, url); } - BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); - String line = null; - while ((line = reader.readLine()) != null) { - lineno++; - if(DEBUG_CODE) { - System.err.printf("%3d: %s\n", lineno, line); - } - if (line.startsWith("#include ")) { - String includeFile = line.substring(9).trim(); - URL nextURL = null; - - // Try relative path first - String next = IOUtil.getRelativeOf(url, includeFile); - if(null != next) { - nextURL = IOUtil.getResource(context, next); - } - if (nextURL == null) { - // Try absolute path - nextURL = IOUtil.getResource(context, includeFile); + final BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream())); + try { + String line = null; + while ((line = reader.readLine()) != null) { + lineno++; + if(DEBUG_CODE) { + System.err.printf("%3d: %s\n", lineno, line); } - if (nextURL == null) { - // Fail - throw new FileNotFoundException("Can't find include file " + includeFile); + if (line.startsWith("#include ")) { + String includeFile = line.substring(9).trim(); + URL nextURL = null; + + // Try relative path first + String next = IOUtil.getRelativeOf(url, includeFile); + if(null != next) { + nextURL = IOUtil.getResource(context, next); + } + if (nextURL == null) { + // Try absolute path + nextURL = IOUtil.getResource(context, includeFile); + } + if (nextURL == null) { + // Fail + throw new FileNotFoundException("Can't find include file " + includeFile); + } + lineno = readShaderSource(context, nextURL, result, lineno); + } else { + result.append(line + "\n"); } - lineno = readShaderSource(context, nextURL, result, lineno); - } else { - result.append(line + "\n"); } + } finally { + IOUtil.close(reader, false); } } catch (IOException e) { throw new RuntimeException(e); @@ -358,12 +362,17 @@ public class ShaderCode { } public static ByteBuffer readShaderBinary(Class<?> context, String path) { + final URL url = IOUtil.getResource(context, path); + if (url == null) { + return null; + } try { - URL url = IOUtil.getResource(context, path); - if (url == null) { - return null; + final BufferedInputStream bis = new BufferedInputStream( url.openStream() ); + try { + return IOUtil.copyStream2ByteBuffer( bis ); + } finally { + IOUtil.close(bis, false); } - return IOUtil.copyStream2ByteBuffer( new BufferedInputStream( url.openStream() ) ); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java index 4b680b849..245f5fb06 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java +++ b/src/jogl/classes/com/jogamp/opengl/util/glsl/ShaderState.java @@ -31,7 +31,6 @@ package com.jogamp.opengl.util.glsl; import java.security.AccessController; import java.util.ArrayList; import java.util.HashMap; -import java.util.HashSet; import java.util.Iterator; import javax.media.opengl.GL; @@ -205,8 +204,6 @@ public class ShaderState { * @throws GLException if program was not linked and linking fails */ public synchronized void attachShaderProgram(GL2ES2 gl, ShaderProgram prog, boolean enable) throws GLException { - boolean prgInUse = false; // earmarked state - if(DEBUG) { int curId = (null!=shaderProgram)?shaderProgram.id():-1; int newId = (null!=prog)?prog.id():-1; @@ -317,7 +314,7 @@ public class ShaderState { * @see GL2ES2#glGetAttribLocation(int, String) */ public int getCachedAttribLocation(String name) { - Integer idx = (Integer) activeAttribLocationMap.get(name); + Integer idx = activeAttribLocationMap.get(name); return (null!=idx)?idx.intValue():-1; } @@ -337,7 +334,7 @@ public class ShaderState { * @see ShaderProgram#glReplaceShader */ public GLArrayData getAttribute(String name) { - return (GLArrayData) activeAttribDataMap.get(name); + return activeAttribDataMap.get(name); } /** @@ -485,7 +482,8 @@ public class ShaderState { * @return true if the named attribute is enable */ public final boolean isVertexAttribArrayEnabled(String name) { - return enabledAttributes.contains(name); + final Boolean v = activedAttribEnabledMap.get(name); + return null != v && v.booleanValue(); } /** @@ -496,7 +494,7 @@ public class ShaderState { } private boolean enableVertexAttribArray(GL2ES2 gl, String name, int location) { - enabledAttributes.add(name); + activedAttribEnabledMap.put(name, Boolean.TRUE); if(0>location) { location = getAttribLocation(gl, name); if(0>location) { @@ -569,7 +567,7 @@ public class ShaderState { } private boolean disableVertexAttribArray(GL2ES2 gl, String name, int location) { - enabledAttributes.remove(name); + activedAttribEnabledMap.put(name, Boolean.FALSE); if(0>location) { location = getAttribLocation(gl, name); if(0>location) { @@ -691,14 +689,14 @@ public class ShaderState { throw new GLException("Internal Error: mapped vertex attribute couldn't be disabled"); } } - for(Iterator<String> iter = enabledAttributes.iterator(); iter.hasNext(); ) { + for(Iterator<String> iter = activedAttribEnabledMap.keySet().iterator(); iter.hasNext(); ) { if(!disableVertexAttribArray(gl, iter.next())) { throw new GLException("Internal Error: prev enabled vertex attribute couldn't be disabled"); } } } activeAttribDataMap.clear(); - enabledAttributes.clear(); + activedAttribEnabledMap.clear(); activeAttribLocationMap.clear(); managedAttributes.clear(); } @@ -721,10 +719,10 @@ public class ShaderState { * @see ShaderProgram#glReplaceShader */ public void disableAllVertexAttributeArrays(GL2ES2 gl, boolean removeFromState) { - for(Iterator<String> iter = enabledAttributes.iterator(); iter.hasNext(); ) { + for(Iterator<String> iter = activedAttribEnabledMap.keySet().iterator(); iter.hasNext(); ) { final String name = iter.next(); if(removeFromState) { - enabledAttributes.remove(name); + activedAttribEnabledMap.remove(name); } final int index = getAttribLocation(gl, name); if(0<=index) { @@ -740,7 +738,7 @@ public class ShaderState { attribute.setLocation(loc); if(0<=loc) { - if(enabledAttributes.contains(name)) { + if(isVertexAttribArrayEnabled(name)) { // enable attrib, VBO and pass location/data gl.glEnableVertexAttribArray(loc); } @@ -787,7 +785,7 @@ public class ShaderState { if(0<=loc) { this.bindAttribLocation(gl, loc, name); - if(enabledAttributes.contains(name)) { + if(isVertexAttribArrayEnabled(name)) { // enable attrib, VBO and pass location/data gl.glEnableVertexAttribArray(loc); } @@ -1006,8 +1004,12 @@ public class ShaderState { sb.append("ShaderProgram: null"); } sb.append(Platform.getNewline()).append(" enabledAttributes ["); - for(Iterator<String> iter = enabledAttributes.iterator(); iter.hasNext(); ) { - sb.append(Platform.getNewline()).append(" ").append(iter.next()); + { + Iterator<String> names = activedAttribEnabledMap.keySet().iterator(); + Iterator<Boolean> values = activedAttribEnabledMap.values().iterator(); + while( names.hasNext() ) { + sb.append(Platform.getNewline()).append(" ").append(names.next()).append(": ").append(values.next()); + } } sb.append(Platform.getNewline()).append(" ],").append(" activeAttributes ["); for(Iterator<GLArrayData> iter = activeAttribDataMap.values().iterator(); iter.hasNext(); ) { @@ -1037,7 +1039,7 @@ public class ShaderState { private boolean verbose = DEBUG ? true : false; private ShaderProgram shaderProgram=null; - private HashSet<String> enabledAttributes = new HashSet<String>(); + private HashMap<String, Boolean> activedAttribEnabledMap = new HashMap<String, Boolean>(); private HashMap<String, Integer> activeAttribLocationMap = new HashMap<String, Integer>(); private HashMap<String, GLArrayData> activeAttribDataMap = new HashMap<String, GLArrayData>(); private ArrayList<GLArrayData> managedAttributes = new ArrayList<GLArrayData>(); |