summaryrefslogtreecommitdiffstats
path: root/src/jogl/classes/jogamp/opengl/macosx
diff options
context:
space:
mode:
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/macosx')
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java56
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java79
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java8
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java13
-rw-r--r--src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java11
5 files changed, 115 insertions, 52 deletions
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
index 2efdf958d..b942fb904 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java
@@ -47,6 +47,7 @@ import javax.media.nativewindow.AbstractGraphicsConfiguration;
import javax.media.nativewindow.AbstractGraphicsDevice;
import javax.media.nativewindow.DefaultGraphicsConfiguration;
import javax.media.nativewindow.NativeSurface;
+import javax.media.nativewindow.SurfaceUpdatedListener;
import javax.media.opengl.GLCapabilitiesImmutable;
import javax.media.opengl.GLContext;
import javax.media.opengl.GLException;
@@ -79,7 +80,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl
boolean makeCurrent(long ctx);
boolean release(long ctx);
boolean setSwapInterval(int interval);
- boolean swapBuffers(boolean isOnscreen);
+ boolean swapBuffers();
}
/* package */ static final boolean isTigerOrLater;
@@ -271,9 +272,8 @@ public abstract class MacOSXCGLContext extends GLContextImpl
}
protected void swapBuffers() {
- DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) drawable.getNativeSurface().getGraphicsConfiguration().getNativeGraphicsConfiguration();
- GLCapabilitiesImmutable caps = (GLCapabilitiesImmutable)config.getChosenCapabilities();
- if(!impl.swapBuffers(caps.isOnscreen())) {
+ // single-buffer is already filtered out @ GLDrawableImpl#swapBuffers()
+ if(!impl.swapBuffers()) {
throw new GLException("Error swapping buffers: "+this);
}
}
@@ -417,16 +417,6 @@ public abstract class MacOSXCGLContext extends GLContextImpl
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) {
@@ -483,11 +473,21 @@ public abstract class MacOSXCGLContext extends GLContextImpl
final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(surface);
nsOpenGLLayerPFmt = pixelFormat;
pixelFormat = 0;
- nsOpenGLLayer = CGL.createNSOpenGLLayer(ctx, nsOpenGLLayerPFmt, drawable.getNSViewHandle(), fixedCaps.isBackgroundOpaque());
+ // final long nsView = drawable.getNSViewHandle();
+ // nsOpenGLLayer = CGL.createNSOpenGLLayer(ctx, nsOpenGLLayerPFmt, nsView, fixedCaps.isBackgroundOpaque());
+ nsOpenGLLayer = CGL.createNSOpenGLLayer(ctx, nsOpenGLLayerPFmt, drawable.getHandle(), fixedCaps.isBackgroundOpaque(),
+ drawable.getWidth(), drawable.getHeight());
if (DEBUG) {
System.err.println("NS create nsOpenGLLayer "+toHexString(nsOpenGLLayer));
}
lsh.attachSurfaceLayer(nsOpenGLLayer);
+ lsh.addSurfaceUpdatedListener(new SurfaceUpdatedListener() {
+ public void surfaceUpdated(Object updater, NativeSurface ns, long when) {
+ if(0 != nsOpenGLLayer) {
+ CGL.setNSOpenGLLayerNeedsDisplay(nsOpenGLLayer);
+ }
+ }
+ });
}
} finally {
if(0!=pixelFormat) {
@@ -530,23 +530,8 @@ public abstract class MacOSXCGLContext extends GLContextImpl
CGL.setSwapInterval(contextHandle, interval);
return true;
}
- public boolean swapBuffers(boolean isOnscreen) {
- /*
- 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;
+ public boolean swapBuffers() {
+ return CGL.flushBuffer(contextHandle);
}
}
@@ -614,11 +599,8 @@ public abstract class MacOSXCGLContext extends GLContextImpl
CGL.CGLSetParameter(contextHandle, CGL.kCGLCPSwapInterval, lval, 0);
return true;
}
- public boolean swapBuffers(boolean isOnscreen) {
- if(isOnscreen) {
- return CGL.kCGLNoError == CGL.CGLFlushDrawable(contextHandle);
- }
- return true;
+ public boolean swapBuffers() {
+ return CGL.kCGLNoError == CGL.CGLFlushDrawable(contextHandle);
}
}
}
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java
index 6ac0af6e8..a97f3b1b2 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawable.java
@@ -40,12 +40,16 @@
package jogamp.opengl.macosx.cgl;
+import java.lang.ref.WeakReference;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
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;
@@ -99,13 +103,15 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl {
}
}
+ private List<WeakReference<MacOSXCGLContext>> createdContexts = new ArrayList<WeakReference<MacOSXCGLContext>>();
+
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());
+ initOpenGLImpl(getOpenGLMode());
}
public final LayeredSurfaceType getLayeredSurfaceType() { return layeredSurfaceType; }
@@ -117,6 +123,7 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl {
return GLBackendType.NSOPENGL == openGLMode ? getHandle() : null;
}
+ /**
@Override
protected void destroyHandle() {
if(layeredSurfaceType == LayeredSurfaceType.Direct) {
@@ -126,10 +133,12 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl {
System.err.println("destroyHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(lsh.getSurfaceHandle()) + " -> 0");
}
OSXUtil.DestroyNSView(lsh.getSurfaceHandle());
+ // CGL.releaseNSOpenGLView(lsh.getSurfaceHandle());
lsh.setSurfaceHandle(0);
} else if (DEBUG) {
System.err.println("destroyHandle: layerType " + layeredSurfaceType);
}
+ super.destroyHandle();
}
@Override
@@ -139,14 +148,16 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl {
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 oldNSView = lsh.getSurfaceHandle();
+ if(0 != oldNSView) {
+ OSXUtil.DestroyNSView(oldNSView);
+ // CGL.releaseNSOpenGLView(oldNSView);
}
- final long newNSBackingView = OSXUtil.CreateNSView(0, 0, getWidth(), getHeight());
- lsh.setSurfaceHandle(newNSBackingView);
+ final long nsView = OSXUtil.CreateNSView(0, 0, getWidth(), getHeight());
+ // final long nsView = CGL.createNSOpenGLView(0, 0, getWidth(), getHeight());
+ lsh.setSurfaceHandle(nsView);
if (DEBUG) {
- System.err.println("updateHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(newNSBackingView) + " -> "+toHexString(oldNSBackingView));
+ System.err.println("updateHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(oldNSView) + " -> "+toHexString(nsView));
}
} else {
// parent surface host, eg. via native parenting w/ NewtCanvasAWT
@@ -161,8 +172,58 @@ public abstract class MacOSXCGLDrawable extends GLDrawableImpl {
System.err.println("updateHandle: layerType " + layeredSurfaceType);
}
}
- }
+ super.updateHandle();
+ } */
+ @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;
+ if (DEBUG) {
+ System.err.println("updateHandle: layerType " + layeredSurfaceType + ", backingLayer "+toHexString(lsh.getSurfaceHandle()));
+ }
+ } 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);
+ }
+ }
+ super.updateHandle();
+ }
+
+ protected void registerContext(MacOSXCGLContext ctx) {
+ // NOTE: we need to keep track of the created contexts in order to
+ // implement swapBuffers() because of how Mac OS X implements its
+ // OpenGL window interface
+ synchronized (createdContexts) {
+ createdContexts.add(new WeakReference<MacOSXCGLContext>(ctx));
+ }
+ }
+ protected final void swapBuffersImpl() {
+ // single-buffer is already filtered out @ GLDrawableImpl#swapBuffers()
+ synchronized (createdContexts) {
+ for (Iterator<WeakReference<MacOSXCGLContext>> iter = createdContexts.iterator(); iter.hasNext(); ) {
+ WeakReference<MacOSXCGLContext> ref = iter.next();
+ MacOSXCGLContext ctx = ref.get();
+ if (ctx != null) {
+ ctx.swapBuffers();
+ } else {
+ iter.remove();
+ }
+ }
+ }
+ }
+
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 cbdff144f..18401a025 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLDrawableFactory.java
@@ -248,8 +248,12 @@ public class MacOSXCGLDrawableFactory extends GLDrawableFactoryImpl {
final MacOSXJAWTWindow lsh = MacOSXCGLDrawableFactory.getLayeredSurfaceHost(target);
if(null != lsh) {
// layered surface -> PBuffer
- final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) target.getGraphicsConfiguration().getNativeGraphicsConfiguration();
- final GLCapabilitiesImmutable chosenCaps = GLGraphicsConfigurationUtil.fixGLPBufferGLCapabilities((GLCapabilitiesImmutable) config.getChosenCapabilities());
+ final MacOSXCGLGraphicsConfiguration config = (MacOSXCGLGraphicsConfiguration) target.getGraphicsConfiguration().getNativeGraphicsConfiguration();
+ final GLCapabilities chosenCaps = (GLCapabilities) config.getChosenCapabilities().cloneMutable();
+ // chosenCaps.setDoubleBuffered(false); // FIXME DBLBUFOFFSCRN
+ chosenCaps.setOnscreen(false);
+ chosenCaps.setPBuffer(true);
+ // chosenCaps.setPbufferRenderToTextureRectangle(true);
config.setChosenCapabilities(chosenCaps);
return new MacOSXPbufferCGLDrawable(this, target, false);
}
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java
index 865238f06..741bb19c5 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLGraphicsConfiguration.java
@@ -83,6 +83,8 @@ public class MacOSXCGLGraphicsConfiguration extends DefaultGraphicsConfiguration
static final int[] cglInternalAttributeToken = new int[] {
CGL.kCGLPFAOpenGLProfile,
CGL.kCGLPFAColorFloat,
+ CGL.NSOpenGLPFANoRecovery,
+ CGL.NSOpenGLPFAAccelerated,
CGL.NSOpenGLPFAPixelBuffer,
CGL.NSOpenGLPFADoubleBuffer,
CGL.NSOpenGLPFAStereo,
@@ -114,6 +116,13 @@ public class MacOSXCGLGraphicsConfiguration extends DefaultGraphicsConfiguration
ivalues[idx] = caps.getPbufferFloatingPointBuffers() ? 1 : 0;
break;
+ case CGL.NSOpenGLPFANoRecovery:
+ ivalues[idx] = caps.getHardwareAccelerated() ? 1 : 0; // FIXME: Jau ??
+ break;
+ case CGL.NSOpenGLPFAAccelerated:
+ ivalues[idx] = caps.getHardwareAccelerated() ? 1 : 0; // FIXME: Jau ??
+ break;
+
case CGL.NSOpenGLPFAPixelBuffer:
ivalues[idx] = caps.isPBuffer() ? 1 : 0;
break;
@@ -285,6 +294,10 @@ public class MacOSXCGLGraphicsConfiguration extends DefaultGraphicsConfiguration
caps.setPbufferFloatingPointBuffers(ivalues[i] != 0);
break;
+ case CGL.NSOpenGLPFAAccelerated:
+ caps.setHardwareAccelerated(ivalues[i] != 0);
+ break;
+
case CGL.NSOpenGLPFAPixelBuffer:
caps.setPBuffer(ivalues[i] != 0);
break;
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java
index 525134f1e..5f511c505 100644
--- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java
+++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXPbufferCGLDrawable.java
@@ -136,13 +136,16 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable {
DefaultGraphicsConfiguration config = (DefaultGraphicsConfiguration) ns.getGraphicsConfiguration().getNativeGraphicsConfiguration();
GLCapabilitiesImmutable capabilities = (GLCapabilitiesImmutable)config.getChosenCapabilities();
GLProfile glProfile = capabilities.getGLProfile();
+ final int w, h;
int renderTarget;
if (glProfile.isGL2GL3() && capabilities.getPbufferRenderToTextureRectangle()) {
+ w = getWidth();
+ h = getHeight();
renderTarget = GL2.GL_TEXTURE_RECTANGLE;
} else {
- int w = getNextPowerOf2(getWidth());
- int h = getNextPowerOf2(getHeight());
- ((SurfaceChangeable)ns).setSize(w, h);
+ w = getNextPowerOf2(getWidth());
+ h = getNextPowerOf2(getHeight());
+ // FIXME - JAU: ((SurfaceChangeable)ns).setSize(w, h); // can't do that, removed orig size
renderTarget = GL.GL_TEXTURE_2D;
}
@@ -168,7 +171,7 @@ public class MacOSXPbufferCGLDrawable extends MacOSXCGLDrawable {
}
}
- pBuffer = impl.create(renderTarget, internalFormat, getWidth(), getHeight());
+ pBuffer = impl.create(renderTarget, internalFormat, w, h);
if (pBuffer == 0) {
throw new GLException("pbuffer creation error: CGL.createPBuffer() failed");
}