summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--make/stub_includes/opengl/macosx-window-system.h1
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java75
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java4
-rw-r--r--src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m1
-rw-r--r--src/jogl/native/macosx/MacOSXWindowSystemInterface.m13
-rw-r--r--src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java3
-rw-r--r--src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java3
7 files changed, 74 insertions, 26 deletions
diff --git a/make/stub_includes/opengl/macosx-window-system.h b/make/stub_includes/opengl/macosx-window-system.h
index aaa0cc42e..a2da66878 100644
--- a/make/stub_includes/opengl/macosx-window-system.h
+++ b/make/stub_includes/opengl/macosx-window-system.h
@@ -36,6 +36,7 @@ NSOpenGLContext* createContext(NSOpenGLContext* shareContext,
NSOpenGLPixelFormat* pixelFormat,
Bool opaque,
int* viewNotReady);
+void setContextView(NSOpenGLContext* ctx, NSView* view);
Bool makeCurrentContext(NSOpenGLContext* ctx);
Bool clearCurrentContext(NSOpenGLContext *ctx);
Bool deleteContext(NSOpenGLContext* ctx, Bool releaseOnMainThread);
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
index 360b7457b..1c59b8d97 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
@@ -84,6 +84,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl
// NSOpenGL-based or CGL-based)
protected interface GLBackendImpl {
boolean isNSContext();
+ void drawableChangedNotify();
long create(long share, int ctp, int major, int minor);
boolean destroy(long ctx);
boolean contextRealized(boolean realized);
@@ -336,7 +337,13 @@ public abstract class MacOSXCGLContext extends GLContextImpl
super.contextRealized(false); // 2) free drawable stuff
}
}
-
+
+ /* pp */ void drawableChangedNotify() {
+ if( 0 != contextHandle) {
+ impl.drawableChangedNotify();
+ }
+ }
+
/* pp */ void detachPBuffer() {
impl.detachPBuffer();
}
@@ -475,7 +482,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl
class NSOpenGLImpl implements GLBackendImpl {
private OffscreenLayerSurface backingLayerHost = null;
private long nsOpenGLLayer = 0;
- private long nsOpenGLLayerPFmt = 0;
+ private long nsOpenGLLayerPFmt = 0; // lifecycle: [create - contextRealized]
private float screenVSyncTimeout; // microSec
private int vsyncTimeout; // microSec - for nsOpenGLLayer mode
private int lastWidth=0, lastHeight=0; // allowing to detect size change
@@ -486,26 +493,31 @@ public abstract class MacOSXCGLContext extends GLContextImpl
public boolean isNSContext() { return true; }
@Override
- public long create(long share, int ctp, int major, int minor) {
- long ctx = 0;
- final NativeSurface surface = drawable.getNativeSurface();
- final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) surface.getGraphicsConfiguration();
- final GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
+ public void drawableChangedNotify() {
+ backingLayerHost = NativeWindowFactory.getOffscreenLayerSurface(drawable.getNativeSurface(), true);
+ if( null == backingLayerHost ) {
+ boolean[] isPBuffer = { false };
+ boolean[] isFBO = { false };
+ CGL.setContextView(contextHandle, getNSViewHandle(isPBuffer, isFBO));
+ } else {
+ nsOpenGLLayer = backingLayerHost.getAttachedSurfaceLayer();
+ }
+ }
+
+ private long getNSViewHandle(boolean[] isPBuffer, boolean[] isFBO) {
final long nsViewHandle;
- final boolean isPBuffer;
- final boolean isFBO;
if(drawable instanceof GLFBODrawableImpl) {
nsViewHandle = 0;
- isPBuffer = false;
- isFBO = true;
+ isPBuffer[0] = false;
+ isFBO[0] = true;
if(DEBUG) {
System.err.println("NS create GLFBODrawableImpl drawable: isFBO "+isFBO+", isPBuffer "+isPBuffer+", "+drawable.getClass().getName()+",\n\t"+drawable);
}
} else if(drawable instanceof MacOSXCGLDrawable) {
// we allow null here! (special pbuffer case)
nsViewHandle = ((MacOSXCGLDrawable)MacOSXCGLContext.this.drawable).getNSViewHandle();
- isPBuffer = CGL.isNSOpenGLPixelBuffer(drawable.getHandle());
- isFBO = false;
+ isPBuffer[0] = CGL.isNSOpenGLPixelBuffer(drawable.getHandle());
+ isFBO[0] = false;
if(DEBUG) {
System.err.println("NS create MacOSXCGLDrawable drawable handle isFBO "+isFBO+", isPBuffer "+isPBuffer+", "+drawable.getClass().getName()+",\n\t"+drawable);
}
@@ -514,8 +526,8 @@ public abstract class MacOSXCGLContext extends GLContextImpl
final long drawableHandle = drawable.getHandle();
final boolean isNSView = OSXUtil.isNSView(drawableHandle);
final boolean isNSWindow = OSXUtil.isNSWindow(drawableHandle);
- isPBuffer = CGL.isNSOpenGLPixelBuffer(drawableHandle);
- isFBO = false;
+ isPBuffer[0] = CGL.isNSOpenGLPixelBuffer(drawableHandle);
+ isFBO[0] = false;
if(DEBUG) {
System.err.println("NS create Anonymous drawable handle "+toHexString(drawableHandle)+": isNSView "+isNSView+", isNSWindow "+isNSWindow+", isFBO "+isFBO+", isPBuffer "+isPBuffer+", "+drawable.getClass().getName()+",\n\t"+drawable);
@@ -524,13 +536,32 @@ public abstract class MacOSXCGLContext extends GLContextImpl
nsViewHandle = drawableHandle;
} else if( isNSWindow ) {
nsViewHandle = OSXUtil.GetNSView(drawableHandle);
- } else if( isPBuffer ) {
+ } else if( isPBuffer[0] ) {
nsViewHandle = 0;
} else {
throw new RuntimeException("Anonymous drawable instance's handle neither NSView, NSWindow nor PBuffer: "+toHexString(drawableHandle)+", "+drawable.getClass().getName()+",\n\t"+drawable);
}
}
- needsSetContextPBuffer = isPBuffer;
+ needsSetContextPBuffer = isPBuffer[0];
+ return nsViewHandle;
+ }
+
+ @Override
+ public long create(long share, int ctp, int major, int minor) {
+ long ctx = 0;
+ final NativeSurface surface = drawable.getNativeSurface();
+ final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) surface.getGraphicsConfiguration();
+ final GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities();
+ final long nsViewHandle;
+ final boolean isPBuffer;
+ final boolean isFBO;
+ {
+ boolean[] _isPBuffer = { false };
+ boolean[] _isFBO = { false };
+ nsViewHandle = getNSViewHandle(_isPBuffer, _isFBO);
+ isPBuffer = _isPBuffer[0];
+ isFBO = _isFBO[0];
+ }
backingLayerHost = NativeWindowFactory.getOffscreenLayerSurface(surface, true);
boolean incompleteView = null != backingLayerHost;
@@ -661,6 +692,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl
gl3ShaderProgramName = 0;
}
nsOpenGLLayer = CGL.createNSOpenGLLayer(ctx, gl3ShaderProgramName, nsOpenGLLayerPFmt, pbufferHandle, texID, chosenCaps.isBackgroundOpaque(), lastWidth, lastHeight);
+ nsOpenGLLayerPFmt = 0; // NSOpenGLLayer will release pfmt
if (DEBUG) {
System.err.println("NS create nsOpenGLLayer "+toHexString(nsOpenGLLayer)+" w/ pbuffer "+toHexString(pbufferHandle)+", texID "+texID+", texSize "+lastWidth+"x"+lastHeight+", "+drawable);
}
@@ -688,10 +720,6 @@ public abstract class MacOSXCGLContext extends GLContextImpl
}
nsOpenGLLayer = 0;
}
- if(0 != nsOpenGLLayerPFmt) {
- CGL.deletePixelFormat(nsOpenGLLayerPFmt);
- nsOpenGLLayerPFmt = 0;
- }
}
backingLayerHost = null;
return true;
@@ -842,6 +870,11 @@ public abstract class MacOSXCGLContext extends GLContextImpl
public boolean isNSContext() { return false; }
@Override
+ public void drawableChangedNotify() {
+ // FIXME
+ }
+
+ @Override
public long create(long share, int ctp, int major, int minor) {
long ctx = 0;
MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration();
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java
index cc727c8e1..ff1772860 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java
@@ -117,7 +117,9 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl {
// OpenGL window interface
synchronized (createdContexts) {
if(bound) {
- createdContexts.add(new WeakReference<MacOSXCGLContext>((MacOSXCGLContext)ctx));
+ final MacOSXCGLContext osxCtx = (MacOSXCGLContext)ctx;
+ createdContexts.add(new WeakReference<MacOSXCGLContext>(osxCtx));
+ osxCtx.drawableChangedNotify();
} else {
for(int i=0; i<createdContexts.size(); ) {
final WeakReference<MacOSXCGLContext> ref = createdContexts.get(i);
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
index 6ebf400e2..b37930587 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface-calayer.m
@@ -448,6 +448,7 @@ static const GLfloat gl_verts[] = {
[self disableAnimation];
[self deallocPBuffer];
[[self openGLContext] release];
+ [parentPixelFmt release];
[self release];
DBG_PRINT("MyNSOpenGLLayer::releaseLayer.X: %p (refcnt %d)\n", self, (int)[self retainCount]);
pthread_mutex_unlock(&renderLock);
diff --git a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
index 48807ee29..e8925f8e8 100644
--- a/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
+++ b/src/jogl/native/macosx/MacOSXWindowSystemInterface.m
@@ -551,8 +551,7 @@ NSOpenGLContext* createContext(NSOpenGLContext* share,
NSOpenGLContext* ctx = [[NSOpenGLContext alloc] initWithFormat:fmt shareContext:share];
- if (ctx != nil) {
- if (view != nil) {
+ if ( nil != ctx && nil != view ) {
if(!opaque) {
GLint zeroOpacity = 0;
[ctx setValues:&zeroOpacity forParameter:NSOpenGLCPSurfaceOpacity];
@@ -563,7 +562,6 @@ NSOpenGLContext* createContext(NSOpenGLContext* share,
DBG_PRINT("createContext.3.X: setView\n");
[view unlockFocus];
}
- }
}
DBG_PRINT("createContext.X: ctx: %p\n", ctx);
@@ -571,6 +569,15 @@ NSOpenGLContext* createContext(NSOpenGLContext* share,
return ctx;
}
+void setContextView(NSOpenGLContext* ctx, NSView* view) {
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ if ( nil != ctx && nil != view ) {
+ [ctx setView:view];
+ }
+ [pool release];
+ return ctx;
+}
+
Bool makeCurrentContext(NSOpenGLContext* ctx) {
#if 0
// we issue the CGL Lock from Java upfront!
diff --git a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
index a62d08ccf..35c919f28 100644
--- a/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
+++ b/src/nativewindow/classes/com/jogamp/nativewindow/awt/JAWTWindow.java
@@ -239,7 +239,8 @@ public abstract class JAWTWindow implements NativeWindow, OffscreenLayerSurface,
}
protected abstract void detachSurfaceLayerImpl(final long layerHandle);
- protected final long getAttachedSurfaceLayer() {
+ @Override
+ public final long getAttachedSurfaceLayer() {
return offscreenSurfaceLayer;
}
diff --git a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
index f9800109c..f6bc5822b 100644
--- a/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
+++ b/src/nativewindow/classes/javax/media/nativewindow/OffscreenLayerSurface.java
@@ -47,6 +47,9 @@ public interface OffscreenLayerSurface {
*/
public void detachSurfaceLayer() throws NativeWindowException;
+ /** Returns the attached surface layer or null if none is attached. */
+ public long getAttachedSurfaceLayer();
+
/** Returns true if a surface layer is attached, otherwise false. */
public boolean isSurfaceLayerAttached();