Update of /cvsroot/java-game-lib/LWJGL/src/native/win32 In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19234/src/native/win32 Modified Files: context.c context.h extgl_wgl.c extgl_wgl.h org_lwjgl_opengl_Pbuffer.c org_lwjgl_opengl_Win32ContextImplementation.c Log Message: Win32: Handle context-dependent wgl extensions Index: extgl_wgl.h =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/extgl_wgl.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- extgl_wgl.h 23 Feb 2005 15:34:42 -0000 1.4 +++ extgl_wgl.h 24 Feb 2005 13:24:08 -0000 1.5 @@ -40,40 +40,18 @@ #include "extgl.h" #include "common_tools.h" -typedef struct { - bool WGL_ARB_buffer_region; - bool WGL_ARB_extensions_string; - bool WGL_ARB_make_current_read; - bool WGL_ARB_multisample; - bool WGL_ARB_pbuffer; - bool WGL_ARB_pixel_format; - bool WGL_ARB_render_texture; - bool WGL_EXT_extensions_string; - bool WGL_EXT_swap_control; - bool WGL_NV_render_depth_texture; - bool WGL_NV_render_texture_rectangle; -} WGLExtensions; - -extern WGLExtensions extension_flags; - -extern void extgl_InitWGL(); - /*-------------------------------------------------------------------*/ /*------------WGL_EXT_EXTENSION_STRING-------------------------------*/ /*-------------------------------------------------------------------*/ typedef const char* (APIENTRY * wglGetExtensionsStringEXTPROC) (); -extern wglGetExtensionsStringEXTPROC wglGetExtensionsStringEXT; - /*-------------------------------------------------------------------*/ /*------------WGL_ARB_EXTENSION_STRING-------------------------------*/ /*-------------------------------------------------------------------*/ typedef const char* (APIENTRY * wglGetExtensionsStringARBPROC) (HDC hdc); -extern wglGetExtensionsStringARBPROC wglGetExtensionsStringARB; - /*-------------------------------------------------------------------*/ /*------------WGL_ARB_PBUFFER----------------------------------------*/ /*-------------------------------------------------------------------*/ @@ -96,12 +74,6 @@ typedef BOOL (APIENTRY * wglDestroyPbufferARBPROC) (HPBUFFERARB hPbuffer); typedef BOOL (APIENTRY * wglQueryPbufferARBPROC) (HPBUFFERARB hPbuffer, int iAttribute, int *piValue); -extern wglCreatePbufferARBPROC wglCreatePbufferARB; -extern wglGetPbufferDCARBPROC wglGetPbufferDCARB; -extern wglReleasePbufferDCARBPROC wglReleasePbufferDCARB; -extern wglDestroyPbufferARBPROC wglDestroyPbufferARB; -extern wglQueryPbufferARBPROC wglQueryPbufferARB; - /*-------------------------------------------------------------------*/ /*------------WGL_ARB_PIXEL_FORMAT-----------------------------------*/ /*-------------------------------------------------------------------*/ @@ -160,18 +132,10 @@ typedef BOOL (APIENTRY * wglGetPixelFormatAttribfvARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, FLOAT *pfValues); typedef BOOL (APIENTRY * wglChoosePixelFormatARBPROC) (HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats); -extern wglGetPixelFormatAttribivARBPROC wglGetPixelFormatAttribivARB; -extern wglGetPixelFormatAttribfvARBPROC wglGetPixelFormatAttribfvARB; -extern wglChoosePixelFormatARBPROC wglChoosePixelFormatARB; - typedef BOOL (APIENTRY * wglBindTexImageARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); typedef BOOL (APIENTRY * wglReleaseTexImageARBPROC) (HPBUFFERARB hPbuffer, int iBuffer); typedef BOOL (APIENTRY * wglSetPbufferAttribARBPROC) (HPBUFFERARB hPbuffer, const int *piAttribList); -extern wglBindTexImageARBPROC wglBindTexImageARB; -extern wglReleaseTexImageARBPROC wglReleaseTexImageARB; -extern wglSetPbufferAttribARBPROC wglSetPbufferAttribARB; - /*-------------------------------------------------------------------*/ /*------------WGL_EXT_SWAP_CONTROL-----------------------------------*/ /*-------------------------------------------------------------------*/ @@ -179,9 +143,6 @@ typedef BOOL (APIENTRY * wglSwapIntervalEXTPROC) (int interval); typedef int (APIENTRY * wglGetSwapIntervalEXTPROC) (void); -extern wglSwapIntervalEXTPROC wglSwapIntervalEXT; -extern wglGetSwapIntervalEXTPROC wglGetSwapIntervalEXT; - /*-------------------------------------------------------------------*/ /*------------WGL_ARB_MAKE_CURRENT_READ------------------------------*/ /*-------------------------------------------------------------------*/ @@ -192,9 +153,6 @@ typedef BOOL (APIENTRY * wglMakeContextCurrentARBPROC) (HDC hDrawDC, HDC hReadDC, HGLRC hglrc); typedef HDC (APIENTRY * wglGetCurrentReadDCARBPROC) (void); -extern wglMakeContextCurrentARBPROC wglMakeContextCurrentARB; -extern wglGetCurrentReadDCARBPROC wglGetCurrentReadDCARB; - /*-------------------------------------------------------------------*/ /*------------WGL_ARB_MULTISAMPLE------------------------------------*/ /*-------------------------------------------------------------------*/ @@ -202,5 +160,44 @@ #define WGL_SAMPLE_BUFFERS_ARB 0x2041 #define WGL_SAMPLES_ARB 0x2042 +typedef struct { + bool WGL_ARB_buffer_region; + bool WGL_ARB_extensions_string; + bool WGL_ARB_make_current_read; + bool WGL_ARB_multisample; + bool WGL_ARB_pbuffer; + bool WGL_ARB_pixel_format; + bool WGL_ARB_render_texture; + bool WGL_EXT_extensions_string; + bool WGL_EXT_swap_control; + bool WGL_NV_render_depth_texture; + bool WGL_NV_render_texture_rectangle; + wglGetExtensionsStringEXTPROC wglGetExtensionsStringEXT; + + wglGetExtensionsStringARBPROC wglGetExtensionsStringARB; + + wglCreatePbufferARBPROC wglCreatePbufferARB; + wglGetPbufferDCARBPROC wglGetPbufferDCARB; + wglReleasePbufferDCARBPROC wglReleasePbufferDCARB; + wglDestroyPbufferARBPROC wglDestroyPbufferARB; + wglQueryPbufferARBPROC wglQueryPbufferARB; + + wglGetPixelFormatAttribivARBPROC wglGetPixelFormatAttribivARB; + wglGetPixelFormatAttribfvARBPROC wglGetPixelFormatAttribfvARB; + wglChoosePixelFormatARBPROC wglChoosePixelFormatARB; + + wglBindTexImageARBPROC wglBindTexImageARB; + wglReleaseTexImageARBPROC wglReleaseTexImageARB; + wglSetPbufferAttribARBPROC wglSetPbufferAttribARB; + + wglSwapIntervalEXTPROC wglSwapIntervalEXT; + wglGetSwapIntervalEXTPROC wglGetSwapIntervalEXT; + + wglMakeContextCurrentARBPROC wglMakeContextCurrentARB; + wglGetCurrentReadDCARBPROC wglGetCurrentReadDCARB; +} WGLExtensions; + +extern void extgl_InitWGL(WGLExtensions *extensions); + #endif Index: org_lwjgl_opengl_Win32ContextImplementation.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_opengl_Win32ContextImplementation.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- org_lwjgl_opengl_Win32ContextImplementation.c 21 Feb 2005 14:46:47 -0000 1.1 +++ org_lwjgl_opengl_Win32ContextImplementation.c 24 Feb 2005 13:24:08 -0000 1.2 @@ -43,6 +43,7 @@ #include "common_tools.h" typedef struct { + WGLExtensions extensions; HGLRC context; } Win32Context; @@ -53,6 +54,9 @@ Win32Context *context_info; HGLRC context; HGLRC shared_context = NULL; + HDC saved_hdc; + HGLRC saved_context; + WGLExtensions extensions; jobject context_handle = newJavaManagedByteBuffer(env, sizeof(Win32Context)); if (context_handle == NULL) { @@ -74,9 +78,21 @@ return NULL; } } + saved_hdc = wglGetCurrentDC(); + saved_context = wglGetCurrentContext(); + if (!wglMakeCurrent(peer_info->format_hdc, context)) { + wglMakeCurrent(saved_hdc, saved_context); + wglDeleteContext(context); + throwException(env, "Could not make context current"); + return NULL; + } + extgl_InitWGL(&extensions); + if (!wglMakeCurrent(saved_hdc, saved_context)) + printfDebug("Failed to restore current context\n"); context_info = (Win32Context *)(*env)->GetDirectBufferAddress(env, context_handle); context_info->context = context; - return context_handle; + context_info->extensions = extensions; + return context_handle; } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32ContextImplementation_nSwapBuffers @@ -105,12 +121,13 @@ } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32ContextImplementation_nSetVSync - (JNIEnv *env, jclass clazz, jboolean enable) { - if (extension_flags.WGL_EXT_swap_control) { + (JNIEnv *env, jclass clazz, jobject context_handle, jboolean enable) { + Win32Context *context_info = (Win32Context *)(*env)->GetDirectBufferAddress(env, context_handle); + if (context_info->extensions.WGL_EXT_swap_control) { if (enable == JNI_TRUE) { - wglSwapIntervalEXT(1); + context_info->extensions.wglSwapIntervalEXT(1); } else { - wglSwapIntervalEXT(0); + context_info->extensions.wglSwapIntervalEXT(0); } } } Index: context.h =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/context.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- context.h 21 Feb 2005 14:46:47 -0000 1.1 +++ context.h 24 Feb 2005 13:24:08 -0000 1.2 @@ -50,7 +50,12 @@ typedef struct { union { HWND format_hwnd; - HPBUFFERARB pbuffer; + struct { + HPBUFFERARB pbuffer; + // Contains the function pointers that + // created the pbuffer + WGLExtensions extensions; + } pbuffer; }; HDC format_hdc; HDC drawable_hdc; Index: extgl_wgl.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/extgl_wgl.c,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- extgl_wgl.c 23 Feb 2005 15:17:53 -0000 1.6 +++ extgl_wgl.c 24 Feb 2005 13:24:08 -0000 1.7 @@ -38,50 +38,9 @@ #include "extgl_wgl.h" #include "extgl.h" -WGLExtensions extension_flags; - -/* WGL_EXT_etxension_string */ - -wglGetExtensionsStringEXTPROC wglGetExtensionsStringEXT = NULL; - -/* WGL_ARB_extension_string */ - -wglGetExtensionsStringARBPROC wglGetExtensionsStringARB = NULL; - -/* WGL_ARB_pbuffer */ - -wglCreatePbufferARBPROC wglCreatePbufferARB = NULL; -wglGetPbufferDCARBPROC wglGetPbufferDCARB = NULL; -wglReleasePbufferDCARBPROC wglReleasePbufferDCARB = NULL; -wglDestroyPbufferARBPROC wglDestroyPbufferARB = NULL; -wglQueryPbufferARBPROC wglQueryPbufferARB = NULL; - -/* WGL_ARB_pixel_format */ - -wglGetPixelFormatAttribivARBPROC wglGetPixelFormatAttribivARB = NULL; -wglGetPixelFormatAttribfvARBPROC wglGetPixelFormatAttribfvARB = NULL; -wglChoosePixelFormatARBPROC wglChoosePixelFormatARB = NULL; - -/* WGL_ARB_render_texture */ - -wglBindTexImageARBPROC wglBindTexImageARB = NULL; -wglReleaseTexImageARBPROC wglReleaseTexImageARB = NULL; -wglSetPbufferAttribARBPROC wglSetPbufferAttribARB = NULL; - -/* WGL_EXT_swap_control */ - -wglSwapIntervalEXTPROC wglSwapIntervalEXT = NULL; -wglGetSwapIntervalEXTPROC wglGetSwapIntervalEXT = NULL; - -/* WGL_ARB_make_current_read */ - -wglMakeContextCurrentARBPROC wglMakeContextCurrentARB = NULL; -wglGetCurrentReadDCARBPROC wglGetCurrentReadDCARB = NULL; - static HMODULE lib_gl_handle = NULL; -void *extgl_GetProcAddress(const char *name) -{ +void *extgl_GetProcAddress(const char *name) { void *t = wglGetProcAddress(name); if (t == NULL) { @@ -94,8 +53,7 @@ return t; } -bool extgl_Open(JNIEnv *env) -{ +bool extgl_Open(JNIEnv *env) { if (lib_gl_handle != NULL) return true; // load the dynamic libraries for OpenGL @@ -107,104 +65,105 @@ return true; } -void extgl_Close(void) -{ +void extgl_Close(void) { FreeLibrary(lib_gl_handle); lib_gl_handle = NULL; } /** returns true if the extension is available */ -static bool WGLQueryExtension(const char *name) -{ - const GLubyte *extensions; +static bool WGLQueryExtension(WGLExtensions *extensions, const char *name) { + const GLubyte *extension_string; - if (wglGetExtensionsStringARB == NULL) - if (wglGetExtensionsStringEXT == NULL) + if (extensions->wglGetExtensionsStringARB == NULL) + if (extensions->wglGetExtensionsStringEXT == NULL) return false; else - extensions = (GLubyte*)wglGetExtensionsStringEXT(); + extension_string = (GLubyte*)extensions->wglGetExtensionsStringEXT(); else - extensions = (GLubyte*)wglGetExtensionsStringARB(wglGetCurrentDC()); - return extgl_QueryExtension(extensions, name); + extension_string = (GLubyte*)extensions->wglGetExtensionsStringARB(wglGetCurrentDC()); + return extgl_QueryExtension(extension_string, name); } -static void extgl_InitWGLARBPbuffer() -{ +static void extgl_InitWGLARBPbuffer(WGLExtensions *extensions) { ExtFunction functions[] = { - {"wglCreatePbufferARB", (void **)&wglCreatePbufferARB}, - {"wglGetPbufferDCARB", (void **)&wglGetPbufferDCARB}, - {"wglReleasePbufferDCARB", (void **)&wglReleasePbufferDCARB}, - {"wglDestroyPbufferARB", (void **)&wglDestroyPbufferARB}, - {"wglQueryPbufferARB", (void **)&wglQueryPbufferARB}}; - if (extension_flags.WGL_ARB_pbuffer) - extension_flags.WGL_ARB_pbuffer = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); + {"wglCreatePbufferARB", (void **)&extensions->wglCreatePbufferARB}, + {"wglGetPbufferDCARB", (void **)&extensions->wglGetPbufferDCARB}, + {"wglReleasePbufferDCARB", (void **)&extensions->wglReleasePbufferDCARB}, + {"wglDestroyPbufferARB", (void **)&extensions->wglDestroyPbufferARB}, + {"wglQueryPbufferARB", (void **)&extensions->wglQueryPbufferARB}}; + if (extensions->WGL_ARB_pbuffer) + extensions->WGL_ARB_pbuffer = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); } -static void extgl_InitWGLARBPixelFormat() -{ +static void extgl_InitWGLARBPixelFormat(WGLExtensions *extensions) { ExtFunction functions[] = { - {"wglGetPixelFormatAttribivARB", (void **)&wglGetPixelFormatAttribivARB}, - {"wglGetPixelFormatAttribfvARB", (void **)&wglGetPixelFormatAttribfvARB}, - {"wglChoosePixelFormatARB", (void **)&wglChoosePixelFormatARB}}; - if (extension_flags.WGL_ARB_pixel_format) - extension_flags.WGL_ARB_pixel_format = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); + {"wglGetPixelFormatAttribivARB", (void **)&extensions->wglGetPixelFormatAttribivARB}, + {"wglGetPixelFormatAttribfvARB", (void **)&extensions->wglGetPixelFormatAttribfvARB}, + {"wglChoosePixelFormatARB", (void **)&extensions->wglChoosePixelFormatARB}}; + if (extensions->WGL_ARB_pixel_format) + extensions->WGL_ARB_pixel_format = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); } -static void extgl_InitWGLARBRenderTexture() -{ +static void extgl_InitWGLARBRenderTexture(WGLExtensions *extensions) { ExtFunction functions[] = { - {"wglBindTexImageARB", (void **)&wglBindTexImageARB}, - {"wglReleaseTexImageARB", (void **)&wglReleaseTexImageARB}, - {"wglSetPbufferAttribARB", (void **)&wglSetPbufferAttribARB}}; - if (extension_flags.WGL_ARB_render_texture) - extension_flags.WGL_ARB_render_texture = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); + {"wglBindTexImageARB", (void **)&extensions->wglBindTexImageARB}, + {"wglReleaseTexImageARB", (void **)&extensions->wglReleaseTexImageARB}, + {"wglSetPbufferAttribARB", (void **)&extensions->wglSetPbufferAttribARB}}; + if (extensions->WGL_ARB_render_texture) + extensions->WGL_ARB_render_texture = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); } -static void extgl_InitWGLEXTSwapControl() -{ +static void extgl_InitWGLEXTSwapControl(WGLExtensions *extensions) { ExtFunction functions[] = { - {"wglSwapIntervalEXT", (void **)&wglSwapIntervalEXT}, - {"wglGetSwapIntervalEXT", (void **)&wglGetSwapIntervalEXT}}; - if (extension_flags.WGL_EXT_swap_control) - extension_flags.WGL_EXT_swap_control = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); + {"wglSwapIntervalEXT", (void **)&extensions->wglSwapIntervalEXT}, + {"wglGetSwapIntervalEXT", (void **)&extensions->wglGetSwapIntervalEXT}}; + if (extensions->WGL_EXT_swap_control) + extensions->WGL_EXT_swap_control = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); } -static void extgl_InitWGLARBMakeCurrentRead() -{ +static void extgl_InitWGLARBMakeCurrentRead(WGLExtensions *extensions) { ExtFunction functions[] = { - {"wglMakeContextCurrentARB", (void **)&wglMakeContextCurrentARB}, - {"wglGetCurrentReadDCARB", (void **)&wglGetCurrentReadDCARB}}; - if (extension_flags.WGL_ARB_make_current_read) - extension_flags.WGL_ARB_make_current_read = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); + {"wglMakeContextCurrentARB", (void **)&extensions->wglMakeContextCurrentARB}, + {"wglGetCurrentReadDCARB", (void **)&extensions->wglGetCurrentReadDCARB}}; + if (extensions->WGL_ARB_make_current_read) + extensions->WGL_ARB_make_current_read = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); } -static void extgl_InitSupportedWGLExtensions() -{ - extension_flags.WGL_ARB_buffer_region = WGLQueryExtension("WGL_ARB_buffer_region"); - extension_flags.WGL_ARB_make_current_read = WGLQueryExtension("WGL_ARB_make_current_read"); - extension_flags.WGL_ARB_multisample = WGLQueryExtension("WGL_ARB_multisample"); - extension_flags.WGL_ARB_pbuffer = WGLQueryExtension("WGL_ARB_pbuffer"); - extension_flags.WGL_ARB_pixel_format = WGLQueryExtension("WGL_ARB_pixel_format"); - extension_flags.WGL_ARB_render_texture = WGLQueryExtension("WGL_ARB_render_texture"); - extension_flags.WGL_EXT_swap_control = WGLQueryExtension("WGL_EXT_swap_control"); - extension_flags.WGL_NV_render_depth_texture = WGLQueryExtension("WGL_NV_render_depth_texture"); - extension_flags.WGL_NV_render_texture_rectangle = WGLQueryExtension("WGL_NV_render_texture_rectangle"); +static void extgl_InitSupportedWGLExtensions(WGLExtensions *extensions) { + extensions->WGL_ARB_buffer_region = WGLQueryExtension(extensions, "WGL_ARB_buffer_region"); + extensions->WGL_ARB_make_current_read = WGLQueryExtension(extensions, "WGL_ARB_make_current_read"); + extensions->WGL_ARB_multisample = WGLQueryExtension(extensions, "WGL_ARB_multisample"); + extensions->WGL_ARB_pbuffer = WGLQueryExtension(extensions, "WGL_ARB_pbuffer"); + extensions->WGL_ARB_pixel_format = WGLQueryExtension(extensions, "WGL_ARB_pixel_format"); + extensions->WGL_ARB_render_texture = WGLQueryExtension(extensions, "WGL_ARB_render_texture"); + extensions->WGL_EXT_swap_control = WGLQueryExtension(extensions, "WGL_EXT_swap_control"); + extensions->WGL_NV_render_depth_texture = WGLQueryExtension(extensions, "WGL_NV_render_depth_texture"); + extensions->WGL_NV_render_texture_rectangle = WGLQueryExtension(extensions, "WGL_NV_render_texture_rectangle"); } -void extgl_InitWGL() -{ +static void extgl_InitWGLEXTExtensionsString(WGLExtensions *extensions) { ExtFunction functions[] = { - {"wglGetExtensionsStringARB", (void **)&wglGetExtensionsStringARB}, - {"wglGetExtensionsStringEXT", (void **)&wglGetExtensionsStringEXT}}; - extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); - extension_flags.WGL_ARB_extensions_string = wglGetExtensionsStringARB != NULL; - extension_flags.WGL_EXT_extensions_string = wglGetExtensionsStringEXT != NULL; + {"wglGetExtensionsStringEXT", (void **)&extensions->wglGetExtensionsStringEXT} + }; + extensions->WGL_EXT_extensions_string = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); +} - extgl_InitSupportedWGLExtensions(); +static void extgl_InitWGLARBExtensionsString(WGLExtensions *extensions) { + ExtFunction functions[] = { + {"wglGetExtensionsStringARB", (void **)&extensions->wglGetExtensionsStringARB} + }; + extensions->WGL_ARB_extensions_string = extgl_InitializeFunctions(sizeof(functions)/sizeof(ExtFunction), functions); +} - extgl_InitWGLARBMakeCurrentRead(); - extgl_InitWGLEXTSwapControl(); - extgl_InitWGLARBRenderTexture(); - extgl_InitWGLARBPixelFormat(); - extgl_InitWGLARBPbuffer(); +void extgl_InitWGL(WGLExtensions *extensions) { + extgl_InitWGLARBExtensionsString(extensions); + extgl_InitWGLEXTExtensionsString(extensions); + + extgl_InitSupportedWGLExtensions(extensions); + + extgl_InitWGLARBMakeCurrentRead(extensions); + extgl_InitWGLEXTSwapControl(extensions); + extgl_InitWGLARBRenderTexture(extensions); + extgl_InitWGLARBPixelFormat(extensions); + extgl_InitWGLARBPbuffer(extensions); } Index: org_lwjgl_opengl_Pbuffer.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/org_lwjgl_opengl_Pbuffer.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- org_lwjgl_opengl_Pbuffer.c 23 Feb 2005 11:42:04 -0000 1.11 +++ org_lwjgl_opengl_Pbuffer.c 24 Feb 2005 13:24:08 -0000 1.12 @@ -49,31 +49,68 @@ #include "common_tools.h" -typedef struct _PbufferInfo { - HGLRC Pbuffer_context; - HPBUFFERARB Pbuffer; - HDC Pbuffer_dc; -} PbufferInfo; - -static bool isPbuffersSupported() { - return extension_flags.WGL_ARB_pixel_format && extension_flags.WGL_ARB_pbuffer; +static bool isPbufferSupported(WGLExtensions *extensions) { + return extensions->WGL_ARB_pixel_format && extensions->WGL_ARB_pbuffer; } -JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getPbufferCapabilities - (JNIEnv *env, jobject self) +JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_nGetPbufferCapabilities + (JNIEnv *env, jobject self, jobject pixel_format) { int caps = 0; - if (isPbuffersSupported()) + int origin_x = 0; int origin_y = 0; + HWND dummy_hwnd; + HDC dummy_hdc; + HGLRC dummy_context; + HDC saved_hdc; + HGLRC saved_context; + int pixel_format_id; + WGLExtensions extensions; + + pixel_format_id = findPixelFormat(env, origin_x, origin_y, pixel_format, NULL, false, false, true, false); + if (pixel_format_id == -1) + return 0; + dummy_hwnd = createDummyWindow(origin_x, origin_y); + if (dummy_hwnd == NULL) { + throwException(env, "Could not create dummy window"); + return 0; + } + dummy_hdc = GetDC(dummy_hwnd); + if (!applyPixelFormat(dummy_hdc, pixel_format_id)) { + closeWindow(&dummy_hwnd, &dummy_hdc); + throwException(env, "Could not apply pixel format"); + return 0; + } + dummy_context = wglCreateContext(dummy_hdc); + if (dummy_context == NULL) { + closeWindow(&dummy_hwnd, &dummy_hdc); + throwException(env, "Could not create dummy context"); + return 0; + } + saved_hdc = wglGetCurrentDC(); + saved_context = wglGetCurrentContext(); + if (!wglMakeCurrent(dummy_hdc, dummy_context)) { + wglMakeCurrent(saved_hdc, saved_context); + closeWindow(&dummy_hwnd, &dummy_hdc); + wglDeleteContext(dummy_context); + throwException(env, "Could not create dummy context"); + return 0; + } + extgl_InitWGL(&extensions); + if (isPbufferSupported(&extensions)) caps |= org_lwjgl_opengl_Pbuffer_PBUFFER_SUPPORTED; - if (extension_flags.WGL_ARB_render_texture) + if (extensions.WGL_ARB_render_texture) caps |= org_lwjgl_opengl_Pbuffer_RENDER_TEXTURE_SUPPORTED; - if (extension_flags.WGL_NV_render_texture_rectangle) + if (extensions.WGL_NV_render_texture_rectangle) caps |= org_lwjgl_opengl_Pbuffer_RENDER_TEXTURE_RECTANGLE_SUPPORTED; - if (extension_flags.WGL_NV_render_depth_texture) + if (extensions.WGL_NV_render_depth_texture) caps |= org_lwjgl_opengl_Pbuffer_RENDER_DEPTH_TEXTURE_SUPPORTED; + if (!wglMakeCurrent(saved_hdc, saved_context)) + printfDebug("ERROR: Could not restore current context\n"); + closeWindow(&dummy_hwnd, &dummy_hdc); + wglDeleteContext(dummy_context); return caps; } @@ -86,8 +123,12 @@ int origin_x = 0; int origin_y = 0; HWND dummy_hwnd; HDC dummy_hdc; + HGLRC dummy_context; HPBUFFERARB Pbuffer; HDC Pbuffer_dc; + HDC saved_hdc; + HGLRC saved_context; + WGLExtensions extensions; const int *pBufferAttribs_ptr; Win32PeerInfo *peer_info = (Win32PeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); int pixel_format_id; @@ -98,7 +139,8 @@ pBufferAttribs_ptr = NULL; } pixel_format_id = findPixelFormat(env, origin_x, origin_y, pixel_format, pixelFormatCaps, false, false, true, false); - + if (pixel_format_id == -1) + return; dummy_hwnd = createDummyWindow(origin_x, origin_y); if (dummy_hwnd == NULL) { throwException(env, "Could not create dummy window"); @@ -110,36 +152,59 @@ throwException(env, "Could not apply pixel format"); return; } - Pbuffer = wglCreatePbufferARB(dummy_hdc, pixel_format_id, width, height, pBufferAttribs_ptr); + dummy_context = wglCreateContext(dummy_hdc); + if (dummy_context == NULL) { + closeWindow(&dummy_hwnd, &dummy_hdc); + throwException(env, "Could not create dummy context"); + return; + } + saved_hdc = wglGetCurrentDC(); + saved_context = wglGetCurrentContext(); + if (!wglMakeCurrent(dummy_hdc, dummy_context)) { + wglMakeCurrent(saved_hdc, saved_context); + wglDeleteContext(dummy_context); + closeWindow(&dummy_hwnd, &dummy_hdc); + throwException(env, "Could not make context current"); + return; + } + extgl_InitWGL(&extensions); + wglMakeCurrent(saved_hdc, saved_context); + wglDeleteContext(dummy_context); + closeWindow(&dummy_hwnd, &dummy_hdc); + if (!isPbufferSupported(&extensions)) { + throwException(env, "Pbuffers are not supported"); + return; + } + Pbuffer = extensions.wglCreatePbufferARB(dummy_hdc, pixel_format_id, width, height, pBufferAttribs_ptr); closeWindow(&dummy_hwnd, &dummy_hdc); if (Pbuffer == NULL) { throwException(env, "Could not create Pbuffer"); return; } - Pbuffer_dc = wglGetPbufferDCARB(Pbuffer); + Pbuffer_dc = extensions.wglGetPbufferDCARB(Pbuffer); if (Pbuffer_dc == NULL) { - wglDestroyPbufferARB(Pbuffer); + extensions.wglDestroyPbufferARB(Pbuffer); throwException(env, "Could not get Pbuffer DC"); return; } peer_info->format_hdc = Pbuffer_dc; - peer_info->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_Win32PbufferPeerInfo_nDestroy (JNIEnv *env, jclass clazz, jobject peer_info_handle) { Win32PeerInfo *peer_info = (Win32PeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - wglReleasePbufferDCARB(peer_info->pbuffer, peer_info->drawable_hdc); - wglDestroyPbufferARB(peer_info->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_Win32PbufferPeerInfo_nIsBufferLost (JNIEnv *env, jclass clazz, jobject peer_info_handle) { Win32PeerInfo *peer_info = (Win32PeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); BOOL buffer_lost; - wglQueryPbufferARB(peer_info->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; } @@ -152,17 +217,17 @@ attribs[1] = value; attribs[2] = 0; - wglSetPbufferAttribARB(peer_info->pbuffer, attribs); + peer_info->pbuffer.extensions.wglSetPbufferAttribARB(peer_info->pbuffer.pbuffer, attribs); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32PbufferPeerInfo_nBindTexImageToPbuffer (JNIEnv *env, jclass clazz, jobject peer_info_handle, jint buffer) { Win32PeerInfo *peer_info = (Win32PeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - wglBindTexImageARB(peer_info->pbuffer, buffer); + peer_info->pbuffer.extensions.wglBindTexImageARB(peer_info->pbuffer.pbuffer, buffer); } JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32PbufferPeerInfo_nReleaseTexImageFromPbuffer (JNIEnv *env, jclass clazz, jobject peer_info_handle, jint buffer) { Win32PeerInfo *peer_info = (Win32PeerInfo *)(*env)->GetDirectBufferAddress(env, peer_info_handle); - wglReleaseTexImageARB(peer_info->pbuffer, buffer); + peer_info->pbuffer.extensions.wglReleaseTexImageARB(peer_info->pbuffer.pbuffer, buffer); } Index: context.c =================================================================== RCS file: /cvsroot/java-game-lib/LWJGL/src/native/win32/context.c,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- context.c 23 Feb 2005 15:19:21 -0000 1.2 +++ context.c 24 Feb 2005 13:24:08 -0000 1.3 @@ -161,7 +161,7 @@ return new_hwnd; } -static int findPixelFormatARBFromBPP(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixelFormatCaps, int bpp, bool window, bool pbuffer, bool double_buffer) { +static int findPixelFormatARBFromBPP(JNIEnv *env, HDC hdc, WGLExtensions *extensions, jobject pixel_format, jobject pixelFormatCaps, int bpp, bool window, bool pbuffer, bool double_buffer) { jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format); int alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "alpha", "I")); int depth = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "depth", "I")); @@ -195,7 +195,8 @@ putAttrib(&attrib_list, WGL_ALPHA_BITS_ARB); putAttrib(&attrib_list, alpha); putAttrib(&attrib_list, WGL_DEPTH_BITS_ARB); putAttrib(&attrib_list, depth); putAttrib(&attrib_list, WGL_STENCIL_BITS_ARB); putAttrib(&attrib_list, stencil); - if (samples > 0 && extension_flags.WGL_ARB_multisample) { + // Assume caller checked extension availability + if (samples > 0) { putAttrib(&attrib_list, WGL_SAMPLE_BUFFERS_ARB); putAttrib(&attrib_list, 1); putAttrib(&attrib_list, WGL_SAMPLES_ARB); putAttrib(&attrib_list, samples); } @@ -203,11 +204,8 @@ putAttrib(&attrib_list, WGL_ACCUM_ALPHA_BITS_ARB); putAttrib(&attrib_list, accum_alpha); putAttrib(&attrib_list, WGL_STEREO_ARB); putAttrib(&attrib_list, stereo ? TRUE : FALSE); putAttrib(&attrib_list, WGL_AUX_BUFFERS_ARB); putAttrib(&attrib_list, num_aux_buffers); + // Assume caller checked extension availability if ( pixelFormatCaps != NULL ) { - if ( !extension_flags.WGL_ARB_render_texture ) { - return -1; - } - pixelFormatCaps_ptr = (GLuint *)(*env)->GetDirectBufferAddress(env, pixelFormatCaps); pixelFormatCapsSize = (*env)->GetDirectBufferCapacity(env, pixelFormatCaps); @@ -215,7 +213,7 @@ putAttrib(&attrib_list, pixelFormatCaps_ptr[i]); } putAttrib(&attrib_list, 0); putAttrib(&attrib_list, 0); - result = wglChoosePixelFormatARB(hdc, attrib_list.attribs, NULL, 1, &iPixelFormat, &num_formats_returned); + result = extensions->wglChoosePixelFormatARB(hdc, attrib_list.attribs, NULL, 1, &iPixelFormat, &num_formats_returned); if (result == FALSE || num_formats_returned < 1) { return -1; @@ -223,20 +221,20 @@ return iPixelFormat; } -static int findPixelFormatARB(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer) { +static int findPixelFormatARB(JNIEnv *env, HDC hdc, WGLExtensions *extensions, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer) { int bpp; int iPixelFormat; jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format); if (use_hdc_bpp) { bpp = GetDeviceCaps(hdc, BITSPIXEL); - iPixelFormat = findPixelFormatARBFromBPP(env, hdc, pixel_format, pixelFormatCaps, bpp, window, pbuffer, double_buffer); + iPixelFormat = findPixelFormatARBFromBPP(env, hdc, extensions, pixel_format, pixelFormatCaps, bpp, window, pbuffer, double_buffer); if (iPixelFormat == -1) bpp = 16; else return iPixelFormat; } else bpp = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "bpp", "I")); - return findPixelFormatARBFromBPP(env, hdc, pixel_format, pixelFormatCaps, bpp, window, pbuffer, double_buffer); + return findPixelFormatARBFromBPP(env, hdc, extensions, pixel_format, pixelFormatCaps, bpp, window, pbuffer, double_buffer); } /* @@ -345,6 +343,7 @@ HGLRC dummy_hglrc; HDC saved_current_hdc; HGLRC saved_current_hglrc; + WGLExtensions extensions; 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")); @@ -364,17 +363,32 @@ 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(); + extgl_InitWGL(&extensions); - if (!extension_flags.WGL_ARB_pixel_format) { + 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; } - pixel_format_id = findPixelFormatARB(env, hdc, pixel_format, pixelFormatCaps, use_hdc_bpp, window, pbuffer, double_buffer); + 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; + } + 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_multisample"); + return -1; + } + pixel_format_id = findPixelFormatARB(env, hdc, &extensions, pixel_format, pixelFormatCaps, use_hdc_bpp, window, pbuffer, double_buffer); wglMakeCurrent(saved_current_hdc, saved_current_hglrc); wglDeleteContext(dummy_hglrc); } |