From b5194bbb04237bafae1bf437f38fcb06be70c0e1 Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Sat, 3 Jan 2004 08:09:17 +0000 Subject: [PATCH] Implemented linux swap control through GLX_SGI_swap_control --- src/native/common/extgl.cpp | 13 ++++++++++ src/native/common/extgl.h | 6 +++++ src/native/linux/org_lwjgl_opengl_Window.cpp | 25 +++++++++----------- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/src/native/common/extgl.cpp b/src/native/common/extgl.cpp index 980c0899..0ba1ce7c 100755 --- a/src/native/common/extgl.cpp +++ b/src/native/common/extgl.cpp @@ -87,6 +87,9 @@ glXWaitXPROC glXWaitX = NULL; glXGetClientStringPROC glXGetClientString = NULL; glXQueryServerStringPROC glXQueryServerString = NULL; glXQueryExtensionsStringPROC glXQueryExtensionsString = NULL; + +/* GLX_SGI_swap_control */ +glXSwapIntervalSGIPROC glXSwapIntervalSGI = NULL; #endif #ifdef _AGL @@ -2538,6 +2541,15 @@ static void extgl_InitGLXSupportedExtensions(JNIEnv *env, jobject ext_set, Displ { extgl_Extensions.GLX_EXT_visual_info = GLXQueryExtension(env, ext_set, disp, screen, "GLX_EXT_visual_info"); extgl_Extensions.GLX_EXT_visual_rating = GLXQueryExtension(env, ext_set, disp, screen, "GLX_EXT_visual_rating"); + extgl_Extensions.GLX_SGI_swap_control = GLXQueryExtension(env, ext_set, disp, screen, "GLX_SGI_swap_control"); +} + +static void extgl_InitGLXSGISwapControl(JNIEnv *env, jobject ext_set) +{ + if (extgl_Extensions.GLX_SGI_swap_control != 1) + return; + glXSwapIntervalSGI = (glXSwapIntervalSGIPROC)extgl_GetProcAddress("glXSwapIntervalSGI"); + EXTGL_SANITY_CHECK(env, ext_set, GLX_SGI_swap_control) } bool extgl_InitGLX(JNIEnv *env, jobject ext_set, Display *disp, int screen) @@ -2556,6 +2568,7 @@ bool extgl_InitGLX(JNIEnv *env, jobject ext_set, Display *disp, int screen) if (major > 1 || (major == 1 && minor >= 3)) extgl_Extensions.GLX13 = true; extgl_InitGLX13(env, ext_set); + extgl_InitGLXSGISwapControl(env, ext_set); return true; } #endif diff --git a/src/native/common/extgl.h b/src/native/common/extgl.h index 9e93f1a0..6603a6b3 100644 --- a/src/native/common/extgl.h +++ b/src/native/common/extgl.h @@ -539,6 +539,11 @@ extern glXGetClientStringPROC glXGetClientString; extern glXQueryServerStringPROC glXQueryServerString; extern glXQueryExtensionsStringPROC glXQueryExtensionsString; +/* GLX_SGI_swap_control */ +typedef void (APIENTRY * glXSwapIntervalSGIPROC)(int interval); + +extern glXSwapIntervalSGIPROC glXSwapIntervalSGI; + #endif /* X11 */ #ifdef _AGL @@ -5535,6 +5540,7 @@ struct ExtensionTypes bool GLX13; bool GLX_EXT_visual_info; bool GLX_EXT_visual_rating; + bool GLX_SGI_swap_control; #endif /* X11 */ bool OpenGL12; diff --git a/src/native/linux/org_lwjgl_opengl_Window.cpp b/src/native/linux/org_lwjgl_opengl_Window.cpp index 12dc1c93..c8f71397 100644 --- a/src/native/linux/org_lwjgl_opengl_Window.cpp +++ b/src/native/linux/org_lwjgl_opengl_Window.cpp @@ -68,6 +68,7 @@ static int current_width; static bool input_released; static bool dirty; +static bool vsync_enabled; static bool minimized; static bool focused; static bool closerequested; @@ -182,7 +183,7 @@ static void createWindow(JNIEnv* env, Display *disp, int screen, XVisualInfo *vi focused = true; minimized = false; closerequested = false; - + vsync_enabled = false; Window root_win; Window win; XSetWindowAttributes attribs; @@ -556,25 +557,21 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsFocused 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; + return vsync_enabled; } -/* - * 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 + if (extgl_Extensions.GLX_SGI_swap_control) { + bool vsync = sync == JNI_TRUE ? true : false; + if (vsync != vsync_enabled) { + int interval = vsync ? 1 : 0; + glXSwapIntervalSGI(interval); + vsync_enabled = vsync; + } + } }