diff options
author | Sven Gothel <[email protected]> | 2012-04-22 05:12:16 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2012-04-22 05:12:16 +0200 |
commit | 9d522e77a9ac1f85c57236f00d5432e671f9169c (patch) | |
tree | 79c86efc114560393c6e870f55365c2726307130 /src/jogl/classes/jogamp/opengl/macosx | |
parent | 218d67fc0222d7709b21c45792d44501351939c4 (diff) |
Completing swap-interval implementation for OSX's CALayer usage. Closing Bug 555
- Based on Andres Colubri's initiative and commit 218d67fc0222d7709b21c45792d44501351939c4.
- Reading real screen refresh rate ('stolen' from NEWT)
- Properly handling swap-interval and vsync-to in native code
- Increasing accuracy vsync-to to microseconds
Tested manually w/ TestGearsES2AWT.
Diffstat (limited to 'src/jogl/classes/jogamp/opengl/macosx')
-rw-r--r-- | src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java index 7d7dae950..3cd4b340c 100644 --- a/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java +++ b/src/jogl/classes/jogamp/opengl/macosx/cgl/MacOSXCGLContext.java @@ -396,11 +396,12 @@ public abstract class MacOSXCGLContext extends GLContextImpl class NSOpenGLImpl implements GLBackendImpl { long nsOpenGLLayer = 0; long nsOpenGLLayerPFmt = 0; - int vsyncTimeout = 16; + float screenVSyncTimeout; // microSec + int vsyncTimeout; // microSec - for nsOpenGLLayer mode public boolean isNSContext() { return true; } - public long create(long share, int ctp, int major, int minor) { + public long create(long share, int ctp, int major, int minor) { long ctx = 0; final MacOSXCGLDrawable drawable = (MacOSXCGLDrawable) MacOSXCGLContext.this.drawable; final NativeSurface surface = drawable.getNativeSurface(); @@ -415,6 +416,8 @@ public abstract class MacOSXCGLContext extends GLContextImpl return 0; } config.setChosenPixelFormat(pixelFormat); + int sRefreshRate = CGL.getScreenRefreshRate(drawable.getNativeSurface().getGraphicsConfiguration().getScreen().getIndex()); + screenVSyncTimeout = 1000000f / (float)sRefreshRate; if(DEBUG) { System.err.println("NS create OSX>=lion "+isLionOrLater); System.err.println("NS create backendType: "+drawable.getOpenGLMode()); @@ -424,6 +427,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl 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())); + System.err.println("NS create screen refresh-rate: "+sRefreshRate+" hz, "+screenVSyncTimeout+" micros"); // Thread.dumpStack(); } try { @@ -483,6 +487,7 @@ public abstract class MacOSXCGLContext extends GLContextImpl System.err.println("NS create nsOpenGLLayer "+toHexString(nsOpenGLLayer)+", texSize "+texWidth+"x"+texHeight+", "+drawable); } backingLayerHost.attachSurfaceLayer(nsOpenGLLayer); + setSwapInterval(1); // enabled per default in layered surface } } finally { if(0!=pixelFormat) { @@ -554,23 +559,17 @@ public abstract class MacOSXCGLContext extends GLContextImpl public boolean setSwapInterval(int interval) { if(0 != nsOpenGLLayer) { CGL.setNSOpenGLLayerSwapInterval(nsOpenGLLayer, interval); + vsyncTimeout = interval * (int)screenVSyncTimeout; + if(DEBUG) { System.err.println("NS setSwapInterval: "+vsyncTimeout+" micros"); } } CGL.setSwapInterval(contextHandle, interval); - if (interval == 0) { - // v-sync is disabled, frames were drawn as quickly as possible without adding any - // timeout delay. - vsyncTimeout = 0; - } else { - // v-sync is enabled. Swaping interval of 1 means a - // timeout of 16ms -> 60Hz, 60fps - vsyncTimeout = interval * 16; - } return true; } public boolean swapBuffers() { - if(0 != nsOpenGLLayer && 0 < vsyncTimeout) { - // sync w/ CALayer renderer - wait until next frame is required (v-sync) + if( 0 != nsOpenGLLayer ) { + // If v-sync is disabled, frames will be drawn as quickly as possible + // w/o delay but in sync w/ CALayer. Otherwise wait until next swap interval (v-sync). CGL.waitUntilNSOpenGLLayerIsReady(nsOpenGLLayer, vsyncTimeout); } if(CGL.flushBuffer(contextHandle)) { |