diff --git a/src/java/org/lwjgl/opengl/AWTGLCanvas.java b/src/java/org/lwjgl/opengl/AWTGLCanvas.java index 1ce0d1e2..0bd542bc 100644 --- a/src/java/org/lwjgl/opengl/AWTGLCanvas.java +++ b/src/java/org/lwjgl/opengl/AWTGLCanvas.java @@ -170,16 +170,23 @@ public class AWTGLCanvas extends Canvas implements Drawable, ComponentListener, } /** - * Enable vsync + * Set swap interval. */ - public void setVSyncEnabled(boolean enabled) throws LWJGLException { + public void setSwapInterval(int swap_interval) throws LWJGLException { synchronized(SYNC_LOCK) { if (context == null) throw new IllegalStateException("Canvas not yet displayable"); - Context.setVSync(enabled); + Context.setSwapInterval(swap_interval); } } + /** + * Enable vsync + */ + public void setVSyncEnabled(boolean enabled) throws LWJGLException { + setSwapInterval(enabled ? 1 : 0); + } + /** * Swap the canvas' buffer */ diff --git a/src/java/org/lwjgl/opengl/Context.java b/src/java/org/lwjgl/opengl/Context.java index f9849180..be8824d1 100644 --- a/src/java/org/lwjgl/opengl/Context.java +++ b/src/java/org/lwjgl/opengl/Context.java @@ -209,14 +209,19 @@ final class Context { } /** - * Enable or disable vertical monitor synchronization. This call is a best-attempt at changing - * the monitor vertical refresh synchronization of the context, and is not guaranteed to be successful. + * Set the buffer swap interval. This call is a best-attempt at changing + * the monitor swap interval, which is the minimum periodicity of color buffer swaps, + * measured in video frame periods, and is not guaranteed to be successful. + * + * A video frame period is the time required to display a full frame of video data. + * * @param sync true to synchronize; false to ignore synchronization */ - public static void setVSync(boolean enable) { - implementation.setVSync(enable); + public static void setSwapInterval(int value) { + implementation.setSwapInterval(value); } + /** * Destroy the context. This method behaves the same as destroy() with the extra * requirement that the context must be either current to the current thread or not diff --git a/src/java/org/lwjgl/opengl/ContextImplementation.java b/src/java/org/lwjgl/opengl/ContextImplementation.java index a66dc281..ceb5069b 100644 --- a/src/java/org/lwjgl/opengl/ContextImplementation.java +++ b/src/java/org/lwjgl/opengl/ContextImplementation.java @@ -75,7 +75,7 @@ interface ContextImplementation { */ public boolean isCurrent(ByteBuffer handle) throws LWJGLException; - public void setVSync(boolean enable); + public void setSwapInterval(int value); /** * Destroys the Context. diff --git a/src/java/org/lwjgl/opengl/Display.java b/src/java/org/lwjgl/opengl/Display.java index 669a6ec0..52892571 100644 --- a/src/java/org/lwjgl/opengl/Display.java +++ b/src/java/org/lwjgl/opengl/Display.java @@ -91,8 +91,8 @@ public final class Display { /** Fullscreen */ private static boolean fullscreen; - /** VSync */ - private static boolean vsync; + /** Swap interval */ + private static int swap_interval; /** A unique context object, so we can track different contexts between creates() and destroys() */ private static PeerInfo peer_info; @@ -267,7 +267,7 @@ public final class Display { setTitle(title); initControls(); - setVSyncEnabled(vsync); + setSwapInterval(swap_interval); window_created = true; // set cached window icon if exists @@ -773,15 +773,29 @@ public final class Display { return context != null; } + /** + * Set the buffer swap interval. This call is a best-attempt at changing + * the monitor swap interval, which is the minimum periodicity of color buffer swaps, + * measured in video frame periods, and is not guaranteed to be successful. + * + * A video frame period is the time required to display a full frame of video data. + * + * @param sync true to synchronize; false to ignore synchronization + */ + public static void setSwapInterval(int value) { + swap_interval = value; + if (isCreated()) + Context.setSwapInterval(swap_interval); + } + + /** * Enable or disable vertical monitor synchronization. This call is a best-attempt at changing * the vertical refresh synchronization of the monitor, and is not guaranteed to be successful. * @param sync true to synchronize; false to ignore synchronization */ public static void setVSyncEnabled(boolean sync) { - vsync = sync; - if (isCreated()) - Context.setVSync(vsync); + setSwapInterval(sync ? 1 : 0); } /** diff --git a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java index 27224388..04dad774 100644 --- a/src/java/org/lwjgl/opengl/LinuxContextImplementation.java +++ b/src/java/org/lwjgl/opengl/LinuxContextImplementation.java @@ -129,17 +129,17 @@ final class LinuxContextImplementation implements ContextImplementation { } private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException; - public void setVSync(boolean enabled) { + public void setSwapInterval(int value) { Context current_context = Context.getCurrentContext(); if (current_context == null) throw new IllegalStateException("No context is current"); synchronized (current_context) { LinuxDisplay.lockAWT(); - nSetVSync(current_context.getHandle(), enabled); + nSetSwapInterval(current_context.getHandle(), value); LinuxDisplay.unlockAWT(); } } - private static native void nSetVSync(ByteBuffer context_handle, boolean enabled); + private static native void nSetSwapInterval(ByteBuffer context_handle, int value); public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException { LinuxDisplay.lockAWT(); diff --git a/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java b/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java index 201920b5..e8ed2aca 100644 --- a/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java +++ b/src/java/org/lwjgl/opengl/MacOSXContextImplementation.java @@ -110,13 +110,13 @@ final class MacOSXContextImplementation implements ContextImplementation { } private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException; - public void setVSync(boolean enabled) { + public void setSwapInterval(int value) { Context current_context = Context.getCurrentContext(); synchronized (current_context) { - nSetVSync(current_context.getHandle(), enabled); + nSetSwapInterval(current_context.getHandle(), value); } } - private static native void nSetVSync(ByteBuffer context_handle, boolean enabled); + private static native void nSetSwapInterval(ByteBuffer context_handle, int value); public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException { nDestroy(handle); diff --git a/src/java/org/lwjgl/opengl/Win32ContextImplementation.java b/src/java/org/lwjgl/opengl/Win32ContextImplementation.java index 28ba7ebb..03b193a2 100644 --- a/src/java/org/lwjgl/opengl/Win32ContextImplementation.java +++ b/src/java/org/lwjgl/opengl/Win32ContextImplementation.java @@ -92,15 +92,15 @@ final class Win32ContextImplementation implements ContextImplementation { } private static native boolean nIsCurrent(ByteBuffer context_handle) throws LWJGLException; - public void setVSync(boolean enabled) { + public void setSwapInterval(int value) { Context current_context = Context.getCurrentContext(); if (current_context == null) throw new IllegalStateException("No context is current"); synchronized (current_context) { - nSetVSync(current_context.getHandle(), enabled); + nSetSwapInterval(current_context.getHandle(), value); } } - private static native void nSetVSync(ByteBuffer context_handle, boolean enabled); + private static native void nSetSwapInterval(ByteBuffer context_handle, int value); public void destroy(PeerInfo peer_info, ByteBuffer handle) throws LWJGLException { nDestroy(handle); diff --git a/src/native/linux/org_lwjgl_opengl_LinuxContextImplementation.c b/src/native/linux/org_lwjgl_opengl_LinuxContextImplementation.c index ae04573d..c0c1d74d 100644 --- a/src/native/linux/org_lwjgl_opengl_LinuxContextImplementation.c +++ b/src/native/linux/org_lwjgl_opengl_LinuxContextImplementation.c @@ -88,13 +88,12 @@ static void createContextGLX(JNIEnv *env, X11PeerInfo *peer_info, X11Context *co context_info->context = context; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nSetVSync - (JNIEnv *env, jclass clazz, jobject context_handle, jboolean sync) +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_LinuxContextImplementation_nSetSwapInterval + (JNIEnv *env, jclass clazz, jobject context_handle, jint value) { X11Context *context_info = (*env)->GetDirectBufferAddress(env, context_handle); if (context_info->extension_flags.GLX_SGI_swap_control) { - int interval = sync == JNI_TRUE ? 1 : 0; - lwjgl_glXSwapIntervalSGI(interval); + lwjgl_glXSwapIntervalSGI(value); } } diff --git a/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m b/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m index e0735692..d4f7455d 100644 --- a/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m +++ b/src/native/macosx/org_lwjgl_opengl_MacOSXContextImplementation.m @@ -138,12 +138,12 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nIs return result ? JNI_TRUE : JNI_FALSE; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nSetVSync - (JNIEnv *env, jclass clazz, jobject context_handle, jboolean enable) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_MacOSXContextImplementation_nSetSwapInterval + (JNIEnv *env, jclass clazz, jobject context_handle, jint int_value) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; MacOSXContext *context_info = (MacOSXContext *)(*env)->GetDirectBufferAddress(env, context_handle); - long vsync_value = enable == JNI_TRUE ? 1 : 0; - [context_info->context setValues:&vsync_value forParameter:NSOpenGLCPSwapInterval]; + long value = int_value; + [context_info->context setValues:&value forParameter:NSOpenGLCPSwapInterval]; [pool release]; } diff --git a/src/native/win32/org_lwjgl_opengl_Win32ContextImplementation.c b/src/native/win32/org_lwjgl_opengl_Win32ContextImplementation.c index fa018bb8..ee5326e3 100644 --- a/src/native/win32/org_lwjgl_opengl_Win32ContextImplementation.c +++ b/src/native/win32/org_lwjgl_opengl_Win32ContextImplementation.c @@ -119,15 +119,11 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Win32ContextImplementation_nIsC return wglGetCurrentContext() == context_info->context; } -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32ContextImplementation_nSetVSync - (JNIEnv *env, jclass clazz, jobject context_handle, jboolean enable) { +JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32ContextImplementation_nSetSwapInterval + (JNIEnv *env, jclass clazz, jobject context_handle, jint value) { Win32Context *context_info = (Win32Context *)(*env)->GetDirectBufferAddress(env, context_handle); if (context_info->extensions.WGL_EXT_swap_control) { - if (enable == JNI_TRUE) { - context_info->extensions.wglSwapIntervalEXT(1); - } else { - context_info->extensions.wglSwapIntervalEXT(0); - } + context_info->extensions.wglSwapIntervalEXT(value); } }