diff options
16 files changed, 261 insertions, 109 deletions
diff --git a/make/config/jogl/gl-impl-CustomJavaCode-common.java b/make/config/jogl/gl-impl-CustomJavaCode-common.java index 2c3227ee5..d552bc6e4 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-common.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-common.java @@ -1,7 +1,7 @@ public GLProfile getGLProfile() { return this.glProfile; } - private GLProfile glProfile; + private final GLProfile glProfile; public int glGetBoundBuffer(int target) { return bufferStateTracker.getBoundBufferObject(target, this); @@ -46,7 +46,7 @@ return _context; } - private GLContextImpl _context; + private final GLContextImpl _context; /** * @see javax.media.opengl.GLContext#setSwapInterval(int) diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java index dc4f898e6..95aa7cc2c 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gl4bc.java @@ -17,9 +17,15 @@ public void setObjectTracker(GLObjectTracker tracker) { public GL4bcImpl(GLProfile glp, GLContextImpl context) { this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); + if(null != context) { + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + } else { + this.bufferSizeTracker = null; + this.bufferStateTracker = null; + this.glStateTracker = null; + } this.glProfile = glp; } @@ -35,9 +41,9 @@ public java.nio.ByteBuffer glAllocateMemoryNV(int arg0, float arg1, float arg2, // Helpers for ensuring the correct amount of texture data // -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; +private final GLBufferSizeTracker bufferSizeTracker; +private final GLBufferStateTracker bufferStateTracker; +private final GLStateTracker glStateTracker; private boolean bufferObjectExtensionsInitialized = false; private boolean haveARBPixelBufferObject; diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java index 9b0d98fe9..dff33cf81 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-gles1.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gles1.java @@ -1,8 +1,14 @@ public GLES1Impl(GLProfile glp, GLContextImpl context) { this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); + if(null != context) { + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + } else { + this.bufferSizeTracker = null; + this.bufferStateTracker = null; + this.glStateTracker = null; + } this.glProfile = glp; } @@ -106,9 +112,9 @@ public final GL2GL3 getGL2GL3() throws GLException { // Helpers for ensuring the correct amount of texture data // -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; +private final GLBufferSizeTracker bufferSizeTracker; +private final GLBufferStateTracker bufferStateTracker; +private final GLStateTracker glStateTracker; private boolean bufferObjectExtensionsInitialized = false; private boolean haveOESFramebufferObject; diff --git a/make/config/jogl/gl-impl-CustomJavaCode-gles2.java b/make/config/jogl/gl-impl-CustomJavaCode-gles2.java index ea6544d29..a4976f5ea 100644 --- a/make/config/jogl/gl-impl-CustomJavaCode-gles2.java +++ b/make/config/jogl/gl-impl-CustomJavaCode-gles2.java @@ -4,9 +4,15 @@ private boolean inBeginEndPair; public GLES2Impl(GLProfile glp, GLContextImpl context) { this._context = context; - this.bufferSizeTracker = context.getBufferSizeTracker(); - this.bufferStateTracker = context.getBufferStateTracker(); - this.glStateTracker = context.getGLStateTracker(); + if(null != context) { + this.bufferSizeTracker = context.getBufferSizeTracker(); + this.bufferStateTracker = context.getBufferStateTracker(); + this.glStateTracker = context.getGLStateTracker(); + } else { + this.bufferSizeTracker = null; + this.bufferStateTracker = null; + this.glStateTracker = null; + } this.glProfile = glp; } @@ -110,9 +116,9 @@ public final GL2GL3 getGL2GL3() throws GLException { // Helpers for ensuring the correct amount of texture data // -private GLBufferSizeTracker bufferSizeTracker; -private GLBufferStateTracker bufferStateTracker; -private GLStateTracker glStateTracker; +private final GLBufferSizeTracker bufferSizeTracker; +private final GLBufferStateTracker bufferStateTracker; +private final GLStateTracker glStateTracker; private boolean bufferObjectExtensionsInitialized = false; private boolean haveOESFramebufferObject; diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh index 852dd6f25..10890c786 100755 --- a/make/scripts/tests.sh +++ b/make/scripts/tests.sh @@ -53,6 +53,7 @@ function jrun() { swton=$1 shift + #D_ARGS="-Djogl.debug.GLContext.NoProfileAliasing" #D_ARGS="-Djogamp.debug=all -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all" #D_ARGS="-Djogl.debug=all -Dnativewindow.debug=all -Dnewt.debug=all" #D_ARGS="-Djogl.debug=all -Dnativewindow.debug=all" @@ -214,7 +215,7 @@ function testawtswt() { #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestNEWTCloseX11DisplayBug565 $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestMainVersionGLWindowNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLProfile01NEWT $* -#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestShutdownCompleteNEWT $* +testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestShutdownCompleteNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestShutdownSharedNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestInitConcurrentNEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLContextSurfaceLockNEWT $* @@ -226,7 +227,7 @@ function testawtswt() { #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES2NEWT $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES2NEWT2 $* #testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLAutoDrawableDelegateNEWT $* -testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLContextDrawableSwitchNEWT $* +#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestGLContextDrawableSwitchNEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01NEWT $* #testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting02NEWT $* diff --git a/src/jogl/classes/com/jogamp/opengl/JoglVersion.java b/src/jogl/classes/com/jogamp/opengl/JoglVersion.java index c8e5d212b..75785fd86 100644 --- a/src/jogl/classes/com/jogamp/opengl/JoglVersion.java +++ b/src/jogl/classes/com/jogamp/opengl/JoglVersion.java @@ -93,22 +93,24 @@ public class JoglVersion extends JogampVersion { return sb; } - public static StringBuilder getDefaultOpenGLInfo(StringBuilder sb) { + public static StringBuilder getDefaultOpenGLInfo(StringBuilder sb, boolean withCapabilitiesInfo) { if(null==sb) { sb = new StringBuilder(); } final AbstractGraphicsDevice device = GLProfile.getDefaultDevice(); - sb.append("Default Profiles ").append(Platform.getNewline()); + sb.append("Default Profiles on device ").append(device).append(Platform.getNewline()); if(null!=device) { GLProfile.glAvailabilityToString(device, sb, "\t", 1); } else { sb.append("none"); } - sb.append(Platform.getNewline()).append(Platform.getNewline()); - sb.append("Desktop Capabilities: ").append(Platform.getNewline()); - getAvailableCapabilitiesInfo(GLDrawableFactory.getDesktopFactory(), device, sb); - sb.append("EGL Capabilities: ").append(Platform.getNewline()); - getAvailableCapabilitiesInfo(GLDrawableFactory.getEGLFactory(), device, sb); + if(withCapabilitiesInfo) { + sb.append(Platform.getNewline()).append(Platform.getNewline()); + sb.append("Desktop Capabilities: ").append(Platform.getNewline()); + getAvailableCapabilitiesInfo(GLDrawableFactory.getDesktopFactory(), device, sb); + sb.append("EGL Capabilities: ").append(Platform.getNewline()); + getAvailableCapabilitiesInfo(GLDrawableFactory.getEGLFactory(), device, sb); + } return sb; } diff --git a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java index 62b496891..571f5c5b2 100644 --- a/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java +++ b/src/jogl/classes/com/jogamp/opengl/swt/GLCanvas.java @@ -570,7 +570,7 @@ public class GLCanvas extends Canvas implements GLAutoDrawable { // System.err.println(NativeWindowVersion.getInstance()); System.err.println(JoglVersion.getInstance()); - System.err.println(JoglVersion.getDefaultOpenGLInfo(null).toString()); + System.err.println(JoglVersion.getDefaultOpenGLInfo(null, true).toString()); final GLCapabilitiesImmutable caps = new GLCapabilities( GLProfile.getDefault(GLProfile.getDefaultDevice()) ); final Display display = new Display(); diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index ecfa230d2..351f90027 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -43,12 +43,15 @@ package javax.media.opengl; import java.nio.IntBuffer; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; +import java.util.Set; import javax.media.nativewindow.AbstractGraphicsDevice; import jogamp.opengl.Debug; import jogamp.opengl.GLContextImpl; +import com.jogamp.common.os.Platform; import com.jogamp.common.util.IntObjectHashMap; import com.jogamp.common.util.locks.LockFactory; import com.jogamp.common.util.locks.RecursiveLock; @@ -66,6 +69,32 @@ import com.jogamp.common.util.locks.RecursiveLock; abstraction provides a stable object which clients can use to refer to a given context. */ public abstract class GLContext { + /** + * If <code>true</code> (default), bootstrapping the available GL profiles + * will use the highest compatible GL context for each profile, + * hence skipping querying lower profiles if a compatible higher one is found: + * <ul> + * <li>4.2-core -> 4.2-core, 3.3-core</li> + * <li>4.2-comp -> 4.2-comp, 3.3-comp, 2</li> + * </ul> + * Otherwise the dedicated GL context would be queried and used: + * <ul> + * <li>4.2-core -> 4.2-core</li> + * <li>3.3-core -> 3.3-core</li> + * <li>4.2-comp -> 4.2-comp</li> + * <li>3.3-comp -> 3.3-comp</li> + * <li>3.0-comp -> 2</li> + * </ul> + * Using aliasing speeds up initialization about: + * <ul> + * <li>Linux x86_64 - Nvidia: 28%, 700ms down to 500ms</li> + * <li>Linux x86_64 - AMD : 40%, 1500ms down to 900ms</li> + * <p> + * Can be turned off with property <code>jogl.debug.GLContext.NoProfileAliasing</code>. + * </p> + */ + public static final boolean PROFILE_ALIASING = !Debug.isPropertyDefined("jogl.debug.GLContext.NoProfileAliasing", true); + public static final boolean DEBUG = Debug.debug("GLContext"); public static final boolean TRACE_SWITCH = Debug.isPropertyDefined("jogl.debug.GLContext.TraceSwitch", true); @@ -981,12 +1010,40 @@ public abstract class GLContext { validateProfileBits(profile, "profile"); validateProfileBits(resCtp, "resCtp"); - String key = getDeviceVersionAvailableKey(device, reqMajor, profile); - Integer val = new Integer(composeBits(resMajor, resMinor, resCtp)); + final String key = getDeviceVersionAvailableKey(device, reqMajor, profile); + final Integer val = new Integer(composeBits(resMajor, resMinor, resCtp)); synchronized(deviceVersionAvailable) { - val = deviceVersionAvailable.put( key, val ); + return deviceVersionAvailable.put( key, val ); } - return val; + } + + protected static StringBuffer dumpAvailableGLVersions(StringBuffer sb) { + if(null == sb) { + sb = new StringBuffer(); + } + synchronized(deviceVersionAvailable) { + final Set<String> keys = deviceVersionAvailable.keySet(); + boolean needsSeparator = false; + for(Iterator<String> i = keys.iterator(); i.hasNext(); ) { + if(needsSeparator) { + sb.append(Platform.getNewline()); + } + final String key = i.next(); + sb.append(key).append(": "); + final Integer valI = deviceVersionAvailable.get(key); + if(null != valI) { + final int bits32 = valI.intValue(); + final int major = ( bits32 & 0xFF000000 ) >> 24 ; + final int minor = ( bits32 & 0x00FF0000 ) >> 16 ; + final int ctp = ( bits32 & 0x0000FFFF ) ; + sb.append(GLContext.getGLVersion(major, minor, ctp, null)); + } else { + sb.append("n/a"); + } + needsSeparator = true; + } + } + return sb; } /** @@ -1003,7 +1060,7 @@ public abstract class GLContext { } return val; } - + /** * @param reqMajor Key Value either 1, 2, 3 or 4 * @param reqProfile Key Value either {@link #CTX_PROFILE_COMPAT}, {@link #CTX_PROFILE_CORE} or {@link #CTX_PROFILE_ES} @@ -1014,12 +1071,12 @@ public abstract class GLContext { protected static boolean getAvailableGLVersion(AbstractGraphicsDevice device, int reqMajor, int reqProfile, int[] major, int minor[], int ctp[]) { - Integer valI = getAvailableGLVersion(device, reqMajor, reqProfile); + final Integer valI = getAvailableGLVersion(device, reqMajor, reqProfile); if(null==valI) { return false; } - int bits32 = valI.intValue(); + final int bits32 = valI.intValue(); if(null!=major) { major[0] = ( bits32 & 0xFF000000 ) >> 24 ; diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java index cc4f6c517..a7200b560 100644 --- a/src/jogl/classes/javax/media/opengl/GLProfile.java +++ b/src/jogl/classes/javax/media/opengl/GLProfile.java @@ -39,6 +39,7 @@ package javax.media.opengl; import jogamp.nativewindow.NWJNILibLoader; import jogamp.opengl.Debug; +import jogamp.opengl.GLContextImpl; import jogamp.opengl.GLDrawableFactoryImpl; import jogamp.opengl.DesktopGLDynamicLookupHelper; @@ -131,6 +132,23 @@ public class GLProfile { public Object run() { Platform.initSingleton(); + // Performance hack to trigger classloading of the GL classes impl, which makes up to 12%, 800ms down to 700ms + new Thread(new Runnable() { + public void run() { + final ClassLoader cl = GLProfile.class.getClassLoader(); + try { + ReflectionUtil.createInstance(getGLImplBaseClassName(GL4bc)+"Impl", new Class[] { GLProfile.class, GLContextImpl.class }, new Object[] { null, null }, cl); + } catch (Throwable t) {} + try { + ReflectionUtil.createInstance(getGLImplBaseClassName(GLES2)+"Impl", new Class[] { GLProfile.class, GLContextImpl.class }, new Object[] { null, null }, cl); + } catch (Throwable t) {} + try { + ReflectionUtil.createInstance(getGLImplBaseClassName(GLES1)+"Impl", new Class[] { GLProfile.class, GLContextImpl.class }, new Object[] { null, null }, cl); + } catch (Throwable t) {} + } + }, "GLProfile-GL_Bootstrapping").start(); + + if(TempJarCache.isInitialized()) { final ClassLoader cl = GLProfile.class.getClassLoader(); // either: [jogl-all.jar, jogl-all-noawt.jar, jogl-all-mobile.jar] -> jogl-all-natives-<os.and.arch>.jar @@ -914,6 +932,22 @@ public class GLProfile { return getGLImplBaseClassName(getImplName()); } + private static final String getGLImplBaseClassName(String profileImpl) { + if( GLES2 == profileImpl ) { + return "jogamp.opengl.es2.GLES2"; + } else if( GLES1 == profileImpl ) { + return "jogamp.opengl.es1.GLES1"; + } else if ( GL4bc == profileImpl || + GL4 == profileImpl || + GL3bc == profileImpl || + GL3 == profileImpl || + GL2 == profileImpl ) { + return "jogamp.opengl.gl4.GL4bc"; + } else { + throw new GLException("unsupported profile \"" + profileImpl + "\""); + } + } + /** * @param o GLProfile object to compare with * @return true if given Object is a GLProfile and @@ -922,8 +956,8 @@ public class GLProfile { public final boolean equals(Object o) { if(this==o) { return true; } if(o instanceof GLProfile) { - GLProfile glp = (GLProfile)o; - return getName().equals(glp.getName()) && getImplName().equals(glp.getImplName()) ; + final GLProfile glp = (GLProfile)o; + return getName() == glp.getName() && getImplName() == glp.getImplName() ; } return false; } @@ -1363,7 +1397,6 @@ public class GLProfile { */ private static void initProfilesForDefaultDevices(boolean firstUIActionOnProcess) { NativeWindowFactory.initSingleton(firstUIActionOnProcess); - if(DEBUG) { System.err.println("GLProfile.init firstUIActionOnProcess: "+ firstUIActionOnProcess + ", thread: " + Thread.currentThread().getName()); @@ -1509,7 +1542,7 @@ public class GLProfile { System.err.println("GLProfile.init defaultDevice "+defaultDevice); System.err.println("GLProfile.init profile order "+array2String(GL_PROFILE_LIST_ALL)); if(hasGL234Impl || hasGLES1Impl || hasGLES2Impl) { // avoid deadlock - System.err.println(JoglVersion.getDefaultOpenGLInfo(null)); + System.err.println(JoglVersion.getDefaultOpenGLInfo(null, true)); } } } @@ -1553,9 +1586,9 @@ public class GLProfile { boolean addedDesktopProfile = false; boolean addedEGLProfile = false; - - final boolean deviceIsDesktopCompatible = hasDesktopGLFactory && desktopFactory.getIsDeviceCompatible(device); - + + final boolean deviceIsDesktopCompatible = hasDesktopGLFactory && desktopFactory.getIsDeviceCompatible(device); + if( deviceIsDesktopCompatible ) { // 1st pretend we have all Desktop and EGL profiles .. computeProfileMap(device, true /* desktopCtxUndef*/, true /* esCtxUndef */); @@ -1628,8 +1661,8 @@ public class GLProfile { } } addedEGLProfile = computeProfileMap(device, false /* desktopCtxUndef*/, false /* esCtxUndef */); - } - + } + if( !addedDesktopProfile && !addedEGLProfile ) { setProfileMap(device, new HashMap<String /*GLProfile_name*/, GLProfile>()); // empty if(DEBUG) { @@ -1858,42 +1891,12 @@ public class GLProfile { return GL2; } else if(GLES2.equals(profile) && hasGLES2Impl && ( esCtxUndef || GLContext.isGLES2Available(device, isHardwareRasterizer))) { return GLES2; - /** - * TODO: GLES2_TRUE_DESKTOP (see: GLContextImpl, GLProfile) - * Hack to enable GLES2 for desktop profiles w/ ES2 compatibility, - * however .. a consequent implementation would need to have all GL2ES2 - * implementing profile to also implement GLES2! - * Let's rely on GL2ES2 and let the user/impl. query isGLES2Compatible() - } else if(GLES2.equals(profile)) { - if(hasGL234Impl || hasGLES2Impl) { - if(esCtxUndef) { - return GLES2; - } - return GLContext.getAvailableGLProfile(device, 2, GLContext.CTX_PROFILE_ES); - } - */ } else if(GLES1.equals(profile) && hasGLES1Impl && ( esCtxUndef || GLContext.isGLES1Available(device, isHardwareRasterizer))) { return GLES1; } return null; } - private static String getGLImplBaseClassName(String profileImpl) { - if ( GL4bc.equals(profileImpl) || - GL4.equals(profileImpl) || - GL3bc.equals(profileImpl) || - GL3.equals(profileImpl) || - GL2.equals(profileImpl) ) { - return "jogamp.opengl.gl4.GL4bc"; - } else if(GLES1.equals(profileImpl) || GL2ES1.equals(profileImpl)) { - return "jogamp.opengl.es1.GLES1"; - } else if(GLES2.equals(profileImpl) || GL2ES2.equals(profileImpl)) { - return "jogamp.opengl.es2.GLES2"; - } else { - throw new GLException("unsupported profile \"" + profileImpl + "\""); - } - } - private static /*final*/ HashMap<String /*device_connection*/, HashMap<String /*GLProfile_name*/, GLProfile>> deviceConn2ProfileMap = new HashMap<String /*device_connection*/, HashMap<String /*GLProfile_name*/, GLProfile>>(); diff --git a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java index 3161f898d..48f7ea24a 100644 --- a/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java +++ b/src/jogl/classes/javax/media/opengl/awt/GLCanvas.java @@ -1070,7 +1070,7 @@ public class GLCanvas extends Canvas implements AWTGLAutoDrawable, WindowClosing // System.err.println(NativeWindowVersion.getInstance()); System.err.println(JoglVersion.getInstance()); - System.err.println(JoglVersion.getDefaultOpenGLInfo(null).toString()); + System.err.println(JoglVersion.getDefaultOpenGLInfo(null, true).toString()); final GLCapabilitiesImmutable caps = new GLCapabilities( GLProfile.getDefault(GLProfile.getDefaultDevice()) ); final Frame frame = new Frame("JOGL AWT Test"); diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java index 7362a2bd8..4dd8806fa 100644 --- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java +++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java @@ -529,7 +529,7 @@ public abstract class GLContextImpl extends GLContext { if (DEBUG || TRACE_SWITCH) { if(created) { System.err.println(getThreadName() + ": Create GL context OK: obj " + toHexString(hashCode()) + ", ctx " + toHexString(contextHandle) + " for " + getClass().getName()+" - "+getGLVersion()); - Thread.dumpStack(); // JAU + // Thread.dumpStack(); } else { System.err.println(getThreadName() + ": Create GL context FAILED obj " + toHexString(hashCode()) + ", for " + getClass().getName()); } @@ -694,16 +694,80 @@ public abstract class GLContextImpl extends GLContext { private final boolean mapGLVersions(AbstractGraphicsDevice device) { synchronized (GLContext.deviceVersionAvailable) { + final long t0 = ( DEBUG ) ? System.nanoTime() : 0; boolean success = false; // Following GLProfile.GL_PROFILE_LIST_ALL order of profile detection { GL4bc, GL3bc, GL2, GL4, GL3, GL2GL3, GLES2, GL2ES2, GLES1, GL2ES1 } - success |= createContextARBMapVersionsAvailable(4, true /* compat */); // GL4bc - success |= createContextARBMapVersionsAvailable(3, true /* compat */); // GL3bc - success |= createContextARBMapVersionsAvailable(2, true /* compat */); // GL2 - success |= createContextARBMapVersionsAvailable(4, false /* core */); // GL4 - success |= createContextARBMapVersionsAvailable(3, false /* core */); // GL3 + boolean hasGL4bc = false; + boolean hasGL3bc = false; + boolean hasGL2 = false; + boolean hasGL4 = false; + boolean hasGL3 = false; + if(!hasGL4bc) { + hasGL4bc = createContextARBMapVersionsAvailable(4, CTX_PROFILE_COMPAT); // GL4bc + success |= hasGL4bc; + if(hasGL4bc) { + // Map all lower compatible profiles: GL3bc, GL2, GL4, GL3 + GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_COMPAT, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 2, CTX_PROFILE_COMPAT, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 4, CTX_PROFILE_CORE, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_CORE, ctxMajorVersion, ctxMinorVersion, ctxOptions); + if(PROFILE_ALIASING) { + hasGL3bc = true; + hasGL2 = true; + hasGL4 = true; + hasGL3 = true; + } + resetStates(); // clean this context states, since creation was temporary + } + } + if(!hasGL3bc) { + hasGL3bc = createContextARBMapVersionsAvailable(3, CTX_PROFILE_COMPAT); // GL3bc + success |= hasGL3bc; + if(hasGL3bc) { + // Map all lower compatible profiles: GL2 and GL3 + GLContext.mapAvailableGLVersion(device, 2, CTX_PROFILE_COMPAT, ctxMajorVersion, ctxMinorVersion, ctxOptions); + GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_CORE, ctxMajorVersion, ctxMinorVersion, ctxOptions); + if(PROFILE_ALIASING) { + hasGL2 = true; + hasGL3 = true; + } + resetStates(); // clean this context states, since creation was temporary + } + } + if(!hasGL2) { + hasGL2 = createContextARBMapVersionsAvailable(2, CTX_PROFILE_COMPAT); // GL2 + success |= hasGL2; + if(hasGL2) { + resetStates(); // clean this context states, since creation was temporary + } + } + if(!hasGL4) { + hasGL4 = createContextARBMapVersionsAvailable(4, CTX_PROFILE_CORE); // GL4 + success |= hasGL4; + if(hasGL4) { + // Map all lower compatible profiles: GL3 + GLContext.mapAvailableGLVersion(device, 3, CTX_PROFILE_CORE, ctxMajorVersion, ctxMinorVersion, ctxOptions); + if(PROFILE_ALIASING) { + hasGL3 = true; + } + resetStates(); // clean this context states, since creation was temporary + } + } + if(!hasGL3) { + hasGL3 = createContextARBMapVersionsAvailable(3, CTX_PROFILE_CORE); // GL3 + success |= hasGL3; + if(hasGL3) { + resetStates(); // clean this context states, since creation was temporary + } + } if(success) { // only claim GL versions set [and hence detected] if ARB context creation was successful GLContext.setAvailableGLVersionsSet(device); + if(DEBUG) { + final long t1 = System.nanoTime(); + System.err.println("GLContextImpl.mapGLVersions: "+device+", profileAliasing: "+PROFILE_ALIASING+", total "+(t1-t0)/1e6 +"ms"); + System.err.println(GLContext.dumpAvailableGLVersions(null).toString()); + } } else if (DEBUG) { System.err.println(getThreadName() + ": createContextARB-MapVersions NONE for :"+device); } @@ -711,11 +775,14 @@ public abstract class GLContextImpl extends GLContext { } } - private final boolean createContextARBMapVersionsAvailable(int reqMajor, boolean compat) { + /** + * Note: Since context creation is temproary, caller need to issue {@link #resetStates()}, if creation was successful, i.e. returns true. + * This method does not reset the states, allowing the caller to utilize the state variables. + **/ + private final boolean createContextARBMapVersionsAvailable(int reqMajor, int reqProfile) { long _context; - int reqProfile = compat ? CTX_PROFILE_COMPAT : CTX_PROFILE_CORE ; int ctp = CTX_IS_ARB_CREATED; - if(compat) { + if(CTX_PROFILE_COMPAT == reqProfile) { ctp |= CTX_PROFILE_COMPAT ; } else { ctp |= CTX_PROFILE_CORE ; @@ -745,7 +812,7 @@ public abstract class GLContextImpl extends GLContext { /* min */ majorMin, minorMin, /* res */ major, minor); - if(0==_context && !compat) { + if(0==_context && CTX_PROFILE_CORE == reqProfile) { // try w/ FORWARD instead of CORE ctp &= ~CTX_PROFILE_CORE ; ctp |= CTX_OPTION_FORWARD ; @@ -764,6 +831,7 @@ public abstract class GLContextImpl extends GLContext { /* res */ major, minor); } } + final boolean res; if(0!=_context) { AbstractGraphicsDevice device = drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getDevice(); // ctxMajorVersion, ctxMinorVersion, ctxOptions is being set by @@ -773,15 +841,14 @@ public abstract class GLContextImpl extends GLContext { if (DEBUG) { System.err.println(getThreadName() + ": createContextARB-MapVersionsAvailable HAVE: " +reqMajor+"."+reqProfile+ " -> "+getGLVersion()); } - // only reset [and hence modify] this context state if ARB context creation was successful - resetStates(); - return true; + res = true; } else { if (DEBUG) { System.err.println(getThreadName() + ": createContextARB-MapVersionsAvailable NOPE: "+reqMajor+"."+reqProfile); } - return false; + res = false; } + return res; } private final long createContextARBVersions(long share, boolean direct, int ctxOptionFlags, @@ -796,7 +863,6 @@ public abstract class GLContextImpl extends GLContext { while ( !ok && GLContext.isValidGLVersion(major[0], minor[0]) && ( major[0]>majorMin || major[0]==majorMin && minor[0] >=minorMin ) ) { - if (DEBUG) { System.err.println(getThreadName() + ": createContextARBVersions: share "+share+", direct "+direct+", version "+major[0]+"."+minor[0]); } @@ -900,7 +966,7 @@ public abstract class GLContextImpl extends GLContext { /** Create the GL for this context. */ protected GL createGL(GLProfile glp) { - GL gl = (GL) createInstance(glp, "Impl", new Class[] { GLProfile.class, GLContextImpl.class }, new Object[] { glp, this } ); + final GL gl = (GL) createInstance(glp, "Impl", new Class[] { GLProfile.class, GLContextImpl.class }, new Object[] { glp, this } ); /* FIXME: refactor dependence on Java 2D / JOGL bridge if (tracker != null) { @@ -1018,7 +1084,7 @@ public abstract class GLContextImpl extends GLContext { } if(null==this.gl || !verifyInstance(gl.getGLProfile(), "Impl", this.gl)) { - setGL(createGL(getGLDrawable().getGLProfile())); + setGL( createGL( getGLDrawable().getGLProfile() ) ); } updateGLXProcAddressTable(); diff --git a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java index 918bf8643..0afadc677 100644 --- a/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java +++ b/src/jogl/classes/jogamp/opengl/x11/glx/X11GLXContext.java @@ -275,10 +275,10 @@ public abstract class X11GLXContext extends GLContextImpl { boolean direct = true; // try direct always isDirect = false; // fall back - X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); - X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration(); - AbstractGraphicsDevice device = config.getScreen().getDevice(); - X11GLXContext sharedContext = (X11GLXContext) factory.getOrCreateSharedContextImpl(device); + final X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl(); + final X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeSurface().getGraphicsConfiguration(); + final AbstractGraphicsDevice device = config.getScreen().getDevice(); + final X11GLXContext sharedContext = (X11GLXContext) factory.getOrCreateSharedContextImpl(device); long display = device.getHandle(); long share = 0; @@ -337,7 +337,6 @@ public abstract class X11GLXContext extends GLContextImpl { } setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT); // use GL_VERSION glXMakeContextCurrent(display, 0, 0, 0); // release temp context - if( !createContextARBTried ) { // is*Available calls are valid since setGLFunctionAvailability(..) was called final boolean isProcCreateContextAttribsARBAvailable = isFunctionAvailable("glXCreateContextAttribsARB"); @@ -393,6 +392,7 @@ public abstract class X11GLXContext extends GLContextImpl { if (DEBUG) { System.err.println(getThreadName() + ": createContextImpl: OK direct "+isDirect+"/"+direct); } + return true; } diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 5cc0d765c..f08fbc8fa 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -762,7 +762,7 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind System.err.println(GlueGenVersion.getInstance()); System.err.println(JoglVersion.getInstance()); - System.err.println(JoglVersion.getDefaultOpenGLInfo(null).toString()); + System.err.println(JoglVersion.getDefaultOpenGLInfo(null, true).toString()); final GLProfile glp = GLProfile.getDefault(); final GLCapabilitiesImmutable caps = new GLCapabilities( glp ); diff --git a/src/newt/classes/jogamp/newt/driver/android/MD.java b/src/newt/classes/jogamp/newt/driver/android/MD.java index 150dea9c7..403eae383 100644 --- a/src/newt/classes/jogamp/newt/driver/android/MD.java +++ b/src/newt/classes/jogamp/newt/driver/android/MD.java @@ -43,7 +43,7 @@ public class MD { .append(JoglVersion.getInstance()).append(Platform.NEWLINE) .append(Platform.NEWLINE); - JoglVersion.getDefaultOpenGLInfo(sb); + JoglVersion.getDefaultOpenGLInfo(sb, true); return sb.toString(); } diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java index 2c89ec7f6..9ca6670ad 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLProfile01NEWT.java @@ -54,7 +54,7 @@ public class TestGLProfile01NEWT extends UITestCase { System.err.println(JoglVersion.getInstance()); System.err.println(NewtVersion.getInstance()); - System.err.println(JoglVersion.getDefaultOpenGLInfo(null).toString()); + System.err.println(JoglVersion.getDefaultOpenGLInfo(null, true).toString()); } @Test diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java index 459284177..5f374830d 100644 --- a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java +++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestShutdownCompleteNEWT.java @@ -39,6 +39,7 @@ import org.junit.Assert; import org.junit.Test; import com.jogamp.newt.opengl.GLWindow; +import com.jogamp.opengl.JoglVersion; import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2; import com.jogamp.opengl.test.junit.util.UITestCase; import com.jogamp.opengl.util.Animator; @@ -73,7 +74,7 @@ public class TestShutdownCompleteNEWT extends UITestCase { glWindow.destroy(); } - protected void oneLife() throws InterruptedException { + protected void oneLife(boolean glInfo) throws InterruptedException { if(waitForEach) { waitForEnter(); } @@ -84,28 +85,32 @@ public class TestShutdownCompleteNEWT extends UITestCase { runTestGL(); } long t2 = System.nanoTime(); + if(glInfo) { + System.err.println(JoglVersion.getDefaultOpenGLInfo(null, false).toString()); + } + long t3 = System.nanoTime(); GLProfile.shutdown(GLProfile.ShutdownType.COMPLETE); - long t3 = System.nanoTime(); + long t4 = System.nanoTime(); System.err.println("Total: "+ (t3-t0)/1e6 +"ms"); System.err.println(" GLProfile.initSingleton(): "+ (t1-t0)/1e6 +"ms"); System.err.println(" Demo Code: "+ (t2-t1)/1e6 +"ms"); - System.err.println(" GLProfile.shutdown(COMPLETE): "+ (t3-t2)/1e6 +"ms"); + System.err.println(" GLProfile.shutdown(COMPLETE): "+ (t4-t3)/1e6 +"ms"); } @Test public void test01OneLife() throws InterruptedException { - oneLife(); + oneLife(true); } @Test public void test01AnotherLife() throws InterruptedException { - oneLife(); + oneLife(false); } @Test public void test01TwoLifes() throws InterruptedException { - oneLife(); - oneLife(); + oneLife(false); + oneLife(false); } static boolean initOnly = false; |