X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=vid_wgl.c;h=db3ec891b14b969497fe8c3d8342e00a7c4ae89e;hb=31c60f86f584447beac6b654e54587229f2c9496;hp=88cc6814fa86a398ffc597527827e271902c17f1;hpb=ecddae3859018ea01887528f3248f03a138be6c3;p=xonotic%2Fdarkplaces.git diff --git a/vid_wgl.c b/vid_wgl.c index 88cc6814..db3ec891 100644 --- a/vid_wgl.c +++ b/vid_wgl.c @@ -25,10 +25,14 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "quakedef.h" #include #include +#ifdef SUPPORTDIRECTX #include +#endif #include "resource.h" #include +#ifdef SUPPORTDIRECTX #include +#endif extern HINSTANCE global_hInstance; @@ -91,6 +95,7 @@ static DEVMODE gdevmode, initialdevmode; static qboolean vid_initialized = false; static qboolean vid_wassuspended = false; static qboolean vid_usingmouse = false; +static qboolean vid_usinghidecursor = false; static qboolean vid_usingvsync = false; static qboolean vid_usevsync = false; static HICON hIcon; @@ -117,17 +122,15 @@ static qboolean vid_isfullscreen; static int window_x, window_y; -static void IN_Activate (qboolean grab); - static qboolean mouseinitialized; -static qboolean dinput; - -// input code +#ifdef SUPPORTDIRECTX +static qboolean dinput; #define DINPUT_BUFFERSIZE 16 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d) static HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter); +#endif // LordHavoc: thanks to backslash for this support for mouse buttons 4 and 5 /* backslash :: imouse explorer buttons */ @@ -156,9 +159,11 @@ static int mouse_buttons; static int mouse_oldbuttonstate; static unsigned int uiWheelMessage; +#ifdef SUPPORTDIRECTX static qboolean dinput_acquired; static unsigned int mstate_di; +#endif // joystick defines and variables // where should defines be moved? @@ -220,13 +225,14 @@ static int joy_id; static DWORD joy_flags; static DWORD joy_numbuttons; +#ifdef SUPPORTDIRECTX static LPDIRECTINPUT g_pdi; static LPDIRECTINPUTDEVICE g_pMouse; +static HINSTANCE hInstDI; +#endif static JOYINFOEX ji; -static HINSTANCE hInstDI; - // forward-referenced functions static void IN_StartupJoystick (void); static void Joy_AdvancedUpdate_f (void); @@ -236,10 +242,8 @@ static void IN_StartupMouse (void); //==================================== -void VID_Finish (qboolean allowmousegrab) +void VID_Finish (void) { - qboolean vid_usemouse; - vid_usevsync = vid_vsync.integer && !cls.timedemo && gl_videosyncavailable; if (vid_usingvsync != vid_usevsync && gl_videosyncavailable) { @@ -247,16 +251,6 @@ void VID_Finish (qboolean allowmousegrab) qwglSwapIntervalEXT (vid_usevsync); } -// handle the mouse state when windowed if that's changed - vid_usemouse = false; - if (allowmousegrab && vid_mouse.integer && !key_consoleactive && (key_dest != key_game || !cls.demoplayback)) - vid_usemouse = true; - if (vid_isfullscreen) - vid_usemouse = true; - if (!vid_activewindow) - vid_usemouse = false; - IN_Activate(vid_usemouse); - if (r_render.integer && !vid_hidden) { CHECKGLERROR @@ -267,6 +261,11 @@ void VID_Finish (qboolean allowmousegrab) SwapBuffers(baseDC); } + // make sure a context switch can happen every frame - Logitech drivers + // input drivers sometimes eat cpu time every 3 seconds or lag badly + // without this help + Sleep(0); + VID_UpdateGamma(false, 256); } @@ -429,7 +428,7 @@ void AppActivate(BOOL fActive, BOOL minimize) if (!fActive) { - IN_Activate (false); + VID_SetMouse(false, false, false); if (vid_isfullscreen) { ChangeDisplaySettings (NULL, 0); @@ -503,7 +502,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_MOVE: window_x = (int) LOWORD(lParam); window_y = (int) HIWORD(lParam); - IN_Activate(false); + VID_SetMouse(false, false, false); break; case WM_KEYDOWN: @@ -515,7 +514,7 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) GetKeyboardState (state); // alt/ctrl/shift tend to produce funky ToAscii values, // and if it's not a single character we don't know care about it - charlength = ToAscii (wParam, lParam >> 16, state, (unsigned short *)asciichar, 0); + charlength = ToAscii (wParam, lParam >> 16, state, (LPWORD)asciichar, 0); if (vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || charlength == 0) asciichar[0] = 0; else if( charlength == 2 ) { @@ -530,8 +529,11 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) case WM_SYSCOMMAND: // prevent screensaver from occuring while the active window + // note: password-locked screensavers on Vista still work if (vid_activewindow && ((wParam & 0xFFF0) == SC_SCREENSAVE || (wParam & 0xFFF0) == SC_MONITORPOWER)) - lRet = 0;; // note: password-locked screensavers on Vista still work + lRet = 0; + else + lRet = DefWindowProc (hWnd, uMsg, wParam, lParam); break; // this is complicated because Win32 seems to pack multiple mouse events into @@ -576,7 +578,9 @@ LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) if (wParam & MK_XBUTTON7) temp |= 512; - if (vid_usingmouse && !dinput_acquired) +#ifdef SUPPORTDIRECTX + if (!dinput_acquired) +#endif { // perform button actions int i; @@ -777,7 +781,7 @@ void VID_Init(void) IN_Init(); } -int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrate, int stereobuffer, int samples) +int VID_InitMode (int fullscreen, int *width, int *height, int bpp, int refreshrate, int stereobuffer, int samples) { int i; HDC hdc; @@ -824,13 +828,21 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat // if stencil is enabled, ask for alpha too if (bpp >= 32) { - pfd.cStencilBits = 8; + pfd.cRedBits = 8; + pfd.cGreenBits = 8; + pfd.cBlueBits = 8; pfd.cAlphaBits = 8; + pfd.cDepthBits = 24; + pfd.cStencilBits = 8; } else { - pfd.cStencilBits = 0; + pfd.cRedBits = 5; + pfd.cGreenBits = 5; + pfd.cBlueBits = 5; pfd.cAlphaBits = 0; + pfd.cDepthBits = 16; + pfd.cStencilBits = 0; } if (stereobuffer) @@ -854,7 +866,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat *a++ = WGL_BLUE_BITS_ARB; *a++ = 8; *a++ = WGL_ALPHA_BITS_ARB; - *a++ = 1; + *a++ = 8; *a++ = WGL_DEPTH_BITS_ARB; *a++ = 24; *a++ = WGL_STENCIL_BITS_ARB; @@ -910,8 +922,8 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat foundmode = true; gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; gdevmode.dmBitsPerPel = bpp; - gdevmode.dmPelsWidth = width; - gdevmode.dmPelsHeight = height; + gdevmode.dmPelsWidth = *width; + gdevmode.dmPelsHeight = *height; gdevmode.dmSize = sizeof (gdevmode); if(refreshrate) { @@ -944,13 +956,13 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat Con_Printf("wrong bpp\n"); continue; } - if(thismode.dmPelsWidth != (DWORD)width) + if(thismode.dmPelsWidth != (DWORD)*width) { if(developer.integer >= 100) Con_Printf("wrong width\n"); continue; } - if(thismode.dmPelsHeight != (DWORD)height) + if(thismode.dmPelsHeight != (DWORD)*height) { if(developer.integer >= 100) Con_Printf("wrong height\n"); @@ -1002,13 +1014,13 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat if (!foundmode) { VID_Shutdown(); - Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", width, height, bpp); + Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", *width, *height, bpp); return false; } else if(ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { VID_Shutdown(); - Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp); + Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", *width, *height, bpp); return false; } @@ -1041,8 +1053,8 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat rect.top = 0; rect.left = 0; - rect.right = width; - rect.bottom = height; + rect.right = *width; + rect.bottom = *height; AdjustWindowRectEx(&rect, WindowStyle, false, 0); if (fullscreen) @@ -1068,8 +1080,12 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat pixelformat = 0; newpixelformat = 0; - for (windowpass = 0;windowpass < 2;windowpass++) + // start out at the final windowpass if samples is 1 as it's the only feature we need extended pixel formats for + for (windowpass = samples == 1;windowpass < 2;windowpass++) { + gl_extensions = ""; + gl_platformextensions = ""; + mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL); if (!mainwindow) { @@ -1127,15 +1143,17 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat if ((qwglGetExtensionsStringARB = (const char *(WINAPI *)(HDC hdc))GL_GetProcAddress("wglGetExtensionsStringARB")) == NULL) Con_Print("wglGetExtensionsStringARB not found\n"); - gl_renderer = qglGetString(GL_RENDERER); - gl_vendor = qglGetString(GL_VENDOR); - gl_version = qglGetString(GL_VERSION); - gl_extensions = qglGetString(GL_EXTENSIONS); + gl_extensions = (const char *)qglGetString(GL_EXTENSIONS); gl_platform = "WGL"; gl_platformextensions = ""; if (qwglGetExtensionsStringARB) - gl_platformextensions = qwglGetExtensionsStringARB(baseDC); + gl_platformextensions = (const char *)qwglGetExtensionsStringARB(baseDC); + + if (!gl_extensions) + gl_extensions = ""; + if (!gl_platformextensions) + gl_platformextensions = ""; // now some nice Windows pain: // we have created a window, we needed one to find out if there are @@ -1160,12 +1178,6 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat } } - Con_DPrintf("GL_VENDOR: %s\n", gl_vendor); - Con_DPrintf("GL_RENDERER: %s\n", gl_renderer); - Con_DPrintf("GL_VERSION: %s\n", gl_version); - Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions); - Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions); - /* if (!fullscreen) SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME); @@ -1207,6 +1219,7 @@ int VID_InitMode (int fullscreen, int width, int height, int bpp, int refreshrat //vid_menudrawfn = VID_MenuDraw; //vid_menukeyfn = VID_MenuKey; vid_usingmouse = false; + vid_usinghidecursor = false; vid_usingvsync = false; vid_hidden = false; vid_initialized = true; @@ -1230,6 +1243,7 @@ void VID_Shutdown (void) if(vid_initialized == false) return; + VID_SetMouse(false, false, false); VID_RestoreSystemGamma(); vid_initialized = false; @@ -1251,7 +1265,7 @@ void VID_Shutdown (void) vid_isfullscreen = false; } -static void IN_Activate (qboolean grab) +void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor) { static qboolean restore_spi; static int originalmouseparms[3]; @@ -1259,18 +1273,20 @@ static void IN_Activate (qboolean grab) if (!mouseinitialized) return; - if (grab) + if (relative) { if (!vid_usingmouse) { vid_usingmouse = true; cl_ignoremousemoves = 2; +#ifdef SUPPORTDIRECTX if (dinput && g_pMouse) { IDirectInputDevice_Acquire(g_pMouse); dinput_acquired = true; } else +#endif { RECT window_rect; window_rect.left = window_x; @@ -1295,7 +1311,6 @@ static void IN_Activate (qboolean grab) SetCapture (mainwindow); ClipCursor (&window_rect); } - ShowCursor (false); } } else @@ -1304,12 +1319,14 @@ static void IN_Activate (qboolean grab) { vid_usingmouse = false; cl_ignoremousemoves = 2; +#ifdef SUPPORTDIRECTX if (dinput_acquired) { IDirectInputDevice_Unacquire(g_pMouse); dinput_acquired = false; } else +#endif { // restore system mouseparms if we changed them if (restore_spi) @@ -1318,12 +1335,18 @@ static void IN_Activate (qboolean grab) ClipCursor (NULL); ReleaseCapture (); } - ShowCursor (true); } } + + if (vid_usinghidecursor != hidecursor) + { + vid_usinghidecursor = hidecursor; + ShowCursor (!hidecursor); + } } +#ifdef SUPPORTDIRECTX /* =========== IN_InitDInput @@ -1413,6 +1436,7 @@ static qboolean IN_InitDInput (void) return true; } +#endif /* @@ -1427,6 +1451,7 @@ static void IN_StartupMouse (void) mouseinitialized = true; +#ifdef SUPPORTDIRECTX // COMMANDLINEOPTION: Windows Input: -dinput enables DirectInput for mouse/joystick input if (COM_CheckParm ("-dinput")) dinput = IN_InitDInput (); @@ -1435,6 +1460,7 @@ static void IN_StartupMouse (void) Con_Print("DirectInput initialized\n"); else Con_Print("DirectInput not initialized\n"); +#endif mouse_buttons = 10; } @@ -1447,23 +1473,22 @@ IN_MouseMove */ static void IN_MouseMove (void) { - int i, mx, my; POINT current_pos; + GetCursorPos (¤t_pos); + in_windowmouse_x = current_pos.x - window_x; + in_windowmouse_y = current_pos.y - window_y; + if (!vid_usingmouse) - { - //GetCursorPos (¤t_pos); - //ui_mouseupdate(current_pos.x - window_x, current_pos.y - window_y); return; - } +#ifdef SUPPORTDIRECTX if (dinput_acquired) { + int i; DIDEVICEOBJECTDATA od; DWORD dwElements; HRESULT hr; - mx = 0; - my = 0; for (;;) { @@ -1487,11 +1512,11 @@ static void IN_MouseMove (void) switch (od.dwOfs) { case DIMOFS_X: - mx += (LONG) od.dwData; + in_mouse_x += (LONG) od.dwData; break; case DIMOFS_Y: - my += (LONG) od.dwData; + in_mouse_y += (LONG) od.dwData; break; case DIMOFS_Z: @@ -1542,22 +1567,15 @@ static void IN_MouseMove (void) if ((mstate_di ^ mouse_oldbuttonstate) & (1<