diff options
Diffstat (limited to 'src/jogl/classes')
9 files changed, 136 insertions, 89 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>(); diff --git a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java index 1bb509479..8aa6d5165 100644 --- a/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java +++ b/src/jogl/classes/javax/media/opengl/DefaultGLCapabilitiesChooser.java @@ -88,6 +88,21 @@ import javax.media.nativewindow.CapabilitiesImmutable; public class DefaultGLCapabilitiesChooser implements GLCapabilitiesChooser { private static final boolean DEBUG = Debug.isPropertyDefined("jogl.debug.CapabilitiesChooser", true, AccessController.getContext()); + final static int NO_SCORE = -9999999; + final static int DOUBLE_BUFFER_MISMATCH_PENALTY = 1000; + final static int OPAQUE_MISMATCH_PENALTY = 750; + final static int STENCIL_MISMATCH_PENALTY = 500; + final static int MULTISAMPLE_MISMATCH_PENALTY = 500; + final static int MULTISAMPLE_EXTENSION_MISMATCH_PENALTY = 250; // just a little drop, no scale + // Pseudo attempt to keep equal rank penalties scale-equivalent + // (e.g., stencil mismatch is 3 * accum because there are 3 accum + // components) + final static int COLOR_MISMATCH_PENALTY_SCALE = 36; + final static int DEPTH_MISMATCH_PENALTY_SCALE = 6; + final static int ACCUM_MISMATCH_PENALTY_SCALE = 1; + final static int STENCIL_MISMATCH_PENALTY_SCALE = 3; + final static int MULTISAMPLE_MISMATCH_PENALTY_SCALE = 3; + public int chooseCapabilities(final CapabilitiesImmutable desired, final List /*<CapabilitiesImmutable>*/ available, final int windowSystemRecommendedChoice) { @@ -122,20 +137,6 @@ public class DefaultGLCapabilitiesChooser implements GLCapabilitiesChooser { // Create score array int[] scores = new int[availnum]; - final int NO_SCORE = -9999999; - final int DOUBLE_BUFFER_MISMATCH_PENALTY = 1000; - final int OPAQUE_MISMATCH_PENALTY = 750; - final int STENCIL_MISMATCH_PENALTY = 500; - final int MULTISAMPLE_MISMATCH_PENALTY = 500; - final int MULTISAMPLE_EXTENSION_MISMATCH_PENALTY = 250; // just a little drop, no scale - // Pseudo attempt to keep equal rank penalties scale-equivalent - // (e.g., stencil mismatch is 3 * accum because there are 3 accum - // components) - final int COLOR_MISMATCH_PENALTY_SCALE = 36; - final int DEPTH_MISMATCH_PENALTY_SCALE = 6; - final int ACCUM_MISMATCH_PENALTY_SCALE = 1; - final int STENCIL_MISMATCH_PENALTY_SCALE = 3; - final int MULTISAMPLE_MISMATCH_PENALTY_SCALE = 3; for (int i = 0; i < scores.length; i++) { scores[i] = NO_SCORE; diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index c039112c1..cc6b40f54 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -128,6 +128,7 @@ public abstract class GLContext { protected int ctxMinorVersion; protected int ctxOptions; protected String ctxVersionString; + private int currentSwapInterval; protected void resetStates() { ctxMajorVersion=-1; @@ -137,6 +138,7 @@ public abstract class GLContext { attachedObjectsByString.clear(); attachedObjectsByInt.clear(); contextHandle=0; + currentSwapInterval = -1; } /** @@ -621,17 +623,54 @@ public abstract class GLContext { return isGL2GL3() || isGLES2() ; } - public final void setSwapInterval(int interval) { + /** + * Set the swap interval if the current context. + * @param interval Should be ≥ 0. 0 Disables the vertical synchronisation, + * where ≥ 1 is the number of vertical refreshes before a swap buffer occurs. + * A value < 0 is ignored. + * @return true if the operation was successful, otherwise false + * + * @throws GLException if the context is not current. + */ + public final boolean setSwapInterval(int interval) throws GLException { if (!isCurrent()) { throw new GLException("This context is not current. Current context: "+getCurrent()+", this context "+this); } - setSwapIntervalImpl(interval); + if(0<=interval) { + if( setSwapIntervalImpl(interval) ) { + currentSwapInterval = interval; + return true; + } + } + return false; } - protected void setSwapIntervalImpl(int interval) { /** nop per default .. **/ } - protected int currentSwapInterval = -1; // default: not set yet .. - public int getSwapInterval() { + protected boolean setSwapIntervalImpl(int interval) { + return false; + } + /** Return the current swap interval. + * <p> + * If the context has not been made current at all, + * the default value <code>-1</code> is returned. + * </p> + * <p> + * The default value for a valid context is <code>1</code> for + * an EGL based profile (ES1 or ES2) and <code>-1</code> (undefined) + * for desktop. + * </p> + */ + public final int getSwapInterval() { + if(-1 == currentSwapInterval && this.isGLES()) { + currentSwapInterval = 1; + } return currentSwapInterval; } + protected final void setDefaultSwapInterval() { + if(this.isGLES()) { + currentSwapInterval = 1; + } else { + currentSwapInterval = -1; + } + } public final boolean queryMaxSwapGroups(int[] maxGroups, int maxGroups_offset, int[] maxBarriers, int maxBarriers_offset) { diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 8c9ac589a..49b90008b 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -1083,6 +1083,8 @@ public abstract class GLContextImpl extends GLContext { // Set GL Version (complete w/ version string) // setContextVersion(major, minor, ctxProfileBits, true); + + setDefaultSwapInterval(); } protected final void removeCachedVersion(int major, int minor, int ctxProfileBits) { diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java index dc47799c1..f5f9f62c4 100644 --- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java +++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java @@ -274,18 +274,19 @@ public abstract class EGLContext extends GLContextImpl { return sb; } - protected void setSwapIntervalImpl(int interval) { + @Override + protected boolean setSwapIntervalImpl(int interval) { // FIXME !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! // eglSwapInterval(..) issued: // Android 4.0.3 / Pandaboard ES / PowerVR SGX 540: crashes // FIXME !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - if( ! ( Platform.OSType.ANDROID == Platform.getOSType() && getGLRendererString(true).contains("powervr") ) ) { - if (EGL.eglSwapInterval(((EGLDrawable)drawable).getDisplay(), interval)) { - currentSwapInterval = interval ; + if( Platform.OSType.ANDROID == Platform.getOSType() && getGLRendererString(true).contains("powervr") ) { + if(DEBUG) { + System.err.println("Ignored: eglSwapInterval("+interval+") - cause: OS "+Platform.getOSType() + " / Renderer " + getGLRendererString(false)); } - } else if(DEBUG) { - System.err.println("Ignored: eglSwapInterval("+interval+") - cause: OS "+Platform.getOSType() + " / Renderer " + getGLRendererString(false)); + return false; } + return EGL.eglSwapInterval(((EGLDrawable)drawable).getDisplay(), interval); } public abstract void bindPbufferToTexture(); diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index 4ef49e337..63d58f447 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -279,14 +279,9 @@ public abstract class MacOSXCGLContext extends GLContextImpl } } - protected void setSwapIntervalImpl(int interval) { - if( ! isCreated() ) { - throw new GLException("OpenGL context not created"); - } - if(!impl.setSwapInterval(interval)) { - throw new GLException("Error set swap-interval: "+this); - } - currentSwapInterval = interval ; + @Override + protected boolean setSwapIntervalImpl(int interval) { + return impl.setSwapInterval(interval); } public ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, float arg3) { diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java index 06dc07c1e..a6ef9bd1c 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLContext.java @@ -435,7 +435,7 @@ public class WindowsWGLContext extends GLContextImpl { } @Override - protected void setSwapIntervalImpl(int interval) { + protected boolean setSwapIntervalImpl(int interval) { WGLExt wglExt = getWGLExt(); if(0==hasSwapIntervalSGI) { try { @@ -444,11 +444,10 @@ public class WindowsWGLContext extends GLContextImpl { } if (hasSwapIntervalSGI>0) { try { - if ( wglExt.wglSwapIntervalEXT(interval) ) { - currentSwapInterval = interval ; - } + return wglExt.wglSwapIntervalEXT(interval); } catch (Throwable t) { hasSwapIntervalSGI=-1; } } + return false; } private final int initSwapGroupImpl(WGLExt wglExt) { diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java index 79361ac0c..1dc1441e1 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java @@ -509,10 +509,10 @@ public abstract class X11GLXContext extends GLContextImpl { } @Override - protected void setSwapIntervalImpl(int interval) { + protected boolean setSwapIntervalImpl(int interval) { X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration(); GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); - if(!glCaps.isOnscreen()) return; + if(!glCaps.isOnscreen()) { return false; } GLXExt glXExt = getGLXExt(); if(0==hasSwapIntervalSGI) { @@ -522,11 +522,10 @@ public abstract class X11GLXContext extends GLContextImpl { } if (hasSwapIntervalSGI>0) { try { - if( 0 == glXExt.glXSwapIntervalSGI(interval) ) { - currentSwapInterval = interval; - } + return 0 == glXExt.glXSwapIntervalSGI(interval); } catch (Throwable t) { hasSwapIntervalSGI=-1; } } + return false; } private final int initSwapGroupImpl(GLXExt glXExt) { |