Added setSwapInterval to Display and AWTGLCanvas
This commit is contained in:
parent
2a9b8de2fb
commit
5faf661f04
|
@ -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
|
||||
*/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue