From: <eli...@us...> - 2006-10-11 13:49:06
|
Revision: 2582 http://svn.sourceforge.net/java-game-lib/?rev=2582&view=rev Author: elias_naur Date: 2006-10-11 06:48:48 -0700 (Wed, 11 Oct 2006) Log Message: ----------- Windows: Don't use a dummy window (HDC) when finding a pixel format but use the actual window directly. This will avoid cases where the pixel format index for the dummy window's HDC wasn't valid for the actual window's HDC. It also avoid unnecessary complexity. Fix FullScreenWindowedTest to use the Display's current BPP to avoid 24/16 bpp weirdness Modified Paths: -------------- trunk/LWJGL/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java trunk/LWJGL/src/native/windows/context.c trunk/LWJGL/src/native/windows/context.h trunk/LWJGL/src/native/windows/display.c trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Pbuffer.c trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c Modified: trunk/LWJGL/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java =================================================================== --- trunk/LWJGL/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java 2006-10-11 11:21:40 UTC (rev 2581) +++ trunk/LWJGL/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java 2006-10-11 13:48:48 UTC (rev 2582) @@ -80,7 +80,7 @@ private void initialize() { try { //find displaymode - mode = findDisplayMode(800, 600, 16); + mode = findDisplayMode(800, 600, Display.getDisplayMode().getBitsPerPixel()); // start of in windowed mode Display.create(); glInit(); Modified: trunk/LWJGL/src/native/windows/context.c =================================================================== --- trunk/LWJGL/src/native/windows/context.c 2006-10-11 11:21:40 UTC (rev 2581) +++ trunk/LWJGL/src/native/windows/context.c 2006-10-11 13:48:48 UTC (rev 2582) @@ -370,68 +370,76 @@ return findPixelFormatFromBPP(env, hdc, pixel_format, bpp, double_buffer); } -static int findPixelFormatOnDC(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer, bool floating_point) { +static bool validateAndGetExtensions(JNIEnv *env, WGLExtensions *extensions, HDC dummy_hdc, HGLRC dummy_hglrc, int samples, bool floating_point, jobject pixelFormatCaps) { + if (!wglMakeCurrent(dummy_hdc, dummy_hglrc)) { + throwException(env, "Could not bind context to dummy window"); + return false; + } + extgl_InitWGL(extensions); + + if (!extensions->WGL_ARB_pixel_format) { + throwException(env, "No support for WGL_ARB_pixel_format"); + return false; + } + if (samples > 0 && !extensions->WGL_ARB_multisample) { + throwException(env, "No support for WGL_ARB_multisample"); + return false; + } + /* + * Apparently, some drivers don't report WGL_ARB_pixel_format_float + * even though GL_ARB_color_buffer_float and WGL_ATI_color_format_float + * is supported. + */ + if (floating_point && !(extensions->WGL_ARB_pixel_format_float || extensions->WGL_ATI_pixel_format_float)) { + throwException(env, "No support for WGL_ARB_pixel_format_float nor WGL_ATI_pixel_format_float"); + return false; + } + if (pixelFormatCaps != NULL && !extensions->WGL_ARB_render_texture) { + throwException(env, "No support for WGL_ARB_render_texture"); + return false; + } + return true; +} + +int findPixelFormatOnDC(JNIEnv *env, HDC hdc, int origin_x, int origin_y, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer, bool floating_point) { HGLRC dummy_hglrc; HDC saved_current_hdc; HGLRC saved_current_hglrc; WGLExtensions extensions; + HWND dummy_hwnd; + HDC dummy_hdc; int pixel_format_id; jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format); int samples = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "samples", "I")); bool use_arb_selection = samples > 0 || floating_point || pbuffer || pixelFormatCaps != NULL; pixel_format_id = findPixelFormatDefault(env, hdc, pixel_format, use_hdc_bpp, double_buffer); if (pixel_format_id != -1 && use_arb_selection) { - if (!applyPixelFormat(env, hdc, pixel_format_id)) { + dummy_hwnd = createDummyWindow(origin_x, origin_y); + if (dummy_hwnd == NULL) { + throwException(env, "Could not create dummy window"); return -1; } - dummy_hglrc = wglCreateContext(hdc); + dummy_hdc = GetDC(dummy_hwnd); + if (!applyPixelFormat(env, dummy_hdc, pixel_format_id)) { + closeWindow(&dummy_hwnd, &dummy_hdc); + return -1; + } + dummy_hglrc = wglCreateContext(dummy_hdc); if (dummy_hglrc == NULL) { + closeWindow(&dummy_hwnd, &dummy_hdc); throwException(env, "Failed to create OpenGL rendering context"); return -1; } // Save the current HDC and HGLRC to avoid disruption saved_current_hdc = wglGetCurrentDC(); saved_current_hglrc = wglGetCurrentContext(); - if (!wglMakeCurrent(hdc, dummy_hglrc)) { - wglMakeCurrent(saved_current_hdc, saved_current_hglrc); - wglDeleteContext(dummy_hglrc); - throwException(env, "Could not bind context to dummy window"); - return -1; - } - extgl_InitWGL(&extensions); - - if (!extensions.WGL_ARB_pixel_format) { - wglMakeCurrent(saved_current_hdc, saved_current_hglrc); - wglDeleteContext(dummy_hglrc); - throwException(env, "No support for WGL_ARB_pixel_format"); - return -1; - } - if (samples > 0 && !extensions.WGL_ARB_multisample) { - wglMakeCurrent(saved_current_hdc, saved_current_hglrc); - wglDeleteContext(dummy_hglrc); - throwException(env, "No support for WGL_ARB_multisample"); - return -1; - } - /* - * Apparently, some drivers don't report WGL_ARB_pixel_format_float - * even though GL_ARB_color_buffer_float and WGL_ATI_color_format_float - * is supported. - */ - if (floating_point && !(extensions.WGL_ARB_pixel_format_float || extensions.WGL_ATI_pixel_format_float)) { - wglMakeCurrent(saved_current_hdc, saved_current_hglrc); - wglDeleteContext(dummy_hglrc); - throwException(env, "No support for WGL_ARB_pixel_format_float nor WGL_ATI_pixel_format_float"); - return -1; - } - if (pixelFormatCaps != NULL && !extensions.WGL_ARB_render_texture) { - wglMakeCurrent(saved_current_hdc, saved_current_hglrc); - wglDeleteContext(dummy_hglrc); - throwException(env, "No support for WGL_ARB_render_texture"); - return -1; - } - pixel_format_id = findPixelFormatARB(env, hdc, &extensions, pixel_format, pixelFormatCaps, use_hdc_bpp, window, pbuffer, double_buffer, floating_point); + if (validateAndGetExtensions(env, &extensions, dummy_hdc, dummy_hglrc, samples, floating_point, pixelFormatCaps)) { + pixel_format_id = findPixelFormatARB(env, hdc, &extensions, pixel_format, pixelFormatCaps, use_hdc_bpp, window, pbuffer, double_buffer, floating_point); + } else + pixel_format_id = -1; wglMakeCurrent(saved_current_hdc, saved_current_hglrc); wglDeleteContext(dummy_hglrc); + closeWindow(&dummy_hwnd, &dummy_hdc); } if (pixel_format_id == -1) { throwException(env, "Could not find a valid pixel format"); @@ -455,18 +463,3 @@ return NULL; return createWindow(_CONTEXT_PRIVATE_CLASS_NAME, origin_x, origin_y, 1, 1, false, false); } - -int findPixelFormat(JNIEnv *env, int origin_x, int origin_y, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer, bool floating_point) { - HWND dummy_hwnd; - HDC dummy_hdc; - int pixel_format_id; - dummy_hwnd = createDummyWindow(origin_x, origin_y); - if (dummy_hwnd == NULL) { - throwException(env, "Failed to create the dummy window."); - return -1; - } - dummy_hdc = GetDC(dummy_hwnd); - pixel_format_id = findPixelFormatOnDC(env, dummy_hdc, pixel_format, pixelFormatCaps, use_hdc_bpp, window, pbuffer, double_buffer, floating_point); - closeWindow(&dummy_hwnd, &dummy_hdc); - return pixel_format_id; -} Modified: trunk/LWJGL/src/native/windows/context.h =================================================================== --- trunk/LWJGL/src/native/windows/context.h 2006-10-11 11:21:40 UTC (rev 2581) +++ trunk/LWJGL/src/native/windows/context.h 2006-10-11 13:48:48 UTC (rev 2582) @@ -88,6 +88,6 @@ */ extern HWND createWindow(LPCTSTR window_class_name, int x, int y, int width, int height, bool fullscreen, bool undecorated); -extern int findPixelFormat(JNIEnv *env, int origin_x, int origin_y, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer, bool floating_point); +extern int findPixelFormatOnDC(JNIEnv *env, HDC hdc, int origin_x, int origin_y, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer, bool floating_point); #endif Modified: trunk/LWJGL/src/native/windows/display.c =================================================================== --- trunk/LWJGL/src/native/windows/display.c 2006-10-11 11:21:40 UTC (rev 2581) +++ trunk/LWJGL/src/native/windows/display.c 2006-10-11 13:48:48 UTC (rev 2582) @@ -40,10 +40,6 @@ */ #include <windows.h> -// Multimon.h enables multi monitor emulation on win95 and winnt4 -// So we only need the extended, multi-monitor aware path -//#define COMPILE_MULTIMON_STUBS -//#include <Multimon.h> #include <jni.h> #include "org_lwjgl_opengl_WindowsDisplay.h" #include "display.h" Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Pbuffer.c =================================================================== --- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Pbuffer.c 2006-10-11 11:21:40 UTC (rev 2581) +++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_Pbuffer.c 2006-10-11 13:48:48 UTC (rev 2582) @@ -62,15 +62,17 @@ HGLRC saved_context; int pixel_format_id; - pixel_format_id = findPixelFormat(env, origin_x, origin_y, pixel_format, pixelFormatCaps, false, true, false, false, false); - if (pixel_format_id == -1) - return false; dummy_hwnd = createDummyWindow(origin_x, origin_y); if (dummy_hwnd == NULL) { throwException(env, "Could not create dummy window"); return false; } dummy_hdc = GetDC(dummy_hwnd); + pixel_format_id = findPixelFormatOnDC(env, dummy_hdc, origin_x, origin_y, pixel_format, pixelFormatCaps, false, true, false, false, false); + if (pixel_format_id == -1) { + closeWindow(&dummy_hwnd, &dummy_hdc); + return false; + } if (!applyPixelFormat(env, dummy_hdc, pixel_format_id)) { closeWindow(&dummy_hwnd, &dummy_hdc); return false; @@ -142,9 +144,6 @@ } else { pBufferAttribs_ptr = NULL; } - pixel_format_id = findPixelFormat(env, origin_x, origin_y, pixel_format, pixelFormatCaps, false, false, true, false, floating_point); - if (pixel_format_id == -1) - return; if (!getExtensions(env, &extensions, pixel_format, pixelFormatCaps)) return; dummy_hwnd = createDummyWindow(origin_x, origin_y); @@ -153,6 +152,11 @@ return; } dummy_hdc = GetDC(dummy_hwnd); + pixel_format_id = findPixelFormatOnDC(env, dummy_hdc, origin_x, origin_y, pixel_format, pixelFormatCaps, false, false, true, false, floating_point); + if (pixel_format_id == -1) { + closeWindow(&dummy_hwnd, &dummy_hdc); + return; + } Pbuffer = extensions.wglCreatePbufferARB(dummy_hdc, pixel_format_id, width, height, pBufferAttribs_ptr); closeWindow(&dummy_hwnd, &dummy_hdc); if (Pbuffer == NULL) { Modified: trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c =================================================================== --- trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c 2006-10-11 11:21:40 UTC (rev 2581) +++ trunk/LWJGL/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c 2006-10-11 13:48:48 UTC (rev 2582) @@ -52,7 +52,7 @@ WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format); bool floating_point = (bool)(*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "floating_point", "Z")); - int pixel_format_id = findPixelFormat(env, origin_x, origin_y, pixel_format, pixel_format_caps, use_hdc_bpp, window, pbuffer, double_buffer, floating_point); + int pixel_format_id = findPixelFormatOnDC(env, peer_info->drawable_hdc, origin_x, origin_y, pixel_format, pixel_format_caps, use_hdc_bpp, window, pbuffer, double_buffer, floating_point); if (pixel_format_id == -1) return; // Let it throw This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |