Converted win32 specific native source from C++->C (removes the strange debug flag behaviour exhibited by SourceLimitTest.java)

This commit is contained in:
Elias Naur 2004-12-09 15:36:13 +00:00
parent 3640f60f47
commit 46967b394c
10 changed files with 390 additions and 310 deletions

View File

@ -57,7 +57,6 @@ static WORD currentGamma[GAMMA_SIZE]; // Current gamma settings
static DEVMODE devmode; // Now we'll remember this value for the future
extern HWND display_hwnd; // Handle to the window
extern RECT clientSize;
static char * driver = getDriver();
jobjectArray getAvailableDisplayModes(JNIEnv *env)
{
@ -79,6 +78,17 @@ static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
EnumDisplaySettingsExAPROC EnumDisplaySettingsExA;
HMODULE lib_handle = LoadLibrary("user32.dll");
int i = 0, j = 0, n = 0;
int AvailableModes = 0;
DISPLAY_DEVICE DisplayDevice;
DEVMODE DevMode;
jclass displayModeClass;
jobjectArray ret;
jmethodID displayModeConstructor;
if (lib_handle == NULL) {
printfDebug("Could not load user32.dll\n");
return NULL;
@ -90,12 +100,6 @@ static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
if (EnumDisplaySettingsExA == NULL)
return NULL;
int i = 0, j = 0, n = 0;
int AvailableModes = 0;
DISPLAY_DEVICE DisplayDevice;
DEVMODE DevMode;
ZeroMemory(&DevMode, sizeof(DEVMODE));
ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE));
@ -123,10 +127,10 @@ static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java
// Allocate an array of DisplayModes big enough
jclass displayModeClass = env->FindClass("org/lwjgl/opengl/DisplayMode");
displayModeClass = (*env)->FindClass(env, "org/lwjgl/opengl/DisplayMode");
jobjectArray ret = env->NewObjectArray(AvailableModes, displayModeClass, NULL);
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
ret = (*env)->NewObjectArray(env, AvailableModes, displayModeClass, NULL);
displayModeConstructor = (*env)->GetMethodID(env, displayModeClass, "<init>", "(IIII)V");
i = 0, n = 0;
while(EnumDisplayDevicesA(NULL, i++, &DisplayDevice, 0) != 0) {
@ -140,11 +144,11 @@ static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
// Filter out indexed modes
if (DevMode.dmBitsPerPel > 8 && ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN | CDS_TEST) == DISP_CHANGE_SUCCESSFUL) {
jobject displayMode;
displayMode = env->NewObject(displayModeClass, displayModeConstructor,
displayMode = (*env)->NewObject(env, displayModeClass, displayModeConstructor,
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
env->SetObjectArrayElement(ret, n++, displayMode);
(*env)->SetObjectArrayElement(env, ret, n++, displayMode);
}
}
}
@ -161,6 +165,11 @@ static jobjectArray GetAvailableDisplayModes(JNIEnv * env) {
DEVMODE DevMode;
jclass displayModeClass;
jobjectArray ret;
jmethodID displayModeConstructor;
ZeroMemory(&DevMode, sizeof(DEVMODE));
DevMode.dmSize = sizeof(DEVMODE);
@ -176,20 +185,20 @@ static jobjectArray GetAvailableDisplayModes(JNIEnv * env) {
// now that we have the count create the classes, and add 'em all - we'll remove dups in Java
// Allocate an array of DisplayModes big enough
jclass displayModeClass = env->FindClass("org/lwjgl/opengl/DisplayMode");
displayModeClass = (*env)->FindClass(env, "org/lwjgl/opengl/DisplayMode");
jobjectArray ret = env->NewObjectArray(AvailableModes, displayModeClass, NULL);
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
ret = (*env)->NewObjectArray(env, AvailableModes, displayModeClass, NULL);
displayModeConstructor = (*env)->GetMethodID(env, displayModeClass, "<init>", "(IIII)V");
i = 0, j = 0, n = 0;
while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) {
// Filter out indexed modes
if (DevMode.dmBitsPerPel > 8 && ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN | CDS_TEST) == DISP_CHANGE_SUCCESSFUL) {
jobject displayMode;
displayMode = env->NewObject(displayModeClass, displayModeConstructor,
displayMode = (*env)->NewObject(env, displayModeClass, displayModeConstructor,
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
env->SetObjectArrayElement(ret, n++, displayMode);
(*env)->SetObjectArrayElement(env, ret, n++, displayMode);
}
}
return ret;
@ -197,16 +206,17 @@ static jobjectArray GetAvailableDisplayModes(JNIEnv * env) {
void switchDisplayMode(JNIEnv * env, jobject mode)
{
jclass cls_displayMode = env->GetObjectClass(mode);
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
jfieldID fid_bpp = env->GetFieldID(cls_displayMode, "bpp", "I");
jfieldID fid_freq = env->GetFieldID(cls_displayMode, "freq", "I");
jclass cls_displayMode = (*env)->GetObjectClass(env, mode);
jfieldID fid_width = (*env)->GetFieldID(env, cls_displayMode, "width", "I");
jfieldID fid_height = (*env)->GetFieldID(env, cls_displayMode, "height", "I");
jfieldID fid_bpp = (*env)->GetFieldID(env, cls_displayMode, "bpp", "I");
jfieldID fid_freq = (*env)->GetFieldID(env, cls_displayMode, "freq", "I");
int width = env->GetIntField(mode, fid_width);
int height = env->GetIntField(mode, fid_height);
int bpp = env->GetIntField(mode, fid_bpp);
int freq = env->GetIntField(mode, fid_freq);
int width = (*env)->GetIntField(env, mode, fid_width);
int height = (*env)->GetIntField(env, mode, fid_height);
int bpp = (*env)->GetIntField(env, mode, fid_bpp);
int freq = (*env)->GetIntField(env, mode, fid_freq);
LONG cdsret;
devmode.dmSize = sizeof(DEVMODE);
devmode.dmBitsPerPel = bpp;
@ -217,7 +227,7 @@ void switchDisplayMode(JNIEnv * env, jobject mode)
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS;
if (freq != 0)
devmode.dmFields |= DM_DISPLAYFREQUENCY;
LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
// Failed: so let's check to see if it's a wierd dual screen display
@ -241,17 +251,21 @@ int getGammaRampLength(void)
void setGammaRamp(JNIEnv * env, jobject gammaRampBuffer)
{
const float *gammaRamp = (const float *)env->GetDirectBufferAddress(gammaRampBuffer);
int i;
float scaledRampEntry;
WORD rampEntry;
HDC screenDC;
const float *gammaRamp = (const float *)(*env)->GetDirectBufferAddress(env, gammaRampBuffer);
// Turn array of floats into array of RGB WORDs
for (int i = 0; i < 256; i ++) {
float scaledRampEntry = gammaRamp[i]*0xffff;
WORD rampEntry = (WORD)scaledRampEntry;
for (i = 0; i < 256; i ++) {
scaledRampEntry = gammaRamp[i]*0xffff;
rampEntry = (WORD)scaledRampEntry;
currentGamma[i] = rampEntry;
currentGamma[i + 256] = rampEntry;
currentGamma[i + 512] = rampEntry;
}
HDC screenDC = GetDC(NULL);
screenDC = GetDC(NULL);
if (SetDeviceGammaRamp(screenDC, currentGamma) == FALSE) {
throwException(env, "Failed to set device gamma.");
}
@ -261,6 +275,13 @@ void setGammaRamp(JNIEnv * env, jobject gammaRampBuffer)
jobject initDisplay(JNIEnv * env)
{
int width;
int height;
int bpp;
int freq;
jclass jclass_DisplayMode;
jmethodID ctor;
jobject newMode;
// Determine the current screen resolution
// Get the screen
HDC screenDC = GetDC(NULL);
@ -269,16 +290,16 @@ jobject initDisplay(JNIEnv * env)
return NULL;
}
// Get the device caps
int width = GetDeviceCaps(screenDC, HORZRES);
int height = GetDeviceCaps(screenDC, VERTRES);
int bpp = GetDeviceCaps(screenDC, BITSPIXEL);
int freq = GetDeviceCaps(screenDC, VREFRESH);
width = GetDeviceCaps(screenDC, HORZRES);
height = GetDeviceCaps(screenDC, VERTRES);
bpp = GetDeviceCaps(screenDC, BITSPIXEL);
freq = GetDeviceCaps(screenDC, VREFRESH);
if (freq <= 1)
freq = 0; // Unknown
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/opengl/DisplayMode");
jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V");
jobject newMode = env->NewObject(jclass_DisplayMode, ctor, width, height, bpp, freq);
jclass_DisplayMode = (*env)->FindClass(env, "org/lwjgl/opengl/DisplayMode");
ctor = (*env)->GetMethodID(env, jclass_DisplayMode, "<init>", "(IIII)V");
newMode = (*env)->NewObject(env, jclass_DisplayMode, ctor, width, height, bpp, freq);
// Get the default gamma ramp
if (GetDeviceGammaRamp(screenDC, originalGamma) == FALSE) {
@ -314,6 +335,7 @@ void resetDisplayMode(JNIEnv * env) {
void restoreDisplayMode(void) {
// Restore gamma
HDC screenDC = GetDC(NULL);
LONG cdsret;
if (!SetDeviceGammaRamp(screenDC, currentGamma)) {
printfDebug("Could not restore device gamma\n");
}
@ -322,7 +344,7 @@ void restoreDisplayMode(void) {
if (!modeSet) {
printfDebug("Attempting to restore the display mode\n");
modeSet = true;
LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
printfDebug("Failed to restore display mode\n");
@ -391,6 +413,7 @@ jstring getAdapter(JNIEnv * env)
{
jstring ret = NULL;
char *driver = getDriver();
if (driver == NULL) {
return NULL;
}
@ -405,16 +428,20 @@ jstring getVersion(JNIEnv * env)
jstring ret = NULL;
TCHAR driverDLL[256] = "\0";
DWORD var = 0;
DWORD dwInfoSize;
LPVOID lpInfoBuff;
BOOL bRetval;
char *driver = getDriver();
if (driver == NULL) {
return NULL;
}
strcat(driverDLL, driver);
strcat(driverDLL, ".dll");
DWORD var = 0;
DWORD dwInfoSize = GetFileVersionInfoSize(driverDLL, &var);
LPVOID lpInfoBuff = new unsigned char[dwInfoSize];
BOOL bRetval = GetFileVersionInfo(driverDLL, NULL, dwInfoSize, lpInfoBuff);
dwInfoSize = GetFileVersionInfoSize(driverDLL, &var);
lpInfoBuff = malloc(dwInfoSize);
bRetval = GetFileVersionInfo(driverDLL, 0, dwInfoSize, lpInfoBuff);
if (bRetval == 0) {
} else {
VS_FIXEDFILEINFO * fxdFileInfo;
@ -431,7 +458,7 @@ jstring getVersion(JNIEnv * env)
}
}
delete lpInfoBuff;
free(lpInfoBuff);
return ret;
}

View File

@ -139,6 +139,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nOpenURL
(JNIEnv * env, jobject self, jstring url)
{
STARTUPINFO si;
PROCESS_INFORMATION pi;
char * urlString = GetStringNativeChars(env, url);
char command[256];
@ -147,9 +150,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nOpenURL
strncat(command, urlString, 200); // Prevent buffer overflow
free(urlString);
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
@ -182,12 +182,12 @@ const void * getClipboard(int type)
{
void * ret;
HANDLE hglb;
// Open the clipboard
if (!OpenClipboard(NULL))
return NULL;
HANDLE hglb = GetClipboardData(type);
hglb = GetClipboardData(type);
if (hglb != NULL) {
ret = GlobalLock(hglb);
if (ret != NULL) {
@ -211,7 +211,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
if (unicodeAvailable) {
const wchar_t * str = (const wchar_t *) getClipboard(CF_UNICODETEXT);
return env->NewString(str, wcslen(str));
return (*env)->NewString(env, str, wcslen(str));
} else if (textAvailable) {
return NewStringNative(env, (const char *) getClipboard(CF_TEXT));
} else {

View File

@ -169,7 +169,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jcla
}
/* Aquire the Controller */
hr = cDIDevice->Acquire();
hr = IDirectInputDevice_Acquire(cDIDevice);
if(FAILED(hr)) {
ShutdownController();
throwException(env, "Acquire failed");
@ -195,13 +195,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll(JNIEnv * env, jclas
HRESULT hRes;
// poll the Controller to read the current state
hRes = cDIDevice->Poll();
hRes = IDirectInputDevice2_Poll(cDIDevice);
if (FAILED(hRes)) {
printfDebug("Poll fail\n");
//check if we need to reaquire
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
cDIDevice->Acquire();
IDirectInputDevice_Acquire(cDIDevice);
printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
}
return;
@ -216,8 +216,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll(JNIEnv * env, jclas
static void ShutdownController() {
// release device
if (cDIDevice != NULL) {
cDIDevice->Unacquire();
cDIDevice->Release();
IDirectInputDevice_Unacquire(cDIDevice);
IDirectInputDevice_Release(cDIDevice);
cDIDevice = NULL;
}
}
@ -227,7 +227,7 @@ static void ShutdownController() {
*/
static void EnumerateControllerCapabilities() {
HRESULT hr;
hr = cDIDevice->EnumObjects(EnumControllerObjectsCallback, NULL, DIDFT_ALL);
hr = IDirectInputDevice_EnumObjects(cDIDevice, EnumControllerObjectsCallback, NULL, DIDFT_ALL);
if FAILED(hr) {
printfDebug("EnumObjects failed\n");
cCreate_success = false;
@ -241,7 +241,7 @@ static void EnumerateControllerCapabilities() {
*/
static void EnumerateControllers() {
HRESULT hr;
hr = cDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY);
hr = IDirectInput_EnumDevices(cDI, DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY);
if FAILED(hr) {
printfDebug("EnumDevices failed\n");
cCreate_success = false;
@ -266,23 +266,23 @@ BOOL CALLBACK EnumControllerCallback(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef) {
*/
BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
printfDebug("found %s\n", lpddoi->tszName);
if(lpddoi->guidType == GUID_Button) {
if(IsEqualGUID(&lpddoi->guidType, &GUID_Button)) {
cButtoncount++;
} else if(lpddoi->guidType == GUID_XAxis) {
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_XAxis)) {
cHasx = true;
} else if(lpddoi->guidType == GUID_YAxis) {
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_YAxis)) {
cHasy = true;
} else if(lpddoi->guidType == GUID_ZAxis){
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_ZAxis)) {
cHasz = true;
} else if (lpddoi->guidType == GUID_POV){
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_POV)) {
cHaspov = true;
} else if (lpddoi->guidType == GUID_Slider){
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_Slider)) {
cHasslider = true;
} else if (lpddoi->guidType == GUID_RxAxis) {
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_RxAxis)) {
cHasrx = true;
} else if (lpddoi->guidType == GUID_RyAxis) {
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_RyAxis)) {
cHasry = true;
} else if (lpddoi->guidType == GUID_RzAxis) {
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_RzAxis)) {
cHasrz = true;
} else {
printfDebug("Unhandled object found: %s\n", lpddoi->tszName);
@ -295,7 +295,7 @@ BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LP
*/
static void CreateController(LPCDIDEVICEINSTANCE lpddi) {
HRESULT hr;
hr = cDI->CreateDevice(lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL);
hr = IDirectInput_CreateDevice(cDI, &lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL);
if FAILED(hr) {
printfDebug("CreateDevice failed\n");
cCreate_success = false;
@ -308,15 +308,16 @@ static void CreateController(LPCDIDEVICEINSTANCE lpddi) {
* Sets up the Controller properties
*/
static void SetupController() {
DIPROPRANGE diprg;
// set Controller data format
if(cDIDevice->SetDataFormat(&c_dfDIJoystick2) != DI_OK) {
if(IDirectInputDevice_SetDataFormat(cDIDevice, &c_dfDIJoystick2) != DI_OK) {
printfDebug("SetDataFormat failed\n");
cCreate_success = false;
return;
}
// set the cooperative level
if(cDIDevice->SetCooperativeLevel(getCurrentHWND(), DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
if(IDirectInputDevice_SetCooperativeLevel(cDIDevice, getCurrentHWND(), DISCL_EXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
printfDebug("SetCooperativeLevel failed\n");
cCreate_success = false;
return;
@ -324,7 +325,6 @@ static void SetupController() {
// set range to (-1000 ... +1000)
// This lets us test against 0 to see which way the stick is pointed.
DIPROPRANGE diprg;
diprg.diph.dwSize = sizeof(diprg);
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
diprg.diph.dwHow = DIPH_BYOFFSET;
@ -334,7 +334,7 @@ static void SetupController() {
// set X-axis
if(cHasx) {
diprg.diph.dwObj = DIJOFS_X;
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
if(IDirectInputDevice_SetProperty(cDIDevice, DIPROP_RANGE, &diprg.diph) != DI_OK) {
printfDebug("SetProperty(DIJOFS_X) failed\n");
cCreate_success = false;
return;
@ -344,7 +344,7 @@ static void SetupController() {
// set RX-axis
if(cHasrx) {
diprg.diph.dwObj = DIJOFS_RX;
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
if(IDirectInputDevice_SetProperty(cDIDevice, DIPROP_RANGE, &diprg.diph) != DI_OK) {
printfDebug("SetProperty(DIJOFS_RX) failed\n");
cCreate_success = false;
return;
@ -355,7 +355,7 @@ static void SetupController() {
// set Y-axis
if(cHasy) {
diprg.diph.dwObj = DIJOFS_Y;
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
if(IDirectInputDevice_SetProperty(cDIDevice, DIPROP_RANGE, &diprg.diph) != DI_OK) {
printfDebug("SetProperty(DIJOFS_Y) failed\n");
cCreate_success = false;
return;
@ -365,7 +365,7 @@ static void SetupController() {
// set RY-axis
if(cHasry) {
diprg.diph.dwObj = DIJOFS_RY;
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
if(IDirectInputDevice_SetProperty(cDIDevice, DIPROP_RANGE, &diprg.diph) != DI_OK) {
printfDebug("SetProperty(DIJOFS_RY) failed\n");
cCreate_success = false;
return;
@ -375,7 +375,7 @@ static void SetupController() {
// set Z-axis
if(cHasz) {
diprg.diph.dwObj = DIJOFS_Z;
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
if(IDirectInputDevice_SetProperty(cDIDevice, DIPROP_RANGE, &diprg.diph) != DI_OK) {
printfDebug("SetProperty(DIJOFS_Z) failed\n");
cCreate_success = false;
return;
@ -386,7 +386,7 @@ static void SetupController() {
// set RZ-axis
if(cHasrz) {
diprg.diph.dwObj = DIJOFS_RZ;
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
if(IDirectInputDevice_SetProperty(cDIDevice, DIPROP_RANGE, &diprg.diph) != DI_OK) {
printfDebug("SetProperty(DIJOFS_RZ) failed\n");
cCreate_success = false;
return;
@ -399,7 +399,7 @@ static void SetupController() {
//
if(cHasslider) {
diprg.diph.dwObj = DIJOFS_Z;
if(cDIDevice->SetProperty(DIPROP_RANGE, &diprg.diph) != DI_OK) {
if(IDirectInputDevice_SetProperty(cDIDevice, DIPROP_RANGE, &diprg.diph) != DI_OK) {
printfDebug("SetProperty(DIJOFS_Z(SLIDER)) failed\n");
cCreate_success = false;
return;
@ -413,26 +413,28 @@ static void SetupController() {
*/
static void InitializeControllerFields(JNIEnv *env, jclass clsController) {
//create buttons array
jbooleanArray cButtonsArray = env->NewBooleanArray(cButtoncount);
jbooleanArray cButtonsArray = (*env)->NewBooleanArray(env, cButtoncount);
//set buttons array
env->SetStaticObjectField(clsController, fidCButtons, cButtonsArray);
(*env)->SetStaticObjectField(env, clsController, fidCButtons, cButtonsArray);
}
/**
* Updates the fields on the Controller
*/
static void UpdateControllerFields(JNIEnv *env, jclass clsController) {
int i;
jbyteArray buttonsArray;
HRESULT hRes;
// get data from the Controller
hRes = cDIDevice->GetDeviceState(sizeof(DIJOYSTATE2), &cJS);
hRes = IDirectInputDevice_GetDeviceState(cDIDevice, sizeof(DIJOYSTATE2), &cJS);
if (hRes != DI_OK) {
// did the read fail because we lost input for some reason?
// if so, then attempt to reacquire.
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
cDIDevice->Acquire();
IDirectInputDevice_Acquire(cDIDevice);
printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
}
printfDebug("Error getting controller state: %d\n", hRes);
@ -441,49 +443,49 @@ static void UpdateControllerFields(JNIEnv *env, jclass clsController) {
//axis's
if(cHasx) {
env->SetStaticIntField(clsController, fidCX, cJS.lX);
(*env)->SetStaticIntField(env, clsController, fidCX, cJS.lX);
}
if(cHasy) {
env->SetStaticIntField(clsController, fidCY, cJS.lY);
(*env)->SetStaticIntField(env, clsController, fidCY, cJS.lY);
}
if(cHasz) {
env->SetStaticIntField(clsController, fidCZ, cJS.lZ);
(*env)->SetStaticIntField(env, clsController, fidCZ, cJS.lZ);
}
//rotational axis
if(cHasrx) {
env->SetStaticIntField(clsController, fidCRX, cJS.lRx);
(*env)->SetStaticIntField(env, clsController, fidCRX, cJS.lRx);
}
if(cHasry) {
env->SetStaticIntField(clsController, fidCRY, cJS.lRy);
(*env)->SetStaticIntField(env, clsController, fidCRY, cJS.lRy);
}
if(cHasrz) {
env->SetStaticIntField(clsController, fidCRZ, cJS.lRz);
(*env)->SetStaticIntField(env, clsController, fidCRZ, cJS.lRz);
}
//buttons
for (int i = 0; i < cButtoncount; i++) {
for (i = 0; i < cButtoncount; i++) {
if (cJS.rgbButtons[i] != 0) {
cJS.rgbButtons[i] = 1;
} else {
cJS.rgbButtons[i] = 0;
}
}
jbyteArray buttonsArray = (jbyteArray) env->GetStaticObjectField(clsController, fidCButtons);
env->SetByteArrayRegion(buttonsArray, 0, cButtoncount, (jbyte *)cJS.rgbButtons);
buttonsArray = (jbyteArray) (*env)->GetStaticObjectField(env, clsController, fidCButtons);
(*env)->SetByteArrayRegion(env, buttonsArray, 0, cButtoncount, (jbyte *)cJS.rgbButtons);
//pov
if(cHaspov) {
env->SetStaticIntField(clsController, fidCPOV, cJS.rgdwPOV[0]);
(*env)->SetStaticIntField(env, clsController, fidCPOV, cJS.rgdwPOV[0]);
}
//slider
if(cHasslider) {
env->SetStaticIntField(clsController, fidCSlider, cJS.lZ);
(*env)->SetStaticIntField(env, clsController, fidCSlider, cJS.lZ);
}
}
@ -492,45 +494,45 @@ static void UpdateControllerFields(JNIEnv *env, jclass clsController) {
*/
static void SetControllerCapabilities(JNIEnv *env, jclass clsController) {
//set buttoncount
env->SetStaticIntField(clsController, fidCButtonCount, cButtoncount);
(*env)->SetStaticIntField(env, clsController, fidCButtonCount, cButtoncount);
//set axis
env->SetStaticBooleanField(clsController, fidCHasXAxis, cHasx);
env->SetStaticBooleanField(clsController, fidCHasYAxis, cHasy);
env->SetStaticBooleanField(clsController, fidCHasZAxis, cHasz);
(*env)->SetStaticBooleanField(env, clsController, fidCHasXAxis, cHasx);
(*env)->SetStaticBooleanField(env, clsController, fidCHasYAxis, cHasy);
(*env)->SetStaticBooleanField(env, clsController, fidCHasZAxis, cHasz);
//set rotational axis
env->SetStaticBooleanField(clsController, fidCHasRXAxis, cHasrx);
env->SetStaticBooleanField(clsController, fidCHasRYAxis, cHasry);
env->SetStaticBooleanField(clsController, fidCHasRZAxis, cHasrz);
(*env)->SetStaticBooleanField(env, clsController, fidCHasRXAxis, cHasrx);
(*env)->SetStaticBooleanField(env, clsController, fidCHasRYAxis, cHasry);
(*env)->SetStaticBooleanField(env, clsController, fidCHasRZAxis, cHasrz);
//set pov
env->SetStaticBooleanField(clsController, fidCHasPOV, cHaspov);
(*env)->SetStaticBooleanField(env, clsController, fidCHasPOV, cHaspov);
//set slider
env->SetStaticBooleanField(clsController, fidCHasSlider, cHasslider);
(*env)->SetStaticBooleanField(env, clsController, fidCHasSlider, cHasslider);
}
/**
* Caches the field ids for quicker access
*/
static void CacheControllerFields(JNIEnv *env, jclass clsController) {
fidCButtonCount = env->GetStaticFieldID(clsController, "buttonCount", "I");
fidCHasXAxis = env->GetStaticFieldID(clsController, "hasXAxis", "Z");
fidCHasRXAxis = env->GetStaticFieldID(clsController, "hasRXAxis", "Z");
fidCHasYAxis = env->GetStaticFieldID(clsController, "hasYAxis", "Z");
fidCHasRYAxis = env->GetStaticFieldID(clsController, "hasRYAxis", "Z");
fidCHasZAxis = env->GetStaticFieldID(clsController, "hasZAxis", "Z");
fidCHasRZAxis = env->GetStaticFieldID(clsController, "hasRZAxis", "Z");
fidCHasPOV = env->GetStaticFieldID(clsController, "hasPOV", "Z");
fidCHasSlider = env->GetStaticFieldID(clsController, "hasSlider", "Z");
fidCButtons = env->GetStaticFieldID(clsController, "buttons", "[Z");
fidCX = env->GetStaticFieldID(clsController, "x", "I");
fidCRX = env->GetStaticFieldID(clsController, "rx", "I");
fidCY = env->GetStaticFieldID(clsController, "y", "I");
fidCRY = env->GetStaticFieldID(clsController, "ry", "I");
fidCZ = env->GetStaticFieldID(clsController, "z", "I");
fidCRZ = env->GetStaticFieldID(clsController, "rz", "I");
fidCPOV = env->GetStaticFieldID(clsController, "pov", "I");
fidCSlider = env->GetStaticFieldID(clsController, "slider", "I");
fidCButtonCount = (*env)->GetStaticFieldID(env, clsController, "buttonCount", "I");
fidCHasXAxis = (*env)->GetStaticFieldID(env, clsController, "hasXAxis", "Z");
fidCHasRXAxis = (*env)->GetStaticFieldID(env, clsController, "hasRXAxis", "Z");
fidCHasYAxis = (*env)->GetStaticFieldID(env, clsController, "hasYAxis", "Z");
fidCHasRYAxis = (*env)->GetStaticFieldID(env, clsController, "hasRYAxis", "Z");
fidCHasZAxis = (*env)->GetStaticFieldID(env, clsController, "hasZAxis", "Z");
fidCHasRZAxis = (*env)->GetStaticFieldID(env, clsController, "hasRZAxis", "Z");
fidCHasPOV = (*env)->GetStaticFieldID(env, clsController, "hasPOV", "Z");
fidCHasSlider = (*env)->GetStaticFieldID(env, clsController, "hasSlider", "Z");
fidCButtons = (*env)->GetStaticFieldID(env, clsController, "buttons", "[Z");
fidCX = (*env)->GetStaticFieldID(env, clsController, "x", "I");
fidCRX = (*env)->GetStaticFieldID(env, clsController, "rx", "I");
fidCY = (*env)->GetStaticFieldID(env, clsController, "y", "I");
fidCRY = (*env)->GetStaticFieldID(env, clsController, "ry", "I");
fidCZ = (*env)->GetStaticFieldID(env, clsController, "z", "I");
fidCRZ = (*env)->GetStaticFieldID(env, clsController, "rz", "I");
fidCPOV = (*env)->GetStaticFieldID(env, clsController, "pov", "I");
fidCSlider = (*env)->GetStaticFieldID(env, clsController, "slider", "I");
}

View File

@ -47,18 +47,34 @@
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor
(JNIEnv *env, jobject self, jobject handle_buffer, jint width, jint height, jint x_hotspot, jint y_hotspot, jint num_images, jobject image_buffer, jint images_offset, jobject delay_buffer, jint delays_offset)
{
if (env->GetDirectBufferCapacity(handle_buffer) < sizeof(HCURSOR)) {
unsigned char col0, col1, col2, col3, col4, col5, col6, col7;
unsigned char mask;
BITMAPINFO bitmapInfo;
HBITMAP cursorMask;
HCURSOR *cursor_handle;
HCURSOR cursor = NULL;
ICONINFO iconInfo;
char *ptrCursorImage;
HBITMAP colorDIB;
int *srcPtr;
char *dstPtr;
int bitWidth;
int scanlinePad;
int imageSize; // Size in bits
unsigned char *maskPixels;
int pixelCount = 0;
int maskCount = 0;
HBITMAP colorBitmap;
int x, y;
int *pixels;
if ((*env)->GetDirectBufferCapacity(env, handle_buffer) < sizeof(HCURSOR)) {
throwException(env, "Handle buffer not large enough");
return;
}
int *pixels = (int *)env->GetDirectBufferAddress(image_buffer) + images_offset;
BITMAPINFO bitmapInfo;
char *ptrCursorImage;
HBITMAP colorDIB;
HBITMAP colorBitmap;
int x, y;
pixels = (int *)(*env)->GetDirectBufferAddress(env, image_buffer) + images_offset;
memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
@ -73,8 +89,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor
DIB_RGB_COLORS,
(void**)&(ptrCursorImage),
NULL, 0);
int *srcPtr = pixels;
char *dstPtr = ptrCursorImage;
srcPtr = pixels;
dstPtr = ptrCursorImage;
if (!dstPtr) {
throwException(env, "Could not allocate DIB section.");
return;
@ -100,31 +116,27 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor
DeleteObject(colorDIB);
// Convert alpha map to pixel packed mask
int bitWidth = width >> 3;
int scanlinePad = bitWidth & (sizeof(WORD) - 1);
int imageSize = (bitWidth + scanlinePad)*height; // Size in bits
unsigned char *maskPixels = new unsigned char[imageSize];
bitWidth = width >> 3;
scanlinePad = bitWidth & (sizeof(WORD) - 1);
imageSize = (bitWidth + scanlinePad)*height; // Size in bits
maskPixels = (unsigned char*)malloc(sizeof(unsigned char)*imageSize);
memset(maskPixels, 0, imageSize);
int pixelCount = 0;
int maskCount = 0;
for (y = 0; y < height; y++)
for (x = 0; x < bitWidth; x++) {
unsigned char col0 = (pixels[pixelCount++] & 0x01000000) >> 17;
unsigned char col1 = (pixels[pixelCount++] & 0x01000000) >> 18;
unsigned char col2 = (pixels[pixelCount++] & 0x01000000) >> 19;
unsigned char col3 = (pixels[pixelCount++] & 0x01000000) >> 20;
unsigned char col4 = (pixels[pixelCount++] & 0x01000000) >> 21;
unsigned char col5 = (pixels[pixelCount++] & 0x01000000) >> 22;
unsigned char col6 = (pixels[pixelCount++] & 0x01000000) >> 23;
unsigned char col7 = (pixels[pixelCount++] & 0x01000000) >> 24;
unsigned char mask = col0 | col1 | col2 | col3 | col4 | col5 | col6 | col7;
col0 = (pixels[pixelCount++] & 0x01000000) >> 17;
col1 = (pixels[pixelCount++] & 0x01000000) >> 18;
col2 = (pixels[pixelCount++] & 0x01000000) >> 19;
col3 = (pixels[pixelCount++] & 0x01000000) >> 20;
col4 = (pixels[pixelCount++] & 0x01000000) >> 21;
col5 = (pixels[pixelCount++] & 0x01000000) >> 22;
col6 = (pixels[pixelCount++] & 0x01000000) >> 23;
col7 = (pixels[pixelCount++] & 0x01000000) >> 24;
mask = col0 | col1 | col2 | col3 | col4 | col5 | col6 | col7;
maskPixels[maskCount++] = ~mask; // 1 is tranparant, 0 opaque
}
HBITMAP cursorMask = CreateBitmap(width, height, 1, 1, maskPixels);
cursorMask = CreateBitmap(width, height, 1, 1, maskPixels);
HCURSOR cursor = NULL;
ICONINFO iconInfo;
memset(&iconInfo, 0, sizeof(ICONINFO));
iconInfo.hbmMask = cursorMask;
iconInfo.hbmColor = colorBitmap;
@ -134,9 +146,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor
cursor = CreateIconIndirect(&iconInfo);
DeleteObject(colorBitmap);
DeleteObject(cursorMask);
delete[] maskPixels;
free(maskPixels);
HCURSOR *cursor_handle = (HCURSOR *)env->GetDirectBufferAddress(handle_buffer);
cursor_handle = (HCURSOR *)(*env)->GetDirectBufferAddress(env, handle_buffer);
*cursor_handle = cursor;
}
@ -149,6 +161,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_destroyCursor
(JNIEnv *env, jobject self, jobject handle_buffer)
{
// HCURSOR cursor = (HCURSOR)cursor_handle;
HCURSOR *cursor_handle = (HCURSOR *)env->GetDirectBufferAddress(handle_buffer);
HCURSOR *cursor_handle = (HCURSOR *)(*env)->GetDirectBufferAddress(env, handle_buffer);
DestroyCursor(*cursor_handle);
}

View File

@ -61,6 +61,7 @@ static bool useUnicode;
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createKeyboard
(JNIEnv * env, jobject self)
{
DIPROPDWORD dipropdw;
// Create input
HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION) {
@ -76,28 +77,27 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createKeyboard
}
// Create a keyboard device
if (lpdi->CreateDevice(GUID_SysKeyboard, &lpdiKeyboard, NULL) != DI_OK) {
if (IDirectInput_CreateDevice(lpdi, &GUID_SysKeyboard, &lpdiKeyboard, NULL) != DI_OK) {
throwException(env, "Failed to create keyboard.");
return;
}
if (lpdiKeyboard->SetCooperativeLevel(getCurrentHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
if (IDirectInputDevice_SetCooperativeLevel(lpdiKeyboard, getCurrentHWND(), DISCL_NONEXCLUSIVE | DISCL_FOREGROUND) != DI_OK) {
throwException(env, "Failed to set keyboard cooperation mode.");
return;
}
// Tell 'em wot format to be in (the default "you are a mouse and keyboard" format)
lpdiKeyboard->SetDataFormat(&c_dfDIKeyboard);
IDirectInputDevice_SetDataFormat(lpdiKeyboard, &c_dfDIKeyboard);
DIPROPDWORD dipropdw;
dipropdw.diph.dwSize = sizeof(DIPROPDWORD);
dipropdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipropdw.diph.dwObj = 0;
dipropdw.diph.dwHow = DIPH_DEVICE;
dipropdw.dwData = KEYBOARD_BUFFER_SIZE;
lpdiKeyboard->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
IDirectInputDevice_SetProperty(lpdiKeyboard, DIPROP_BUFFERSIZE, &dipropdw.diph);
ret = lpdiKeyboard->Acquire();
ret = IDirectInputDevice_Acquire(lpdiKeyboard);
if(FAILED(ret)) {
printfDebug("Failed to acquire keyboard\n");
}
@ -113,14 +113,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_destroyKeyboard
{
// Release keyboard
if (lpdiKeyboard != NULL) {
lpdiKeyboard->Unacquire();
lpdiKeyboard->Release();
IDirectInputDevice_Unacquire(lpdiKeyboard);
IDirectInputDevice_Release(lpdiKeyboard);
lpdiKeyboard = NULL;
}
// Release DirectInput
if (lpdi != NULL) {
printfDebug("Destroying directinput\n");
lpdi->Release();
IDirectInput_Release(lpdi);
lpdi = NULL;
}
}
@ -134,8 +134,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_pollKeyboard
(JNIEnv * env, jobject self, jobject buffer)
{
HRESULT ret;
void *keyboardBuffer;
jlong buffer_size;
do {
ret = lpdiKeyboard->Acquire();
ret = IDirectInputDevice_Acquire(lpdiKeyboard);
if (ret == DIERR_INPUTLOST) {
printf("Input lost\n");
return;
@ -157,15 +159,24 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_pollKeyboard
}
} while (ret != DI_OK && ret != S_FALSE);
void *keyboardBuffer = (void *)env->GetDirectBufferAddress(buffer);
jlong buffer_size = env->GetDirectBufferCapacity(buffer);
lpdiKeyboard->GetDeviceState((DWORD)buffer_size, keyboardBuffer);
keyboardBuffer = (void *)(*env)->GetDirectBufferAddress(env, buffer);
buffer_size = (*env)->GetDirectBufferCapacity(env, buffer);
IDirectInputDevice_GetDeviceState(lpdiKeyboard, (DWORD)buffer_size, keyboardBuffer);
}
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readKeyboard
(JNIEnv * env, jobject self, jobject buffer_obj, jint buffer_position)
{
static DIDEVICEOBJECTDATA rgdod[KEYBOARD_BUFFER_SIZE];
UINT scan_code;
UINT virt_key;
bool key_down;
jint * buf;
jint ch_int;
int buffer_size;
int index = 0;
int event_size = 3;
DWORD current_di_event = 0;
DIDEVICEOBJECTDATA rgdod[KEYBOARD_BUFFER_SIZE];
wchar_t transBufUnicode[KEYBOARD_BUFFER_SIZE];
WORD transBufAscii[KEYBOARD_BUFFER_SIZE];
@ -176,30 +187,27 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readKeyboard
int num_chars;
int num_events = 0;
ret = lpdiKeyboard->Acquire();
ret = IDirectInputDevice_Acquire(lpdiKeyboard);
if (ret != DI_OK && ret != S_FALSE)
return 0;
ret = lpdiKeyboard->GetDeviceData(
ret = IDirectInputDevice_GetDeviceData(lpdiKeyboard,
sizeof(DIDEVICEOBJECTDATA),
rgdod,
&num_di_events,
0);
if (ret == DI_OK) {
jint * buf = buffer_position + (jint *)env->GetDirectBufferAddress(buffer_obj);
int buffer_size = ((int)env->GetDirectBufferCapacity(buffer_obj))/sizeof(jint) - buffer_position;
int index = 0;
int event_size = 3;
DWORD current_di_event = 0;
buf = buffer_position + (jint *)(*env)->GetDirectBufferAddress(env, buffer_obj);
buffer_size = ((int)(*env)->GetDirectBufferCapacity(env, buffer_obj))/sizeof(jint) - buffer_position;
while (index + event_size <= buffer_size && current_di_event < num_di_events) {
num_events++;
buf[index++] = (unsigned char) rgdod[current_di_event].dwOfs;
buf[index++] = (unsigned char) rgdod[current_di_event].dwData;
bool key_down = (rgdod[current_di_event].dwData & 0x80) != 0;
key_down = (rgdod[current_di_event].dwData & 0x80) != 0;
if (translationEnabled && key_down) {
UINT scan_code = rgdod[current_di_event].dwOfs;
UINT virt_key = MapVirtualKey(scan_code, 1);
scan_code = rgdod[current_di_event].dwOfs;
virt_key = MapVirtualKey(scan_code, 1);
if (virt_key != 0 && GetKeyboardState(state)) {
// Mark key down in the scan code
scan_code = scan_code & 0x7fff;
@ -224,7 +232,6 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readKeyboard
buf[index++] = 0;
buf[index++] = 0;
}
jint ch_int;
if (useUnicode) {
wchar_t ch = transBufUnicode[current_char];
ch_int = ((int)ch) & 0xFFFF;

View File

@ -114,7 +114,7 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getButtonCount(JNIEnv
* Called when the Mouse instance is to be created
*/
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *env, jobject self) {
HRESULT hr;
HRESULT ret;
initEventQueue(&event_queue, EVENT_SIZE);
@ -122,7 +122,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *en
buffer_enabled = false;
// Create input
HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION) {
throwException(env, "Failed to create DirectInput");
return;
@ -149,9 +149,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *en
SetupMouse();
}
}
/* Aquire the Mouse */
hr = mDIDevice->Acquire();
if(FAILED(hr)) {
/* Aquire the Mouse */
ret = IDirectInputDevice_Acquire(mDIDevice);
if(FAILED(ret)) {
printfDebug("Failed to acquire mouse\n");
}
}
@ -168,10 +168,12 @@ void handleMouseScrolled(int event_dwheel) {
}
void handleMouseMoved(int x, int y) {
int dx;
int dy;
if(mCreate_success) {
y = transformY(y);
int dx = x - last_x;
int dy = y - last_y;
dx = x - last_x;
dy = y - last_y;
accum_dx += dx;
accum_dy += dy;
last_x = x;
@ -193,8 +195,10 @@ void handleMouseButton(int button, int state) {
static void copyDXEvents(int num_di_events, DIDEVICEOBJECTDATA *di_buffer) {
int buffer_index = 0;
int dx = 0, dy = 0, dwheel = 0;
for (int i = 0; i < num_di_events; i++) {
int button_state = (di_buffer[i].dwData & 0x80) != 0 ? 1 : 0;
int button_state;
int i;
for (i = 0; i < num_di_events; i++) {
button_state = (di_buffer[i].dwData & 0x80) != 0 ? 1 : 0;
switch (di_buffer[i].dwOfs) {
case DIMOFS_BUTTON0:
putMouseEventWithCoords(0, button_state, dx, -dy, dwheel);
@ -233,11 +237,11 @@ static void readDXBuffer() {
HRESULT ret;
ret = mDIDevice->Acquire();
ret = IDirectInputDevice_Acquire(mDIDevice);
if (ret != DI_OK && ret != S_FALSE)
return;
ret = mDIDevice->GetDeviceData(
ret = IDirectInputDevice_GetDeviceData(mDIDevice,
sizeof(DIDEVICEOBJECTDATA),
rgdod,
&num_di_events,
@ -265,8 +269,8 @@ static void readDXBuffer() {
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readMouse
(JNIEnv * env, jobject self, jobject buffer_obj, jint buffer_position)
{
jint* buffer_ptr = (jint *)env->GetDirectBufferAddress(buffer_obj) + buffer_position;
int buffer_size = (env->GetDirectBufferCapacity(buffer_obj))/sizeof(jint) - buffer_position;
jint* buffer_ptr = (jint *)(*env)->GetDirectBufferAddress(env, buffer_obj) + buffer_position;
int buffer_size = ((*env)->GetDirectBufferCapacity(env, buffer_obj))/sizeof(jint) - buffer_position;
if (mouse_grabbed) {
readDXBuffer();
} else {
@ -284,11 +288,13 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getNativeCursorCaps
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_setNativeCursor
(JNIEnv *env, jobject self, jobject handle_buffer)
{
HCURSOR *cursor_handle;
HCURSOR cursor;
if (mDIDevice == NULL)
throwException(env, "null device!");
if (handle_buffer != NULL) {
HCURSOR *cursor_handle = (HCURSOR *)env->GetDirectBufferAddress(handle_buffer);
HCURSOR cursor = *cursor_handle;
cursor_handle = (HCURSOR *)(*env)->GetDirectBufferAddress(env, handle_buffer);
cursor = *cursor_handle;
SetClassLong(getCurrentHWND(), GCL_HCURSOR, (LONG)cursor);
SetCursor(cursor);
} else {
@ -314,14 +320,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_destroyMouse(JNIEnv *e
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_pollMouse(JNIEnv * env, jobject self, jobject coord_buffer_obj, jobject button_buffer_obj) {
mDIDevice->Acquire();
UpdateMouseFields(env, coord_buffer_obj, button_buffer_obj);
IDirectInputDevice_Acquire(mDIDevice);
UpdateMouseFields(env, coord_buffer_obj, button_buffer_obj);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_grabMouse
(JNIEnv * env, jobject self, jboolean grab) {
mDIDevice->Unacquire();
IDirectInputDevice_Unacquire(mDIDevice);
if(grab) {
if (!mouse_grabbed) {
mouse_grabbed = true;
@ -335,12 +340,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_grabMouse
mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
}
}
mDIDevice->Unacquire();
if(mDIDevice->SetCooperativeLevel(getCurrentHWND(), mouseMask) != DI_OK) {
IDirectInputDevice_Unacquire(mDIDevice);
if (IDirectInputDevice_SetCooperativeLevel(mDIDevice, getCurrentHWND(), mouseMask) != DI_OK) {
throwException(env, "Could not set the CooperativeLevel.");
return;
}
mDIDevice->Acquire();
IDirectInputDevice_Acquire(mDIDevice);
initEventQueue(&event_queue, EVENT_SIZE);
}
@ -350,14 +355,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_grabMouse
static void ShutdownMouse() {
// release device
if (mDIDevice != NULL) {
mDIDevice->Unacquire();
mDIDevice->Release();
IDirectInputDevice_Unacquire(mDIDevice);
IDirectInputDevice_Release(mDIDevice);
mDIDevice = NULL;
}
// Release DirectInput
if (lpdi != NULL) {
printfDebug("Destroying directinput\n");
lpdi->Release();
IDirectInput_Release(lpdi);
lpdi = NULL;
}
mCreate_success = false;
@ -367,7 +372,7 @@ static void ShutdownMouse() {
*/
static void EnumerateMouseCapabilities() {
HRESULT hr;
hr = mDIDevice->EnumObjects(EnumMouseObjectsCallback, NULL, DIDFT_ALL);
hr = IDirectInputDevice_EnumObjects(mDIDevice, EnumMouseObjectsCallback, NULL, DIDFT_ALL);
if FAILED(hr) {
printfDebug("EnumObjects failed\n");
mCreate_success = false;
@ -388,11 +393,11 @@ static void EnumerateMouseCapabilities() {
*/
static BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
printfDebug("found %s\n", lpddoi->tszName);
if(lpddoi->guidType == GUID_Button) {
if(IsEqualGUID(&lpddoi->guidType, &GUID_Button)) {
mButtoncount++;
} else if(lpddoi->guidType == GUID_XAxis) {
} else if(lpddoi->guidType == GUID_YAxis) {
} else if(lpddoi->guidType == GUID_ZAxis) {
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_XAxis)) {
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_YAxis)) {
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_ZAxis)) {
mHaswheel = true;
} else {
printfDebug("Unhandled object found: %s\n", lpddoi->tszName);
@ -405,7 +410,7 @@ static BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi,
*/
static void CreateMouse() {
HRESULT hr;
hr = lpdi->CreateDevice(GUID_SysMouse, &mDIDevice, NULL);
hr = IDirectInput_CreateDevice(lpdi, &GUID_SysMouse, &mDIDevice, NULL);
if FAILED(hr) {
printfDebug("CreateDevice failed\n");
mCreate_success = false;
@ -418,23 +423,23 @@ static void CreateMouse() {
* Sets up the Mouse properties
*/
static void SetupMouse() {
DIPROPDWORD dipropdw;
// set Mouse data format
if(mDIDevice->SetDataFormat(&c_dfDIMouse) != DI_OK) {
if(IDirectInputDevice_SetDataFormat(mDIDevice, &c_dfDIMouse) != DI_OK) {
printfDebug("SetDataFormat failed\n");
mCreate_success = false;
return;
}
DIPROPDWORD dipropdw;
dipropdw.diph.dwSize = sizeof(DIPROPDWORD);
dipropdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
dipropdw.diph.dwObj = 0;
dipropdw.diph.dwHow = DIPH_DEVICE;
dipropdw.dwData = EVENT_BUFFER_SIZE;
mDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
IDirectInputDevice_SetProperty(mDIDevice, DIPROP_BUFFERSIZE, &dipropdw.diph);
// set the cooperative level
if(mDIDevice->SetCooperativeLevel(getCurrentHWND(), mouseMask) != DI_OK) {
if (IDirectInputDevice_SetCooperativeLevel(mDIDevice, getCurrentHWND(), mouseMask) != DI_OK) {
printfDebug("SetCooperativeLevel failed\n");
mCreate_success = false;
return;
@ -458,20 +463,22 @@ static int cap(int val, int min, int max) {
static void UpdateMouseFields(JNIEnv *env, jobject coord_buffer_obj, jobject button_buffer_obj) {
HRESULT hRes;
DIMOUSESTATE diMouseState; // State of Mouse
int i, j;
handleMessages();
int *coords = (int *)env->GetDirectBufferAddress(coord_buffer_obj);
int coords_length = (int)env->GetDirectBufferCapacity(coord_buffer_obj);
unsigned char *buttons_buffer = (unsigned char *)env->GetDirectBufferAddress(button_buffer_obj);
int buttons_length = (int)env->GetDirectBufferCapacity(button_buffer_obj);
int *coords = (int *)(*env)->GetDirectBufferAddress(env, coord_buffer_obj);
int coords_length = (int)(*env)->GetDirectBufferCapacity(env, coord_buffer_obj);
unsigned char *buttons_buffer = (unsigned char *)(*env)->GetDirectBufferAddress(env, button_buffer_obj);
int num_buttons;
int buttons_length = (int)(*env)->GetDirectBufferCapacity(env, button_buffer_obj);
if (coords_length < 3) {
printfDebug("ERROR: Not enough space in coords array: %d < 3\n", coords_length);
return;
}
handleMessages();
// get data from the Mouse
hRes = mDIDevice->GetDeviceState(sizeof(DIMOUSESTATE), &diMouseState);
hRes = IDirectInputDevice_GetDeviceState(mDIDevice, sizeof(DIMOUSESTATE), &diMouseState);
if (hRes != DI_OK) {
// Don't allow the mouse to drift when failed
diMouseState.lX = 0;
@ -480,7 +487,7 @@ static void UpdateMouseFields(JNIEnv *env, jobject coord_buffer_obj, jobject but
// did the read fail because we lost input for some reason?
// if so, then attempt to reacquire.
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
hRes = mDIDevice->Acquire();
hRes = IDirectInputDevice_Acquire(mDIDevice);
if (hRes != DI_OK)
return;
} else {
@ -500,16 +507,16 @@ static void UpdateMouseFields(JNIEnv *env, jobject coord_buffer_obj, jobject but
accum_dx = accum_dy = accum_dwheel = 0;
}
for (int i = 0; i < mButtoncount; i++) {
for (i = 0; i < mButtoncount; i++) {
if (diMouseState.rgbButtons[i] != 0) {
diMouseState.rgbButtons[i] = JNI_TRUE;
} else {
diMouseState.rgbButtons[i] = JNI_FALSE;
}
}
int num_buttons = mButtoncount;
num_buttons = mButtoncount;
if (num_buttons > buttons_length)
num_buttons = buttons_length;
for (int j = 0; j < num_buttons; j++)
for (j = 0; j < num_buttons; j++)
buttons_buffer[j] = (unsigned char)diMouseState.rgbButtons[j];
}

View File

@ -89,18 +89,23 @@ HGLRC getCurrentContext() {
}
static int findPixelFormatARBFromBPP(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixelFormatCaps, int bpp, bool window, bool pbuffer, 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"));
int stencil = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "stencil", "I"));
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
int num_aux_buffers = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "num_aux_buffers", "I"));
int accum_bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_bpp", "I"));
int accum_alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_alpha", "I"));
jboolean stereo = env->GetBooleanField(pixel_format, env->GetFieldID(cls_pixel_format, "stereo", "Z"));
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"));
int stencil = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stencil", "I"));
int samples = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "samples", "I"));
int num_aux_buffers = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "num_aux_buffers", "I"));
int accum_bpp = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_bpp", "I"));
int accum_alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_alpha", "I"));
jboolean stereo = (*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stereo", "Z"));
int iPixelFormat;
unsigned int num_formats_returned;
attrib_list_t attrib_list;
GLuint *pixelFormatCaps_ptr;
jlong pixelFormatCapsSize;
BOOL result;
jlong i;
initAttribList(&attrib_list);
if (window) {
putAttrib(&attrib_list, WGL_DRAW_TO_WINDOW_ARB); putAttrib(&attrib_list, TRUE);
@ -129,14 +134,14 @@ static int findPixelFormatARBFromBPP(JNIEnv *env, HDC hdc, jobject pixel_format,
return -1;
}
GLuint *pixelFormatCaps_ptr = (GLuint *)env->GetDirectBufferAddress(pixelFormatCaps);
jlong pixelFormatCapsSize = env->GetDirectBufferCapacity(pixelFormatCaps);
pixelFormatCaps_ptr = (GLuint *)(*env)->GetDirectBufferAddress(env, pixelFormatCaps);
pixelFormatCapsSize = (*env)->GetDirectBufferCapacity(env, pixelFormatCaps);
for (jlong i = 0; i < pixelFormatCapsSize; i++)
for (i = 0; i < pixelFormatCapsSize; i++)
putAttrib(&attrib_list, pixelFormatCaps_ptr[i]);
}
putAttrib(&attrib_list, 0); putAttrib(&attrib_list, 0);
BOOL result = wglChoosePixelFormatARB(hdc, attrib_list.attribs, NULL, 1, &iPixelFormat, &num_formats_returned);
result = wglChoosePixelFormatARB(hdc, attrib_list.attribs, NULL, 1, &iPixelFormat, &num_formats_returned);
if (result == FALSE || num_formats_returned < 1) {
return -1;
@ -146,16 +151,17 @@ static int findPixelFormatARBFromBPP(JNIEnv *env, HDC hdc, jobject pixel_format,
int findPixelFormatARB(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer) {
int bpp;
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
int iPixelFormat;
jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
if (use_hdc_bpp) {
bpp = GetDeviceCaps(hdc, BITSPIXEL);
int iPixelFormat = findPixelFormatARBFromBPP(env, hdc, pixel_format, pixelFormatCaps, bpp, window, pbuffer, double_buffer);
iPixelFormat = findPixelFormatARBFromBPP(env, hdc, pixel_format, pixelFormatCaps, bpp, window, pbuffer, double_buffer);
if (iPixelFormat == -1)
bpp = 16;
else
return iPixelFormat;
} else
bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "bpp", "I"));
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);
}
@ -164,21 +170,22 @@ int findPixelFormatARB(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixel
*/
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"));
int depth = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "depth", "I"));
int stencil = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "stencil", "I"));
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
int num_aux_buffers = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "num_aux_buffers", "I"));
int accum_bpp = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_bpp", "I"));
int accum_alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "accum_alpha", "I"));
jboolean stereo = env->GetBooleanField(pixel_format, env->GetFieldID(cls_pixel_format, "stereo", "Z"));
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"));
int stencil = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stencil", "I"));
int samples = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "samples", "I"));
int num_aux_buffers = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "num_aux_buffers", "I"));
int accum_bpp = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_bpp", "I"));
int accum_alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_alpha", "I"));
jboolean stereo = (*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stereo", "Z"));
unsigned int flags = PFD_DRAW_TO_WINDOW | // support window
PFD_SUPPORT_OPENGL | // support OpenGL
PFD_DOUBLEBUFFER; // double buffered
if (stereo)
flags = flags | PFD_STEREO;
PIXELFORMATDESCRIPTOR pfd = {
PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER |
(stereo ? PFD_STEREO : 0);
PIXELFORMATDESCRIPTOR desc;
int iPixelFormat;
PIXELFORMATDESCRIPTOR pfd = {
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
1, // version number
flags, // RGBA type
@ -198,13 +205,12 @@ static int findPixelFormatFromBPP(JNIEnv *env, HDC hdc, jobject pixel_format, in
};
// get the best available match of pixel format for the device context
int iPixelFormat = ChoosePixelFormat(hdc, &pfd);
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
if (iPixelFormat == 0) {
throwException(env, "Failed to choose pixel format");
return -1;
}
PIXELFORMATDESCRIPTOR desc;
if (DescribePixelFormat(hdc, iPixelFormat, sizeof(PIXELFORMATDESCRIPTOR), &desc) == 0) {
throwException(env, "Could not describe pixel format");
return -1;
@ -248,9 +254,8 @@ static int findPixelFormatFromBPP(JNIEnv *env, HDC hdc, jobject pixel_format, in
}
int findPixelFormat(JNIEnv *env, HDC hdc, jobject pixel_format) {
int bpp;
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
bpp = GetDeviceCaps(hdc, BITSPIXEL);
int bpp = GetDeviceCaps(hdc, BITSPIXEL);
jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
int iPixelFormat = findPixelFormatFromBPP(env, hdc, pixel_format, bpp);
if (iPixelFormat == -1) {
return findPixelFormatFromBPP(env, hdc, pixel_format, 16);
@ -311,7 +316,11 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
WPARAM wParam,
LPARAM lParam)
{
int xPos;
int yPos;
int dwheel;
bool oldIsMinimized;
bool oldIsFocused;
switch (msg) {
// disable screen saver and monitor power down messages which wreak havoc
case WM_SYSCOMMAND:
@ -331,14 +340,14 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
break;
case WM_MOUSEMOVE:
{
int xPos = GET_X_LPARAM(lParam);
int yPos = GET_Y_LPARAM(lParam);
xPos = GET_X_LPARAM(lParam);
yPos = GET_Y_LPARAM(lParam);
handleMouseMoved(xPos, yPos);
return 0;
}
case WM_MOUSEWHEEL:
{
int dwheel = GET_WHEEL_DELTA_WPARAM(wParam);
dwheel = GET_WHEEL_DELTA_WPARAM(wParam);
handleMouseScrolled(dwheel);
return 0;
}
@ -384,20 +393,20 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
}
/*case WM_MOVE: {
// get fields of display
jclass cls_display = env->FindClass("org/lwjgl/opengl/Display");
jfieldID fid_x = env->GetStaticFieldID(cls_display, "x", "I");
jfieldID fid_y = env->GetStaticFieldID(cls_display, "y", "I");
jclass cls_display = (*env)->FindClass(env, "org/lwjgl/opengl/Display");
jfieldID fid_x = (*env)->GetStaticFieldID(env, cls_display, "x", "I");
jfieldID fid_y = (*env)->GetStaticFieldID(env, cls_display, "y", "I");
// set fields
env->SetStaticIntField(cls_display, fid_x, (int)(short) LOWORD(lParam));
env->SetStaticIntField(cls_display, fid_y, (int)(short) HIWORD(lParam));
(*env)->SetStaticIntField(env, cls_display, fid_x, (int)(short) LOWORD(lParam));
(*env)->SetStaticIntField(env, cls_display, fid_y, (int)(short) HIWORD(lParam));
}*/
}
// Update window state directly having processed window messages
bool oldIsMinimized = isMinimized;
bool oldIsFocused = isFocused;
oldIsMinimized = isMinimized;
oldIsFocused = isFocused;
isMinimized = IsIconic(display_hwnd);
isFocused = GetForegroundWindow() == display_hwnd;
if (oldIsMinimized != isMinimized || oldIsFocused != isFocused) {
@ -414,9 +423,8 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
*/
static bool registerWindow()
{
WNDCLASS windowClass;
if (!oneShotInitialised) {
WNDCLASS windowClass;
windowClass.style = CS_GLOBALCLASS | CS_OWNDC;
windowClass.lpfnWndProc = lwjglWindowProc;
windowClass.cbClsExtra = 0;
@ -472,7 +480,7 @@ void handleMessages(void)
HWND createWindow(int x, int y, int width, int height, bool fullscreen, bool undecorated)
{
int exstyle, windowflags;
HWND new_hwnd;
// 1. Register window class if necessary
if (!registerWindow()) {
return NULL;
@ -504,7 +512,7 @@ HWND createWindow(int x, int y, int width, int height, bool fullscreen, bool und
);
// Create the window now, using that class:
HWND new_hwnd = CreateWindowEx (
new_hwnd = CreateWindowEx (
exstyle,
WINDOWCLASSNAME,
"",
@ -629,17 +637,18 @@ JNIEXPORT jobjectArray JNICALL Java_org_lwjgl_opengl_Win32Display_getAvailableDi
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createWindow(JNIEnv *env, jobject self, jobject mode, jboolean fullscreen, jint x, jint y) {
jclass cls_displayMode = (*env)->GetObjectClass(env, mode);
jfieldID fid_width = (*env)->GetFieldID(env, cls_displayMode, "width", "I");
jfieldID fid_height = (*env)->GetFieldID(env, cls_displayMode, "height", "I");
int width = (*env)->GetIntField(env, mode, fid_width);
int height = (*env)->GetIntField(env, mode, fid_height);
BOOL result;
closerequested = false;
isMinimized = false;
isFocused = false;
isDirty = true;
isFullScreen = fullscreen == JNI_TRUE;
isUndecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated");
jclass cls_displayMode = env->GetObjectClass(mode);
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
int width = env->GetIntField(mode, fid_width);
int height = env->GetIntField(mode, fid_height);
display_hwnd = createWindow(x, y, width, height, isFullScreen, isUndecorated);
if (display_hwnd == NULL) {
@ -653,7 +662,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createWindow(JNIEnv *e
return;
}
BOOL result = wglMakeCurrent(display_hdc, display_hglrc);
result = wglMakeCurrent(display_hdc, display_hglrc);
if (!result) {
throwException(env, "Could not bind context to window");
closeWindow(display_hwnd, display_hdc);
@ -699,26 +708,30 @@ JNIEXPORT jobject JNICALL Java_org_lwjgl_opengl_Win32Display_init(JNIEnv *env, j
}
static bool createARBContextAndPixelFormat(JNIEnv *env, HDC hdc, jobject pixel_format, int *pixel_format_index_return, HGLRC *context_return) {
int pixel_format_index;
HWND arb_hwnd;
HDC arb_hdc;
HGLRC arb_context;
// Some crazy strangeness here so we can use ARB_pixel_format to specify the number
// of multisamples we want. If the extension is present we'll delete the existing
// rendering context and start over, using the ARB extension instead to pick the context.
if (!extgl_Extensions.WGL_ARB_pixel_format)
return false;
int pixel_format_index = findPixelFormatARB(env, hdc, pixel_format, NULL, true, true, true, true);
pixel_format_index = findPixelFormatARB(env, hdc, pixel_format, NULL, true, true, true, true);
if (pixel_format_index == -1) {
pixel_format_index = findPixelFormatARB(env, hdc, pixel_format, NULL, true, true, false, true);
if (pixel_format_index == -1)
return false;
}
HWND arb_hwnd = createWindow(0, 0, 1, 1, false, false);
arb_hwnd = createWindow(0, 0, 1, 1, false, false);
if (arb_hwnd == NULL)
return false;
HDC arb_hdc = GetDC(arb_hwnd);
arb_hdc = GetDC(arb_hwnd);
if (!applyPixelFormat(arb_hdc, pixel_format_index)) {
closeWindow(arb_hwnd, arb_hdc);
return false;
}
HGLRC arb_context = wglCreateContext(arb_hdc);
arb_context = wglCreateContext(arb_hdc);
closeWindow(arb_hwnd, arb_hdc);
*pixel_format_index_return = pixel_format_index;
*context_return = arb_context;
@ -727,11 +740,18 @@ static bool createARBContextAndPixelFormat(JNIEnv *env, HDC hdc, jobject pixel_f
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createContext(JNIEnv *env, jobject self, jobject pixel_format) {
HWND dummy_hwnd = createWindow(0, 0, 1, 1, false, false);
HDC dummy_hdc;
BOOL result;
jclass cls_pixel_format;
int samples;
int pixel_format_index_arb;
HGLRC context_arb;
bool arb_success;
if (dummy_hwnd == NULL) {
throwException(env, "Failed to create the window.");
return;
}
HDC dummy_hdc = GetDC(dummy_hwnd);
dummy_hdc = GetDC(dummy_hwnd);
pixel_format_index = findPixelFormat(env, dummy_hdc, pixel_format);
if (pixel_format_index == -1) {
return;
@ -747,7 +767,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createContext(JNIEnv *
throwException(env, "Failed to create OpenGL rendering context");
return;
}
BOOL result = wglMakeCurrent(dummy_hdc, display_hglrc);
result = wglMakeCurrent(dummy_hdc, display_hglrc);
if (!result) {
throwException(env, "Could not bind context to dummy window");
wglDeleteContext(display_hglrc);
@ -755,12 +775,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createContext(JNIEnv *
return;
}
extgl_InitWGL(env);
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
samples = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "samples", "I"));
if (samples > 0) {
int pixel_format_index_arb;
HGLRC context_arb;
bool arb_success = createARBContextAndPixelFormat(env, dummy_hdc, pixel_format, &pixel_format_index_arb, &context_arb);
arb_success = createARBContextAndPixelFormat(env, dummy_hdc, pixel_format, &pixel_format_index_arb, &context_arb);
closeWindow(dummy_hwnd, dummy_hdc);
wglDeleteContext(display_hglrc);
if (!arb_success) {
@ -785,12 +803,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_destroyContext(JNIEnv
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_reshape(JNIEnv *env, jobject self, jint x, jint y, jint width, jint height) {
int exstyle, windowflags;
if (isFullScreen) {
return;
}
int exstyle, windowflags;
if (isFullScreen) {
exstyle = WS_EX_APPWINDOW | WS_EX_TOPMOST;
windowflags = WS_POPUP;

View File

@ -76,12 +76,17 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getPbufferCaps
static HPBUFFERARB createPbuffer(JNIEnv *env, int width, int height, jobject pixel_format, jobject pixelFormatCaps, const int *pBufferAttribs_ptr) {
HWND dummy_hwnd = createWindow(0, 0, 1, 1, false, false);
HDC dummy_hdc;
int iPixelFormat;
HGLRC dummy_hglrc;
BOOL result;
HPBUFFERARB Pbuffer;
if (dummy_hwnd == NULL) {
throwException(env, "Could not create dummy window");
return NULL;
}
HDC dummy_hdc = GetDC(dummy_hwnd);
int iPixelFormat = findPixelFormat(env, dummy_hdc, pixel_format);
dummy_hdc = GetDC(dummy_hwnd);
iPixelFormat = findPixelFormat(env, dummy_hdc, pixel_format);
if (iPixelFormat == -1) {
return NULL;
}
@ -91,13 +96,13 @@ static HPBUFFERARB createPbuffer(JNIEnv *env, int width, int height, jobject pix
return NULL;
}
HGLRC dummy_hglrc = wglCreateContext(dummy_hdc);
dummy_hglrc = wglCreateContext(dummy_hdc);
if (dummy_hglrc == NULL) {
closeWindow(dummy_hwnd, dummy_hdc);
throwException(env, "Failed to create OpenGL rendering context");
return NULL;
}
BOOL result = wglMakeCurrent(dummy_hdc, dummy_hglrc);
result = wglMakeCurrent(dummy_hdc, dummy_hglrc);
if (!result) {
wglDeleteContext(dummy_hglrc);
closeWindow(dummy_hwnd, dummy_hdc);
@ -115,7 +120,7 @@ static HPBUFFERARB createPbuffer(JNIEnv *env, int width, int height, jobject pix
throwException(env, "Could not find suitable pixel format.");
return NULL;
}
HPBUFFERARB Pbuffer = wglCreatePbufferARB(dummy_hdc, iPixelFormat, width, height, pBufferAttribs_ptr);
Pbuffer = wglCreatePbufferARB(dummy_hdc, iPixelFormat, width, height, pBufferAttribs_ptr);
closeWindow(dummy_hwnd, dummy_hdc);
return Pbuffer;
}
@ -139,14 +144,17 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
jint width, jint height, jobject pixel_format,
jobject pixelFormatCaps, jobject pBufferAttribs)
{
if (env->GetDirectBufferCapacity(buffer_handle) < sizeof(PbufferInfo)) {
HPBUFFERARB Pbuffer;
const int *pBufferAttribs_ptr;
HDC Pbuffer_dc;
HGLRC Pbuffer_context;
PbufferInfo *Pbuffer_info;
if ((*env)->GetDirectBufferCapacity(env, buffer_handle) < sizeof(PbufferInfo)) {
throwException(env, "Buffer handle not large enough");
return;
}
HPBUFFERARB Pbuffer;
const int *pBufferAttribs_ptr;
if ( pBufferAttribs != NULL ) {
pBufferAttribs_ptr = (const int *)env->GetDirectBufferAddress(pBufferAttribs);
pBufferAttribs_ptr = (const int *)(*env)->GetDirectBufferAddress(env, pBufferAttribs);
} else {
pBufferAttribs_ptr = NULL;
}
@ -157,20 +165,19 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
return;
}
HDC Pbuffer_dc = wglGetPbufferDCARB(Pbuffer);
Pbuffer_dc = wglGetPbufferDCARB(Pbuffer);
if (Pbuffer_dc == NULL) {
wglDestroyPbufferARB(Pbuffer);
throwException(env, "Could not get Pbuffer dc.");
return;
}
HGLRC Pbuffer_context;
Pbuffer_context = createPbufferContext(env, Pbuffer_dc);
if (Pbuffer_context == NULL) {
wglReleasePbufferDCARB(Pbuffer, Pbuffer_dc);
wglDestroyPbufferARB(Pbuffer);
return;
}
PbufferInfo *Pbuffer_info = (PbufferInfo *)env->GetDirectBufferAddress(buffer_handle);
Pbuffer_info = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, buffer_handle);
Pbuffer_info->Pbuffer = Pbuffer;
Pbuffer_info->Pbuffer_context = Pbuffer_context;
Pbuffer_info->Pbuffer_dc = Pbuffer_dc;
@ -179,7 +186,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Pbuffer_nIsBufferLost
(JNIEnv *env, jclass clazz, jobject buffer_handle)
{
PbufferInfo *Pbuffer_info = (PbufferInfo *)env->GetDirectBufferAddress(buffer_handle);
PbufferInfo *Pbuffer_info = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, buffer_handle);
BOOL buffer_lost;
wglQueryPbufferARB(Pbuffer_info->Pbuffer, WGL_PBUFFER_LOST_ARB, &buffer_lost);
return buffer_lost ? JNI_TRUE : JNI_FALSE;
@ -188,7 +195,7 @@ JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Pbuffer_nIsBufferLost
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nMakeCurrent
(JNIEnv *env, jclass clazz, jobject buffer_handle)
{
PbufferInfo *Pbuffer_info = (PbufferInfo *)env->GetDirectBufferAddress(buffer_handle);
PbufferInfo *Pbuffer_info = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, buffer_handle);
// PbufferInfo *Pbuffer_info = (PbufferInfo *)handle;
if (!wglMakeCurrent(Pbuffer_info->Pbuffer_dc, Pbuffer_info->Pbuffer_context))
throwException(env, "Could not make pbuffer context current");
@ -197,7 +204,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nMakeCurrent
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nDestroy
(JNIEnv *env, jclass clazz, jobject buffer_handle)
{
PbufferInfo *Pbuffer_info = (PbufferInfo *)env->GetDirectBufferAddress(buffer_handle);
PbufferInfo *Pbuffer_info = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, buffer_handle);
wglDeleteContext(Pbuffer_info->Pbuffer_context);
wglReleasePbufferDCARB(Pbuffer_info->Pbuffer, Pbuffer_info->Pbuffer_dc);
wglDestroyPbufferARB(Pbuffer_info->Pbuffer);
@ -206,7 +213,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nDestroy
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nSetAttrib
(JNIEnv *env, jclass clazz, jobject buffer_handle, jint attrib, jint value)
{
PbufferInfo *Pbuffer_info = (PbufferInfo *)env->GetDirectBufferAddress(buffer_handle);
PbufferInfo *Pbuffer_info = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, buffer_handle);
int attribs[3];
@ -220,13 +227,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nSetAttrib
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nBindTexImage
(JNIEnv *env, jclass clazz, jobject buffer_handle, jint buffer)
{
PbufferInfo *Pbuffer_info = (PbufferInfo *)env->GetDirectBufferAddress(buffer_handle);
PbufferInfo *Pbuffer_info = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, buffer_handle);
wglBindTexImageARB(Pbuffer_info->Pbuffer, buffer);
}
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nReleaseTexImage
(JNIEnv *env, jclass clazz, jobject buffer_handle, jint buffer)
{
PbufferInfo *Pbuffer_info = (PbufferInfo *)env->GetDirectBufferAddress(buffer_handle);
PbufferInfo *Pbuffer_info = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, buffer_handle);
wglReleaseTexImageARB(Pbuffer_info->Pbuffer, buffer);
}