Undo GLContext.cpp split

This commit is contained in:
Elias Naur 2004-07-06 08:06:16 +00:00
parent 19b7f16291
commit f661aaa22b
7 changed files with 87 additions and 184 deletions

View File

@ -37,6 +37,7 @@ COMMON = \
org_lwjgl_openal_eax_EAXBufferProperties.h \
org_lwjgl_openal_eax_EAXListenerProperties.cpp \
org_lwjgl_openal_eax_EAXListenerProperties.h \
org_lwjgl_opengl_GLContext.cpp \
org_lwjgl_opengl_GL11.cpp \
org_lwjgl_opengl_GL11.h \
org_lwjgl_opengl_GL12.cpp \

View File

@ -32,7 +32,6 @@
#include "org_lwjgl_opengl_GLContext.h"
#include "extgl.h"
#include "common_tools.h"
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLContext_nLoadOpenGLLibrary(JNIEnv * env, jclass clazz) {
if (!extgl_Open()) {

View File

@ -11,7 +11,6 @@ NATIVE = \
org_lwjgl_input_Cursor.cpp \
org_lwjgl_opengl_Display.cpp \
org_lwjgl_opengl_Pbuffer.cpp \
org_lwjgl_opengl_GLContext.cpp \
display.cpp \
extgl_glx.cpp \
extxcursor.cpp

View File

@ -55,6 +55,7 @@
#include "org_lwjgl_opengl_Display.h"
#define USEGLX13 extgl_Extensions.GLX13
#define ERR_MSG_SIZE 1024
static GLXContext context = NULL; // OpenGL rendering context
static GLXWindow glx_window;
@ -78,6 +79,67 @@ static bool closerequested;
static bool grab;
static bool ignore_motion_events;
static int current_screen;
static Display *display_connection = NULL;
static int display_connection_usage = 0;
static bool async_x_error;
static char error_message[ERR_MSG_SIZE];
static Atom warp_atom;
Atom getWarpAtom(void) {
return warp_atom;
}
int getCurrentScreen(void) {
return current_screen;
}
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;
}
Display *getDisplay(void) {
return display_connection;
}
Display *incDisplay(JNIEnv *env) {
if (display_connection_usage == 0) {
async_x_error = false;
XSetErrorHandler(errorHandler);
display_connection = XOpenDisplay(NULL);
if (display_connection == NULL) {
throwException(env, "Could not open X display");
return NULL;
}
warp_atom = XInternAtom(getDisplay(), "ignore_warp_atom", False);
}
display_connection_usage++;
return display_connection;
}
void decDisplay(void) {
display_connection_usage--;
if (display_connection_usage == 0)
XCloseDisplay(display_connection);
}
static void waitMapped(Window win) {
XEvent event;
@ -555,6 +617,17 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_opengl_Display_getVersion(JNIEnv *env,
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_createContext(JNIEnv *env, jclass clazz, jobject pixel_format) {
Display *disp = incDisplay(env);
if (disp == NULL) {
return;
}
current_screen = XDefaultScreen(disp);
if (!extgl_InitGLX(env, disp, current_screen)) {
decDisplay();
throwException(env, "Could not init GLX");
return;
}
if (USEGLX13) {
initWindowGLX13(env, pixel_format);
} else {
@ -564,6 +637,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_createContext(JNIEnv *env,
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_destroyContext(JNIEnv *env, jclass clazz) {
destroyContext();
decDisplay();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nCreateWindow(JNIEnv *env, jclass clazz, jobject mode, jboolean fullscreen) {

View File

@ -1,131 +0,0 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* 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.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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
* 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
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <X11/X.h>
#include <X11/Xlib.h>
#include "org_lwjgl_opengl_GLContext.h"
#include "extgl.h"
#include "extgl_glx.h"
#include "common_tools.h"
#include "Window.h"
#define ERR_MSG_SIZE 1024
static int current_screen;
static Display *display_connection = NULL;
static int display_connection_usage = 0;
static bool async_x_error;
static char error_message[ERR_MSG_SIZE];
static Atom warp_atom;
Atom getWarpAtom(void) {
return warp_atom;
}
int getCurrentScreen(void) {
return current_screen;
}
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;
}
Display *getDisplay(void) {
return display_connection;
}
Display *incDisplay(JNIEnv *env) {
if (display_connection_usage == 0) {
async_x_error = false;
XSetErrorHandler(errorHandler);
display_connection = XOpenDisplay(NULL);
if (display_connection == NULL) {
throwException(env, "Could not open X display");
return NULL;
}
warp_atom = XInternAtom(getDisplay(), "ignore_warp_atom", False);
}
display_connection_usage++;
return display_connection;
}
void decDisplay(void) {
display_connection_usage--;
if (display_connection_usage == 0)
XCloseDisplay(display_connection);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLContext_nLoadOpenGLLibrary(JNIEnv * env, jclass clazz) {
if (!extgl_Open()) {
throwException(env, "Failed to load OpenGL library");
return;
}
Display *disp = incDisplay(env);
if (disp == NULL) {
extgl_Close();
return;
}
current_screen = XDefaultScreen(disp);
if (!extgl_InitGLX(env, disp, current_screen)) {
decDisplay();
extgl_Close();
throwException(env, "Could not init GLX");
return;
}
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLContext_nUnloadOpenGLLibrary(JNIEnv * env, jclass clazz) {
decDisplay();
extgl_Close();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLContext_resetNativeStubs(JNIEnv *env, jclass clazz, jclass gl_class) {
env->UnregisterNatives(gl_class);
}

View File

@ -70,12 +70,23 @@ static void destroyPbuffer(PbufferInfo *buffer_info) {
glXDestroyPbuffer(getDisplay(), buffer);
glXDestroyContext(getDisplay(), context);
free(buffer_info);
decDisplay();
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate(JNIEnv *env, jclass clazz, jint width, jint height, jobject pixel_format,
jobject pixelFormatCaps, jobject pBufferAttribs)
{
Display *disp = getDisplay();
Display *disp = incDisplay(env);
if (disp == NULL) {
return -1;
}
int current_screen = XDefaultScreen(disp);
if (!extgl_InitGLX(env, disp, current_screen)) {
decDisplay();
throwException(env, "Could not init GLX");
return -1;
}
GLXFBConfig *configs = chooseVisualGLX13(env, pixel_format, false, GLX_PBUFFER_BIT, false);
if (configs == 0) {
XFree(configs);

View File

@ -1,50 +0,0 @@
/*
* Copyright (c) 2002-2004 LWJGL Project
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* 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.
*
* * Neither the name of 'LWJGL' nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* 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
* 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
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "org_lwjgl_opengl_GLContext.h"
#include "extgl.h"
#include "common_tools.h"
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLContext_nLoadOpenGLLibrary(JNIEnv * env, jclass clazz) {
if (!extgl_Open()) {
throwException(env, "Failed to load OpenGL library");
return;
}
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLContext_nUnloadOpenGLLibrary(JNIEnv * env, jclass clazz) {
extgl_Close();
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_GLContext_resetNativeStubs(JNIEnv *env, jclass clazz, jclass gl_class) {
env->UnregisterNatives(gl_class);
}