From f661aaa22b3af6571b99dad67cf0f30cde5c5f6f Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Tue, 6 Jul 2004 08:06:16 +0000 Subject: [PATCH] Undo GLContext.cpp split --- src/native/common/Makefile.am | 1 + .../org_lwjgl_opengl_GLContext.cpp | 1 - src/native/linux/Makefile.am | 1 - src/native/linux/org_lwjgl_opengl_Display.cpp | 74 ++++++++++ .../linux/org_lwjgl_opengl_GLContext.cpp | 131 ------------------ src/native/linux/org_lwjgl_opengl_Pbuffer.cpp | 13 +- .../win32/org_lwjgl_opengl_GLContext.cpp | 50 ------- 7 files changed, 87 insertions(+), 184 deletions(-) rename src/native/{macosx => common}/org_lwjgl_opengl_GLContext.cpp (98%) delete mode 100644 src/native/linux/org_lwjgl_opengl_GLContext.cpp delete mode 100644 src/native/win32/org_lwjgl_opengl_GLContext.cpp diff --git a/src/native/common/Makefile.am b/src/native/common/Makefile.am index 3465a4f0..6de1fe5c 100644 --- a/src/native/common/Makefile.am +++ b/src/native/common/Makefile.am @@ -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 \ diff --git a/src/native/macosx/org_lwjgl_opengl_GLContext.cpp b/src/native/common/org_lwjgl_opengl_GLContext.cpp similarity index 98% rename from src/native/macosx/org_lwjgl_opengl_GLContext.cpp rename to src/native/common/org_lwjgl_opengl_GLContext.cpp index 1a383620..990fbb80 100644 --- a/src/native/macosx/org_lwjgl_opengl_GLContext.cpp +++ b/src/native/common/org_lwjgl_opengl_GLContext.cpp @@ -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()) { diff --git a/src/native/linux/Makefile.am b/src/native/linux/Makefile.am index 9bc793d3..284ff00d 100644 --- a/src/native/linux/Makefile.am +++ b/src/native/linux/Makefile.am @@ -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 diff --git a/src/native/linux/org_lwjgl_opengl_Display.cpp b/src/native/linux/org_lwjgl_opengl_Display.cpp index a60bda30..048a4cf1 100644 --- a/src/native/linux/org_lwjgl_opengl_Display.cpp +++ b/src/native/linux/org_lwjgl_opengl_Display.cpp @@ -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) { diff --git a/src/native/linux/org_lwjgl_opengl_GLContext.cpp b/src/native/linux/org_lwjgl_opengl_GLContext.cpp deleted file mode 100644 index 4ef30e8c..00000000 --- a/src/native/linux/org_lwjgl_opengl_GLContext.cpp +++ /dev/null @@ -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 -#include -#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); -} diff --git a/src/native/linux/org_lwjgl_opengl_Pbuffer.cpp b/src/native/linux/org_lwjgl_opengl_Pbuffer.cpp index f3dfa2e7..a42a2dfa 100644 --- a/src/native/linux/org_lwjgl_opengl_Pbuffer.cpp +++ b/src/native/linux/org_lwjgl_opengl_Pbuffer.cpp @@ -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); diff --git a/src/native/win32/org_lwjgl_opengl_GLContext.cpp b/src/native/win32/org_lwjgl_opengl_GLContext.cpp deleted file mode 100644 index 1a383620..00000000 --- a/src/native/win32/org_lwjgl_opengl_GLContext.cpp +++ /dev/null @@ -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); -}