diff --git a/src/java/org/lwjgl/opengl/WindowsDisplayPeerInfo.java b/src/java/org/lwjgl/opengl/WindowsDisplayPeerInfo.java index 3adf818c..64a8f1a0 100644 --- a/src/java/org/lwjgl/opengl/WindowsDisplayPeerInfo.java +++ b/src/java/org/lwjgl/opengl/WindowsDisplayPeerInfo.java @@ -42,30 +42,19 @@ import org.lwjgl.LWJGLException; * $Id$ */ final class WindowsDisplayPeerInfo extends WindowsPeerInfo { + private final PixelFormat pixel_format; + public WindowsDisplayPeerInfo(PixelFormat pixel_format) throws LWJGLException { + this.pixel_format = pixel_format; GLContext.loadOpenGLLibrary(); - try { - createDummyDC(getHandle()); - try { - choosePixelFormat(0, 0, pixel_format, null, true, true, false, true); - } catch (LWJGLException e) { - nDestroy(getHandle()); - throw e; - } - } catch (LWJGLException e) { - GLContext.unloadOpenGLLibrary(); - throw e; - } } - private static native void createDummyDC(ByteBuffer peer_info_handle) throws LWJGLException; - void initDC() { + void initDC() throws LWJGLException { nInitDC(getHandle()); + choosePixelFormat(0, 0, pixel_format, null, true, true, false, true); } private static native void nInitDC(ByteBuffer peer_info_handle); - private static native void nDestroy(ByteBuffer peer_info_handle); - protected void doLockAndInitHandle() throws LWJGLException { // NO-OP } @@ -76,7 +65,6 @@ final class WindowsDisplayPeerInfo extends WindowsPeerInfo { public void destroy() { super.destroy(); - nDestroy(getHandle()); GLContext.unloadOpenGLLibrary(); } } diff --git a/src/native/windows/context.h b/src/native/windows/context.h index ac7c64b7..8f6ef46d 100644 --- a/src/native/windows/context.h +++ b/src/native/windows/context.h @@ -47,16 +47,12 @@ #include "extgl_wgl.h" typedef struct { - union { - HWND format_hwnd; - struct { - HPBUFFERARB pbuffer; - // Contains the function pointers that - // created the pbuffer - WGLExtensions extensions; - } pbuffer; - } u; - HDC format_hdc; + struct { + HPBUFFERARB pbuffer; + // Contains the function pointers that + // created the pbuffer + WGLExtensions extensions; + } pbuffer; HDC drawable_hdc; } WindowsPeerInfo; diff --git a/src/native/windows/org_lwjgl_opengl_Pbuffer.c b/src/native/windows/org_lwjgl_opengl_Pbuffer.c index e4131029..e03afb84 100644 --- a/src/native/windows/org_lwjgl_opengl_Pbuffer.c +++ b/src/native/windows/org_lwjgl_opengl_Pbuffer.c @@ -165,24 +165,23 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nCreate throwException(env, "Could not get Pbuffer DC"); return; } - peer_info->format_hdc = Pbuffer_dc; - peer_info->u.pbuffer.extensions = extensions; - peer_info->u.pbuffer.pbuffer = Pbuffer; + peer_info->pbuffer.extensions = extensions; + peer_info->pbuffer.pbuffer = Pbuffer; peer_info->drawable_hdc = Pbuffer_dc; } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nDestroy (JNIEnv *env, jclass clazz, jobject peer_info_handle) { WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - peer_info->u.pbuffer.extensions.wglReleasePbufferDCARB(peer_info->u.pbuffer.pbuffer, peer_info->drawable_hdc); - peer_info->u.pbuffer.extensions.wglDestroyPbufferARB(peer_info->u.pbuffer.pbuffer); + peer_info->pbuffer.extensions.wglReleasePbufferDCARB(peer_info->pbuffer.pbuffer, peer_info->drawable_hdc); + peer_info->pbuffer.extensions.wglDestroyPbufferARB(peer_info->pbuffer.pbuffer); } JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nIsBufferLost (JNIEnv *env, jclass clazz, jobject peer_info_handle) { WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); BOOL buffer_lost; - peer_info->u.pbuffer.extensions.wglQueryPbufferARB(peer_info->u.pbuffer.pbuffer, WGL_PBUFFER_LOST_ARB, &buffer_lost); + peer_info->pbuffer.extensions.wglQueryPbufferARB(peer_info->pbuffer.pbuffer, WGL_PBUFFER_LOST_ARB, &buffer_lost); return buffer_lost ? JNI_TRUE : JNI_FALSE; } @@ -195,17 +194,17 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nSetPbufferA attribs[1] = value; attribs[2] = 0; - peer_info->u.pbuffer.extensions.wglSetPbufferAttribARB(peer_info->u.pbuffer.pbuffer, attribs); + peer_info->pbuffer.extensions.wglSetPbufferAttribARB(peer_info->pbuffer.pbuffer, attribs); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nBindTexImageToPbuffer (JNIEnv *env, jclass clazz, jobject peer_info_handle, jint buffer) { WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - peer_info->u.pbuffer.extensions.wglBindTexImageARB(peer_info->u.pbuffer.pbuffer, buffer); + peer_info->pbuffer.extensions.wglBindTexImageARB(peer_info->pbuffer.pbuffer, buffer); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPbufferPeerInfo_nReleaseTexImageFromPbuffer (JNIEnv *env, jclass clazz, jobject peer_info_handle, jint buffer) { WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - peer_info->u.pbuffer.extensions.wglReleaseTexImageARB(peer_info->u.pbuffer.pbuffer, buffer); + peer_info->pbuffer.extensions.wglReleaseTexImageARB(peer_info->pbuffer.pbuffer, buffer); } diff --git a/src/native/windows/org_lwjgl_opengl_WindowsAWTGLCanvasPeerInfo.c b/src/native/windows/org_lwjgl_opengl_WindowsAWTGLCanvasPeerInfo.c index 14ae9b80..dcb1ba7d 100644 --- a/src/native/windows/org_lwjgl_opengl_WindowsAWTGLCanvasPeerInfo.c +++ b/src/native/windows/org_lwjgl_opengl_WindowsAWTGLCanvasPeerInfo.c @@ -50,7 +50,5 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsAWTGLCanvasPeerInfo_nInitHan WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); AWTSurfaceLock *surface = (AWTSurfaceLock *)(*env)->GetDirectBufferAddress(env, lock_buffer_handle); JAWT_Win32DrawingSurfaceInfo *win32_dsi = (JAWT_Win32DrawingSurfaceInfo *)surface->dsi->platformInfo; - peer_info->u.format_hwnd = win32_dsi->hwnd; - peer_info->format_hdc = win32_dsi->hdc; peer_info->drawable_hdc = win32_dsi->hdc; } diff --git a/src/native/windows/org_lwjgl_opengl_WindowsContextImplementation.c b/src/native/windows/org_lwjgl_opengl_WindowsContextImplementation.c index b2e918a7..9177fe8a 100644 --- a/src/native/windows/org_lwjgl_opengl_WindowsContextImplementation.c +++ b/src/native/windows/org_lwjgl_opengl_WindowsContextImplementation.c @@ -63,7 +63,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsContextImplementation_nCr return NULL; } peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - context = wglCreateContext(peer_info->format_hdc); + context = wglCreateContext(peer_info->drawable_hdc); if (context == NULL) { throwException(env, "Could not create context"); return NULL; @@ -79,7 +79,7 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_WindowsContextImplementation_nCr } saved_hdc = wglGetCurrentDC(); saved_context = wglGetCurrentContext(); - if (!wglMakeCurrent(peer_info->format_hdc, context)) { + if (!wglMakeCurrent(peer_info->drawable_hdc, context)) { wglMakeCurrent(saved_hdc, saved_context); wglDeleteContext(context); throwException(env, "Could not make context current"); diff --git a/src/native/windows/org_lwjgl_opengl_WindowsDisplayPeerInfo.c b/src/native/windows/org_lwjgl_opengl_WindowsDisplayPeerInfo.c index 328a4505..0253d521 100644 --- a/src/native/windows/org_lwjgl_opengl_WindowsDisplayPeerInfo.c +++ b/src/native/windows/org_lwjgl_opengl_WindowsDisplayPeerInfo.c @@ -43,36 +43,8 @@ #include "context.h" #include "common_tools.h" -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplayPeerInfo_createDummyDC - (JNIEnv *env, jclass clazz, jobject peer_info_handle) { - WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - HWND dummy_hwnd = createDummyWindow(0, 0); - HDC dummy_hdc; - if (dummy_hwnd == NULL) { - throwException(env, "Failed to create a dummy window."); - return; - } - dummy_hdc = GetDC(dummy_hwnd); - peer_info->u.format_hwnd = dummy_hwnd; - peer_info->format_hdc = dummy_hdc; -} - -JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplayPeerInfo_nDestroy - (JNIEnv *env, jclass clazz, jobject peer_info_handle) { - WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - closeWindow(&peer_info->u.format_hwnd, &peer_info->format_hdc); -} - JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsDisplayPeerInfo_nInitDC (JNIEnv *env, jclass clazz, jobject peer_info_handle) { WindowsPeerInfo *peer_info = (WindowsPeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - int pixel_format; peer_info->drawable_hdc = getCurrentHDC(); - pixel_format = GetPixelFormat(peer_info->format_hdc); - if (pixel_format == 0) { - throwException(env, "Could not get pixel format from dummy hdc"); - return; - } - // If applyPixelFormat fails, just let it throw - applyPixelFormat(env, peer_info->drawable_hdc, pixel_format); } diff --git a/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c b/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c index 1a3aca7d..8a6685a3 100644 --- a/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c +++ b/src/native/windows/org_lwjgl_opengl_WindowsPeerInfo.c @@ -56,5 +56,5 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_WindowsPeerInfo_nChoosePixelFormat if (pixel_format_id == -1) return; // Let it throw - applyPixelFormat(env, peer_info->format_hdc, pixel_format_id); + applyPixelFormat(env, peer_info->drawable_hdc, pixel_format_id); }