diff options
author | Kenneth Russel <[email protected]> | 2005-07-10 23:17:43 +0000 |
---|---|---|
committer | Kenneth Russel <[email protected]> | 2005-07-10 23:17:43 +0000 |
commit | 8a4e964a88703bcab4a8888b25ea9e997953180a (patch) | |
tree | 073e1a11d44a0f4cb407419c90f89aee0979403d /src/net/java/games/jogl/impl/macosx | |
parent | 6e8dd12319e2d6f702cf66728b177e6ea0152c2c (diff) |
Initial set of context-related changes for the JSR-231 API. GLContext
has been exposed in the public API. The GLEventListener callback
mechanism has been removed from the core GLContext implementation and
moved up to a higher level. GLAutoDrawable now contains the
GLEventListener-related methods, and the GLEventListener's methods now
receive a GLAutoDrawable as argument. All JOGL demos have been updated
for the new APIs. Many FIXMEs and much unimplemented functionality
remain. There is slightly different initialization behavior for the
demos containing pbuffers, and the deferring of reshape callbacks
needs to be rethought.
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@320 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/impl/macosx')
4 files changed, 42 insertions, 31 deletions
diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java index 8cc33f8ff..b921116db 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXGLContext.java @@ -45,7 +45,7 @@ import net.java.games.gluegen.runtime.*; // for PROCADDRESS_VAR_PREFIX import net.java.games.jogl.*; import net.java.games.jogl.impl.*; -public abstract class MacOSXGLContext extends GLContext +public abstract class MacOSXGLContext extends GLContextImpl { private static JAWT jawt; protected long nsContext; // NSOpenGLContext @@ -119,7 +119,7 @@ public abstract class MacOSXGLContext extends GLContext /** * Creates and initializes an appropriate OpenGl nsContext. Should only be - * called by {@link makeCurrent(Runnable)}. + * called by {@link makeCurrentImpl()}. */ protected boolean create(boolean pbuffer, boolean floatingPoint) { MacOSXGLContext other = (MacOSXGLContext) GLContextShareSet.getShareContext(this); @@ -165,7 +165,7 @@ public abstract class MacOSXGLContext extends GLContext return true; } - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { + protected int makeCurrentImpl() throws GLException { boolean created = false; if (nsContext == 0) { if (!create()) { @@ -183,14 +183,12 @@ public abstract class MacOSXGLContext extends GLContext if (created) { resetGLFunctionAvailability(); - if (initAction != null) { - initAction.run(); - } + return CONTEXT_CURRENT_NEW; } - return true; + return CONTEXT_CURRENT; } - protected synchronized void free() throws GLException { + protected void releaseImpl() throws GLException { if (!CGL.clearCurrentContext(nsContext, nsView)) { throw new GLException("Error freeing OpenGL nsContext"); } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java index 37b2302c0..39aab5652 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOffscreenGLContext.java @@ -83,7 +83,7 @@ public class MacOSXOffscreenGLContext extends MacOSXPbufferGLContext throw new GLException("Should not call this"); } - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { + protected int makeCurrentImpl() throws GLException { if (pendingOffscreenResize && (nsContext != 0)) { if (pendingOffscreenWidth != width || pendingOffscreenHeight != height) { destroyPBuffer(); @@ -93,9 +93,9 @@ public class MacOSXOffscreenGLContext extends MacOSXPbufferGLContext pendingOffscreenResize = false; } } - return super.makeCurrent(initAction); + return super.makeCurrentImpl(); } - public synchronized void swapBuffers() throws GLException { + public void swapBuffers() throws GLException { } } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java index ba4eee0ef..f2398aab8 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java @@ -53,6 +53,18 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { private JAWT_DrawingSurfaceInfo dsi; private JAWT_MacOSXDrawingSurfaceInfo macosxdsi; + // Indicates whether the component (if an onscreen context) has been + // realized. Plausibly, before the component is realized the JAWT + // should return an error or NULL object from some of its + // operations; this appears to be the case on Win32 but is not true + // at least with Sun's current X11 implementation (1.4.x), which + // crashes with no other error reported if the DrawingSurfaceInfo is + // fetched from a locked DrawingSurface during the validation as a + // result of calling show() on the main thread. To work around this + // we prevent any JAWT or OpenGL operations from being done until + // addNotify() is called on the component. + protected boolean realized; + // Variables for pbuffer support List pbuffersToInstantiate = new ArrayList(); @@ -82,8 +94,9 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { return true; } - public synchronized GLContext createPbufferContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { + public GLContext createPbufferContext(GLCapabilities capabilities, int initialWidth, int initialHeight) { MacOSXPbufferGLContext ctx = new MacOSXPbufferGLContext(capabilities, initialWidth, initialHeight); + ctx.setSynchronized(true); GLContextShareSet.registerSharing(this, ctx); pbuffersToInstantiate.add(ctx); return ctx; @@ -97,22 +110,17 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { throw new GLException("Should not call this"); } - public synchronized void setRenderingThread(Thread currentThreadOrNull, Runnable initAction) { - this.willSetRenderingThread = false; - // FIXME: the JAWT in the Panther developer release - // requires all JAWT operations to be done on the AWT - // thread. This means that setRenderingThread won't work - // yet on this platform. This method can be deleted once - // the update for that release ships. - } - - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { + protected int makeCurrentImpl() throws GLException { try { + if (!realized) { + return CONTEXT_NOT_CURRENT; + } if (!lockSurface()) { - return false; + return CONTEXT_NOT_CURRENT; } - boolean ret = super.makeCurrent(initAction); - if (ret) { + int ret = super.makeCurrentImpl(); + if ((ret == CONTEXT_CURRENT) || + (ret == CONTEXT_CURRENT_NEW)) { // Assume the canvas might have been resized or moved and tell the OpenGL // context to update itself. This used to be done only upon receiving a // reshape event but that doesn't appear to be sufficient. An experiment @@ -142,15 +150,20 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext { } } - protected synchronized void free() throws GLException { + protected void releaseImpl() throws GLException { try { - super.free(); + super.releaseImpl(); } finally { unlockSurface(); } } - public synchronized void swapBuffers() throws GLException { + protected void destroyImpl() throws GLException { + realized = false; + super.destroyImpl(); + } + + public void swapBuffers() throws GLException { if (!CGL.flushBuffer(nsContext, nsView)) { throw new GLException("Error swapping buffers"); } diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java index 6c8004bee..b163bb9ce 100644 --- a/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java +++ b/src/net/java/games/jogl/impl/macosx/MacOSXPbufferGLContext.java @@ -104,7 +104,7 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { } } - protected synchronized boolean makeCurrent(Runnable initAction) throws GLException { + protected int makeCurrentImpl() throws GLException { created = false; if (pBuffer == 0) { @@ -112,10 +112,10 @@ public class MacOSXPbufferGLContext extends MacOSXGLContext { System.err.println("Pbuffer not instantiated yet for " + this); } // pbuffer not instantiated yet - return false; + return CONTEXT_NOT_CURRENT; } - boolean res = super.makeCurrent(initAction); + int res = super.makeCurrentImpl(); if (created) { // Initialize render-to-texture support if requested boolean rect = capabilities.getOffscreenRenderToTextureRectangle(); |