From d9828de0c4dc45535acb19ce922b15cac210d27a Mon Sep 17 00:00:00 2001 From: Elias Naur Date: Thu, 27 Mar 2003 15:16:35 +0000 Subject: [PATCH] Various linux fixes --- src/native/common/extgl.c | 6 +- src/native/config.h.in | 3 - src/native/configure.in | 6 +- src/native/linux/org_lwjgl_Display.cpp | 126 +++--------------- src/native/linux/org_lwjgl_input_Keyboard.cpp | 5 - src/native/linux/org_lwjgl_opengl_BaseGL.cpp | 16 ++- 6 files changed, 34 insertions(+), 128 deletions(-) diff --git a/src/native/common/extgl.c b/src/native/common/extgl.c index fa9cf36d..40039f15 100644 --- a/src/native/common/extgl.c +++ b/src/native/common/extgl.c @@ -2484,13 +2484,11 @@ int extgl_InitGLX12(void) return extgl_error; } -#ifdef _X11 void extgl_InitGLXSupportedExtensions(Display *disp, int screen) { extgl_Extensions.glx.EXT_visual_info = GLXQueryExtension(disp, screen, "GLX_EXT_visual_info"); extgl_Extensions.glx.EXT_visual_rating = GLXQueryExtension(disp, screen, "GLX_EXT_visual_rating"); } -#endif int extgl_InitGLX(Display *disp, int screen) { @@ -3239,11 +3237,11 @@ int extgl_Initialize() #ifdef _X11 int extgl_Open(Display *disp, int screen) { - lib_gl_handle = dlopen("libGL.so.1", RTLD_LAZY | RTLD_GLOBAL); + lib_gl_handle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL); if (lib_gl_handle == NULL) return 1; - lib_glu_handle = dlopen("libGLU.so", RTLD_LAZY | RTLD_GLOBAL); + lib_glu_handle = dlopen("libGLU.so", RTLD_NOW | RTLD_GLOBAL); if (lib_glu_handle == NULL) return 1; if (extgl_InitGLX(disp, screen) != 0) diff --git a/src/native/config.h.in b/src/native/config.h.in index 62f464af..c9d7b202 100644 --- a/src/native/config.h.in +++ b/src/native/config.h.in @@ -6,9 +6,6 @@ /* Define to 1 if you have the header file. */ #undef HAVE_INTTYPES_H -/* Define to 1 if you have the `openal' library (-lopenal). */ -#undef HAVE_LIBOPENAL - /* Define to 1 if you have the `X11' library (-lX11). */ #undef HAVE_LIBX11 diff --git a/src/native/configure.in b/src/native/configure.in index acfebc3a..5a64e8df 100644 --- a/src/native/configure.in +++ b/src/native/configure.in @@ -51,8 +51,8 @@ if test "x$JAVA_HOME" = x; then else AC_MSG_RESULT($JAVA_HOME) JAVA_HOME="$JAVA_HOME" - CPPFLAGS="$CPPFLAGS -D_X11 -I$JAVA_HOME/include -I$JAVA_HOME/include/linux" - CFLAGS="$CFLAGS -D_X11 -I$JAVA_HOME/include -I$JAVA_HOME/include/linux" + CPPFLAGS="$CPPFLAGS -D_DEBUG -D_X11 -Wall -I$JAVA_HOME/include -I$JAVA_HOME/include/linux" + CFLAGS="$CFLAGS -D_DEBUG -D_X11 -Wall -I$JAVA_HOME/include -I$JAVA_HOME/include/linux" fi dnl Checks for libraries. @@ -64,8 +64,6 @@ dnl Replace `main' with a function in -lXext: AC_CHECK_LIB(Xext, main,, AC_MSG_ERROR(Xext is required)) dnl Replace `main' with a function in -lXxf86vm: AC_CHECK_LIB(Xxf86vm, main,, AC_MSG_ERROR(Xxf86vm is required)) -dnl Replace `main' with a function in -lopenal: -AC_CHECK_LIB(openal, main,, AC_MSG_ERROR(openal is required)) dnl Checks for header files. diff --git a/src/native/linux/org_lwjgl_Display.cpp b/src/native/linux/org_lwjgl_Display.cpp index 435b2f40..dfb3eccf 100644 --- a/src/native/linux/org_lwjgl_Display.cpp +++ b/src/native/linux/org_lwjgl_Display.cpp @@ -64,7 +64,6 @@ static int win_height; static XF86VidModeModeInfo **avail_modes; static XVisualInfo * vis_info; static Atom delete_atom; -static bool gl_loaded = false; static jclass saved_clazz; extern void handlePointerMotion(XMotionEvent *); @@ -83,70 +82,6 @@ struct pixelformat { int stencil; }; -/*static int fillFormat(struct pixelformat *formats, int index, int bpp, int depth, int alpha, int stencil) { - for (int i = 0; i < index; i++) - if (formats[i].bpp == bpp && - formats[i].depth == depth && - formats[i].alpha == alpha && - formats[i].stencil == stencil) - return 0; - formats[index].bpp = bpp; - formats[index].depth = depth; - formats[index].stencil = stencil; - formats[index].alpha = alpha; - return 1; -} - -static struct pixelformat *getGLXAvailablePixelFormats(Display *disp, int screen, int *length) { - if (extgl_Extensions.glx.GLX13 == 1) { - int num_formats; - int attriblist[] = {GLX_DOUBLEBUFFER, True, - GLX_STEREO, False, - GLX_RENDER_TYPE, GLX_RGBA_BIT, - GLX_DRAWABLE_TYPE, GLX_WINDOW_BIT, - GLX_CONFIG_CAVEAT, GLX_NONE, - None}; - GLXFBConfig *configs = glXChooseFBConfig(disp, screen, attriblist, &num_formats); - struct pixelformat *formats = (struct pixelformat *)malloc(num_formats*sizeof(struct pixelformat)); - *length = 0; - for (int i = 0; i < num_formats; i++) { - int bpp, depth, alpha, stencil; - int val; - if (glXGetFBConfigAttrib(disp, configs[i], GLX_RED_SIZE, &val) != 0) { - ree(formats); - return NULL; - } - bpp = val; - if (glXGetFBConfigAttrib(disp, configs[i], GLX_GREEN_SIZE, &val) != 0) { - free(formats); - return NULL; - } - bpp += val; - if (glXGetFBConfigAttrib(disp, configs[i], GLX_BLUE_SIZE, &val) != 0) { - free(formats); - return NULL; - } - bpp += val; - if (glXGetFBConfigAttrib(disp, configs[i], GLX_ALPHA_SIZE, &alpha) != 0) { - free(formats); - return NULL; - } - if (glXGetFBConfigAttrib(disp, configs[i], GLX_DEPTH_SIZE, &depth) != 0) { - free(formats); - return NULL; - } - if (glXGetFBConfigAttrib(disp, configs[i], GLX_STENCIL_SIZE, &stencil) != 0) { - free(formats); - return NULL; - } - if (fillFormat(formats, *length, bpp, depth, alpha, stencil) == 1) - (*length)++; - } - return formats; - } - return NULL; -} -*/ static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, int alpha, int stencil) { int bpe; switch (bpp) { @@ -173,27 +108,16 @@ static XVisualInfo *chooseVisual(Display *disp, int screen, int bpp, int depth, return glXChooseVisual(disp, screen, attriblist); } -/*static struct pixelformat *getAvailablePixelFormats(Display *disp, int screen, int *length) { - struct pixelformat *formats = getGLXAvailablePixelFormats(disp, screen, length); - if (formats != NULL) - return formats; - *length = 16; - formats = (struct pixelformat *)malloc((*length)*sizeof(struct pixelformat)); - *length = 0; - for (int bpp = 16; bpp <= 24; bpp += 8) - for (int depth = 16; depth <= 24; depth += 8) - for (int alpha = 0; alpha <= 8; alpha += 8) - for (int stencil = 0; stencil <= 8; stencil += 8) { - XVisualInfo * visual = chooseVisual(disp, screen, bpp, depth, alpha, stencil); - if (visual != NULL) { - if (fillFormat(formats, *length, bpp, depth, alpha, stencil) == 1) - (*length)++; - XFree(visual); - } - } - return formats; +static void dumpVisualInfo(Display *disp, XVisualInfo *vis_info) { + int alpha, depth, stencil, r, g, b; + glXGetConfig(disp, vis_info, GLX_RED_SIZE, &r); + glXGetConfig(disp, vis_info, GLX_GREEN_SIZE, &g); + glXGetConfig(disp, vis_info, GLX_BLUE_SIZE, &b); + glXGetConfig(disp, vis_info, GLX_ALPHA_SIZE, &alpha); + glXGetConfig(disp, vis_info, GLX_DEPTH_SIZE, &depth); + glXGetConfig(disp, vis_info, GLX_STENCIL_SIZE, &stencil); + printf("Pixel format chosen sizes: r = %d, g = %d, b = %d, a = %d, depth = %d, stencil = %d\n", r, g, b, alpha, depth, stencil); } -*/ static void waitMapped(Display *disp, Window win) { XEvent event; @@ -234,7 +158,7 @@ void handleMessages(JNIEnv *env) { XNextEvent(disp, &event); switch (event.type) { case ClientMessage: - if ((event.xclient.format == 32) && (event.xclient.data.l[0] == delete_atom)) + if ((event.xclient.format == 32) && ((Atom)event.xclient.data.l[0] == delete_atom)) env->SetStaticBooleanField(saved_clazz, fid_close, JNI_TRUE); break; case FocusIn: @@ -264,20 +188,16 @@ void handleMessages(JNIEnv *env) { } static bool loadGL(Display *disp, int screen) { - if (gl_loaded == true) - return true; if (extgl_Open(disp, screen) != 0) { #ifdef _DEBUG printf("Could not load gl libs\n"); #endif return false; } - gl_loaded = true; return true; } static void closeGL(void) { - gl_loaded = false; extgl_Close(); } @@ -373,6 +293,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c } root_win = RootWindow(disp, screen); vis_info = chooseVisual(disp, screen, bpp, depth_bits, alpha_bits, stencil_bits); + XSync(disp, False); if (vis_info == NULL) { XCloseDisplay(disp); #ifdef _DEBUG @@ -380,7 +301,9 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c #endif return JNI_FALSE; } - +#ifdef _DEBUG + dumpVisualInfo(disp, vis_info); +#endif cmap = XCreateColormap(disp, root_win, vis_info->visual, AllocNone); attribs.colormap = cmap; attribs.event_mask = FocusChangeMask | VisibilityChangeMask| StructureNotifyMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask | PointerMotionMask; @@ -391,6 +314,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c attribs.override_redirect = True; } win = XCreateWindow(disp, root_win, 0, 0, width, height, 0, vis_info->depth, InputOutput, vis_info->visual, attribmask, &attribs); + XFreeColormap(disp, cmap); #ifdef _DEBUG printf("Created window\n"); #endif @@ -425,6 +349,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_Display_nCreate(JNIEnv * env, jclass c #endif return JNI_FALSE; } + break; } } XF86VidModeSetViewPort(disp, screen, 0, 0); @@ -446,8 +371,11 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Display_nDestroy(JNIEnv * env, jclass claz } } XFree(avail_modes); + avail_modes = NULL; XFree(vis_info); + vis_info = NULL; XCloseDisplay(disp); + disp = NULL; closeGL(); #ifdef _DEBUG printf("Closed X connection\n"); @@ -479,13 +407,6 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes screen = DefaultScreen(disp); int bpp = XDefaultDepth(disp, screen); - if (!loadGL(disp, screen)) { -#ifdef _DEBUG - printf("Could not load GL\n"); -#endif - XCloseDisplay(disp); - return NULL; - } if (!getDisplayModes(disp, screen, &num_modes, &avail_modes)) { #ifdef _DEBUG printf("Could not get display modes\n"); @@ -493,22 +414,15 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_Display_nGetAvailableDisplayModes XCloseDisplay(disp); return NULL; } - int num_pixelformats; -// struct pixelformat *formats = getAvailablePixelFormats(disp, screen, &num_pixelformats); // Allocate an array of DisplayModes big enough jclass displayModeClass = env->FindClass("org/lwjgl/DisplayMode"); - jobjectArray ret = env->NewObjectArray(num_modes/**num_pixelformats*/, displayModeClass, NULL); + jobjectArray ret = env->NewObjectArray(num_modes, displayModeClass, NULL); jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "", "(IIII)V"); for (i = 0; i < num_modes; i++) { -/* for (int j = 0; j < num_pixelformats; j++) { - jobject displayMode = env->NewObject(displayModeClass, displayModeConstructor, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay, formats[j].bpp, 0, formats[j].alpha, formats[j].depth, formats[j].stencil); - env->SetObjectArrayElement(ret, i*num_pixelformats + j, displayMode); - }*/ jobject displayMode = env->NewObject(displayModeClass, displayModeConstructor, avail_modes[i]->hdisplay, avail_modes[i]->vdisplay, bpp, 0); env->SetObjectArrayElement(ret, i, displayMode); } -// free(formats); XFree(avail_modes); XCloseDisplay(disp); return ret; diff --git a/src/native/linux/org_lwjgl_input_Keyboard.cpp b/src/native/linux/org_lwjgl_input_Keyboard.cpp index 2844f186..67d564d5 100644 --- a/src/native/linux/org_lwjgl_input_Keyboard.cpp +++ b/src/native/linux/org_lwjgl_input_Keyboard.cpp @@ -257,9 +257,6 @@ void handleKeyEvent(XKeyEvent *event) { JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll (JNIEnv * env, jclass clazz, jint buf) { - XEvent event; - unsigned char state; - handleMessages(env); updateGrab(); memcpy((unsigned char*)buf, key_buf, KEYBOARD_SIZE*sizeof(unsigned char)); @@ -273,10 +270,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nPoll JNIEXPORT int JNICALL Java_org_lwjgl_input_Keyboard_nRead (JNIEnv * env, jclass clazz) { - XEvent event; XKeyEvent *key_event; int buf_count = 0; - int state; int num_events = 0; handleMessages(env); diff --git a/src/native/linux/org_lwjgl_opengl_BaseGL.cpp b/src/native/linux/org_lwjgl_opengl_BaseGL.cpp index fbccefa6..b7ef1ac9 100644 --- a/src/native/linux/org_lwjgl_opengl_BaseGL.cpp +++ b/src/native/linux/org_lwjgl_opengl_BaseGL.cpp @@ -65,15 +65,20 @@ static void releaseContext(void) { JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_BaseGL_nCreate (JNIEnv * env, jobject obj) { - - if (!getVisualInfo()) { + if (disp == NULL) { +#ifdef _DEBUG + printf("No display\n"); +#endif + return JNI_FALSE; + } + if (getVisualInfo() == NULL) { #ifdef _DEBUG printf("No visual info\n"); #endif return JNI_FALSE; } context = glXCreateContext(disp, getVisualInfo(), NULL, True); - if (!context) { + if (context == NULL) { #ifdef _DEBUG printf("Could not create context\n"); #endif @@ -103,9 +108,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_BaseGL_nDestroy (JNIEnv * env, jobject obj) { releaseContext(); - // Delete the rendering context - if (context != NULL) - glXDestroyContext(disp, context); + glXDestroyContext(disp, context); + context = NULL; } /*