Win32: Make pbuffer creation independent of display context
This commit is contained in:
parent
39c06a14ab
commit
19b7f16291
|
@ -52,20 +52,29 @@
|
||||||
#else
|
#else
|
||||||
#define WINDOW_H_API extern
|
#define WINDOW_H_API extern
|
||||||
|
|
||||||
extern HWND hwnd; // Handle to the window
|
extern HWND display_hwnd; // Handle to the window
|
||||||
extern HDC hdc; // Device context
|
extern HDC display_hdc; // Device context
|
||||||
extern bool isFullScreen; // Whether we're fullscreen or not
|
extern bool isFullScreen; // Whether we're fullscreen or not
|
||||||
extern bool isMinimized; // Whether we're minimized or not
|
extern bool isMinimized; // Whether we're minimized or not
|
||||||
extern bool isFocused; // Whether we're focused or not
|
extern bool isFocused; // Whether we're focused or not
|
||||||
extern bool isDirty; // Whether we're dirty or not
|
extern bool isDirty; // Whether we're dirty or not
|
||||||
extern RECT clientSize;
|
extern RECT clientSize;
|
||||||
extern HGLRC hglrc;
|
extern HGLRC display_hglrc;
|
||||||
#endif /* _PRIVATE_WINDOW_H_ */
|
#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
|
* 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
|
* Create a window with the specified title, position, size, and
|
||||||
|
@ -74,7 +83,7 @@
|
||||||
*
|
*
|
||||||
* Returns true for success, or false for failure
|
* 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);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -42,9 +42,7 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include "org_lwjgl_Sys.h"
|
#include "org_lwjgl_Sys.h"
|
||||||
#include "common_tools.h"
|
#include "common_tools.h"
|
||||||
|
#include "Window.h"
|
||||||
// Handle to the application's window
|
|
||||||
extern HWND hwnd;
|
|
||||||
|
|
||||||
unsigned __int64 hires_timer_freq = 0; // Hires timer frequency
|
unsigned __int64 hires_timer_freq = 0; // Hires timer frequency
|
||||||
unsigned __int64 hires_timer = 0; // Hires timer current time
|
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;
|
jboolean copy = JNI_FALSE;
|
||||||
const char * eMessageText = env->GetStringUTFChars(message, ©);
|
const char * eMessageText = env->GetStringUTFChars(message, ©);
|
||||||
const char * cTitleBarText = env->GetStringUTFChars(title, ©);
|
const char * cTitleBarText = env->GetStringUTFChars(title, ©);
|
||||||
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);
|
printfDebug("*** Alert ***%s\n%s\n", cTitleBarText, eMessageText);
|
||||||
|
|
||||||
|
|
|
@ -53,7 +53,6 @@
|
||||||
#define CONTROLLER_AXISMIN -1000 // Minimum range to which we'll gauge the swing
|
#define CONTROLLER_AXISMIN -1000 // Minimum range to which we'll gauge the swing
|
||||||
|
|
||||||
extern HINSTANCE dll_handle;
|
extern HINSTANCE dll_handle;
|
||||||
extern HWND hwnd;
|
|
||||||
|
|
||||||
static IDirectInput* cDI; // DI instance
|
static IDirectInput* cDI; // DI instance
|
||||||
static IDirectInputDevice2* cDIDevice; // DI Device 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
|
* Called when the Controller instance is to be created
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jclass clazz) {
|
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.
|
// Create the DirectInput object.
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &cDI, NULL);
|
hr = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &cDI, NULL);
|
||||||
|
@ -326,7 +318,7 @@ static void SetupController() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the cooperative level
|
// 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");
|
printfDebug("SetCooperativeLevel failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -70,7 +70,7 @@ JNIEXPORT jlong JNICALL Java_org_lwjgl_input_Cursor_nCreateCursor
|
||||||
bitmapInfo.bmiHeader.biBitCount = 24;
|
bitmapInfo.bmiHeader.biBitCount = 24;
|
||||||
bitmapInfo.bmiHeader.biCompression = BI_RGB;
|
bitmapInfo.bmiHeader.biCompression = BI_RGB;
|
||||||
|
|
||||||
colorDIB = CreateDIBSection(hdc, (BITMAPINFO*)&(bitmapInfo),
|
colorDIB = CreateDIBSection(GetDC(NULL), (BITMAPINFO*)&(bitmapInfo),
|
||||||
DIB_RGB_COLORS,
|
DIB_RGB_COLORS,
|
||||||
(void**)&(ptrCursorImage),
|
(void**)&(ptrCursorImage),
|
||||||
NULL, 0);
|
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,
|
(BITMAPINFOHEADER*)&bitmapInfo.bmiHeader,
|
||||||
CBM_INIT,
|
CBM_INIT,
|
||||||
(void *)ptrCursorImage,
|
(void *)ptrCursorImage,
|
||||||
|
|
|
@ -81,7 +81,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hwnd == NULL) {
|
if (display_hwnd == NULL) {
|
||||||
throwException(env, "No window.");
|
throwException(env, "No window.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Keyboard_nCreate
|
||||||
return;
|
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.");
|
throwException(env, "Failed to set keyboard cooperation mode.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ void UpdateMouseFields(JNIEnv *env, jclass clsMouse, jobject coord_buffer_obj, j
|
||||||
|
|
||||||
static void getScreenClientRect(RECT* clientRect, RECT* windowRect)
|
static void getScreenClientRect(RECT* clientRect, RECT* windowRect)
|
||||||
{
|
{
|
||||||
GetClientRect(hwnd, clientRect);
|
GetClientRect(display_hwnd, clientRect);
|
||||||
// transform clientRect to screen coordinates
|
// transform clientRect to screen coordinates
|
||||||
clientRect->top = -clientSize.top + windowRect->top;
|
clientRect->top = -clientSize.top + windowRect->top;
|
||||||
clientRect->left = -clientSize.left + windowRect->left;
|
clientRect->left = -clientSize.left + windowRect->left;
|
||||||
|
@ -228,14 +228,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nSetNativeCursor
|
||||||
throwException(env, "null device!");
|
throwException(env, "null device!");
|
||||||
if (cursor_handle != 0) {
|
if (cursor_handle != 0) {
|
||||||
HCURSOR cursor = (HCURSOR)cursor_handle;
|
HCURSOR cursor = (HCURSOR)cursor_handle;
|
||||||
SetClassLong(hwnd, GCL_HCURSOR, (LONG)cursor);
|
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)cursor);
|
||||||
SetCursor(cursor);
|
SetCursor(cursor);
|
||||||
if (!usingNativeCursor) {
|
if (!usingNativeCursor) {
|
||||||
usingNativeCursor = true;
|
usingNativeCursor = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (usingNativeCursor) {
|
if (usingNativeCursor) {
|
||||||
SetClassLong(hwnd, GCL_HCURSOR, (LONG)NULL);
|
SetClassLong(display_hwnd, GCL_HCURSOR, (LONG)NULL);
|
||||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||||
usingNativeCursor = false;
|
usingNativeCursor = false;
|
||||||
}
|
}
|
||||||
|
@ -300,14 +300,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Mouse_nGrabMouse
|
||||||
|
|
||||||
/* Reset cursor position to middle of the window */
|
/* Reset cursor position to middle of the window */
|
||||||
RECT clientRect;
|
RECT clientRect;
|
||||||
GetWindowRect(hwnd, &windowRect);
|
GetWindowRect(display_hwnd, &windowRect);
|
||||||
getScreenClientRect(&clientRect, &windowRect);
|
getScreenClientRect(&clientRect, &windowRect);
|
||||||
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
||||||
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
||||||
SetCursorPos(cursorPos.x, cursorPos.y);
|
SetCursorPos(cursorPos.x, cursorPos.y);
|
||||||
}
|
}
|
||||||
mDIDevice->Unacquire();
|
mDIDevice->Unacquire();
|
||||||
if(mDIDevice->SetCooperativeLevel(hwnd, mouseMask) != DI_OK) {
|
if(mDIDevice->SetCooperativeLevel(display_hwnd, mouseMask) != DI_OK) {
|
||||||
throwException(env, "Could not set the CooperativeLevel.");
|
throwException(env, "Could not set the CooperativeLevel.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -403,7 +403,7 @@ static void SetupMouse() {
|
||||||
mDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
|
mDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
|
||||||
|
|
||||||
// set the cooperative level
|
// set the cooperative level
|
||||||
if(mDIDevice->SetCooperativeLevel(hwnd, mouseMask) != DI_OK) {
|
if(mDIDevice->SetCooperativeLevel(display_hwnd, mouseMask) != DI_OK) {
|
||||||
printfDebug("SetCooperativeLevel failed\n");
|
printfDebug("SetCooperativeLevel failed\n");
|
||||||
mCreate_success = false;
|
mCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -412,7 +412,7 @@ static void SetupMouse() {
|
||||||
|
|
||||||
/* Reset cursor position to middle of the window */
|
/* Reset cursor position to middle of the window */
|
||||||
RECT clientRect;
|
RECT clientRect;
|
||||||
GetWindowRect(hwnd, &windowRect);
|
GetWindowRect(display_hwnd, &windowRect);
|
||||||
getScreenClientRect(&clientRect, &windowRect);
|
getScreenClientRect(&clientRect, &windowRect);
|
||||||
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
cursorPos.x = (clientRect.left + clientRect.right)/2;
|
||||||
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
cursorPos.y = clientRect.bottom - 1 - (clientRect.bottom - clientRect.top)/2;
|
||||||
|
@ -436,7 +436,7 @@ static void getGDICursorDelta(int* return_dx, int* return_dy) {
|
||||||
GetCursorPos(&newCursorPos);
|
GetCursorPos(&newCursorPos);
|
||||||
RECT clientRect;
|
RECT clientRect;
|
||||||
RECT newWindowRect;
|
RECT newWindowRect;
|
||||||
GetWindowRect(hwnd, &newWindowRect);
|
GetWindowRect(display_hwnd, &newWindowRect);
|
||||||
cursorPos.x += newWindowRect.left - windowRect.left;
|
cursorPos.x += newWindowRect.left - windowRect.left;
|
||||||
cursorPos.y += newWindowRect.top - windowRect.top;
|
cursorPos.y += newWindowRect.top - windowRect.top;
|
||||||
windowRect = newWindowRect;
|
windowRect = newWindowRect;
|
||||||
|
|
|
@ -49,9 +49,9 @@
|
||||||
|
|
||||||
static bool oneShotInitialised = false; // Registers the LWJGL window class
|
static bool oneShotInitialised = false; // Registers the LWJGL window class
|
||||||
|
|
||||||
HWND hwnd = NULL; // Handle to the window
|
HWND display_hwnd = NULL; // Handle to the window
|
||||||
HDC hdc = NULL; // Device context
|
HDC display_hdc = NULL; // Device context
|
||||||
HGLRC hglrc = NULL; // OpenGL context
|
HGLRC display_hglrc = NULL; // OpenGL context
|
||||||
static bool isFullScreen = false; // Whether we're fullscreen or not
|
static bool isFullScreen = false; // Whether we're fullscreen or not
|
||||||
static bool isMinimized = false; // Whether we're minimized or not
|
static bool isMinimized = false; // Whether we're minimized or not
|
||||||
static bool isFocused = false; // whether we're focused or not
|
static bool isFocused = false; // whether we're focused or not
|
||||||
|
@ -65,7 +65,7 @@ static int pixel_format_index;
|
||||||
|
|
||||||
#define WINDOWCLASSNAME "LWJGL"
|
#define WINDOWCLASSNAME "LWJGL"
|
||||||
|
|
||||||
static bool applyPixelFormat(JNIEnv *env, HDC hdc, int iPixelFormat) {
|
bool applyPixelFormat(JNIEnv *env, HDC hdc, int iPixelFormat) {
|
||||||
PIXELFORMATDESCRIPTOR desc;
|
PIXELFORMATDESCRIPTOR desc;
|
||||||
if (DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &desc) == 0) {
|
if (DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &desc) == 0) {
|
||||||
throwException(env, "Could not describe pixel format");
|
throwException(env, "Could not describe pixel format");
|
||||||
|
@ -80,7 +80,7 @@ static bool applyPixelFormat(JNIEnv *env, HDC hdc, int iPixelFormat) {
|
||||||
return true;
|
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);
|
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
||||||
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
|
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"));
|
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;
|
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;
|
int bpp;
|
||||||
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
||||||
if (use_hdc_bpp) {
|
if (use_hdc_bpp) {
|
||||||
bpp = GetDeviceCaps(hdc, BITSPIXEL);
|
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)
|
if (iPixelFormat == -1)
|
||||||
bpp = 16;
|
bpp = 16;
|
||||||
else
|
else
|
||||||
return iPixelFormat;
|
return iPixelFormat;
|
||||||
} else
|
} else
|
||||||
bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "bpp", "I"));
|
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
|
* 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);
|
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
||||||
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
|
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;
|
return iPixelFormat;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int findPixelFormat(JNIEnv *env, jobject pixel_format) {
|
int findPixelFormat(JNIEnv *env, HDC hdc, jobject pixel_format) {
|
||||||
int bpp;
|
int bpp;
|
||||||
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
||||||
bpp = GetDeviceCaps(hdc, BITSPIXEL);
|
bpp = GetDeviceCaps(hdc, BITSPIXEL);
|
||||||
int iPixelFormat = findPixelFormatFromBPP(env, pixel_format, bpp);
|
int iPixelFormat = findPixelFormatFromBPP(env, hdc, pixel_format, bpp);
|
||||||
if (iPixelFormat == -1) {
|
if (iPixelFormat == -1) {
|
||||||
return findPixelFormatFromBPP(env, pixel_format, 16);
|
return findPixelFormatFromBPP(env, hdc, pixel_format, 16);
|
||||||
} else
|
} else
|
||||||
return iPixelFormat;
|
return iPixelFormat;
|
||||||
}
|
}
|
||||||
|
@ -254,7 +254,7 @@ static int findPixelFormat(JNIEnv *env, jobject pixel_format) {
|
||||||
/*
|
/*
|
||||||
* Close the window
|
* Close the window
|
||||||
*/
|
*/
|
||||||
static void closeWindow()
|
void closeWindow(HWND hwnd, HDC hdc)
|
||||||
{
|
{
|
||||||
// Release device context
|
// Release device context
|
||||||
if (hdc != NULL && hwnd != NULL) {
|
if (hdc != NULL && hwnd != NULL) {
|
||||||
|
@ -278,10 +278,10 @@ static void closeWindow()
|
||||||
static void appActivate(bool active)
|
static void appActivate(bool active)
|
||||||
{
|
{
|
||||||
if (active) {
|
if (active) {
|
||||||
SetForegroundWindow(hwnd);
|
SetForegroundWindow(display_hwnd);
|
||||||
ShowWindow(hwnd, SW_RESTORE);
|
ShowWindow(display_hwnd, SW_RESTORE);
|
||||||
} else if (isFullScreen) {
|
} 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;
|
MSG msg;
|
||||||
while (PeekMessage(
|
while (PeekMessage(
|
||||||
&msg, // message information
|
&msg, // message information
|
||||||
hwnd, // handle to window
|
display_hwnd, // handle to window
|
||||||
0, // first message
|
0, // first message
|
||||||
0, // last message
|
0, // last message
|
||||||
PM_REMOVE // removal options
|
PM_REMOVE // removal options
|
||||||
|
@ -409,10 +409,16 @@ static void handleMessages(JNIEnv * env, jclass clazz)
|
||||||
*
|
*
|
||||||
* Returns true for success, or false for failure
|
* 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;
|
int exstyle, windowflags;
|
||||||
|
|
||||||
|
// 1. Register window class if necessary
|
||||||
|
if (!registerWindow()) {
|
||||||
|
throwException(env, "Could not register window class");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (fullscreen) {
|
if (fullscreen) {
|
||||||
exstyle = WS_EX_APPWINDOW | WS_EX_TOPMOST;
|
exstyle = WS_EX_APPWINDOW | WS_EX_TOPMOST;
|
||||||
windowflags = WS_POPUP;
|
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:
|
// Create the window now, using that class:
|
||||||
hwnd = CreateWindowEx (
|
HWND new_hwnd = CreateWindowEx (
|
||||||
exstyle,
|
exstyle,
|
||||||
WINDOWCLASSNAME,
|
WINDOWCLASSNAME,
|
||||||
"",
|
"",
|
||||||
|
@ -450,13 +456,12 @@ static bool createWindow(JNIEnv *env, int width, int height, bool fullscreen, bo
|
||||||
dll_handle,
|
dll_handle,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
if (hwnd == NULL) {
|
if (new_hwnd == NULL) {
|
||||||
throwException(env, "Failed to create the window.");
|
throwException(env, "Failed to create the window.");
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
hdc = GetDC(hwnd);
|
return new_hwnd;
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -468,7 +473,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetTitle
|
||||||
(JNIEnv * env, jclass clazz, jstring title_obj)
|
(JNIEnv * env, jclass clazz, jstring title_obj)
|
||||||
{
|
{
|
||||||
const char * title = env->GetStringUTFChars(title_obj, NULL);
|
const char * title = env->GetStringUTFChars(title_obj, NULL);
|
||||||
SetWindowText(hwnd, title);
|
SetWindowText(display_hwnd, title);
|
||||||
env->ReleaseStringUTFChars(title_obj, title);
|
env->ReleaseStringUTFChars(title_obj, title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,8 +498,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_swapBuffers
|
||||||
(JNIEnv * env, jclass clazz)
|
(JNIEnv * env, jclass clazz)
|
||||||
{
|
{
|
||||||
isDirty = false;
|
isDirty = false;
|
||||||
SwapBuffers(hdc);
|
SwapBuffers(display_hdc);
|
||||||
// wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -561,7 +565,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nSetVSyncEnabled
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nMakeCurrent
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nMakeCurrent
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
BOOL result = wglMakeCurrent(hdc, hglrc);
|
BOOL result = wglMakeCurrent(display_hdc, display_hglrc);
|
||||||
if (!result)
|
if (!result)
|
||||||
throwException(env, "Could not make display context current");
|
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 width = env->GetIntField(mode, fid_width);
|
||||||
int height = env->GetIntField(mode, fid_height);
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (!applyPixelFormat(env, hdc, pixel_format_index)) {
|
display_hdc = GetDC(display_hwnd);
|
||||||
closeWindow();
|
if (!applyPixelFormat(env, display_hdc, pixel_format_index)) {
|
||||||
|
closeWindow(display_hwnd, display_hdc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL result = wglMakeCurrent(hdc, hglrc);
|
BOOL result = wglMakeCurrent(display_hdc, display_hglrc);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throwException(env, "Could not bind context to window");
|
throwException(env, "Could not bind context to window");
|
||||||
closeWindow();
|
closeWindow(display_hwnd, display_hdc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
extgl_InitWGL(env);
|
extgl_InitWGL(env);
|
||||||
ShowWindow(hwnd, SW_SHOW);
|
ShowWindow(display_hwnd, SW_SHOW);
|
||||||
UpdateWindow(hwnd);
|
UpdateWindow(display_hwnd);
|
||||||
SetForegroundWindow(hwnd);
|
SetForegroundWindow(display_hwnd);
|
||||||
SetFocus(hwnd);
|
SetFocus(display_hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_nDestroyWindow(JNIEnv *env, jclass clazz) {
|
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) {
|
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) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_createContext(JNIEnv *env, jclass clazz, jobject pixel_format) {
|
||||||
// 1. Register window class if necessary
|
HWND dummy_hwnd = createWindow(env, 1, 1, false, false);
|
||||||
if (!registerWindow()) {
|
if (dummy_hwnd == NULL) {
|
||||||
throwException(env, "Could not register window class");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
HDC dummy_hdc = GetDC(dummy_hwnd);
|
||||||
if (!createWindow(env, 1, 1, false, false)) {
|
pixel_format_index = findPixelFormat(env, dummy_hdc, pixel_format);
|
||||||
return;
|
|
||||||
}
|
|
||||||
pixel_format_index = findPixelFormat(env, pixel_format);
|
|
||||||
if (pixel_format_index == -1) {
|
if (pixel_format_index == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Special option for allowing software opengl
|
if (!applyPixelFormat(env, dummy_hdc, pixel_format_index)) {
|
||||||
if (!applyPixelFormat(env, hdc, pixel_format_index)) {
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
closeWindow();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hglrc = wglCreateContext(hdc);
|
display_hglrc = wglCreateContext(dummy_hdc);
|
||||||
if (hglrc == NULL) {
|
if (display_hglrc == NULL) {
|
||||||
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
throwException(env, "Failed to create OpenGL rendering context");
|
throwException(env, "Failed to create OpenGL rendering context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BOOL result = wglMakeCurrent(hdc, hglrc);
|
BOOL result = wglMakeCurrent(dummy_hdc, display_hglrc);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throwException(env, "Could not bid context to dummy window");
|
throwException(env, "Could not bind context to dummy window");
|
||||||
wglDeleteContext(hglrc);
|
wglDeleteContext(display_hglrc);
|
||||||
closeWindow();
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Some crazy strangeness here so we can use ARB_pixel_format to specify the number
|
// 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.
|
// rendering context and start over, using the ARB extension instead to pick the context.
|
||||||
extgl_InitWGL(env);
|
extgl_InitWGL(env);
|
||||||
if (extgl_Extensions.WGL_ARB_pixel_format) {
|
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);
|
wglMakeCurrent(NULL, NULL);
|
||||||
wglDeleteContext(hglrc);
|
wglDeleteContext(display_hglrc);
|
||||||
closeWindow();
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
if (pixel_format_index == -1) {
|
if (pixel_format_index == -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!createWindow(env, 1, 1, false, false)) {
|
dummy_hwnd = createWindow(env, 1, 1, false, false);
|
||||||
|
if (dummy_hwnd == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!applyPixelFormat(env, hdc, pixel_format_index)) {
|
dummy_hdc = GetDC(dummy_hwnd);
|
||||||
closeWindow();
|
if (!applyPixelFormat(env, dummy_hdc, pixel_format_index)) {
|
||||||
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
hglrc = wglCreateContext(hdc);
|
display_hglrc = wglCreateContext(dummy_hdc);
|
||||||
closeWindow();
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
if (hglrc == NULL) {
|
if (display_hglrc == NULL) {
|
||||||
throwException(env, "Failed to create OpenGL rendering context (ARB)");
|
throwException(env, "Failed to create OpenGL rendering context (ARB)");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
closeWindow();
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_destroyContext(JNIEnv *env, jclass clazz) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Display_destroyContext(JNIEnv *env, jclass clazz) {
|
||||||
wglMakeCurrent(NULL, NULL);
|
wglMakeCurrent(NULL, NULL);
|
||||||
|
|
||||||
// Delete the rendering context
|
// Delete the rendering context
|
||||||
if (hglrc != NULL) {
|
if (display_hglrc != NULL) {
|
||||||
printfDebug("Deleting GL context\n");
|
printfDebug("Deleting GL context\n");
|
||||||
wglDeleteContext(hglrc);
|
wglDeleteContext(display_hglrc);
|
||||||
hglrc = NULL;
|
display_hglrc = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,11 +91,41 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
|
||||||
jint width, jint height, jobject pixel_format,
|
jint width, jint height, jobject pixel_format,
|
||||||
jobject pixelFormatCaps, jobject pBufferAttribs)
|
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) {
|
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.");
|
throwException(env, "Could not choose pixel formats.");
|
||||||
return (jint)NULL;
|
return (jint)NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HPBUFFERARB Pbuffer;
|
HPBUFFERARB Pbuffer;
|
||||||
|
@ -112,10 +142,12 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
|
||||||
|
|
||||||
pBufferAttribList[i] = 0;
|
pBufferAttribList[i] = 0;
|
||||||
|
|
||||||
Pbuffer = wglCreatePbufferARB(hdc, iPixelFormat, width, height, pBufferAttribList);
|
Pbuffer = wglCreatePbufferARB(dummy_hdc, iPixelFormat, width, height, pBufferAttribList);
|
||||||
} else {
|
} 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) {
|
if (Pbuffer == NULL) {
|
||||||
throwException(env, "Could not create Pbuffer.");
|
throwException(env, "Could not create Pbuffer.");
|
||||||
|
@ -138,13 +170,12 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
|
||||||
return (jint)NULL;
|
return (jint)NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wglShareLists(hglrc, Pbuffer_context)) {
|
if (display_hglrc != NULL && !wglShareLists(display_hglrc, Pbuffer_context)) {
|
||||||
wglDeleteContext(Pbuffer_context);
|
wglDeleteContext(Pbuffer_context);
|
||||||
wglReleasePbufferDCARB(Pbuffer, Pbuffer_dc);
|
wglReleasePbufferDCARB(Pbuffer, Pbuffer_dc);
|
||||||
wglDestroyPbufferARB(Pbuffer);
|
wglDestroyPbufferARB(Pbuffer);
|
||||||
throwException(env, "Could not share buffer context.");
|
throwException(env, "Could not share buffer context.");
|
||||||
return (jint)NULL;
|
return (jint)NULL;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PbufferInfo *Pbuffer_info = (PbufferInfo *)malloc(sizeof(PbufferInfo));
|
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
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nReleaseContext
|
||||||
(JNIEnv *env, jclass clazz)
|
(JNIEnv *env, jclass clazz)
|
||||||
{
|
{
|
||||||
wglMakeCurrent(hdc, hglrc);
|
wglMakeCurrent(display_hdc, display_hglrc);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Pbuffer_nIsBufferLost
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Pbuffer_nIsBufferLost
|
||||||
|
|
Loading…
Reference in New Issue