From aedb5ad9127863fd77d8e1dd8fb7a070cee2df5b Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Wed, 7 Jun 2006 06:35:52 +0000 Subject: [PATCH] Mac OS X: Fixed flickering caused by the new context handling in AWTGLCanvas --- src/java/org/lwjgl/opengl/Context.java | 13 +++++++++++++ .../org/lwjgl/opengl/ContextImplementation.java | 5 +++++ src/java/org/lwjgl/opengl/Display.java | 3 ++- .../lwjgl/opengl/LinuxContextImplementation.java | 3 +++ .../lwjgl/opengl/MacOSXContextImplementation.java | 9 +++------ .../lwjgl/opengl/Win32ContextImplementation.java | 3 +++ 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/java/org/lwjgl/opengl/Context.java b/src/java/org/lwjgl/opengl/Context.java index 6fb9e40c..ac943d60 100644 --- a/src/java/org/lwjgl/opengl/Context.java +++ b/src/java/org/lwjgl/opengl/Context.java @@ -144,6 +144,18 @@ final class Context { } } + /** + * Release the context from its drawable. This is necessary on some platforms, + * like Mac OS X, where binding the context to a drawable and binding the context + * for rendering are two distinct actions and where calling releaseDrawable + * on every releaseCurrentContext results in artifacts. + */ + public synchronized void releaseDrawable() throws LWJGLException { + if (destroyed) + throw new IllegalStateException("Context is destroyed"); + implementation.releaseDrawable(getHandle()); + } + /** * Update the context. Should be called whenever it's drawable is moved or resized */ @@ -198,6 +210,7 @@ final class Context { private void checkDestroy() { if (!destroyed && destroy_requested) { try { + releaseDrawable(); implementation.destroy(peer_info, handle); destroyed = true; thread = null; diff --git a/src/java/org/lwjgl/opengl/ContextImplementation.java b/src/java/org/lwjgl/opengl/ContextImplementation.java index 9c819cb8..3e3edd1f 100644 --- a/src/java/org/lwjgl/opengl/ContextImplementation.java +++ b/src/java/org/lwjgl/opengl/ContextImplementation.java @@ -55,6 +55,11 @@ interface ContextImplementation { */ public void swapBuffers() throws LWJGLException; + /** + * Release the context from its drawable, if any. + */ + public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException; + /** * Release the current context (if any). After this call, no context is current. */ diff --git a/src/java/org/lwjgl/opengl/Display.java b/src/java/org/lwjgl/opengl/Display.java index 730ba45c..f0f2b558 100644 --- a/src/java/org/lwjgl/opengl/Display.java +++ b/src/java/org/lwjgl/opengl/Display.java @@ -283,10 +283,11 @@ public final class Display { } try { if (context.isCurrent()) { + context.releaseDrawable(); Context.releaseCurrentContext(); } } catch (LWJGLException e) { - LWJGLUtil.log("Exception occurred while trying to release context"); + LWJGLUtil.log("Exception occurred while trying to release context: " + e); } // Automatically destroy keyboard & mouse diff --git a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java index d227ed1a..a2c54135 100644 --- a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java +++ b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java @@ -57,6 +57,9 @@ final class LinuxContextImplementation implements ContextImplementation { } private static native ByteBuffer nCreate(ByteBuffer peer_handle, ByteBuffer shared_context_handle) throws LWJGLException; + + public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException { + } public void swapBuffers() throws LWJGLException { Context current_context = Context.getCurrentContext(); diff --git a/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java b/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java index d3459ee3..9b3482c7 100644 --- a/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java +++ b/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java @@ -68,16 +68,13 @@ final class MacOSXContextImplementation implements ContextImplementation { private static native void nUpdate(ByteBuffer context_handle); public void releaseCurrentContext() throws LWJGLException { - Context current_context = Context.getCurrentContext(); - if (current_context != null) { - synchronized (current_context) { - clearDrawable(current_context.getHandle()); - } - } nReleaseCurrentContext(); } private static native void nReleaseCurrentContext() throws LWJGLException; + public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException { + clearDrawable(context_handle); + } private static native void clearDrawable(ByteBuffer handle) throws LWJGLException; static void resetView(PeerInfo peer_info, Context context) throws LWJGLException { diff --git a/src/java/org/lwjgl/opengl/Win32ContextImplementation.java b/src/java/org/lwjgl/opengl/Win32ContextImplementation.java index e6eb8b3a..3385d4c2 100644 --- a/src/java/org/lwjgl/opengl/Win32ContextImplementation.java +++ b/src/java/org/lwjgl/opengl/Win32ContextImplementation.java @@ -68,6 +68,9 @@ final class Win32ContextImplementation implements ContextImplementation { } private static native void nSwapBuffers(ByteBuffer peer_info_handle) throws LWJGLException; + public void releaseDrawable(ByteBuffer context_handle) throws LWJGLException { + } + public void update(ByteBuffer context_handle) { }