summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl
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
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')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java5
-rwxr-xr-xsrc/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java50
-rwxr-xr-xsrc/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java8
-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
-rwxr-xr-xsrc/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java19
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java116
-rwxr-xr-xsrc/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java21
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java115
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OnscreenGLXContext.java2
13 files changed, 292 insertions, 344 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java
index 91530e078..416f0d694 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/GLContextImpl.java
@@ -663,11 +663,6 @@ public abstract class GLContextImpl extends GLContext {
((ProcAddressTable)table).reset(getDrawableImpl().getDynamicLookupHelper() );
}
- /** Indicates whether the underlying OpenGL context has been
- created. This is used to manage sharing of display lists and
- textures between contexts. */
- public abstract boolean isCreated();
-
/**
* Sets the OpenGL implementation class and
* the cache of which GL functions are available for calling through this
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java
index 95301b9d0..e64b5bcf2 100755
--- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLContext.java
@@ -44,7 +44,6 @@ import java.nio.*;
import java.util.*;
public abstract class EGLContext extends GLContextImpl {
- private long eglContext;
private boolean eglQueryStringInitialized;
private boolean eglQueryStringAvailable;
private EGLExt eglExt;
@@ -85,10 +84,6 @@ public abstract class EGLContext extends GLContextImpl {
protected Map/*<String, String>*/ getExtensionNameMap() { return null; }
- public long getContext() {
- return eglContext;
- }
-
protected int makeCurrentImpl() throws GLException {
if(EGL.EGL_NO_DISPLAY==((EGLDrawable)drawable).getDisplay() ) {
throw new GLException("drawable not properly initialized, NO DISPLAY: "+drawable);
@@ -96,26 +91,25 @@ public abstract class EGLContext extends GLContextImpl {
if (0 == drawable.getNativeWindow().getSurfaceHandle()) {
throw new GLException("drawable has invalid surface handle: "+drawable);
}
- boolean created = false;
- if (eglContext == 0) {
- create();
- created = true;
+ boolean newCreated = false;
+ if (!isCreated()) {
+ create(); // throws exception if fails!
+ newCreated = true;
if (DEBUG) {
- System.err.println(getThreadName() + ": !!! Created GL context 0x" +
- Long.toHexString(eglContext) + " for " + getClass().getName());
+ System.err.println(getThreadName() + ": !!! Created GL context " + toHexString(contextHandle) + " for " + getClass().getName());
}
}
- if (EGL.eglGetCurrentContext() != eglContext) {
+ if (EGL.eglGetCurrentContext() != contextHandle) {
if (!EGL.eglMakeCurrent(((EGLDrawable)drawable).getDisplay(),
((EGLDrawable)drawable).getSurface(),
((EGLDrawable)drawableRead).getSurface(),
- eglContext)) {
+ contextHandle)) {
throw new GLException("Error making context 0x" +
- Long.toHexString(eglContext) + " current: error code " + EGL.eglGetError());
+ Long.toHexString(contextHandle) + " current: error code " + EGL.eglGetError());
}
}
- if (created) {
+ if(newCreated) {
setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_ES|CTX_OPTION_ANY);
return CONTEXT_CURRENT_NEW;
}
@@ -130,7 +124,7 @@ public abstract class EGLContext extends GLContextImpl {
EGL.EGL_NO_SURFACE,
EGL.EGL_NO_CONTEXT)) {
throw new GLException("Error freeing OpenGL context 0x" +
- Long.toHexString(eglContext) + ": error code " + EGL.eglGetError());
+ Long.toHexString(contextHandle) + ": error code " + EGL.eglGetError());
}
} finally {
getDrawableImpl().getFactoryImpl().unlockToolkit();
@@ -140,12 +134,12 @@ public abstract class EGLContext extends GLContextImpl {
protected void destroyImpl() throws GLException {
getDrawableImpl().getFactoryImpl().lockToolkit();
try {
- if (eglContext != 0) {
- if (!EGL.eglDestroyContext(((EGLDrawable)drawable).getDisplay(), eglContext)) {
+ if (contextHandle != 0) {
+ if (!EGL.eglDestroyContext(((EGLDrawable)drawable).getDisplay(), contextHandle)) {
throw new GLException("Error destroying OpenGL context 0x" +
- Long.toHexString(eglContext) + ": error code " + EGL.eglGetError());
+ Long.toHexString(contextHandle) + ": error code " + EGL.eglGetError());
}
- eglContext = 0;
+ contextHandle = 0;
GLContextShareSet.contextDestroyed(this);
}
} finally {
@@ -188,7 +182,7 @@ public abstract class EGLContext extends GLContextImpl {
EGLContext other = (EGLContext) GLContextShareSet.getShareContext(this);
if (other != null) {
- shareWith = other.getContext();
+ shareWith = other.getHandle();
if (shareWith == 0) {
throw new GLException("GLContextShareSet returned an invalid OpenGL context");
}
@@ -205,15 +199,15 @@ public abstract class EGLContext extends GLContextImpl {
} else {
throw new GLException("Error creating OpenGL context - invalid GLProfile: "+glProfile);
}
- eglContext = EGL.eglCreateContext(eglDisplay, eglConfig, shareWith, contextAttrs, 0);
- if (eglContext == 0) {
+ contextHandle = EGL.eglCreateContext(eglDisplay, eglConfig, shareWith, contextAttrs, 0);
+ if (contextHandle == 0) {
throw new GLException("Error creating OpenGL context: eglDisplay 0x"+Long.toHexString(eglDisplay)+
", "+glProfile+", error 0x"+Integer.toHexString(EGL.eglGetError()));
}
GLContextShareSet.contextCreated(this);
if (DEBUG) {
System.err.println(getThreadName() + ": !!! Created OpenGL context 0x" +
- Long.toHexString(eglContext) +
+ Long.toHexString(contextHandle) +
",\n\twrite surface 0x" + Long.toHexString(((EGLDrawable)drawable).getSurface()) +
",\n\tread surface 0x" + Long.toHexString(((EGLDrawable)drawableRead).getSurface())+
",\n\t"+this+
@@ -222,17 +216,13 @@ public abstract class EGLContext extends GLContextImpl {
if (!EGL.eglMakeCurrent(((EGLDrawable)drawable).getDisplay(),
((EGLDrawable)drawable).getSurface(),
((EGLDrawable)drawableRead).getSurface(),
- eglContext)) {
+ contextHandle)) {
throw new GLException("Error making context 0x" +
- Long.toHexString(eglContext) + " current: error code " + EGL.eglGetError());
+ Long.toHexString(contextHandle) + " current: error code " + EGL.eglGetError());
}
setGLFunctionAvailability(true, glProfile.usesNativeGLES2()?2:1, 0, CTX_PROFILE_ES|CTX_OPTION_ANY);
}
- public boolean isCreated() {
- return (eglContext != 0);
- }
-
protected void updateGLProcAddressTable(int major, int minor, int ctp) {
if (DEBUG) {
System.err.println(getThreadName() + ": !!! Initializing EGL extension address table");
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java
index b289aa9ce..f5f027f94 100755
--- a/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/egl/EGLExternalContext.java
@@ -41,7 +41,6 @@ import javax.media.nativewindow.*;
public class EGLExternalContext extends EGLContext {
private boolean firstMakeCurrent = true;
- private boolean created = true;
private GLContext lastContext;
public EGLExternalContext(AbstractGraphicsScreen screen) {
@@ -71,6 +70,7 @@ public class EGLExternalContext extends EGLContext {
protected int makeCurrentImpl() throws GLException {
if (firstMakeCurrent) {
firstMakeCurrent = false;
+ // FIXME: set contextHandle
return CONTEXT_CURRENT_NEW;
}
return CONTEXT_CURRENT;
@@ -80,14 +80,10 @@ public class EGLExternalContext extends EGLContext {
}
protected void destroyImpl() throws GLException {
- created = false;
+ contextHandle = 0 ;
GLContextShareSet.contextDestroyed(this);
}
- public boolean isCreated() {
- return created;
- }
-
public void bindPbufferToTexture() {
throw new GLException("Should not call this");
}
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);
}
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java
index e712d8568..55c9dc378 100755
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsExternalWGLContext.java
@@ -46,14 +46,13 @@ import com.jogamp.nativewindow.impl.NullWindow;
public class WindowsExternalWGLContext extends WindowsWGLContext {
private boolean firstMakeCurrent = true;
- private boolean created = true;
private GLContext lastContext;
- private WindowsExternalWGLContext(Drawable drawable, long hglrc, WindowsWGLGraphicsConfiguration cfg) {
+ private WindowsExternalWGLContext(Drawable drawable, long ctx, WindowsWGLGraphicsConfiguration cfg) {
super(drawable, null);
- this.context = hglrc;
+ this.contextHandle = ctx;
if (DEBUG) {
- System.err.println(getThreadName() + ": !!! Created external OpenGL context " + toHexString(hglrc) + " for " + this);
+ System.err.println(getThreadName() + ": !!! Created external OpenGL context " + toHexString(ctx) + " for " + this);
}
GLContextShareSet.contextCreated(this);
setGLFunctionAvailability(false, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
@@ -66,8 +65,8 @@ public class WindowsExternalWGLContext extends WindowsWGLContext {
if (0==hdc) {
throw new GLException("Error: attempted to make an external GLDrawable without a drawable current");
}
- long hglrc = WGL.wglGetCurrentContext();
- if (hglrc == 0) {
+ long ctx = WGL.wglGetCurrentContext();
+ if (ctx == 0) {
throw new GLException("Error: attempted to make an external GLContext without a context current");
}
int pfdID = WGL.GetPixelFormat(hdc);
@@ -81,7 +80,7 @@ public class WindowsExternalWGLContext extends WindowsWGLContext {
NullWindow nw = new NullWindow(cfg);
nw.setSurfaceHandle(hdc);
- return new WindowsExternalWGLContext(new Drawable(factory, nw), hglrc, cfg);
+ return new WindowsExternalWGLContext(new Drawable(factory, nw), ctx, cfg);
}
public int makeCurrent() throws GLException {
@@ -113,14 +112,10 @@ public class WindowsExternalWGLContext extends WindowsWGLContext {
}
protected void destroyImpl() throws GLException {
- created = false;
+ contextHandle = 0;
GLContextShareSet.contextDestroyed(this);
}
- public boolean isCreated() {
- return created;
- }
-
// Need to provide the display connection to extension querying APIs
static class Drawable extends WindowsWGLDrawable {
Drawable(GLDrawableFactory factory, NativeWindow comp) {
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java
index 489e4c860..e52c585de 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/windows/wgl/WindowsWGLContext.java
@@ -48,7 +48,6 @@ import com.jogamp.gluegen.runtime.ProcAddressTable;
import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver;
public class WindowsWGLContext extends GLContextImpl {
- protected long hglrc;
private boolean wglGetExtensionsStringEXTInitialized;
private boolean wglGetExtensionsStringEXTAvailable;
private boolean wglMakeContextCurrentInitialized;
@@ -93,7 +92,7 @@ public class WindowsWGLContext extends GLContextImpl {
return wglExt;
}
- public boolean wglMakeContextCurrent(long hDrawDC, long hReadDC, long hglrc) {
+ public boolean wglMakeContextCurrent(long hDrawDC, long hReadDC, long ctx) {
WGLExt wglExt = getWGLExt();
if (!wglMakeContextCurrentInitialized) {
wglMakeContextCurrentARBAvailable = isFunctionAvailable("wglMakeContextCurrentARB");
@@ -104,11 +103,11 @@ public class WindowsWGLContext extends GLContextImpl {
}
}
if(wglMakeContextCurrentARBAvailable) {
- return wglExt.wglMakeContextCurrentARB(hDrawDC, hReadDC, hglrc);
+ return wglExt.wglMakeContextCurrentARB(hDrawDC, hReadDC, ctx);
} else if(wglMakeContextCurrentEXTAvailable) {
- return wglExt.wglMakeContextCurrentEXT(hDrawDC, hReadDC, hglrc);
+ return wglExt.wglMakeContextCurrentEXT(hDrawDC, hReadDC, ctx);
}
- return WGL.wglMakeCurrent(hDrawDC, hglrc);
+ return WGL.wglMakeCurrent(hDrawDC, ctx);
}
public final ProcAddressTable getPlatformExtProcAddressTable() {
@@ -141,7 +140,7 @@ public class WindowsWGLContext extends GLContextImpl {
boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ;
boolean ctDebug = 0 != ( CTX_OPTION_DEBUG & ctp ) ;
- long _context=0;
+ long ctx=0;
final int idx_flags = 4;
final int idx_profile = 6;
@@ -175,24 +174,24 @@ public class WindowsWGLContext extends GLContextImpl {
}
}
- _context = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), share, attribs, 0);
+ ctx = wglExt.wglCreateContextAttribsARB(drawable.getNativeWindow().getSurfaceHandle(), share, attribs, 0);
if(DEBUG) {
- System.err.println("WindowsWGLContext.createContextARB success: "+(0!=_context)+" - "+getGLVersion(major, minor, ctp, "@creation")+", bwdCompat "+ctBwdCompat+", fwdCompat "+ctFwdCompat);
+ System.err.println("WindowsWGLContext.createContextARB success: "+(0!=ctx)+" - "+getGLVersion(major, minor, ctp, "@creation")+", bwdCompat "+ctBwdCompat+", fwdCompat "+ctFwdCompat);
}
- if(0!=_context) {
+ if(0!=ctx) {
// In contrast to GLX no verification with a drawable binding, ie default framebuffer, is necessary,
// if no 3.2 is available creation fails already!
// Nevertheless .. we do it ..
- if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), _context)) {
+ if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), ctx)) {
if(DEBUG) {
System.err.println("WindowsWGLContext.createContextARB couldn't make current "+getGLVersion(major, minor, ctp, "@creation"));
}
WGL.wglMakeCurrent(0, 0);
- WGL.wglDeleteContext(_context);
- _context = 0;
+ WGL.wglDeleteContext(ctx);
+ ctx = 0;
}
}
- return _context;
+ return ctx;
}
/**
@@ -200,8 +199,8 @@ public class WindowsWGLContext extends GLContextImpl {
* called by {@link #makeCurrentImpl()}.
*/
protected void create() {
- if(0!=context) {
- throw new GLException("context is not null: "+context);
+ if(0!=contextHandle) {
+ throw new GLException("context is not null: "+contextHandle);
}
WindowsWGLDrawableFactory factory = (WindowsWGLDrawableFactory)drawable.getFactoryImpl();
GLCapabilities glCaps = drawable.getChosenGLCapabilities();
@@ -210,7 +209,7 @@ public class WindowsWGLContext extends GLContextImpl {
WindowsWGLContext other = (WindowsWGLContext) GLContextShareSet.getShareContext(this);
long share = 0;
if (other != null) {
- share = other.getHGLRC();
+ share = other.getHandle();
if (share == 0) {
throw new GLException("GLContextShareSet returned an invalid OpenGL context");
}
@@ -226,20 +225,20 @@ public class WindowsWGLContext extends GLContextImpl {
if(DEBUG) {
System.err.println("WindowsWGLContext.createContext using shared Context: "+factory.getSharedContext());
}
- hglrc = createContextARB(share, true, major, minor, ctp);
+ contextHandle = createContextARB(share, true, major, minor, ctp);
createContextARBTried = true;
}
- long temp_hglrc = 0;
- if(0==hglrc) {
+ long temp_ctx = 0;
+ if(0==contextHandle) {
// To use WGL_ARB_create_context, we have to make a temp context current,
// so we are able to use GetProcAddress
- temp_hglrc = WGL.wglCreateContext(drawable.getNativeWindow().getSurfaceHandle());
- if (temp_hglrc == 0) {
+ temp_ctx = WGL.wglCreateContext(drawable.getNativeWindow().getSurfaceHandle());
+ if (temp_ctx == 0) {
throw new GLException("Unable to create temp OpenGL context for device context " + toHexString(drawable.getNativeWindow().getSurfaceHandle()));
}
- if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), temp_hglrc)) {
- throw new GLException("Error making temp context current: 0x" + toHexString(temp_hglrc) + ", werr: 0x"+Integer.toHexString(WGL.GetLastError()));
+ if (!WGL.wglMakeCurrent(drawable.getNativeWindow().getSurfaceHandle(), temp_ctx)) {
+ throw new GLException("Error making temp context current: 0x" + toHexString(temp_ctx) + ", werr: 0x"+Integer.toHexString(WGL.GetLastError()));
}
setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
@@ -248,31 +247,31 @@ public class WindowsWGLContext extends GLContextImpl {
!isExtensionAvailable("WGL_ARB_create_context") ) {
if(glCaps.getGLProfile().isGL3()) {
WGL.wglMakeCurrent(0, 0);
- WGL.wglDeleteContext(temp_hglrc);
+ WGL.wglDeleteContext(temp_ctx);
throw new GLException("Unable to create OpenGL >= 3.1 context (no WGL_ARB_create_context)");
}
// continue with temp context for GL < 3.0
- hglrc = temp_hglrc;
+ contextHandle = temp_ctx;
return;
}
- hglrc = createContextARB(share, true, major, minor, ctp);
+ contextHandle = createContextARB(share, true, major, minor, ctp);
createContextARBTried=true;
}
- if(0!=hglrc) {
+ if(0!=contextHandle) {
share = 0; // mark as shared ..
WGL.wglMakeCurrent(0, 0);
- WGL.wglDeleteContext(temp_hglrc);
+ WGL.wglDeleteContext(temp_ctx);
- if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) {
- throw new GLException("Cannot make previous verified context current: 0x" + toHexString(hglrc) + ", werr: 0x" + Integer.toHexString(WGL.GetLastError()));
+ if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), contextHandle)) {
+ throw new GLException("Cannot make previous verified context current: 0x" + toHexString(contextHandle) + ", werr: 0x" + Integer.toHexString(WGL.GetLastError()));
}
} else {
if(glCaps.getGLProfile().isGL3()) {
WGL.wglMakeCurrent(0, 0);
- WGL.wglDeleteContext(temp_hglrc);
+ WGL.wglDeleteContext(temp_ctx);
throw new GLException("WindowsWGLContext.createContext failed, but context > GL2 requested "+getGLVersion(major[0], minor[0], ctp[0], "@creation")+", ");
}
if(DEBUG) {
@@ -280,18 +279,18 @@ public class WindowsWGLContext extends GLContextImpl {
}
// continue with temp context for GL < 3.0
- hglrc = temp_hglrc;
- if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) {
+ contextHandle = temp_ctx;
+ if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), contextHandle)) {
WGL.wglMakeCurrent(0, 0);
- WGL.wglDeleteContext(hglrc);
- throw new GLException("Error making old context current: 0x" + toHexString(hglrc) + ", werr: 0x" + Integer.toHexString(WGL.GetLastError()));
+ WGL.wglDeleteContext(contextHandle);
+ throw new GLException("Error making old context current: 0x" + toHexString(contextHandle) + ", werr: 0x" + Integer.toHexString(WGL.GetLastError()));
}
}
if(0!=share) {
- if (!WGL.wglShareLists(share, hglrc)) {
+ if (!WGL.wglShareLists(share, contextHandle)) {
throw new GLException("wglShareLists(" + toHexString(share) +
- ", " + toHexString(hglrc) + ") failed: werr 0x" +
+ ", " + toHexString(contextHandle) + ") failed: werr 0x" +
Integer.toHexString(WGL.GetLastError()));
}
}
@@ -302,27 +301,27 @@ public class WindowsWGLContext extends GLContextImpl {
if (0 == drawable.getNativeWindow().getSurfaceHandle()) {
throw new GLException("drawable has invalid surface handle: "+drawable);
}
- boolean created = false;
- if (hglrc == 0) {
- create();
- created = true;
+ boolean newCreated = false;
+ if (!isCreated()) {
+ create(); // throws exception if fails!
+ newCreated = true;
if (DEBUG) {
- System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName());
+ System.err.println(getThreadName() + ": !!! Created GL context " + toHexString(contextHandle) + " for " + getClass().getName());
}
}
- if (WGL.wglGetCurrentContext() != hglrc) {
- if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), hglrc)) {
- throw new GLException("Error making context current: 0x" + toHexString(hglrc) + ", werr: 0x" + Integer.toHexString(WGL.GetLastError()) + ", " + this);
+ if (WGL.wglGetCurrentContext() != contextHandle) {
+ if (!wglMakeContextCurrent(drawable.getNativeWindow().getSurfaceHandle(), drawableRead.getNativeWindow().getSurfaceHandle(), contextHandle)) {
+ throw new GLException("Error making context current: 0x" + toHexString(contextHandle) + ", werr: 0x" + Integer.toHexString(WGL.GetLastError()) + ", " + this);
} else {
if (DEBUG && VERBOSE) {
System.err.println(getThreadName() + ": wglMakeCurrent(hdc " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) +
- ", hglrc " + toHexString(hglrc) + ") succeeded");
+ ", contextHandle " + toHexString(contextHandle) + ") succeeded");
}
}
}
- if (created) {
+ if (newCreated) {
setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
WindowsWGLGraphicsConfiguration config =
@@ -342,25 +341,21 @@ public class WindowsWGLContext extends GLContextImpl {
protected void destroyImpl() throws GLException {
if (DEBUG) {
- Exception e = new Exception(getThreadName() + ": !!! Destroyed OpenGL context " + toHexString(hglrc));
+ Exception e = new Exception(getThreadName() + ": !!! Destroyed OpenGL context " + toHexString(contextHandle));
e.printStackTrace();
}
- if (hglrc != 0) {
- if (!WGL.wglDeleteContext(hglrc)) {
+ if (contextHandle != 0) {
+ if (!WGL.wglDeleteContext(contextHandle)) {
throw new GLException("Unable to delete OpenGL context");
}
- hglrc = 0;
+ contextHandle = 0;
GLContextShareSet.contextDestroyed(this);
}
}
- public boolean isCreated() {
- return (hglrc != 0);
- }
-
public void copy(GLContext source, int mask) throws GLException {
- long dst = getHGLRC();
- long src = ((WindowsWGLContext) source).getHGLRC();
+ long dst = getHandle();
+ long src = source.getHandle();
if (src == 0) {
throw new GLException("Source OpenGL context has not been created");
}
@@ -436,11 +431,4 @@ public class WindowsWGLContext extends GLContextImpl {
throw new GLException("Should not call this");
}
- //----------------------------------------------------------------------
- // Internals only below this point
- //
-
- public long getHGLRC() {
- return hglrc;
- }
}
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java
index 139c0deed..8792ac08e 100755
--- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11ExternalGLXContext.java
@@ -48,12 +48,11 @@ import com.jogamp.nativewindow.impl.x11.*;
public class X11ExternalGLXContext extends X11GLXContext {
private boolean firstMakeCurrent = true;
- private boolean created = true;
private GLContext lastContext;
- private X11ExternalGLXContext(Drawable drawable, long context) {
+ private X11ExternalGLXContext(Drawable drawable, long ctx) {
super(drawable, null);
- this.context = context;
+ this.contextHandle = ctx;
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
@@ -62,8 +61,8 @@ public class X11ExternalGLXContext extends X11GLXContext {
protected static X11ExternalGLXContext create(GLDrawableFactory factory, GLProfile glp) {
((GLDrawableFactoryImpl)factory).lockToolkit();
try {
- long context = GLX.glXGetCurrentContext();
- if (context == 0) {
+ long ctx = GLX.glXGetCurrentContext();
+ if (ctx == 0) {
throw new GLException("Error: current context null");
}
long display = GLX.glXGetCurrentDisplay();
@@ -75,15 +74,15 @@ public class X11ExternalGLXContext extends X11GLXContext {
throw new GLException("Error: attempted to make an external GLDrawable without a drawable/context current");
}
int[] val = new int[1];
- GLX.glXQueryContext(display, context, GLX.GLX_SCREEN, val, 0);
+ GLX.glXQueryContext(display, ctx, GLX.GLX_SCREEN, val, 0);
X11GraphicsScreen x11Screen = (X11GraphicsScreen) X11GraphicsScreen.createScreenDevice(display, val[0]);
- GLX.glXQueryContext(display, context, GLX.GLX_FBCONFIG_ID, val, 0);
+ GLX.glXQueryContext(display, ctx, GLX.GLX_FBCONFIG_ID, val, 0);
X11GLXGraphicsConfiguration cfg = X11GLXGraphicsConfiguration.create(glp, x11Screen, val[0]);
NullWindow nw = new NullWindow(cfg);
nw.setSurfaceHandle(drawable);
- return new X11ExternalGLXContext(new Drawable(factory, nw), context);
+ return new X11ExternalGLXContext(new Drawable(factory, nw), ctx);
} finally {
((GLDrawableFactoryImpl)factory).unlockToolkit();
}
@@ -121,14 +120,10 @@ public class X11ExternalGLXContext extends X11GLXContext {
}
protected void destroyImpl() throws GLException {
- created = false;
+ contextHandle = 0;
GLContextShareSet.contextDestroyed(this);
}
- public boolean isCreated() {
- return created;
- }
-
// Need to provide the display connection to extension querying APIs
static class Drawable extends X11GLXDrawable {
Drawable(GLDrawableFactory factory, NativeWindow comp) {
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java
index 76a6830d5..b81521729 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11GLXContext.java
@@ -51,7 +51,6 @@ import com.jogamp.gluegen.runtime.ProcAddressTable;
import com.jogamp.gluegen.runtime.opengl.GLProcAddressResolver;
public abstract class X11GLXContext extends GLContextImpl {
- protected long context;
private boolean glXQueryExtensionsStringInitialized;
private boolean glXQueryExtensionsStringAvailable;
private static final Map/*<String, String>*/ functionNameMap;
@@ -128,12 +127,12 @@ public abstract class X11GLXContext extends GLContextImpl {
return res;
}
- protected void destroyContextARBImpl(long _context) {
+ protected void destroyContextARBImpl(long ctx) {
X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
long display = config.getScreen().getDevice().getHandle();
glXMakeContextCurrent(display, 0, 0, 0);
- GLX.glXDestroyContext(display, _context);
+ GLX.glXDestroyContext(display, ctx);
}
protected long createContextARBImpl(long share, boolean direct, int ctp, int major, int minor) {
@@ -152,7 +151,7 @@ public abstract class X11GLXContext extends GLContextImpl {
boolean ctFwdCompat = 0 != ( CTX_OPTION_FORWARD & ctp ) ;
boolean ctDebug = 0 != ( CTX_OPTION_DEBUG & ctp ) ;
- long _context=0;
+ long ctx=0;
final int idx_flags = 6;
final int idx_profile = 8;
@@ -186,7 +185,7 @@ public abstract class X11GLXContext extends GLContextImpl {
}
try {
- _context = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0);
+ ctx = glXExt.glXCreateContextAttribsARB(display, config.getFBConfig(), share, direct, attribs, 0);
} catch (RuntimeException re) {
if(DEBUG) {
System.err.println("X11GLXContext.createContextARB glXCreateContextAttribsARB failed: "+re+", with "+getGLVersion(major, minor, ctp, "@creation"));
@@ -194,22 +193,22 @@ public abstract class X11GLXContext extends GLContextImpl {
}
}
if(DEBUG) {
- System.err.println("X11GLXContext.createContextARB success: "+(0!=_context)+" - "+getGLVersion(major, minor, ctp, "@creation")+", bwdCompat "+ctBwdCompat+", fwdCompat "+ctFwdCompat);
+ System.err.println("X11GLXContext.createContextARB success: "+(0!=ctx)+" - "+getGLVersion(major, minor, ctp, "@creation")+", bwdCompat "+ctBwdCompat+", fwdCompat "+ctFwdCompat);
}
- if(0!=_context) {
+ if(0!=ctx) {
if (!glXMakeContextCurrent(display,
drawable.getNativeWindow().getSurfaceHandle(),
drawableRead.getNativeWindow().getSurfaceHandle(),
- _context)) {
+ ctx)) {
if(DEBUG) {
System.err.println("X11GLXContext.createContextARB couldn't make current "+getGLVersion(major, minor, ctp, "@creation"));
}
glXMakeContextCurrent(display, 0, 0, 0);
- GLX.glXDestroyContext(display, _context);
- _context = 0;
+ GLX.glXDestroyContext(display, ctx);
+ ctx = 0;
}
}
- return _context;
+ return ctx;
}
/**
@@ -218,8 +217,8 @@ public abstract class X11GLXContext extends GLContextImpl {
* Note: The direct parameter may be overwritten by the direct state of a shared context.
*/
protected void createContext(boolean direct) {
- if(0!=context) {
- throw new GLException("context is not null: "+context);
+ if(0!=contextHandle) {
+ throw new GLException("context is not null: "+contextHandle);
}
X11GLXDrawableFactory factory = (X11GLXDrawableFactory)drawable.getFactoryImpl();
X11GLXGraphicsConfiguration config = (X11GLXGraphicsConfiguration)drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
@@ -228,7 +227,7 @@ public abstract class X11GLXContext extends GLContextImpl {
X11GLXContext other = (X11GLXContext) GLContextShareSet.getShareContext(this);
long share = 0;
if (other != null) {
- share = other.getContext();
+ share = other.getHandle();
if (share == 0) {
throw new GLException("GLContextShareSet returned an invalid OpenGL context");
}
@@ -244,15 +243,15 @@ public abstract class X11GLXContext extends GLContextImpl {
if(glp.isGL3()) {
throw new GLException("Unable to create OpenGL >= 3.1 context");
}
- context = GLX.glXCreateContext(display, config.getXVisualInfo(), share, direct);
- if (context == 0) {
+ contextHandle = GLX.glXCreateContext(display, config.getXVisualInfo(), share, direct);
+ if (contextHandle == 0) {
throw new GLException("Unable to create context(0)");
}
if (!glXMakeContextCurrent(display,
drawable.getNativeWindow().getSurfaceHandle(),
drawableRead.getNativeWindow().getSurfaceHandle(),
- context)) {
- throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable);
+ contextHandle)) {
+ throw new GLException("Error making temp context(0) current: display "+toHexString(display)+", context "+toHexString(contextHandle)+", drawable "+drawable);
}
setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION
return;
@@ -268,23 +267,23 @@ public abstract class X11GLXContext extends GLContextImpl {
if(DEBUG) {
System.err.println("X11GLXContext.createContext using shared Context: "+factory.getSharedContext());
}
- context = createContextARB(share, direct, major, minor, ctp);
+ contextHandle = createContextARB(share, direct, major, minor, ctp);
createContextARBTried = true;
}
- long temp_context = 0;
- if(0==context) {
+ long temp_ctx = 0;
+ if(0==contextHandle) {
// To use GLX_ARB_create_context, we have to make a temp context current,
// so we are able to use GetProcAddress
- temp_context = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct);
- if (temp_context == 0) {
+ temp_ctx = GLX.glXCreateNewContext(display, config.getFBConfig(), GLX.GLX_RGBA_TYPE, share, direct);
+ if (temp_ctx == 0) {
throw new GLException("Unable to create temp OpenGL context(1)");
}
if (!glXMakeContextCurrent(display,
drawable.getNativeWindow().getSurfaceHandle(),
drawableRead.getNativeWindow().getSurfaceHandle(),
- temp_context)) {
- throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(temp_context)+", drawable "+drawable);
+ temp_ctx)) {
+ throw new GLException("Error making temp context(1) current: display "+toHexString(display)+", context "+toHexString(temp_ctx)+", drawable "+drawable);
}
setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION
@@ -293,33 +292,33 @@ public abstract class X11GLXContext extends GLContextImpl {
!isExtensionAvailable("GLX_ARB_create_context") ) {
if(glp.isGL3()) {
glXMakeContextCurrent(display, 0, 0, 0);
- GLX.glXDestroyContext(display, temp_context);
+ GLX.glXDestroyContext(display, temp_ctx);
throw new GLException("Unable to create OpenGL >= 3.1 context (failed GLX_ARB_create_context), GLProfile "+glp+", Drawable "+drawable);
}
// continue with temp context for GL < 3.0
- context = temp_context;
+ contextHandle = temp_ctx;
return;
}
- context = createContextARB(share, direct, major, minor, ctp);
+ contextHandle = createContextARB(share, direct, major, minor, ctp);
createContextARBTried=true;
}
- if(0!=context) {
- if(0!=temp_context) {
+ if(0!=contextHandle) {
+ if(0!=temp_ctx) {
glXMakeContextCurrent(display, 0, 0, 0);
- GLX.glXDestroyContext(display, temp_context);
+ GLX.glXDestroyContext(display, temp_ctx);
if (!glXMakeContextCurrent(display,
drawable.getNativeWindow().getSurfaceHandle(),
drawableRead.getNativeWindow().getSurfaceHandle(),
- context)) {
+ contextHandle)) {
throw new GLException("Cannot make previous verified context current");
}
}
} else {
if(glp.isGL3()) {
glXMakeContextCurrent(display, 0, 0, 0);
- GLX.glXDestroyContext(display, temp_context);
+ GLX.glXDestroyContext(display, temp_ctx);
throw new GLException("X11GLXContext.createContext failed, but context > GL2 requested "+getGLVersion(major[0], minor[0], ctp[0], "@creation")+", ");
}
if(DEBUG) {
@@ -327,14 +326,14 @@ public abstract class X11GLXContext extends GLContextImpl {
}
// continue with temp context for GL <= 3.0
- context = temp_context;
+ contextHandle = temp_ctx;
if (!glXMakeContextCurrent(display,
drawable.getNativeWindow().getSurfaceHandle(),
drawableRead.getNativeWindow().getSurfaceHandle(),
- context)) {
+ contextHandle)) {
glXMakeContextCurrent(display, 0, 0, 0);
- GLX.glXDestroyContext(display, temp_context);
- throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(context)+", drawable "+drawable);
+ GLX.glXDestroyContext(display, temp_ctx);
+ throw new GLException("Error making context(1) current: display "+toHexString(display)+", context "+toHexString(contextHandle)+", drawable "+drawable);
}
}
}
@@ -378,34 +377,34 @@ public abstract class X11GLXContext extends GLContextImpl {
getDrawableImpl().getFactoryImpl().lockToolkit();
try {
- boolean created = false;
- if (context == 0) {
- create();
- created = true;
+ boolean newCreated = false;
+ if (!isCreated()) {
+ create(); // throws exception if fails!
+ newCreated = true;
GLContextShareSet.contextCreated(this);
if (DEBUG) {
- System.err.println(getThreadName() + ": !!! Created GL context for " + getClass().getName());
+ System.err.println(getThreadName() + ": !!! Created GL context " + toHexString(contextHandle) + " for " + getClass().getName());
}
}
- if (GLX.glXGetCurrentContext() != context) {
+ if (GLX.glXGetCurrentContext() != contextHandle) {
if (!glXMakeContextCurrent(dpy,
drawable.getNativeWindow().getSurfaceHandle(),
drawableRead.getNativeWindow().getSurfaceHandle(),
- context)) {
+ contextHandle)) {
throw new GLException("Error making context current: "+this);
}
- if (DEBUG && (VERBOSE || created)) {
+ if (DEBUG && (VERBOSE || isCreated())) {
System.err.println(getThreadName() + ": glXMakeCurrent(display " +
toHexString(dpy)+
", drawable " + toHexString(drawable.getNativeWindow().getSurfaceHandle()) +
", drawableRead " + toHexString(drawableRead.getNativeWindow().getSurfaceHandle()) +
- ", context " + toHexString(context) + ") succeeded");
+ ", context " + toHexString(contextHandle) + ") succeeded");
}
}
- if (created) {
+ if(newCreated) {
setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
return CONTEXT_CURRENT_NEW;
}
@@ -430,18 +429,18 @@ public abstract class X11GLXContext extends GLContextImpl {
protected void destroyImpl() throws GLException {
getDrawableImpl().getFactoryImpl().lockToolkit();
try {
- if (context != 0) {
+ if (contextHandle != 0) {
if (DEBUG) {
System.err.println("glXDestroyContext(" +
toHexString(drawable.getNativeWindow().getDisplayHandle()) +
", " +
- toHexString(context) + ")");
+ toHexString(contextHandle) + ")");
}
- GLX.glXDestroyContext(drawable.getNativeWindow().getDisplayHandle(), context);
+ GLX.glXDestroyContext(drawable.getNativeWindow().getDisplayHandle(), contextHandle);
if (DEBUG) {
- System.err.println("!!! Destroyed OpenGL context " + context);
+ System.err.println("!!! Destroyed OpenGL context " + contextHandle);
}
- context = 0;
+ contextHandle = 0;
GLContextShareSet.contextDestroyed(this);
}
} finally {
@@ -449,13 +448,9 @@ public abstract class X11GLXContext extends GLContextImpl {
}
}
- public boolean isCreated() {
- return (context != 0);
- }
-
public void copy(GLContext source, int mask) throws GLException {
- long dst = getContext();
- long src = ((X11GLXContext) source).getContext();
+ long dst = getHandle();
+ long src = source.getHandle();
if (src == 0) {
throw new GLException("Source OpenGL context has not been created");
}
@@ -583,10 +578,6 @@ public abstract class X11GLXContext extends GLContextImpl {
// Internals only below this point
//
- public long getContext() {
- return context;
- }
-
private boolean isVendorATI = false;
}
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OnscreenGLXContext.java b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OnscreenGLXContext.java
index c89a5efd5..710f93e98 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OnscreenGLXContext.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/x11/glx/X11OnscreenGLXContext.java
@@ -63,6 +63,6 @@ public class X11OnscreenGLXContext extends X11GLXContext {
protected void create() {
createContext(true);
- isIndirect = !GLX.glXIsDirect(drawable.getNativeWindow().getDisplayHandle(), context);
+ isIndirect = !GLX.glXIsDirect(drawable.getNativeWindow().getDisplayHandle(), contextHandle);
}
}