|
From: Elias N. <eli...@us...> - 2005-04-28 12:55:35
|
Update of /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16742/src/java/org/lwjgl/opengl Modified Files: MacOSXContextImplementation.java MacOSXDisplay.java MacOSXGLCanvas.java Log Message: Mac OS X: Added a workaround for the 'white screen' problem Index: MacOSXContextImplementation.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- MacOSXContextImplementation.java 23 Feb 2005 12:12:47 -0000 1.3 +++ MacOSXContextImplementation.java 28 Apr 2005 12:55:23 -0000 1.4 @@ -81,6 +81,18 @@ private static native void clearDrawable(ByteBuffer handle) throws LWJGLException; + static void resetView(PeerInfo peer_info, Context context) throws LWJGLException { + ByteBuffer peer_handle = peer_info.lockAndGetHandle(); + try { + synchronized (context) { + clearDrawable(context.getHandle()); + setView(peer_handle, context.getHandle()); + } + } finally { + peer_info.unlock(); + } + } + public void makeCurrent(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException { ByteBuffer peer_handle = peer_info.lockAndGetHandle(); try { Index: MacOSXDisplay.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl/MacOSXDisplay.java,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- MacOSXDisplay.java 12 Apr 2005 11:45:06 -0000 1.27 +++ MacOSXDisplay.java 28 Apr 2005 12:55:23 -0000 1.28 @@ -208,7 +208,36 @@ } public void update() { - if (frame.getCanvas().syncShouldUpdateContext()) { + boolean should_update = frame.getCanvas().syncShouldUpdateContext(); + /* + * Workaround for the "white screen in fullscreen mode" problem + * + * Sometimes, switching from windowed mode to fullscreen or simply creating the Display + * in fullscreen mode will result in the context not being bound to the window correctly. + * The program runs fine, but the canvas background (white) is shown instead of the context + * front buffer. + * + * I've discovered that re-binding the context with another setView() won't fix the problem, while a + * clearDrawable() followed by a setView() does work. A straightforward workaround would be + * to simply run the combination at every update(). This is not sufficient, since the clearDrawable() + * call makes the the background appear shortly, causing visual artifacts. + * What we really need is a way to detect that a setView() failed, and then do the magic combo. I've not + * been able to find such a detection so alternatively I'm triggering the combo if the display is fullscreen + * (I've not seen the white screen problem in windowed mode) and if the canvas has gotten a paint message or + * if its update flag was set. + * + * My testing seems to indicate that the workaround works, since I've not seen the problem after the fix. + * + * - elias + */ + if (Display.isFullscreen() && (frame.getCanvas().syncCanvasPainted() || should_update)) { + try { + MacOSXContextImplementation.resetView(Display.getContext().getPeerInfo(), Display.getContext()); + } catch (LWJGLException e) { + LWJGLUtil.log("Failed to reset context: " + e); + } + } + if (should_update) { Display.getContext().update(); /* This is necessary to make sure the context won't "forget" about the view size */ GL11.glViewport(0, 0, frame.getCanvas().syncGetWidth(), frame.getCanvas().syncGetHeight()); Index: MacOSXGLCanvas.java =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/java/org/lwjgl/opengl/MacOSXGLCanvas.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -d -r1.7 -r1.8 --- MacOSXGLCanvas.java 23 Feb 2005 11:11:07 -0000 1.7 +++ MacOSXGLCanvas.java 28 Apr 2005 12:55:23 -0000 1.8 @@ -50,6 +50,7 @@ private int width; private int height; private boolean context_update; + private boolean canvas_painted; private boolean dirty; public void update(Graphics g) { @@ -59,6 +60,7 @@ public void paint(Graphics g) { synchronized ( this ) { dirty = true; + canvas_painted = true; } } @@ -75,6 +77,15 @@ setUpdate(); } + public boolean syncCanvasPainted() { + boolean result; + synchronized (this) { + result = canvas_painted; + canvas_painted = false; + } + return result; + } + public boolean syncIsDirty() { boolean result; synchronized ( this ) { |