Windows: Got rid of dummy window in WindowsDisplayPeerInfo

This commit is contained in:
Elias Naur 2006-09-19 14:17:13 +00:00
parent def08f06f8
commit 87523ce63a
7 changed files with 22 additions and 69 deletions

View File

@ -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();
}
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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");

View File

@ -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);
}

View File

@ -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);
}