diff options
-rw-r--r-- | make/cgl-macosx.cfg | 3 | ||||
-rw-r--r-- | make/stub_includes/macosx/window-system.c | 3 | ||||
-rw-r--r-- | src/native/jogl/MacOSXWindowSystemInterface.m | 8 | ||||
-rw-r--r-- | src/net/java/games/jogl/GLJPanel.java | 8 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java | 2 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java | 18 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java | 3 | ||||
-rw-r--r-- | src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java | 16 |
8 files changed, 47 insertions, 14 deletions
diff --git a/make/cgl-macosx.cfg b/make/cgl-macosx.cfg index dab1ec206..e4fad5a5f 100644 --- a/make/cgl-macosx.cfg +++ b/make/cgl-macosx.cfg @@ -28,7 +28,8 @@ CustomCCode int accumGreenBits, CustomCCode int accumBlueBits, CustomCCode int accumAlphaBits, CustomCCode int sampleBuffers, -CustomCCode int numSamples); +CustomCCode int numSamples, +CustomCCode int* viewNotReady); CustomCCode extern Bool makeCurrentContext(void* nsContext, void* nsView); CustomCCode extern Bool clearCurrentContext(void* nsContext, void* nsView); CustomCCode extern Bool deleteContext(void* nsContext, void* nsView); diff --git a/make/stub_includes/macosx/window-system.c b/make/stub_includes/macosx/window-system.c index b30c252f3..8ce6120a3 100644 --- a/make/stub_includes/macosx/window-system.c +++ b/make/stub_includes/macosx/window-system.c @@ -16,7 +16,8 @@ void* createContext(void* shareContext, void* nsView, int accumBlueBits, int accumAlphaBits, int sampleBuffers, - int numSamples); + int numSamples, + int* viewNotReady); Bool makeCurrentContext(void* nsContext, void* nsView); Bool clearCurrentContext(void* nsContext, void* nsView); Bool deleteContext(void* nsContext, void* nsView); diff --git a/src/native/jogl/MacOSXWindowSystemInterface.m b/src/native/jogl/MacOSXWindowSystemInterface.m index 6a5969fff..46c50ceb7 100644 --- a/src/native/jogl/MacOSXWindowSystemInterface.m +++ b/src/native/jogl/MacOSXWindowSystemInterface.m @@ -29,7 +29,8 @@ void* createContext(void* shareContext, void* view, int accumBlueBits, int accumAlphaBits, int sampleBuffers, - int numSamples) + int numSamples, + int* viewNotReady) { int colorSize = redBits + greenBits + blueBits; int accumSize = accumRedBits + accumGreenBits + accumBlueBits; @@ -48,7 +49,10 @@ void* createContext(void* shareContext, void* view, } else if ([nsView lockFocusIfCanDraw] == NO) { - fprintf(stderr, "Error: view not ready, cannot lock focus at \"%s:%s:%d\"\n", __FILE__, __FUNCTION__, __LINE__); + if (viewNotReady != NULL) { + *viewNotReady = 1; + } + // the view is not ready yet return NULL; } diff --git a/src/net/java/games/jogl/GLJPanel.java b/src/net/java/games/jogl/GLJPanel.java index 07399b978..155aca639 100644 --- a/src/net/java/games/jogl/GLJPanel.java +++ b/src/net/java/games/jogl/GLJPanel.java @@ -153,6 +153,9 @@ public final class GLJPanel extends JPanel implements GLDrawable { heavyweight.display(); pbuffer.display(); } catch (GLException e) { + if (DEBUG) { + e.printStackTrace(); + } // We consider any exception thrown during updating of the // heavyweight or pbuffer during the initialization phases // to be an indication that there was a problem @@ -436,13 +439,16 @@ public final class GLJPanel extends JPanel implements GLDrawable { pbufferInitializationCompleted = false; if (firstTime) { toplevel.add(heavyweight); - toplevel.setSize(0, 0); + toplevel.setSize(1, 1); } EventQueue.invokeLater(new Runnable() { public void run() { try { toplevel.setVisible(true); } catch (GLException e) { + if (DEBUG) { + e.printStackTrace(); + } disableHardwareRendering(); } } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java index 9b8f02660..f32c8bb15 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXDummyGLContext.java @@ -106,7 +106,7 @@ class MacOSXDummyGLContext extends MacOSXGLContext throw new GLException("Should not call this"); } - protected void create() { + protected boolean create() { throw new GLException("Should not call this"); } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java index cfa5c3d99..684f82a53 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java @@ -121,7 +121,7 @@ public abstract class MacOSXGLContext extends GLContext * Creates and initializes an appropriate OpenGl nsContext. Should only be * called by {@link makeCurrent(Runnable)}. */ - protected void create() { + protected boolean create() { MacOSXGLContext other = (MacOSXGLContext) GLContextShareSet.getShareContext(this); long share = 0; if (other != null) { @@ -130,6 +130,7 @@ public abstract class MacOSXGLContext extends GLContext throw new GLException("GLContextShareSet returned an invalid OpenGL context"); } } + int[] viewNotReady = new int[1]; nsContext = CGL.createContext(share, nsView, capabilities.getDoubleBuffered() ? 1 : 0, @@ -144,18 +145,29 @@ public abstract class MacOSXGLContext extends GLContext capabilities.getAccumBlueBits(), capabilities.getAccumAlphaBits(), capabilities.getSampleBuffers() ? 1 : 0, - capabilities.getNumSamples()); + capabilities.getNumSamples(), + viewNotReady); if (nsContext == 0) { + if (viewNotReady[0] == 1) { + if (DEBUG) { + System.err.println("!!! View not ready for " + getClass().getName()); + } + // View not ready at the window system level -- this is OK + return false; + } throw new GLException("Error creating nsContext"); } //updater = CGL.updateContextRegister(nsContext, nsView); // gznote: not thread safe yet! GLContextShareSet.contextCreated(this); + return true; } protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { boolean created = false; if (nsContext == 0) { - create(); + if (!create()) { + return false; + } if (DEBUG) { System.err.println("!!! Created GL nsContext for " + getClass().getName()); } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java index 401a657fe..f28a302b1 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java @@ -131,6 +131,9 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { (MacOSXPbufferGLContext) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1); ctx.createPbuffer(nsView, nsContext); } + } else { + // View might not have been ready + unlockSurface(); } return ret; } catch (RuntimeException e) { diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java index 8e65ce1f3..bc046bcc1 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java @@ -65,13 +65,13 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { renderTarget = GL.GL_TEXTURE_2D; } - this.pBuffer = CGL.createPBuffer(renderTarget, width, height); - if (this.pBuffer == 0) { + pBuffer = CGL.createPBuffer(renderTarget, width, height); + if (pBuffer == 0) { throw new GLException("pbuffer creation error: CGL.createPBuffer() failed"); } if (DEBUG) { - System.err.println("Created pbuffer " + width + " x " + height); + System.err.println("Created pbuffer 0x" + Long.toHexString(pBuffer) + ", " + width + " x " + height + " for " + this); } } @@ -79,6 +79,9 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { created = false; if (pBuffer == 0) { + if (DEBUG) { + System.err.println("Pbuffer not instantiated yet for " + this); + } // pbuffer not instantiated yet return false; } @@ -151,10 +154,13 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { return (1<<power); } - protected void create() { - super.create(); + protected boolean create() { + if (!super.create()) { + return false; + } created = true; // Must now associate the pbuffer with our newly-created context CGL.setContextPBuffer(nsContext, pBuffer); + return true; } } |