2004-06-12 16:28:34 -04:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2002-2004 LWJGL Project
|
2002-11-15 05:40:55 -05:00
|
|
|
* All rights reserved.
|
2004-06-12 16:28:34 -04:00
|
|
|
*
|
2002-11-15 05:40:55 -05:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
2004-06-12 16:28:34 -04:00
|
|
|
* modification, are permitted provided that the following conditions are
|
2002-11-15 05:40:55 -05:00
|
|
|
* met:
|
2004-06-12 16:28:34 -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.
|
|
|
|
*
|
2004-06-12 16:28:34 -04:00
|
|
|
* * Neither the name of 'LWJGL' 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.
|
2004-06-12 16:28:34 -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
|
2004-06-12 16:28:34 -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
|
2004-06-12 16:28:34 -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$
|
|
|
|
*
|
2004-07-02 15:02:00 -04:00
|
|
|
* Linux specific display 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"
|
2004-03-11 07:38:13 -05:00
|
|
|
#include "extgl_glx.h"
|
2003-03-30 14:26:39 -05:00
|
|
|
#include "Window.h"
|
2004-07-02 15:02:00 -04:00
|
|
|
#include "display.h"
|
|
|
|
#include "org_lwjgl_opengl_Display.h"
|
2002-11-15 05:40:55 -05:00
|
|
|
|
2003-09-26 09:59:50 -04:00
|
|
|
#define USEGLX13 extgl_Extensions.GLX13
|
2004-05-11 16:34:47 -04:00
|
|
|
#define ERR_MSG_SIZE 1024
|
2003-05-30 12:29:17 -04:00
|
|
|
|
2003-02-09 12:01:01 -05:00
|
|
|
static GLXContext context = NULL; // OpenGL rendering context
|
2003-05-20 08:20:13 -04:00
|
|
|
static GLXWindow glx_window;
|
2004-07-02 15:02:00 -04:00
|
|
|
static XVisualInfo * vis_info;
|
|
|
|
static GLXFBConfig *configs;
|
2003-02-09 12:01:01 -05:00
|
|
|
|
2003-08-04 06:09:40 -04:00
|
|
|
static Atom delete_atom;
|
2004-05-10 17:48:06 -04:00
|
|
|
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;
|
2004-01-03 03:09:17 -05:00
|
|
|
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
|
|
|
|
2004-04-07 03:46:03 -04:00
|
|
|
static Display *display_connection = NULL;
|
2004-04-13 08:13:32 -04:00
|
|
|
static Atom warp_atom;
|
2004-04-07 03:46:03 -04:00
|
|
|
static int display_connection_usage = 0;
|
2004-05-11 16:34:47 -04:00
|
|
|
static bool async_x_error;
|
|
|
|
static char error_message[ERR_MSG_SIZE];
|
|
|
|
|
|
|
|
bool checkXError(JNIEnv *env) {
|
|
|
|
XSync(getDisplay(), False);
|
|
|
|
if (async_x_error) {
|
|
|
|
async_x_error = false;
|
|
|
|
throwException(env, error_message);
|
|
|
|
return false;
|
|
|
|
} else
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int errorHandler(Display *disp, XErrorEvent *error) {
|
|
|
|
char err_msg_buffer[ERR_MSG_SIZE];
|
|
|
|
XGetErrorText(disp, error->error_code, err_msg_buffer, ERR_MSG_SIZE);
|
|
|
|
err_msg_buffer[ERR_MSG_SIZE - 1] = '\0';
|
|
|
|
snprintf(error_message, ERR_MSG_SIZE, "X Error - serial: %d, error_code: %s, request_code: %d, minor_code: %d", (int)error->serial, err_msg_buffer, (int)error->request_code, (int)error->minor_code);
|
|
|
|
error_message[ERR_MSG_SIZE - 1] = '\0';
|
|
|
|
async_x_error = true;
|
|
|
|
return 0;
|
|
|
|
}
|
2004-04-07 03:46:03 -04:00
|
|
|
|
|
|
|
Display *getDisplay(void) {
|
|
|
|
return display_connection;
|
|
|
|
}
|
|
|
|
|
|
|
|
Display *incDisplay(JNIEnv *env) {
|
|
|
|
if (display_connection_usage == 0) {
|
2004-05-11 16:34:47 -04:00
|
|
|
async_x_error = false;
|
|
|
|
XSetErrorHandler(errorHandler);
|
2004-04-07 03:46:03 -04:00
|
|
|
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);
|
2004-04-07 03:46:03 -04:00
|
|
|
}
|
|
|
|
display_connection_usage++;
|
|
|
|
return display_connection;
|
|
|
|
}
|
|
|
|
|
2004-04-13 08:13:32 -04:00
|
|
|
Atom getWarpAtom(void) {
|
|
|
|
return warp_atom;
|
|
|
|
}
|
|
|
|
|
2004-04-07 03:46:03 -04:00
|
|
|
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 {
|
2004-04-07 03:46:03 -04:00
|
|
|
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;
|
2004-04-07 03:46:03 -04:00
|
|
|
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:
|
2004-04-07 03:46:03 -04:00
|
|
|
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) {
|
2004-04-07 03:46:03 -04:00
|
|
|
XStoreName(getDisplay(), current_win, title);
|
2003-08-04 06:09:40 -04:00
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetTitle
|
2003-08-04 06:09:40 -04:00
|
|
|
(JNIEnv * env, jclass clazz, jstring title_obj)
|
|
|
|
{
|
|
|
|
const char * title = env->GetStringUTFChars(title_obj, NULL);
|
|
|
|
setWindowTitle(title);
|
|
|
|
env->ReleaseStringUTFChars(title_obj, title);
|
|
|
|
}
|
|
|
|
|
2004-05-11 16:34:47 -04:00
|
|
|
static void destroyWindow() {
|
|
|
|
XDestroyWindow(getDisplay(), current_win);
|
|
|
|
XFreeColormap(getDisplay(), cmap);
|
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
static bool createWindow(JNIEnv* env, int width, int height) {
|
|
|
|
bool undecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated");
|
2003-08-04 06:09:40 -04:00
|
|
|
dirty = true;
|
|
|
|
focused = true;
|
|
|
|
minimized = false;
|
|
|
|
closerequested = false;
|
2004-01-03 03:09:17 -05:00
|
|
|
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;
|
|
|
|
|
|
|
|
input_released = false;
|
|
|
|
current_width = width;
|
|
|
|
current_height = height;
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
root_win = RootWindow(getDisplay(), getCurrentScreen());
|
2004-04-07 03:46:03 -04:00
|
|
|
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-07-02 15:02:00 -04:00
|
|
|
if (current_fullscreen || undecorated) {
|
2003-08-04 06:09:40 -04:00
|
|
|
attribmask |= CWOverrideRedirect;
|
|
|
|
attribs.override_redirect = True;
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
win = XCreateWindow(getDisplay(), root_win, 0, 0, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs);
|
2004-05-11 16:34:47 -04:00
|
|
|
if (!checkXError(env)) {
|
|
|
|
XFreeColormap(getDisplay(), cmap);
|
|
|
|
return false;
|
|
|
|
}
|
2003-12-20 17:03:25 -05:00
|
|
|
printfDebug("Created window\n");
|
2003-08-04 06:09:40 -04:00
|
|
|
current_win = win;
|
|
|
|
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;
|
2004-04-07 03:46:03 -04:00
|
|
|
XSetWMNormalHints(getDisplay(), win, size_hints);
|
2003-08-04 06:09:40 -04:00
|
|
|
XFree(size_hints);
|
2004-04-07 03:46:03 -04:00
|
|
|
delete_atom = XInternAtom(getDisplay(), "WM_DELETE_WINDOW", False);
|
|
|
|
XSetWMProtocols(getDisplay(), win, &delete_atom, 1);
|
|
|
|
XMapRaised(getDisplay(), win);
|
|
|
|
waitMapped(win);
|
|
|
|
XClearWindow(getDisplay(), win);
|
2004-04-12 10:29:55 -04:00
|
|
|
setRepeatMode(AutoRepeatModeOff);
|
2004-05-11 16:34:47 -04:00
|
|
|
if (!checkXError(env)) {
|
|
|
|
destroyWindow();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
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
|
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_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
|
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nMakeCurrent
|
2004-02-18 12:48:26 -05:00
|
|
|
(JNIEnv *env, jclass clazz)
|
|
|
|
{
|
|
|
|
makeCurrent();
|
|
|
|
}
|
|
|
|
|
2003-05-20 08:20:13 -04:00
|
|
|
void makeCurrent(void) {
|
2003-09-26 09:59:50 -04:00
|
|
|
if (USEGLX13)
|
2004-04-07 03:46:03 -04:00
|
|
|
glXMakeContextCurrent(getDisplay(), glx_window, glx_window, context);
|
2003-05-20 08:20:13 -04:00
|
|
|
else
|
2004-04-07 03:46:03 -04:00
|
|
|
glXMakeCurrent(getDisplay(), getCurrentWindow(), context);
|
2002-11-21 06:00:40 -05:00
|
|
|
}
|
|
|
|
|
2003-02-14 06:23:01 -05:00
|
|
|
static void releaseContext(void) {
|
2003-09-26 09:59:50 -04:00
|
|
|
if (USEGLX13)
|
2004-04-07 03:46:03 -04:00
|
|
|
glXMakeContextCurrent(getDisplay(), None, None, NULL);
|
2003-05-20 08:20:13 -04:00
|
|
|
else
|
2004-04-07 03:46:03 -04:00
|
|
|
glXMakeCurrent(getDisplay(), None, NULL);
|
2003-03-30 14:26:39 -05:00
|
|
|
}
|
|
|
|
|
2003-05-20 08:20:13 -04: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;
|
2003-05-20 08:20:13 -04:00
|
|
|
case 16: /* Fall through */
|
2003-03-30 14:26:39 -05:00
|
|
|
default:
|
2004-04-04 04:36:55 -04:00
|
|
|
bpe = 4;
|
2003-05-20 08:20:13 -04:00
|
|
|
break;
|
2003-03-30 14:26:39 -05:00
|
|
|
}
|
2003-05-20 08:20:13 -04:00
|
|
|
return bpe;
|
|
|
|
}
|
2003-03-30 14:26:39 -05:00
|
|
|
|
2003-05-20 08:20:13 -04:00
|
|
|
GLXContext getCurrentContext(void) {
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2004-07-03 06:32:12 -04:00
|
|
|
static GLXFBConfig *chooseVisualGLX13FromBPP(JNIEnv *env, jobject pixel_format, int bpp, int drawable_type, bool double_buffer) {
|
2004-07-02 15:02:00 -04:00
|
|
|
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
|
|
|
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
|
|
|
|
int depth = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "depth", "I"));
|
|
|
|
int stencil = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "stencil", "I"));
|
|
|
|
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
|
|
|
|
int num_aux_buffers = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "num_aux_buffers", "I"));
|
|
|
|
int accum_bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_bpp", "I"));
|
|
|
|
int accum_alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_alpha", "I"));
|
|
|
|
bool stereo = (bool)env->GetBooleanField(pixel_format, env->GetFieldID(cls_pixel_format, "stereo", "Z"));
|
|
|
|
|
2003-05-20 08:20:13 -04:00
|
|
|
int bpe = convertToBPE(bpp);
|
2004-07-02 15:02:00 -04:00
|
|
|
int accum_bpe = convertToBPE(accum_bpp);
|
|
|
|
attrib_list_t attrib_list;
|
|
|
|
initAttribList(&attrib_list);
|
|
|
|
putAttrib(&attrib_list, GLX_RENDER_TYPE); putAttrib(&attrib_list, GLX_RGBA_BIT);
|
|
|
|
putAttrib(&attrib_list, GLX_DOUBLEBUFFER); putAttrib(&attrib_list, double_buffer ? True : False);
|
|
|
|
putAttrib(&attrib_list, GLX_DRAWABLE_TYPE); putAttrib(&attrib_list, drawable_type);
|
|
|
|
putAttrib(&attrib_list, GLX_DEPTH_SIZE); putAttrib(&attrib_list, depth);
|
|
|
|
putAttrib(&attrib_list, GLX_RED_SIZE); putAttrib(&attrib_list, bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_GREEN_SIZE); putAttrib(&attrib_list, bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_BLUE_SIZE); putAttrib(&attrib_list, bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_ALPHA_SIZE); putAttrib(&attrib_list, alpha);
|
|
|
|
putAttrib(&attrib_list, GLX_STENCIL_SIZE); putAttrib(&attrib_list, stencil);
|
|
|
|
putAttrib(&attrib_list, GLX_AUX_BUFFERS); putAttrib(&attrib_list, num_aux_buffers);
|
|
|
|
putAttrib(&attrib_list, GLX_ACCUM_RED_SIZE); putAttrib(&attrib_list, accum_bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_ACCUM_GREEN_SIZE); putAttrib(&attrib_list, accum_bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_ACCUM_BLUE_SIZE); putAttrib(&attrib_list, accum_bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_ACCUM_ALPHA_SIZE); putAttrib(&attrib_list, accum_alpha);
|
|
|
|
putAttrib(&attrib_list, GLX_STEREO); putAttrib(&attrib_list, stereo ? True : False);
|
2004-02-15 10:27:02 -05:00
|
|
|
if (samples > 0 && extgl_Extensions.GLX_ARB_multisample) {
|
2004-07-02 15:02:00 -04:00
|
|
|
putAttrib(&attrib_list, GLX_SAMPLE_BUFFERS_ARB); putAttrib(&attrib_list, 1);
|
|
|
|
putAttrib(&attrib_list, GLX_SAMPLES_ARB); putAttrib(&attrib_list, samples);
|
2004-02-15 10:27:02 -05:00
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
putAttrib(&attrib_list, None); putAttrib(&attrib_list, None);
|
|
|
|
int num_formats = 0;
|
|
|
|
GLXFBConfig* configs = glXChooseFBConfig(getDisplay(), getCurrentScreen(), attrib_list.attribs, &num_formats);
|
|
|
|
if (num_formats > 0) {
|
2003-05-30 02:10:33 -04:00
|
|
|
return configs;
|
2004-07-02 15:02:00 -04:00
|
|
|
} else {
|
2003-05-30 02:10:33 -04:00
|
|
|
if (configs != NULL)
|
|
|
|
XFree(configs);
|
|
|
|
return NULL;
|
|
|
|
}
|
2003-05-20 08:20:13 -04:00
|
|
|
}
|
|
|
|
|
2004-07-03 06:32:12 -04:00
|
|
|
GLXFBConfig *chooseVisualGLX13(JNIEnv *env, jobject pixel_format, bool use_display_bpp, int drawable_type, bool double_buffer) {
|
|
|
|
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
|
|
|
int bpp;
|
|
|
|
if (use_display_bpp) {
|
|
|
|
bpp = XDefaultDepthOfScreen(XScreenOfDisplay(getDisplay(), getCurrentScreen()));
|
|
|
|
GLXFBConfig *configs = chooseVisualGLX13FromBPP(env, pixel_format, bpp, drawable_type, double_buffer);
|
|
|
|
if (configs == NULL)
|
|
|
|
bpp = 16;
|
|
|
|
} else
|
|
|
|
bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "bpp", "I"));
|
|
|
|
return chooseVisualGLX13FromBPP(env, pixel_format, bpp, drawable_type, double_buffer);
|
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
static XVisualInfo *chooseVisualGLX(JNIEnv *env, jobject pixel_format) {
|
|
|
|
int bpp = XDefaultDepthOfScreen(XScreenOfDisplay(getDisplay(), getCurrentScreen()));
|
|
|
|
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
|
|
|
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
|
|
|
|
int depth = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "depth", "I"));
|
|
|
|
int stencil = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "stencil", "I"));
|
|
|
|
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
|
|
|
|
int num_aux_buffers = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "num_aux_buffers", "I"));
|
|
|
|
int accum_bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_bpp", "I"));
|
|
|
|
int accum_alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_alpha", "I"));
|
|
|
|
bool stereo = (bool)env->GetBooleanField(pixel_format, env->GetFieldID(cls_pixel_format, "stereo", "Z"));
|
|
|
|
|
2003-05-20 08:20:13 -04:00
|
|
|
int bpe = convertToBPE(bpp);
|
2004-07-02 15:02:00 -04:00
|
|
|
int accum_bpe = convertToBPE(accum_bpp);
|
|
|
|
attrib_list_t attrib_list;
|
|
|
|
initAttribList(&attrib_list);
|
|
|
|
putAttrib(&attrib_list, GLX_RGBA);
|
|
|
|
putAttrib(&attrib_list, GLX_DOUBLEBUFFER);
|
|
|
|
putAttrib(&attrib_list, GLX_DEPTH_SIZE); putAttrib(&attrib_list, depth);
|
|
|
|
putAttrib(&attrib_list, GLX_RED_SIZE); putAttrib(&attrib_list, bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_GREEN_SIZE); putAttrib(&attrib_list, bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_BLUE_SIZE); putAttrib(&attrib_list, bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_ALPHA_SIZE); putAttrib(&attrib_list, alpha);
|
|
|
|
putAttrib(&attrib_list, GLX_STENCIL_SIZE); putAttrib(&attrib_list, stencil);
|
|
|
|
putAttrib(&attrib_list, GLX_AUX_BUFFERS); putAttrib(&attrib_list, num_aux_buffers);
|
|
|
|
putAttrib(&attrib_list, GLX_ACCUM_RED_SIZE); putAttrib(&attrib_list, accum_bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_ACCUM_GREEN_SIZE); putAttrib(&attrib_list, accum_bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_ACCUM_BLUE_SIZE); putAttrib(&attrib_list, accum_bpe);
|
|
|
|
putAttrib(&attrib_list, GLX_ACCUM_ALPHA_SIZE); putAttrib(&attrib_list, accum_alpha);
|
|
|
|
if (stereo)
|
|
|
|
putAttrib(&attrib_list, GLX_STEREO);
|
2004-02-15 10:27:02 -05:00
|
|
|
if (samples > 0 && extgl_Extensions.GLX_ARB_multisample) {
|
2004-07-02 15:02:00 -04:00
|
|
|
putAttrib(&attrib_list, GLX_SAMPLE_BUFFERS_ARB); putAttrib(&attrib_list, 1);
|
|
|
|
putAttrib(&attrib_list, GLX_SAMPLES_ARB); putAttrib(&attrib_list, samples);
|
2004-02-15 10:27:02 -05:00
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
putAttrib(&attrib_list, None);
|
|
|
|
return glXChooseVisual(getDisplay(), getCurrentScreen(), attrib_list.attribs);
|
2003-03-30 14:26:39 -05:00
|
|
|
}
|
|
|
|
|
2004-04-07 03:46:03 -04: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;
|
2004-04-07 03:46:03 -04:00
|
|
|
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) {
|
2004-04-07 03:46:03 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
static void destroyContext(void) {
|
2003-03-30 14:26:39 -05:00
|
|
|
releaseContext();
|
2004-07-02 15:02:00 -04:00
|
|
|
if (USEGLX13) {
|
2004-04-07 03:46:03 -04:00
|
|
|
glXDestroyWindow(getDisplay(), glx_window);
|
2004-07-02 15:02:00 -04:00
|
|
|
XFree(configs);
|
|
|
|
}
|
|
|
|
XFree(vis_info);
|
2004-04-07 03:46:03 -04:00
|
|
|
glXDestroyContext(getDisplay(), context);
|
2003-03-30 14:26:39 -05:00
|
|
|
context = NULL;
|
2004-04-12 06:05:13 -04:00
|
|
|
setRepeatMode(AutoRepeatModeDefault);
|
2004-04-07 03:46:03 -04:00
|
|
|
decDisplay();
|
2003-03-30 14:26:39 -05:00
|
|
|
extgl_Close();
|
2002-11-25 12:04:56 -05:00
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
static bool initWindowGLX13(JNIEnv *env, jobject pixel_format) {
|
|
|
|
configs = chooseVisualGLX13(env, pixel_format, true, GLX_WINDOW_BIT, true);
|
2003-05-20 08:20:13 -04:00
|
|
|
if (configs == NULL) {
|
|
|
|
throwException(env, "Could not find a matching pixel format");
|
|
|
|
return false;
|
|
|
|
}
|
2004-04-07 03:46:03 -04:00
|
|
|
context = glXCreateNewContext(getDisplay(), configs[0], GLX_RGBA_TYPE, NULL, True);
|
2003-05-20 08:20:13 -04:00
|
|
|
if (context == NULL) {
|
|
|
|
XFree(configs);
|
|
|
|
throwException(env, "Could not create a GLX context");
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-12 02:12:34 -05:00
|
|
|
jboolean allow_software_acceleration = getBooleanProperty(env, "org.lwjgl.opengl.Window.allowSoftwareOpenGL");
|
2004-04-07 03:46:03 -04:00
|
|
|
if (!allow_software_acceleration && (glXIsDirect(getDisplay(), context) == False)) {
|
|
|
|
glXDestroyContext(getDisplay(), context);
|
2003-05-20 08:20:13 -04:00
|
|
|
XFree(configs);
|
2004-02-15 10:27:02 -05:00
|
|
|
throwException(env, "Could not create a direct GLX context");
|
2003-05-20 08:20:13 -04:00
|
|
|
return false;
|
|
|
|
}
|
2004-07-02 15:02:00 -04:00
|
|
|
vis_info = glXGetVisualFromFBConfig(getDisplay(), configs[0]);
|
2003-05-30 02:10:33 -04:00
|
|
|
if (vis_info == NULL) {
|
2004-04-07 03:46:03 -04:00
|
|
|
glXDestroyContext(getDisplay(), context);
|
2003-05-30 02:10:33 -04:00
|
|
|
XFree(configs);
|
2004-07-02 15:02:00 -04:00
|
|
|
throwException(env, "Could not get visual from FB config");
|
2004-05-11 16:34:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (!checkXError(env)) {
|
|
|
|
glXDestroyContext(getDisplay(), context);
|
2004-07-02 15:02:00 -04:00
|
|
|
XFree(configs);
|
2004-05-11 16:34:47 -04:00
|
|
|
return false;
|
|
|
|
}
|
2003-05-20 08:20:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
static bool initWindowGLX(JNIEnv *env, jobject pixel_format) {
|
|
|
|
vis_info = chooseVisualGLX(env, pixel_format);
|
2003-05-20 08:20:13 -04:00
|
|
|
if (vis_info == NULL) {
|
|
|
|
throwException(env, "Could not find a matching pixel format");
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-27 09:09:55 -05:00
|
|
|
if (isDebugEnabled())
|
2004-04-07 03:46:03 -04:00
|
|
|
dumpVisualInfo(vis_info);
|
|
|
|
context = glXCreateContext(getDisplay(), vis_info, NULL, True);
|
2003-05-20 08:20:13 -04:00
|
|
|
if (context == NULL) {
|
|
|
|
XFree(vis_info);
|
|
|
|
throwException(env, "Could not create a GLX context");
|
|
|
|
return false;
|
|
|
|
}
|
2004-03-29 06:26:26 -05:00
|
|
|
jboolean allow_software_acceleration = getBooleanProperty(env, "org.lwjgl.opengl.Window.allowSoftwareOpenGL");
|
2004-04-07 03:46:03 -04:00
|
|
|
if (!allow_software_acceleration && glXIsDirect(getDisplay(), context) == False) {
|
|
|
|
glXDestroyContext(getDisplay(), context);
|
2003-05-20 08:20:13 -04:00
|
|
|
XFree(vis_info);
|
2003-07-15 10:02:39 -04:00
|
|
|
throwException(env, "Could not create a direct GLX context");
|
2003-05-20 08:20:13 -04:00
|
|
|
return false;
|
|
|
|
}
|
2004-05-11 16:34:47 -04:00
|
|
|
if (!checkXError(env)) {
|
|
|
|
glXDestroyContext(getDisplay(), context);
|
|
|
|
return false;
|
|
|
|
}
|
2003-05-20 08:20:13 -04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_Display_nGetAvailableDisplayModes(JNIEnv *env, jclass clazz) {
|
|
|
|
return getAvailableDisplayModes(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) {
|
|
|
|
switchDisplayMode(env, mode);
|
|
|
|
}
|
2003-03-30 14:26:39 -05:00
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_resetDisplayMode(JNIEnv *env, jclass clazz) {
|
|
|
|
resetDisplayMode(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Display_getGammaRampLength(JNIEnv *env, jclass clazz) {
|
|
|
|
return (jint)getGammaRampLength();
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_setGammaRamp(JNIEnv *env, jclass clazz, jobject gamma_buffer) {
|
|
|
|
setGammaRamp(env, gamma_buffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_Display_init(JNIEnv *env, jclass clazz) {
|
|
|
|
return initDisplay(env);
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_Display_getAdapter(JNIEnv *env , jclass clazz) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_Display_getVersion(JNIEnv *env, jclass clazz) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_createContext(JNIEnv *env, jclass clazz, jobject pixel_format) {
|
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;
|
|
|
|
}
|
2004-04-07 03:46:03 -04:00
|
|
|
Display *disp = incDisplay(env);
|
|
|
|
if (disp == NULL)
|
2003-03-30 14:26:39 -05:00
|
|
|
return;
|
2004-07-02 15:02:00 -04:00
|
|
|
current_screen = XDefaultScreen(disp);
|
|
|
|
if (!extgl_InitGLX(env, disp, current_screen)) {
|
2004-04-07 03:46:03 -04:00
|
|
|
decDisplay();
|
2003-03-30 14:26:39 -05:00
|
|
|
extgl_Close();
|
|
|
|
throwException(env, "Could not init GLX");
|
|
|
|
return;
|
|
|
|
}
|
2003-05-20 08:20:13 -04:00
|
|
|
bool create_success;
|
2003-09-26 09:59:50 -04:00
|
|
|
if (USEGLX13) {
|
2004-07-02 15:02:00 -04:00
|
|
|
create_success = initWindowGLX13(env, pixel_format);
|
2003-05-20 08:20:13 -04:00
|
|
|
} else {
|
2004-07-02 15:02:00 -04:00
|
|
|
create_success = initWindowGLX(env, pixel_format);
|
2002-11-15 05:40:55 -05:00
|
|
|
}
|
2003-05-20 08:20:13 -04:00
|
|
|
if (!create_success) {
|
2004-04-07 03:46:03 -04:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_destroyContext(JNIEnv *env, jclass clazz) {
|
|
|
|
destroyContext();
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nCreateWindow(JNIEnv *env, jclass clazz, jobject mode, jboolean fullscreen) {
|
|
|
|
current_fullscreen = fullscreen == JNI_TRUE;
|
|
|
|
jclass cls_displayMode = env->GetObjectClass(mode);
|
|
|
|
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
|
|
|
|
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
|
|
|
|
int width = env->GetIntField(mode, fid_width);
|
|
|
|
int height = env->GetIntField(mode, fid_height);
|
|
|
|
bool window_created = createWindow(env, width, height);
|
|
|
|
if (!window_created) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (isDebugEnabled())
|
|
|
|
dumpVisualInfo(vis_info);
|
|
|
|
if (USEGLX13)
|
|
|
|
glx_window = glXCreateWindow(getDisplay(), configs[0], getCurrentWindow(), NULL);
|
|
|
|
makeCurrent();
|
|
|
|
if (!checkXError(env)) {
|
|
|
|
glXDestroyWindow(getDisplay(), glx_window);
|
|
|
|
destroyWindow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroyWindow(JNIEnv *env, jclass clazz) {
|
|
|
|
destroyWindow();
|
2002-11-15 05:40:55 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2003-07-18 15:02:49 -04:00
|
|
|
* Class: org_lwjgl_opengl_GLWindow
|
2002-11-15 05:40:55 -05:00
|
|
|
* Method: swapBuffers
|
|
|
|
* Signature: ()V
|
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_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)
|
2004-04-07 03:46:03 -04:00
|
|
|
glXSwapBuffers(getDisplay(), glx_window);
|
2003-05-20 08:20:13 -04:00
|
|
|
else
|
2004-04-07 03:46:03 -04:00
|
|
|
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
|
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsDirty
|
2003-08-04 06:09:40 -04:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2004-04-04 10:09:12 -04:00
|
|
|
bool result = dirty;
|
|
|
|
dirty = false;
|
|
|
|
return result ? JNI_TRUE : JNI_FALSE;
|
2003-08-04 06:09:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_opengl_Window
|
2004-04-04 08:53:45 -04:00
|
|
|
* Method: nIsVisible
|
2003-08-04 06:09:40 -04:00
|
|
|
* Signature: ()Z
|
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsVisible
|
2003-08-04 06:09:40 -04:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2004-04-04 08:53:45 -04:00
|
|
|
return minimized ? JNI_FALSE : JNI_TRUE;
|
2003-08-04 06:09:40 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_opengl_Window
|
|
|
|
* Method: nIsCloseRequested
|
|
|
|
* Signature: ()Z
|
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsCloseRequested
|
2003-08-04 06:09:40 -04:00
|
|
|
(JNIEnv *, jclass) {
|
|
|
|
bool saved = closerequested;
|
|
|
|
closerequested = false;
|
|
|
|
return saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Class: org_lwjgl_opengl_Window
|
2004-04-04 08:53:45 -04:00
|
|
|
* Method: nIsActive
|
2003-08-04 06:09:40 -04:00
|
|
|
* Signature: ()Z
|
|
|
|
*/
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Display_nIsActive
|
2003-08-04 06:09:40 -04:00
|
|
|
(JNIEnv *env, jclass clazz) {
|
2004-04-04 08:53:45 -04:00
|
|
|
return focused ? JNI_TRUE : JNI_FALSE;
|
2003-08-04 06:09:40 -04:00
|
|
|
}
|
2003-10-20 10:17:47 -04:00
|
|
|
|
2004-07-02 15:02:00 -04:00
|
|
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetVSyncEnabled
|
2003-10-20 10:17:47 -04:00
|
|
|
(JNIEnv * env, jclass clazz, jboolean sync)
|
|
|
|
{
|
2004-01-03 03:09:17 -05:00
|
|
|
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
|
|
|
|