Mac OS X: Fixed flickering caused by the new context handling in AWTGLCanvas

This commit is contained in:
Elias Naur 2006-06-07 06:35:52 +00:00
parent 548fc1df71
commit aedb5ad912
6 changed files with 29 additions and 7 deletions

View File

@ -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;

View File

@ -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.
*/

View File

@ -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

View File

@ -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();

View File

@ -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 {

View File

@ -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) {
}