aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/impl/macosx
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-06-02 04:04:19 +0200
committerSven Gothel <[email protected]>2010-06-02 04:04:19 +0200
commitdd0400a41478c1f365414b8c760eee1c91105280 (patch)
treef485f7216126b5e7e3931462b2e1ce7adb47458f /src/jogl/classes/com/jogamp/opengl/impl/macosx
parent3d53317d3a0748cb3fd1a71f88f6cd4f5de9d4cb (diff)
JOGL: Unified GLContext native handle
- All GLContext implementations are using the contextHandle of the super class. - GLContext.getHandle() exposes contextHandle for API cross access
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/impl/macosx')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java160
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java53
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java8
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java53
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java26
5 files changed, 149 insertions, 151 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java
index e786dfde9..371df1ee5 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java
@@ -49,8 +49,7 @@ import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver;
public abstract class MacOSXCGLContext extends GLContextImpl
{
- protected long nsContext; // NSOpenGLContext
- protected long cglContext; // CGLContextObj
+ protected boolean isNSContext;
private CGLExt cglExt;
// Table that holds the addresses of the native C-language entry points for
// CGL extension functions.
@@ -70,6 +69,8 @@ public abstract class MacOSXCGLContext extends GLContextImpl
return getCGLExt();
}
+ protected boolean isNSContext() { return isNSContext; }
+
public CGLExt getCGLExt() {
if (cglExt == null) {
cglExt = new CGLExtImpl(this);
@@ -98,16 +99,19 @@ public abstract class MacOSXCGLContext extends GLContextImpl
}
/**
- * Creates and initializes an appropriate OpenGl nsContext. Should only be
+ * Creates and initializes an appropriate OpenGl Context (NS). Should only be
* called by {@link makeCurrentImpl()}.
*/
protected boolean create(boolean pbuffer, boolean floatingPoint) {
MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this);
long share = 0;
if (other != null) {
- share = other.getNSContext();
+ if (!other.isNSContext()) {
+ throw new GLException("GLContextShareSet is not a NS Context");
+ }
+ share = other.getHandle();
if (share == 0) {
- throw new GLException("GLContextShareSet returned an invalid OpenGL context");
+ throw new GLException("GLContextShareSet returned a NULL OpenGL context");
}
}
MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
@@ -129,11 +133,11 @@ public abstract class MacOSXCGLContext extends GLContextImpl
try {
int[] viewNotReady = new int[1];
// Try to allocate a context with this
- nsContext = CGL.createContext(share,
+ contextHandle = CGL.createContext(share,
drawable.getNativeWindow().getSurfaceHandle(),
pixelFormat,
viewNotReady, 0);
- if (nsContext == 0) {
+ if (contextHandle == 0) {
if (viewNotReady[0] == 1) {
if (DEBUG) {
System.err.println("!!! View not ready for " + getClass().getName());
@@ -146,7 +150,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl
if (!pbuffer && !capabilities.isBackgroundOpaque()) {
// Set the context opacity
- CGL.setContextOpacity(nsContext, 0);
+ CGL.setContextOpacity(contextHandle, 0);
}
GLCapabilities caps = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(glProfile, pixelFormat);
@@ -154,41 +158,45 @@ public abstract class MacOSXCGLContext extends GLContextImpl
} finally {
CGL.deletePixelFormat(pixelFormat);
}
- if (!CGL.makeCurrentContext(nsContext)) {
- throw new GLException("Error making nsContext current");
+ if (!CGL.makeCurrentContext(contextHandle)) {
+ throw new GLException("Error making Context (NS) current");
}
+ isNSContext = true;
setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
GLContextShareSet.contextCreated(this);
return true;
- }
+ }
protected int makeCurrentImpl() throws GLException {
- boolean created = false;
if (0 == drawable.getNativeWindow().getSurfaceHandle()) {
throw new GLException("drawable has invalid surface handle: "+drawable);
}
- if ( 0 == cglContext && 0 == nsContext) {
+ boolean newCreated = false;
+ if (!isCreated()) {
create();
- created = 0 != cglContext || 0 != nsContext ;
- if(!created) {
+ newCreated = isCreated();
+ if(!newCreated) {
+ if (DEBUG) {
+ System.err.println("!!! GL Context creation failed for " + getClass().getName());
+ }
return CONTEXT_NOT_CURRENT;
}
if (DEBUG) {
- System.err.println("!!! Created OpenGL context " + toHexString(nsContext) + " for " + getClass().getName());
+ System.err.println("!!! Created OpenGL context " + toHexString(contextHandle) + " for " + getClass().getName());
}
}
- if ( 0 != cglContext ) {
- if (CGL.kCGLNoError != CGL.CGLSetCurrentContext(cglContext)) {
- throw new GLException("Error making cglContext current");
+ if ( isNSContext ) {
+ if (!CGL.makeCurrentContext(contextHandle)) {
+ throw new GLException("Error making Context (NS) current");
}
} else {
- if (!CGL.makeCurrentContext(nsContext)) {
- throw new GLException("Error making nsContext current");
+ if (CGL.kCGLNoError != CGL.CGLSetCurrentContext(contextHandle)) {
+ throw new GLException("Error making Context (CGL) current");
}
}
- if (created) {
+ if (newCreated) {
setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
return CONTEXT_CURRENT_NEW;
}
@@ -196,61 +204,57 @@ public abstract class MacOSXCGLContext extends GLContextImpl
}
protected void releaseImpl() throws GLException {
- if ( 0 != cglContext ) {
- CGL.CGLReleaseContext(cglContext);
- } else {
- if (!CGL.clearCurrentContext(nsContext)) {
- throw new GLException("Error freeing OpenGL nsContext");
+ if ( isNSContext ) {
+ if (!CGL.clearCurrentContext(contextHandle)) {
+ throw new GLException("Error freeing OpenGL Context (NS)");
}
+ } else {
+ CGL.CGLReleaseContext(contextHandle);
}
}
protected void destroyImpl() throws GLException {
- boolean hadContext = isCreated();
- if ( 0 != cglContext ) {
- if (CGL.kCGLNoError != CGL.CGLDestroyContext(cglContext)) {
- throw new GLException("Unable to delete OpenGL cglContext");
+ if( ! isCreated() ) {
+ return;
+ }
+ if ( !isNSContext ) {
+ if (CGL.kCGLNoError != CGL.CGLDestroyContext(contextHandle)) {
+ throw new GLException("Unable to delete OpenGL Context (CGL)");
}
if (DEBUG) {
- System.err.println("!!! Destroyed OpenGL cglContext " + cglContext);
+ System.err.println("!!! Destroyed OpenGL Context (CGL) " + contextHandle);
}
- cglContext = 0;
+ contextHandle = 0;
GLContextShareSet.contextDestroyed(this);
- } else if ( 0 != nsContext ) {
- if (!CGL.deleteContext(nsContext)) {
- throw new GLException("Unable to delete OpenGL nsContext");
+ } else {
+ if (!CGL.deleteContext(contextHandle)) {
+ throw new GLException("Unable to delete OpenGL Context (NS)");
}
if (DEBUG) {
- System.err.println("!!! Destroyed OpenGL nsContext " + nsContext);
+ System.err.println("!!! Destroyed OpenGL Context (NS) " + contextHandle);
}
- nsContext = 0;
- }
- if(hadContext) {
- GLContextShareSet.contextDestroyed(this);
+ contextHandle = 0;
}
+ GLContextShareSet.contextDestroyed(this);
}
- public boolean isCreated() {
- return 0 != cglContext || 0 != nsContext ;
- }
-
public void copy(GLContext source, int mask) throws GLException {
- long dst = getCGLContext();
- long src = 0;
- if( 0 != dst ) {
- src = ((MacOSXCGLContext) source).getCGLContext();
- if (src == 0) {
- throw new GLException("Source OpenGL cglContext has not been created ; Destination has a cglContext.");
+ long dst = getHandle();
+ if (0 == dst) {
+ throw new GLException("Destination OpenGL Context has not been created");
+ }
+ long src = source.getHandle();
+ if (0 == src) {
+ throw new GLException("Source OpenGL Context has not been created");
+ }
+ if( !isNSContext() ) {
+ if ( ((MacOSXCGLContext)source).isNSContext() ) {
+ throw new GLException("Source OpenGL Context is NS ; Destination Context is CGL.");
}
CGL.CGLCopyContext(src, dst, mask);
} else {
- dst = getNSContext();
- src = ((MacOSXCGLContext) source).getNSContext();
- if (src == 0) {
- throw new GLException("Source OpenGL nsContext has not been created");
- }
- if (dst == 0) {
- throw new GLException("Destination OpenGL nsContext has not been created");
+ if ( !((MacOSXCGLContext)source).isNSContext() ) {
+ throw new GLException("Source OpenGL Context is CGL ; Destination Context is NS.");
}
CGL.copyContext(dst, src, mask);
}
@@ -274,14 +278,31 @@ public abstract class MacOSXCGLContext extends GLContextImpl
return "";
}
+ protected void swapBuffers() {
+ DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
+ GLCapabilities caps = (GLCapabilities)config.getChosenCapabilities();
+ if(caps.isOnscreen()) {
+ if(isNSContext) {
+ if (!CGL.flushBuffer(contextHandle)) {
+ throw new GLException("Error swapping buffers (NS)");
+ }
+ } else {
+ if (CGL.kCGLNoError != CGL.CGLFlushDrawable(contextHandle)) {
+ throw new GLException("Error swapping buffers (CGL)");
+ }
+ }
+ }
+ }
+
protected void setSwapIntervalImpl(int interval) {
- if ( 0 != cglContext ) {
- int[] lval = new int[] { (int) interval } ;
- CGL.CGLSetParameter(cglContext, CGL.kCGLCPSwapInterval, lval, 0);
- } else if ( 0 != nsContext ) {
- CGL.setSwapInterval(nsContext, interval);
+ if( ! isCreated() ) {
+ throw new GLException("OpenGL context not created");
+ }
+ if ( isNSContext ) {
+ CGL.setSwapInterval(contextHandle, interval);
} else {
- throw new GLException("OpenGL context not current");
+ int[] lval = new int[] { (int) interval } ;
+ CGL.CGLSetParameter(contextHandle, CGL.kCGLCPSwapInterval, lval, 0);
}
currentSwapInterval = interval ;
}
@@ -327,15 +348,4 @@ public abstract class MacOSXCGLContext extends GLContextImpl
// Support for "mode switching" as described in MacOSXCGLDrawable
public abstract void setOpenGLMode(int mode);
public abstract int getOpenGLMode();
-
- //----------------------------------------------------------------------
- // Internals only below this point
- //
-
- public long getCGLContext() {
- return cglContext;
- }
- public long getNSContext() {
- return nsContext;
- }
}
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java
index eba3cf50e..9865fdfca 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java
@@ -47,14 +47,13 @@ import com.jogamp.nativewindow.impl.NullWindow;
public class MacOSXExternalCGLContext extends MacOSXCGLContext {
private boolean firstMakeCurrent = true;
- private boolean created = true;
private GLContext lastContext;
- private MacOSXExternalCGLContext(Drawable drawable, long cglContext, long nsContext) {
+ private MacOSXExternalCGLContext(Drawable drawable, boolean isNSContext, long handle) {
super(drawable, null);
drawable.setExternalCGLContext(this);
- this.cglContext = cglContext;
- this.nsContext = nsContext;
+ this.isNSContext = isNSContext;
+ this.contextHandle = handle;
GLContextShareSet.contextCreated(this);
setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
getGLStateTracker().setEnabled(false); // external context usage can't track state in Java
@@ -65,34 +64,34 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext {
try {
long pixelFormat = 0;
long currentDrawable = 0;
- long cglContext = 0;
- long nsContext = CGL.getCurrentContext(); // Check: MacOSX 10.3 ..
- if( 0 != nsContext ) {
- currentDrawable = CGL.getNSView(nsContext);
- long ctx = CGL.getCGLContext(nsContext);
+ long contextHandle = CGL.getCurrentContext(); // Check: MacOSX 10.3 ..
+ boolean isNSContext = 0 != contextHandle;
+ if( isNSContext ) {
+ currentDrawable = CGL.getNSView(contextHandle);
+ long ctx = CGL.getCGLContext(contextHandle);
if (ctx == 0) {
- throw new GLException("Error: NULL cglContext of nsContext 0x" +Long.toHexString(nsContext));
+ throw new GLException("Error: NULL Context (CGL) of Context (NS) 0x" +Long.toHexString(contextHandle));
}
pixelFormat = CGL.CGLGetPixelFormat(ctx);
if(DEBUG) {
- System.err.println("MacOSXExternalCGLContext Create nsContext 0x"+Long.toHexString(nsContext)+
- ", cglContext 0x"+Long.toHexString(ctx)+
+ System.err.println("MacOSXExternalCGLContext Create Context (NS) 0x"+Long.toHexString(contextHandle)+
+ ", Context (CGL) 0x"+Long.toHexString(ctx)+
", pixelFormat 0x"+Long.toHexString(pixelFormat));
}
} else {
- cglContext = CGL.CGLGetCurrentContext();
- if (cglContext == 0) {
- throw new GLException("Error: current cglContext null, no nsContext");
+ contextHandle = CGL.CGLGetCurrentContext();
+ if (contextHandle == 0) {
+ throw new GLException("Error: current Context (CGL) null, no Context (NS)");
}
- pixelFormat = CGL.CGLGetPixelFormat(cglContext);
+ pixelFormat = CGL.CGLGetPixelFormat(contextHandle);
if(DEBUG) {
- System.err.println("MacOSXExternalCGLContext Create cglContext 0x"+Long.toHexString(cglContext)+
+ System.err.println("MacOSXExternalCGLContext Create Context (CGL) 0x"+Long.toHexString(contextHandle)+
", pixelFormat 0x"+Long.toHexString(pixelFormat));
}
}
if (0 == pixelFormat) {
- throw new GLException("Error: current pixelformat of current cglContext 0x"+Long.toHexString(cglContext)+" is null");
+ throw new GLException("Error: current pixelformat of current Context 0x"+Long.toHexString(contextHandle)+" is null");
}
GLCapabilities caps = MacOSXCGLGraphicsConfiguration.CGLPixelFormat2GLCapabilities(glp, pixelFormat);
if(DEBUG) {
@@ -104,7 +103,7 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext {
NullWindow nw = new NullWindow(cfg);
nw.setSurfaceHandle(currentDrawable);
- return new MacOSXExternalCGLContext(new Drawable(factory, nw), cglContext, nsContext);
+ return new MacOSXExternalCGLContext(new Drawable(factory, nw), isNSContext, contextHandle);
} finally {
((GLDrawableFactoryImpl)factory).unlockToolkit();
}
@@ -124,16 +123,6 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext {
return super.makeCurrent();
}
- protected void swapBuffers() {
- DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
- GLCapabilities caps = (GLCapabilities)config.getChosenCapabilities();
- if(caps.isOnscreen()) {
- if (CGL.kCGLNoError != CGL.CGLFlushDrawable(cglContext)) {
- throw new GLException("Error swapping buffers");
- }
- }
- }
-
public void release() throws GLException {
super.release();
setCurrent(lastContext);
@@ -152,14 +141,10 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext {
}
protected void destroyImpl() throws GLException {
- created = false;
+ contextHandle = 0;
GLContextShareSet.contextDestroyed(this);
}
- public boolean isCreated() {
- return created;
- }
-
public void setOpenGLMode(int mode) {
if (mode != MacOSXCGLDrawable.CGL_MODE)
throw new GLException("OpenGL mode switching not supported for external GLContexts");
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java
index c4eaee489..ede0c28eb 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java
@@ -71,7 +71,7 @@ public class MacOSXOnscreenCGLContext extends MacOSXCGLContext {
// 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);
+ CGL.updateContext(contextHandle);
} else {
if (!isOptimizable()) {
// This can happen if the window currently is zero-sized, for example.
@@ -103,16 +103,16 @@ public class MacOSXOnscreenCGLContext extends MacOSXCGLContext {
}
protected void swapBuffers() {
- if (!CGL.flushBuffer(nsContext)) {
+ if (!CGL.flushBuffer(contextHandle)) {
throw new GLException("Error swapping buffers");
}
}
protected void update() throws GLException {
- if (nsContext == 0) {
+ if (contextHandle == 0) {
throw new GLException("Context not created");
}
- CGL.updateContext(nsContext);
+ CGL.updateContext(contextHandle);
}
protected void create() {
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java
index 52a892b70..391908540 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java
@@ -38,7 +38,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
// FIXME: not clear whether this is really necessary, but since
// the API docs seem to imply it is and since it doesn't seem to
// impact performance, leaving it in
- CGL.setContextTextureImageToPBuffer(nsContext, drawable.getPbuffer(), GL.GL_FRONT);
+ CGL.setContextTextureImageToPBuffer(contextHandle, drawable.getPbuffer(), GL.GL_FRONT);
}
public void releasePbufferFromTexture() {
@@ -57,23 +57,24 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
setOpenGLMode(drawable.getOpenGLMode());
}
- boolean created = false;
- if (nsContext == 0) {
+ if (contextHandle == 0) {
create();
- created = 0 != nsContext ;
- if(!created) {
+ if(!isCreated()) {
return CONTEXT_NOT_CURRENT;
}
+ if(!isNSContext()) {
+ throw new GLException("Not a NS Context");
+ }
if (DEBUG) {
- System.err.println("!!! Created OpenGL context " + toHexString(nsContext) + " for " + getClass().getName());
+ System.err.println("!!! Created OpenGL context (NS) " + toHexString(contextHandle) + " for " + getClass().getName());
}
}
- if (!impl.makeCurrent(nsContext)) {
- throw new GLException("Error making nsContext current");
+ if (!impl.makeCurrent(contextHandle)) {
+ throw new GLException("Error making Context (NS) current");
}
- if (created) {
+ if (isCreated()) {
setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
// Initialize render-to-texture support if requested
@@ -105,29 +106,29 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
}
protected void releaseImpl() throws GLException {
- if (!impl.release(nsContext)) {
- throw new GLException("Error releasing OpenGL nsContext");
+ if (!impl.release(contextHandle)) {
+ throw new GLException("Error releasing OpenGL Context (NS)");
}
}
protected void destroyImpl() throws GLException {
- if (nsContext != 0) {
- if (!impl.destroy(nsContext)) {
+ if (contextHandle != 0) {
+ if (!impl.destroy(contextHandle)) {
throw new GLException("Unable to delete OpenGL context");
}
if (DEBUG) {
- System.err.println("!!! Destroyed OpenGL context " + nsContext);
+ System.err.println("!!! Destroyed OpenGL context " + contextHandle);
}
- nsContext = 0;
+ contextHandle = 0;
GLContextShareSet.contextDestroyed(this);
}
}
protected void setSwapIntervalImpl(int interval) {
- if (nsContext == 0) {
+ if (contextHandle == 0) {
throw new GLException("OpenGL context not current");
}
- impl.setSwapInterval(nsContext, interval);
+ impl.setSwapInterval(contextHandle, interval);
currentSwapInterval = impl.getSwapInterval() ;
}
@@ -148,10 +149,11 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
setOpenGLMode(other.getOpenGLMode());
}
// Will throw exception upon error
- nsContext = impl.create();
+ isNSContext = impl.isNSContext();
+ contextHandle = impl.create();
- if (!impl.makeCurrent(nsContext)) {
- throw new GLException("Error making nsContext current");
+ if (!impl.makeCurrent(contextHandle)) {
+ throw new GLException("Error making Context (NS:"+isNSContext()+") current");
}
setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
}
@@ -206,6 +208,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
// Abstract interface for implementation of this context (either
// NSOpenGL-based or CGL-based)
interface Impl {
+ public boolean isNSContext();
public long create();
public boolean destroy(long ctx);
public boolean makeCurrent(long ctx);
@@ -216,6 +219,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
// NSOpenGLContext-based implementation
class NSOpenGLImpl implements Impl {
+ public boolean isNSContext() { return true; }
public long create() {
DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
GLCapabilities capabilities = (GLCapabilities)config.getChosenCapabilities();
@@ -227,8 +231,8 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
throw new GLException("Error creating context for pbuffer");
}
// Must now associate the pbuffer with our newly-created context
- CGL.setContextPBuffer(nsContext, drawable.getPbuffer());
- return nsContext;
+ CGL.setContextPBuffer(contextHandle, drawable.getPbuffer());
+ return contextHandle;
}
public boolean destroy(long ctx) {
@@ -255,6 +259,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
}
class CGLImpl implements Impl {
+ public boolean isNSContext() { return false; }
public long create() {
// Find and configure share context
MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(MacOSXPbufferCGLContext.this);
@@ -265,11 +270,11 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
MacOSXPbufferCGLContext ctx = (MacOSXPbufferCGLContext) other;
ctx.setOpenGLMode(MacOSXCGLDrawable.CGL_MODE);
} else {
- if (other.getOpenGLMode() != MacOSXCGLDrawable.CGL_MODE) {
+ if (other.isNSContext()) {
throw new GLException("Can't share between NSOpenGLContexts and CGLContextObjs");
}
}
- share = other.getNSContext();
+ share = other.getHandle();
// Note we don't check for a 0 return value, since switching
// the context's mode causes it to be destroyed and not
// re-initialized until the next makeCurrent
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java
index 97a1435bc..9a90cbdc4 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java
@@ -71,24 +71,21 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL
}
protected int makeCurrentImpl() throws GLException {
- boolean created = false;
- if (nsContext == 0) {
+ if (contextHandle == 0) {
create();
- created = 0 != nsContext ;
- if(!created) {
+ if(!isCreated()) {
return CONTEXT_NOT_CURRENT;
}
if (DEBUG) {
- System.err.println("!!! Created GL nsContext for " + getClass().getName());
+ System.err.println("!!! Created GL Context (NS) for " + getClass().getName());
}
- created = true;
}
- if (!Java2D.makeOGLContextCurrentOnSurface(graphics, nsContext)) {
+ if (!Java2D.makeOGLContextCurrentOnSurface(graphics, contextHandle)) {
throw new GLException("Error making context current");
}
- if (created) {
+ if (isCreated()) {
setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
return CONTEXT_CURRENT_NEW;
}
@@ -109,7 +106,7 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL
throw new GLException("Can't share between NSOpenGLContexts and CGLContextObjs");
}
}
- share = other.getNSContext();
+ share = other.getHandle();
// Note we don't check for a 0 return value, since switching
// the context's mode causes it to be destroyed and not
// re-initialized until the next makeCurrent
@@ -124,7 +121,8 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL
return;
}
// FIXME: think about GLContext sharing
- nsContext = ctx;
+ contextHandle = ctx;
+ isNSContext = true;
}
protected void releaseImpl() throws GLException {
@@ -134,12 +132,12 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL
}
protected void destroyImpl() throws GLException {
- if (nsContext != 0) {
- Java2D.destroyOGLContext(nsContext);
+ if (contextHandle != 0) {
+ Java2D.destroyOGLContext(contextHandle);
if (DEBUG) {
- System.err.println("!!! Destroyed OpenGL context " + nsContext);
+ System.err.println("!!! Destroyed OpenGL context " + contextHandle);
}
- nsContext = 0;
+ contextHandle = 0;
// FIXME
// GLContextShareSet.contextDestroyed(this);
}