diff options
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/macosx')
6 files changed, 182 insertions, 22 deletions
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index 1fe47f60b..2efdf958d 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -46,16 +46,19 @@ import java.util.Map; import javax.media.nativewindow.AbstractGraphicsConfiguration; import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.DefaultGraphicsConfiguration; +import javax.media.nativewindow.NativeSurface; import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLContext; import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; +import jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow; import jogamp.opengl.GLContextImpl; import jogamp.opengl.GLContextShareSet; import jogamp.opengl.GLDrawableImpl; import jogamp.opengl.GLGraphicsConfigurationUtil; import jogamp.opengl.macosx.cgl.MacOSXCGLDrawable.GLBackendType; +import jogamp.opengl.macosx.cgl.MacOSXCGLDrawable.LayeredSurfaceType; import com.jogamp.common.nio.PointerBuffer; import com.jogamp.common.os.Platform; @@ -403,31 +406,53 @@ public abstract class MacOSXCGLContext extends GLContextImpl // NSOpenGLContext-based implementation class NSOpenGLImpl implements GLBackendImpl { + long nsOpenGLLayer = 0; + long nsOpenGLLayerPFmt = 0; + public boolean isNSContext() { return true; } public long create(long share, int ctp, int major, int minor) { long ctx = 0; - MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration(); - GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + final MacOSXCGLDrawable drawable = (MacOSXCGLDrawable) MacOSXCGLContext.this.drawable; + final NativeSurface surface = drawable.getNativeSurface(); + final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) surface.getGraphicsConfiguration().getNativeGraphicsConfiguration(); + final boolean isBackingLayerView = LayeredSurfaceType.None != drawable.getLayeredSurfaceType(); + /** + final GLCapabilitiesImmutable chosenCaps; + { + final GLCapabilitiesImmutable _chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + if(isBackingLayerView) { + chosenCaps = GLGraphicsConfigurationUtil.fixSingleBufferGLCapabilities(_chosenCaps); + } else { + chosenCaps = _chosenCaps; + } + } */ + final GLCapabilitiesImmutable chosenCaps = (GLCapabilitiesImmutable) config.getChosenCapabilities(); long pixelFormat = MacOSXCGLGraphicsConfiguration.GLCapabilities2NSPixelFormat(chosenCaps, ctp, major, minor); if (pixelFormat == 0) { throw new GLException("Unable to allocate pixel format with requested GLCapabilities"); } config.setChosenPixelFormat(pixelFormat); + if(DEBUG) { + System.err.println("NS create OSX>=lion "+isLionOrLater); + System.err.println("NS create drawable layeredType: "+drawable.getLayeredSurfaceType()+", backingLayerView "+isBackingLayerView); + System.err.println("NS create share: "+share); + System.err.println("NS create chosenCaps: "+chosenCaps); + System.err.println("NS create pixelFormat: "+toHexString(pixelFormat)); + System.err.println("NS create drawable native-handle: "+toHexString(drawable.getHandle())); + System.err.println("NS create drawable NSView-handle: "+toHexString(drawable.getNSViewHandle())); + } try { int[] viewNotReady = new int[1]; // Try to allocate a context with this ctx = CGL.createContext(share, - drawable.getHandle(), + drawable.getNSViewHandle(), isBackingLayerView, pixelFormat, chosenCaps.isBackgroundOpaque(), viewNotReady, 0); if (0 == ctx) { - if (viewNotReady[0] == 1) { - if (DEBUG) { - System.err.println("!!! View not ready for " + getClass().getName()); - } - // View not ready at the window system level + if(DEBUG) { + System.err.println("NS create failed: viewNotReady: "+ (1 == viewNotReady[0])); } return 0; } @@ -439,22 +464,52 @@ public abstract class MacOSXCGLContext extends GLContextImpl if(DEBUG) { GLCapabilitiesImmutable caps0 = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(null, pixelFormat); - System.err.println("NS created(>=lion "+isLionOrLater+"): "+caps0); + System.err.println("NS create pixelformat2GLCaps: "+caps0); + } + GLCapabilitiesImmutable fixedCaps = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(chosenCaps.getGLProfile(), pixelFormat); + fixedCaps = GLGraphicsConfigurationUtil.fixOpaqueGLCapabilities(fixedCaps, chosenCaps.isBackgroundOpaque()); + config.setChosenCapabilities(fixedCaps); + if(DEBUG) { + System.err.println("NS create fixedCaps: "+fixedCaps); } - GLCapabilitiesImmutable caps = MacOSXCGLGraphicsConfiguration.NSPixelFormat2GLCapabilities(chosenCaps.getGLProfile(), pixelFormat); - caps = GLGraphicsConfigurationUtil.fixOpaqueGLCapabilities(caps, chosenCaps.isBackgroundOpaque()); - config.setChosenCapabilities(caps); - if(caps.isPBuffer()) { + if(fixedCaps.isPBuffer()) { // Must now associate the pbuffer with our newly-created context CGL.setContextPBuffer(ctx, drawable.getHandle()); - } + } + // + // handled layered surface (same path for direct and parented) + // + if(isBackingLayerView) { + final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(surface); + nsOpenGLLayerPFmt = pixelFormat; + pixelFormat = 0; + nsOpenGLLayer = CGL.createNSOpenGLLayer(ctx, nsOpenGLLayerPFmt, drawable.getNSViewHandle(), fixedCaps.isBackgroundOpaque()); + if (DEBUG) { + System.err.println("NS create nsOpenGLLayer "+toHexString(nsOpenGLLayer)); + } + lsh.attachSurfaceLayer(nsOpenGLLayer); + } } finally { - CGL.deletePixelFormat(pixelFormat); + if(0!=pixelFormat) { + CGL.deletePixelFormat(pixelFormat); + } } return ctx; } public boolean destroy(long ctx) { + if(0 != nsOpenGLLayer) { + final NativeSurface surface = drawable.getNativeSurface(); + final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(surface); + if (DEBUG) { + System.err.println("NS destroy nsOpenGLLayer "+toHexString(nsOpenGLLayer)); + } + lsh.attachSurfaceLayer(0); + CGL.releaseNSOpenGLLayer(nsOpenGLLayer); + CGL.deletePixelFormat(nsOpenGLLayerPFmt); + nsOpenGLLayerPFmt = 0; + nsOpenGLLayer = 0; + } return CGL.deleteContext(ctx, true); } @@ -476,10 +531,22 @@ public abstract class MacOSXCGLContext extends GLContextImpl return true; } public boolean swapBuffers(boolean isOnscreen) { - if(isOnscreen) { - return CGL.flushBuffer(contextHandle); - } - return true; + /* + boolean res = true; + if(isOnscreen) { + res = CGL.flushBuffer(contextHandle); + } + if(res && 0 != nsOpenGLLayer) { + CGL.setNSOpenGLLayerNeedsDisplay(nsOpenGLLayer); + } + return res; */ + + if(0 != nsOpenGLLayer) { + CGL.setNSOpenGLLayerNeedsDisplay(nsOpenGLLayer); + } else if(isOnscreen) { + return CGL.flushBuffer(contextHandle); + } + return true; } } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java index 5a35f661d..6ac0af6e8 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java @@ -44,6 +44,8 @@ import javax.media.nativewindow.NativeSurface; import javax.media.opengl.GLDrawableFactory; import javax.media.opengl.GLException; +import jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow; +import jogamp.nativewindow.macosx.OSXUtil; import jogamp.opengl.GLDrawableImpl; import jogamp.opengl.GLDynamicLookupHelper; @@ -87,18 +89,80 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl { this.id = id; } } + public enum LayeredSurfaceType { + None(0), Direct(1), Parented(2); + + public final int id; + + LayeredSurfaceType(int id){ + this.id = id; + } + } private boolean haveSetOpenGLMode = false; private GLBackendType openGLMode = GLBackendType.NSOPENGL; + protected LayeredSurfaceType layeredSurfaceType = LayeredSurfaceType.None; public MacOSXCGLDrawable(GLDrawableFactory factory, NativeSurface comp, boolean realized) { super(factory, comp, realized); initOpenGLImpl(getOpenGLMode()); - } + } + + public final LayeredSurfaceType getLayeredSurfaceType() { return layeredSurfaceType; } protected void setRealizedImpl() { } + protected long getNSViewHandle() { + return GLBackendType.NSOPENGL == openGLMode ? getHandle() : null; + } + + @Override + protected void destroyHandle() { + if(layeredSurfaceType == LayeredSurfaceType.Direct) { + // direct surface host, eg. AWT GLCanvas + final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(surface); + if (DEBUG) { + System.err.println("destroyHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(lsh.getSurfaceHandle()) + " -> 0"); + } + OSXUtil.DestroyNSView(lsh.getSurfaceHandle()); + lsh.setSurfaceHandle(0); + } else if (DEBUG) { + System.err.println("destroyHandle: layerType " + layeredSurfaceType); + } + } + + @Override + protected void updateHandle() { + final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(surface); + if (null != lsh) { + if(lsh == surface) { + // direct surface host, eg. AWT GLCanvas + layeredSurfaceType = LayeredSurfaceType.Direct; + final long oldNSBackingView = lsh.getSurfaceHandle(); + if(0 != oldNSBackingView) { + OSXUtil.DestroyNSView(oldNSBackingView); + } + final long newNSBackingView = OSXUtil.CreateNSView(0, 0, getWidth(), getHeight()); + lsh.setSurfaceHandle(newNSBackingView); + if (DEBUG) { + System.err.println("updateHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(newNSBackingView) + " -> "+toHexString(oldNSBackingView)); + } + } else { + // parent surface host, eg. via native parenting w/ NewtCanvasAWT + layeredSurfaceType = LayeredSurfaceType.Parented; + if (DEBUG) { + System.err.println("updateHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(getHandle())); + } + } + } else { + layeredSurfaceType = LayeredSurfaceType.None; + if (DEBUG) { + System.err.println("updateHandle: layerType " + layeredSurfaceType); + } + } + } + public GLDynamicLookupHelper getGLDynamicLookupHelper() { return getFactoryImpl().getGLDynamicLookupHelper(0); } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java index 5c726bc54..14af0a544 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java @@ -49,6 +49,7 @@ import javax.media.nativewindow.AbstractGraphicsDevice; import javax.media.nativewindow.AbstractGraphicsScreen; import javax.media.nativewindow.DefaultGraphicsScreen; import javax.media.nativewindow.NativeSurface; +import javax.media.nativewindow.NativeWindow; import javax.media.nativewindow.NativeWindowFactory; import javax.media.nativewindow.ProxySurface; import javax.media.nativewindow.macosx.MacOSXGraphicsDevice; @@ -61,6 +62,7 @@ import javax.media.opengl.GLException; import javax.media.opengl.GLProfile; import jogamp.nativewindow.WrappedSurface; +import jogamp.nativewindow.jawt.macosx.MacOSXJAWTWindow; import jogamp.opengl.DesktopGLDynamicLookupHelper; import jogamp.opengl.GLDrawableFactoryImpl; import jogamp.opengl.GLDrawableImpl; @@ -219,6 +221,25 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl { return MacOSXCGLGraphicsConfiguration.getAvailableCapabilities(this, device); } + protected static MacOSXJAWTWindow getLayeredSurfaceHost(NativeSurface surface) { + if(surface instanceof NativeWindow) { + final NativeWindow nwThis = (NativeWindow) surface; + if( nwThis instanceof MacOSXJAWTWindow) { + // direct surface host, eg. via AWT GLCanvas + final MacOSXJAWTWindow r = (MacOSXJAWTWindow) nwThis; + return r.isLayeredSurface() ? r : null; + } else { + // parent surface host, eg. via native parenting w/ NewtCanvasAWT + final NativeWindow nwParent = nwThis.getParent(); + if(null != nwParent && nwParent instanceof MacOSXJAWTWindow) { + final MacOSXJAWTWindow r = (MacOSXJAWTWindow) nwParent; + return r.isLayeredSurface() ? r : null; + } + } + } + return null; + } + protected GLDrawableImpl createOnscreenDrawableImpl(NativeSurface target) { if (target == null) { throw new IllegalArgumentException("Null target"); diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java index a429720db..865238f06 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java @@ -222,7 +222,7 @@ public class MacOSXCGLGraphicsConfiguration extends DefaultGraphicsConfiguration // Use attribute array to select pixel format PointerBuffer fmt = PointerBuffer.allocateDirect(1); - long[] numScreens = new long[1]; + int[] numScreens = new int[1]; int res = CGL.CGLChoosePixelFormat(attrs, 0, fmt, numScreens, 0); if (res != CGL.kCGLNoError) { throw new GLException("Error code " + res + " while choosing pixel format"); diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java index 24276c39e..2e1c24d91 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXOnscreenCGLDrawable.java @@ -49,9 +49,10 @@ import javax.media.nativewindow.NativeSurface; import javax.media.opengl.GLContext; import javax.media.opengl.GLDrawableFactory; + public class MacOSXOnscreenCGLDrawable extends MacOSXCGLDrawable { private List<WeakReference<MacOSXCGLContext>> createdContexts = new ArrayList<WeakReference<MacOSXCGLContext>>(); - + protected MacOSXOnscreenCGLDrawable(GLDrawableFactory factory, NativeSurface component) { super(factory, component, false); } diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java index fdbfaf6d6..ac76cfe6c 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java @@ -112,6 +112,13 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable { } } + @Override + protected long getNSViewHandle() { + // pbuffer handle is NSOpenGLPixelBuffer + return 0; + } + + @Override public long getHandle() { return pBuffer; } |