lwjgl/src/native/linux/org_lwjgl_opengl_Window.cpp

629 lines
17 KiB
C++
Raw Normal View History

2003-08-04 06:09:40 -04:00
/*
2002-11-15 05:40:55 -05:00
* Copyright (c) 2002 Light Weight Java Game Library Project
* All rights reserved.
2003-08-04 06:09:40 -04:00
*
2002-11-15 05:40:55 -05:00
* Redistribution and use in source and binary forms, with or without
2003-08-04 06:09:40 -04:00
* modification, are permitted provided that the following conditions are
2002-11-15 05:40:55 -05:00
* met:
2003-08-04 06:09:40 -04:00
*
* * Redistributions of source code must retain the above copyright
2002-11-15 05:40:55 -05:00
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
2003-08-04 06:09:40 -04:00
* * Neither the name of 'Light Weight Java Game Library' nor the names of
* its contributors may be used to endorse or promote products derived
2002-11-15 05:40:55 -05:00
* from this software without specific prior written permission.
2003-08-04 06:09:40 -04:00
*
2002-11-15 05:40:55 -05:00
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2003-08-04 06:09:40 -04:00
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
2002-11-15 05:40:55 -05:00
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
2003-08-04 06:09:40 -04:00
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
2002-11-15 05:40:55 -05:00
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
2003-08-04 06:09:40 -04:00
2002-11-15 05:40:55 -05:00
/**
* $Id$
*
2003-08-04 06:09:40 -04:00
* Linux specific window functions.
2002-11-15 05:40:55 -05:00
*
2002-11-15 06:10:32 -05:00
* @author elias_naur <elias_naur@users.sourceforge.net>
2002-11-15 05:40:55 -05:00
* @version $Revision$
*/
2003-08-04 06:09:40 -04:00
#include <X11/X.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <jni.h>
2003-10-11 12:29:40 -04:00
#include "common_tools.h"
2002-11-19 02:42:55 -05:00
#include "extgl.h"
#include "extgl_glx.h"
2003-03-30 14:26:39 -05:00
#include "Window.h"
2003-08-04 06:09:40 -04:00
#include "org_lwjgl_opengl_Window.h"
2002-11-15 05:40:55 -05:00
2003-09-26 09:59:50 -04:00
#define USEGLX13 extgl_Extensions.GLX13
2003-05-30 12:29:17 -04:00
2003-02-09 12:01:01 -05:00
static GLXContext context = NULL; // OpenGL rendering context
static GLXWindow glx_window;
2003-02-09 12:01:01 -05:00
2003-08-04 06:09:40 -04:00
static Atom delete_atom;
static Colormap cmap;
2003-08-04 06:09:40 -04:00
static Window current_win;
static int current_screen;
static bool current_fullscreen;
static int current_height;
static int current_width;
static bool input_released;
2004-04-04 04:36:55 -04:00
static bool dirty;
static bool vsync_enabled;
2003-08-04 06:09:40 -04:00
static bool minimized;
static bool focused;
static bool closerequested;
2004-04-12 06:05:13 -04:00
static bool grab;
2004-04-12 06:33:39 -04:00
static bool ignore_motion_events;
2003-08-04 06:09:40 -04:00
static Display *display_connection = NULL;
2004-04-13 08:13:32 -04:00
static Atom warp_atom;
static int display_connection_usage = 0;
Display *getDisplay(void) {
return display_connection;
}
Display *incDisplay(JNIEnv *env) {
if (display_connection_usage == 0) {
display_connection = XOpenDisplay(NULL);
if (display_connection == NULL) {
throwException(env, "Could not open X display");
return NULL;
}
2004-04-13 08:13:32 -04:00
warp_atom = XInternAtom(getDisplay(), "ignore_warp_atom", False);
}
display_connection_usage++;
return display_connection;
}
2004-04-13 08:13:32 -04:00
Atom getWarpAtom(void) {
return warp_atom;
}
void decDisplay(void) {
display_connection_usage--;
if (display_connection_usage == 0)
XCloseDisplay(display_connection);
}
static void waitMapped(Window win) {
2003-08-04 06:09:40 -04:00
XEvent event;
do {
XMaskEvent(getDisplay(), StructureNotifyMask, &event);
2003-08-04 06:09:40 -04:00
} while ((event.type != MapNotify) || (event.xmap.event != win));
}
2004-04-12 06:05:13 -04:00
static void updateInputGrab(void) {
updatePointerGrab();
updateKeyboardGrab();
2003-08-04 06:09:40 -04:00
}
2004-04-12 06:05:13 -04:00
static void setRepeatMode(int mode) {
XKeyboardControl repeat_mode;
repeat_mode.auto_repeat_mode = mode;
XChangeKeyboardControl(getDisplay(), KBAutoRepeatMode, &repeat_mode);
2003-08-04 06:09:40 -04:00
}
bool releaseInput(void) {
if (current_fullscreen || input_released)
return false;
2004-04-12 06:05:13 -04:00
input_released = true;
setRepeatMode(AutoRepeatModeDefault);
updateInputGrab();
2003-08-04 06:09:40 -04:00
return true;
}
2004-04-12 06:05:13 -04:00
static void acquireInput(void) {
if (current_fullscreen || !input_released)
return;
input_released = false;
setRepeatMode(AutoRepeatModeOff);
updateInputGrab();
}
2003-08-04 06:09:40 -04:00
bool isFullscreen(void) {
return current_fullscreen;
}
2004-04-12 06:05:13 -04:00
bool shouldGrab(void) {
2004-04-13 08:13:32 -04:00
return !input_released && grab;
2004-04-12 06:05:13 -04:00
}
void setGrab(bool new_grab) {
grab = new_grab;
updateInputGrab();
}
2004-04-12 06:33:39 -04:00
static void handleMotion(XMotionEvent *event) {
2004-04-13 08:13:32 -04:00
if (ignore_motion_events) {
2004-04-12 08:20:59 -04:00
resetCursor(event->x, event->y);
} else {
2004-04-12 06:33:39 -04:00
handlePointerMotion(event);
2004-04-12 08:20:59 -04:00
}
2004-04-12 06:33:39 -04:00
}
2004-04-13 08:13:32 -04:00
static void checkInput(void) {
Window win;
int revert_mode;
XGetInputFocus(getDisplay(), &win, &revert_mode);
if (win == current_win) {
acquireInput();
focused = true;
}
}
2003-08-04 06:09:40 -04:00
static void handleMessages() {
XEvent event;
2003-08-05 10:21:59 -04:00
Window win;
int revert_mode;
while (XPending(getDisplay()) > 0) {
XNextEvent(getDisplay(), &event);
2003-08-04 06:09:40 -04:00
switch (event.type) {
case ClientMessage:
2004-04-13 08:13:32 -04:00
if (event.xclient.message_type == warp_atom) {
ignore_motion_events = event.xclient.data.b[0] == 1 ? true : false;
} else if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom))
2003-08-04 06:09:40 -04:00
closerequested = true;
break;
case FocusOut:
XGetInputFocus(getDisplay(), &win, &revert_mode);
2003-08-05 10:21:59 -04:00
if (win != current_win) {
releaseInput();
focused = false;
}
2003-08-04 06:09:40 -04:00
break;
case FocusIn:
2004-04-13 08:13:32 -04:00
checkInput();
2003-08-04 06:09:40 -04:00
break;
case MapNotify:
dirty = true;
minimized = false;
break;
case UnmapNotify:
minimized = true;
break;
case Expose:
dirty = true;
break;
case ButtonPress:
2004-04-13 08:13:32 -04:00
checkInput();
2003-08-04 06:09:40 -04:00
handleButtonPress(&(event.xbutton));
break;
case ButtonRelease:
handleButtonRelease(&(event.xbutton));
break;
case MotionNotify:
2004-04-12 06:33:39 -04:00
handleMotion(&(event.xmotion));
2003-08-04 06:09:40 -04:00
break;
case KeyPress:
case KeyRelease:
handleKeyEvent(&(event.xkey));
break;
}
}
}
static void setWindowTitle(const char *title) {
XStoreName(getDisplay(), current_win, title);
2003-08-04 06:09:40 -04:00
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetTitle
(JNIEnv * env, jclass clazz, jstring title_obj)
{
const char * title = env->GetStringUTFChars(title_obj, NULL);
setWindowTitle(title);
env->ReleaseStringUTFChars(title_obj, title);
}
static void createWindow(JNIEnv* env, int screen, XVisualInfo *vis_info, jstring title, int x, int y, int width, int height, bool fullscreen, bool undecorated) {
2003-08-04 06:09:40 -04:00
dirty = true;
focused = true;
minimized = false;
closerequested = false;
vsync_enabled = false;
2004-04-12 06:05:13 -04:00
grab = false;
2004-04-12 06:33:39 -04:00
ignore_motion_events = false;
2003-08-04 06:09:40 -04:00
Window root_win;
Window win;
XSetWindowAttributes attribs;
int attribmask;
current_screen = screen;
input_released = false;
current_fullscreen = fullscreen;
current_width = width;
current_height = height;
root_win = RootWindow(getDisplay(), screen);
cmap = XCreateColormap(getDisplay(), root_win, vis_info->visual, AllocNone);
2003-08-04 06:09:40 -04:00
attribs.colormap = cmap;
attribs.event_mask = ExposureMask | FocusChangeMask | VisibilityChangeMask| StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask;
attribs.background_pixel = 0xFF000000;
attribmask = CWColormap | CWBackPixel | CWEventMask;
2004-04-05 10:19:25 -04:00
if (fullscreen || undecorated) {
2003-08-04 06:09:40 -04:00
attribmask |= CWOverrideRedirect;
attribs.override_redirect = True;
}
win = XCreateWindow(getDisplay(), root_win, x, y, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs);
2003-12-20 17:03:25 -05:00
printfDebug("Created window\n");
2003-08-04 06:09:40 -04:00
current_win = win;
Java_org_lwjgl_opengl_Window_nSetTitle(env, NULL, title);
XSizeHints * size_hints = XAllocSizeHints();
size_hints->flags = PMinSize | PMaxSize;
size_hints->min_width = width;
size_hints->max_width = width;
size_hints->min_height = height;
size_hints->max_height = height;
XSetWMNormalHints(getDisplay(), win, size_hints);
2003-08-04 06:09:40 -04:00
XFree(size_hints);
delete_atom = XInternAtom(getDisplay(), "WM_DELETE_WINDOW", False);
XSetWMProtocols(getDisplay(), win, &delete_atom, 1);
XMapRaised(getDisplay(), win);
waitMapped(win);
XClearWindow(getDisplay(), win);
setRepeatMode(AutoRepeatModeOff);
XSync(getDisplay(), True);
2003-08-04 06:09:40 -04:00
}
static void destroyWindow() {
XDestroyWindow(getDisplay(), current_win);
XFreeColormap(getDisplay(), cmap);
2003-08-04 06:09:40 -04:00
}
int getCurrentScreen(void) {
return current_screen;
}
Window getCurrentWindow(void) {
return current_win;
}
int getWindowWidth(void) {
return current_width;
}
int getWindowHeight(void) {
return current_height;
}
/*
* Class: org_lwjgl_Window
2004-03-26 06:09:39 -05:00
* Method: nUpdate
2003-08-04 06:09:40 -04:00
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nUpdate
2003-08-04 06:09:40 -04:00
(JNIEnv *env, jclass clazz)
{
handleMessages();
}
2004-02-18 12:48:26 -05:00
/*
* Class: org_lwjgl_Window
* Method: nMakeCurrent
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nMakeCurrent
(JNIEnv *env, jclass clazz)
{
makeCurrent();
}
void makeCurrent(void) {
2003-09-26 09:59:50 -04:00
if (USEGLX13)
glXMakeContextCurrent(getDisplay(), glx_window, glx_window, context);
else
glXMakeCurrent(getDisplay(), getCurrentWindow(), context);
}
static void releaseContext(void) {
2003-09-26 09:59:50 -04:00
if (USEGLX13)
glXMakeContextCurrent(getDisplay(), None, None, NULL);
else
glXMakeCurrent(getDisplay(), None, NULL);
2003-03-30 14:26:39 -05:00
}
int convertToBPE(int bpp) {
2004-04-04 04:36:55 -04:00
int bpe;
2003-03-30 14:26:39 -05:00
switch (bpp) {
case 32:
case 24:
bpe = 8;
break;
case 16: /* Fall through */
2003-03-30 14:26:39 -05:00
default:
2004-04-04 04:36:55 -04:00
bpe = 4;
break;
2003-03-30 14:26:39 -05:00
}
return bpe;
}
2003-03-30 14:26:39 -05:00
GLXContext getCurrentContext(void) {
return context;
}
static GLXFBConfig *chooseVisualGLX13(int screen, int bpp, int depth, int alpha, int stencil, int samples) {
int bpe = convertToBPE(bpp);
int attriblist[] = {GLX_RENDER_TYPE, GLX_RGBA_BIT,
GLX_DOUBLEBUFFER, True,
GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT,
GLX_DEPTH_SIZE, depth,
GLX_RED_SIZE, bpe,
GLX_GREEN_SIZE, bpe,
GLX_BLUE_SIZE, bpe,
GLX_ALPHA_SIZE, alpha,
GLX_STENCIL_SIZE, stencil,
2004-02-15 10:27:02 -05:00
None, None, /* For ARB_multisample */
None, None, /* */
None};
2003-05-30 02:10:33 -04:00
int num_formats = 0;
2004-02-15 10:27:02 -05:00
if (samples > 0 && extgl_Extensions.GLX_ARB_multisample) {
attriblist[18] = GLX_SAMPLE_BUFFERS_ARB;
attriblist[19] = 1;
attriblist[20] = GLX_SAMPLES_ARB;
attriblist[21] = samples;
}
GLXFBConfig* configs = glXChooseFBConfig(getDisplay(), screen, attriblist, &num_formats);
2003-05-30 02:10:33 -04:00
if (num_formats > 0)
return configs;
else {
if (configs != NULL)
XFree(configs);
return NULL;
}
}
static XVisualInfo *chooseVisual(int screen, int bpp, int depth, int alpha, int stencil, int samples) {
int bpe = convertToBPE(bpp);
int attriblist[] = {GLX_RGBA,
GLX_DOUBLEBUFFER,
GLX_DEPTH_SIZE, depth,
GLX_RED_SIZE, bpe,
GLX_GREEN_SIZE, bpe,
GLX_BLUE_SIZE, bpe,
GLX_ALPHA_SIZE, alpha,
GLX_STENCIL_SIZE, stencil,
2004-02-15 10:27:02 -05:00
None, None, /* For ARB_multisample */
None, None, /* */
None};
2004-02-15 10:27:02 -05:00
if (samples > 0 && extgl_Extensions.GLX_ARB_multisample) {
attriblist[14] = GLX_SAMPLE_BUFFERS_ARB;
attriblist[15] = 1;
attriblist[16] = GLX_SAMPLES_ARB;
attriblist[17] = samples;
}
return glXChooseVisual(getDisplay(), screen, attriblist);
2003-03-30 14:26:39 -05:00
}
static void dumpVisualInfo(XVisualInfo *vis_info) {
2003-03-30 14:26:39 -05:00
int alpha, depth, stencil, r, g, b;
2004-02-15 10:27:02 -05:00
int sample_buffers = 0;
int samples = 0;
glXGetConfig(getDisplay(), vis_info, GLX_RED_SIZE, &r);
glXGetConfig(getDisplay(), vis_info, GLX_GREEN_SIZE, &g);
glXGetConfig(getDisplay(), vis_info, GLX_BLUE_SIZE, &b);
glXGetConfig(getDisplay(), vis_info, GLX_ALPHA_SIZE, &alpha);
glXGetConfig(getDisplay(), vis_info, GLX_DEPTH_SIZE, &depth);
glXGetConfig(getDisplay(), vis_info, GLX_STENCIL_SIZE, &stencil);
2004-02-15 10:27:02 -05:00
if (extgl_Extensions.GLX_ARB_multisample) {
glXGetConfig(getDisplay(), vis_info, GLX_SAMPLE_BUFFERS_ARB, &sample_buffers);
glXGetConfig(getDisplay(), vis_info, GLX_SAMPLES_ARB, &samples);
2004-02-15 10:27:02 -05:00
}
2004-04-12 08:20:59 -04:00
printfDebug("Pixel format info: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d, sample buffers = %d, samples = %d\n", r, g, b, alpha, depth, stencil, sample_buffers, samples);
2003-03-30 14:26:39 -05:00
}
static void destroy(void) {
releaseContext();
2003-09-26 09:59:50 -04:00
if (USEGLX13)
glXDestroyWindow(getDisplay(), glx_window);
glXDestroyContext(getDisplay(), context);
2003-03-30 14:26:39 -05:00
context = NULL;
destroyWindow();
2004-04-12 06:05:13 -04:00
setRepeatMode(AutoRepeatModeDefault);
decDisplay();
2003-03-30 14:26:39 -05:00
extgl_Close();
}
static bool initWindowGLX13(JNIEnv *env, int screen, jstring title, int x, int y, int width, int height, int bpp, int depth, int alpha, int stencil, int samples, bool fscreen, bool undecorated) {
GLXFBConfig *configs = chooseVisualGLX13(screen, bpp, depth, alpha, stencil, samples);
if (configs == NULL) {
throwException(env, "Could not find a matching pixel format");
return false;
}
context = glXCreateNewContext(getDisplay(), configs[0], GLX_RGBA_TYPE, NULL, True);
if (context == NULL) {
XFree(configs);
throwException(env, "Could not create a GLX context");
return false;
}
jboolean allow_software_acceleration = getBooleanProperty(env, "org.lwjgl.opengl.Window.allowSoftwareOpenGL");
if (!allow_software_acceleration && (glXIsDirect(getDisplay(), context) == False)) {
glXDestroyContext(getDisplay(), context);
XFree(configs);
2004-02-15 10:27:02 -05:00
throwException(env, "Could not create a direct GLX context");
return false;
}
XVisualInfo * vis_info = glXGetVisualFromFBConfig(getDisplay(), configs[0]);
2003-05-30 02:10:33 -04:00
if (vis_info == NULL) {
glXDestroyContext(getDisplay(), context);
2003-05-30 02:10:33 -04:00
XFree(configs);
throwException(env, "Could not create visual info from FB config");
return false;
}
createWindow(env, screen, vis_info, title, x, y, width, height, fscreen, undecorated);
glx_window = glXCreateWindow(getDisplay(), configs[0], getCurrentWindow(), NULL);
makeCurrent();
if (isDebugEnabled())
dumpVisualInfo(vis_info);
XFree(configs);
XFree(vis_info);
return true;
}
static bool initWindowGLX(JNIEnv *env, int screen, jstring title, int x, int y, int width, int height, int bpp, int depth, int alpha, int stencil, int samples, bool fscreen, bool undecorated) {
XVisualInfo *vis_info = chooseVisual(screen, bpp, depth, alpha, stencil, samples);
if (vis_info == NULL) {
throwException(env, "Could not find a matching pixel format");
return false;
}
if (isDebugEnabled())
dumpVisualInfo(vis_info);
context = glXCreateContext(getDisplay(), vis_info, NULL, True);
if (context == NULL) {
XFree(vis_info);
throwException(env, "Could not create a GLX context");
return false;
}
jboolean allow_software_acceleration = getBooleanProperty(env, "org.lwjgl.opengl.Window.allowSoftwareOpenGL");
if (!allow_software_acceleration && glXIsDirect(getDisplay(), context) == False) {
glXDestroyContext(getDisplay(), context);
XFree(vis_info);
2003-07-15 10:02:39 -04:00
throwException(env, "Could not create a direct GLX context");
return false;
}
createWindow(env, screen, vis_info, title, x, y, width, height, fscreen, undecorated);
makeCurrent();
XFree(vis_info);
return true;
}
2003-08-04 06:09:40 -04:00
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nCreate
(JNIEnv * env, jclass clazz, jstring title, jint x, jint y, jint width, jint height, jboolean fullscreen, jint bpp, jint alpha, jint depth, jint stencil, jint samples)
2002-11-15 05:40:55 -05:00
{
2003-03-30 14:26:39 -05:00
int screen;
bool fscreen = false;
if (fullscreen == JNI_TRUE)
fscreen = true;
2004-04-04 09:43:43 -04:00
bool isUndecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated");
2003-03-30 14:26:39 -05:00
2003-09-26 09:59:50 -04:00
if (!extgl_Open()) {
2003-03-30 14:26:39 -05:00
throwException(env, "Could not load gl libs");
return;
}
Display *disp = incDisplay(env);
if (disp == NULL)
2003-03-30 14:26:39 -05:00
return;
screen = XDefaultScreen(disp);
2004-02-25 11:44:45 -05:00
if (!extgl_InitGLX(env, disp, screen)) {
decDisplay();
2003-03-30 14:26:39 -05:00
extgl_Close();
throwException(env, "Could not init GLX");
return;
}
bool create_success;
2003-09-26 09:59:50 -04:00
if (USEGLX13) {
create_success = initWindowGLX13(env, screen, title, x, y, width, height, bpp, depth, alpha, stencil, samples, fscreen, isUndecorated);
} else {
create_success = initWindowGLX(env, screen, title, x, y, width, height, bpp, depth, alpha, stencil, samples, fscreen, isUndecorated);
2002-11-15 05:40:55 -05:00
}
if (!create_success) {
decDisplay();
2003-03-30 14:26:39 -05:00
extgl_Close();
return;
2002-11-18 15:22:01 -05:00
}
2002-11-15 05:40:55 -05:00
}
/*
* Class: org_lwjgl_opengl_GLWindow
2002-11-15 05:40:55 -05:00
* Method: nDestroy
* Signature: ()V
*/
2003-08-04 06:09:40 -04:00
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nDestroy
(JNIEnv *env, jclass clazz)
2002-11-15 05:40:55 -05:00
{
2003-03-30 14:26:39 -05:00
destroy();
2002-11-15 05:40:55 -05:00
}
/*
* Class: org_lwjgl_opengl_GLWindow
2002-11-15 05:40:55 -05:00
* Method: swapBuffers
* Signature: ()V
*/
2003-08-04 06:09:40 -04:00
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_swapBuffers(JNIEnv * env, jclass clazz)
2002-11-15 05:40:55 -05:00
{
2003-08-04 06:09:40 -04:00
dirty = false;
2003-09-26 09:59:50 -04:00
if (USEGLX13)
glXSwapBuffers(getDisplay(), glx_window);
else
glXSwapBuffers(getDisplay(), getCurrentWindow());
2002-11-15 05:40:55 -05:00
}
2003-08-04 06:09:40 -04:00
/*
* Class: org_lwjgl_opengl_Window
* Method: nIsDirty
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsDirty
(JNIEnv *env, jclass clazz) {
bool result = dirty;
dirty = false;
return result ? JNI_TRUE : JNI_FALSE;
2003-08-04 06:09:40 -04:00
}
/*
* Class: org_lwjgl_opengl_Window
* Method: nIsVisible
2003-08-04 06:09:40 -04:00
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsVisible
2003-08-04 06:09:40 -04:00
(JNIEnv *env, jclass clazz) {
return minimized ? JNI_FALSE : JNI_TRUE;
2003-08-04 06:09:40 -04:00
}
/*
* Class: org_lwjgl_opengl_Window
* Method: nIsCloseRequested
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsCloseRequested
(JNIEnv *, jclass) {
bool saved = closerequested;
closerequested = false;
return saved;
}
/*
* Class: org_lwjgl_opengl_Window
* Method: nIsActive
2003-08-04 06:09:40 -04:00
* Signature: ()Z
*/
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Window_nIsActive
2003-08-04 06:09:40 -04:00
(JNIEnv *env, jclass clazz) {
return focused ? JNI_TRUE : JNI_FALSE;
2003-08-04 06:09:40 -04:00
}
2003-10-20 10:17:47 -04:00
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Window_nSetVSyncEnabled
(JNIEnv * env, jclass clazz, jboolean sync)
{
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;
}
}
2003-10-20 10:17:47 -04:00
}
2004-04-03 18:01:39 -05:00