aboutsummaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-06-10 09:35:06 +0200
committerSven Gothel <[email protected]>2010-06-10 09:35:06 +0200
commit1d333a771ce0bc7c8594e21d031703f698f06a46 (patch)
tree933d470582896320855fa1d98c1a917edc412c24 /src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl
parent4512900ddcb9ce9a498411d257b1b6d6010ec006 (diff)
Fix: Locking/Threading; Common IntIntHashMap and Buffers; Fix: glMap*Buffer*; GLX/WGL/CgGL: All runtime dynamic; Misc ..
TODO: Compile and test on MacOSX .. Fix: ===== Multithreading/Locking: See jogl/doc/Implementation/MultiThreading.txt - Locking layer is not platform agnostic, ie GLContextImpl, GLDrawableImpl, .. and NEWT: Window/Display - No more use of JAWT global lock necessary, removed. - No need for X11 Display lock, on the contrary, this made the NV driver hang. - Use common window/surface lock - All NativeWindow surfaceLock's are recursive now glMapBuffer: If size is 0, don't do cont with the native call. glMapBufferRange: Fix capacity. glNamedBufferDataEXT: Track the size. glMapNamedBufferEXT: Manual impl. - use the tracked size glXGetVisualFromFBConfig, glXChooseFBConfig, glXChooseVisual: Instead of ignoring and implement a renamed version (*Copied), we just use ManualImplementation for the proper copy-result code. DesktopGLDynamicLookupHelper: Initialize _hasGLBinding* attributes in the determing loadGLJNILibrary() method, which is called by super(). Otherwise static init will overwrite them after the super() call. X11GLXDrawableFactory: Don't release anything at shutdown (removed sharedContext.destroy()), since this caused a freeze/SEGV sometimes. Fixed NEWT's reparentWindow() functionality incl NewtCanvasAWT usage. - Native: if not visible, don't focus, etc - NewtCanvasAWT: Use the container size to start with - Run the command on the EDT Using GlueGen's new DynamicLibraryBundle utility: - X11, Windows and MacOSX OpenGL adapted to DynamicLibraryBundleInfo. - X11GLXDynamicLookupHelper -> X11GLXDynamicLibraryBundleInfo - Remove all path from lib names. - GL order: libGL.so.1, libGL.so, GL - shallLinkGlobal: true -> to server some 'old' DRI systems -> http://dri.sourceforge.net/doc/DRIuserguide.html - shallLookupGlobal: false - Try both : glXGetProcAddressARB and glXGetProcAddress - Using bootstrap: GLX.glXGetProcAddress(long glxGetProcAddressHandle, String glFuncName) Found the issue with LIBGL_DRIVERS_PATH, ie if not set no valid GL instance can be found (ie ATI fglrx/DRI). This may happen if using a differen user than the desktop user for whom the env var is set within some /etc/X11/Xsession.d/ script. Enhancements: ============= GLBufferSizeTracker: Use IntIntHashMap and add DirectState size tracking. GLBufferStateTracker: Use IntIntHashMap. GLStateTracker: Use IntIntHashMap. GLDynamicLookupHelper: More generic (global loading/lookup and GetProcAddress function name list), remove redundant code. FIXME: MacOSXCGLDynamicLookupHelper: - Not tested - Not using NSImage lookup anymore as recommended by OSX API Doc, so dlsym is used always (to be tested) WindowsWGLDynamicLookupHelper: - Not tested GLX/WGL/CgGL is all runtime-dynamic as now, ie loaded and looked-up at runtime, no compile time dependencies to GL anymore, nor a need to specify CgGL. Split up WGL in GDI and WGL, to allow proper dynamic runtime linkage of OpenGL32 while using static binding to GDI32 NEWT events generated by native code are enqueued and not send directly. This should ease locking mechanisms .. if any are necessary. NEWT: More platform specific code moved to *Impl method, simplifying the generic code of the superclass and impl protocol. Cleanup: ========= Replace all InternalBufferUtil's with com.jogamp.common.nio.Buffers Removed all InternalBufferUtil's from repository Removed GLContextImpl notion of 'optimized' surface locking, where the surface gets unlocked during makeCurrent/release. This just makes no sense and would impact multithreading in a horrible way.
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl')
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java45
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java10
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java21
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDynamicLibraryBundleInfo.java (renamed from src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDynamicLookupHelper.java)60
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXExternalCGLContext.java86
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXOnscreenCGLContext.java51
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLContext.java49
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java2
-rw-r--r--src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/awt/MacOSXJava2DCGLContext.java31
9 files changed, 104 insertions, 251 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLContext.java
index 371df1ee5..46b86a557 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
@@ -134,7 +134,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl
int[] viewNotReady = new int[1];
// Try to allocate a context with this
contextHandle = CGL.createContext(share,
- drawable.getNativeWindow().getSurfaceHandle(),
+ drawable.getHandle(),
pixelFormat,
viewNotReady, 0);
if (contextHandle == 0) {
@@ -166,26 +166,8 @@ public abstract class MacOSXCGLContext extends GLContextImpl
GLContextShareSet.contextCreated(this);
return true;
}
-
- protected int makeCurrentImpl() throws GLException {
- if (0 == drawable.getNativeWindow().getSurfaceHandle()) {
- throw new GLException("drawable has invalid surface handle: "+drawable);
- }
- boolean newCreated = false;
- if (!isCreated()) {
- create();
- 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(contextHandle) + " for " + getClass().getName());
- }
- }
-
+
+ protected void makeCurrentImpl(boolean newCreated) throws GLException {
if ( isNSContext ) {
if (!CGL.makeCurrentContext(contextHandle)) {
throw new GLException("Error making Context (NS) current");
@@ -195,12 +177,6 @@ public abstract class MacOSXCGLContext extends GLContextImpl
throw new GLException("Error making Context (CGL) current");
}
}
-
- if (newCreated) {
- setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
- return CONTEXT_CURRENT_NEW;
- }
- return CONTEXT_CURRENT;
}
protected void releaseImpl() throws GLException {
@@ -214,9 +190,6 @@ public abstract class MacOSXCGLContext extends GLContextImpl
}
protected void destroyImpl() throws GLException {
- if( ! isCreated() ) {
- return;
- }
if ( !isNSContext ) {
if (CGL.kCGLNoError != CGL.CGLDestroyContext(contextHandle)) {
throw new GLException("Unable to delete OpenGL Context (CGL)");
@@ -224,8 +197,6 @@ public abstract class MacOSXCGLContext extends GLContextImpl
if (DEBUG) {
System.err.println("!!! Destroyed OpenGL Context (CGL) " + contextHandle);
}
- contextHandle = 0;
- GLContextShareSet.contextDestroyed(this);
} else {
if (!CGL.deleteContext(contextHandle)) {
throw new GLException("Unable to delete OpenGL Context (NS)");
@@ -233,20 +204,12 @@ public abstract class MacOSXCGLContext extends GLContextImpl
if (DEBUG) {
System.err.println("!!! Destroyed OpenGL Context (NS) " + contextHandle);
}
- contextHandle = 0;
}
- GLContextShareSet.contextDestroyed(this);
}
- public void copy(GLContext source, int mask) throws GLException {
+ protected void copyImpl(GLContext source, int mask) throws GLException {
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.");
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java
index 3f41d95cb..23fdcbf6d 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawable.java
@@ -42,7 +42,6 @@ package com.jogamp.opengl.impl.macosx.cgl;
import javax.media.nativewindow.*;
import javax.media.opengl.*;
import com.jogamp.opengl.impl.*;
-import com.jogamp.common.os.DynamicLookupHelper;
public abstract class MacOSXCGLDrawable extends GLDrawableImpl {
// The Java2D/OpenGL pipeline on OS X uses low-level CGLContextObjs
@@ -83,17 +82,10 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl {
}
protected void setRealizedImpl() {
- if(realized) {
- if( NativeWindow.LOCK_SURFACE_NOT_READY == lockSurface() ) {
- throw new GLException("Couldn't lock surface");
- }
- // locking the surface is essential to update surface data
- unlockSurface();
- }
}
public GLDynamicLookupHelper getGLDynamicLookupHelper() {
- return MacOSXCGLDynamicLookupHelper.getMacOSXCGLDynamicLookupHelper();
+ return getFactoryImpl().getGLDynamicLookupHelper(0);
}
protected static String getThreadName() {
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java
index e507e4886..7f050412d 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDrawableFactory.java
@@ -48,9 +48,26 @@ import com.jogamp.opengl.impl.*;
import com.jogamp.nativewindow.impl.NullWindow;
public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
+ private static final DesktopGLDynamicLookupHelper macOSXCGLDynamicLookupHelper;
+
+ static {
+ DesktopGLDynamicLookupHelper tmp = null;
+ try {
+ tmp = new DesktopGLDynamicLookupHelper(new MacOSXCGLDynamicLibraryBundleInfo());
+ } catch (GLException gle) {
+ if(DEBUG) {
+ gle.printStackTrace();
+ }
+ }
+ macOSXCGLDynamicLookupHelper = tmp;
+ /** FIXME ??
+ if(null!=macOSXCGLDynamicLookupHelper) {
+ CGL.getCGLProcAddressTable().reset(macOSXCGLDynamicLookupHelper);
+ } */
+ }
public GLDynamicLookupHelper getGLDynamicLookupHelper(int profile) {
- return MacOSXCGLDynamicLookupHelper.getMacOSXCGLDynamicLookupHelper();
+ return macOSXCGLDynamicLookupHelper;
}
public MacOSXCGLDrawableFactory() {
@@ -60,8 +77,6 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
// The act of constructing them causes them to be registered
new MacOSXCGLGraphicsConfigurationFactory();
- MacOSXCGLDynamicLookupHelper.getMacOSXCGLDynamicLookupHelper(); // setup and initialize
-
try {
ReflectionUtil.createInstance("com.jogamp.opengl.impl.macosx.cgl.awt.MacOSXAWTCGLGraphicsConfigurationFactory",
new Object[] {});
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDynamicLookupHelper.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDynamicLibraryBundleInfo.java
index 3ed75b245..154cf61b5 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDynamicLookupHelper.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXCGLDynamicLibraryBundleInfo.java
@@ -35,59 +35,37 @@ import java.util.*;
import java.security.*;
import javax.media.opengl.GLException;
-public class MacOSXCGLDynamicLookupHelper extends DesktopGLDynamicLookupHelper {
- private static final MacOSXCGLDynamicLookupHelper macOSXCGLDynamicLookupHelper;
-
- static {
- MacOSXCGLDynamicLookupHelper tmp = null;
- try {
- tmp = new MacOSXCGLDynamicLookupHelper();
- } catch (GLException gle) {
- if(DEBUG) {
- gle.printStackTrace();
- }
- }
- macOSXCGLDynamicLookupHelper = tmp;
- }
-
- public static MacOSXCGLDynamicLookupHelper getMacOSXCGLDynamicLookupHelper() {
- return macOSXCGLDynamicLookupHelper;
- }
-
- protected MacOSXCGLDynamicLookupHelper() {
+public class MacOSXCGLDynamicLibraryBundleInfo extends DesktopGLDynamicLibraryBundleInfo {
+ protected MacOSXCGLDynamicLibraryBundleInfo() {
super();
}
- public synchronized void loadGLULibrary() {
- if(null==gluLib) {
- List/*<String>*/ gluLibNames = new ArrayList();
- gluLibNames.add("/System/Library/Frameworks/OpenGL.framework/Libraries/libGLU.dylib");
- gluLibNames.add("GLU");
- gluLib = loadFirstAvailable(gluLibNames, null, false);
- if(null != gluLib) {
- glLibraries.add(gluLib);
- }
- }
- }
- NativeLibrary gluLib = null;
+ public List getToolLibNames() {
+ List/*<List>*/ libNamesList = new ArrayList();
- protected final List/*<String>*/ getGLLibNames() {
List/*<String>*/ glesLibNames = new ArrayList();
+
glesLibNames.add("/System/Library/Frameworks/OpenGL.framework/Libraries/libGL.dylib");
glesLibNames.add("GL");
- return glesLibNames;
- }
- protected final List/*<String>*/ getGLXLibNames() {
- return null;
+ libNamesList.add(glesLibNames);
+
+ return libNamesList;
}
- protected final String getGLXGetProcAddressFuncName() {
- return "getProcAddress" ; // dummy
+ public final List getToolGetProcAddressFuncNameList() {
+ return null;
+ /** OSX manual says: NSImage use is discouraged
+ List res = new ArrayList();
+ res.add("GetProcAddress"); // dummy
+ return res; */
}
- protected long dynamicLookupFunctionOnGLX(long glxGetProcAddressHandle, String glFuncName) {
- return CGL.getProcAddress(glFuncName); // manual implementation
+ public final long toolDynamicLookupFunction(long toolGetProcAddressHandle, String funcName) {
+ return 0;
+ /** OSX manual says: NSImage use is discouraged
+ return CGL.getProcAddress(glFuncName); // manual implementation
+ */
}
}
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 9865fdfca..e8518925a 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
@@ -60,56 +60,52 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext {
}
protected static MacOSXExternalCGLContext create(GLDrawableFactory factory, GLProfile glp) {
- ((GLDrawableFactoryImpl)factory).lockToolkit();
- try {
- long pixelFormat = 0;
- long currentDrawable = 0;
- 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 Context (CGL) of Context (NS) 0x" +Long.toHexString(contextHandle));
- }
- pixelFormat = CGL.CGLGetPixelFormat(ctx);
- if(DEBUG) {
- System.err.println("MacOSXExternalCGLContext Create Context (NS) 0x"+Long.toHexString(contextHandle)+
- ", Context (CGL) 0x"+Long.toHexString(ctx)+
- ", pixelFormat 0x"+Long.toHexString(pixelFormat));
- }
- } else {
- contextHandle = CGL.CGLGetCurrentContext();
- if (contextHandle == 0) {
- throw new GLException("Error: current Context (CGL) null, no Context (NS)");
- }
- pixelFormat = CGL.CGLGetPixelFormat(contextHandle);
- if(DEBUG) {
- System.err.println("MacOSXExternalCGLContext Create Context (CGL) 0x"+Long.toHexString(contextHandle)+
- ", pixelFormat 0x"+Long.toHexString(pixelFormat));
- }
+ long pixelFormat = 0;
+ long currentDrawable = 0;
+ 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 Context (CGL) of Context (NS) 0x" +Long.toHexString(contextHandle));
}
-
- if (0 == pixelFormat) {
- throw new GLException("Error: current pixelformat of current Context 0x"+Long.toHexString(contextHandle)+" is null");
+ pixelFormat = CGL.CGLGetPixelFormat(ctx);
+ if(DEBUG) {
+ System.err.println("MacOSXExternalCGLContext Create Context (NS) 0x"+Long.toHexString(contextHandle)+
+ ", Context (CGL) 0x"+Long.toHexString(ctx)+
+ ", pixelFormat 0x"+Long.toHexString(pixelFormat));
}
- GLCapabilities caps = MacOSXCGLGraphicsConfiguration.CGLPixelFormat2GLCapabilities(glp, pixelFormat);
+ } else {
+ contextHandle = CGL.CGLGetCurrentContext();
+ if (contextHandle == 0) {
+ throw new GLException("Error: current Context (CGL) null, no Context (NS)");
+ }
+ pixelFormat = CGL.CGLGetPixelFormat(contextHandle);
if(DEBUG) {
- System.err.println("MacOSXExternalCGLContext Create "+caps);
+ System.err.println("MacOSXExternalCGLContext Create Context (CGL) 0x"+Long.toHexString(contextHandle)+
+ ", pixelFormat 0x"+Long.toHexString(pixelFormat));
}
+ }
- AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault();
- MacOSXCGLGraphicsConfiguration cfg = new MacOSXCGLGraphicsConfiguration(aScreen, caps, caps, pixelFormat);
-
- NullWindow nw = new NullWindow(cfg);
- nw.setSurfaceHandle(currentDrawable);
- return new MacOSXExternalCGLContext(new Drawable(factory, nw), isNSContext, contextHandle);
- } finally {
- ((GLDrawableFactoryImpl)factory).unlockToolkit();
+ if (0 == pixelFormat) {
+ throw new GLException("Error: current pixelformat of current Context 0x"+Long.toHexString(contextHandle)+" is null");
+ }
+ GLCapabilities caps = MacOSXCGLGraphicsConfiguration.CGLPixelFormat2GLCapabilities(glp, pixelFormat);
+ if(DEBUG) {
+ System.err.println("MacOSXExternalCGLContext Create "+caps);
}
+
+ AbstractGraphicsScreen aScreen = DefaultGraphicsScreen.createDefault();
+ MacOSXCGLGraphicsConfiguration cfg = new MacOSXCGLGraphicsConfiguration(aScreen, caps, caps, pixelFormat);
+
+ NullWindow nw = new NullWindow(cfg);
+ nw.setSurfaceHandle(currentDrawable);
+ return new MacOSXExternalCGLContext(new Drawable(factory, nw), isNSContext, contextHandle);
}
- protected void create() {
+ protected boolean createImpl() throws GLException {
+ return true;
}
public int makeCurrent() throws GLException {
@@ -129,20 +125,16 @@ public class MacOSXExternalCGLContext extends MacOSXCGLContext {
lastContext = null;
}
- protected int makeCurrentImpl() throws GLException {
+ protected void makeCurrentImpl(boolean newCreated) throws GLException {
if (firstMakeCurrent) {
firstMakeCurrent = false;
- return CONTEXT_CURRENT_NEW;
}
- return CONTEXT_CURRENT;
}
protected void releaseImpl() throws GLException {
}
protected void destroyImpl() throws GLException {
- contextHandle = 0;
- GLContextShareSet.contextDestroyed(this);
}
public void setOpenGLMode(int mode) {
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 ede0c28eb..568204384 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
@@ -54,52 +54,13 @@ public class MacOSXOnscreenCGLContext extends MacOSXCGLContext {
this.drawable = drawable;
}
- protected int makeCurrentImpl() throws GLException {
- int lockRes = drawable.lockSurface();
- boolean exceptionOccurred = false;
- try {
- if (lockRes == NativeWindow.LOCK_SURFACE_NOT_READY) {
- return CONTEXT_NOT_CURRENT;
- }
- int ret = super.makeCurrentImpl();
- if ((ret == CONTEXT_CURRENT) ||
- (ret == CONTEXT_CURRENT_NEW)) {
- // Assume the canvas might have been resized or moved and tell the OpenGL
- // context to update itself. This used to be done only upon receiving a
- // reshape event but that doesn't appear to be sufficient. An experiment
- // was also done to add a HierarchyBoundsListener to the GLCanvas and
- // 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(contextHandle);
- } else {
- if (!isOptimizable()) {
- // This can happen if the window currently is zero-sized, for example.
- // Make sure we don't leave the surface locked in this case.
- drawable.unlockSurface();
- lockRes = NativeWindow.LOCK_SURFACE_NOT_READY;
- }
- }
- return ret;
- } catch (RuntimeException e) {
- exceptionOccurred = true;
- throw e;
- } finally {
- if (exceptionOccurred ||
- (isOptimizable() && lockRes != NativeWindow.LOCK_SURFACE_NOT_READY)) {
- drawable.unlockSurface();
- }
- }
+ protected void makeCurrentImpl(boolean newCreated) throws GLException {
+ super.makeCurrentImpl(newCreated);
+ CGL.updateContext(contextHandle);
}
protected void releaseImpl() throws GLException {
- try {
- super.releaseImpl();
- } finally {
- if (!isOptimizable() && drawable.isSurfaceLocked()) {
- drawable.unlockSurface();
- }
- }
+ super.releaseImpl();
}
protected void swapBuffers() {
@@ -115,8 +76,8 @@ public class MacOSXOnscreenCGLContext extends MacOSXCGLContext {
CGL.updateContext(contextHandle);
}
- protected void create() {
- create(false, false);
+ protected boolean createImpl() {
+ return create(false, false);
}
public void setOpenGLMode(int mode) {
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 391908540..9c630d24b 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,45 +38,22 @@ 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(contextHandle, drawable.getPbuffer(), GL.GL_FRONT);
+ CGL.setContextTextureImageToPBuffer(contextHandle, drawable.getHandle(), GL.GL_FRONT);
}
public void releasePbufferFromTexture() {
}
- protected int makeCurrentImpl() throws GLException {
- if (drawable.getPbuffer() == 0) {
- if (DEBUG) {
- System.err.println("Pbuffer not instantiated yet for " + this);
- }
- // pbuffer not instantiated yet
- return CONTEXT_NOT_CURRENT;
- }
-
+ protected void makeCurrentImpl(boolean newCreated) throws GLException {
if (getOpenGLMode() != drawable.getOpenGLMode()) {
setOpenGLMode(drawable.getOpenGLMode());
}
- if (contextHandle == 0) {
- create();
- if(!isCreated()) {
- return CONTEXT_NOT_CURRENT;
- }
- if(!isNSContext()) {
- throw new GLException("Not a NS Context");
- }
- if (DEBUG) {
- System.err.println("!!! Created OpenGL context (NS) " + toHexString(contextHandle) + " for " + getClass().getName());
- }
- }
-
if (!impl.makeCurrent(contextHandle)) {
throw new GLException("Error making Context (NS) current");
}
- if (isCreated()) {
- setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
-
+ if (newCreated) {
// Initialize render-to-texture support if requested
DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
GLCapabilities capabilities = (GLCapabilities)config.getChosenCapabilities();
@@ -99,10 +76,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
gl.glTexParameteri(textureTarget, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
gl.glCopyTexImage2D(textureTarget, 0, GL.GL_RGB, 0, 0, drawable.getWidth(), drawable.getHeight(), 0);
-
- return CONTEXT_CURRENT_NEW;
}
- return CONTEXT_CURRENT;
}
protected void releaseImpl() throws GLException {
@@ -112,22 +86,15 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
}
protected void destroyImpl() throws GLException {
- if (contextHandle != 0) {
if (!impl.destroy(contextHandle)) {
throw new GLException("Unable to delete OpenGL context");
}
if (DEBUG) {
System.err.println("!!! Destroyed OpenGL context " + contextHandle);
}
- contextHandle = 0;
- GLContextShareSet.contextDestroyed(this);
- }
}
protected void setSwapIntervalImpl(int interval) {
- if (contextHandle == 0) {
- throw new GLException("OpenGL context not current");
- }
impl.setSwapInterval(contextHandle, interval);
currentSwapInterval = impl.getSwapInterval() ;
}
@@ -136,7 +103,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
return GLPbuffer.APPLE_FLOAT;
}
- protected void create() {
+ protected boolean createImpl() throws GLException {
DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeWindow().getGraphicsConfiguration().getNativeGraphicsConfiguration();
GLCapabilities capabilities = (GLCapabilities)config.getChosenCapabilities();
if (capabilities.getPbufferFloatingPointBuffers() &&
@@ -155,7 +122,11 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
if (!impl.makeCurrent(contextHandle)) {
throw new GLException("Error making Context (NS:"+isNSContext()+") current");
}
+ if(!isNSContext()) { // FIXME: ??
+ throw new GLException("Not a NS Context");
+ }
setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
+ return true;
}
//---------------------------------------------------------------------------
@@ -231,7 +202,7 @@ 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(contextHandle, drawable.getPbuffer());
+ CGL.setContextPBuffer(contextHandle, drawable.getHandle());
return contextHandle;
}
@@ -335,7 +306,7 @@ public class MacOSXPbufferCGLContext extends MacOSXCGLContext {
throw new GLException("Error code " + res + " while creating context");
}
// Attach newly-created context to the pbuffer
- res = CGL.CGLSetPBuffer(ctx.get(0), drawable.getPbuffer(), 0, 0, 0);
+ res = CGL.CGLSetPBuffer(ctx.get(0), drawable.getHandle(), 0, 0, 0);
if (res != CGL.kCGLNoError) {
throw new GLException("Error code " + res + " while attaching context to pbuffer");
}
diff --git a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java
index afdc40dbb..64d646cfb 100644
--- a/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java
+++ b/src/jogl/classes/com/jogamp/opengl/impl/macosx/cgl/MacOSXPbufferCGLDrawable.java
@@ -96,7 +96,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable {
}
}
- public long getPbuffer() {
+ public long getHandle() {
return pBuffer;
}
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 9a90cbdc4..b42f1132c 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
@@ -70,29 +70,13 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL
this.graphics = g;
}
- protected int makeCurrentImpl() throws GLException {
- if (contextHandle == 0) {
- create();
- if(!isCreated()) {
- return CONTEXT_NOT_CURRENT;
- }
- if (DEBUG) {
- System.err.println("!!! Created GL Context (NS) for " + getClass().getName());
- }
- }
-
+ protected void makeCurrentImpl(boolean newCreated) throws GLException {
if (!Java2D.makeOGLContextCurrentOnSurface(graphics, contextHandle)) {
throw new GLException("Error making context current");
- }
-
- if (isCreated()) {
- setGLFunctionAvailability(false, -1, -1, CTX_PROFILE_COMPAT|CTX_OPTION_ANY);
- return CONTEXT_CURRENT_NEW;
- }
- return CONTEXT_CURRENT;
+ }
}
- protected void create() {
+ protected boolean createImpl() {
// Find and configure share context
MacOSXCGLContext other = (MacOSXCGLContext) GLContextShareSet.getShareContext(this);
long share = 0;
@@ -118,11 +102,13 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL
long ctx = Java2D.createOGLContextOnSurface(graphics, share);
if (ctx == 0) {
- return;
+ return false;
}
+ setGLFunctionAvailability(true, 0, 0, CTX_PROFILE_COMPAT|CTX_OPTION_ANY); // use GL_VERSION
// FIXME: think about GLContext sharing
contextHandle = ctx;
isNSContext = true;
+ return true;
}
protected void releaseImpl() throws GLException {
@@ -132,15 +118,10 @@ public class MacOSXJava2DCGLContext extends MacOSXCGLContext implements Java2DGL
}
protected void destroyImpl() throws GLException {
- if (contextHandle != 0) {
Java2D.destroyOGLContext(contextHandle);
if (DEBUG) {
System.err.println("!!! Destroyed OpenGL context " + contextHandle);
}
- contextHandle = 0;
- // FIXME
- // GLContextShareSet.contextDestroyed(this);
- }
}
public void setOpenGLMode(int mode) {