Win32: Make pbuffer creation independent of display context

This commit is contained in:
Elias Naur 2004-07-06 07:50:33 +00:00
parent 39c06a14ab
commit 19b7f16291
8 changed files with 139 additions and 105 deletions

View File

@ -52,20 +52,29 @@
#else
#define WINDOW_H_API extern
extern HWND hwnd; // Handle to the window
extern HDC hdc; // Device context
extern HWND display_hwnd; // Handle to the window
extern HDC display_hdc; // Device context
extern bool isFullScreen; // Whether we're fullscreen or not
extern bool isMinimized; // Whether we're minimized or not
extern bool isFocused; // Whether we're focused or not
extern bool isDirty; // Whether we're dirty or not
extern RECT clientSize;
extern HGLRC hglrc;
extern HGLRC display_hglrc;
#endif /* _PRIVATE_WINDOW_H_ */
WINDOW_H_API bool applyPixelFormat(JNIEnv *env, HDC hdc, int iPixelFormat);
WINDOW_H_API void closeWindow(HWND hwnd, HDC hdc);
/*
* Find a suitable pixel format
*/
WINDOW_H_API int findPixelFormat(JNIEnv *env, HDC hdc, jobject pixel_format);
/*
* Find a suitable pixel format using the WGL_ARB_pixel_format extension
*/
WINDOW_H_API int findPixelFormatARB(JNIEnv *env, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool double_buffer);
WINDOW_H_API int findPixelFormatARB(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool double_buffer);
/*
* Create a window with the specified title, position, size, and
@ -74,7 +83,7 @@
*
* Returns true for success, or false for failure
*/
WINDOW_H_API bool createWindow(const char * title, int x, int y, int width, int height, bool fullscreen);
WINDOW_H_API HWND createWindow(JNIEnv *env, int width, int height, bool fullscreen, bool undecorated);
/*

View File

@ -42,9 +42,7 @@
#include <windows.h>
#include "org_lwjgl_Sys.h"
#include "common_tools.h"
// Handle to the application's window
extern HWND hwnd;
#include "Window.h"
unsigned __int64 hires_timer_freq = 0; // Hires timer frequency
unsigned __int64 hires_timer = 0; // Hires timer current time
@ -125,7 +123,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert
jboolean copy = JNI_FALSE;
const char * eMessageText = env->GetStringUTFChars(message, &copy);
const char * cTitleBarText = env->GetStringUTFChars(title, &copy);
MessageBox(hwnd, eMessageText, cTitleBarText, MB_OK | MB_TOPMOST);
MessageBox(display_hwnd, eMessageText, cTitleBarText, MB_OK | MB_TOPMOST);
printfDebug("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText);

View File

@ -53,7 +53,6 @@
#define CONTROLLER_AXISMIN -1000 // Minimum range to which we'll gauge the swing
extern HINSTANCE dll_handle;
extern HWND hwnd;
static IDirectInput* cDI; // DI instance
static IDirectInputDevice2* cDIDevice; // DI Device instance
@ -117,13 +116,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_initIDs(JNIEnv * env, jcl
* Called when the Controller instance is to be created
*/
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jclass clazz) {
// assert that window has been created
if(hwnd == NULL) {
throwException(env, "Please create the window before initializing input devices");
return;
}
// Create the DirectInput object.
HRESULT hr;
hr = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &cDI, NULL);
@ -326,7 +318,7 @@ static void SetupController() {
}
// set the cooperative level
if(cDIDevice->SetCooperativeLevel(hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
if(cDIDevice->SetCooperativeLevel(display_hwnd, DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
printfDebug("SetCooperativeLevel failed\n");
cCreate_success = false;
return;

View File

@ -70,7 +70,7 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_input_Cursor_nCreateCursor
bitmapInfo.bmiHeader.biBitCount = 24;
bitmapInfo.bmiHeader.biCompression = BI_RGB;
colorDIB = CreateDIBSection(hdc, (BITMAPINFO*)&(bitmapInfo),
colorDIB = CreateDIBSection(GetDC(NULL), (BITMAPINFO*)&(bitmapInfo),
DIB_RGB_COLORS,
(void**)&(ptrCursorImage),
NULL, 0);
@ -91,7 +91,7 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_input_Cursor_nCreateCursor
}
}
colorBitmap = CreateDIBitmap(hdc,
colorBitmap = CreateDIBitmap(GetDC(NULL),
(BITMAPINFOHEADER*)&bitmapInfo.bmiHeader,
CBM_INIT,
(void *)ptrCursorImage,

View File

@ -81,7 +81,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
return;
}
if (hwnd == NULL) {
if (display_hwnd == NULL) {
throwException(env, "No window.");
return;
}
@ -92,7 +92,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
return;
}
if (lpdiKeyboard->SetCooperativeLevel(hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
if (lpdiKeyboard->SetCooperativeLevel(display_hwnd, DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
throwException(env, "Failed to set keyboard cooperation mode.");
return;
}

View File

@ -73,7 +73,7 @@ void UpdateMouseFields(JNIEnv *env, jclass clsMouse, jobject coord_buffer_obj, j
static void getScreenClientRect(RECT* clientRect, RECT* windowRect)
{
GetClientRect(hwnd, clientRect);
GetClientRect(display_hwnd, clientRect);
// transform clientRect to screen coordinates
clientRect->top = -clientSize.top + windowRect->top;
clientRect->left = -clientSize.left + windowRect->left;
@ -228,14 +228,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
throwException(env, "null device!");
if (cursor_handle != 0) {
HCURSOR cursor = (HCURSOR)cursor_handle;
SetClassLong(hwnd, GCL_HCURSOR, (LONG)cursor);
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)cursor);
SetCursor(cursor);
if (!usingNativeCursor) {
usingNativeCursor = true;
}
} else {
if (usingNativeCursor) {
SetClassLong(hwnd, GCL_HCURSOR, (LONG)NULL);
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)NULL);
SetCursor(LoadCursor(NULL, IDC_ARROW));
usingNativeCursor = false;
}
@ -300,14 +300,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse
/* Reset cursor position to middle of the window */
RECT clientRect;
GetWindowRect(hwnd, &windowRect);
GetWindowRect(display_hwnd, &windowRect);
getScreenClientRect(&clientRect, &windowRect);
cursorPos.x = (clientRect.left + clientRect.right)/2;
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
SetCursorPos(cursorPos.x, cursorPos.y);
}
mDIDevice->Unacquire();
if(mDIDevice->SetCooperativeLevel(hwnd, mouseMask) != DI_OK) {
if(mDIDevice->SetCooperativeLevel(display_hwnd, mouseMask) != DI_OK) {
throwException(env, "Could not set the CooperativeLevel.");
return;
}
@ -403,7 +403,7 @@ static void SetupMouse() {
mDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
// set the cooperative level
if(mDIDevice->SetCooperativeLevel(hwnd, mouseMask) != DI_OK) {
if(mDIDevice->SetCooperativeLevel(display_hwnd, mouseMask) != DI_OK) {
printfDebug("SetCooperativeLevel failed\n");
mCreate_success = false;
return;
@ -412,11 +412,11 @@ static void SetupMouse() {
/* Reset cursor position to middle of the window */
RECT clientRect;
GetWindowRect(hwnd, &windowRect);
GetWindowRect(display_hwnd, &windowRect);
getScreenClientRect(&clientRect, &windowRect);
cursorPos.x = (clientRect.left + clientRect.right)/2;
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
SetCursorPos(cursorPos.x, cursorPos.y);
SetCursorPos(cursorPos.x, cursorPos.y);
}
static int cap(int val, int min, int max) {
@ -436,7 +436,7 @@ static void getGDICursorDelta(int* return_dx, int* return_dy) {
GetCursorPos(&newCursorPos);
RECT clientRect;
RECT newWindowRect;
GetWindowRect(hwnd, &newWindowRect);
GetWindowRect(display_hwnd, &newWindowRect);
cursorPos.x += newWindowRect.left - windowRect.left;
cursorPos.y += newWindowRect.top - windowRect.top;
windowRect = newWindowRect;

View File

@ -49,9 +49,9 @@
static bool oneShotInitialised = false; // Registers the LWJGL window class
HWND hwnd = NULL; // Handle to the window
HDC hdc = NULL; // Device context
HGLRC hglrc = NULL; // OpenGL context
HWND display_hwnd = NULL; // Handle to the window
HDC display_hdc = NULL; // Device context
HGLRC display_hglrc = NULL; // OpenGL context
static bool isFullScreen = false; // Whether we're fullscreen or not
static bool isMinimized = false; // Whether we're minimized or not
static bool isFocused = false; // whether we're focused or not
@ -65,7 +65,7 @@ static int pixel_format_index;
#define WINDOWCLASSNAME "LWJGL"
static bool applyPixelFormat(JNIEnv *env, HDC hdc, int iPixelFormat) {
bool applyPixelFormat(JNIEnv *env, HDC hdc, int iPixelFormat) {
PIXELFORMATDESCRIPTOR desc;
if (DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &desc) == 0) {
throwException(env, "Could not describe pixel format");
@ -80,7 +80,7 @@ static bool applyPixelFormat(JNIEnv *env, HDC hdc, int iPixelFormat) {
return true;
}
static int findPixelFormatARBFromBPP(JNIEnv *env, jobject pixel_format, jobject pixelFormatCaps, int bpp, bool window, bool double_buffer) {
static int findPixelFormatARBFromBPP(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixelFormatCaps, int bpp, bool window, bool double_buffer) {
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
int depth = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "depth", "I"));
@ -137,25 +137,25 @@ static int findPixelFormatARBFromBPP(JNIEnv *env, jobject pixel_format, jobject
return iPixelFormat;
}
int findPixelFormatARB(JNIEnv *env, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool double_buffer) {
int findPixelFormatARB(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool double_buffer) {
int bpp;
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
if (use_hdc_bpp) {
bpp = GetDeviceCaps(hdc, BITSPIXEL);
int iPixelFormat = findPixelFormatARBFromBPP(env, pixel_format, pixelFormatCaps, bpp, window, double_buffer);
int iPixelFormat = findPixelFormatARBFromBPP(env, hdc, pixel_format, pixelFormatCaps, bpp, window, double_buffer);
if (iPixelFormat == -1)
bpp = 16;
else
return iPixelFormat;
} else
bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "bpp", "I"));
return findPixelFormatARBFromBPP(env, pixel_format, pixelFormatCaps, bpp, window, double_buffer);
return findPixelFormatARBFromBPP(env, hdc, pixel_format, pixelFormatCaps, bpp, window, double_buffer);
}
/*
* Find an appropriate pixel format
*/
static int findPixelFormatFromBPP(JNIEnv *env, jobject pixel_format, int bpp)
static int findPixelFormatFromBPP(JNIEnv *env, HDC hdc, jobject pixel_format, int bpp)
{
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
@ -240,13 +240,13 @@ static int findPixelFormatFromBPP(JNIEnv *env, jobject pixel_format, int bpp)
return iPixelFormat;
}
static int findPixelFormat(JNIEnv *env, jobject pixel_format) {
int findPixelFormat(JNIEnv *env, HDC hdc, jobject pixel_format) {
int bpp;
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
bpp = GetDeviceCaps(hdc, BITSPIXEL);
int iPixelFormat = findPixelFormatFromBPP(env, pixel_format, bpp);
int iPixelFormat = findPixelFormatFromBPP(env, hdc, pixel_format, bpp);
if (iPixelFormat == -1) {
return findPixelFormatFromBPP(env, pixel_format, 16);
return findPixelFormatFromBPP(env, hdc, pixel_format, 16);
} else
return iPixelFormat;
}
@ -254,7 +254,7 @@ static int findPixelFormat(JNIEnv *env, jobject pixel_format) {
/*
* Close the window
*/
static void closeWindow()
void closeWindow(HWND hwnd, HDC hdc)
{
// Release device context
if (hdc != NULL && hwnd != NULL) {
@ -278,10 +278,10 @@ static void closeWindow()
static void appActivate(bool active)
{
if (active) {
SetForegroundWindow(hwnd);
ShowWindow(hwnd, SW_RESTORE);
SetForegroundWindow(display_hwnd);
ShowWindow(display_hwnd, SW_RESTORE);
} else if (isFullScreen) {
ShowWindow(hwnd, SW_MINIMIZE);
ShowWindow(display_hwnd, SW_MINIMIZE);
}
}
@ -391,7 +391,7 @@ static void handleMessages(JNIEnv * env, jclass clazz)
MSG msg;
while (PeekMessage(
&msg, // message information
hwnd, // handle to window
display_hwnd, // handle to window
0, // first message
0, // last message
PM_REMOVE // removal options
@ -409,10 +409,16 @@ static void handleMessages(JNIEnv * env, jclass clazz)
*
* Returns true for success, or false for failure
*/
static bool createWindow(JNIEnv *env, int width, int height, bool fullscreen, bool undecorated)
HWND createWindow(JNIEnv *env, int width, int height, bool fullscreen, bool undecorated)
{
int exstyle, windowflags;
// 1. Register window class if necessary
if (!registerWindow()) {
throwException(env, "Could not register window class");
return NULL;
}
if (fullscreen) {
exstyle = WS_EX_APPWINDOW | WS_EX_TOPMOST;
windowflags = WS_POPUP;
@ -439,7 +445,7 @@ static bool createWindow(JNIEnv *env, int width, int height, bool fullscreen, bo
);
// Create the window now, using that class:
hwnd = CreateWindowEx (
HWND new_hwnd = CreateWindowEx (
exstyle,
WINDOWCLASSNAME,
"",
@ -450,13 +456,12 @@ static bool createWindow(JNIEnv *env, int width, int height, bool fullscreen, bo
dll_handle,
NULL);
if (hwnd == NULL) {
if (new_hwnd == NULL) {
throwException(env, "Failed to create the window.");
return false;
return NULL;
}
hdc = GetDC(hwnd);
return true;
return new_hwnd;
}
/*
@ -468,7 +473,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetTitle
(JNIEnv * env, jclass clazz, jstring title_obj)
{
const char * title = env->GetStringUTFChars(title_obj, NULL);
SetWindowText(hwnd, title);
SetWindowText(display_hwnd, title);
env->ReleaseStringUTFChars(title_obj, title);
}
@ -493,8 +498,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_swapBuffers
(JNIEnv * env, jclass clazz)
{
isDirty = false;
SwapBuffers(hdc);
// wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE);
SwapBuffers(display_hdc);
}
/*
@ -561,7 +565,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetVSyncEnabled
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nMakeCurrent
(JNIEnv *env, jclass clazz)
{
BOOL result = wglMakeCurrent(hdc, hglrc);
BOOL result = wglMakeCurrent(display_hdc, display_hglrc);
if (!result)
throwException(env, "Could not make display context current");
}
@ -620,29 +624,31 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nCreateWindow(JNIEnv *env,
int width = env->GetIntField(mode, fid_width);
int height = env->GetIntField(mode, fid_height);
if (!createWindow(env, width, height, isFullScreen, isUndecorated)) {
display_hwnd = createWindow(env, width, height, isFullScreen, isUndecorated);
if (display_hwnd == NULL) {
return;
}
if (!applyPixelFormat(env, hdc, pixel_format_index)) {
closeWindow();
display_hdc = GetDC(display_hwnd);
if (!applyPixelFormat(env, display_hdc, pixel_format_index)) {
closeWindow(display_hwnd, display_hdc);
return;
}
BOOL result = wglMakeCurrent(hdc, hglrc);
BOOL result = wglMakeCurrent(display_hdc, display_hglrc);
if (!result) {
throwException(env, "Could not bind context to window");
closeWindow();
closeWindow(display_hwnd, display_hdc);
return;
}
extgl_InitWGL(env);
ShowWindow(hwnd, SW_SHOW);
UpdateWindow(hwnd);
SetForegroundWindow(hwnd);
SetFocus(hwnd);
ShowWindow(display_hwnd, SW_SHOW);
UpdateWindow(display_hwnd);
SetForegroundWindow(display_hwnd);
SetFocus(display_hwnd);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroyWindow(JNIEnv *env, jclass clazz) {
closeWindow();
closeWindow(display_hwnd, display_hdc);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_switchDisplayMode(JNIEnv *env, jclass clazz, jobject mode) {
@ -674,35 +680,31 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_Display_init(JNIEnv *env, jclass
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_createContext(JNIEnv *env, jclass clazz, jobject pixel_format) {
// 1. Register window class if necessary
if (!registerWindow()) {
throwException(env, "Could not register window class");
HWND dummy_hwnd = createWindow(env, 1, 1, false, false);
if (dummy_hwnd == NULL) {
return;
}
if (!createWindow(env, 1, 1, false, false)) {
return;
}
pixel_format_index = findPixelFormat(env, pixel_format);
HDC dummy_hdc = GetDC(dummy_hwnd);
pixel_format_index = findPixelFormat(env, dummy_hdc, pixel_format);
if (pixel_format_index == -1) {
return;
}
// Special option for allowing software opengl
if (!applyPixelFormat(env, hdc, pixel_format_index)) {
closeWindow();
if (!applyPixelFormat(env, dummy_hdc, pixel_format_index)) {
closeWindow(dummy_hwnd, dummy_hdc);
return;
}
hglrc = wglCreateContext(hdc);
if (hglrc == NULL) {
display_hglrc = wglCreateContext(dummy_hdc);
if (display_hglrc == NULL) {
closeWindow(dummy_hwnd, dummy_hdc);
throwException(env, "Failed to create OpenGL rendering context");
return;
}
BOOL result = wglMakeCurrent(hdc, hglrc);
BOOL result = wglMakeCurrent(dummy_hdc, display_hglrc);
if (!result) {
throwException(env, "Could not bid context to dummy window");
wglDeleteContext(hglrc);
closeWindow();
throwException(env, "Could not bind context to dummy window");
wglDeleteContext(display_hglrc);
closeWindow(dummy_hwnd, dummy_hdc);
return;
}
// Some crazy strangeness here so we can use ARB_pixel_format to specify the number
@ -710,37 +712,39 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_createContext(JNIEnv *env,
// rendering context and start over, using the ARB extension instead to pick the context.
extgl_InitWGL(env);
if (extgl_Extensions.WGL_ARB_pixel_format) {
pixel_format_index = findPixelFormatARB(env, pixel_format, NULL, true, true, true);
pixel_format_index = findPixelFormatARB(env, dummy_hdc, pixel_format, NULL, true, true, true);
wglMakeCurrent(NULL, NULL);
wglDeleteContext(hglrc);
closeWindow();
wglDeleteContext(display_hglrc);
closeWindow(dummy_hwnd, dummy_hdc);
if (pixel_format_index == -1) {
return;
}
if (!createWindow(env, 1, 1, false, false)) {
dummy_hwnd = createWindow(env, 1, 1, false, false);
if (dummy_hwnd == NULL) {
return;
}
if (!applyPixelFormat(env, hdc, pixel_format_index)) {
closeWindow();
dummy_hdc = GetDC(dummy_hwnd);
if (!applyPixelFormat(env, dummy_hdc, pixel_format_index)) {
closeWindow(dummy_hwnd, dummy_hdc);
return;
}
hglrc = wglCreateContext(hdc);
closeWindow();
if (hglrc == NULL) {
display_hglrc = wglCreateContext(dummy_hdc);
closeWindow(dummy_hwnd, dummy_hdc);
if (display_hglrc == NULL) {
throwException(env, "Failed to create OpenGL rendering context (ARB)");
return;
}
} else
closeWindow();
closeWindow(dummy_hwnd, dummy_hdc);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_destroyContext(JNIEnv *env, jclass clazz) {
wglMakeCurrent(NULL, NULL);
// Delete the rendering context
if (hglrc != NULL) {
if (display_hglrc != NULL) {
printfDebug("Deleting GL context\n");
wglDeleteContext(hglrc);
hglrc = NULL;
wglDeleteContext(display_hglrc);
display_hglrc = NULL;
}
}

View File

@ -91,11 +91,41 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
jint width, jint height, jobject pixel_format,
jobject pixelFormatCaps, jobject pBufferAttribs)
{
int iPixelFormat = findPixelFormatARB(env, pixel_format, pixelFormatCaps, false, false, false);
HWND dummy_hwnd = createWindow(env, 1, 1, false, false);
if (dummy_hwnd == NULL) {
return (jint)NULL;
}
HDC dummy_hdc = GetDC(dummy_hwnd);
int iPixelFormat = findPixelFormat(env, dummy_hdc, pixel_format);
if (iPixelFormat == -1) {
return (jint)NULL;
}
if (!applyPixelFormat(env, dummy_hdc, iPixelFormat)) {
closeWindow(dummy_hwnd, dummy_hdc);
return (jint)NULL;
}
HGLRC dummy_hglrc = wglCreateContext(dummy_hdc);
if (dummy_hglrc == NULL) {
closeWindow(dummy_hwnd, dummy_hdc);
throwException(env, "Failed to create OpenGL rendering context");
return (jint)NULL;
}
BOOL result = wglMakeCurrent(dummy_hdc, dummy_hglrc);
if (!result) {
wglDeleteContext(dummy_hglrc);
closeWindow(dummy_hwnd, dummy_hdc);
throwException(env, "Could not bind context to dummy window");
return (jint)NULL;
}
extgl_InitWGL(env);
iPixelFormat = findPixelFormatARB(env, dummy_hdc, pixel_format, pixelFormatCaps, false, false, false);
if (iPixelFormat == -1) {
wglDeleteContext(dummy_hglrc);
closeWindow(dummy_hwnd, dummy_hdc);
throwException(env, "Could not choose pixel formats.");
return (jint)NULL;
}
HPBUFFERARB Pbuffer;
@ -112,10 +142,12 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
pBufferAttribList[i] = 0;
Pbuffer = wglCreatePbufferARB(hdc, iPixelFormat, width, height, pBufferAttribList);
Pbuffer = wglCreatePbufferARB(dummy_hdc, iPixelFormat, width, height, pBufferAttribList);
} else {
Pbuffer = wglCreatePbufferARB(hdc, iPixelFormat, width, height, NULL);
Pbuffer = wglCreatePbufferARB(dummy_hdc, iPixelFormat, width, height, NULL);
}
wglDeleteContext(dummy_hglrc);
closeWindow(dummy_hwnd, dummy_hdc);
if (Pbuffer == NULL) {
throwException(env, "Could not create Pbuffer.");
@ -138,13 +170,12 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
return (jint)NULL;
}
if (!wglShareLists(hglrc, Pbuffer_context)) {
if (display_hglrc != NULL && !wglShareLists(display_hglrc, Pbuffer_context)) {
wglDeleteContext(Pbuffer_context);
wglReleasePbufferDCARB(Pbuffer, Pbuffer_dc);
wglDestroyPbufferARB(Pbuffer);
throwException(env, "Could not share buffer context.");
return (jint)NULL;
}
PbufferInfo *Pbuffer_info = (PbufferInfo *)malloc(sizeof(PbufferInfo));
@ -158,7 +189,7 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nReleaseContext
(JNIEnv *env, jclass clazz)
{
wglMakeCurrent(hdc, hglrc);
wglMakeCurrent(display_hdc, display_hglrc);
}
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Pbuffer_nIsBufferLost