Added setSwapInterval to Display and AWTGLCanvas

This commit is contained in:
Elias Naur 2006-01-01 19:50:06 +00:00
parent 2a9b8de2fb
commit 5faf661f04
10 changed files with 59 additions and 38 deletions

View file

@ -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
*/

View file

@ -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

View file

@ -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.

View file

@ -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);
}
/**

View file

@ -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();

View file

@ -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);

View file

@ -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);