aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java
diff options
context:
space:
mode:
authorKenneth Russel <[email protected]>2005-07-17 06:13:24 +0000
committerKenneth Russel <[email protected]>2005-07-17 06:13:24 +0000
commit7e7e225eaf4fddb31152ab204bf1776f26079d40 (patch)
tree522044c1fb226235fa34b9d013945f320765edd8 /src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java
parent9d28b7f7fffdaeee7353945000546cb73a00157b (diff)
Further context-related changes for the JSR-231 API. The GLContext
implementations on all platforms have been split into orthogonal GLDrawable and GLContext concepts. It is now possible to create more than one GLContet per GLDrawable (though this has not been tested yet). GLCanvas has been reimplemented in terms of GLDrawableFactory.getGLDrawable(). More functionality has been moved from GLDrawable to GLAutoDrawable. Reimplemented lazy sending of reshape GLEventListener events in GLCanvas and GLJPanel and deleted notion of deferred reshapes from GLDrawableHelper and elsewhere. Sharing of textures and display lists is now expressed in terms of GLContexts instead of GLDrawables. Still need to move pbuffer creation into GLDrawableFactory from the onscreen GLContext implementations. Added option to gleem ExaminerViewer to disable automatic redraws upon mouse events and respecified more of gleem to work on GLAutoDrawables rather than GLDrawables. Updated all JOGL demos to work with new APIs and slightly different initialization sequences (in particular, for pbuffers -- this will change with the addition of GLDrawableFactory.createGLPbuffer()). git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JSR-231@324 232f8b59-042b-4e1e-8c03-345bb8c30851
Diffstat (limited to 'src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java')
-rw-r--r--src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java169
1 files changed, 22 insertions, 147 deletions
diff --git a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java
index 70da97f32..a8ffcf8ec 100644
--- a/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java
+++ b/src/net/java/games/jogl/impl/macosx/MacOSXOnscreenGLContext.java
@@ -39,49 +39,22 @@
package net.java.games.jogl.impl.macosx;
-import java.awt.Component;
import java.util.*;
import net.java.games.jogl.*;
import net.java.games.jogl.impl.*;
-import java.security.*;
-
public class MacOSXOnscreenGLContext extends MacOSXGLContext {
- // Variables for lockSurface/unlockSurface
- private JAWT_DrawingSurface ds;
- 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;
-
+ protected MacOSXOnscreenGLDrawable drawable;
// Variables for pbuffer support
List pbuffersToInstantiate = new ArrayList();
- // Workaround for instance of 4796548
- private boolean firstLock = true;
-
- public MacOSXOnscreenGLContext(Component component,
- GLCapabilities capabilities,
- GLCapabilitiesChooser chooser,
+ public MacOSXOnscreenGLContext(MacOSXOnscreenGLDrawable drawable,
GLContext shareWith) {
- super(component, capabilities, chooser, shareWith);
+ super(drawable, shareWith);
+ this.drawable = drawable;
}
- protected boolean isOffscreen() {
- return false;
- }
-
public int getOffscreenContextReadBuffer() {
throw new GLException("Should not call this");
}
@@ -94,12 +67,12 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext {
return true;
}
- 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;
+ public GLDrawableImpl createPbufferDrawable(GLCapabilities capabilities,
+ int initialWidth,
+ int initialHeight) {
+ MacOSXPbufferGLDrawable buf = new MacOSXPbufferGLDrawable(capabilities, initialWidth, initialHeight);
+ pbuffersToInstantiate.add(buf);
+ return buf;
}
public void bindPbufferToTexture() {
@@ -110,17 +83,14 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext {
throw new GLException("Should not call this");
}
- public void setRealized() {
- realized = true;
- }
-
protected int makeCurrentImpl() throws GLException {
try {
- if (!realized) {
+ int lockRes = drawable.lockSurface();
+ if (lockRes == MacOSXOnscreenGLDrawable.LOCK_SURFACE_NOT_READY) {
return CONTEXT_NOT_CURRENT;
}
- if (!lockSurface()) {
- return CONTEXT_NOT_CURRENT;
+ if (lockRes == MacOSXOnscreenGLDrawable.LOCK_SURFACE_CHANGED) {
+ super.destroy();
}
int ret = super.makeCurrentImpl();
if ((ret == CONTEXT_CURRENT) ||
@@ -132,21 +102,21 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext {
// do this updating only upon reshape of this component or reshape or movement
// of an ancestor, but this also wasn't sufficient and left garbage on the
// screen in some situations.
- CGL.updateContext(nsContext, nsView);
+ CGL.updateContext(nsContext, drawable.getView());
// Instantiate any pending pbuffers
while (!pbuffersToInstantiate.isEmpty()) {
- MacOSXPbufferGLContext ctx =
- (MacOSXPbufferGLContext) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1);
- ctx.createPbuffer(nsView, nsContext);
+ MacOSXPbufferGLDrawable buf =
+ (MacOSXPbufferGLDrawable) pbuffersToInstantiate.remove(pbuffersToInstantiate.size() - 1);
+ buf.createPbuffer(getGL());
}
} else {
// View might not have been ready
- unlockSurface();
+ drawable.unlockSurface();
}
return ret;
} catch (RuntimeException e) {
try {
- unlockSurface();
+ drawable.unlockSurface();
} catch (Exception e2) {
// do nothing if unlockSurface throws
}
@@ -158,108 +128,13 @@ public class MacOSXOnscreenGLContext extends MacOSXGLContext {
try {
super.releaseImpl();
} finally {
- unlockSurface();
+ drawable.unlockSurface();
}
}
- protected void destroyImpl() throws GLException {
- realized = false;
- super.destroyImpl();
- }
-
public void swapBuffers() throws GLException {
- if (!CGL.flushBuffer(nsContext, nsView)) {
+ if (!CGL.flushBuffer(nsContext, drawable.getView())) {
throw new GLException("Error swapping buffers");
}
}
-
- private boolean lockSurface() throws GLException {
- if (nsView != 0) {
- throw new GLException("Surface already locked");
- }
-
- ds = getJAWT().GetDrawingSurface(component);
- if (ds == null) {
- // Widget not yet realized
- return false;
- }
-
- int res = ds.Lock();
- if ((res & JAWTFactory.JAWT_LOCK_ERROR) != 0) {
- throw new GLException("Unable to lock surface");
- }
-
- // See whether the surface changed and if so destroy the old
- // OpenGL nsContext so it will be recreated
- if ((res & JAWTFactory.JAWT_LOCK_SURFACE_CHANGED) != 0) {
- if (nsContext != 0) {
- //CGL.updateContextUnregister(nsContext, nsView, updater); // gznote: not thread safe yet!
- if (!CGL.deleteContext(nsContext, nsView)) {
- throw new GLException("Unable to delete old GL nsContext after surface changed");
- }
- }
- }
-
- if (firstLock) {
- AccessController.doPrivileged(new PrivilegedAction() {
- public Object run() {
- dsi = ds.GetDrawingSurfaceInfo();
- return null;
- }
- });
- } else {
- dsi = ds.GetDrawingSurfaceInfo();
- }
- if (dsi == null) {
- ds.Unlock();
- getJAWT().FreeDrawingSurface(ds);
- ds = null;
-
- // Widget not yet realized
- return false;
- }
-
- firstLock = false;
-
- macosxdsi = (JAWT_MacOSXDrawingSurfaceInfo) dsi.platformInfo();
- if (macosxdsi == null) {
- ds.FreeDrawingSurfaceInfo(dsi);
- ds.Unlock();
- getJAWT().FreeDrawingSurface(ds);
- ds = null;
- dsi = null;
-
- // Widget not yet realized
- return false;
- }
-
- nsView = macosxdsi.cocoaViewRef();
- if (nsView == 0) {
- ds.FreeDrawingSurfaceInfo(dsi);
- ds.Unlock();
- getJAWT().FreeDrawingSurface(ds);
- ds = null;
- dsi = null;
- macosxdsi = null;
-
- // Widget not yet realized
- return false;
- }
-
- return true;
- }
-
- private void unlockSurface() throws GLException {
- if (nsView == 0) {
- throw new GLException("Surface already unlocked");
- }
-
- ds.FreeDrawingSurfaceInfo(dsi);
- ds.Unlock();
- getJAWT().FreeDrawingSurface(ds);
- ds = null;
- dsi = null;
- macosxdsi = null;
- nsView = 0;
- }
}