aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xmake/scripts/tests.sh28
-rw-r--r--src/jogl/classes/javax/media/opengl/GLContext.java249
-rw-r--r--src/jogl/classes/javax/media/opengl/GLDrawableFactory.java17
-rw-r--r--src/jogl/classes/javax/media/opengl/GLProfile.java9
-rw-r--r--src/jogl/classes/jogamp/opengl/GLContextImpl.java97
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLContext.java10
-rw-r--r--src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java2
-rw-r--r--src/newt/classes/com/jogamp/newt/opengl/GLWindow.java2
-rw-r--r--src/newt/classes/jogamp/newt/WindowImpl.java2
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitchNEWT.java322
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java17
-rw-r--r--src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java15
-rw-r--r--src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java57
13 files changed, 695 insertions, 132 deletions
diff --git a/make/scripts/tests.sh b/make/scripts/tests.sh
index 55fbc5378..852dd6f25 100755
--- a/make/scripts/tests.sh
+++ b/make/scripts/tests.sh
@@ -53,6 +53,10 @@ function jrun() {
swton=$1
shift
+ #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"
+ #D_ARGS="-Djogl.debug=all -Dnewt.debug=all"
#D_ARGS="-Djogl.debug.DebugGL -Djogl.debug.TraceGL"
#D_ARGS="-Djogl.debug.GLDebugMessageHandler"
#D_ARGS="-Djogl.debug.GLDebugMessageHandler -Djogl.debug.DebugGL"
@@ -68,11 +72,8 @@ function jrun() {
#D_ARGS="-Djogl.debug.EGL -Dnativewindow.debug.GraphicsConfiguration -Djogl.debug.GLDrawable"
#D_ARGS="-Dnewt.test.Screen.disableScreenMode -Dnewt.debug.Screen"
#D_ARGS="-Djogl.debug.ExtensionAvailabilityCache -Djogl.debug=all -Dnativewindow.debug=all -Djogamp.debug.ProcAddressHelper=true -Djogamp.debug.NativeLibrary=true -Djogamp.debug.NativeLibrary.Lookup=true"
- #D_ARGS="-Djogamp.debug=all -Dnativewindow.debug=all -Djogl.debug=all -Dnewt.debug=all"
- #D_ARGS="-Djogl.debug=all -Djogamp.debug.Lock -Djogamp.common.utils.locks.Lock.timeout=600000"
#D_ARGS="-Dnewt.debug.MainThread"
#D_ARGS="-Dnewt.debug.Window"
- #D_ARGS="-Djogl.debug=all -Dnativewindow.debug=all"
#D_ARGS="-Dnativewindow.debug.GraphicsConfiguration -Dnativewindow.debug.NativeWindow"
#D_ARGS="-Djogl.debug.GLCanvas -Djogl.debug.Animator -Djogl.debug.GLDrawable -Djogl.debug.GLContext -Djogl.debug.GLContext.TraceSwitch"
#D_ARGS="-Djogl.debug.GLContext -Djogl.debug.ExtensionAvailabilityCache"
@@ -83,8 +84,10 @@ function jrun() {
#D_ARGS="-Dnativewindow.debug.NativeWindow"
#D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Display -Dnewt.debug.EDT"
#D_ARGS="-Dnewt.debug.EDT -Dnewt.debug.Window -Djogl.debug.GLContext"
- #D_ARGS="-Dnativewindow.debug.ToolkitLock.TraceLock -Dnativewindow.debug.X11Util.TraceDisplayLifecycle=true -Dnativewindow.debug.X11Util"
+ #D_ARGS="-Dnativewindow.debug.ToolkitLock.TraceLock -Dnativewindow.debug.X11Util.XErrorStackDump -Dnativewindow.debug.X11Util.TraceDisplayLifecycle -Dnativewindow.debug.X11Util"
#D_ARGS="-Dnativewindow.debug.X11Util -Djogl.debug.GLContext -Djogl.debug.GLDrawable -Dnewt.debug=all"
+ #D_ARGS="-Dnativewindow.debug.X11Util -Dnativewindow.debug.X11Util.XSync"
+ #D_ARGS="-Dnativewindow.debug.X11Util.XSync -Dnewt.debug.Window"
#D_ARGS="-Djogl.debug.GLDrawable -Djogl.debug.GLContext"
#D_ARGS="-Djogamp.common.utils.locks.Lock.timeout=3000 -Djogamp.debug.Lock -Djogl.debug.GLContext.TraceSwitch"
#D_ARGS="-Djogamp.common.utils.locks.Lock.timeout=600000 -Djogamp.debug.Lock -Djogamp.debug.Lock.TraceLock"
@@ -100,9 +103,6 @@ function jrun() {
#D_ARGS="-Dnewt.debug.Screen -Dnewt.debug.EDT -Djogamp.debug.Lock"
#D_ARGS="-Djogl.debug.GLContext -Djogl.debug.GraphicsConfiguration"
#D_ARGS="-Dnewt.debug.EDT"
- #D_ARGS="-Djogamp.debug=all -Djogl.debug=all -Dnativewindow.debug=all -Dnewt.debug=all"
- #D_ARGS="-Djogl.debug=all -Dnativewindow.debug=all -Dnewt.debug=all"
- #D_ARGS="-Djogl.debug=all -Dnewt.debug=all"
#D_ARGS="-Dnewt.debug.Window -Dnewt.debug.Display -Dnewt.debug.EDT -Djogl.debug.GLContext"
#D_ARGS="-Dnewt.debug.Window -Djogl.debug.Animator -Dnewt.debug.Screen"
#D_ARGS="-Dnewt.debug.Window"
@@ -211,7 +211,6 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestFloatUtil01MatrixMatrixMultNOUI $*
-#testnoawt com.jogamp.opengl.test.junit.jogl.glu.TestGluUnprojectFloatNOUI $*
#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 $*
@@ -226,6 +225,15 @@ function testawtswt() {
#testnoawt com.jogamp.opengl.test.junit.jogl.acore.TestSharedContextVBOES1NEWT $*
#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.newt.parenting.TestParenting01NEWT $*
+#testnoawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting02NEWT $*
+#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01cSwingAWT $*
+
+
+#testnoawt com.jogamp.opengl.test.junit.jogl.glu.TestGluUnprojectFloatNOUI $*
#testnoawt com.jogamp.opengl.test.junit.newt.TestRemoteWindow01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.newt.TestRemoteGLWindows01NEWT $*
#testnoawt com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT $*
@@ -271,7 +279,7 @@ function testawtswt() {
#testawt com.jogamp.opengl.test.junit.jogl.awt.TestAWT02WindowClosing
#testawt com.jogamp.opengl.test.junit.jogl.awt.text.TestAWTTextRendererUseVertexArrayBug464
#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT $*
-testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $*
+#testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWTAnalyzeBug455 $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsGLJPanelAWT $*
#testawt com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsGLJPanelAWTBug450 $*
@@ -384,8 +392,6 @@ testawt com.jogamp.opengl.test.junit.jogl.demos.es2.awt.TestGearsES2AWT $*
#testawt com.jogamp.opengl.test.junit.newt.TestFocus02SwingAWTRobot $*
#linux:
-#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParenting01cSwingAWT $*
-#testnoawt com.jogamp.opengl.test.junit.jogl.glsl.TestGLSLShaderState02NEWT $*
# osx:
#testawt com.jogamp.opengl.test.junit.newt.parenting.TestParentingFocusTraversal01AWT $*
diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java
index bf6ee31df..ecfa230d2 100644
--- a/src/jogl/classes/javax/media/opengl/GLContext.java
+++ b/src/jogl/classes/javax/media/opengl/GLContext.java
@@ -46,13 +46,13 @@ import java.util.HashSet;
import javax.media.nativewindow.AbstractGraphicsDevice;
+import jogamp.opengl.Debug;
+import jogamp.opengl.GLContextImpl;
+
import com.jogamp.common.util.IntObjectHashMap;
import com.jogamp.common.util.locks.LockFactory;
import com.jogamp.common.util.locks.RecursiveLock;
-import jogamp.opengl.Debug;
-import jogamp.opengl.GLContextImpl;
-
/** Abstraction for an OpenGL rendering context. In order to perform
OpenGL rendering, a context must be "made current" on the current
thread. OpenGL rendering semantics specify that only one context
@@ -70,9 +70,9 @@ public abstract class GLContext {
public static final boolean TRACE_SWITCH = Debug.isPropertyDefined("jogl.debug.GLContext.TraceSwitch", true);
/** Reflects property jogl.debug.DebugGL. If true, the debug pipeline is enabled at context creation. */
- public final static boolean DEBUG_GL = Debug.isPropertyDefined("jogl.debug.DebugGL", true);
+ public static final boolean DEBUG_GL = Debug.isPropertyDefined("jogl.debug.DebugGL", true);
/** Reflects property jogl.debug.TraceGL. If true, the trace pipeline is enabled at context creation. */
- public final static boolean TRACE_GL = Debug.isPropertyDefined("jogl.debug.TraceGL", true);
+ public static final boolean TRACE_GL = Debug.isPropertyDefined("jogl.debug.TraceGL", true);
/** Indicates that the context was not made current during the last call to {@link #makeCurrent makeCurrent}. */
public static final int CONTEXT_NOT_CURRENT = 0;
@@ -81,32 +81,49 @@ public abstract class GLContext {
/** Indicates that a newly-created context was made current during the last call to {@link #makeCurrent makeCurrent}. */
public static final int CONTEXT_CURRENT_NEW = 2;
- /** <code>ARB_create_context</code> related: created via ARB_create_context. Cache key value. */
+ /** <code>ARB_create_context</code> related: created via ARB_create_context. Cache key value. See {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */
protected static final int CTX_IS_ARB_CREATED = 1 << 0;
- /** <code>ARB_create_context</code> related: compatibility profile. Cache key value. */
+ /** <code>ARB_create_context</code> related: desktop compatibility profile. Cache key value. See {@link #isGLCompatibilityProfile()}, {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */
protected static final int CTX_PROFILE_COMPAT = 1 << 1;
- /** <code>ARB_create_context</code> related: core profile. Cache key value. */
+ /** <code>ARB_create_context</code> related: desktop core profile. Cache key value. See {@link #isGLCoreProfile()}, {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */
protected static final int CTX_PROFILE_CORE = 1 << 2;
- /** <code>ARB_create_context</code> related: ES profile. Cache key value. */
+ /** <code>ARB_create_context</code> related: ES profile. Cache key value. See {@link #isGLES()}, {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */
protected static final int CTX_PROFILE_ES = 1 << 3;
- /** <code>ARB_create_context</code> related: flag forward compatible. Cache key value. */
+ /** <code>ARB_create_context</code> related: flag forward compatible. Cache key value. See {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */
protected static final int CTX_OPTION_FORWARD = 1 << 4;
- /** <code>ARB_create_context</code> related: flag debug. Not a cache key. */
+ /** <code>ARB_create_context</code> related: flag debug. Not a cache key. See {@link #setContextCreationFlags(int)}, {@link GLAutoDrawable#setContextCreationFlags(int)}, {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */
public static final int CTX_OPTION_DEBUG = 1 << 5;
- /** <code>GL_ARB_ES2_compatibility</code> implementation related: Context is compatible w/ ES2. Not a cache key. */
+ /** <code>GL_ARB_ES2_compatibility</code> implementation related: Context is compatible w/ ES2. Not a cache key. See {@link #isGLES2Compatible()}, {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */
protected static final int CTX_IMPL_ES2_COMPAT = 1 << 8;
- /** Context uses software rasterizer, otherwise hardware rasterizer. Cache key value. */
- protected static final int CTX_IMPL_ACCEL_SOFT = 1 << 15;
+ /** Context supports FBO, details see {@link #hasFBO()}.
+ * Not a cache key.
+ * @see #hasFBO()
+ * @see #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)
+ */
+ protected static final int CTX_IMPL_FBO = 1 << 9;
- private static ThreadLocal<GLContext> currentContext = new ThreadLocal<GLContext>();
+ /** Context uses software rasterizer, otherwise hardware rasterizer. Cache key value. See {@link #isHardwareRasterizer()}, {@link #getAvailableContextProperties(AbstractGraphicsDevice, GLProfile)}. */
+ protected static final int CTX_IMPL_ACCEL_SOFT = 1 << 15;
- private HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>();
- private IntObjectHashMap attachedObjectsByInt = new IntObjectHashMap();
+ protected static final String GL_ARB_ES2_compatibility = "GL_ARB_ES2_compatibility";
+ protected static final String GL_ARB_framebuffer_object = "GL_ARB_framebuffer_object";
+ protected static final String GL_EXT_framebuffer_object = "GL_EXT_framebuffer_object";
+ protected static final String GL_EXT_framebuffer_blit = "GL_EXT_framebuffer_blit";
+ protected static final String GL_EXT_framebuffer_multisample = "GL_EXT_framebuffer_multisample";
+ protected static final String GL_EXT_packed_depth_stencil = "GL_EXT_packed_depth_stencil";
+ protected static final String GL_ARB_texture_non_power_of_two = "GL_ARB_texture_non_power_of_two";
+ protected static final String GL_EXT_texture_format_BGRA8888 = "GL_EXT_texture_format_BGRA8888";
+ protected static final String GL_IMG_texture_format_BGRA8888 = "GL_IMG_texture_format_BGRA8888";
+
+ private static final ThreadLocal<GLContext> currentContext = new ThreadLocal<GLContext>();
+
+ private final HashMap<String, Object> attachedObjectsByString = new HashMap<String, Object>();
+ private final IntObjectHashMap attachedObjectsByInt = new IntObjectHashMap();
// RecursiveLock maintains a queue of waiting Threads, ensuring the longest waiting thread will be notified at unlock.
- protected RecursiveLock lock = LockFactory.createRecursiveLock();
+ protected final RecursiveLock lock = LockFactory.createRecursiveLock();
/** The underlying native OpenGL context */
protected long contextHandle;
@@ -137,36 +154,74 @@ public abstract class GLContext {
}
/**
- * Returns the GLDrawable to which this context may be used to
- * draw.
+ * Sets the read/write drawable for framebuffer operations.
+ * <p>
+ * If the context was current on this thread, it is being released before switching the drawable
+ * and made current afterwards. However the user shall take extra care that not other thread
+ * attempts to make this context current. Otherwise a race condition may happen.
+ * </p>
+ * <p>
+ * <b>Disclaimer</b>: Even though the API may allows this functionality in theory, your mileage may vary
+ * switching the drawable of an already established GLContext, i.e. which is already made current once.
+ * FIXME: Validate functionality!
+ * </p>
+ * @param readWrite the read/write drawable for framebuffer operations.
+ * @param setWriteOnly if <code>true</code> and if the current read-drawable differs
+ * from the write-drawable ({@link #setGLReadDrawable(GLDrawable)}),
+ * only change the write-drawable. Otherwise set both drawables.
+ * @return the replaced read/write drawable
+ *
+ * @throws GLException in case <code>null</code> is being passed or
+ * this context is made current on another thread.
+ *
+ * @see #isGLReadDrawableAvailable()
+ * @see #getGLReadDrawable()
+ * @see #setGLReadDrawable()
+ * @see #getGLDrawable()
+ */
+ public abstract GLDrawable setGLDrawable(GLDrawable readWrite, boolean setWriteOnly);
+
+ /**
+ * Returns the write-drawable this context uses for framebuffer operations.
*/
public abstract GLDrawable getGLDrawable();
/**
- * Return availability of GL read drawable.
- * @return true if a GL read drawable is supported with your driver, otherwise false.
+ * Query whether using a distinguished read-drawable is supported.
+ * @return true if using a read-drawable is supported with your driver/OS, otherwise false.
*/
public abstract boolean isGLReadDrawableAvailable();
/**
- * Set the read GLDrawable for read framebuffer operations.<br>
+ * Set the read-Drawable for read framebuffer operations.<br>
* The caller should query if this feature is supported via {@link #isGLReadDrawableAvailable()}.
+ * <p>
+ * If the context was current on this thread, it is being released before switching the drawable
+ * and made current afterwards. However the user shall take extra care that not other thread
+ * attempts to make this context current. Otherwise a race condition may happen.
+ * </p>
*
- * @param read the read GLDrawable for read framebuffer operations.
- * If null is passed, the default write drawable will be set.
+ * @param read the read-drawable for read framebuffer operations.
+ * If null is passed, the default write drawable will be set.
+ * @return the replaced read-drawable
*
- * @throws GLException in case a read drawable is not supported
- * and the given drawable is not null and not equal to the internal write drawable.
+ * @throws GLException in case a read drawable is not supported or
+ * this context is made current on another thread.
*
* @see #isGLReadDrawableAvailable()
* @see #getGLReadDrawable()
*/
- public abstract void setGLReadDrawable(GLDrawable read);
+ public abstract GLDrawable setGLReadDrawable(GLDrawable read);
/**
- * Returns the read GLDrawable this context uses for read framebuffer operations.
+ * Returns the read-Drawable this context uses for read framebuffer operations.
+ * <p>
+ * If the read-drawable has not been changed manually via {@link #setGLReadDrawable(GLDrawable)},
+ * it equals to the write-drawable (default).
+ * </p>
* @see #isGLReadDrawableAvailable()
* @see #setGLReadDrawable(javax.media.opengl.GLDrawable)
+ * @see #getGLDrawable()
*/
public abstract GLDrawable getGLReadDrawable();
@@ -190,7 +245,7 @@ public abstract class GLContext {
* </p>
* <p>
* This method is blocking, i.e. waits until another thread has
- * released the context.
+ * released the context.
* </p>
* <p>
* The drawable's surface is being locked at entry
@@ -547,6 +602,28 @@ public abstract class GLContext {
return 0 != ( ctxOptions & CTX_IMPL_ES2_COMPAT ) ;
}
+ /**
+ * @return true if impl. is a hardware rasterizer, otherwise false.
+ * @see GLProfile#isHardwareRasterizer()
+ */
+ public final boolean isHardwareRasterizer() {
+ return 0 == ( ctxOptions & CTX_IMPL_ACCEL_SOFT ) ;
+ }
+
+ /** Returns whether the context supports FBO, hence is either GL-ES >= 2.0, >= core GL 3.0 or implements the extensions
+ * <code>GL_ARB_ES2_compatibility</code>, <code>ARB_framebuffer_object</code> or all of
+ * <code>EXT_framebuffer_object</code>, <code>EXT_framebuffer_multisample</code>,
+ * <code>EXT_framebuffer_blit</code>, <code>GL_EXT_packed_depth_stencil</code>.
+ * @see #CTX_IMPL_FBO
+ */
+ public final boolean hasFBO() {
+ return 0 != ( ctxOptions & CTX_IMPL_FBO ) ;
+ }
+
+ /**
+ * @return true if context supports GLSL
+ * @see GLProfile#hasGLSL()
+ */
public final boolean hasGLSL() {
return isGL2ES2() ;
}
@@ -555,60 +632,70 @@ public abstract class GLContext {
public boolean isNPOTTextureAvailable() {
return isGL3() || isGLES2Compatible() || isExtensionAvailable(GL_ARB_texture_non_power_of_two);
}
- private static final String GL_ARB_texture_non_power_of_two = "GL_ARB_texture_non_power_of_two";
public boolean isTextureFormatBGRA8888Available() {
return isGL2GL3() ||
- isExtensionAvailable("GL_EXT_texture_format_BGRA8888") ||
- isExtensionAvailable("GL_IMG_texture_format_BGRA8888") ;
+ isExtensionAvailable(GL_EXT_texture_format_BGRA8888) ||
+ isExtensionAvailable(GL_IMG_texture_format_BGRA8888) ;
}
+ /** @see GLProfile#isGL4bc() */
public final boolean isGL4bc() {
return ctxMajorVersion>=4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED)
&& 0 != (ctxOptions & CTX_PROFILE_COMPAT);
}
+ /** @see GLProfile#isGL4() */
public final boolean isGL4() {
return ctxMajorVersion>=4 && 0 != (ctxOptions & CTX_IS_ARB_CREATED)
&& 0 != (ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_CORE));
}
+ /** @see GLProfile#isGL3bc() */
public final boolean isGL3bc() {
return ( ctxMajorVersion>3 || ctxMajorVersion==3 && ctxMinorVersion>=1 )
&& 0 != (ctxOptions & CTX_IS_ARB_CREATED)
&& 0 != (ctxOptions & CTX_PROFILE_COMPAT);
}
+ /** @see GLProfile#isGL3() */
public final boolean isGL3() {
return ( ctxMajorVersion>3 || ctxMajorVersion==3 && ctxMinorVersion>=1 )
&& 0 != (ctxOptions & CTX_IS_ARB_CREATED)
&& 0 != (ctxOptions & (CTX_PROFILE_COMPAT|CTX_PROFILE_CORE));
}
-
+
+ /** @see GLProfile#isGL2() */
public final boolean isGL2() {
return ctxMajorVersion>=1 && 0!=(ctxOptions & CTX_PROFILE_COMPAT);
}
+ /** @see GLProfile#isGL2GL3() */
public final boolean isGL2GL3() {
return isGL2() || isGL3();
}
+ /** @see GLProfile#isGLES1() */
public final boolean isGLES1() {
return ctxMajorVersion==1 && 0 != ( ctxOptions & CTX_PROFILE_ES ) ;
}
+ /** @see GLProfile#isGLES2() */
public final boolean isGLES2() {
return ctxMajorVersion==2 && 0 != ( ctxOptions & CTX_PROFILE_ES ) ;
}
+ /** @see GLProfile#isGLES() */
public final boolean isGLES() {
return 0 != ( CTX_PROFILE_ES & ctxOptions ) ;
}
+ /** @see GLProfile#isGL2ES1() */
public final boolean isGL2ES1() {
return isGL2() || isGLES1() ;
}
+ /** @see GLProfile#isGL2ES2() */
public final boolean isGL2ES2() {
return isGL2GL3() || isGLES2() ;
}
@@ -846,8 +933,11 @@ public abstract class GLContext {
*/
private static /*final*/ HashSet<String> deviceVersionsAvailableSet = new HashSet<String>();
- protected static String getDeviceVersionAvailableKey(AbstractGraphicsDevice device, int major, int profile) {
- return device.getUniqueID() + "-" + toHexString(composeBits(major, profile, 0));
+ /** clears the device/context mappings as well as the GL/GLX proc address tables. */
+ protected static void shutdown() {
+ deviceVersionAvailable.clear();
+ deviceVersionsAvailableSet.clear();
+ GLContextImpl.shutdownImpl(); // well ..
}
protected static boolean getAvailableGLVersionsSet(AbstractGraphicsDevice device) {
@@ -869,11 +959,8 @@ public abstract class GLContext {
}
}
- /** clears the device/context mappings as well as the GL/GLX proc address tables. */
- protected static void shutdown() {
- deviceVersionAvailable.clear();
- deviceVersionsAvailableSet.clear();
- GLContextImpl.shutdownImpl(); // well ..
+ protected static String getDeviceVersionAvailableKey(AbstractGraphicsDevice device, int major, int profile) {
+ return device.getUniqueID() + "-" + toHexString(composeBits(major, profile, 0));
}
/**
@@ -967,18 +1054,71 @@ public abstract class GLContext {
}
/**
+ * Returns the GLProfile's major version number and it's context property (CTP) for availability mapping request.
+ */
+ protected static final void getRequestMajorAndCompat(final GLProfile glp, int[/*2*/] reqMajorCTP) {
+ final GLProfile glpImpl = glp.getImpl();
+ if(glpImpl.isGL4()) {
+ reqMajorCTP[0]=4;
+ } else if (glpImpl.isGL3()) {
+ reqMajorCTP[0]=3;
+ } else /* if (glpImpl.isGL2()) */ {
+ reqMajorCTP[0]=2;
+ }
+ if( glpImpl.isGL2() ) { // incl GL3bc and GL4bc
+ reqMajorCTP[1]=CTX_PROFILE_COMPAT;
+ } else {
+ reqMajorCTP[1]=CTX_PROFILE_CORE;
+ }
+ }
+
+ /**
+ * @param device the device the context profile is being requested for
+ * @param GLProfile the GLProfile the context profile is being requested for
+ * @return the GLProfile's context property (CTP) if available, otherwise <code>0</code>
+ */
+ protected static final int getAvailableContextProperties(final AbstractGraphicsDevice device, final GLProfile glp) {
+ final int[] reqMajorCTP = new int[] { 0, 0 };
+ getRequestMajorAndCompat(glp, reqMajorCTP);
+
+ int _major[] = { 0 };
+ int _minor[] = { 0 };
+ int _ctp[] = { 0 };
+ if( GLContext.getAvailableGLVersion(device, reqMajorCTP[0], reqMajorCTP[1],
+ _major, _minor, _ctp)) {
+ return _ctp[0];
+ }
+ return 0; // n/a
+ }
+
+ /**
+ * @param device the device the profile is being requested
* @param major Key Value either 1, 2, 3 or 4
* @param profile Key Value either {@link #CTX_PROFILE_COMPAT}, {@link #CTX_PROFILE_CORE} or {@link #CTX_PROFILE_ES}
- * @return the highest GLProfile string regarding the version and profile bits.
- * @throws GLException if version and context profile bits could not be mapped to a GLProfile
+ * @return the highest GLProfile regarding availability, version and profile bits.
*/
- public static String getAvailableGLProfile(AbstractGraphicsDevice device, int reqMajor, int reqProfile)
+ protected static GLProfile getAvailableGLProfile(AbstractGraphicsDevice device, int reqMajor, int reqProfile)
throws GLException {
int major[] = { 0 };
int minor[] = { 0 };
int ctp[] = { 0 };
if(GLContext.getAvailableGLVersion(device, reqMajor, reqProfile, major, minor, ctp)) {
- return GLContext.getGLProfile(major[0], minor[0], ctp[0]);
+ return GLProfile.get(GLContext.getGLProfile(major[0], minor[0], ctp[0]));
+ }
+ return null;
+ }
+
+ /**
+ * @param device the device the profile is being requested
+ * @param major Key Value either 1, 2, 3 or 4
+ * @param profile Key Value either {@link #CTX_PROFILE_COMPAT}, {@link #CTX_PROFILE_CORE} or {@link #CTX_PROFILE_ES}
+ */
+ protected static String getAvailableGLVersionAsString(AbstractGraphicsDevice device, int major, int profile) {
+ int _major[] = { 0 };
+ int _minor[] = { 0 };
+ int _ctp[] = { 0 };
+ if(getAvailableGLVersion(device, major, profile, _major, _minor, _ctp)) {
+ return getGLVersion(_major[0], _minor[0], _ctp[0], null);
}
return null;
}
@@ -990,7 +1130,7 @@ public abstract class GLContext {
* @param isHardware return value of one boolean, whether the profile is a hardware rasterizer or not
* @return true if the requested GL version is available regardless of a software or hardware rasterizer, otherwise false.
*/
- public static boolean isGLVersionAvailable(AbstractGraphicsDevice device, int reqMajor, int reqProfile, boolean isHardware[]) {
+ protected static boolean isGLVersionAvailable(AbstractGraphicsDevice device, int reqMajor, int reqProfile, boolean isHardware[]) {
Integer valI = getAvailableGLVersion(device, reqMajor, reqProfile);
if(null==valI) {
return false;
@@ -1027,21 +1167,7 @@ public abstract class GLContext {
return isGLVersionAvailable(device, 2, CTX_PROFILE_COMPAT, isHardware);
}
- /**
- * @param major Key Value either 1, 2, 3 or 4
- * @param profile Key Value either {@link #CTX_PROFILE_COMPAT}, {@link #CTX_PROFILE_CORE} or {@link #CTX_PROFILE_ES}
- */
- public static String getAvailableGLVersionAsString(AbstractGraphicsDevice device, int major, int profile) {
- int _major[] = { 0 };
- int _minor[] = { 0 };
- int _ctp[] = { 0 };
- if(getAvailableGLVersion(device, major, profile, _major, _minor, _ctp)) {
- return getGLVersion(_major[0], _minor[0], _ctp[0], null);
- }
- return null;
- }
-
- public static String getGLVersion(int major, int minor, int ctp, String gl_version) {
+ protected static String getGLVersion(int major, int minor, int ctp, String gl_version) {
boolean needColon = false;
StringBuilder sb = new StringBuilder();
sb.append(major);
@@ -1055,6 +1181,7 @@ public abstract class GLContext {
needColon = appendString(sb, "arb", needColon, 0 != ( CTX_IS_ARB_CREATED & ctp ));
needColon = appendString(sb, "debug", needColon, 0 != ( CTX_OPTION_DEBUG & ctp ));
needColon = appendString(sb, "ES2 compatible", needColon, 0 != ( CTX_IMPL_ES2_COMPAT & ctp ));
+ needColon = appendString(sb, "FBO", needColon, 0 != ( CTX_IMPL_FBO & ctp ));
if( 0 != ( CTX_IMPL_ACCEL_SOFT & ctp ) ) {
needColon = appendString(sb, "software", needColon, true);
} else {
diff --git a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
index 1093685d6..d6480e7aa 100644
--- a/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
+++ b/src/jogl/classes/javax/media/opengl/GLDrawableFactory.java
@@ -492,6 +492,23 @@ public abstract class GLDrawableFactory {
GLContext shareWith)
throws GLException;
+ /**
+ * Returns true if it is possible to create an <i>framebuffer object</i> (FBO).
+ * <p>
+ * FBO feature is implemented in OpenGL, hence it is {@link GLProfile} dependent.
+ * </p>
+ * <p>
+ * FBO support is queried as described in {@link GLContext#hasFBO()}.
+ * </p>
+ *
+ * @param device which {@link javax.media.nativewindow.AbstractGraphicsDevice#getConnection() connection} denotes the shared the target device, may be <code>null</code> for the platform's default device.
+ * @param glp {@link GLProfile} to check for FBO capabilities
+ * @see GLContext#hasFBO()
+ */
+ public final boolean canCreateFBO(AbstractGraphicsDevice device, GLProfile glp) {
+ return 0 != ( GLContext.CTX_IMPL_FBO & GLContext.getAvailableContextProperties(device, glp) );
+ }
+
//----------------------------------------------------------------------
// Methods for interacting with third-party OpenGL libraries
diff --git a/src/jogl/classes/javax/media/opengl/GLProfile.java b/src/jogl/classes/javax/media/opengl/GLProfile.java
index ed457b0ea..cc4f6c517 100644
--- a/src/jogl/classes/javax/media/opengl/GLProfile.java
+++ b/src/jogl/classes/javax/media/opengl/GLProfile.java
@@ -113,9 +113,7 @@ public class GLProfile {
* @param firstUIActionOnProcess Should be <code>true</code> if called before the first UI action of the running program,
* otherwise <code>false</code>.
*
- * @deprecated This method shall not need to be called for other reasons than having a defined initialization sequence.
- * To ensure homogeneous behavior with application not calling this method, you shall pass <code>firstUIActionOnProcess=false</code>.
- * This method is subject to be removed in future versions of JOGL.
+ * @deprecated Use {@link #initSingleton()}. This method is subject to be removed in future versions of JOGL.
*/
public static void initSingleton(final boolean firstUIActionOnProcess) {
initLock.lock();
@@ -1003,6 +1001,11 @@ public class GLProfile {
public final boolean isGLES2() {
return GLES2 == profile;
}
+
+ /** Indicates whether this profile is capable of GLES. <p>Includes [ GLES1, GLES2 ].</p> */
+ public final boolean isGLES() {
+ return GLES2 == profile || GLES1 == profile;
+ }
/** Indicates whether this profile is capable of GL2ES1. <p>Includes [ GL4bc, GL3bc, GL2, GLES1, GL2ES1 ].</p> */
public final boolean isGL2ES1() {
diff --git a/src/jogl/classes/jogamp/opengl/GLContextImpl.java b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
index 4ef8b9750..7362a2bd8 100644
--- a/src/jogl/classes/jogamp/opengl/GLContextImpl.java
+++ b/src/jogl/classes/jogamp/opengl/GLContextImpl.java
@@ -161,18 +161,22 @@ public abstract class GLContextImpl extends GLContext {
}
@Override
- public final void setGLReadDrawable(GLDrawable read) {
- if(null!=read && drawable!=read && !isGLReadDrawableAvailable()) {
- throw new GLException("GL Read Drawable not available");
+ public final GLDrawable setGLReadDrawable(GLDrawable read) {
+ if(!isGLReadDrawableAvailable()) {
+ throw new GLException("Setting read drawable feature not available");
}
final boolean lockHeld = lock.isOwner(Thread.currentThread());
if(lockHeld) {
release();
+ } else if(lock.isLockedByOtherThread()) { // still could glitch ..
+ throw new GLException("GLContext current by other thread ("+lock.getOwner()+"), operation not allowed.");
}
+ final GLDrawable old = drawableRead;
drawableRead = ( null != read ) ? (GLDrawableImpl) read : drawable;
if(lockHeld) {
makeCurrent();
}
+ return old;
}
@Override
@@ -181,6 +185,28 @@ public abstract class GLContextImpl extends GLContext {
}
@Override
+ public final GLDrawable setGLDrawable(GLDrawable readWrite, boolean setWriteOnly) {
+ if(null==readWrite) {
+ throw new GLException("Null read/write drawable not allowed");
+ }
+ final boolean lockHeld = lock.isOwner(Thread.currentThread());
+ if(lockHeld) {
+ release();
+ } else if(lock.isLockedByOtherThread()) { // still could glitch ..
+ throw new GLException("GLContext current by other thread ("+lock.getOwner()+"), operation not allowed.");
+ }
+ if(!setWriteOnly || drawableRead==drawable) { // if !setWriteOnly || !explicitReadDrawable
+ drawableRead = (GLDrawableImpl) readWrite;
+ }
+ final GLDrawable old = drawable;
+ drawable = ( null != readWrite ) ? (GLDrawableImpl) readWrite : null;
+ if(lockHeld) {
+ makeCurrent();
+ }
+ return old;
+ }
+
+ @Override
public final GLDrawable getGLDrawable() {
return drawable;
}
@@ -630,13 +656,10 @@ public abstract class GLContextImpl extends GLContext {
* @see #createContextARBImpl
* @see #destroyContextARBImpl
*/
- protected final long createContextARB(long share, boolean direct)
+ protected final long createContextARB(final long share, final boolean direct)
{
- AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration();
- AbstractGraphicsDevice device = config.getScreen().getDevice();
- GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
- GLProfile glp = glCaps.getGLProfile();
- GLProfile glpImpl = glp.getImpl();
+ final AbstractGraphicsConfiguration config = drawable.getNativeSurface().getGraphicsConfiguration();
+ final AbstractGraphicsDevice device = config.getScreen().getDevice();
if (DEBUG) {
System.err.println(getThreadName() + ": createContextARB: mappedVersionsAvailableSet("+device.getConnection()+"): "+
@@ -650,22 +673,15 @@ public abstract class GLContextImpl extends GLContext {
}
}
- int reqMajor;
- if(glpImpl.isGL4()) {
- reqMajor=4;
- } else if (glpImpl.isGL3()) {
- reqMajor=3;
- } else /* if (glpImpl.isGL2()) */ {
- reqMajor=2;
- }
-
- boolean compat = glpImpl.isGL2(); // incl GL3bc and GL4bc
+ final GLCapabilitiesImmutable glCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
+ final int[] reqMajorCTP = new int[] { 0, 0 };
+ getRequestMajorAndCompat(glCaps.getGLProfile(), reqMajorCTP);
+
int _major[] = { 0 };
int _minor[] = { 0 };
int _ctp[] = { 0 };
long _ctx = 0;
-
- if( GLContext.getAvailableGLVersion(device, reqMajor, compat?CTX_PROFILE_COMPAT:CTX_PROFILE_CORE,
+ if( GLContext.getAvailableGLVersion(device, reqMajorCTP[0], reqMajorCTP[1],
_major, _minor, _ctp)) {
_ctp[0] |= additionalCtxCreationFlags;
_ctx = createContextARBImpl(share, direct, _ctp[0], _major[0], _minor[0]);
@@ -675,7 +691,7 @@ public abstract class GLContextImpl extends GLContext {
}
return _ctx;
}
-
+
private final boolean mapGLVersions(AbstractGraphicsDevice device) {
synchronized (GLContext.deviceVersionAvailable) {
boolean success = false;
@@ -698,10 +714,11 @@ public abstract class GLContextImpl extends GLContext {
private final boolean createContextARBMapVersionsAvailable(int reqMajor, boolean compat) {
long _context;
int reqProfile = compat ? CTX_PROFILE_COMPAT : CTX_PROFILE_CORE ;
- int ctp = CTX_IS_ARB_CREATED | CTX_PROFILE_CORE; // default
+ int ctp = CTX_IS_ARB_CREATED;
if(compat) {
- ctp &= ~CTX_PROFILE_CORE ;
- ctp |= CTX_PROFILE_COMPAT ;
+ ctp |= CTX_PROFILE_COMPAT ;
+ } else {
+ ctp |= CTX_PROFILE_CORE ;
}
// To ensure GL profile compatibility within the JOGL application
@@ -1070,10 +1087,15 @@ public abstract class GLContextImpl extends GLContext {
}
}
}
- if( isExtensionAvailable("GL_ARB_ES2_compatibility") ) {
+
+ if( 0 != ( CTX_PROFILE_ES & ctxProfileBits ) && ctxMajorVersion >= 2 ||
+ isExtensionAvailable(GL_ARB_ES2_compatibility) ) {
ctxProfileBits |= CTX_IMPL_ES2_COMPAT;
+ ctxProfileBits |= CTX_IMPL_FBO;
+ } else if( hasFBOImpl(ctxMajorVersion, ctxProfileBits, extensionAvailability) ) {
+ ctxProfileBits |= CTX_IMPL_FBO;
}
-
+
//
// Set GL Version (complete w/ version string)
//
@@ -1081,7 +1103,24 @@ public abstract class GLContextImpl extends GLContext {
setDefaultSwapInterval();
}
-
+
+ protected static final boolean hasFBOImpl(int ctxMajorVersion, int ctxProfileBits, ExtensionAvailabilityCache extCache) {
+ return ( ctxMajorVersion >= 3 ) || // any >= 3.0 GL ctx
+
+ ( 0 != (ctxProfileBits & CTX_PROFILE_ES) && ctxMajorVersion >= 2 ) || // ES >= 2.0
+
+ ( null != extCache &&
+
+ ( extCache.isExtensionAvailable(GL_ARB_ES2_compatibility) ) || // ES 2.0 compatible
+
+ ( extCache.isExtensionAvailable(GL_ARB_framebuffer_object) ) || // ARB_framebuffer_object
+
+ ( extCache.isExtensionAvailable(GL_EXT_framebuffer_object) && // EXT_framebuffer_object*
+ extCache.isExtensionAvailable(GL_EXT_framebuffer_multisample) &&
+ extCache.isExtensionAvailable(GL_EXT_framebuffer_blit) &&
+ extCache.isExtensionAvailable(GL_EXT_packed_depth_stencil) ) );
+ }
+
protected final void removeCachedVersion(int major, int minor, int ctxProfileBits) {
if(!isCurrentContextHardwareRasterizer()) {
ctxProfileBits |= GLContext.CTX_IMPL_ACCEL_SOFT;
@@ -1212,7 +1251,7 @@ public abstract class GLContextImpl extends GLContext {
protected static String getContextFQN(AbstractGraphicsDevice device, int major, int minor, int ctxProfileBits) {
// remove non-key values
- ctxProfileBits &= ~( GLContext.CTX_OPTION_DEBUG | GLContext.CTX_IMPL_ES2_COMPAT ) ;
+ ctxProfileBits &= ~( GLContext.CTX_OPTION_DEBUG | GLContext.CTX_IMPL_ES2_COMPAT | GLContext.CTX_IMPL_FBO ) ;
return device.getUniqueID() + "-" + toHexString(composeBits(major, minor, ctxProfileBits));
}
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
index 06cd550b4..65a4c3ece 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLContext.java
@@ -224,15 +224,7 @@ public abstract class EGLContext extends GLContextImpl {
throw new GLException("Error making context 0x" +
Long.toHexString(contextHandle) + " current: error code " + EGL.eglGetError());
}
- int ctp = CTX_PROFILE_ES;
- int major;
- if(glProfile.usesNativeGLES2()) {
- ctp |= CTX_IMPL_ES2_COMPAT;
- major = 2;
- } else {
- major = 1;
- }
- setGLFunctionAvailability(true, major, 0, ctp);
+ setGLFunctionAvailability(true, glProfile.usesNativeGLES2() ? 2 : 1, 0, CTX_PROFILE_ES);
return true;
}
diff --git a/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java
index 0a451e5eb..585638d21 100644
--- a/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java
+++ b/src/jogl/classes/jogamp/opengl/egl/EGLExternalContext.java
@@ -45,7 +45,7 @@ public class EGLExternalContext extends EGLContext {
public EGLExternalContext(AbstractGraphicsScreen screen) {
super(null, null);
GLContextShareSet.contextCreated(this);
- setGLFunctionAvailability(false, 0, 0, CTX_IS_ARB_CREATED|CTX_PROFILE_ES);
+ setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_ES);
getGLStateTracker().setEnabled(false); // external context usage can't track state in Java
}
diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
index 96baab3ae..5cc0d765c 100644
--- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
+++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java
@@ -531,7 +531,7 @@ public class GLWindow extends GLAutoDrawableBase implements GLAutoDrawable, Wind
return;
}
- window.lockWindow(); // sync: context/drawable could been recreated/destroyed while animating
+ window.lockWindow(); // sync: context/drawable could have been recreated/destroyed while animating
try {
if( null == context && 0<getWidth()*getHeight() ) {
// retry drawable and context creation
diff --git a/src/newt/classes/jogamp/newt/WindowImpl.java b/src/newt/classes/jogamp/newt/WindowImpl.java
index 45745e89c..e49f91abd 100644
--- a/src/newt/classes/jogamp/newt/WindowImpl.java
+++ b/src/newt/classes/jogamp/newt/WindowImpl.java
@@ -1233,6 +1233,8 @@ public abstract class WindowImpl implements Window, NEWTEventConsumer
// This may run on the new Display/Screen connection, hence a new EDT task
runOnEDTIfAvail(true, reparentActionRecreate);
break;
+
+ default:
}
}
if(DEBUG_IMPLEMENTATION) {
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitchNEWT.java b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitchNEWT.java
new file mode 100644
index 000000000..483a09735
--- /dev/null
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/acore/TestGLContextDrawableSwitchNEWT.java
@@ -0,0 +1,322 @@
+/**
+ * Copyright 2010 JogAmp Community. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification, are
+ * permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice, this list of
+ * conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright notice, this list
+ * of conditions and the following disclaimer in the documentation and/or other materials
+ * provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+ * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * The views and conclusions contained in the software and documentation are those of the
+ * authors and should not be interpreted as representing official policies, either expressed
+ * or implied, of JogAmp Community.
+ */
+
+package com.jogamp.opengl.test.junit.jogl.acore;
+
+import java.io.IOException;
+
+import com.jogamp.newt.NewtFactory;
+import com.jogamp.newt.Window;
+import com.jogamp.newt.event.WindowAdapter;
+import com.jogamp.newt.event.WindowEvent;
+import com.jogamp.newt.event.WindowListener;
+import com.jogamp.newt.event.WindowUpdateEvent;
+import com.jogamp.newt.opengl.GLWindow;
+
+import javax.media.opengl.GLAutoDrawable;
+import javax.media.opengl.GLAutoDrawableDelegate;
+import javax.media.opengl.GLCapabilities;
+import javax.media.opengl.GLContext;
+import javax.media.opengl.GLDrawable;
+import javax.media.opengl.GLDrawableFactory;
+import javax.media.opengl.GLEventListener;
+import javax.media.opengl.GLProfile;
+import com.jogamp.opengl.util.Animator;
+
+import com.jogamp.opengl.test.junit.jogl.demos.es2.GearsES2;
+import com.jogamp.opengl.test.junit.jogl.demos.es2.RedSquareES2;
+import com.jogamp.opengl.test.junit.util.AWTRobotUtil;
+import com.jogamp.opengl.test.junit.util.QuitAdapter;
+import com.jogamp.opengl.test.junit.util.UITestCase;
+
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestGLContextDrawableSwitchNEWT extends UITestCase {
+ static GLProfile glp;
+ static GLCapabilities caps;
+ static int width, height;
+
+ @BeforeClass
+ public static void initClass() {
+ glp = GLProfile.getGL2ES2();
+ caps = new GLCapabilities(glp);
+ width = 256;
+ height = 256;
+ }
+
+ /** Note: No GLContext is attached w/ this implementation ! */
+ private GLAutoDrawable createGLAutoDrawable(GLCapabilities caps, int x, int y, int width, int height, WindowListener wl) throws InterruptedException {
+ final Window window = NewtFactory.createWindow(caps);
+ Assert.assertNotNull(window);
+ window.setPosition(x, y);
+ window.setSize(width, height);
+ window.setVisible(true);
+ Assert.assertTrue(AWTRobotUtil.waitForVisible(window, true));
+ Assert.assertTrue(AWTRobotUtil.waitForRealized(window, true));
+
+ GLDrawableFactory factory = GLDrawableFactory.getFactory(caps.getGLProfile());
+ GLDrawable drawable = factory.createGLDrawable(window);
+ Assert.assertNotNull(drawable);
+
+ drawable.setRealized(true);
+ Assert.assertTrue(drawable.isRealized());
+
+ final GLAutoDrawableDelegate glad = new GLAutoDrawableDelegate(drawable, null) {
+ @Override
+ public void destroy() {
+ super.destroy(); // destroys drawable/context
+ window.destroy(); // destroys the actual window
+ }
+ };
+
+ // add basic window interaction
+ window.addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowRepaint(WindowUpdateEvent e) {
+ glad.defaultWindowRepaintOp();
+ }
+ @Override
+ public void windowResized(WindowEvent e) {
+ glad.defaultWindowResizedOp();
+ }
+ @Override
+ public void windowDestroyNotify(WindowEvent e) {
+ glad.defaultWindowDestroyNotifyOp();
+ }
+ });
+ window.addWindowListener(wl);
+
+ return glad;
+ }
+
+ @Test(timeout=30000)
+ public void testSwitch2WindowSingleContext() throws InterruptedException {
+ final QuitAdapter quitAdapter = new QuitAdapter();
+
+ GLAutoDrawable glad1 = createGLAutoDrawable(caps, 64, 64, width, height, quitAdapter); // no GLContext!
+ GLAutoDrawable glad2 = createGLAutoDrawable(caps, 2*64+width, 64, width+100, height+100, quitAdapter); // no GLContext!
+
+ // create single context using glad1 and assign it to glad1
+ {
+ GLContext singleCtx = glad1.createContext(null);
+ Assert.assertNotNull(singleCtx);
+ int res = singleCtx.makeCurrent();
+ Assert.assertTrue(GLContext.CONTEXT_CURRENT_NEW==res || GLContext.CONTEXT_CURRENT==res);
+ singleCtx.release();
+ glad1.setContext(singleCtx);
+ }
+
+ GearsES2 gears = new GearsES2(1);
+ glad1.addGLEventListener(gears);
+
+ Animator animator = new Animator();
+ animator.add(glad1);
+ animator.add(glad2);
+ animator.start();
+
+ int s = 0;
+ long t0 = System.currentTimeMillis();
+ long t1 = t0;
+
+ while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) {
+ if( ( t1 - t0 ) / period > s) {
+ s++;
+ System.err.println(s+" - switch - START "+ ( t1 - t0 ));
+ animator.pause();
+
+ if(0 == s%2) {
+ glad1.addGLEventListener(0, glad2.removeGLEventListener(0));
+ GLContext ctx1 = glad1.setContext(glad2.getContext());
+ glad2.setContext(ctx1);
+ } else {
+ glad2.addGLEventListener(0, glad1.removeGLEventListener(0));
+ GLContext ctx2 = glad2.setContext(glad1.getContext());
+ glad1.setContext(ctx2);
+ }
+
+ System.err.println(s+" - switch - END "+ ( t1 - t0 ));
+
+ animator.resume();
+ }
+ Thread.sleep(100);
+ t1 = System.currentTimeMillis();
+ }
+
+ animator.stop();
+ glad1.destroy();
+ glad2.destroy();
+ }
+
+ @Test(timeout=30000)
+ public void testSwitch2GLWindowOneDemo() throws InterruptedException {
+ GearsES2 gears = new GearsES2(1);
+ final QuitAdapter quitAdapter = new QuitAdapter();
+
+ GLWindow glWindow1 = GLWindow.create(caps);
+ glWindow1.setTitle("win1");
+ glWindow1.setSize(width, height);
+ glWindow1.setPosition(64, 64);
+ glWindow1.addGLEventListener(0, gears);
+ glWindow1.addWindowListener(quitAdapter);
+
+ GLWindow glWindow2 = GLWindow.create(caps);
+ glWindow2.setTitle("win2");
+ glWindow2.setSize(width+100, height+100);
+ glWindow2.setPosition(2*64+width, 64);
+ glWindow2.addWindowListener(quitAdapter);
+
+ Animator animator = new Animator();
+ animator.add(glWindow1);
+ animator.add(glWindow2);
+ animator.start();
+
+ glWindow1.setVisible(true);
+ glWindow2.setVisible(true);
+
+ int s = 0;
+ long t0 = System.currentTimeMillis();
+ long t1 = t0;
+
+ while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) {
+ if( ( t1 - t0 ) / period > s) {
+ s++;
+ System.err.println(s+" - switch - START "+ ( t1 - t0 ));
+ animator.pause();
+
+ if(0 == s%2) {
+ glWindow1.addGLEventListener(0, glWindow2.removeGLEventListener(0));
+ GLContext ctx1 = glWindow1.setContext(glWindow2.getContext());
+ glWindow2.setContext(ctx1);
+ } else {
+ glWindow2.addGLEventListener(0, glWindow1.removeGLEventListener(0));
+ GLContext ctx2 = glWindow2.setContext(glWindow1.getContext());
+ glWindow1.setContext(ctx2);
+ }
+
+ System.err.println(s+" - switch - END "+ ( t1 - t0 ));
+
+ animator.resume();
+ }
+ Thread.sleep(100);
+ t1 = System.currentTimeMillis();
+ }
+
+ animator.stop();
+ glWindow1.destroy();
+ glWindow2.destroy();
+
+ }
+
+ @Test(timeout=30000)
+ public void testSwitch2GLWindowEachWithOwnDemo() throws InterruptedException {
+ GearsES2 gears = new GearsES2(1);
+ RedSquareES2 rsquare = new RedSquareES2(1);
+ final QuitAdapter quitAdapter = new QuitAdapter();
+
+ GLWindow glWindow1 = GLWindow.create(caps);
+ glWindow1.setTitle("win1");
+ glWindow1.setSize(width, height);
+ glWindow1.setPosition(64, 64);
+ glWindow1.addGLEventListener(0, gears);
+ glWindow1.addWindowListener(quitAdapter);
+
+ GLWindow glWindow2 = GLWindow.create(caps);
+ glWindow2.setTitle("win2");
+ glWindow2.setSize(width+100, height+100);
+ glWindow2.setPosition(2*64+width, 64);
+ glWindow2.addGLEventListener(0, rsquare);
+ glWindow2.addWindowListener(quitAdapter);
+
+ Animator animator = new Animator();
+ animator.add(glWindow1);
+ animator.add(glWindow2);
+ animator.start();
+
+ glWindow1.setVisible(true);
+ glWindow2.setVisible(true);
+
+ int s = 0;
+ long t0 = System.currentTimeMillis();
+ long t1 = t0;
+
+ while( !quitAdapter.shouldQuit() && ( t1 - t0 ) < duration ) {
+ if( ( t1 - t0 ) / period > s) {
+ s++;
+ System.err.println(s+" - switch - START "+ ( t1 - t0 ));
+ animator.pause();
+
+ GLEventListener demo1 = glWindow1.removeGLEventListener(0);
+ GLEventListener demo2 = glWindow2.removeGLEventListener(0);
+
+ GLContext ctx1 = glWindow1.setContext(glWindow2.getContext());
+ glWindow1.addGLEventListener(0, demo2);
+
+ glWindow2.setContext(ctx1);
+ glWindow2.addGLEventListener(0, demo1);
+
+ System.err.println(s+" - switch - END "+ ( t1 - t0 ));
+
+ animator.resume();
+ }
+ Thread.sleep(100);
+ t1 = System.currentTimeMillis();
+ }
+
+ animator.stop();
+ glWindow1.destroy();
+ glWindow2.destroy();
+
+ }
+
+ // default timing for 2 switches
+ static long duration = 2200; // ms
+ static long period = 1000; // ms
+
+ public static void main(String args[]) throws IOException {
+ for(int i=0; i<args.length; i++) {
+ if(args[i].equals("-time")) {
+ i++;
+ try {
+ duration = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ } else if(args[i].equals("-period")) {
+ i++;
+ try {
+ period = Integer.parseInt(args[i]);
+ } catch (Exception ex) { ex.printStackTrace(); }
+ }
+ }
+ /**
+ BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
+ System.err.println("Press enter to continue");
+ System.err.println(stdin.readLine()); */
+ org.junit.runner.JUnitCore.main(TestGLContextDrawableSwitchNEWT.class.getName());
+ }
+}
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
index c6c34d05a..6aea5bb9c 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/GearsES2.java
@@ -64,6 +64,7 @@ public class GearsES2 implements GLEventListener {
private KeyListener gearsKeys = new GearsKeyAdapter();
private int prevMouseX, prevMouseY;
+ private boolean isInitialized = false;
public GearsES2(int swapInterval) {
this.swapInterval = swapInterval;
@@ -100,6 +101,11 @@ public class GearsES2 implements GLEventListener {
public void init(GLAutoDrawable drawable) {
+ if(isInitialized) {
+ System.err.println(Thread.currentThread()+" GearsES2.init skipped!");
+ return;
+ }
+ isInitialized = true;
System.err.println(Thread.currentThread()+" GearsES2.init ...");
GL2ES2 gl = drawable.getGL().getGL2ES2();
@@ -174,15 +180,15 @@ public class GearsES2 implements GLEventListener {
}
st.useProgram(gl, false);
- gl.setSwapInterval(swapInterval);
-
System.err.println(Thread.currentThread()+" GearsES2.init FIN");
}
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
- // System.err.println(Thread.currentThread()+" GearsES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval);
+ System.err.println(Thread.currentThread()+" GearsES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval);
GL2ES2 gl = drawable.getGL().getGL2ES2();
+ gl.setSwapInterval(swapInterval); // in case switching the drawable (impl. may bound attribute there)
+
st.useProgram(gl, true);
pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
pmvMatrix.glLoadIdentity();
@@ -206,6 +212,11 @@ public class GearsES2 implements GLEventListener {
// private boolean useAndroidDebug = false;
public void dispose(GLAutoDrawable drawable) {
+ if(!isInitialized) {
+ System.err.println(Thread.currentThread()+" GearsES2.dispose skipped!");
+ return;
+ }
+ isInitialized = false;
System.err.println(Thread.currentThread()+" GearsES2.dispose ... ");
if (drawable.getNativeSurface() instanceof Window) {
Window window = (Window) drawable.getNativeSurface();
diff --git a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
index 11f96ed77..6982d61b7 100644
--- a/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
+++ b/src/test/com/jogamp/opengl/test/junit/jogl/demos/es2/RedSquareES2.java
@@ -55,6 +55,7 @@ public class RedSquareES2 implements GLEventListener {
GLWindow glWindow = null;
float aspect = 1.0f;
boolean doRotate = true;
+ boolean isInitialized = false;
public RedSquareES2(int swapInterval) {
this.swapInterval = swapInterval;
@@ -68,6 +69,11 @@ public class RedSquareES2 implements GLEventListener {
public void setDoRotation(boolean rotate) { this.doRotate = rotate; }
public void init(GLAutoDrawable glad) {
+ if(isInitialized) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.init skipped!");
+ return;
+ }
+ isInitialized = true;
System.err.println(Thread.currentThread()+" RedSquareES2.init ...");
GL2ES2 gl = glad.getGL().getGL2ES2();
@@ -127,8 +133,6 @@ public class RedSquareES2 implements GLEventListener {
gl.glEnable(GL2ES2.GL_DEPTH_TEST);
st.useProgram(gl, false);
- gl.setSwapInterval(swapInterval);
-
if (glad instanceof GLWindow) {
glWindow = (GLWindow) glad;
glWindow.addMouseListener(myMouse);
@@ -167,6 +171,8 @@ public class RedSquareES2 implements GLEventListener {
System.err.println(Thread.currentThread()+" RedSquareES2.reshape "+x+"/"+y+" "+width+"x"+height+", swapInterval "+swapInterval);
GL2ES2 gl = glad.getGL().getGL2ES2();
+ gl.setSwapInterval(swapInterval); // in case switching the drawable (impl. may bound attribute there)
+
st.useProgram(gl, true);
// Set location in front of camera
pmvMatrix.glMatrixMode(PMVMatrix.GL_PROJECTION);
@@ -180,6 +186,11 @@ public class RedSquareES2 implements GLEventListener {
}
public void dispose(GLAutoDrawable glad) {
+ if(!isInitialized) {
+ System.err.println(Thread.currentThread()+" RedSquareES2.dispose skipped!");
+ return;
+ }
+ isInitialized = false;
System.err.println(Thread.currentThread()+" RedSquareES2.dispose ... ");
if (null != glWindow) {
glWindow.removeMouseListener(myMouse);
diff --git a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java
index 41c69336c..4b02be873 100644
--- a/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java
+++ b/src/test/com/jogamp/opengl/test/junit/newt/parenting/TestParenting01cSwingAWT.java
@@ -102,7 +102,7 @@ public class TestParenting01cSwingAWT extends UITestCase {
synchronized(this) {
isRunning = true;
this.notifyAll();
- System.out.println("$");
+ System.err.println("$");
}
while(!shallStop) {
try {
@@ -166,7 +166,7 @@ public class TestParenting01cSwingAWT extends UITestCase {
jFrame1.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); // equivalent to Frame, use windowClosing event!
jFrame1.setContentPane(jPanel1);
jFrame1.setSize(width, height);
- System.out.println("Demos: 1 - Visible");
+ System.err.println("Demos: 1 - Visible");
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
jFrame1.setVisible(true);
@@ -181,27 +181,30 @@ public class TestParenting01cSwingAWT extends UITestCase {
while(animator1.isAnimating() && animator1.getTotalFPSDuration()<durationPerTest) {
Thread.sleep(100);
}
- System.out.println("Demos: 2 - StopAnimator");
+ System.err.println("Demos: 2 - StopAnimator");
animator1.stop();
Assert.assertEquals(false, animator1.isAnimating());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- System.out.println("Demos: 3 - !Visible");
+ System.err.println("Demos: 3 - !Visible");
jFrame1.setVisible(false);
} });
Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glWindow1, false));
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- System.out.println("Demos: 4 - Visible");
+ System.err.println("Demos: 4 - Visible");
jFrame1.setVisible(true);
} });
Assert.assertEquals(true, AWTRobotUtil.waitForVisible(glWindow1, true));
+ // Always recommended to remove our native parented Window
+ // from the AWT resources before destruction, since it could lead
+ // to a BadMatch X11 error w/o.
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
- System.out.println("Demos: 5 - X Container");
+ System.err.println("Demos: 5 - X Container");
jPanel1.remove(container1);
jFrame1.validate();
} });
@@ -209,13 +212,17 @@ public class TestParenting01cSwingAWT extends UITestCase {
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
+ System.err.println("Demos: 6 - X Frame");
jFrame1.dispose();
} });
Assert.assertEquals(true, glWindow1.isNativeValid());
- disturbanceAction.stopAndWaitUntilDone();
+ System.err.println("Demos: 7 - X GLWindow");
glWindow1.destroy();
Assert.assertEquals(false, glWindow1.isNativeValid());
+
+ System.err.println("Demos: 8 - X DisturbanceThread");
+ disturbanceAction.stopAndWaitUntilDone();
}
@Test
@@ -344,24 +351,48 @@ public class TestParenting01cSwingAWT extends UITestCase {
animator1.stop();
Assert.assertEquals(false, animator1.isAnimating());
- disturbanceAction.stopAndWaitUntilDone();
-
+ /*
+ * Always recommended to remove our native parented Window
+ * from the AWT resources before destruction, since it could lead
+ * to a BadMatch X11 error w/o (-> XAWT related).
+ * Or ensure old/new parent is visible, see below.
+ *
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
+ System.err.println("Demos: 1 - X Container 1");
+ container1.remove(newtCanvasAWT);
+ jFrame1.validate();
+ System.err.println("Demos: 1 - X Container 2");
+ jPanel2.remove(newtCanvasAWT);
+ jFrame2.validate();
+ } }); */
+ /*
+ * Invisible X11 windows may also case BadMatch (-> XAWT related)
+ */
+ SwingUtilities.invokeAndWait(new Runnable() {
+ public void run() {
+ System.err.println("Demos: 2 - !visible");
jFrame1.setVisible(false);
+ System.err.println("Demos: 3 - !visible");
jFrame2.setVisible(false);
} });
Assert.assertEquals(true, glWindow1.isNativeValid());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
+ System.err.println("Demos: 4 - X frame");
jFrame1.dispose();
+ System.err.println("Demos: 5 - X frame");
jFrame2.dispose();
} });
Assert.assertEquals(true, glWindow1.isNativeValid());
+ System.err.println("Demos: 6 - X GLWindow");
glWindow1.destroy();
Assert.assertEquals(false, glWindow1.isNativeValid());
+
+ System.err.println("Demos: 7 - X DisturbanceThread");
+ disturbanceAction.stopAndWaitUntilDone();
}
public static void setDemoFields(GLEventListener demo, GLWindow glWindow, boolean debug) {
@@ -393,8 +424,10 @@ public class TestParenting01cSwingAWT extends UITestCase {
waitReparent = atoi(args[++i]);
}
}
- System.out.println("durationPerTest "+durationPerTest);
- System.out.println("waitReparent "+waitReparent);
+ System.err.println("durationPerTest "+durationPerTest);
+ System.err.println("waitReparent "+waitReparent);
+ org.junit.runner.JUnitCore.main(TestParenting01cSwingAWT.class.getName());
+ /**
String tstname = TestParenting01cSwingAWT.class.getName();
org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] {
tstname,
@@ -406,7 +439,7 @@ public class TestParenting01cSwingAWT extends UITestCase {
"logfailedtests=true",
"logtestlistenerevents=true",
"formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter",
- "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } );
+ "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); */
}
}