diff options
author | Michael Bien <[email protected]> | 2010-06-02 14:17:17 +0200 |
---|---|---|
committer | Michael Bien <[email protected]> | 2010-06-02 14:17:17 +0200 |
commit | 1c4dadcc23b3920b0c612254af361da370d86cb8 (patch) | |
tree | 95d505f3109cada84ee54d3b1d0f27737e398640 /src | |
parent | ace04b51b41dd7887aec4095c8c4792dfc4c284b (diff) | |
parent | ede9386de45b63f46c206aaed27ddeafe8fe96fa (diff) |
Merge branch 'master' of github.com:sgothel/jogl
Diffstat (limited to 'src')
30 files changed, 647 insertions, 659 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); } } diff --git a/src/jogl/classes/com/jogamp/openmax/OMXInstance.java b/src/jogl/classes/com/jogamp/openmax/OMXInstance.java index 9f5b850ba..2ebae9b58 100644 --- a/src/jogl/classes/com/jogamp/openmax/OMXInstance.java +++ b/src/jogl/classes/com/jogamp/openmax/OMXInstance.java @@ -82,7 +82,7 @@ public class OMXInstance { if(null==eglDrawable) { throw new RuntimeException("No valid drawable"); } - eglContext = eglCtx.getContext(); + eglContext = eglCtx.getHandle(); eglDisplay = eglDrawable.getDisplay(); eglSurface = eglDrawable.getSurface(); eglExt = eglCtx.getEGLExt(); diff --git a/src/jogl/classes/javax/media/opengl/GLContext.java b/src/jogl/classes/javax/media/opengl/GLContext.java index 37172e370..efc914de9 100644 --- a/src/jogl/classes/javax/media/opengl/GLContext.java +++ b/src/jogl/classes/javax/media/opengl/GLContext.java @@ -67,7 +67,8 @@ public abstract class GLContext { private HashMap/*<int, Object>*/ attachedObjects = new HashMap(); - protected long context; + /** The underlying native OpenGL context */ + protected long contextHandle; /** * Returns the GLDrawable to which this context may be used to @@ -233,16 +234,28 @@ public abstract class GLContext { public abstract GL setGL(GL gl); /** + * Returns the native GL context handle + */ + public final long getHandle() { return contextHandle; } + + /** + * Indicates whether the underlying OpenGL context has been created. + */ + public final boolean isCreated() { + return 0 != contextHandle; + } + + /** * Returns the attached user object for the given name to this GLContext. */ - public Object getAttachedObject(int name) { + public final Object getAttachedObject(int name) { return attachedObjects.get(new Integer(name)); } /** * Returns the attached user object for the given name to this GLContext. */ - public Object getAttachedObject(String name) { + public final Object getAttachedObject(String name) { return attachedObjects.get(name); } @@ -250,7 +263,7 @@ public abstract class GLContext { * Sets the attached user object for the given name to this GLContext. * Returns the previously set object or null. */ - public Object putAttachedObject(int name, Object obj) { + public final Object putAttachedObject(int name, Object obj) { return attachedObjects.put(new Integer(name), obj); } @@ -258,7 +271,7 @@ public abstract class GLContext { * Sets the attached user object for the given name to this GLContext. * Returns the previously set object or null. */ - public Object putAttachedObject(String name, Object obj) { + public final Object putAttachedObject(String name, Object obj) { return attachedObjects.put(name, obj); } @@ -306,21 +319,23 @@ public abstract class GLContext { public final boolean isCreatedWithARBMethod() { return ( 0 != ( CTX_IS_ARB_CREATED & ctxOptions ) ); } /** - * Returns a valid OpenGL version string, ie - * <code>major.minor ([option]?[options,]*) - gl-version</code> + * Returns a valid OpenGL version string, ie<br> + * <pre> + * major.minor ([option]?[options,]*) - gl-version + * </pre><br> * * <ul> * <li> options * <ul> - * <li> <code>old</code> refers to the non ARB_create_context created context - * <li> <code>new</code> refers to the ARB_create_context created context - * <li> <code>compatible profile</code> - * <li> <code>core profile</code> - * <li> <code>forward compatible</code> - * <li> <code>any</code> refers to the non forward compatible context - * <li> <code>ES</code> refers to the GLES context variant - * </ul> - * <li> <i>gl-version</i> the GL_VERSION string + * <li> <code>old</code> refers to the non ARB_create_context created context</li> + * <li> <code>new</code> refers to the ARB_create_context created context</li> + * <li> <code>compatible profile</code></li> + * <li> <code>core profile</code></li> + * <li> <code>forward compatible</code></li> + * <li> <code>any</code> refers to the non forward compatible context</li> + * <li> <code>ES</code> refers to the GLES context variant</li> + * </ul></li> + * <li> <i>gl-version</i> the GL_VERSION string</li> * </ul> * * e.g.: diff --git a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java index 45c782d38..7fdbd59c8 100755 --- a/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java +++ b/src/junit/com/jogamp/test/junit/jogl/texture/TestTexture01AWT.java @@ -48,29 +48,44 @@ import java.awt.GradientPaint; import java.awt.Graphics2D; import java.awt.image.BufferedImage; +import java.io.IOException; +import org.junit.Assert; import org.junit.After; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; public class TestTexture01AWT { - Frame frame; + static GLProfile glp; + static GLCapabilities caps; BufferedImage textureImage; + @BeforeClass + public static void initClass() { + glp = GLProfile.get(GLProfile.GL2GL3); + Assert.assertNotNull(glp); + caps = new GLCapabilities(glp); + Assert.assertNotNull(caps); + } + @Before - public void init() { + public void initTest() { // create base image - BufferedImage baseImage = new BufferedImage(256, 256, BufferedImage.TYPE_INT_RGB); + BufferedImage baseImage = new BufferedImage(256, 256, BufferedImage.TYPE_3BYTE_BGR); + Assert.assertNotNull(baseImage); Graphics2D g = baseImage.createGraphics(); + Assert.assertNotNull(g); g.setPaint(new GradientPaint(0, 0, Color.CYAN, baseImage.getWidth(), baseImage.getHeight(), Color.BLUE)); g.fillRect(0, 0, baseImage.getWidth(), baseImage.getHeight()); g.dispose(); // create texture image - int imageType = BufferedImage.TYPE_INT_RGB; + int imageType = BufferedImage.TYPE_3BYTE_BGR; textureImage = new BufferedImage(baseImage.getWidth(), baseImage.getHeight(), imageType); + Assert.assertNotNull(textureImage); g = textureImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.drawImage(baseImage, 0, 0, null); @@ -78,22 +93,21 @@ public class TestTexture01AWT { baseImage.flush(); baseImage=null; - - frame = new Frame("Texture Test"); } @After - public void cleanup() { + public void cleanupTest() { + Assert.assertNotNull(textureImage); textureImage.flush(); textureImage=null; - frame.dispose(); - frame=null; } @Test public void test1() throws InterruptedException { - GLCapabilities caps = new GLCapabilities(GLProfile.get(GLProfile.GL2GL3)); GLCanvas glCanvas = new GLCanvas(caps); + + Frame frame = new Frame("Texture Test"); + Assert.assertNotNull(frame); frame.add(glCanvas); frame.setSize(512, 512); @@ -111,9 +125,23 @@ public class TestTexture01AWT { frame.setVisible(false); frame.remove(glCanvas); glCanvas=null; + Assert.assertNotNull(frame); + frame.dispose(); + frame=null; } - public static void main(String args[]) { - org.junit.runner.JUnitCore.main(TestTexture01AWT.class.getName()); + public static void main(String args[]) throws IOException { + String tstname = TestTexture01AWT.class.getName(); + org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner.main(new String[] { + tstname, + "filtertrace=true", + "haltOnError=false", + "haltOnFailure=false", + "showoutput=true", + "outputtoformatters=true", + "logfailedtests=true", + "logtestlistenerevents=true", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.PlainJUnitResultFormatter", + "formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,TEST-"+tstname+".xml" } ); } } diff --git a/src/junit/com/jogamp/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java b/src/junit/com/jogamp/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java index eabd4b79d..c5e656572 100755 --- a/src/junit/com/jogamp/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java +++ b/src/junit/com/jogamp/test/junit/jogl/util/texture/gl2/TextureGL2ListenerDraw1.java @@ -53,7 +53,9 @@ public class TextureGL2ListenerDraw1 implements GLEventListener { } public void init(GLAutoDrawable drawable) { - this.texture = TextureIO.newTexture(textureData); + if(null!=textureData) { + this.texture = TextureIO.newTexture(textureData); + } } public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) { @@ -89,21 +91,23 @@ public class TextureGL2ListenerDraw1 implements GLEventListener { // Now draw one quad with the texture - texture.enable(); - texture.bind(); - gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); - TextureCoords coords = texture.getImageTexCoords(); - gl.glBegin(GL2.GL_QUADS); - gl.glTexCoord2f(coords.left(), coords.bottom()); - gl.glVertex3f(0, 0, 0); - gl.glTexCoord2f(coords.right(), coords.bottom()); - gl.glVertex3f(1, 0, 0); - gl.glTexCoord2f(coords.right(), coords.top()); - gl.glVertex3f(1, 1, 0); - gl.glTexCoord2f(coords.left(), coords.top()); - gl.glVertex3f(0, 1, 0); - gl.glEnd(); - texture.disable(); + if(null!=texture) { + texture.enable(); + texture.bind(); + gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE); + TextureCoords coords = texture.getImageTexCoords(); + gl.glBegin(GL2.GL_QUADS); + gl.glTexCoord2f(coords.left(), coords.bottom()); + gl.glVertex3f(0, 0, 0); + gl.glTexCoord2f(coords.right(), coords.bottom()); + gl.glVertex3f(1, 0, 0); + gl.glTexCoord2f(coords.right(), coords.top()); + gl.glVertex3f(1, 1, 0); + gl.glTexCoord2f(coords.left(), coords.top()); + gl.glVertex3f(0, 1, 0); + gl.glEnd(); + texture.disable(); + } } } diff --git a/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java b/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java index b96e74182..9aec605be 100755 --- a/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestGLWindows01NEWT.java @@ -127,10 +127,16 @@ public class TestGLWindows01NEWT { window.display(); window.destroy(); Assert.assertEquals(false,window.isNativeWindowValid()); - Assert.assertEquals(true,window.isVisible()); + Assert.assertEquals(false,window.isVisible()); window.display(); + Assert.assertEquals(false,window.isNativeWindowValid()); + Assert.assertEquals(false,window.isVisible()); + + window.setVisible(true); Assert.assertEquals(true,window.isNativeWindowValid()); + Assert.assertEquals(true,window.isVisible()); + window.display(); Animator animator = new Animator(window); animator.start(); diff --git a/src/junit/com/jogamp/test/junit/newt/TestParenting02AWT.java b/src/junit/com/jogamp/test/junit/newt/TestParenting02AWT.java index 6d0791c1c..753da1836 100755 --- a/src/junit/com/jogamp/test/junit/newt/TestParenting02AWT.java +++ b/src/junit/com/jogamp/test/junit/newt/TestParenting02AWT.java @@ -68,6 +68,7 @@ public class TestParenting02AWT { static int width, height; static long durationPerTest = 500; static long waitReparent = 300; + static boolean verbose = false; @BeforeClass public static void initClass() { @@ -157,7 +158,9 @@ public class TestParenting02AWT { Assert.assertEquals(true, glWindow.isNativeWindowValid()); Assert.assertNotNull(glWindow.getParentNativeWindow()); - System.out.println("+++++++++++++++++++ 1st ADDED"); + if(verbose) { + System.out.println("+++++++++++++++++++ 1st ADDED"); + } Thread.sleep(waitReparent); if(useLayout) { @@ -166,7 +169,9 @@ public class TestParenting02AWT { Assert.assertEquals(false, glWindow.isVisible()); Assert.assertEquals(true, glWindow.isNativeWindowValid()); Assert.assertNull(glWindow.getParentNativeWindow()); - System.out.println("+++++++++++++++++++ REMOVED!"); + if(verbose) { + System.out.println("+++++++++++++++++++ REMOVED!"); + } Thread.sleep(waitReparent); // should recreate properly .. @@ -175,7 +180,9 @@ public class TestParenting02AWT { Assert.assertEquals(true, glWindow.isVisible()); Assert.assertEquals(true, glWindow.isNativeWindowValid()); Assert.assertNotNull(glWindow.getParentNativeWindow()); - System.out.println("+++++++++++++++++++ 2nd ADDED"); + if(verbose) { + System.out.println("+++++++++++++++++++ 2nd ADDED"); + } Thread.sleep(waitReparent); } @@ -204,7 +211,9 @@ public class TestParenting02AWT { } } } - System.out.println("+++++++++++++++++++ END"); + if(verbose) { + System.out.println("+++++++++++++++++++ END"); + } Thread.sleep(waitReparent); glWindow.destroy(); @@ -236,6 +245,7 @@ public class TestParenting02AWT { } public static void main(String args[]) throws IOException { + verbose = true; for(int i=0; i<args.length; i++) { if(args[i].equals("-time")) { durationPerTest = atoi(args[++i]); diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java index d2429cdab..6233bf533 100644 --- a/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java +++ b/src/nativewindow/classes/com/jogamp/nativewindow/impl/NativeWindowFactoryImpl.java @@ -56,13 +56,13 @@ public class NativeWindowFactoryImpl extends NativeWindowFactory { throw new IllegalArgumentException("AbstractGraphicsConfiguration is null with a non NativeWindow object"); } - if (ReflectionUtil.instanceOf(winObj, "java.awt.Component")) { + if (ReflectionUtil.instanceOf(winObj, AWTComponentClassName)) { return getAWTNativeWindow(winObj, config); } throw new IllegalArgumentException("Target window object type " + winObj.getClass().getName() + " is unsupported; expected " + - "javax.media.nativewindow.NativeWindow or java.awt.Component"); + "javax.media.nativewindow.NativeWindow or "+AWTComponentClassName); } private Constructor nativeWindowConstructor = null; diff --git a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java index 2125fb4c0..14cb830e3 100644 --- a/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java +++ b/src/nativewindow/classes/javax/media/nativewindow/NativeWindowFactory.java @@ -75,7 +75,7 @@ public abstract class NativeWindowFactory { private static String nativeWindowingTypeCustom; private static String nativeOSNameCustom; private static final boolean isAWTAvailable; - private static final String awtComponentClassName = "java.awt.Component" ; + public static final String AWTComponentClassName = "java.awt.Component" ; /** Creates a new NativeWindowFactory instance. End users do not need to call this method. */ @@ -126,7 +126,7 @@ public abstract class NativeWindowFactory { // make it easier to run this code on mobile devices isAWTAvailable = !Debug.getBooleanProperty("java.awt.headless", true, acc) && - ReflectionUtil.isClassAvailable(awtComponentClassName) && + ReflectionUtil.isClassAvailable(AWTComponentClassName) && ReflectionUtil.isClassAvailable("javax.media.nativewindow.awt.AWTGraphicsDevice") ; boolean toolkitLockForced = Debug.getBooleanProperty("nativewindow.locking", true, acc); @@ -195,7 +195,7 @@ public abstract class NativeWindowFactory { if ( isAWTAvailable ) { // register either our default factory or (if exist) the X11/AWT one -> AWT Component - registerFactory(ReflectionUtil.getClass(awtComponentClassName, false), factory); + registerFactory(ReflectionUtil.getClass(AWTComponentClassName, false), factory); } defaultFactory = factory; diff --git a/src/newt/classes/com/jogamp/newt/Display.java b/src/newt/classes/com/jogamp/newt/Display.java index 113ec547e..8710f82ba 100755 --- a/src/newt/classes/com/jogamp/newt/Display.java +++ b/src/newt/classes/com/jogamp/newt/Display.java @@ -112,7 +112,7 @@ public abstract class Display { Map displayMap = getCurrentDisplayMap(); Set entrySet = displayMap.entrySet(); Iterator i = entrySet.iterator(); - System.err.println(prefix+" DisplayMap["+entrySet.size()+"] "+Thread.currentThread()); + System.err.println(prefix+" DisplayMap[] entries: "+entrySet.size()+" - "+Thread.currentThread()); for(int j=0; i.hasNext(); j++) { Map.Entry entry = (Map.Entry) i.next(); System.err.println(" ["+j+"] "+entry.getKey()+" -> "+entry.getValue()); @@ -125,7 +125,7 @@ public abstract class Display { } /** Make sure to reuse a Display with the same name */ - protected static Display create(String type, String name, final long handle) { + protected static synchronized Display create(String type, String name, final long handle) { try { Class displayClass = getDisplayClass(type); Display tmpDisplay = (Display) displayClass.newInstance(); @@ -140,41 +140,30 @@ public abstract class Display { tmpDisplay = null; display.name = name; display.type=type; - display.refCount=1; - - if(NewtFactory.useEDT()) { - final Display f_dpy = display; - Thread current = Thread.currentThread(); - display.edtUtil = new EDTUtil(current.getThreadGroup(), - "Display_"+display.getFQName(), - new Runnable() { - public void run() { - if(null!=f_dpy.getGraphicsDevice()) { - f_dpy.pumpMessagesImpl(); - } - } } ); - display.edt = display.edtUtil.start(); - display.edtUtil.invokeAndWait(new Runnable() { - public void run() { - f_dpy.createNative(); - } - } ); - } else { - display.createNative(); - } - if(null==display.aDevice) { - throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); - } - setCurrentDisplay(display); + display.refCount=0; if(DEBUG) { - System.err.println("Display.create("+getFQName(type, name)+") NEW: "+display+" "+Thread.currentThread()); + System.err.println("Display.create("+getFQName(type, name)+") NEW: refCount "+display.refCount+", "+display+" "+Thread.currentThread()); } } else { tmpDisplay = null; - synchronized(display) { - display.refCount++; + if(DEBUG) { + System.err.println("Display.create("+getFQName(type, name)+") REUSE: refCount "+display.refCount+", "+display+" "+Thread.currentThread()); + } + } + synchronized(display) { + display.refCount++; + if(null==display.aDevice) { + final Display f_dpy = display; + display.runOnEDTIfAvail(true, new Runnable() { + public void run() { + f_dpy.createNative(); + }}); + if(null==display.aDevice) { + throw new RuntimeException("Display.createNative() failed to instanciate an AbstractGraphicsDevice"); + } + setCurrentDisplay(display); if(DEBUG) { - System.err.println("Display.create("+getFQName(type, name)+") REUSE: refCount "+display.refCount+", "+display+" "+Thread.currentThread()); + System.err.println("Display.create("+getFQName(type, name)+") CreateNative: "+display+" "+Thread.currentThread()); } } } @@ -187,7 +176,41 @@ public abstract class Display { } } - public EDTUtil getEDTUtil() { return edtUtil; } + public boolean runCreateAndDestroyOnEDT() { + return true; + } + public EDTUtil getEDTUtil() { + if( !edtQueried ) { + synchronized (this) { + if( !edtQueried ) { + edtQueried = true; + if(NewtFactory.useEDT()) { + final Display f_dpy = this; + Thread current = Thread.currentThread(); + edtUtil = new EDTUtil(current.getThreadGroup(), + "Display_"+getFQName(), + new Runnable() { + public void run() { + if(null!=f_dpy.getGraphicsDevice()) { + f_dpy.pumpMessagesImpl(); + } } } ); + edt = edtUtil.start(); + } + } + } + } + return edtUtil; + } + volatile boolean edtQueried = false; + + public void runOnEDTIfAvail(boolean wait, final Runnable task) { + EDTUtil edtUtil = getEDTUtil(); + if(runCreateAndDestroyOnEDT() && null!=edtUtil) { + edtUtil.invoke(wait, task); + } else { + task.run(); + } + } public synchronized void destroy() { if(DEBUG) { @@ -199,18 +222,17 @@ public abstract class Display { if(DEBUG) { System.err.println("Display.destroy("+getFQName()+") REMOVE: "+this+" "+Thread.currentThread()); } - if(null!=edtUtil) { - final Display f_dpy = this; - final EDTUtil f_edt = edtUtil; - edtUtil.invokeAndWait(new Runnable() { - public void run() { - f_dpy.closeNative(); + final Display f_dpy = this; + final EDTUtil f_edt = edtUtil; + runOnEDTIfAvail(true, new Runnable() { + public void run() { + f_dpy.closeNative(); + if(null!=f_edt) { f_edt.stop(); } - } ); - } else { - closeNative(); - } + } + } ); + if(null!=edtUtil) { edtUtil.waitUntilStopped(); edtUtil=null; diff --git a/src/newt/classes/com/jogamp/newt/Window.java b/src/newt/classes/com/jogamp/newt/Window.java index bb3fa8982..87f0bf0eb 100755 --- a/src/newt/classes/com/jogamp/newt/Window.java +++ b/src/newt/classes/com/jogamp/newt/Window.java @@ -161,11 +161,6 @@ public abstract class Window implements NativeWindow if( null==screen || 0!=windowHandle || !visible ) { return 0 != windowHandle ; } - EDTUtil edtUtil = screen.getDisplay().getEDTUtil(); - if( null != edtUtil && edtUtil.isRunning() && !edtUtil.isCurrentThreadEDT() ) { - throw new NativeWindowException("EDT enabled but not on EDT"); - } - if(DEBUG_IMPLEMENTATION) { System.err.println("Window.createNative() START ("+Thread.currentThread()+", "+this+")"); } @@ -219,12 +214,8 @@ public abstract class Window implements NativeWindow if(null==screen) { throw new RuntimeException("Null screen of inner class: "+this); } - EDTUtil edtUtil = screen.getDisplay().getEDTUtil(); - if(null!=edtUtil) { - edtUtil.invoke(wait, task); - } else { - task.run(); - } + Display d = screen.getDisplay(); + d.runOnEDTIfAvail(wait, task); } /** diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java index d94a32a9c..33c291e96 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTParentWindowAdapter.java @@ -35,12 +35,24 @@ package com.jogamp.newt.event.awt; * Specialized parent/client adapter, * where the NEWT child window really gets resized, * and the parent move window event gets discarded. */ -public class AWTParentWindowAdapter extends AWTWindowAdapter +public class AWTParentWindowAdapter + extends AWTWindowAdapter + implements java.awt.event.HierarchyListener { public AWTParentWindowAdapter(com.jogamp.newt.Window downstream) { super(downstream); } + public AWTAdapter addTo(java.awt.Component awtComponent) { + awtComponent.addHierarchyListener(this); + return super.addTo(awtComponent); + } + + public AWTAdapter removeFrom(java.awt.Component awtComponent) { + awtComponent.removeHierarchyListener(this); + return super.removeFrom(awtComponent); + } + public void componentResized(java.awt.event.ComponentEvent e) { // Need to resize the NEWT child window // the resized event will be send via the native window feedback. @@ -67,5 +79,31 @@ public class AWTParentWindowAdapter extends AWTWindowAdapter public void windowDeactivated(java.awt.event.WindowEvent e) { // no propagation to NEWT child window } + + public void hierarchyChanged(java.awt.event.HierarchyEvent e) { + if( null == newtListener ) { + long bits = e.getChangeFlags(); + final java.awt.Component changed = e.getChanged(); + if( 0 != ( java.awt.event.HierarchyEvent.SHOWING_CHANGED & bits ) ) { + final boolean showing = changed.isShowing(); + if(DEBUG_IMPLEMENTATION) { + System.out.println("hierarchyChanged SHOWING_CHANGED: showing "+showing+", "+changed); + } + if(!newtWindow.isDestroyed()) { + newtWindow.runOnEDTIfAvail(false, new Runnable() { + public void run() { + newtWindow.setVisible(showing); + } + }); + } + } + if( 0 != ( java.awt.event.HierarchyEvent.DISPLAYABILITY_CHANGED & bits ) ) { + final boolean displayability = changed.isDisplayable(); + if(DEBUG_IMPLEMENTATION) { + System.out.println("hierarchyChanged DISPLAYABILITY_CHANGED: displayability "+displayability+", "+changed); + } + } + } + } } diff --git a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java index 53ce03299..570b0678a 100644 --- a/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java +++ b/src/newt/classes/com/jogamp/newt/event/awt/AWTWindowAdapter.java @@ -33,8 +33,7 @@ package com.jogamp.newt.event.awt; public class AWTWindowAdapter extends AWTAdapter - implements java.awt.event.ComponentListener, java.awt.event.WindowListener, - java.awt.event.HierarchyListener, java.awt.event.HierarchyBoundsListener + implements java.awt.event.ComponentListener, java.awt.event.WindowListener { WindowClosingListener windowClosingListener; @@ -53,8 +52,6 @@ public class AWTWindowAdapter public AWTAdapter addTo(java.awt.Component awtComponent) { java.awt.Window win = getWindow(awtComponent); awtComponent.addComponentListener(this); - awtComponent.addHierarchyListener(this); - awtComponent.addHierarchyBoundsListener(this); if( null == windowClosingListener ) { windowClosingListener = new WindowClosingListener(); } @@ -69,8 +66,6 @@ public class AWTWindowAdapter public AWTAdapter removeFrom(java.awt.Component awtComponent) { awtComponent.removeComponentListener(this); - awtComponent.removeHierarchyListener(this); - awtComponent.removeHierarchyBoundsListener(this); java.awt.Window win = getWindow(awtComponent); if( null != win && null != windowClosingListener ) { win.removeWindowListener(windowClosingListener); @@ -110,6 +105,7 @@ public class AWTWindowAdapter } public void componentShown(java.awt.event.ComponentEvent e) { + /** if(null==newtListener) { if(!newtWindow.isDestroyed()) { newtWindow.runOnEDTIfAvail(false, new Runnable() { @@ -118,10 +114,11 @@ public class AWTWindowAdapter } }); } - } + }*/ } public void componentHidden(java.awt.event.ComponentEvent e) { + /** if(null==newtListener) { if(!newtWindow.isDestroyed()) { newtWindow.runOnEDTIfAvail(false, new Runnable() { @@ -130,7 +127,7 @@ public class AWTWindowAdapter } }); } - } + }*/ } public void windowActivated(java.awt.event.WindowEvent e) { @@ -161,52 +158,6 @@ public class AWTWindowAdapter public void windowOpened(java.awt.event.WindowEvent e) { } - public void hierarchyChanged(java.awt.event.HierarchyEvent e) { - if( null == newtListener ) { - long bits = e.getChangeFlags(); - final java.awt.Component changed = e.getChanged(); - if( 0 != ( java.awt.event.HierarchyEvent.SHOWING_CHANGED & bits ) ) { - final boolean showing = changed.isShowing(); - if(DEBUG_IMPLEMENTATION) { - System.out.println("hierarchyChanged SHOWING_CHANGED: showing "+showing+", "+changed); - } - if(!newtWindow.isDestroyed()) { - newtWindow.runOnEDTIfAvail(false, new Runnable() { - public void run() { - newtWindow.setVisible(showing); - } - }); - } - } - if( 0 != ( java.awt.event.HierarchyEvent.DISPLAYABILITY_CHANGED & bits ) ) { - final boolean displayability = changed.isDisplayable(); - if(DEBUG_IMPLEMENTATION) { - System.out.println("hierarchyChanged DISPLAYABILITY_CHANGED: displayability "+displayability+", "+changed); - } - } - } - } - - public void ancestorMoved(java.awt.event.HierarchyEvent e) { - if( null == newtListener ) { - final java.awt.Component changed = e.getChanged(); - final boolean showing = changed.isShowing(); - if(DEBUG_IMPLEMENTATION) { - System.out.println("ancestorMoved: showing "+showing+", "+changed); - } - } - } - - public void ancestorResized(java.awt.event.HierarchyEvent e) { - if( null == newtListener ) { - final java.awt.Component changed = e.getChanged(); - final boolean showing = changed.isShowing(); - if(DEBUG_IMPLEMENTATION) { - System.out.println("ancestorResized: showing "+showing+", "+changed); - } - } - } - class WindowClosingListener implements java.awt.event.WindowListener { public void windowClosing(java.awt.event.WindowEvent e) { com.jogamp.newt.event.WindowEvent event = AWTNewtEventFactory.createWindowEvent(e, newtWindow); diff --git a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java index f54e66f07..e705d364a 100644 --- a/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java +++ b/src/newt/classes/com/jogamp/newt/impl/awt/AWTDisplay.java @@ -54,6 +54,9 @@ public class AWTDisplay extends Display { protected void closeNative() { } + public boolean runCreateAndDestroyOnEDT() { + return false; + } protected void dispatchMessagesNative() { /* nop */ } } diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java index 0c4362a9e..9b9dca2e4 100755 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacDisplay.java @@ -67,7 +67,16 @@ public class MacDisplay extends Display { private DispatchAction dispatchAction = new DispatchAction(); protected void dispatchMessagesNative() { - MainThread.invoke(false, dispatchAction); + if (false && MainThread.isRunning()) { + MainThread.invoke(false, dispatchAction); + } else { + try { + java.awt.EventQueue.invokeLater(dispatchAction); + // java.awt.EventQueue.invokeAndWait(dispatchAction); + } catch (Exception ie) { + ie.printStackTrace(); + } + } } protected void createNative() { @@ -76,6 +85,12 @@ public class MacDisplay extends Display { protected void closeNative() { } + /*public boolean runCreateAndDestroyOnEDT() { + return false; + } + public EDTUtil getEDTUtil() { + return null; + }*/ private static native boolean initNSApplication0(); protected native void dispatchMessages0(); } diff --git a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java index 20a181096..c45a30bc7 100755 --- a/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/macosx/MacWindow.java @@ -36,7 +36,6 @@ package com.jogamp.newt.impl.macosx; import javax.media.nativewindow.*; import com.jogamp.nativewindow.impl.RecursiveToolkitLock; -import com.jogamp.newt.util.MainThread; import com.jogamp.newt.*; import com.jogamp.newt.event.*; import com.jogamp.newt.impl.*; @@ -149,30 +148,23 @@ public class MacWindow extends Window { } } - class CloseAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION) { System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); } - if (windowHandle != 0) { - close0(windowHandle); - } - } catch (Throwable t) { - if(DEBUG_IMPLEMENTATION) { - Exception e = new Exception("closeNative failed - "+Thread.currentThread().getName(), t); - e.printStackTrace(); - } - } finally { - windowHandle = 0; - nsViewLock.unlock(); + protected void closeNative() { + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION) { System.out.println("MacWindow.CloseAction "+Thread.currentThread().getName()); } + if (windowHandle != 0) { + close0(windowHandle); } + } catch (Throwable t) { + if(DEBUG_IMPLEMENTATION) { + Exception e = new Exception("closeNative failed - "+Thread.currentThread().getName(), t); + e.printStackTrace(); + } + } finally { + windowHandle = 0; + nsViewLock.unlock(); } } - private CloseAction closeAction = new CloseAction(); - - protected void closeNative() { - MainThread.invoke(true, closeAction); - } public long getWindowHandle() { nsViewLock.lock(); @@ -192,25 +184,12 @@ public class MacWindow extends Window { } } - class EnsureWindowCreatedAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); - } finally { - nsViewLock.unlock(); - } - } - } - private EnsureWindowCreatedAction ensureWindowCreatedAction = - new EnsureWindowCreatedAction(); - public Insets getInsets() { // in order to properly calculate insets we need the window to be // created - MainThread.invoke(true, ensureWindowCreatedAction); nsViewLock.lock(); try { + createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); return (Insets) insets.clone(); } finally { nsViewLock.unlock(); @@ -235,120 +214,84 @@ public class MacWindow extends Window { } protected void setVisibleImpl(final boolean visible) { - MainThread.invoke(true, new Runnable() { - public void run() { - nsViewLock.lock(); - try { - if (visible) { - createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); - if (windowHandle != 0) { - makeKeyAndOrderFront0(windowHandle); - } - } else { - if (windowHandle != 0) { - orderOut0(windowHandle); - } - } - } finally { - nsViewLock.unlock(); + nsViewLock.lock(); + try { + if (visible) { + createWindow(false, getX(), getY(), getWidth(), getHeight(), isFullscreen()); + if (windowHandle != 0) { + makeKeyAndOrderFront0(windowHandle); } - } - }); - } - - class TitleAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { + } else { if (windowHandle != 0) { - setTitle0(windowHandle, title); + orderOut0(windowHandle); } - } finally { - nsViewLock.unlock(); } + } finally { + nsViewLock.unlock(); } } - private TitleAction titleAction = new TitleAction(); public void setTitle(String title) { super.setTitle(title); - MainThread.invoke(true, titleAction); - } - - class FocusAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - makeKey0(windowHandle); - } - } finally { - nsViewLock.unlock(); + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setTitle0(windowHandle, title); } + } finally { + nsViewLock.unlock(); } } - private FocusAction focusAction = new FocusAction(); public void requestFocus() { super.requestFocus(); - MainThread.invoke(true, focusAction); - } - - class SizeAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setContentSize0(windowHandle, width, height); - } - } finally { - nsViewLock.unlock(); + nsViewLock.lock(); + try { + if (windowHandle != 0) { + makeKey0(windowHandle); } + } finally { + nsViewLock.unlock(); } } - private SizeAction sizeAction = new SizeAction(); - + protected void setSizeImpl(int width, int height) { // this width/height will be set by sizeChanged, called by OSX - MainThread.invoke(true, sizeAction); - } - - class PositionAction implements Runnable { - public void run() { - nsViewLock.lock(); - try { - if (windowHandle != 0) { - setFrameTopLeftPoint0(parentWindowHandle, windowHandle, x, y); - } - } finally { - nsViewLock.unlock(); + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setContentSize0(windowHandle, width, height); } + } finally { + nsViewLock.unlock(); } } - private PositionAction positionAction = new PositionAction(); - + protected void setPositionImpl(int x, int y) { // this x/y will be set by positionChanged, called by OSX - MainThread.invoke(true, positionAction); + nsViewLock.lock(); + try { + if (windowHandle != 0) { + setFrameTopLeftPoint0(parentWindowHandle, windowHandle, x, y); + } + } finally { + nsViewLock.unlock(); + } } protected boolean setFullscreenImpl(final boolean fullscreen, final int x, final int y, final int w, final int h) { - MainThread.invoke(true, new Runnable() { - public void run() { - nsViewLock.lock(); - try { - if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { - System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); - } - createWindow(true, x, y, w, h, fullscreen); - if (windowHandle != 0) { - makeKeyAndOrderFront0(windowHandle); - } - } finally { - nsViewLock.unlock(); - } + nsViewLock.lock(); + try { + if(DEBUG_IMPLEMENTATION || DEBUG_WINDOW_EVENT) { + System.err.println("MacWindow fs: "+fullscreen+" "+x+"/"+y+" "+w+"x"+h); } - }); + createWindow(true, x, y, w, h, fullscreen); + if (windowHandle != 0) { + makeKeyAndOrderFront0(windowHandle); + } + } finally { + nsViewLock.unlock(); + } return fullscreen; } @@ -500,35 +443,45 @@ public class MacWindow extends Window { super.sendKeyEvent(eventType, modifiers, key, keyChar); } - private void createWindow(boolean recreate, int x, int y, int width, int height, boolean fullscreen) { + private void createWindow(final boolean recreate, final int x, final int y, final int width, final int height, final boolean fullscreen) { + if(0!=windowHandle && !recreate) { return; } - if(0!=windowHandle) { - // save the view .. close the window - surfaceHandle = changeContentView0(parentWindowHandle, windowHandle, 0); - if(recreate && 0==surfaceHandle) { - throw new NativeWindowException("Internal Error - recreate, window but no view"); - } - close0(windowHandle); - windowHandle=0; - } else { - surfaceHandle = 0; - } - windowHandle = createWindow0(parentWindowHandle, - x, y, width, height, fullscreen, - (isUndecorated(fullscreen) ? - NSBorderlessWindowMask : - NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), - NSBackingStoreBuffered, - getScreen().getIndex(), surfaceHandle); - if (windowHandle == 0) { - throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); + + try { + java.awt.EventQueue.invokeAndWait(new Runnable() { + public void run() { + if(0!=windowHandle) { + // save the view .. close the window + surfaceHandle = changeContentView0(parentWindowHandle, windowHandle, 0); + if(recreate && 0==surfaceHandle) { + throw new NativeWindowException("Internal Error - recreate, window but no view"); + } + close0(windowHandle); + windowHandle=0; + } else { + surfaceHandle = 0; + } + windowHandle = createWindow0(parentWindowHandle, + x, y, width, height, fullscreen, + (isUndecorated(fullscreen) ? + NSBorderlessWindowMask : + NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask), + NSBackingStoreBuffered, + getScreen().getIndex(), surfaceHandle); + if (windowHandle == 0) { + throw new NativeWindowException("Could create native window "+Thread.currentThread().getName()+" "+this); + } + surfaceHandle = contentView0(windowHandle); + setTitle0(windowHandle, getTitle()); + // don't make the window visible on window creation + // makeKeyAndOrderFront0(windowHandle); + } } ); + } catch (Exception ie) { + ie.printStackTrace(); } - surfaceHandle = contentView0(windowHandle); - setTitle0(windowHandle, getTitle()); - // don't make the window visible on window creation -// makeKeyAndOrderFront0(windowHandle); + sendWindowEvent(WindowEvent.EVENT_WINDOW_MOVED); sendWindowEvent(WindowEvent.EVENT_WINDOW_RESIZED); sendWindowEvent(WindowEvent.EVENT_WINDOW_GAINED_FOCUS); diff --git a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java index 2bb28466c..9559043c4 100644 --- a/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java +++ b/src/newt/classes/com/jogamp/newt/opengl/GLWindow.java @@ -120,10 +120,14 @@ public class GLWindow extends Window implements GLAutoDrawable { return (null!=window)?window.isDestroyed():true; } - public Window getInnerWindow() { + public final Window getInnerWindow() { return window.getInnerWindow(); } + public final Object getWrappedWindow() { + return window.getWrappedWindow(); + } + /** * EXPERIMENTAL<br> * Enable or disables running the {@link Display#pumpMessages} in the {@link #display()} call.<br> @@ -244,8 +248,8 @@ public class GLWindow extends Window implements GLAutoDrawable { window.setVisible(visible); if (null == context && visible && 0 != window.getWindowHandle() && 0<getWidth()*getHeight()) { NativeWindow nw; - if (window.getWrappedWindow() != null) { - nw = NativeWindowFactory.getNativeWindow(window.getWrappedWindow(), window.getGraphicsConfiguration()); + if (getWrappedWindow() != null) { + nw = NativeWindowFactory.getNativeWindow(getWrappedWindow(), window.getGraphicsConfiguration()); } else { nw = window; } diff --git a/src/newt/native/NewtMacWindow.h b/src/newt/native/NewtMacWindow.h index 4f0561dd5..7f0cd60c6 100644 --- a/src/newt/native/NewtMacWindow.h +++ b/src/newt/native/NewtMacWindow.h @@ -55,7 +55,7 @@ @end -#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 +#if defined(MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 @interface NewtMacWindow : NSWindow <NSWindowDelegate> #else @interface NewtMacWindow : NSWindow |