diff --git a/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java b/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java index aaefc363..8af0a4a8 100644 --- a/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java +++ b/src/java/org/lwjgl/test/opengl/FullScreenWindowedTest.java @@ -80,7 +80,7 @@ public class FullScreenWindowedTest { 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(); diff --git a/src/native/windows/context.c b/src/native/windows/context.c index 10cde331..8322028f 100644 --- a/src/native/windows/context.c +++ b/src/native/windows/context.c @@ -370,68 +370,76 @@ static int findPixelFormatDefault(JNIEnv *env, HDC hdc, jobject pixel_format, bo 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 @@ HWND createDummyWindow(int origin_x, int origin_y) { 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; -} diff --git a/src/native/windows/context.h b/src/native/windows/context.h index 8f6ef46d..4a7279ba 100644 --- a/src/native/windows/context.h +++ b/src/native/windows/context.h @@ -88,6 +88,6 @@ extern void getWindowFlags(DWORD *windowflags_return, DWORD *exstyle_return, boo */ 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 diff --git a/src/native/windows/display.c b/src/native/windows/display.c index 996326d0..1c2ac183 100644 --- a/src/native/windows/display.c +++ b/src/native/windows/display.c @@ -40,10 +40,6 @@ */ #include -// 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 #include #include "org_lwjgl_opengl_WindowsDisplay.h" #include "display.h" diff --git a/src/native/windows/org_lwjgl_opengl_Pbuffer.c b/src/native/windows/org_lwjgl_opengl_Pbuffer.c index e03afb84..49c51e96 100644 --- a/src/native/windows/org_lwjgl_opengl_Pbuffer.c +++ b/src/native/windows/org_lwjgl_opengl_Pbuffer.c @@ -62,15 +62,17 @@ static bool getExtensions(JNIEnv *env, WGLExtensions *extensions, jobject pixel_ 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 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nCreate } 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 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nCreate 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) { diff --git a/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c b/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c index 8a6685a3..cb507ca7 100644 --- a/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c +++ b/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c @@ -52,7 +52,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPeerInfo_nChoosePixelFormat 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