New vsync code
This commit is contained in:
parent
b6390ef976
commit
2714842095
|
@ -1407,24 +1407,6 @@ public abstract class GL extends CoreGL14 implements GLConstants {
|
|||
|
||||
// public static native int wglGetPbufferDCARB(int hPbuffer);
|
||||
|
||||
/* public static native boolean wglGetPixelFormatAttribfvARB(
|
||||
int hdc,
|
||||
int iPixelFormat,
|
||||
int iLayerPlane,
|
||||
int nAttributes,
|
||||
int piAttributes,
|
||||
int pfValues);
|
||||
|
||||
public static native boolean wglGetPixelFormatAttribivARB(
|
||||
int hdc,
|
||||
int iPixelFormat,
|
||||
int iLayerPlane,
|
||||
int nAttributes,
|
||||
int piAttributes,
|
||||
int piValues);
|
||||
*/
|
||||
public static native int wglGetSwapIntervalEXT();
|
||||
|
||||
/* public static native boolean wglMakeContextCurrentARB(
|
||||
int hDrawDC,
|
||||
int hReadDC,
|
||||
|
@ -1441,29 +1423,7 @@ public abstract class GL extends CoreGL14 implements GLConstants {
|
|||
int hPbuffer,
|
||||
int iBuffer);
|
||||
|
||||
/* public static native boolean wglRestoreBufferRegionARB(
|
||||
Buffer hRegion,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height,
|
||||
int xSrc,
|
||||
int ySrc);
|
||||
|
||||
public static native boolean wglSaveBufferRegionARB(
|
||||
Buffer hRegion,
|
||||
int x,
|
||||
int y,
|
||||
int width,
|
||||
int height);
|
||||
*/
|
||||
/* public static native boolean wglSetPbufferAttribARB(
|
||||
int hPbuffer,
|
||||
int piAttribList);
|
||||
*/
|
||||
public static native boolean wglSwapIntervalEXT(int interval);
|
||||
|
||||
public static native void glWindowPos2fARB(float x, float y);
|
||||
public static native void glWindowPos2fARB(float x, float y);
|
||||
|
||||
public static native void glWindowPos2iARB(int x, int y);
|
||||
|
||||
|
|
|
@ -25,7 +25,6 @@ import org.lwjgl.Display;
|
|||
import org.lwjgl.Sys;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class Window {
|
||||
|
||||
|
@ -54,8 +53,9 @@ public final class Window {
|
|||
* I have posted a bug report to apple regarding the behaviour.
|
||||
*
|
||||
*/
|
||||
if (Display.getPlatform() == Display.PLATFORM_AGL)
|
||||
if (Display.getPlatform() == Display.PLATFORM_AGL) {
|
||||
MacOSX.initMacOSX();
|
||||
}
|
||||
}
|
||||
|
||||
/** Whether the window is currently created, ie. has a native peer */
|
||||
|
@ -93,6 +93,9 @@ public final class Window {
|
|||
|
||||
/** Fullscreen */
|
||||
private static boolean fullscreen;
|
||||
|
||||
/** Vsync */
|
||||
private static boolean vsync;
|
||||
|
||||
/** Tracks VBO state for the window context */
|
||||
private static VBOTracker vbo_tracker;
|
||||
|
@ -364,4 +367,35 @@ public final class Window {
|
|||
* to handle window close requests, moves, paints, etc.
|
||||
*/
|
||||
public static native void update();
|
||||
|
||||
/**
|
||||
* Determines to the best of the platform's ability whether monitor vysnc is enabled on
|
||||
* this window. The failsafe assumption is that when vsync cannot be determined, this
|
||||
* method returns false, and you should rely on using a hires timer to throttle your
|
||||
* framerate rather than relying on monitor sync (even if monitor sync is actually working).
|
||||
* Therefore you can guarantee that if we return true from this method that we're pretty
|
||||
* certain vsync is enabled.
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isVSyncEnabled() {
|
||||
assert isCreated() : "Cannot determine sync of uncreated window";
|
||||
return nIsVSyncEnabled();
|
||||
}
|
||||
|
||||
private static native boolean nIsVSyncEnabled();
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* To check whether the call <em>might</em> have been successful, call isVSyncEnabled().
|
||||
* @param sync true to synchronize; false to ignore synchronization
|
||||
*/
|
||||
public static void setVSyncEnabled(boolean sync) {
|
||||
assert isCreated() : "Cannot set sync of uncreated window";
|
||||
nSetVSyncEnabled(sync);
|
||||
}
|
||||
|
||||
private static native boolean nSetVSyncEnabled(boolean sync);
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -338,9 +338,7 @@ public class HWCursorTest {
|
|||
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
//sync frame (only works on windows)
|
||||
if (GLCaps.WGL_EXT_swap_control) {
|
||||
GL.wglSwapIntervalEXT(1);
|
||||
}
|
||||
Window.setVSyncEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -315,9 +315,7 @@ public class FullScreenWindowedTest {
|
|||
GL.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
|
||||
|
||||
//sync frame (only works on windows)
|
||||
if (GLCaps.WGL_EXT_swap_control) {
|
||||
GL.wglSwapIntervalEXT(1);
|
||||
}
|
||||
Window.setVSyncEnabled(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -386,9 +386,8 @@ public class PbufferTest {
|
|||
*/
|
||||
private void glInit() {
|
||||
//sync frame (only works on windows)
|
||||
if (GLCaps.WGL_EXT_swap_control) {
|
||||
GL.wglSwapIntervalEXT(1);
|
||||
}
|
||||
Window.setVSyncEnabled(true);
|
||||
|
||||
GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
|
||||
GL.glEnable(GL.GL_TEXTURE_2D);
|
||||
// Create shared texture
|
||||
|
|
|
@ -3373,7 +3373,6 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_GL_wglGetExtensionsStringEXT(JNI
|
|||
/*
|
||||
* Class: org_lwjgl_opengl_GL
|
||||
* Method: wglGetSwapIntervalEXT
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GL_wglGetSwapIntervalEXT(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
@ -3385,6 +3384,7 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GL_wglGetSwapIntervalEXT(JNIEnv * e
|
|||
return JNI_FALSE;
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_GL
|
||||
|
@ -3504,7 +3504,6 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_GL_wglReleaseTexImageARB(JNIEnv
|
|||
/*
|
||||
* Class: org_lwjgl_opengl_GL
|
||||
* Method: wglSwapIntervalEXT
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_GL_wglSwapIntervalEXT(JNIEnv * env, jclass clazz, jint p0)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
|
@ -3516,6 +3515,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_GL_wglSwapIntervalEXT(JNIEnv *
|
|||
return JNI_FALSE;
|
||||
#endif
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_GL
|
||||
|
|
|
@ -2215,14 +2215,6 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_GL_wglGetExtensionsStringARB
|
|||
JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_GL_wglGetExtensionsStringEXT
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_GL
|
||||
* Method: wglGetSwapIntervalEXT
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GL_wglGetSwapIntervalEXT
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_GL
|
||||
* Method: wglReleaseTexImageARB
|
||||
|
@ -2231,14 +2223,6 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_GL_wglGetSwapIntervalEXT
|
|||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_GL_wglReleaseTexImageARB
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_GL
|
||||
* Method: wglSwapIntervalEXT
|
||||
* Signature: (I)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_GL_wglSwapIntervalEXT
|
||||
(JNIEnv *, jclass, jint);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_GL
|
||||
* Method: glWindowPos2fARB
|
||||
|
|
|
@ -19,8 +19,9 @@ extern "C" {
|
|||
/* Inaccessible static: depth */
|
||||
/* Inaccessible static: stencil */
|
||||
/* Inaccessible static: fullscreen */
|
||||
/* Inaccessible static: vsync */
|
||||
/* Inaccessible static: vbo_tracker */
|
||||
/* Inaccessible static: class_00024org_00024lwjgl_00024opengl_00024Window */
|
||||
/* Inaccessible static: class_000240 */
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_Window
|
||||
* Method: nSetTitle
|
||||
|
@ -88,7 +89,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers
|
|||
/*
|
||||
* Class: org_lwjgl_opengl_Window
|
||||
* Method: nCreate
|
||||
* Signature: (Ljava/lang/String;IIIIZIIIILjava/util/Vector;)V
|
||||
* Signature: (Ljava/lang/String;IIIIZIIIILjava/util/HashSet;)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate
|
||||
(JNIEnv *, jclass, jstring, jint, jint, jint, jint, jboolean, jint, jint, jint, jint, jobject);
|
||||
|
@ -109,6 +110,22 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy
|
|||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_update
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_Window
|
||||
* Method: nIsVSyncEnabled
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsVSyncEnabled
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_Window
|
||||
* Method: nSetVSyncEnabled
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetVSyncEnabled
|
||||
(JNIEnv *, jclass, jboolean);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -559,3 +559,26 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsFocused
|
|||
(JNIEnv *env, jclass clazz) {
|
||||
return focused;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_Window
|
||||
* Method: nIsVSyncEnabled
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsVSyncEnabled
|
||||
(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
// Always return false
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_Window
|
||||
* Method: nSetVSyncEnabled
|
||||
* Signature: (Z)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetVSyncEnabled
|
||||
(JNIEnv * env, jclass clazz, jboolean sync)
|
||||
{
|
||||
// Do nothing on Linux
|
||||
}
|
||||
|
|
|
@ -58,6 +58,7 @@ static bool closerequested;
|
|||
static bool minimized;
|
||||
static bool focused;
|
||||
static bool dirty;
|
||||
static jboolean vsync;
|
||||
|
||||
//CAS: commented these out as no longer used
|
||||
//extern void tempRestoreDisplayMode();
|
||||
|
@ -444,6 +445,8 @@ static bool createWindow(const char * title, int x, int y, int width, int height
|
|||
|
||||
}
|
||||
|
||||
vsync = JNI_FALSE;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -629,3 +632,32 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsFocused
|
|||
(JNIEnv *env, jclass clazz) {
|
||||
return focused;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_Window
|
||||
* Method: nIsVSyncEnabled
|
||||
* Signature: ()Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsVSyncEnabled
|
||||
(JNIEnv * env, jclass clazz)
|
||||
{
|
||||
return vsync;
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_lwjgl_opengl_Window
|
||||
* Method: nSetVSyncEnabled
|
||||
* Signature: (Z)Z
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetVSyncEnabled
|
||||
(JNIEnv * env, jclass clazz, jboolean sync)
|
||||
{
|
||||
if (extgl_Extensions.WGL_EXT_swap_control) {
|
||||
if (sync == JNI_TRUE) {
|
||||
wglSwapIntervalEXT(1);
|
||||
} else {
|
||||
wglSwapIntervalEXT(0);
|
||||
}
|
||||
vsync = sync;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue