Converted win32 specific native source from C++->C (removes the strange debug flag behaviour exhibited by SourceLimitTest.java)
This commit is contained in:
parent
3640f60f47
commit
46967b394c
|
@ -57,7 +57,6 @@ static WORD currentGamma[GAMMA_SIZE]; // Current gamma settings
|
||||||
static DEVMODE devmode; // Now we'll remember this value for the future
|
static DEVMODE devmode; // Now we'll remember this value for the future
|
||||||
extern HWND display_hwnd; // Handle to the window
|
extern HWND display_hwnd; // Handle to the window
|
||||||
extern RECT clientSize;
|
extern RECT clientSize;
|
||||||
static char * driver = getDriver();
|
|
||||||
|
|
||||||
jobjectArray getAvailableDisplayModes(JNIEnv *env)
|
jobjectArray getAvailableDisplayModes(JNIEnv *env)
|
||||||
{
|
{
|
||||||
|
@ -79,6 +78,17 @@ static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
|
||||||
EnumDisplaySettingsExAPROC EnumDisplaySettingsExA;
|
EnumDisplaySettingsExAPROC EnumDisplaySettingsExA;
|
||||||
|
|
||||||
HMODULE lib_handle = LoadLibrary("user32.dll");
|
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) {
|
if (lib_handle == NULL) {
|
||||||
printfDebug("Could not load user32.dll\n");
|
printfDebug("Could not load user32.dll\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -90,12 +100,6 @@ static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
|
||||||
if (EnumDisplaySettingsExA == NULL)
|
if (EnumDisplaySettingsExA == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
int i = 0, j = 0, n = 0;
|
|
||||||
int AvailableModes = 0;
|
|
||||||
|
|
||||||
DISPLAY_DEVICE DisplayDevice;
|
|
||||||
DEVMODE DevMode;
|
|
||||||
|
|
||||||
ZeroMemory(&DevMode, sizeof(DEVMODE));
|
ZeroMemory(&DevMode, sizeof(DEVMODE));
|
||||||
ZeroMemory(&DisplayDevice, sizeof(DISPLAY_DEVICE));
|
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
|
// 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
|
// 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);
|
ret = (*env)->NewObjectArray(env, AvailableModes, displayModeClass, NULL);
|
||||||
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
|
displayModeConstructor = (*env)->GetMethodID(env, displayModeClass, "<init>", "(IIII)V");
|
||||||
|
|
||||||
i = 0, n = 0;
|
i = 0, n = 0;
|
||||||
while(EnumDisplayDevicesA(NULL, i++, &DisplayDevice, 0) != 0) {
|
while(EnumDisplayDevicesA(NULL, i++, &DisplayDevice, 0) != 0) {
|
||||||
|
@ -140,11 +144,11 @@ static jobjectArray GetAvailableDisplayModesEx(JNIEnv * env) {
|
||||||
// Filter out indexed modes
|
// Filter out indexed modes
|
||||||
if (DevMode.dmBitsPerPel > 8 && ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN | CDS_TEST) == DISP_CHANGE_SUCCESSFUL) {
|
if (DevMode.dmBitsPerPel > 8 && ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN | CDS_TEST) == DISP_CHANGE_SUCCESSFUL) {
|
||||||
jobject displayMode;
|
jobject displayMode;
|
||||||
displayMode = env->NewObject(displayModeClass, displayModeConstructor,
|
displayMode = (*env)->NewObject(env, displayModeClass, displayModeConstructor,
|
||||||
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
|
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
|
||||||
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
|
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;
|
DEVMODE DevMode;
|
||||||
|
|
||||||
|
jclass displayModeClass;
|
||||||
|
|
||||||
|
jobjectArray ret;
|
||||||
|
jmethodID displayModeConstructor;
|
||||||
|
|
||||||
ZeroMemory(&DevMode, sizeof(DEVMODE));
|
ZeroMemory(&DevMode, sizeof(DEVMODE));
|
||||||
|
|
||||||
DevMode.dmSize = 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
|
// 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
|
// 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);
|
ret = (*env)->NewObjectArray(env, AvailableModes, displayModeClass, NULL);
|
||||||
jmethodID displayModeConstructor = env->GetMethodID(displayModeClass, "<init>", "(IIII)V");
|
displayModeConstructor = (*env)->GetMethodID(env, displayModeClass, "<init>", "(IIII)V");
|
||||||
|
|
||||||
i = 0, j = 0, n = 0;
|
i = 0, j = 0, n = 0;
|
||||||
while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) {
|
while(EnumDisplaySettings(NULL, j++, &DevMode) != 0) {
|
||||||
// Filter out indexed modes
|
// Filter out indexed modes
|
||||||
if (DevMode.dmBitsPerPel > 8 && ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN | CDS_TEST) == DISP_CHANGE_SUCCESSFUL) {
|
if (DevMode.dmBitsPerPel > 8 && ChangeDisplaySettings(&DevMode, CDS_FULLSCREEN | CDS_TEST) == DISP_CHANGE_SUCCESSFUL) {
|
||||||
jobject displayMode;
|
jobject displayMode;
|
||||||
displayMode = env->NewObject(displayModeClass, displayModeConstructor,
|
displayMode = (*env)->NewObject(env, displayModeClass, displayModeConstructor,
|
||||||
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
|
DevMode.dmPelsWidth, DevMode.dmPelsHeight,
|
||||||
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
|
DevMode.dmBitsPerPel, DevMode.dmDisplayFrequency);
|
||||||
env->SetObjectArrayElement(ret, n++, displayMode);
|
(*env)->SetObjectArrayElement(env, ret, n++, displayMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -197,16 +206,17 @@ static jobjectArray GetAvailableDisplayModes(JNIEnv * env) {
|
||||||
|
|
||||||
void switchDisplayMode(JNIEnv * env, jobject mode)
|
void switchDisplayMode(JNIEnv * env, jobject mode)
|
||||||
{
|
{
|
||||||
jclass cls_displayMode = env->GetObjectClass(mode);
|
jclass cls_displayMode = (*env)->GetObjectClass(env, mode);
|
||||||
jfieldID fid_width = env->GetFieldID(cls_displayMode, "width", "I");
|
jfieldID fid_width = (*env)->GetFieldID(env, cls_displayMode, "width", "I");
|
||||||
jfieldID fid_height = env->GetFieldID(cls_displayMode, "height", "I");
|
jfieldID fid_height = (*env)->GetFieldID(env, cls_displayMode, "height", "I");
|
||||||
jfieldID fid_bpp = env->GetFieldID(cls_displayMode, "bpp", "I");
|
jfieldID fid_bpp = (*env)->GetFieldID(env, cls_displayMode, "bpp", "I");
|
||||||
jfieldID fid_freq = env->GetFieldID(cls_displayMode, "freq", "I");
|
jfieldID fid_freq = (*env)->GetFieldID(env, cls_displayMode, "freq", "I");
|
||||||
|
|
||||||
int width = env->GetIntField(mode, fid_width);
|
int width = (*env)->GetIntField(env, mode, fid_width);
|
||||||
int height = env->GetIntField(mode, fid_height);
|
int height = (*env)->GetIntField(env, mode, fid_height);
|
||||||
int bpp = env->GetIntField(mode, fid_bpp);
|
int bpp = (*env)->GetIntField(env, mode, fid_bpp);
|
||||||
int freq = env->GetIntField(mode, fid_freq);
|
int freq = (*env)->GetIntField(env, mode, fid_freq);
|
||||||
|
LONG cdsret;
|
||||||
|
|
||||||
devmode.dmSize = sizeof(DEVMODE);
|
devmode.dmSize = sizeof(DEVMODE);
|
||||||
devmode.dmBitsPerPel = bpp;
|
devmode.dmBitsPerPel = bpp;
|
||||||
|
@ -217,7 +227,7 @@ void switchDisplayMode(JNIEnv * env, jobject mode)
|
||||||
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS;
|
devmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFLAGS;
|
||||||
if (freq != 0)
|
if (freq != 0)
|
||||||
devmode.dmFields |= DM_DISPLAYFREQUENCY;
|
devmode.dmFields |= DM_DISPLAYFREQUENCY;
|
||||||
LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
||||||
|
|
||||||
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
||||||
// Failed: so let's check to see if it's a wierd dual screen display
|
// 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)
|
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
|
// Turn array of floats into array of RGB WORDs
|
||||||
|
|
||||||
for (int i = 0; i < 256; i ++) {
|
for (i = 0; i < 256; i ++) {
|
||||||
float scaledRampEntry = gammaRamp[i]*0xffff;
|
scaledRampEntry = gammaRamp[i]*0xffff;
|
||||||
WORD rampEntry = (WORD)scaledRampEntry;
|
rampEntry = (WORD)scaledRampEntry;
|
||||||
currentGamma[i] = rampEntry;
|
currentGamma[i] = rampEntry;
|
||||||
currentGamma[i + 256] = rampEntry;
|
currentGamma[i + 256] = rampEntry;
|
||||||
currentGamma[i + 512] = rampEntry;
|
currentGamma[i + 512] = rampEntry;
|
||||||
}
|
}
|
||||||
HDC screenDC = GetDC(NULL);
|
screenDC = GetDC(NULL);
|
||||||
if (SetDeviceGammaRamp(screenDC, currentGamma) == FALSE) {
|
if (SetDeviceGammaRamp(screenDC, currentGamma) == FALSE) {
|
||||||
throwException(env, "Failed to set device gamma.");
|
throwException(env, "Failed to set device gamma.");
|
||||||
}
|
}
|
||||||
|
@ -261,6 +275,13 @@ void setGammaRamp(JNIEnv * env, jobject gammaRampBuffer)
|
||||||
|
|
||||||
jobject initDisplay(JNIEnv * env)
|
jobject initDisplay(JNIEnv * env)
|
||||||
{
|
{
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
int bpp;
|
||||||
|
int freq;
|
||||||
|
jclass jclass_DisplayMode;
|
||||||
|
jmethodID ctor;
|
||||||
|
jobject newMode;
|
||||||
// Determine the current screen resolution
|
// Determine the current screen resolution
|
||||||
// Get the screen
|
// Get the screen
|
||||||
HDC screenDC = GetDC(NULL);
|
HDC screenDC = GetDC(NULL);
|
||||||
|
@ -269,16 +290,16 @@ jobject initDisplay(JNIEnv * env)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// Get the device caps
|
// Get the device caps
|
||||||
int width = GetDeviceCaps(screenDC, HORZRES);
|
width = GetDeviceCaps(screenDC, HORZRES);
|
||||||
int height = GetDeviceCaps(screenDC, VERTRES);
|
height = GetDeviceCaps(screenDC, VERTRES);
|
||||||
int bpp = GetDeviceCaps(screenDC, BITSPIXEL);
|
bpp = GetDeviceCaps(screenDC, BITSPIXEL);
|
||||||
int freq = GetDeviceCaps(screenDC, VREFRESH);
|
freq = GetDeviceCaps(screenDC, VREFRESH);
|
||||||
if (freq <= 1)
|
if (freq <= 1)
|
||||||
freq = 0; // Unknown
|
freq = 0; // Unknown
|
||||||
|
|
||||||
jclass jclass_DisplayMode = env->FindClass("org/lwjgl/opengl/DisplayMode");
|
jclass_DisplayMode = (*env)->FindClass(env, "org/lwjgl/opengl/DisplayMode");
|
||||||
jmethodID ctor = env->GetMethodID(jclass_DisplayMode, "<init>", "(IIII)V");
|
ctor = (*env)->GetMethodID(env, jclass_DisplayMode, "<init>", "(IIII)V");
|
||||||
jobject newMode = env->NewObject(jclass_DisplayMode, ctor, width, height, bpp, freq);
|
newMode = (*env)->NewObject(env, jclass_DisplayMode, ctor, width, height, bpp, freq);
|
||||||
|
|
||||||
// Get the default gamma ramp
|
// Get the default gamma ramp
|
||||||
if (GetDeviceGammaRamp(screenDC, originalGamma) == FALSE) {
|
if (GetDeviceGammaRamp(screenDC, originalGamma) == FALSE) {
|
||||||
|
@ -314,6 +335,7 @@ void resetDisplayMode(JNIEnv * env) {
|
||||||
void restoreDisplayMode(void) {
|
void restoreDisplayMode(void) {
|
||||||
// Restore gamma
|
// Restore gamma
|
||||||
HDC screenDC = GetDC(NULL);
|
HDC screenDC = GetDC(NULL);
|
||||||
|
LONG cdsret;
|
||||||
if (!SetDeviceGammaRamp(screenDC, currentGamma)) {
|
if (!SetDeviceGammaRamp(screenDC, currentGamma)) {
|
||||||
printfDebug("Could not restore device gamma\n");
|
printfDebug("Could not restore device gamma\n");
|
||||||
}
|
}
|
||||||
|
@ -322,7 +344,7 @@ void restoreDisplayMode(void) {
|
||||||
if (!modeSet) {
|
if (!modeSet) {
|
||||||
printfDebug("Attempting to restore the display mode\n");
|
printfDebug("Attempting to restore the display mode\n");
|
||||||
modeSet = true;
|
modeSet = true;
|
||||||
LONG cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
cdsret = ChangeDisplaySettings(&devmode, CDS_FULLSCREEN);
|
||||||
|
|
||||||
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
if (cdsret != DISP_CHANGE_SUCCESSFUL) {
|
||||||
printfDebug("Failed to restore display mode\n");
|
printfDebug("Failed to restore display mode\n");
|
||||||
|
@ -391,6 +413,7 @@ jstring getAdapter(JNIEnv * env)
|
||||||
{
|
{
|
||||||
|
|
||||||
jstring ret = NULL;
|
jstring ret = NULL;
|
||||||
|
char *driver = getDriver();
|
||||||
if (driver == NULL) {
|
if (driver == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -405,16 +428,20 @@ jstring getVersion(JNIEnv * env)
|
||||||
jstring ret = NULL;
|
jstring ret = NULL;
|
||||||
|
|
||||||
TCHAR driverDLL[256] = "\0";
|
TCHAR driverDLL[256] = "\0";
|
||||||
|
DWORD var = 0;
|
||||||
|
DWORD dwInfoSize;
|
||||||
|
LPVOID lpInfoBuff;
|
||||||
|
BOOL bRetval;
|
||||||
|
char *driver = getDriver();
|
||||||
|
|
||||||
if (driver == NULL) {
|
if (driver == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
strcat(driverDLL, driver);
|
strcat(driverDLL, driver);
|
||||||
strcat(driverDLL, ".dll");
|
strcat(driverDLL, ".dll");
|
||||||
DWORD var = 0;
|
dwInfoSize = GetFileVersionInfoSize(driverDLL, &var);
|
||||||
DWORD dwInfoSize = GetFileVersionInfoSize(driverDLL, &var);
|
lpInfoBuff = malloc(dwInfoSize);
|
||||||
LPVOID lpInfoBuff = new unsigned char[dwInfoSize];
|
bRetval = GetFileVersionInfo(driverDLL, 0, dwInfoSize, lpInfoBuff);
|
||||||
BOOL bRetval = GetFileVersionInfo(driverDLL, NULL, dwInfoSize, lpInfoBuff);
|
|
||||||
if (bRetval == 0) {
|
if (bRetval == 0) {
|
||||||
} else {
|
} else {
|
||||||
VS_FIXEDFILEINFO * fxdFileInfo;
|
VS_FIXEDFILEINFO * fxdFileInfo;
|
||||||
|
@ -431,7 +458,7 @@ jstring getVersion(JNIEnv * env)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
delete lpInfoBuff;
|
free(lpInfoBuff);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
|
@ -139,6 +139,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_Sys_nAlert
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nOpenURL
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nOpenURL
|
||||||
(JNIEnv * env, jobject self, jstring url)
|
(JNIEnv * env, jobject self, jstring url)
|
||||||
{
|
{
|
||||||
|
STARTUPINFO si;
|
||||||
|
PROCESS_INFORMATION pi;
|
||||||
|
|
||||||
char * urlString = GetStringNativeChars(env, url);
|
char * urlString = GetStringNativeChars(env, url);
|
||||||
|
|
||||||
char command[256];
|
char command[256];
|
||||||
|
@ -147,9 +150,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nOpenURL
|
||||||
strncat(command, urlString, 200); // Prevent buffer overflow
|
strncat(command, urlString, 200); // Prevent buffer overflow
|
||||||
free(urlString);
|
free(urlString);
|
||||||
|
|
||||||
STARTUPINFO si;
|
|
||||||
PROCESS_INFORMATION pi;
|
|
||||||
|
|
||||||
ZeroMemory( &si, sizeof(si) );
|
ZeroMemory( &si, sizeof(si) );
|
||||||
si.cb = sizeof(si);
|
si.cb = sizeof(si);
|
||||||
ZeroMemory( &pi, sizeof(pi) );
|
ZeroMemory( &pi, sizeof(pi) );
|
||||||
|
@ -182,12 +182,12 @@ const void * getClipboard(int type)
|
||||||
{
|
{
|
||||||
|
|
||||||
void * ret;
|
void * ret;
|
||||||
|
HANDLE hglb;
|
||||||
// Open the clipboard
|
// Open the clipboard
|
||||||
if (!OpenClipboard(NULL))
|
if (!OpenClipboard(NULL))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
HANDLE hglb = GetClipboardData(type);
|
hglb = GetClipboardData(type);
|
||||||
if (hglb != NULL) {
|
if (hglb != NULL) {
|
||||||
ret = GlobalLock(hglb);
|
ret = GlobalLock(hglb);
|
||||||
if (ret != NULL) {
|
if (ret != NULL) {
|
||||||
|
@ -211,7 +211,7 @@ JNIEXPORT jstring JNICALL Java_org_lwjgl_Sys_nGetClipboard
|
||||||
|
|
||||||
if (unicodeAvailable) {
|
if (unicodeAvailable) {
|
||||||
const wchar_t * str = (const wchar_t *) getClipboard(CF_UNICODETEXT);
|
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) {
|
} else if (textAvailable) {
|
||||||
return NewStringNative(env, (const char *) getClipboard(CF_TEXT));
|
return NewStringNative(env, (const char *) getClipboard(CF_TEXT));
|
||||||
} else {
|
} else {
|
|
@ -169,7 +169,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nCreate(JNIEnv *env, jcla
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Aquire the Controller */
|
/* Aquire the Controller */
|
||||||
hr = cDIDevice->Acquire();
|
hr = IDirectInputDevice_Acquire(cDIDevice);
|
||||||
if(FAILED(hr)) {
|
if(FAILED(hr)) {
|
||||||
ShutdownController();
|
ShutdownController();
|
||||||
throwException(env, "Acquire failed");
|
throwException(env, "Acquire failed");
|
||||||
|
@ -195,13 +195,13 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll(JNIEnv * env, jclas
|
||||||
HRESULT hRes;
|
HRESULT hRes;
|
||||||
|
|
||||||
// poll the Controller to read the current state
|
// poll the Controller to read the current state
|
||||||
hRes = cDIDevice->Poll();
|
hRes = IDirectInputDevice2_Poll(cDIDevice);
|
||||||
if (FAILED(hRes)) {
|
if (FAILED(hRes)) {
|
||||||
printfDebug("Poll fail\n");
|
printfDebug("Poll fail\n");
|
||||||
|
|
||||||
//check if we need to reaquire
|
//check if we need to reaquire
|
||||||
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
||||||
cDIDevice->Acquire();
|
IDirectInputDevice_Acquire(cDIDevice);
|
||||||
printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
|
printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -216,8 +216,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_input_Controller_nPoll(JNIEnv * env, jclas
|
||||||
static void ShutdownController() {
|
static void ShutdownController() {
|
||||||
// release device
|
// release device
|
||||||
if (cDIDevice != NULL) {
|
if (cDIDevice != NULL) {
|
||||||
cDIDevice->Unacquire();
|
IDirectInputDevice_Unacquire(cDIDevice);
|
||||||
cDIDevice->Release();
|
IDirectInputDevice_Release(cDIDevice);
|
||||||
cDIDevice = NULL;
|
cDIDevice = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -227,7 +227,7 @@ static void ShutdownController() {
|
||||||
*/
|
*/
|
||||||
static void EnumerateControllerCapabilities() {
|
static void EnumerateControllerCapabilities() {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = cDIDevice->EnumObjects(EnumControllerObjectsCallback, NULL, DIDFT_ALL);
|
hr = IDirectInputDevice_EnumObjects(cDIDevice, EnumControllerObjectsCallback, NULL, DIDFT_ALL);
|
||||||
if FAILED(hr) {
|
if FAILED(hr) {
|
||||||
printfDebug("EnumObjects failed\n");
|
printfDebug("EnumObjects failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
|
@ -241,7 +241,7 @@ static void EnumerateControllerCapabilities() {
|
||||||
*/
|
*/
|
||||||
static void EnumerateControllers() {
|
static void EnumerateControllers() {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = cDI->EnumDevices(DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY);
|
hr = IDirectInput_EnumDevices(cDI, DIDEVTYPE_JOYSTICK, EnumControllerCallback, 0, DIEDFL_ATTACHEDONLY);
|
||||||
if FAILED(hr) {
|
if FAILED(hr) {
|
||||||
printfDebug("EnumDevices failed\n");
|
printfDebug("EnumDevices failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
|
@ -266,23 +266,23 @@ BOOL CALLBACK EnumControllerCallback(LPCDIDEVICEINSTANCE pdinst, LPVOID pvRef) {
|
||||||
*/
|
*/
|
||||||
BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
|
BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
|
||||||
printfDebug("found %s\n", lpddoi->tszName);
|
printfDebug("found %s\n", lpddoi->tszName);
|
||||||
if(lpddoi->guidType == GUID_Button) {
|
if(IsEqualGUID(&lpddoi->guidType, &GUID_Button)) {
|
||||||
cButtoncount++;
|
cButtoncount++;
|
||||||
} else if(lpddoi->guidType == GUID_XAxis) {
|
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_XAxis)) {
|
||||||
cHasx = true;
|
cHasx = true;
|
||||||
} else if(lpddoi->guidType == GUID_YAxis) {
|
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_YAxis)) {
|
||||||
cHasy = true;
|
cHasy = true;
|
||||||
} else if(lpddoi->guidType == GUID_ZAxis){
|
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_ZAxis)) {
|
||||||
cHasz = true;
|
cHasz = true;
|
||||||
} else if (lpddoi->guidType == GUID_POV){
|
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_POV)) {
|
||||||
cHaspov = true;
|
cHaspov = true;
|
||||||
} else if (lpddoi->guidType == GUID_Slider){
|
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_Slider)) {
|
||||||
cHasslider = true;
|
cHasslider = true;
|
||||||
} else if (lpddoi->guidType == GUID_RxAxis) {
|
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_RxAxis)) {
|
||||||
cHasrx = true;
|
cHasrx = true;
|
||||||
} else if (lpddoi->guidType == GUID_RyAxis) {
|
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_RyAxis)) {
|
||||||
cHasry = true;
|
cHasry = true;
|
||||||
} else if (lpddoi->guidType == GUID_RzAxis) {
|
} else if (IsEqualGUID(&lpddoi->guidType, &GUID_RzAxis)) {
|
||||||
cHasrz = true;
|
cHasrz = true;
|
||||||
} else {
|
} else {
|
||||||
printfDebug("Unhandled object found: %s\n", lpddoi->tszName);
|
printfDebug("Unhandled object found: %s\n", lpddoi->tszName);
|
||||||
|
@ -295,7 +295,7 @@ BOOL CALLBACK EnumControllerObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LP
|
||||||
*/
|
*/
|
||||||
static void CreateController(LPCDIDEVICEINSTANCE lpddi) {
|
static void CreateController(LPCDIDEVICEINSTANCE lpddi) {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = cDI->CreateDevice(lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL);
|
hr = IDirectInput_CreateDevice(cDI, &lpddi->guidInstance, (LPDIRECTINPUTDEVICE*) &cDIDevice, NULL);
|
||||||
if FAILED(hr) {
|
if FAILED(hr) {
|
||||||
printfDebug("CreateDevice failed\n");
|
printfDebug("CreateDevice failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
|
@ -308,15 +308,16 @@ static void CreateController(LPCDIDEVICEINSTANCE lpddi) {
|
||||||
* Sets up the Controller properties
|
* Sets up the Controller properties
|
||||||
*/
|
*/
|
||||||
static void SetupController() {
|
static void SetupController() {
|
||||||
|
DIPROPRANGE diprg;
|
||||||
// set Controller data format
|
// set Controller data format
|
||||||
if(cDIDevice->SetDataFormat(&c_dfDIJoystick2) != DI_OK) {
|
if(IDirectInputDevice_SetDataFormat(cDIDevice, &c_dfDIJoystick2) != DI_OK) {
|
||||||
printfDebug("SetDataFormat failed\n");
|
printfDebug("SetDataFormat failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the cooperative level
|
// 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");
|
printfDebug("SetCooperativeLevel failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -324,7 +325,6 @@ static void SetupController() {
|
||||||
|
|
||||||
// set range to (-1000 ... +1000)
|
// set range to (-1000 ... +1000)
|
||||||
// This lets us test against 0 to see which way the stick is pointed.
|
// This lets us test against 0 to see which way the stick is pointed.
|
||||||
DIPROPRANGE diprg;
|
|
||||||
diprg.diph.dwSize = sizeof(diprg);
|
diprg.diph.dwSize = sizeof(diprg);
|
||||||
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
|
diprg.diph.dwHeaderSize = sizeof(diprg.diph);
|
||||||
diprg.diph.dwHow = DIPH_BYOFFSET;
|
diprg.diph.dwHow = DIPH_BYOFFSET;
|
||||||
|
@ -334,7 +334,7 @@ static void SetupController() {
|
||||||
// set X-axis
|
// set X-axis
|
||||||
if(cHasx) {
|
if(cHasx) {
|
||||||
diprg.diph.dwObj = DIJOFS_X;
|
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");
|
printfDebug("SetProperty(DIJOFS_X) failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -344,7 +344,7 @@ static void SetupController() {
|
||||||
// set RX-axis
|
// set RX-axis
|
||||||
if(cHasrx) {
|
if(cHasrx) {
|
||||||
diprg.diph.dwObj = DIJOFS_RX;
|
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");
|
printfDebug("SetProperty(DIJOFS_RX) failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -355,7 +355,7 @@ static void SetupController() {
|
||||||
// set Y-axis
|
// set Y-axis
|
||||||
if(cHasy) {
|
if(cHasy) {
|
||||||
diprg.diph.dwObj = DIJOFS_Y;
|
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");
|
printfDebug("SetProperty(DIJOFS_Y) failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -365,7 +365,7 @@ static void SetupController() {
|
||||||
// set RY-axis
|
// set RY-axis
|
||||||
if(cHasry) {
|
if(cHasry) {
|
||||||
diprg.diph.dwObj = DIJOFS_RY;
|
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");
|
printfDebug("SetProperty(DIJOFS_RY) failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -375,7 +375,7 @@ static void SetupController() {
|
||||||
// set Z-axis
|
// set Z-axis
|
||||||
if(cHasz) {
|
if(cHasz) {
|
||||||
diprg.diph.dwObj = DIJOFS_Z;
|
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");
|
printfDebug("SetProperty(DIJOFS_Z) failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -386,7 +386,7 @@ static void SetupController() {
|
||||||
// set RZ-axis
|
// set RZ-axis
|
||||||
if(cHasrz) {
|
if(cHasrz) {
|
||||||
diprg.diph.dwObj = DIJOFS_RZ;
|
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");
|
printfDebug("SetProperty(DIJOFS_RZ) failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -399,7 +399,7 @@ static void SetupController() {
|
||||||
//
|
//
|
||||||
if(cHasslider) {
|
if(cHasslider) {
|
||||||
diprg.diph.dwObj = DIJOFS_Z;
|
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");
|
printfDebug("SetProperty(DIJOFS_Z(SLIDER)) failed\n");
|
||||||
cCreate_success = false;
|
cCreate_success = false;
|
||||||
return;
|
return;
|
||||||
|
@ -413,26 +413,28 @@ static void SetupController() {
|
||||||
*/
|
*/
|
||||||
static void InitializeControllerFields(JNIEnv *env, jclass clsController) {
|
static void InitializeControllerFields(JNIEnv *env, jclass clsController) {
|
||||||
//create buttons array
|
//create buttons array
|
||||||
jbooleanArray cButtonsArray = env->NewBooleanArray(cButtoncount);
|
jbooleanArray cButtonsArray = (*env)->NewBooleanArray(env, cButtoncount);
|
||||||
|
|
||||||
//set buttons array
|
//set buttons array
|
||||||
env->SetStaticObjectField(clsController, fidCButtons, cButtonsArray);
|
(*env)->SetStaticObjectField(env, clsController, fidCButtons, cButtonsArray);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Updates the fields on the Controller
|
* Updates the fields on the Controller
|
||||||
*/
|
*/
|
||||||
static void UpdateControllerFields(JNIEnv *env, jclass clsController) {
|
static void UpdateControllerFields(JNIEnv *env, jclass clsController) {
|
||||||
|
int i;
|
||||||
|
jbyteArray buttonsArray;
|
||||||
HRESULT hRes;
|
HRESULT hRes;
|
||||||
|
|
||||||
// get data from the Controller
|
// get data from the Controller
|
||||||
hRes = cDIDevice->GetDeviceState(sizeof(DIJOYSTATE2), &cJS);
|
hRes = IDirectInputDevice_GetDeviceState(cDIDevice, sizeof(DIJOYSTATE2), &cJS);
|
||||||
|
|
||||||
if (hRes != DI_OK) {
|
if (hRes != DI_OK) {
|
||||||
// did the read fail because we lost input for some reason?
|
// did the read fail because we lost input for some reason?
|
||||||
// if so, then attempt to reacquire.
|
// if so, then attempt to reacquire.
|
||||||
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
||||||
cDIDevice->Acquire();
|
IDirectInputDevice_Acquire(cDIDevice);
|
||||||
printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
|
printfDebug("DIERR_INPUTLOST, reaquiring input : cCreate_success=%d\n", cCreate_success);
|
||||||
}
|
}
|
||||||
printfDebug("Error getting controller state: %d\n", hRes);
|
printfDebug("Error getting controller state: %d\n", hRes);
|
||||||
|
@ -441,49 +443,49 @@ static void UpdateControllerFields(JNIEnv *env, jclass clsController) {
|
||||||
|
|
||||||
//axis's
|
//axis's
|
||||||
if(cHasx) {
|
if(cHasx) {
|
||||||
env->SetStaticIntField(clsController, fidCX, cJS.lX);
|
(*env)->SetStaticIntField(env, clsController, fidCX, cJS.lX);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cHasy) {
|
if(cHasy) {
|
||||||
env->SetStaticIntField(clsController, fidCY, cJS.lY);
|
(*env)->SetStaticIntField(env, clsController, fidCY, cJS.lY);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cHasz) {
|
if(cHasz) {
|
||||||
env->SetStaticIntField(clsController, fidCZ, cJS.lZ);
|
(*env)->SetStaticIntField(env, clsController, fidCZ, cJS.lZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
//rotational axis
|
//rotational axis
|
||||||
if(cHasrx) {
|
if(cHasrx) {
|
||||||
env->SetStaticIntField(clsController, fidCRX, cJS.lRx);
|
(*env)->SetStaticIntField(env, clsController, fidCRX, cJS.lRx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cHasry) {
|
if(cHasry) {
|
||||||
env->SetStaticIntField(clsController, fidCRY, cJS.lRy);
|
(*env)->SetStaticIntField(env, clsController, fidCRY, cJS.lRy);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(cHasrz) {
|
if(cHasrz) {
|
||||||
env->SetStaticIntField(clsController, fidCRZ, cJS.lRz);
|
(*env)->SetStaticIntField(env, clsController, fidCRZ, cJS.lRz);
|
||||||
}
|
}
|
||||||
|
|
||||||
//buttons
|
//buttons
|
||||||
for (int i = 0; i < cButtoncount; i++) {
|
for (i = 0; i < cButtoncount; i++) {
|
||||||
if (cJS.rgbButtons[i] != 0) {
|
if (cJS.rgbButtons[i] != 0) {
|
||||||
cJS.rgbButtons[i] = 1;
|
cJS.rgbButtons[i] = 1;
|
||||||
} else {
|
} else {
|
||||||
cJS.rgbButtons[i] = 0;
|
cJS.rgbButtons[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
jbyteArray buttonsArray = (jbyteArray) env->GetStaticObjectField(clsController, fidCButtons);
|
buttonsArray = (jbyteArray) (*env)->GetStaticObjectField(env, clsController, fidCButtons);
|
||||||
env->SetByteArrayRegion(buttonsArray, 0, cButtoncount, (jbyte *)cJS.rgbButtons);
|
(*env)->SetByteArrayRegion(env, buttonsArray, 0, cButtoncount, (jbyte *)cJS.rgbButtons);
|
||||||
|
|
||||||
//pov
|
//pov
|
||||||
if(cHaspov) {
|
if(cHaspov) {
|
||||||
env->SetStaticIntField(clsController, fidCPOV, cJS.rgdwPOV[0]);
|
(*env)->SetStaticIntField(env, clsController, fidCPOV, cJS.rgdwPOV[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
//slider
|
//slider
|
||||||
if(cHasslider) {
|
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) {
|
static void SetControllerCapabilities(JNIEnv *env, jclass clsController) {
|
||||||
//set buttoncount
|
//set buttoncount
|
||||||
env->SetStaticIntField(clsController, fidCButtonCount, cButtoncount);
|
(*env)->SetStaticIntField(env, clsController, fidCButtonCount, cButtoncount);
|
||||||
|
|
||||||
//set axis
|
//set axis
|
||||||
env->SetStaticBooleanField(clsController, fidCHasXAxis, cHasx);
|
(*env)->SetStaticBooleanField(env, clsController, fidCHasXAxis, cHasx);
|
||||||
env->SetStaticBooleanField(clsController, fidCHasYAxis, cHasy);
|
(*env)->SetStaticBooleanField(env, clsController, fidCHasYAxis, cHasy);
|
||||||
env->SetStaticBooleanField(clsController, fidCHasZAxis, cHasz);
|
(*env)->SetStaticBooleanField(env, clsController, fidCHasZAxis, cHasz);
|
||||||
|
|
||||||
//set rotational axis
|
//set rotational axis
|
||||||
env->SetStaticBooleanField(clsController, fidCHasRXAxis, cHasrx);
|
(*env)->SetStaticBooleanField(env, clsController, fidCHasRXAxis, cHasrx);
|
||||||
env->SetStaticBooleanField(clsController, fidCHasRYAxis, cHasry);
|
(*env)->SetStaticBooleanField(env, clsController, fidCHasRYAxis, cHasry);
|
||||||
env->SetStaticBooleanField(clsController, fidCHasRZAxis, cHasrz);
|
(*env)->SetStaticBooleanField(env, clsController, fidCHasRZAxis, cHasrz);
|
||||||
|
|
||||||
//set pov
|
//set pov
|
||||||
env->SetStaticBooleanField(clsController, fidCHasPOV, cHaspov);
|
(*env)->SetStaticBooleanField(env, clsController, fidCHasPOV, cHaspov);
|
||||||
|
|
||||||
//set slider
|
//set slider
|
||||||
env->SetStaticBooleanField(clsController, fidCHasSlider, cHasslider);
|
(*env)->SetStaticBooleanField(env, clsController, fidCHasSlider, cHasslider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Caches the field ids for quicker access
|
* Caches the field ids for quicker access
|
||||||
*/
|
*/
|
||||||
static void CacheControllerFields(JNIEnv *env, jclass clsController) {
|
static void CacheControllerFields(JNIEnv *env, jclass clsController) {
|
||||||
fidCButtonCount = env->GetStaticFieldID(clsController, "buttonCount", "I");
|
fidCButtonCount = (*env)->GetStaticFieldID(env, clsController, "buttonCount", "I");
|
||||||
fidCHasXAxis = env->GetStaticFieldID(clsController, "hasXAxis", "Z");
|
fidCHasXAxis = (*env)->GetStaticFieldID(env, clsController, "hasXAxis", "Z");
|
||||||
fidCHasRXAxis = env->GetStaticFieldID(clsController, "hasRXAxis", "Z");
|
fidCHasRXAxis = (*env)->GetStaticFieldID(env, clsController, "hasRXAxis", "Z");
|
||||||
fidCHasYAxis = env->GetStaticFieldID(clsController, "hasYAxis", "Z");
|
fidCHasYAxis = (*env)->GetStaticFieldID(env, clsController, "hasYAxis", "Z");
|
||||||
fidCHasRYAxis = env->GetStaticFieldID(clsController, "hasRYAxis", "Z");
|
fidCHasRYAxis = (*env)->GetStaticFieldID(env, clsController, "hasRYAxis", "Z");
|
||||||
fidCHasZAxis = env->GetStaticFieldID(clsController, "hasZAxis", "Z");
|
fidCHasZAxis = (*env)->GetStaticFieldID(env, clsController, "hasZAxis", "Z");
|
||||||
fidCHasRZAxis = env->GetStaticFieldID(clsController, "hasRZAxis", "Z");
|
fidCHasRZAxis = (*env)->GetStaticFieldID(env, clsController, "hasRZAxis", "Z");
|
||||||
fidCHasPOV = env->GetStaticFieldID(clsController, "hasPOV", "Z");
|
fidCHasPOV = (*env)->GetStaticFieldID(env, clsController, "hasPOV", "Z");
|
||||||
fidCHasSlider = env->GetStaticFieldID(clsController, "hasSlider", "Z");
|
fidCHasSlider = (*env)->GetStaticFieldID(env, clsController, "hasSlider", "Z");
|
||||||
fidCButtons = env->GetStaticFieldID(clsController, "buttons", "[Z");
|
fidCButtons = (*env)->GetStaticFieldID(env, clsController, "buttons", "[Z");
|
||||||
fidCX = env->GetStaticFieldID(clsController, "x", "I");
|
fidCX = (*env)->GetStaticFieldID(env, clsController, "x", "I");
|
||||||
fidCRX = env->GetStaticFieldID(clsController, "rx", "I");
|
fidCRX = (*env)->GetStaticFieldID(env, clsController, "rx", "I");
|
||||||
fidCY = env->GetStaticFieldID(clsController, "y", "I");
|
fidCY = (*env)->GetStaticFieldID(env, clsController, "y", "I");
|
||||||
fidCRY = env->GetStaticFieldID(clsController, "ry", "I");
|
fidCRY = (*env)->GetStaticFieldID(env, clsController, "ry", "I");
|
||||||
fidCZ = env->GetStaticFieldID(clsController, "z", "I");
|
fidCZ = (*env)->GetStaticFieldID(env, clsController, "z", "I");
|
||||||
fidCRZ = env->GetStaticFieldID(clsController, "rz", "I");
|
fidCRZ = (*env)->GetStaticFieldID(env, clsController, "rz", "I");
|
||||||
fidCPOV = env->GetStaticFieldID(clsController, "pov", "I");
|
fidCPOV = (*env)->GetStaticFieldID(env, clsController, "pov", "I");
|
||||||
fidCSlider = env->GetStaticFieldID(clsController, "slider", "I");
|
fidCSlider = (*env)->GetStaticFieldID(env, clsController, "slider", "I");
|
||||||
}
|
}
|
76
src/native/win32/org_lwjgl_input_Cursor.cpp → src/native/win32/org_lwjgl_input_Cursor.c
Executable file → Normal file
76
src/native/win32/org_lwjgl_input_Cursor.cpp → src/native/win32/org_lwjgl_input_Cursor.c
Executable file → Normal file
|
@ -47,18 +47,34 @@
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor
|
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)
|
(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");
|
throwException(env, "Handle buffer not large enough");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int *pixels = (int *)env->GetDirectBufferAddress(image_buffer) + images_offset;
|
pixels = (int *)(*env)->GetDirectBufferAddress(env, image_buffer) + images_offset;
|
||||||
|
|
||||||
BITMAPINFO bitmapInfo;
|
|
||||||
|
|
||||||
char *ptrCursorImage;
|
|
||||||
HBITMAP colorDIB;
|
|
||||||
HBITMAP colorBitmap;
|
|
||||||
int x, y;
|
|
||||||
|
|
||||||
memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
|
memset(&bitmapInfo, 0, sizeof(BITMAPINFO));
|
||||||
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
bitmapInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
||||||
|
@ -73,8 +89,8 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor
|
||||||
DIB_RGB_COLORS,
|
DIB_RGB_COLORS,
|
||||||
(void**)&(ptrCursorImage),
|
(void**)&(ptrCursorImage),
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
int *srcPtr = pixels;
|
srcPtr = pixels;
|
||||||
char *dstPtr = ptrCursorImage;
|
dstPtr = ptrCursorImage;
|
||||||
if (!dstPtr) {
|
if (!dstPtr) {
|
||||||
throwException(env, "Could not allocate DIB section.");
|
throwException(env, "Could not allocate DIB section.");
|
||||||
return;
|
return;
|
||||||
|
@ -100,31 +116,27 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor
|
||||||
DeleteObject(colorDIB);
|
DeleteObject(colorDIB);
|
||||||
|
|
||||||
// Convert alpha map to pixel packed mask
|
// Convert alpha map to pixel packed mask
|
||||||
int bitWidth = width >> 3;
|
bitWidth = width >> 3;
|
||||||
int scanlinePad = bitWidth & (sizeof(WORD) - 1);
|
scanlinePad = bitWidth & (sizeof(WORD) - 1);
|
||||||
int imageSize = (bitWidth + scanlinePad)*height; // Size in bits
|
imageSize = (bitWidth + scanlinePad)*height; // Size in bits
|
||||||
unsigned char *maskPixels = new unsigned char[imageSize];
|
maskPixels = (unsigned char*)malloc(sizeof(unsigned char)*imageSize);
|
||||||
memset(maskPixels, 0, imageSize);
|
memset(maskPixels, 0, imageSize);
|
||||||
int pixelCount = 0;
|
|
||||||
int maskCount = 0;
|
|
||||||
for (y = 0; y < height; y++)
|
for (y = 0; y < height; y++)
|
||||||
for (x = 0; x < bitWidth; x++) {
|
for (x = 0; x < bitWidth; x++) {
|
||||||
unsigned char col0 = (pixels[pixelCount++] & 0x01000000) >> 17;
|
col0 = (pixels[pixelCount++] & 0x01000000) >> 17;
|
||||||
unsigned char col1 = (pixels[pixelCount++] & 0x01000000) >> 18;
|
col1 = (pixels[pixelCount++] & 0x01000000) >> 18;
|
||||||
unsigned char col2 = (pixels[pixelCount++] & 0x01000000) >> 19;
|
col2 = (pixels[pixelCount++] & 0x01000000) >> 19;
|
||||||
unsigned char col3 = (pixels[pixelCount++] & 0x01000000) >> 20;
|
col3 = (pixels[pixelCount++] & 0x01000000) >> 20;
|
||||||
unsigned char col4 = (pixels[pixelCount++] & 0x01000000) >> 21;
|
col4 = (pixels[pixelCount++] & 0x01000000) >> 21;
|
||||||
unsigned char col5 = (pixels[pixelCount++] & 0x01000000) >> 22;
|
col5 = (pixels[pixelCount++] & 0x01000000) >> 22;
|
||||||
unsigned char col6 = (pixels[pixelCount++] & 0x01000000) >> 23;
|
col6 = (pixels[pixelCount++] & 0x01000000) >> 23;
|
||||||
unsigned char col7 = (pixels[pixelCount++] & 0x01000000) >> 24;
|
col7 = (pixels[pixelCount++] & 0x01000000) >> 24;
|
||||||
unsigned char mask = col0 | col1 | col2 | col3 | col4 | col5 | col6 | col7;
|
mask = col0 | col1 | col2 | col3 | col4 | col5 | col6 | col7;
|
||||||
maskPixels[maskCount++] = ~mask; // 1 is tranparant, 0 opaque
|
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));
|
memset(&iconInfo, 0, sizeof(ICONINFO));
|
||||||
iconInfo.hbmMask = cursorMask;
|
iconInfo.hbmMask = cursorMask;
|
||||||
iconInfo.hbmColor = colorBitmap;
|
iconInfo.hbmColor = colorBitmap;
|
||||||
|
@ -134,9 +146,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_nCreateCursor
|
||||||
cursor = CreateIconIndirect(&iconInfo);
|
cursor = CreateIconIndirect(&iconInfo);
|
||||||
DeleteObject(colorBitmap);
|
DeleteObject(colorBitmap);
|
||||||
DeleteObject(cursorMask);
|
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;
|
*cursor_handle = cursor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,6 +161,6 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_destroyCursor
|
||||||
(JNIEnv *env, jobject self, jobject handle_buffer)
|
(JNIEnv *env, jobject self, jobject handle_buffer)
|
||||||
{
|
{
|
||||||
// HCURSOR cursor = (HCURSOR)cursor_handle;
|
// 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);
|
DestroyCursor(*cursor_handle);
|
||||||
}
|
}
|
|
@ -61,6 +61,7 @@ static bool useUnicode;
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createKeyboard
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createKeyboard
|
||||||
(JNIEnv * env, jobject self)
|
(JNIEnv * env, jobject self)
|
||||||
{
|
{
|
||||||
|
DIPROPDWORD dipropdw;
|
||||||
// Create input
|
// Create input
|
||||||
HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
|
HRESULT ret = DirectInputCreate(dll_handle, DIRECTINPUT_VERSION, &lpdi, NULL);
|
||||||
if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION) {
|
if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION) {
|
||||||
|
@ -76,28 +77,27 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createKeyboard
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a keyboard device
|
// 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.");
|
throwException(env, "Failed to create keyboard.");
|
||||||
return;
|
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.");
|
throwException(env, "Failed to set keyboard cooperation mode.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tell 'em wot format to be in (the default "you are a mouse and keyboard" format)
|
// 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.dwSize = sizeof(DIPROPDWORD);
|
||||||
dipropdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
dipropdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||||
dipropdw.diph.dwObj = 0;
|
dipropdw.diph.dwObj = 0;
|
||||||
dipropdw.diph.dwHow = DIPH_DEVICE;
|
dipropdw.diph.dwHow = DIPH_DEVICE;
|
||||||
dipropdw.dwData = KEYBOARD_BUFFER_SIZE;
|
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)) {
|
if(FAILED(ret)) {
|
||||||
printfDebug("Failed to acquire keyboard\n");
|
printfDebug("Failed to acquire keyboard\n");
|
||||||
}
|
}
|
||||||
|
@ -113,14 +113,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_destroyKeyboard
|
||||||
{
|
{
|
||||||
// Release keyboard
|
// Release keyboard
|
||||||
if (lpdiKeyboard != NULL) {
|
if (lpdiKeyboard != NULL) {
|
||||||
lpdiKeyboard->Unacquire();
|
IDirectInputDevice_Unacquire(lpdiKeyboard);
|
||||||
lpdiKeyboard->Release();
|
IDirectInputDevice_Release(lpdiKeyboard);
|
||||||
lpdiKeyboard = NULL;
|
lpdiKeyboard = NULL;
|
||||||
}
|
}
|
||||||
// Release DirectInput
|
// Release DirectInput
|
||||||
if (lpdi != NULL) {
|
if (lpdi != NULL) {
|
||||||
printfDebug("Destroying directinput\n");
|
printfDebug("Destroying directinput\n");
|
||||||
lpdi->Release();
|
IDirectInput_Release(lpdi);
|
||||||
lpdi = NULL;
|
lpdi = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -134,8 +134,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_pollKeyboard
|
||||||
(JNIEnv * env, jobject self, jobject buffer)
|
(JNIEnv * env, jobject self, jobject buffer)
|
||||||
{
|
{
|
||||||
HRESULT ret;
|
HRESULT ret;
|
||||||
|
void *keyboardBuffer;
|
||||||
|
jlong buffer_size;
|
||||||
do {
|
do {
|
||||||
ret = lpdiKeyboard->Acquire();
|
ret = IDirectInputDevice_Acquire(lpdiKeyboard);
|
||||||
if (ret == DIERR_INPUTLOST) {
|
if (ret == DIERR_INPUTLOST) {
|
||||||
printf("Input lost\n");
|
printf("Input lost\n");
|
||||||
return;
|
return;
|
||||||
|
@ -157,15 +159,24 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_pollKeyboard
|
||||||
}
|
}
|
||||||
} while (ret != DI_OK && ret != S_FALSE);
|
} while (ret != DI_OK && ret != S_FALSE);
|
||||||
|
|
||||||
void *keyboardBuffer = (void *)env->GetDirectBufferAddress(buffer);
|
keyboardBuffer = (void *)(*env)->GetDirectBufferAddress(env, buffer);
|
||||||
jlong buffer_size = env->GetDirectBufferCapacity(buffer);
|
buffer_size = (*env)->GetDirectBufferCapacity(env, buffer);
|
||||||
lpdiKeyboard->GetDeviceState((DWORD)buffer_size, keyboardBuffer);
|
IDirectInputDevice_GetDeviceState(lpdiKeyboard, (DWORD)buffer_size, keyboardBuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readKeyboard
|
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readKeyboard
|
||||||
(JNIEnv * env, jobject self, jobject buffer_obj, jint buffer_position)
|
(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];
|
wchar_t transBufUnicode[KEYBOARD_BUFFER_SIZE];
|
||||||
WORD transBufAscii[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_chars;
|
||||||
int num_events = 0;
|
int num_events = 0;
|
||||||
|
|
||||||
ret = lpdiKeyboard->Acquire();
|
ret = IDirectInputDevice_Acquire(lpdiKeyboard);
|
||||||
if (ret != DI_OK && ret != S_FALSE)
|
if (ret != DI_OK && ret != S_FALSE)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
ret = lpdiKeyboard->GetDeviceData(
|
ret = IDirectInputDevice_GetDeviceData(lpdiKeyboard,
|
||||||
sizeof(DIDEVICEOBJECTDATA),
|
sizeof(DIDEVICEOBJECTDATA),
|
||||||
rgdod,
|
rgdod,
|
||||||
&num_di_events,
|
&num_di_events,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
if (ret == DI_OK) {
|
if (ret == DI_OK) {
|
||||||
jint * buf = buffer_position + (jint *)env->GetDirectBufferAddress(buffer_obj);
|
buf = buffer_position + (jint *)(*env)->GetDirectBufferAddress(env, buffer_obj);
|
||||||
int buffer_size = ((int)env->GetDirectBufferCapacity(buffer_obj))/sizeof(jint) - buffer_position;
|
buffer_size = ((int)(*env)->GetDirectBufferCapacity(env, buffer_obj))/sizeof(jint) - buffer_position;
|
||||||
int index = 0;
|
|
||||||
int event_size = 3;
|
|
||||||
DWORD current_di_event = 0;
|
|
||||||
while (index + event_size <= buffer_size && current_di_event < num_di_events) {
|
while (index + event_size <= buffer_size && current_di_event < num_di_events) {
|
||||||
num_events++;
|
num_events++;
|
||||||
buf[index++] = (unsigned char) rgdod[current_di_event].dwOfs;
|
buf[index++] = (unsigned char) rgdod[current_di_event].dwOfs;
|
||||||
buf[index++] = (unsigned char) rgdod[current_di_event].dwData;
|
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) {
|
if (translationEnabled && key_down) {
|
||||||
UINT scan_code = rgdod[current_di_event].dwOfs;
|
scan_code = rgdod[current_di_event].dwOfs;
|
||||||
UINT virt_key = MapVirtualKey(scan_code, 1);
|
virt_key = MapVirtualKey(scan_code, 1);
|
||||||
if (virt_key != 0 && GetKeyboardState(state)) {
|
if (virt_key != 0 && GetKeyboardState(state)) {
|
||||||
// Mark key down in the scan code
|
// Mark key down in the scan code
|
||||||
scan_code = scan_code & 0x7fff;
|
scan_code = scan_code & 0x7fff;
|
||||||
|
@ -224,7 +232,6 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readKeyboard
|
||||||
buf[index++] = 0;
|
buf[index++] = 0;
|
||||||
buf[index++] = 0;
|
buf[index++] = 0;
|
||||||
}
|
}
|
||||||
jint ch_int;
|
|
||||||
if (useUnicode) {
|
if (useUnicode) {
|
||||||
wchar_t ch = transBufUnicode[current_char];
|
wchar_t ch = transBufUnicode[current_char];
|
||||||
ch_int = ((int)ch) & 0xFFFF;
|
ch_int = ((int)ch) & 0xFFFF;
|
|
@ -114,7 +114,7 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getButtonCount(JNIEnv
|
||||||
* Called when the Mouse instance is to be created
|
* Called when the Mouse instance is to be created
|
||||||
*/
|
*/
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *env, jobject self) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *env, jobject self) {
|
||||||
HRESULT hr;
|
HRESULT ret;
|
||||||
|
|
||||||
initEventQueue(&event_queue, EVENT_SIZE);
|
initEventQueue(&event_queue, EVENT_SIZE);
|
||||||
|
|
||||||
|
@ -122,7 +122,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *en
|
||||||
buffer_enabled = false;
|
buffer_enabled = false;
|
||||||
|
|
||||||
// Create input
|
// 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) {
|
if (ret != DI_OK && ret != DIERR_BETADIRECTINPUTVERSION) {
|
||||||
throwException(env, "Failed to create DirectInput");
|
throwException(env, "Failed to create DirectInput");
|
||||||
return;
|
return;
|
||||||
|
@ -149,9 +149,9 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createMouse(JNIEnv *en
|
||||||
SetupMouse();
|
SetupMouse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Aquire the Mouse */
|
/* Aquire the Mouse */
|
||||||
hr = mDIDevice->Acquire();
|
ret = IDirectInputDevice_Acquire(mDIDevice);
|
||||||
if(FAILED(hr)) {
|
if(FAILED(ret)) {
|
||||||
printfDebug("Failed to acquire mouse\n");
|
printfDebug("Failed to acquire mouse\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,10 +168,12 @@ void handleMouseScrolled(int event_dwheel) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleMouseMoved(int x, int y) {
|
void handleMouseMoved(int x, int y) {
|
||||||
|
int dx;
|
||||||
|
int dy;
|
||||||
if(mCreate_success) {
|
if(mCreate_success) {
|
||||||
y = transformY(y);
|
y = transformY(y);
|
||||||
int dx = x - last_x;
|
dx = x - last_x;
|
||||||
int dy = y - last_y;
|
dy = y - last_y;
|
||||||
accum_dx += dx;
|
accum_dx += dx;
|
||||||
accum_dy += dy;
|
accum_dy += dy;
|
||||||
last_x = x;
|
last_x = x;
|
||||||
|
@ -193,8 +195,10 @@ void handleMouseButton(int button, int state) {
|
||||||
static void copyDXEvents(int num_di_events, DIDEVICEOBJECTDATA *di_buffer) {
|
static void copyDXEvents(int num_di_events, DIDEVICEOBJECTDATA *di_buffer) {
|
||||||
int buffer_index = 0;
|
int buffer_index = 0;
|
||||||
int dx = 0, dy = 0, dwheel = 0;
|
int dx = 0, dy = 0, dwheel = 0;
|
||||||
for (int i = 0; i < num_di_events; i++) {
|
int button_state;
|
||||||
int button_state = (di_buffer[i].dwData & 0x80) != 0 ? 1 : 0;
|
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) {
|
switch (di_buffer[i].dwOfs) {
|
||||||
case DIMOFS_BUTTON0:
|
case DIMOFS_BUTTON0:
|
||||||
putMouseEventWithCoords(0, button_state, dx, -dy, dwheel);
|
putMouseEventWithCoords(0, button_state, dx, -dy, dwheel);
|
||||||
|
@ -233,11 +237,11 @@ static void readDXBuffer() {
|
||||||
|
|
||||||
HRESULT ret;
|
HRESULT ret;
|
||||||
|
|
||||||
ret = mDIDevice->Acquire();
|
ret = IDirectInputDevice_Acquire(mDIDevice);
|
||||||
if (ret != DI_OK && ret != S_FALSE)
|
if (ret != DI_OK && ret != S_FALSE)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ret = mDIDevice->GetDeviceData(
|
ret = IDirectInputDevice_GetDeviceData(mDIDevice,
|
||||||
sizeof(DIDEVICEOBJECTDATA),
|
sizeof(DIDEVICEOBJECTDATA),
|
||||||
rgdod,
|
rgdod,
|
||||||
&num_di_events,
|
&num_di_events,
|
||||||
|
@ -265,8 +269,8 @@ static void readDXBuffer() {
|
||||||
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readMouse
|
JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_readMouse
|
||||||
(JNIEnv * env, jobject self, jobject buffer_obj, jint buffer_position)
|
(JNIEnv * env, jobject self, jobject buffer_obj, jint buffer_position)
|
||||||
{
|
{
|
||||||
jint* buffer_ptr = (jint *)env->GetDirectBufferAddress(buffer_obj) + buffer_position;
|
jint* buffer_ptr = (jint *)(*env)->GetDirectBufferAddress(env, buffer_obj) + buffer_position;
|
||||||
int buffer_size = (env->GetDirectBufferCapacity(buffer_obj))/sizeof(jint) - buffer_position;
|
int buffer_size = ((*env)->GetDirectBufferCapacity(env, buffer_obj))/sizeof(jint) - buffer_position;
|
||||||
if (mouse_grabbed) {
|
if (mouse_grabbed) {
|
||||||
readDXBuffer();
|
readDXBuffer();
|
||||||
} else {
|
} else {
|
||||||
|
@ -284,11 +288,13 @@ JNIEXPORT jint JNICALL Java_org_lwjgl_opengl_Win32Display_getNativeCursorCaps
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_setNativeCursor
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_setNativeCursor
|
||||||
(JNIEnv *env, jobject self, jobject handle_buffer)
|
(JNIEnv *env, jobject self, jobject handle_buffer)
|
||||||
{
|
{
|
||||||
|
HCURSOR *cursor_handle;
|
||||||
|
HCURSOR cursor;
|
||||||
if (mDIDevice == NULL)
|
if (mDIDevice == NULL)
|
||||||
throwException(env, "null device!");
|
throwException(env, "null device!");
|
||||||
if (handle_buffer != NULL) {
|
if (handle_buffer != NULL) {
|
||||||
HCURSOR *cursor_handle = (HCURSOR *)env->GetDirectBufferAddress(handle_buffer);
|
cursor_handle = (HCURSOR *)(*env)->GetDirectBufferAddress(env, handle_buffer);
|
||||||
HCURSOR cursor = *cursor_handle;
|
cursor = *cursor_handle;
|
||||||
SetClassLong(getCurrentHWND(), GCL_HCURSOR, (LONG)cursor);
|
SetClassLong(getCurrentHWND(), GCL_HCURSOR, (LONG)cursor);
|
||||||
SetCursor(cursor);
|
SetCursor(cursor);
|
||||||
} else {
|
} 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) {
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_pollMouse(JNIEnv * env, jobject self, jobject coord_buffer_obj, jobject button_buffer_obj) {
|
||||||
mDIDevice->Acquire();
|
IDirectInputDevice_Acquire(mDIDevice);
|
||||||
UpdateMouseFields(env, coord_buffer_obj, button_buffer_obj);
|
UpdateMouseFields(env, coord_buffer_obj, button_buffer_obj);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_grabMouse
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_grabMouse
|
||||||
(JNIEnv * env, jobject self, jboolean grab) {
|
(JNIEnv * env, jobject self, jboolean grab) {
|
||||||
|
IDirectInputDevice_Unacquire(mDIDevice);
|
||||||
mDIDevice->Unacquire();
|
|
||||||
if(grab) {
|
if(grab) {
|
||||||
if (!mouse_grabbed) {
|
if (!mouse_grabbed) {
|
||||||
mouse_grabbed = true;
|
mouse_grabbed = true;
|
||||||
|
@ -335,12 +340,12 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_grabMouse
|
||||||
mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
mouseMask = DISCL_NONEXCLUSIVE | DISCL_FOREGROUND;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
mDIDevice->Unacquire();
|
IDirectInputDevice_Unacquire(mDIDevice);
|
||||||
if(mDIDevice->SetCooperativeLevel(getCurrentHWND(), mouseMask) != DI_OK) {
|
if (IDirectInputDevice_SetCooperativeLevel(mDIDevice, getCurrentHWND(), mouseMask) != DI_OK) {
|
||||||
throwException(env, "Could not set the CooperativeLevel.");
|
throwException(env, "Could not set the CooperativeLevel.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mDIDevice->Acquire();
|
IDirectInputDevice_Acquire(mDIDevice);
|
||||||
initEventQueue(&event_queue, EVENT_SIZE);
|
initEventQueue(&event_queue, EVENT_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,14 +355,14 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_grabMouse
|
||||||
static void ShutdownMouse() {
|
static void ShutdownMouse() {
|
||||||
// release device
|
// release device
|
||||||
if (mDIDevice != NULL) {
|
if (mDIDevice != NULL) {
|
||||||
mDIDevice->Unacquire();
|
IDirectInputDevice_Unacquire(mDIDevice);
|
||||||
mDIDevice->Release();
|
IDirectInputDevice_Release(mDIDevice);
|
||||||
mDIDevice = NULL;
|
mDIDevice = NULL;
|
||||||
}
|
}
|
||||||
// Release DirectInput
|
// Release DirectInput
|
||||||
if (lpdi != NULL) {
|
if (lpdi != NULL) {
|
||||||
printfDebug("Destroying directinput\n");
|
printfDebug("Destroying directinput\n");
|
||||||
lpdi->Release();
|
IDirectInput_Release(lpdi);
|
||||||
lpdi = NULL;
|
lpdi = NULL;
|
||||||
}
|
}
|
||||||
mCreate_success = false;
|
mCreate_success = false;
|
||||||
|
@ -367,7 +372,7 @@ static void ShutdownMouse() {
|
||||||
*/
|
*/
|
||||||
static void EnumerateMouseCapabilities() {
|
static void EnumerateMouseCapabilities() {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = mDIDevice->EnumObjects(EnumMouseObjectsCallback, NULL, DIDFT_ALL);
|
hr = IDirectInputDevice_EnumObjects(mDIDevice, EnumMouseObjectsCallback, NULL, DIDFT_ALL);
|
||||||
if FAILED(hr) {
|
if FAILED(hr) {
|
||||||
printfDebug("EnumObjects failed\n");
|
printfDebug("EnumObjects failed\n");
|
||||||
mCreate_success = false;
|
mCreate_success = false;
|
||||||
|
@ -388,11 +393,11 @@ static void EnumerateMouseCapabilities() {
|
||||||
*/
|
*/
|
||||||
static BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
|
static BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi, LPVOID pvRef) {
|
||||||
printfDebug("found %s\n", lpddoi->tszName);
|
printfDebug("found %s\n", lpddoi->tszName);
|
||||||
if(lpddoi->guidType == GUID_Button) {
|
if(IsEqualGUID(&lpddoi->guidType, &GUID_Button)) {
|
||||||
mButtoncount++;
|
mButtoncount++;
|
||||||
} else if(lpddoi->guidType == GUID_XAxis) {
|
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_XAxis)) {
|
||||||
} else if(lpddoi->guidType == GUID_YAxis) {
|
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_YAxis)) {
|
||||||
} else if(lpddoi->guidType == GUID_ZAxis) {
|
} else if(IsEqualGUID(&lpddoi->guidType, &GUID_ZAxis)) {
|
||||||
mHaswheel = true;
|
mHaswheel = true;
|
||||||
} else {
|
} else {
|
||||||
printfDebug("Unhandled object found: %s\n", lpddoi->tszName);
|
printfDebug("Unhandled object found: %s\n", lpddoi->tszName);
|
||||||
|
@ -405,7 +410,7 @@ static BOOL CALLBACK EnumMouseObjectsCallback(LPCDIDEVICEOBJECTINSTANCE lpddoi,
|
||||||
*/
|
*/
|
||||||
static void CreateMouse() {
|
static void CreateMouse() {
|
||||||
HRESULT hr;
|
HRESULT hr;
|
||||||
hr = lpdi->CreateDevice(GUID_SysMouse, &mDIDevice, NULL);
|
hr = IDirectInput_CreateDevice(lpdi, &GUID_SysMouse, &mDIDevice, NULL);
|
||||||
if FAILED(hr) {
|
if FAILED(hr) {
|
||||||
printfDebug("CreateDevice failed\n");
|
printfDebug("CreateDevice failed\n");
|
||||||
mCreate_success = false;
|
mCreate_success = false;
|
||||||
|
@ -418,23 +423,23 @@ static void CreateMouse() {
|
||||||
* Sets up the Mouse properties
|
* Sets up the Mouse properties
|
||||||
*/
|
*/
|
||||||
static void SetupMouse() {
|
static void SetupMouse() {
|
||||||
|
DIPROPDWORD dipropdw;
|
||||||
// set Mouse data format
|
// set Mouse data format
|
||||||
if(mDIDevice->SetDataFormat(&c_dfDIMouse) != DI_OK) {
|
if(IDirectInputDevice_SetDataFormat(mDIDevice, &c_dfDIMouse) != DI_OK) {
|
||||||
printfDebug("SetDataFormat failed\n");
|
printfDebug("SetDataFormat failed\n");
|
||||||
mCreate_success = false;
|
mCreate_success = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
DIPROPDWORD dipropdw;
|
|
||||||
dipropdw.diph.dwSize = sizeof(DIPROPDWORD);
|
dipropdw.diph.dwSize = sizeof(DIPROPDWORD);
|
||||||
dipropdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
dipropdw.diph.dwHeaderSize = sizeof(DIPROPHEADER);
|
||||||
dipropdw.diph.dwObj = 0;
|
dipropdw.diph.dwObj = 0;
|
||||||
dipropdw.diph.dwHow = DIPH_DEVICE;
|
dipropdw.diph.dwHow = DIPH_DEVICE;
|
||||||
dipropdw.dwData = EVENT_BUFFER_SIZE;
|
dipropdw.dwData = EVENT_BUFFER_SIZE;
|
||||||
mDIDevice->SetProperty(DIPROP_BUFFERSIZE, &dipropdw.diph);
|
IDirectInputDevice_SetProperty(mDIDevice, DIPROP_BUFFERSIZE, &dipropdw.diph);
|
||||||
|
|
||||||
// set the cooperative level
|
// set the cooperative level
|
||||||
if(mDIDevice->SetCooperativeLevel(getCurrentHWND(), mouseMask) != DI_OK) {
|
if (IDirectInputDevice_SetCooperativeLevel(mDIDevice, getCurrentHWND(), mouseMask) != DI_OK) {
|
||||||
printfDebug("SetCooperativeLevel failed\n");
|
printfDebug("SetCooperativeLevel failed\n");
|
||||||
mCreate_success = false;
|
mCreate_success = false;
|
||||||
return;
|
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) {
|
static void UpdateMouseFields(JNIEnv *env, jobject coord_buffer_obj, jobject button_buffer_obj) {
|
||||||
HRESULT hRes;
|
HRESULT hRes;
|
||||||
DIMOUSESTATE diMouseState; // State of Mouse
|
DIMOUSESTATE diMouseState; // State of Mouse
|
||||||
|
int i, j;
|
||||||
|
|
||||||
handleMessages();
|
int *coords = (int *)(*env)->GetDirectBufferAddress(env, coord_buffer_obj);
|
||||||
|
int coords_length = (int)(*env)->GetDirectBufferCapacity(env, coord_buffer_obj);
|
||||||
int *coords = (int *)env->GetDirectBufferAddress(coord_buffer_obj);
|
unsigned char *buttons_buffer = (unsigned char *)(*env)->GetDirectBufferAddress(env, button_buffer_obj);
|
||||||
int coords_length = (int)env->GetDirectBufferCapacity(coord_buffer_obj);
|
int num_buttons;
|
||||||
unsigned char *buttons_buffer = (unsigned char *)env->GetDirectBufferAddress(button_buffer_obj);
|
int buttons_length = (int)(*env)->GetDirectBufferCapacity(env, button_buffer_obj);
|
||||||
int buttons_length = (int)env->GetDirectBufferCapacity(button_buffer_obj);
|
|
||||||
if (coords_length < 3) {
|
if (coords_length < 3) {
|
||||||
printfDebug("ERROR: Not enough space in coords array: %d < 3\n", coords_length);
|
printfDebug("ERROR: Not enough space in coords array: %d < 3\n", coords_length);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleMessages();
|
||||||
|
|
||||||
// get data from the Mouse
|
// get data from the Mouse
|
||||||
hRes = mDIDevice->GetDeviceState(sizeof(DIMOUSESTATE), &diMouseState);
|
hRes = IDirectInputDevice_GetDeviceState(mDIDevice, sizeof(DIMOUSESTATE), &diMouseState);
|
||||||
if (hRes != DI_OK) {
|
if (hRes != DI_OK) {
|
||||||
// Don't allow the mouse to drift when failed
|
// Don't allow the mouse to drift when failed
|
||||||
diMouseState.lX = 0;
|
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?
|
// did the read fail because we lost input for some reason?
|
||||||
// if so, then attempt to reacquire.
|
// if so, then attempt to reacquire.
|
||||||
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
if(hRes == DIERR_INPUTLOST || hRes == DIERR_NOTACQUIRED) {
|
||||||
hRes = mDIDevice->Acquire();
|
hRes = IDirectInputDevice_Acquire(mDIDevice);
|
||||||
if (hRes != DI_OK)
|
if (hRes != DI_OK)
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
@ -500,16 +507,16 @@ static void UpdateMouseFields(JNIEnv *env, jobject coord_buffer_obj, jobject but
|
||||||
accum_dx = accum_dy = accum_dwheel = 0;
|
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) {
|
if (diMouseState.rgbButtons[i] != 0) {
|
||||||
diMouseState.rgbButtons[i] = JNI_TRUE;
|
diMouseState.rgbButtons[i] = JNI_TRUE;
|
||||||
} else {
|
} else {
|
||||||
diMouseState.rgbButtons[i] = JNI_FALSE;
|
diMouseState.rgbButtons[i] = JNI_FALSE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
int num_buttons = mButtoncount;
|
num_buttons = mButtoncount;
|
||||||
if (num_buttons > buttons_length)
|
if (num_buttons > buttons_length)
|
||||||
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];
|
buttons_buffer[j] = (unsigned char)diMouseState.rgbButtons[j];
|
||||||
}
|
}
|
|
@ -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) {
|
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);
|
jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
|
||||||
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
|
int alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "alpha", "I"));
|
||||||
int depth = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "depth", "I"));
|
int depth = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "depth", "I"));
|
||||||
int stencil = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "stencil", "I"));
|
int stencil = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stencil", "I"));
|
||||||
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
|
int samples = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "samples", "I"));
|
||||||
int num_aux_buffers = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "num_aux_buffers", "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(pixel_format, env->GetFieldID(cls_pixel_format, "accum_bpp", "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(pixel_format, env->GetFieldID(cls_pixel_format, "accum_alpha", "I"));
|
int accum_alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_alpha", "I"));
|
||||||
jboolean stereo = env->GetBooleanField(pixel_format, env->GetFieldID(cls_pixel_format, "stereo", "Z"));
|
jboolean stereo = (*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stereo", "Z"));
|
||||||
int iPixelFormat;
|
int iPixelFormat;
|
||||||
unsigned int num_formats_returned;
|
unsigned int num_formats_returned;
|
||||||
attrib_list_t attrib_list;
|
attrib_list_t attrib_list;
|
||||||
|
GLuint *pixelFormatCaps_ptr;
|
||||||
|
jlong pixelFormatCapsSize;
|
||||||
|
BOOL result;
|
||||||
|
jlong i;
|
||||||
|
|
||||||
initAttribList(&attrib_list);
|
initAttribList(&attrib_list);
|
||||||
if (window) {
|
if (window) {
|
||||||
putAttrib(&attrib_list, WGL_DRAW_TO_WINDOW_ARB); putAttrib(&attrib_list, TRUE);
|
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;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLuint *pixelFormatCaps_ptr = (GLuint *)env->GetDirectBufferAddress(pixelFormatCaps);
|
pixelFormatCaps_ptr = (GLuint *)(*env)->GetDirectBufferAddress(env, pixelFormatCaps);
|
||||||
jlong pixelFormatCapsSize = env->GetDirectBufferCapacity(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, pixelFormatCaps_ptr[i]);
|
||||||
}
|
}
|
||||||
putAttrib(&attrib_list, 0); putAttrib(&attrib_list, 0);
|
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) {
|
if (result == FALSE || num_formats_returned < 1) {
|
||||||
return -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 findPixelFormatARB(JNIEnv *env, HDC hdc, jobject pixel_format, jobject pixelFormatCaps, bool use_hdc_bpp, bool window, bool pbuffer, bool double_buffer) {
|
||||||
int bpp;
|
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) {
|
if (use_hdc_bpp) {
|
||||||
bpp = GetDeviceCaps(hdc, BITSPIXEL);
|
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)
|
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(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "bpp", "I"));
|
||||||
return findPixelFormatARBFromBPP(env, hdc, pixel_format, pixelFormatCaps, bpp, window, pbuffer, double_buffer);
|
return findPixelFormatARBFromBPP(env, hdc, 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)
|
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(env, pixel_format);
|
||||||
int alpha = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "alpha", "I"));
|
int alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "alpha", "I"));
|
||||||
int depth = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "depth", "I"));
|
int depth = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "depth", "I"));
|
||||||
int stencil = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "stencil", "I"));
|
int stencil = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stencil", "I"));
|
||||||
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
|
int samples = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "samples", "I"));
|
||||||
int num_aux_buffers = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "num_aux_buffers", "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(pixel_format, env->GetFieldID(cls_pixel_format, "accum_bpp", "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(pixel_format, env->GetFieldID(cls_pixel_format, "accum_alpha", "I"));
|
int accum_alpha = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "accum_alpha", "I"));
|
||||||
jboolean stereo = env->GetBooleanField(pixel_format, env->GetFieldID(cls_pixel_format, "stereo", "Z"));
|
jboolean stereo = (*env)->GetBooleanField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "stereo", "Z"));
|
||||||
unsigned int flags = PFD_DRAW_TO_WINDOW | // support window
|
unsigned int flags = PFD_DRAW_TO_WINDOW | // support window
|
||||||
PFD_SUPPORT_OPENGL | // support OpenGL
|
PFD_SUPPORT_OPENGL |
|
||||||
PFD_DOUBLEBUFFER; // double buffered
|
PFD_DOUBLEBUFFER |
|
||||||
if (stereo)
|
(stereo ? PFD_STEREO : 0);
|
||||||
flags = flags | PFD_STEREO;
|
PIXELFORMATDESCRIPTOR desc;
|
||||||
PIXELFORMATDESCRIPTOR pfd = {
|
int iPixelFormat;
|
||||||
|
PIXELFORMATDESCRIPTOR pfd = {
|
||||||
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
|
sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
|
||||||
1, // version number
|
1, // version number
|
||||||
flags, // RGBA type
|
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
|
// get the best available match of pixel format for the device context
|
||||||
int iPixelFormat = ChoosePixelFormat(hdc, &pfd);
|
iPixelFormat = ChoosePixelFormat(hdc, &pfd);
|
||||||
if (iPixelFormat == 0) {
|
if (iPixelFormat == 0) {
|
||||||
throwException(env, "Failed to choose pixel format");
|
throwException(env, "Failed to choose pixel format");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
return -1;
|
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 findPixelFormat(JNIEnv *env, HDC hdc, jobject pixel_format) {
|
||||||
int bpp;
|
int bpp = GetDeviceCaps(hdc, BITSPIXEL);
|
||||||
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
jclass cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
|
||||||
bpp = GetDeviceCaps(hdc, BITSPIXEL);
|
|
||||||
int iPixelFormat = findPixelFormatFromBPP(env, hdc, pixel_format, bpp);
|
int iPixelFormat = findPixelFormatFromBPP(env, hdc, pixel_format, bpp);
|
||||||
if (iPixelFormat == -1) {
|
if (iPixelFormat == -1) {
|
||||||
return findPixelFormatFromBPP(env, hdc, pixel_format, 16);
|
return findPixelFormatFromBPP(env, hdc, pixel_format, 16);
|
||||||
|
@ -311,7 +316,11 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
|
||||||
WPARAM wParam,
|
WPARAM wParam,
|
||||||
LPARAM lParam)
|
LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
int xPos;
|
||||||
|
int yPos;
|
||||||
|
int dwheel;
|
||||||
|
bool oldIsMinimized;
|
||||||
|
bool oldIsFocused;
|
||||||
switch (msg) {
|
switch (msg) {
|
||||||
// disable screen saver and monitor power down messages which wreak havoc
|
// disable screen saver and monitor power down messages which wreak havoc
|
||||||
case WM_SYSCOMMAND:
|
case WM_SYSCOMMAND:
|
||||||
|
@ -331,14 +340,14 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
|
||||||
break;
|
break;
|
||||||
case WM_MOUSEMOVE:
|
case WM_MOUSEMOVE:
|
||||||
{
|
{
|
||||||
int xPos = GET_X_LPARAM(lParam);
|
xPos = GET_X_LPARAM(lParam);
|
||||||
int yPos = GET_Y_LPARAM(lParam);
|
yPos = GET_Y_LPARAM(lParam);
|
||||||
handleMouseMoved(xPos, yPos);
|
handleMouseMoved(xPos, yPos);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
case WM_MOUSEWHEEL:
|
case WM_MOUSEWHEEL:
|
||||||
{
|
{
|
||||||
int dwheel = GET_WHEEL_DELTA_WPARAM(wParam);
|
dwheel = GET_WHEEL_DELTA_WPARAM(wParam);
|
||||||
handleMouseScrolled(dwheel);
|
handleMouseScrolled(dwheel);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -384,20 +393,20 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
|
||||||
}
|
}
|
||||||
/*case WM_MOVE: {
|
/*case WM_MOVE: {
|
||||||
// get fields of display
|
// get fields of display
|
||||||
jclass cls_display = env->FindClass("org/lwjgl/opengl/Display");
|
jclass cls_display = (*env)->FindClass(env, "org/lwjgl/opengl/Display");
|
||||||
jfieldID fid_x = env->GetStaticFieldID(cls_display, "x", "I");
|
jfieldID fid_x = (*env)->GetStaticFieldID(env, cls_display, "x", "I");
|
||||||
jfieldID fid_y = env->GetStaticFieldID(cls_display, "y", "I");
|
jfieldID fid_y = (*env)->GetStaticFieldID(env, cls_display, "y", "I");
|
||||||
|
|
||||||
// set fields
|
// set fields
|
||||||
env->SetStaticIntField(cls_display, fid_x, (int)(short) LOWORD(lParam));
|
(*env)->SetStaticIntField(env, cls_display, fid_x, (int)(short) LOWORD(lParam));
|
||||||
env->SetStaticIntField(cls_display, fid_y, (int)(short) HIWORD(lParam));
|
(*env)->SetStaticIntField(env, cls_display, fid_y, (int)(short) HIWORD(lParam));
|
||||||
|
|
||||||
}*/
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update window state directly having processed window messages
|
// Update window state directly having processed window messages
|
||||||
bool oldIsMinimized = isMinimized;
|
oldIsMinimized = isMinimized;
|
||||||
bool oldIsFocused = isFocused;
|
oldIsFocused = isFocused;
|
||||||
isMinimized = IsIconic(display_hwnd);
|
isMinimized = IsIconic(display_hwnd);
|
||||||
isFocused = GetForegroundWindow() == display_hwnd;
|
isFocused = GetForegroundWindow() == display_hwnd;
|
||||||
if (oldIsMinimized != isMinimized || oldIsFocused != isFocused) {
|
if (oldIsMinimized != isMinimized || oldIsFocused != isFocused) {
|
||||||
|
@ -414,9 +423,8 @@ LRESULT CALLBACK lwjglWindowProc(HWND hWnd,
|
||||||
*/
|
*/
|
||||||
static bool registerWindow()
|
static bool registerWindow()
|
||||||
{
|
{
|
||||||
|
WNDCLASS windowClass;
|
||||||
if (!oneShotInitialised) {
|
if (!oneShotInitialised) {
|
||||||
WNDCLASS windowClass;
|
|
||||||
|
|
||||||
windowClass.style = CS_GLOBALCLASS | CS_OWNDC;
|
windowClass.style = CS_GLOBALCLASS | CS_OWNDC;
|
||||||
windowClass.lpfnWndProc = lwjglWindowProc;
|
windowClass.lpfnWndProc = lwjglWindowProc;
|
||||||
windowClass.cbClsExtra = 0;
|
windowClass.cbClsExtra = 0;
|
||||||
|
@ -472,7 +480,7 @@ void handleMessages(void)
|
||||||
HWND createWindow(int x, int y, int width, int height, bool fullscreen, bool undecorated)
|
HWND createWindow(int x, int y, int width, int height, bool fullscreen, bool undecorated)
|
||||||
{
|
{
|
||||||
int exstyle, windowflags;
|
int exstyle, windowflags;
|
||||||
|
HWND new_hwnd;
|
||||||
// 1. Register window class if necessary
|
// 1. Register window class if necessary
|
||||||
if (!registerWindow()) {
|
if (!registerWindow()) {
|
||||||
return NULL;
|
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:
|
// Create the window now, using that class:
|
||||||
HWND new_hwnd = CreateWindowEx (
|
new_hwnd = CreateWindowEx (
|
||||||
exstyle,
|
exstyle,
|
||||||
WINDOWCLASSNAME,
|
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) {
|
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;
|
closerequested = false;
|
||||||
isMinimized = false;
|
isMinimized = false;
|
||||||
isFocused = false;
|
isFocused = false;
|
||||||
isDirty = true;
|
isDirty = true;
|
||||||
isFullScreen = fullscreen == JNI_TRUE;
|
isFullScreen = fullscreen == JNI_TRUE;
|
||||||
isUndecorated = getBooleanProperty(env, "org.lwjgl.opengl.Window.undecorated");
|
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);
|
display_hwnd = createWindow(x, y, width, height, isFullScreen, isUndecorated);
|
||||||
if (display_hwnd == NULL) {
|
if (display_hwnd == NULL) {
|
||||||
|
@ -653,7 +662,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createWindow(JNIEnv *e
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL result = wglMakeCurrent(display_hdc, display_hglrc);
|
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(display_hwnd, display_hdc);
|
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) {
|
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
|
// 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
|
// 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.
|
// rendering context and start over, using the ARB extension instead to pick the context.
|
||||||
if (!extgl_Extensions.WGL_ARB_pixel_format)
|
if (!extgl_Extensions.WGL_ARB_pixel_format)
|
||||||
return false;
|
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) {
|
if (pixel_format_index == -1) {
|
||||||
pixel_format_index = findPixelFormatARB(env, hdc, pixel_format, NULL, true, true, false, true);
|
pixel_format_index = findPixelFormatARB(env, hdc, pixel_format, NULL, true, true, false, true);
|
||||||
if (pixel_format_index == -1)
|
if (pixel_format_index == -1)
|
||||||
return false;
|
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)
|
if (arb_hwnd == NULL)
|
||||||
return false;
|
return false;
|
||||||
HDC arb_hdc = GetDC(arb_hwnd);
|
arb_hdc = GetDC(arb_hwnd);
|
||||||
if (!applyPixelFormat(arb_hdc, pixel_format_index)) {
|
if (!applyPixelFormat(arb_hdc, pixel_format_index)) {
|
||||||
closeWindow(arb_hwnd, arb_hdc);
|
closeWindow(arb_hwnd, arb_hdc);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
HGLRC arb_context = wglCreateContext(arb_hdc);
|
arb_context = wglCreateContext(arb_hdc);
|
||||||
closeWindow(arb_hwnd, arb_hdc);
|
closeWindow(arb_hwnd, arb_hdc);
|
||||||
*pixel_format_index_return = pixel_format_index;
|
*pixel_format_index_return = pixel_format_index;
|
||||||
*context_return = arb_context;
|
*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) {
|
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);
|
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) {
|
if (dummy_hwnd == NULL) {
|
||||||
throwException(env, "Failed to create the window.");
|
throwException(env, "Failed to create the window.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HDC dummy_hdc = GetDC(dummy_hwnd);
|
dummy_hdc = GetDC(dummy_hwnd);
|
||||||
pixel_format_index = findPixelFormat(env, dummy_hdc, pixel_format);
|
pixel_format_index = findPixelFormat(env, dummy_hdc, pixel_format);
|
||||||
if (pixel_format_index == -1) {
|
if (pixel_format_index == -1) {
|
||||||
return;
|
return;
|
||||||
|
@ -747,7 +767,7 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createContext(JNIEnv *
|
||||||
throwException(env, "Failed to create OpenGL rendering context");
|
throwException(env, "Failed to create OpenGL rendering context");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BOOL result = wglMakeCurrent(dummy_hdc, display_hglrc);
|
result = wglMakeCurrent(dummy_hdc, display_hglrc);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
throwException(env, "Could not bind context to dummy window");
|
throwException(env, "Could not bind context to dummy window");
|
||||||
wglDeleteContext(display_hglrc);
|
wglDeleteContext(display_hglrc);
|
||||||
|
@ -755,12 +775,10 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Win32Display_createContext(JNIEnv *
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
extgl_InitWGL(env);
|
extgl_InitWGL(env);
|
||||||
jclass cls_pixel_format = env->GetObjectClass(pixel_format);
|
cls_pixel_format = (*env)->GetObjectClass(env, pixel_format);
|
||||||
int samples = (int)env->GetIntField(pixel_format, env->GetFieldID(cls_pixel_format, "samples", "I"));
|
samples = (int)(*env)->GetIntField(env, pixel_format, (*env)->GetFieldID(env, cls_pixel_format, "samples", "I"));
|
||||||
if (samples > 0) {
|
if (samples > 0) {
|
||||||
int pixel_format_index_arb;
|
arb_success = createARBContextAndPixelFormat(env, dummy_hdc, pixel_format, &pixel_format_index_arb, &context_arb);
|
||||||
HGLRC context_arb;
|
|
||||||
bool arb_success = createARBContextAndPixelFormat(env, dummy_hdc, pixel_format, &pixel_format_index_arb, &context_arb);
|
|
||||||
closeWindow(dummy_hwnd, dummy_hdc);
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
wglDeleteContext(display_hglrc);
|
wglDeleteContext(display_hglrc);
|
||||||
if (!arb_success) {
|
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) {
|
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) {
|
if (isFullScreen) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int exstyle, windowflags;
|
|
||||||
|
|
||||||
if (isFullScreen) {
|
if (isFullScreen) {
|
||||||
exstyle = WS_EX_APPWINDOW | WS_EX_TOPMOST;
|
exstyle = WS_EX_APPWINDOW | WS_EX_TOPMOST;
|
||||||
windowflags = WS_POPUP;
|
windowflags = WS_POPUP;
|
43
src/native/win32/org_lwjgl_opengl_Pbuffer.cpp → src/native/win32/org_lwjgl_opengl_Pbuffer.c
Executable file → Normal file
43
src/native/win32/org_lwjgl_opengl_Pbuffer.cpp → src/native/win32/org_lwjgl_opengl_Pbuffer.c
Executable file → Normal 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) {
|
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);
|
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) {
|
if (dummy_hwnd == NULL) {
|
||||||
throwException(env, "Could not create dummy window");
|
throwException(env, "Could not create dummy window");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
HDC dummy_hdc = GetDC(dummy_hwnd);
|
dummy_hdc = GetDC(dummy_hwnd);
|
||||||
int iPixelFormat = findPixelFormat(env, dummy_hdc, pixel_format);
|
iPixelFormat = findPixelFormat(env, dummy_hdc, pixel_format);
|
||||||
if (iPixelFormat == -1) {
|
if (iPixelFormat == -1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -91,13 +96,13 @@ static HPBUFFERARB createPbuffer(JNIEnv *env, int width, int height, jobject pix
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
HGLRC dummy_hglrc = wglCreateContext(dummy_hdc);
|
dummy_hglrc = wglCreateContext(dummy_hdc);
|
||||||
if (dummy_hglrc == NULL) {
|
if (dummy_hglrc == NULL) {
|
||||||
closeWindow(dummy_hwnd, dummy_hdc);
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
throwException(env, "Failed to create OpenGL rendering context");
|
throwException(env, "Failed to create OpenGL rendering context");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
BOOL result = wglMakeCurrent(dummy_hdc, dummy_hglrc);
|
result = wglMakeCurrent(dummy_hdc, dummy_hglrc);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
wglDeleteContext(dummy_hglrc);
|
wglDeleteContext(dummy_hglrc);
|
||||||
closeWindow(dummy_hwnd, dummy_hdc);
|
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.");
|
throwException(env, "Could not find suitable pixel format.");
|
||||||
return NULL;
|
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);
|
closeWindow(dummy_hwnd, dummy_hdc);
|
||||||
return Pbuffer;
|
return Pbuffer;
|
||||||
}
|
}
|
||||||
|
@ -139,14 +144,17 @@ JNIEXPORT void 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)
|
||||||
{
|
{
|
||||||
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");
|
throwException(env, "Buffer handle not large enough");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HPBUFFERARB Pbuffer;
|
|
||||||
const int *pBufferAttribs_ptr;
|
|
||||||
if ( pBufferAttribs != NULL ) {
|
if ( pBufferAttribs != NULL ) {
|
||||||
pBufferAttribs_ptr = (const int *)env->GetDirectBufferAddress(pBufferAttribs);
|
pBufferAttribs_ptr = (const int *)(*env)->GetDirectBufferAddress(env, pBufferAttribs);
|
||||||
} else {
|
} else {
|
||||||
pBufferAttribs_ptr = NULL;
|
pBufferAttribs_ptr = NULL;
|
||||||
}
|
}
|
||||||
|
@ -157,20 +165,19 @@ JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nCreate
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
HDC Pbuffer_dc = wglGetPbufferDCARB(Pbuffer);
|
Pbuffer_dc = wglGetPbufferDCARB(Pbuffer);
|
||||||
if (Pbuffer_dc == NULL) {
|
if (Pbuffer_dc == NULL) {
|
||||||
wglDestroyPbufferARB(Pbuffer);
|
wglDestroyPbufferARB(Pbuffer);
|
||||||
throwException(env, "Could not get Pbuffer dc.");
|
throwException(env, "Could not get Pbuffer dc.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HGLRC Pbuffer_context;
|
|
||||||
Pbuffer_context = createPbufferContext(env, Pbuffer_dc);
|
Pbuffer_context = createPbufferContext(env, Pbuffer_dc);
|
||||||
if (Pbuffer_context == NULL) {
|
if (Pbuffer_context == NULL) {
|
||||||
wglReleasePbufferDCARB(Pbuffer, Pbuffer_dc);
|
wglReleasePbufferDCARB(Pbuffer, Pbuffer_dc);
|
||||||
wglDestroyPbufferARB(Pbuffer);
|
wglDestroyPbufferARB(Pbuffer);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
PbufferInfo *Pbuffer_info = (PbufferInfo *)env->GetDirectBufferAddress(buffer_handle);
|
Pbuffer_info = (PbufferInfo *)(*env)->GetDirectBufferAddress(env, buffer_handle);
|
||||||
Pbuffer_info->Pbuffer = Pbuffer;
|
Pbuffer_info->Pbuffer = Pbuffer;
|
||||||
Pbuffer_info->Pbuffer_context = Pbuffer_context;
|
Pbuffer_info->Pbuffer_context = Pbuffer_context;
|
||||||
Pbuffer_info->Pbuffer_dc = Pbuffer_dc;
|
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
|
JNIEXPORT jboolean JNICALL Java_org_lwjgl_opengl_Pbuffer_nIsBufferLost
|
||||||
(JNIEnv *env, jclass clazz, jobject buffer_handle)
|
(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;
|
BOOL buffer_lost;
|
||||||
wglQueryPbufferARB(Pbuffer_info->Pbuffer, WGL_PBUFFER_LOST_ARB, &buffer_lost);
|
wglQueryPbufferARB(Pbuffer_info->Pbuffer, WGL_PBUFFER_LOST_ARB, &buffer_lost);
|
||||||
return buffer_lost ? JNI_TRUE : JNI_FALSE;
|
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
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nMakeCurrent
|
||||||
(JNIEnv *env, jclass clazz, jobject buffer_handle)
|
(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;
|
// PbufferInfo *Pbuffer_info = (PbufferInfo *)handle;
|
||||||
if (!wglMakeCurrent(Pbuffer_info->Pbuffer_dc, Pbuffer_info->Pbuffer_context))
|
if (!wglMakeCurrent(Pbuffer_info->Pbuffer_dc, Pbuffer_info->Pbuffer_context))
|
||||||
throwException(env, "Could not make pbuffer context current");
|
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
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nDestroy
|
||||||
(JNIEnv *env, jclass clazz, jobject buffer_handle)
|
(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);
|
wglDeleteContext(Pbuffer_info->Pbuffer_context);
|
||||||
wglReleasePbufferDCARB(Pbuffer_info->Pbuffer, Pbuffer_info->Pbuffer_dc);
|
wglReleasePbufferDCARB(Pbuffer_info->Pbuffer, Pbuffer_info->Pbuffer_dc);
|
||||||
wglDestroyPbufferARB(Pbuffer_info->Pbuffer);
|
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
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nSetAttrib
|
||||||
(JNIEnv *env, jclass clazz, jobject buffer_handle, jint attrib, jint value)
|
(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];
|
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
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nBindTexImage
|
||||||
(JNIEnv *env, jclass clazz, jobject buffer_handle, jint buffer)
|
(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);
|
wglBindTexImageARB(Pbuffer_info->Pbuffer, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nReleaseTexImage
|
JNIEXPORT void JNICALL Java_org_lwjgl_opengl_Pbuffer_nReleaseTexImage
|
||||||
(JNIEnv *env, jclass clazz, jobject buffer_handle, jint buffer)
|
(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);
|
wglReleaseTexImageARB(Pbuffer_info->Pbuffer, buffer);
|
||||||
}
|
}
|
Loading…
Reference in New Issue