2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // vid_wgl.c -- NT GL vid component
23 #pragma comment(lib, "comctl32.lib")
29 #pragma comment(lib, "dinput8.lib")
30 #pragma comment(lib, "dxguid.lib")
32 #ifndef DIRECTINPUT_VERSION
33 # define DIRECTINPUT_VERSION 0x0500 /* Version 5.0 */
48 #include "dpsoftrast.h"
53 cvar_t vid_dx9 = {CVAR_SAVE, "vid_dx9", "0", "use Microsoft Direct3D9(r) for rendering"};
54 cvar_t vid_dx9_hal = {CVAR_SAVE, "vid_dx9_hal", "1", "enables hardware rendering (1), otherwise software reference rasterizer (0 - very slow), note that 0 is necessary when using NVPerfHUD (which renders in hardware but requires this option to enable it)"};
55 cvar_t vid_dx9_softvertex = {CVAR_SAVE, "vid_dx9_softvertex", "0", "enables software vertex processing (for compatibility testing? or if you have a very fast CPU), usually you want this off"};
56 cvar_t vid_dx9_triplebuffer = {CVAR_SAVE, "vid_dx9_triplebuffer", "0", "enables triple buffering when using vid_vsync in fullscreen, this options adds some latency and only helps when framerate is below 60 so you usually don't want it"};
57 //cvar_t vid_dx10 = {CVAR_SAVE, "vid_dx10", "1", "use Microsoft Direct3D10(r) for rendering"};
58 //cvar_t vid_dx11 = {CVAR_SAVE, "vid_dx11", "1", "use Microsoft Direct3D11(r) for rendering"};
60 D3DPRESENT_PARAMETERS vid_d3dpresentparameters;
62 // we declare this in vid_shared.c because it is required by dedicated server and all clients when SUPPORTD3D is defined
63 extern LPDIRECT3DDEVICE9 vid_d3d9dev;
66 D3DCAPS9 vid_d3d9caps;
67 qboolean vid_d3ddevicelost;
70 extern HINSTANCE global_hInstance;
72 static HINSTANCE gldll;
75 #define WM_MOUSEWHEEL 0x020A
78 // Tell startup code that we have a client
79 int cl_available = true;
81 qboolean vid_supportrefreshrate = true;
83 static int (WINAPI *qwglChoosePixelFormat)(HDC, CONST PIXELFORMATDESCRIPTOR *);
84 static int (WINAPI *qwglDescribePixelFormat)(HDC, int, UINT, LPPIXELFORMATDESCRIPTOR);
85 //static int (WINAPI *qwglGetPixelFormat)(HDC);
86 static BOOL (WINAPI *qwglSetPixelFormat)(HDC, int, CONST PIXELFORMATDESCRIPTOR *);
87 static BOOL (WINAPI *qwglSwapBuffers)(HDC);
88 static HGLRC (WINAPI *qwglCreateContext)(HDC);
89 static BOOL (WINAPI *qwglDeleteContext)(HGLRC);
90 static HGLRC (WINAPI *qwglGetCurrentContext)(VOID);
91 static HDC (WINAPI *qwglGetCurrentDC)(VOID);
92 static PROC (WINAPI *qwglGetProcAddress)(LPCSTR);
93 static BOOL (WINAPI *qwglMakeCurrent)(HDC, HGLRC);
94 static BOOL (WINAPI *qwglSwapIntervalEXT)(int interval);
95 static const char *(WINAPI *qwglGetExtensionsStringARB)(HDC hdc);
96 static BOOL (WINAPI *qwglChoosePixelFormatARB)(HDC hdc, const int *piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
97 static BOOL (WINAPI *qwglGetPixelFormatAttribivARB)(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
99 static dllfunction_t wglfuncs[] =
101 {"wglChoosePixelFormat", (void **) &qwglChoosePixelFormat},
102 {"wglDescribePixelFormat", (void **) &qwglDescribePixelFormat},
103 // {"wglGetPixelFormat", (void **) &qwglGetPixelFormat},
104 {"wglSetPixelFormat", (void **) &qwglSetPixelFormat},
105 {"wglSwapBuffers", (void **) &qwglSwapBuffers},
106 {"wglCreateContext", (void **) &qwglCreateContext},
107 {"wglDeleteContext", (void **) &qwglDeleteContext},
108 {"wglGetProcAddress", (void **) &qwglGetProcAddress},
109 {"wglMakeCurrent", (void **) &qwglMakeCurrent},
110 {"wglGetCurrentContext", (void **) &qwglGetCurrentContext},
111 {"wglGetCurrentDC", (void **) &qwglGetCurrentDC},
115 static dllfunction_t wglswapintervalfuncs[] =
117 {"wglSwapIntervalEXT", (void **) &qwglSwapIntervalEXT},
121 static dllfunction_t wglpixelformatfuncs[] =
123 {"wglChoosePixelFormatARB", (void **) &qwglChoosePixelFormatARB},
124 {"wglGetPixelFormatAttribivARB", (void **) &qwglGetPixelFormatAttribivARB},
128 static DEVMODE gdevmode, initialdevmode;
129 static vid_mode_t desktop_mode;
130 static qboolean vid_initialized = false;
131 static qboolean vid_wassuspended = false;
132 static qboolean vid_usingmouse = false;
133 static qboolean vid_usinghidecursor = false;
134 static qboolean vid_usingvsync = false;
135 static qboolean vid_usevsync = false;
138 // used by cd_win.c and snd_win.c
144 static HDC vid_softhdc;
145 static HGDIOBJ vid_softhdc_backup;
146 static BITMAPINFO vid_softbmi;
147 static HBITMAP vid_softdibhandle;
149 //HWND WINAPI InitializeWindow (HINSTANCE hInstance, int nCmdShow);
151 static qboolean vid_isfullscreen;
153 //void VID_MenuDraw (void);
154 //void VID_MenuKey (int key);
156 LONG WINAPI MainWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
157 void AppActivate(BOOL fActive, BOOL minimize);
158 static void ClearAllStates(void);
159 qboolean VID_InitModeGL(viddef_mode_t *mode);
160 qboolean VID_InitModeSOFT(viddef_mode_t *mode);
162 //====================================
164 static int window_x, window_y;
166 static qboolean mouseinitialized;
168 #ifdef SUPPORTDIRECTX
169 static qboolean dinput;
170 #define DINPUT_BUFFERSIZE 16
171 #define iDirectInputCreate(a,b,c,d) pDirectInputCreate(a,b,c,d)
173 static HRESULT (WINAPI *pDirectInputCreate)(HINSTANCE hinst, DWORD dwVersion, LPDIRECTINPUT * lplpDirectInput, LPUNKNOWN punkOuter);
176 // LordHavoc: thanks to backslash for this support for mouse buttons 4 and 5
177 /* backslash :: imouse explorer buttons */
178 /* These are #ifdefed out for non-Win2K in the February 2001 version of
179 MS's platform SDK, but we need them for compilation. . . */
180 #ifndef WM_XBUTTONDOWN
181 #define WM_XBUTTONDOWN 0x020B
182 #define WM_XBUTTONUP 0x020C
185 #define MK_XBUTTON1 0x0020
186 #define MK_XBUTTON2 0x0040
189 // LordHavoc: lets hope this allows more buttons in the future...
190 #define MK_XBUTTON3 0x0080
191 #define MK_XBUTTON4 0x0100
192 #define MK_XBUTTON5 0x0200
193 #define MK_XBUTTON6 0x0400
194 #define MK_XBUTTON7 0x0800
199 static int mouse_buttons;
200 static int mouse_oldbuttonstate;
202 static unsigned int uiWheelMessage;
203 #ifdef SUPPORTDIRECTX
204 static qboolean dinput_acquired;
206 static unsigned int mstate_di;
209 static cvar_t vid_forcerefreshrate = {0, "vid_forcerefreshrate", "0", "try to set the given vid_refreshrate even if Windows doesn't list it as valid video mode"};
211 #ifdef SUPPORTDIRECTX
212 static LPDIRECTINPUT g_pdi;
213 static LPDIRECTINPUTDEVICE g_pMouse;
214 static HINSTANCE hInstDI;
217 // forward-referenced functions
218 static void IN_StartupMouse (void);
219 static void AdjustWindowBounds(int fullscreen, int *width, int *height, viddef_mode_t *mode, DWORD WindowStyle, RECT *rect);
221 //====================================
223 qboolean vid_reallyhidden = true;
225 qboolean vid_begunscene = false;
227 void VID_Finish (void)
232 vid_hidden = vid_reallyhidden;
234 vid_usevsync = vid_vsync.integer && !cls.timedemo && qwglSwapIntervalEXT;
238 switch(vid.renderpath)
240 case RENDERPATH_GL11:
241 case RENDERPATH_GL13:
242 case RENDERPATH_GL20:
243 case RENDERPATH_GLES1:
244 case RENDERPATH_GLES2:
245 if (vid_usingvsync != vid_usevsync)
247 vid_usingvsync = vid_usevsync;
248 qwglSwapIntervalEXT (vid_usevsync);
250 if (r_speeds.integer == 2 || gl_finish.integer)
254 case RENDERPATH_D3D9:
258 IDirect3DDevice9_EndScene(vid_d3d9dev);
259 vid_begunscene = false;
261 if (!vid_reallyhidden)
263 if (!vid_d3ddevicelost)
265 vid_hidden = vid_reallyhidden;
266 hr = IDirect3DDevice9_Present(vid_d3d9dev, NULL, NULL, NULL, NULL);
267 if (hr == D3DERR_DEVICELOST)
269 vid_d3ddevicelost = true;
276 hr = IDirect3DDevice9_TestCooperativeLevel(vid_d3d9dev);
279 case D3DERR_DEVICELOST:
280 vid_d3ddevicelost = true;
284 case D3DERR_DEVICENOTRESET:
285 vid_d3ddevicelost = false;
286 vid_hidden = vid_reallyhidden;
287 R_Modules_DeviceLost();
288 IDirect3DDevice9_Reset(vid_d3d9dev, &vid_d3dpresentparameters);
289 R_Modules_DeviceRestored();
292 vid_hidden = vid_reallyhidden;
293 IDirect3DDevice9_Present(vid_d3d9dev, NULL, NULL, NULL, NULL);
297 if (!vid_begunscene && !vid_hidden)
299 IDirect3DDevice9_BeginScene(vid_d3d9dev);
300 vid_begunscene = true;
305 case RENDERPATH_D3D10:
307 case RENDERPATH_D3D11:
309 case RENDERPATH_SOFT:
311 // baseDC = GetDC(mainwindow);
312 BitBlt(baseDC, 0, 0, vid.width, vid.height, vid_softhdc, 0, 0, SRCCOPY);
313 // ReleaseDC(mainwindow, baseDC);
319 // make sure a context switch can happen every frame - Logitech drivers
320 // input drivers sometimes eat cpu time every 3 seconds or lag badly
324 VID_UpdateGamma(false, 256);
327 //==========================================================================
330 static unsigned char scantokey[128] =
332 // 0 1 2 3 4 5 6 7 8 9 A B C D E F
333 0 ,K_ESCAPE,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' ,'0' ,'-' ,'=' ,K_BACKSPACE,K_TAB,//0
334 'q' ,'w' ,'e' ,'r' ,'t' ,'y' ,'u' ,'i' ,'o' ,'p' ,'[' ,']' ,K_ENTER,K_CTRL ,'a' ,'s' ,//1
335 'd' ,'f' ,'g' ,'h' ,'j' ,'k' ,'l' ,';' ,'\'' ,'`' ,K_SHIFT ,'\\' ,'z' ,'x' ,'c' ,'v' ,//2
336 'b' ,'n' ,'m' ,',' ,'.' ,'/' ,K_SHIFT ,'*' ,K_ALT ,' ' ,K_CAPSLOCK,K_F1 ,K_F2 ,K_F3 ,K_F4 ,K_F5 ,//3
337 K_F6 ,K_F7 ,K_F8 ,K_F9 ,K_F10,K_PAUSE,K_SCROLLOCK,K_HOME,K_UPARROW,K_PGUP,K_KP_MINUS,K_LEFTARROW,K_KP_5 ,K_RIGHTARROW,K_KP_PLUS ,K_END,//4
338 K_DOWNARROW,K_PGDN ,K_INS,K_DEL,0 ,0 ,0 ,K_F11 ,K_F12 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,//5
339 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,//6
340 0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 //7
348 Map from windows to quake keynums
351 static int MapKey (int key, int virtualkey)
354 int modified = (key >> 16) & 255;
355 qboolean is_extended = false;
357 if (modified < 128 && scantokey[modified])
358 result = scantokey[modified];
362 Con_DPrintf("key 0x%02x (0x%8x, 0x%8x) has no translation\n", modified, key, virtualkey);
370 if(((GetKeyState(VK_NUMLOCK)) & 0xffff) == 0)
382 return K_KP_LEFTARROW;
384 return K_KP_RIGHTARROW;
388 return K_KP_DOWNARROW;
401 if(virtualkey == VK_NUMLOCK)
418 ===================================================================
422 ===================================================================
430 static void ClearAllStates (void)
434 mouse_oldbuttonstate = 0;
437 void AppActivate(BOOL fActive, BOOL minimize)
438 /****************************************************************************
440 * Function: AppActivate
441 * Parameters: fActive - True if app is activating
443 * Description: If the application is activating, then swap the system
444 * into SYSPAL_NOSTATIC mode so that our palettes will display
447 ****************************************************************************/
449 static qboolean sound_active = false; // initially blocked by Sys_InitConsole()
451 vid_activewindow = fActive != FALSE;
452 vid_reallyhidden = minimize != FALSE;
454 // enable/disable sound on focus gain/loss
455 if ((!vid_reallyhidden && vid_activewindow) || !snd_mutewhenidle.integer)
468 sound_active = false;
474 if (vid_isfullscreen)
476 if (vid_wassuspended)
478 vid_wassuspended = false;
481 ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN);
482 ShowWindow(mainwindow, SW_SHOWNORMAL);
486 // LordHavoc: from dabb, fix for alt-tab bug in NVidia drivers
488 MoveWindow(mainwindow,0,0,gdevmode.dmPelsWidth,gdevmode.dmPelsHeight,false);
494 VID_SetMouse(false, false, false);
495 if (vid_isfullscreen)
498 ChangeDisplaySettings (NULL, CDS_FULLSCREEN);
499 vid_wassuspended = true;
501 VID_RestoreSystemGamma();
505 //TODO: move it around in vid_wgl.c since I dont think this is the right position
506 void Sys_SendKeyEvents (void)
510 while (PeekMessage (&msg, NULL, 0, 0, PM_NOREMOVE))
512 if (!GetMessage (&msg, NULL, 0, 0))
515 TranslateMessage (&msg);
516 DispatchMessage (&msg);
521 LONG CDAudio_MessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
524 static keynum_t buttonremap[16] =
544 /* main window procedure */
545 LONG WINAPI MainWndProc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
548 int fActive, fMinimized, temp;
549 unsigned char state[256];
550 const unsigned int UNICODE_BUFFER_LENGTH = 4;
551 WCHAR unicode[UNICODE_BUFFER_LENGTH];
554 qboolean down = false;
556 if ( uMsg == uiWheelMessage )
557 uMsg = WM_MOUSEWHEEL;
562 if (vid_isfullscreen)
563 ShowWindow(mainwindow, SW_SHOWMINNOACTIVE);
570 window_x = (int) LOWORD(lParam);
571 window_y = (int) HIWORD(lParam);
572 VID_SetMouse(false, false, false);
580 vkey = MapKey(lParam, wParam);
581 GetKeyboardState (state);
582 // alt/ctrl/shift tend to produce funky ToAscii values,
583 // and if it's not a single character we don't know care about it
584 charlength = ToUnicode(wParam, lParam >> 16, state, unicode, UNICODE_BUFFER_LENGTH, 0);
585 if(vkey == K_ALT || vkey == K_CTRL || vkey == K_SHIFT || charlength == 0)
587 else if(charlength == 2)
588 unicode[0] = unicode[1];
589 if (!VID_JoyBlockEmulatedKeys(vkey))
590 Key_Event(vkey, unicode[0], down);
594 // keep Alt-Space from happening
598 // prevent screensaver from occuring while the active window
599 // note: password-locked screensavers on Vista still work
600 if (vid_activewindow && ((wParam & 0xFFF0) == SC_SCREENSAVE || (wParam & 0xFFF0) == SC_MONITORPOWER))
603 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
606 // this is complicated because Win32 seems to pack multiple mouse events into
607 // one update sometimes, so we always check all states and look for events
614 case WM_XBUTTONDOWN: // backslash :: imouse explorer buttons
615 case WM_XBUTTONUP: // backslash :: imouse explorer buttons
619 if (wParam & MK_LBUTTON)
622 if (wParam & MK_RBUTTON)
625 if (wParam & MK_MBUTTON)
628 /* backslash :: imouse explorer buttons */
629 if (wParam & MK_XBUTTON1)
632 if (wParam & MK_XBUTTON2)
636 // LordHavoc: lets hope this allows more buttons in the future...
637 if (wParam & MK_XBUTTON3)
639 if (wParam & MK_XBUTTON4)
641 if (wParam & MK_XBUTTON5)
643 if (wParam & MK_XBUTTON6)
645 if (wParam & MK_XBUTTON7)
648 #ifdef SUPPORTDIRECTX
649 if (!dinput_acquired)
652 // perform button actions
654 for (i=0 ; i<mouse_buttons && i < 16 ; i++)
655 if ((temp ^ mouse_oldbuttonstate) & (1<<i))
656 Key_Event (buttonremap[i], 0, (temp & (1<<i)) != 0);
657 mouse_oldbuttonstate = temp;
662 // JACK: This is the mouse wheel with the Intellimouse
663 // Its delta is either positive or neg, and we generate the proper
666 if ((short) HIWORD(wParam) > 0) {
667 Key_Event(K_MWHEELUP, 0, true);
668 Key_Event(K_MWHEELUP, 0, false);
670 Key_Event(K_MWHEELDOWN, 0, true);
671 Key_Event(K_MWHEELDOWN, 0, false);
679 if (MessageBox (mainwindow, "Are you sure you want to quit?", "Confirm Exit", MB_YESNO | MB_SETFOREGROUND | MB_ICONQUESTION) == IDYES)
685 fActive = LOWORD(wParam);
686 fMinimized = (BOOL) HIWORD(wParam);
687 AppActivate(!(fActive == WA_INACTIVE), fMinimized);
689 // fix the leftover Alt from any Alt-Tab or the like that switched us away
695 // PostQuitMessage (0);
700 lRet = CDAudio_MessageHandler (hWnd, uMsg, wParam, lParam);
705 /* pass all unhandled messages to DefWindowProc */
706 lRet = DefWindowProc (hWnd, uMsg, wParam, lParam);
710 /* return 1 if handled message, 0 if not */
714 int VID_SetGamma(unsigned short *ramps, int rampsize)
718 HDC hdc = GetDC (NULL);
719 int i = SetDeviceGammaRamp(hdc, ramps);
720 ReleaseDC (NULL, hdc);
721 return i; // return success or failure
727 int VID_GetGamma(unsigned short *ramps, int rampsize)
731 HDC hdc = GetDC (NULL);
732 int i = GetDeviceGammaRamp(hdc, ramps);
733 ReleaseDC (NULL, hdc);
734 return i; // return success or failure
740 static void GL_CloseLibrary(void)
747 qwglGetProcAddress = NULL;
750 gl_platformextensions = "";
754 static int GL_OpenLibrary(const char *name)
756 Con_Printf("Loading OpenGL driver %s\n", name);
758 if (!(gldll = LoadLibrary(name)))
760 Con_Printf("Unable to LoadLibrary %s\n", name);
763 strlcpy(gl_driver, name, sizeof(gl_driver));
767 void *GL_GetProcAddress(const char *name)
772 if (qwglGetProcAddress != NULL)
773 p = (void *) qwglGetProcAddress(name);
775 p = (void *) GetProcAddress(gldll, name);
782 #ifndef WGL_ARB_pixel_format
783 #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
784 #define WGL_DRAW_TO_WINDOW_ARB 0x2001
785 #define WGL_DRAW_TO_BITMAP_ARB 0x2002
786 #define WGL_ACCELERATION_ARB 0x2003
787 #define WGL_NEED_PALETTE_ARB 0x2004
788 #define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
789 #define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
790 #define WGL_SWAP_METHOD_ARB 0x2007
791 #define WGL_NUMBER_OVERLAYS_ARB 0x2008
792 #define WGL_NUMBER_UNDERLAYS_ARB 0x2009
793 #define WGL_TRANSPARENT_ARB 0x200A
794 #define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
795 #define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
796 #define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
797 #define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
798 #define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
799 #define WGL_SHARE_DEPTH_ARB 0x200C
800 #define WGL_SHARE_STENCIL_ARB 0x200D
801 #define WGL_SHARE_ACCUM_ARB 0x200E
802 #define WGL_SUPPORT_GDI_ARB 0x200F
803 #define WGL_SUPPORT_OPENGL_ARB 0x2010
804 #define WGL_DOUBLE_BUFFER_ARB 0x2011
805 #define WGL_STEREO_ARB 0x2012
806 #define WGL_PIXEL_TYPE_ARB 0x2013
807 #define WGL_COLOR_BITS_ARB 0x2014
808 #define WGL_RED_BITS_ARB 0x2015
809 #define WGL_RED_SHIFT_ARB 0x2016
810 #define WGL_GREEN_BITS_ARB 0x2017
811 #define WGL_GREEN_SHIFT_ARB 0x2018
812 #define WGL_BLUE_BITS_ARB 0x2019
813 #define WGL_BLUE_SHIFT_ARB 0x201A
814 #define WGL_ALPHA_BITS_ARB 0x201B
815 #define WGL_ALPHA_SHIFT_ARB 0x201C
816 #define WGL_ACCUM_BITS_ARB 0x201D
817 #define WGL_ACCUM_RED_BITS_ARB 0x201E
818 #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
819 #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
820 #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
821 #define WGL_DEPTH_BITS_ARB 0x2022
822 #define WGL_STENCIL_BITS_ARB 0x2023
823 #define WGL_AUX_BUFFERS_ARB 0x2024
824 #define WGL_NO_ACCELERATION_ARB 0x2025
825 #define WGL_GENERIC_ACCELERATION_ARB 0x2026
826 #define WGL_FULL_ACCELERATION_ARB 0x2027
827 #define WGL_SWAP_EXCHANGE_ARB 0x2028
828 #define WGL_SWAP_COPY_ARB 0x2029
829 #define WGL_SWAP_UNDEFINED_ARB 0x202A
830 #define WGL_TYPE_RGBA_ARB 0x202B
831 #define WGL_TYPE_COLORINDEX_ARB 0x202C
834 #ifndef WGL_ARB_multisample
835 #define WGL_SAMPLE_BUFFERS_ARB 0x2041
836 #define WGL_SAMPLES_ARB 0x2042
840 static void IN_Init(void);
846 Cvar_RegisterVariable(&vid_dx9);
847 Cvar_RegisterVariable(&vid_dx9_hal);
848 Cvar_RegisterVariable(&vid_dx9_softvertex);
849 Cvar_RegisterVariable(&vid_dx9_triplebuffer);
850 // Cvar_RegisterVariable(&vid_dx10);
851 // Cvar_RegisterVariable(&vid_dx11);
854 InitCommonControls();
855 hIcon = LoadIcon (global_hInstance, MAKEINTRESOURCE (IDI_ICON1));
857 // Register the frame class
859 wc.lpfnWndProc = (WNDPROC)MainWndProc;
862 wc.hInstance = global_hInstance;
864 wc.hCursor = LoadCursor (NULL,IDC_ARROW);
865 wc.hbrBackground = NULL;
867 wc.lpszClassName = "DarkPlacesWindowClass";
869 if (!RegisterClass (&wc))
870 Con_Printf ("Couldn't register window class\n");
872 memset(&initialdevmode, 0, sizeof(initialdevmode));
873 EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &initialdevmode);
875 desktop_mode.width = initialdevmode.dmPelsWidth;
876 desktop_mode.height = initialdevmode.dmPelsHeight;
877 desktop_mode.bpp = initialdevmode.dmBitsPerPel;
878 desktop_mode.refreshrate = initialdevmode.dmDisplayFrequency;
879 desktop_mode.pixelheight_num = 1;
880 desktop_mode.pixelheight_denom = 1; // Win32 apparently does not provide this (FIXME)
885 qboolean VID_InitModeGL(viddef_mode_t *mode)
891 PIXELFORMATDESCRIPTOR pfd =
893 sizeof(PIXELFORMATDESCRIPTOR), // size of this pfd
895 PFD_DRAW_TO_WINDOW // support window
896 | PFD_SUPPORT_OPENGL // support OpenGL
897 | PFD_DOUBLEBUFFER , // double buffered
898 PFD_TYPE_RGBA, // RGBA type
899 24, // 24-bit color depth
900 0, 0, 0, 0, 0, 0, // color bits ignored
901 0, // no alpha buffer
902 0, // shift bit ignored
903 0, // no accumulation buffer
904 0, 0, 0, 0, // accum bits ignored
905 32, // 32-bit z-buffer
906 0, // no stencil buffer
907 0, // no auxiliary buffer
908 PFD_MAIN_PLANE, // main layer
910 0, 0, 0 // layer masks ignored
913 int pixelformat, newpixelformat;
914 UINT numpixelformats;
915 DWORD WindowStyle, ExWindowStyle;
916 const char *gldrivername;
919 qboolean foundmode, foundgoodmode;
924 int bpp = mode->bitsperpixel;
925 int width = mode->width;
926 int height = mode->height;
927 int refreshrate = (int)floor(mode->refreshrate+0.5);
928 int stereobuffer = mode->stereobuffer;
929 int samples = mode->samples;
930 int fullscreen = mode->fullscreen;
933 Sys_Error("VID_InitMode called when video is already initialised");
935 // if stencil is enabled, ask for alpha too
943 pfd.cStencilBits = 8;
952 pfd.cStencilBits = 0;
956 pfd.dwFlags |= PFD_STEREO;
960 *a++ = WGL_DRAW_TO_WINDOW_ARB;
962 *a++ = WGL_ACCELERATION_ARB;
963 *a++ = WGL_FULL_ACCELERATION_ARB;
964 *a++ = WGL_DOUBLE_BUFFER_ARB;
969 *a++ = WGL_RED_BITS_ARB;
971 *a++ = WGL_GREEN_BITS_ARB;
973 *a++ = WGL_BLUE_BITS_ARB;
975 *a++ = WGL_ALPHA_BITS_ARB;
977 *a++ = WGL_DEPTH_BITS_ARB;
979 *a++ = WGL_STENCIL_BITS_ARB;
984 *a++ = WGL_RED_BITS_ARB;
986 *a++ = WGL_GREEN_BITS_ARB;
988 *a++ = WGL_BLUE_BITS_ARB;
990 *a++ = WGL_DEPTH_BITS_ARB;
996 *a++ = WGL_STEREO_ARB;
1002 *a++ = WGL_SAMPLE_BUFFERS_ARB;
1004 *a++ = WGL_SAMPLES_ARB;
1011 gldrivername = "opengl32.dll";
1012 // COMMANDLINEOPTION: Windows WGL: -gl_driver <drivername> selects a GL driver library, default is opengl32.dll, useful only for 3dfxogl.dll or 3dfxvgl.dll, if you don't know what this is for, you don't need it
1013 i = COM_CheckParm("-gl_driver");
1014 if (i && i < com_argc - 1)
1015 gldrivername = com_argv[i + 1];
1016 if (!GL_OpenLibrary(gldrivername))
1018 Con_Printf("Unable to load GL driver %s\n", gldrivername);
1022 memset(&gdevmode, 0, sizeof(gdevmode));
1024 vid_isfullscreen = false;
1027 if(vid_desktopfullscreen.integer)
1030 gdevmode = initialdevmode;
1031 width = mode->width = gdevmode.dmPelsWidth;
1032 height = mode->height = gdevmode.dmPelsHeight;
1033 bpp = mode->bitsperpixel = gdevmode.dmBitsPerPel;
1035 else if(vid_forcerefreshrate.integer)
1038 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
1039 gdevmode.dmBitsPerPel = bpp;
1040 gdevmode.dmPelsWidth = width;
1041 gdevmode.dmPelsHeight = height;
1042 gdevmode.dmSize = sizeof (gdevmode);
1045 gdevmode.dmFields |= DM_DISPLAYFREQUENCY;
1046 gdevmode.dmDisplayFrequency = refreshrate;
1051 if(refreshrate == 0)
1052 refreshrate = initialdevmode.dmDisplayFrequency; // default vid_refreshrate to the rate of the desktop
1055 foundgoodmode = false;
1057 thismode.dmSize = sizeof(thismode);
1058 thismode.dmDriverExtra = 0;
1059 for(i = 0; EnumDisplaySettings(NULL, i, &thismode); ++i)
1061 if(~thismode.dmFields & (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY))
1063 Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n");
1066 if(developer_extra.integer)
1067 Con_DPrintf("Found mode %dx%dx%dbpp %dHz... ", (int)thismode.dmPelsWidth, (int)thismode.dmPelsHeight, (int)thismode.dmBitsPerPel, (int)thismode.dmDisplayFrequency);
1068 if(thismode.dmBitsPerPel != (DWORD)bpp)
1070 if(developer_extra.integer)
1071 Con_DPrintf("wrong bpp\n");
1074 if(thismode.dmPelsWidth != (DWORD)width)
1076 if(developer_extra.integer)
1077 Con_DPrintf("wrong width\n");
1080 if(thismode.dmPelsHeight != (DWORD)height)
1082 if(developer_extra.integer)
1083 Con_DPrintf("wrong height\n");
1089 // if we have a good mode, make sure this mode is better than the previous one, and allowed by the refreshrate
1090 if(thismode.dmDisplayFrequency > (DWORD)refreshrate)
1092 if(developer_extra.integer)
1093 Con_DPrintf("too high refresh rate\n");
1096 else if(thismode.dmDisplayFrequency <= gdevmode.dmDisplayFrequency)
1098 if(developer_extra.integer)
1099 Con_DPrintf("doesn't beat previous best match (too low)\n");
1105 // we do have one, but it isn't good... make sure it has a lower frequency than the previous one
1106 if(thismode.dmDisplayFrequency >= gdevmode.dmDisplayFrequency)
1108 if(developer_extra.integer)
1109 Con_DPrintf("doesn't beat previous best match (too high)\n");
1113 // otherwise, take anything
1115 memcpy(&gdevmode, &thismode, sizeof(gdevmode));
1116 if(thismode.dmDisplayFrequency <= (DWORD)refreshrate)
1117 foundgoodmode = true;
1120 if(developer_extra.integer)
1121 Con_DPrintf("(out of range)\n");
1124 if(developer_extra.integer)
1125 Con_DPrintf("accepted\n");
1132 Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", width, height, bpp);
1135 else if(ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
1138 Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
1142 vid_isfullscreen = true;
1143 WindowStyle = WS_POPUP;
1144 ExWindowStyle = WS_EX_TOPMOST;
1149 i = GetDeviceCaps(hdc, RASTERCAPS);
1150 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
1151 ReleaseDC (NULL, hdc);
1155 Con_Print("Can't run in non-RGB mode\n");
1161 Con_Print("A higher desktop depth is required to run this video mode\n");
1165 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
1169 AdjustWindowBounds(fullscreen, &width, &height, mode, WindowStyle, &rect);
1173 // start out at the final windowpass if samples is 1 as it's the only feature we need extended pixel formats for
1174 for (windowpass = samples == 1;windowpass < 2;windowpass++)
1177 gl_platformextensions = "";
1179 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
1182 Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %p, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), (void *)NULL, (void *)NULL, (void *)global_hInstance, (void *)NULL);
1187 baseDC = GetDC(mainwindow);
1189 if (!newpixelformat)
1190 newpixelformat = ChoosePixelFormat(baseDC, &pfd);
1191 pixelformat = newpixelformat;
1195 Con_Printf("ChoosePixelFormat(%p, %p) failed\n", (void *)baseDC, (void *)&pfd);
1199 if (SetPixelFormat(baseDC, pixelformat, &pfd) == false)
1202 Con_Printf("SetPixelFormat(%p, %d, %p) failed\n", (void *)baseDC, pixelformat, (void *)&pfd);
1206 if (!GL_CheckExtension("wgl", wglfuncs, NULL, false))
1209 Con_Print("wgl functions not found\n");
1213 baseRC = qwglCreateContext(baseDC);
1217 Con_Print("Could not initialize GL (wglCreateContext failed).\n\nMake sure you are in 65536 color mode, and try running -window.\n");
1220 if (!qwglMakeCurrent(baseDC, baseRC))
1223 Con_Printf("wglMakeCurrent(%p, %p) failed\n", (void *)baseDC, (void *)baseRC);
1227 if ((qglGetString = (const GLubyte* (GLAPIENTRY *)(GLenum name))GL_GetProcAddress("glGetString")) == NULL)
1230 Con_Print("glGetString not found\n");
1233 if ((qwglGetExtensionsStringARB = (const char *(WINAPI *)(HDC hdc))GL_GetProcAddress("wglGetExtensionsStringARB")) == NULL)
1234 Con_Print("wglGetExtensionsStringARB not found\n");
1236 gl_extensions = (const char *)qglGetString(GL_EXTENSIONS);
1237 gl_platform = "WGL";
1238 gl_platformextensions = "";
1240 if (qwglGetExtensionsStringARB)
1241 gl_platformextensions = (const char *)qwglGetExtensionsStringARB(baseDC);
1245 if (!gl_platformextensions)
1246 gl_platformextensions = "";
1248 // now some nice Windows pain:
1249 // we have created a window, we needed one to find out if there are
1250 // any multisample pixel formats available, the problem is that to
1251 // actually use one of those multisample formats we now have to
1252 // recreate the window (yes Microsoft OpenGL really is that bad)
1254 if (windowpass == 0)
1256 if (!GL_CheckExtension("WGL_ARB_pixel_format", wglpixelformatfuncs, "-noarbpixelformat", false) || !qwglChoosePixelFormatARB(baseDC, attribs, attribsf, 1, &newpixelformat, &numpixelformats) || !newpixelformat)
1258 // ok we got one - do it all over again with newpixelformat
1259 qwglMakeCurrent(NULL, NULL);
1260 qwglDeleteContext(baseRC);baseRC = 0;
1261 ReleaseDC(mainwindow, baseDC);baseDC = 0;
1262 // eat up any messages waiting for us
1263 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
1265 TranslateMessage (&msg);
1266 DispatchMessage (&msg);
1273 SetWindowPos (mainwindow, NULL, CenterX, CenterY, 0, 0,SWP_NOSIZE | SWP_NOZORDER | SWP_SHOWWINDOW | SWP_DRAWFRAME);
1276 ShowWindow (mainwindow, SW_SHOWDEFAULT);
1277 UpdateWindow (mainwindow);
1279 // now we try to make sure we get the focus on the mode switch, because
1280 // sometimes in some systems we don't. We grab the foreground, then
1281 // finish setting up, pump all our messages, and sleep for a little while
1282 // to let messages finish bouncing around the system, then we put
1283 // ourselves at the top of the z order, then grab the foreground again,
1284 // Who knows if it helps, but it probably doesn't hurt
1285 SetForegroundWindow (mainwindow);
1287 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
1289 TranslateMessage (&msg);
1290 DispatchMessage (&msg);
1295 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
1297 SetForegroundWindow (mainwindow);
1299 // fix the leftover Alt from any Alt-Tab or the like that switched us away
1302 // COMMANDLINEOPTION: Windows WGL: -novideosync disables WGL_EXT_swap_control
1303 GL_CheckExtension("WGL_EXT_swap_control", wglswapintervalfuncs, "-novideosync", false);
1307 //vid_menudrawfn = VID_MenuDraw;
1308 //vid_menukeyfn = VID_MenuKey;
1309 vid_usingmouse = false;
1310 vid_usinghidecursor = false;
1311 vid_usingvsync = false;
1312 vid_reallyhidden = vid_hidden = false;
1313 vid_initialized = true;
1317 if (qwglSwapIntervalEXT)
1319 vid_usevsync = vid_vsync.integer != 0;
1320 vid_usingvsync = vid_vsync.integer != 0;
1321 qwglSwapIntervalEXT (vid_usevsync);
1327 static void AdjustWindowBounds(int fullscreen, int *width, int *height, viddef_mode_t *mode, DWORD WindowStyle, RECT *rect)
1329 int CenterX, CenterY;
1333 rect->right = *width;
1334 rect->bottom = *height;
1335 AdjustWindowRectEx(rect, WindowStyle, false, 0);
1345 SystemParametersInfo(SPI_GETWORKAREA, NULL, &workArea, 0);
1346 int workWidth = workArea.right - workArea.left;
1347 int workHeight = workArea.bottom - workArea.top;
1349 // if height/width matches physical screen height/width, adjust it to available desktop size
1350 // and allow 2 pixels on top for the title bar so the window can be moved
1351 const int titleBarPixels = 2;
1352 if (*width == GetSystemMetrics(SM_CXSCREEN) && (*height == GetSystemMetrics(SM_CYSCREEN) || *height == workHeight - titleBarPixels))
1354 rect->right -= *width - workWidth;
1355 *width = mode->width = workWidth;
1356 rect->bottom -= *height - (workHeight - titleBarPixels);
1357 *height = mode->height = workHeight - titleBarPixels;
1359 CenterY = titleBarPixels;
1363 CenterX = max(0, (workWidth - *width) / 2);
1364 CenterY = max(0, (workHeight - *height) / 2);
1368 // x and y may be changed by WM_MOVE messages
1371 rect->left += CenterX;
1372 rect->right += CenterX;
1373 rect->top += CenterY;
1374 rect->bottom += CenterY;
1378 static D3DADAPTER_IDENTIFIER9 d3d9adapteridentifier;
1380 extern cvar_t gl_info_extensions;
1381 extern cvar_t gl_info_vendor;
1382 extern cvar_t gl_info_renderer;
1383 extern cvar_t gl_info_version;
1384 extern cvar_t gl_info_platform;
1385 extern cvar_t gl_info_driver;
1386 qboolean VID_InitModeDX(viddef_mode_t *mode, int version)
1391 DWORD WindowStyle, ExWindowStyle;
1392 int bpp = mode->bitsperpixel;
1393 int width = mode->width;
1394 int height = mode->height;
1395 int refreshrate = (int)floor(mode->refreshrate+0.5);
1396 // int stereobuffer = mode->stereobuffer;
1397 int samples = mode->samples;
1398 int fullscreen = mode->fullscreen;
1401 if (vid_initialized)
1402 Sys_Error("VID_InitMode called when video is already initialised");
1404 vid_isfullscreen = fullscreen != 0;
1407 WindowStyle = WS_POPUP;
1408 ExWindowStyle = WS_EX_TOPMOST;
1412 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
1416 AdjustWindowBounds(fullscreen, &width, &height, mode, WindowStyle, &rect);
1419 gl_platformextensions = "";
1421 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
1424 Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %p, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), (void *)NULL, (void *)NULL, global_hInstance, (void *)NULL);
1429 baseDC = GetDC(mainwindow);
1431 vid_d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
1433 Sys_Error("VID_InitMode: Direct3DCreate9 failed");
1435 numdevices = IDirect3D9_GetAdapterCount(vid_d3d9);
1437 memset(&d3d9adapteridentifier, 0, sizeof(d3d9adapteridentifier));
1438 for (deviceindex = 0;deviceindex < numdevices && !vid_d3d9dev;deviceindex++)
1440 memset(&vid_d3dpresentparameters, 0, sizeof(vid_d3dpresentparameters));
1441 // vid_d3dpresentparameters.Flags = D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;
1442 vid_d3dpresentparameters.Flags = 0;
1443 vid_d3dpresentparameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
1444 vid_d3dpresentparameters.hDeviceWindow = mainwindow;
1445 vid_d3dpresentparameters.BackBufferWidth = width;
1446 vid_d3dpresentparameters.BackBufferHeight = height;
1447 vid_d3dpresentparameters.MultiSampleType = samples > 1 ? (D3DMULTISAMPLE_TYPE)samples : D3DMULTISAMPLE_NONE;
1448 vid_d3dpresentparameters.BackBufferCount = fullscreen ? (vid_dx9_triplebuffer.integer ? 3 : 2) : 1;
1449 vid_d3dpresentparameters.FullScreen_RefreshRateInHz = fullscreen ? refreshrate : 0;
1450 vid_d3dpresentparameters.Windowed = !fullscreen;
1451 vid_d3dpresentparameters.EnableAutoDepthStencil = true;
1452 vid_d3dpresentparameters.AutoDepthStencilFormat = bpp > 16 ? D3DFMT_D24S8 : D3DFMT_D16;
1453 vid_d3dpresentparameters.BackBufferFormat = fullscreen?D3DFMT_X8R8G8B8:D3DFMT_UNKNOWN;
1454 vid_d3dpresentparameters.PresentationInterval = vid_vsync.integer ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
1456 memset(&d3d9adapteridentifier, 0, sizeof(d3d9adapteridentifier));
1457 IDirect3D9_GetAdapterIdentifier(vid_d3d9, deviceindex, 0, &d3d9adapteridentifier);
1459 IDirect3D9_CreateDevice(vid_d3d9, deviceindex, vid_dx9_hal.integer ? D3DDEVTYPE_HAL : D3DDEVTYPE_REF, mainwindow, vid_dx9_softvertex.integer ? D3DCREATE_SOFTWARE_VERTEXPROCESSING : D3DCREATE_HARDWARE_VERTEXPROCESSING, &vid_d3dpresentparameters, &vid_d3d9dev);
1468 IDirect3DDevice9_GetDeviceCaps(vid_d3d9dev, &vid_d3d9caps);
1470 Con_Printf("Using D3D9 device: %s\n", d3d9adapteridentifier.Description);
1472 gl_platform = "D3D9";
1473 gl_platformextensions = "";
1475 ShowWindow (mainwindow, SW_SHOWDEFAULT);
1476 UpdateWindow (mainwindow);
1478 // now we try to make sure we get the focus on the mode switch, because
1479 // sometimes in some systems we don't. We grab the foreground, then
1480 // finish setting up, pump all our messages, and sleep for a little while
1481 // to let messages finish bouncing around the system, then we put
1482 // ourselves at the top of the z order, then grab the foreground again,
1483 // Who knows if it helps, but it probably doesn't hurt
1484 SetForegroundWindow (mainwindow);
1486 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
1488 TranslateMessage (&msg);
1489 DispatchMessage (&msg);
1494 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
1496 SetForegroundWindow (mainwindow);
1498 // fix the leftover Alt from any Alt-Tab or the like that switched us away
1501 gl_renderer = d3d9adapteridentifier.Description;
1502 gl_vendor = d3d9adapteridentifier.Driver;
1506 Con_Printf("D3D9 adapter info:\n");
1507 Con_Printf("Description: %s\n", d3d9adapteridentifier.Description);
1508 Con_Printf("DeviceId: %x\n", (unsigned int)d3d9adapteridentifier.DeviceId);
1509 Con_Printf("DeviceName: %p\n", d3d9adapteridentifier.DeviceName);
1510 Con_Printf("Driver: %s\n", d3d9adapteridentifier.Driver);
1511 Con_Printf("DriverVersion: %08x%08x\n", (unsigned int)d3d9adapteridentifier.DriverVersion.u.HighPart, (unsigned int)d3d9adapteridentifier.DriverVersion.u.LowPart);
1512 Con_DPrintf("GL_EXTENSIONS: %s\n", gl_extensions);
1513 Con_DPrintf("%s_EXTENSIONS: %s\n", gl_platform, gl_platformextensions);
1515 // clear the extension flags
1516 memset(&vid.support, 0, sizeof(vid.support));
1517 Cvar_SetQuick(&gl_info_extensions, "");
1519 // D3D9 requires BGRA
1520 vid.forcetextype = TEXTYPE_BGRA;
1522 vid.forcevbo = false;
1523 vid.support.arb_depth_texture = true;
1524 vid.support.arb_draw_buffers = vid_d3d9caps.NumSimultaneousRTs > 1;
1525 vid.support.arb_occlusion_query = true; // can't find a cap for this
1526 vid.support.arb_query_buffer_object = true;
1527 vid.support.arb_shadow = true;
1528 vid.support.arb_texture_compression = true;
1529 vid.support.arb_texture_cube_map = true;
1530 vid.support.arb_texture_non_power_of_two = (vid_d3d9caps.TextureCaps & D3DPTEXTURECAPS_POW2) == 0;
1531 vid.support.arb_vertex_buffer_object = true;
1532 vid.support.ext_blend_subtract = true;
1533 vid.support.ext_draw_range_elements = true;
1534 vid.support.ext_framebuffer_object = true;
1536 vid.support.ext_texture_3d = true;
1537 vid.support.ext_texture_compression_s3tc = true;
1538 vid.support.ext_texture_filter_anisotropic = true;
1539 vid.support.ati_separate_stencil = (vid_d3d9caps.StencilCaps & D3DSTENCILCAPS_TWOSIDED) != 0;
1540 vid.support.ext_texture_srgb = false; // FIXME use D3DSAMP_SRGBTEXTURE if CheckDeviceFormat agrees
1542 vid.maxtexturesize_2d = min(vid_d3d9caps.MaxTextureWidth, vid_d3d9caps.MaxTextureHeight);
1543 vid.maxtexturesize_3d = vid_d3d9caps.MaxVolumeExtent;
1544 vid.maxtexturesize_cubemap = vid.maxtexturesize_2d;
1546 vid.teximageunits = vid_d3d9caps.MaxSimultaneousTextures;
1547 vid.texarrayunits = 8; // can't find a caps field for this?
1548 vid.max_anisotropy = vid_d3d9caps.MaxAnisotropy;
1549 vid.maxdrawbuffers = vid_d3d9caps.NumSimultaneousRTs;
1551 vid.texunits = bound(4, vid.texunits, MAX_TEXTUREUNITS);
1552 vid.teximageunits = bound(16, vid.teximageunits, MAX_TEXTUREUNITS);
1553 vid.texarrayunits = bound(8, vid.texarrayunits, MAX_TEXTUREUNITS);
1554 Con_DPrintf("Using D3D9.0 rendering path - %i texture matrix, %i texture images, %i texcoords, shadowmapping supported%s\n", vid.texunits, vid.teximageunits, vid.texarrayunits, vid.maxdrawbuffers > 1 ? ", MRT detected (allows prepass deferred lighting)" : "");
1555 vid.renderpath = RENDERPATH_D3D9;
1556 vid.sRGBcapable2D = false;
1557 vid.sRGBcapable3D = true;
1558 vid.useinterleavedarrays = true;
1560 Cvar_SetQuick(&gl_info_vendor, gl_vendor);
1561 Cvar_SetQuick(&gl_info_renderer, gl_renderer);
1562 Cvar_SetQuick(&gl_info_version, gl_version);
1563 Cvar_SetQuick(&gl_info_platform, gl_platform ? gl_platform : "");
1564 Cvar_SetQuick(&gl_info_driver, gl_driver);
1566 // LordHavoc: report supported extensions
1567 Con_DPrintf("\nQuakeC extensions for server and client: %s\nQuakeC extensions for menu: %s\n", vm_sv_extensions, vm_m_extensions );
1569 // clear to black (loading plaque will be seen over this)
1570 IDirect3DDevice9_Clear(vid_d3d9dev, 0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
1571 IDirect3DDevice9_BeginScene(vid_d3d9dev);
1572 IDirect3DDevice9_EndScene(vid_d3d9dev);
1573 IDirect3DDevice9_Present(vid_d3d9dev, NULL, NULL, NULL, NULL);
1574 // because the only time we end/begin scene is in VID_Finish, we'd better start a scene now...
1575 IDirect3DDevice9_BeginScene(vid_d3d9dev);
1576 vid_begunscene = true;
1578 //vid_menudrawfn = VID_MenuDraw;
1579 //vid_menukeyfn = VID_MenuKey;
1580 vid_usingmouse = false;
1581 vid_usinghidecursor = false;
1582 vid_usingvsync = false;
1583 vid_hidden = vid_reallyhidden = false;
1584 vid_initialized = true;
1592 qboolean VID_InitModeSOFT(viddef_mode_t *mode)
1598 int pixelformat, newpixelformat;
1599 DWORD WindowStyle, ExWindowStyle;
1602 qboolean foundmode, foundgoodmode;
1603 int bpp = mode->bitsperpixel;
1604 int width = mode->width;
1605 int height = mode->height;
1606 int refreshrate = (int)floor(mode->refreshrate+0.5);
1607 int fullscreen = mode->fullscreen;
1609 if (vid_initialized)
1610 Sys_Error("VID_InitMode called when video is already initialised");
1612 memset(&gdevmode, 0, sizeof(gdevmode));
1614 vid_isfullscreen = false;
1617 if(vid_forcerefreshrate.integer)
1620 gdevmode.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
1621 gdevmode.dmBitsPerPel = bpp;
1622 gdevmode.dmPelsWidth = width;
1623 gdevmode.dmPelsHeight = height;
1624 gdevmode.dmSize = sizeof (gdevmode);
1627 gdevmode.dmFields |= DM_DISPLAYFREQUENCY;
1628 gdevmode.dmDisplayFrequency = refreshrate;
1633 if(refreshrate == 0)
1634 refreshrate = initialdevmode.dmDisplayFrequency; // default vid_refreshrate to the rate of the desktop
1637 foundgoodmode = false;
1639 thismode.dmSize = sizeof(thismode);
1640 thismode.dmDriverExtra = 0;
1641 for(i = 0; EnumDisplaySettings(NULL, i, &thismode); ++i)
1643 if(~thismode.dmFields & (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY))
1645 Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n");
1648 if(developer_extra.integer)
1649 Con_DPrintf("Found mode %dx%dx%dbpp %dHz... ", (int)thismode.dmPelsWidth, (int)thismode.dmPelsHeight, (int)thismode.dmBitsPerPel, (int)thismode.dmDisplayFrequency);
1650 if(thismode.dmBitsPerPel != (DWORD)bpp)
1652 if(developer_extra.integer)
1653 Con_DPrintf("wrong bpp\n");
1656 if(thismode.dmPelsWidth != (DWORD)width)
1658 if(developer_extra.integer)
1659 Con_DPrintf("wrong width\n");
1662 if(thismode.dmPelsHeight != (DWORD)height)
1664 if(developer_extra.integer)
1665 Con_DPrintf("wrong height\n");
1671 // if we have a good mode, make sure this mode is better than the previous one, and allowed by the refreshrate
1672 if(thismode.dmDisplayFrequency > (DWORD)refreshrate)
1674 if(developer_extra.integer)
1675 Con_DPrintf("too high refresh rate\n");
1678 else if(thismode.dmDisplayFrequency <= gdevmode.dmDisplayFrequency)
1680 if(developer_extra.integer)
1681 Con_DPrintf("doesn't beat previous best match (too low)\n");
1687 // we do have one, but it isn't good... make sure it has a lower frequency than the previous one
1688 if(thismode.dmDisplayFrequency >= gdevmode.dmDisplayFrequency)
1690 if(developer_extra.integer)
1691 Con_DPrintf("doesn't beat previous best match (too high)\n");
1695 // otherwise, take anything
1697 memcpy(&gdevmode, &thismode, sizeof(gdevmode));
1698 if(thismode.dmDisplayFrequency <= (DWORD)refreshrate)
1699 foundgoodmode = true;
1702 if(developer_extra.integer)
1703 Con_DPrintf("(out of range)\n");
1706 if(developer_extra.integer)
1707 Con_DPrintf("accepted\n");
1714 Con_Printf("Unable to find the requested mode %dx%dx%dbpp\n", width, height, bpp);
1717 else if(ChangeDisplaySettings (&gdevmode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
1720 Con_Printf("Unable to change to requested mode %dx%dx%dbpp\n", width, height, bpp);
1724 vid_isfullscreen = true;
1725 WindowStyle = WS_POPUP;
1726 ExWindowStyle = WS_EX_TOPMOST;
1731 i = GetDeviceCaps(hdc, RASTERCAPS);
1732 depth = GetDeviceCaps(hdc, PLANES) * GetDeviceCaps(hdc, BITSPIXEL);
1733 ReleaseDC (NULL, hdc);
1737 Con_Print("Can't run in non-RGB mode\n");
1743 Con_Print("A higher desktop depth is required to run this video mode\n");
1747 WindowStyle = WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
1751 AdjustWindowBounds(fullscreen, &width, &height, mode, WindowStyle, &rect);
1756 gl_platformextensions = "";
1758 mainwindow = CreateWindowEx (ExWindowStyle, "DarkPlacesWindowClass", gamename, WindowStyle, rect.left, rect.top, rect.right - rect.left, rect.bottom - rect.top, NULL, NULL, global_hInstance, NULL);
1761 Con_Printf("CreateWindowEx(%d, %s, %s, %d, %d, %d, %d, %d, %p, %p, %p, %p) failed\n", (int)ExWindowStyle, "DarkPlacesWindowClass", gamename, (int)WindowStyle, (int)(rect.left), (int)(rect.top), (int)(rect.right - rect.left), (int)(rect.bottom - rect.top), (void *)NULL, (void *)NULL, (void *)global_hInstance, (void *)NULL);
1766 baseDC = GetDC(mainwindow);
1767 vid.softpixels = NULL;
1768 memset(&vid_softbmi, 0, sizeof(vid_softbmi));
1769 vid_softbmi.bmiHeader.biSize = sizeof(vid_softbmi.bmiHeader);
1770 vid_softbmi.bmiHeader.biWidth = width;
1771 vid_softbmi.bmiHeader.biHeight = -height; // negative to make a top-down bitmap
1772 vid_softbmi.bmiHeader.biPlanes = 1;
1773 vid_softbmi.bmiHeader.biBitCount = 32;
1774 vid_softbmi.bmiHeader.biCompression = BI_RGB;
1775 vid_softbmi.bmiHeader.biSizeImage = width*height*4;
1776 vid_softbmi.bmiHeader.biClrUsed = 256;
1777 vid_softbmi.bmiHeader.biClrImportant = 256;
1778 vid_softdibhandle = CreateDIBSection(baseDC, &vid_softbmi, DIB_RGB_COLORS, (void **)&vid.softpixels, NULL, 0);
1779 if (!vid_softdibhandle)
1781 Con_Printf("CreateDIBSection failed\n");
1786 vid_softhdc = CreateCompatibleDC(baseDC);
1787 vid_softhdc_backup = SelectObject(vid_softhdc, vid_softdibhandle);
1788 if (!vid_softhdc_backup)
1790 Con_Printf("SelectObject failed\n");
1794 // ReleaseDC(mainwindow, baseDC);
1797 vid.softdepthpixels = (unsigned int *)calloc(1, mode->width * mode->height * 4);
1798 if (DPSOFTRAST_Init(mode->width, mode->height, vid_soft_threads.integer, vid_soft_interlace.integer, (unsigned int *)vid.softpixels, (unsigned int *)vid.softdepthpixels) < 0)
1800 Con_Printf("Failed to initialize software rasterizer\n");
1805 VID_Soft_SharedSetup();
1807 ShowWindow (mainwindow, SW_SHOWDEFAULT);
1808 UpdateWindow (mainwindow);
1810 // now we try to make sure we get the focus on the mode switch, because
1811 // sometimes in some systems we don't. We grab the foreground, then
1812 // finish setting up, pump all our messages, and sleep for a little while
1813 // to let messages finish bouncing around the system, then we put
1814 // ourselves at the top of the z order, then grab the foreground again,
1815 // Who knows if it helps, but it probably doesn't hurt
1816 SetForegroundWindow (mainwindow);
1818 while (PeekMessage (&msg, NULL, 0, 0, PM_REMOVE))
1820 TranslateMessage (&msg);
1821 DispatchMessage (&msg);
1826 SetWindowPos (mainwindow, HWND_TOP, 0, 0, 0, 0, SWP_DRAWFRAME | SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW | SWP_NOCOPYBITS);
1828 SetForegroundWindow (mainwindow);
1830 // fix the leftover Alt from any Alt-Tab or the like that switched us away
1833 //vid_menudrawfn = VID_MenuDraw;
1834 //vid_menukeyfn = VID_MenuKey;
1835 vid_usingmouse = false;
1836 vid_usinghidecursor = false;
1837 vid_usingvsync = false;
1838 vid_reallyhidden = vid_hidden = false;
1839 vid_initialized = true;
1846 qboolean VID_InitMode(viddef_mode_t *mode)
1849 if (vid_soft.integer)
1850 return VID_InitModeSOFT(mode);
1853 // if (vid_dx11.integer)
1854 // return VID_InitModeDX(mode, 11);
1855 // if (vid_dx10.integer)
1856 // return VID_InitModeDX(mode, 10);
1857 if (vid_dx9.integer)
1858 return VID_InitModeDX(mode, 9);
1860 return VID_InitModeGL(mode);
1864 static void IN_Shutdown(void);
1865 void VID_Shutdown (void)
1868 if(vid_initialized == false)
1871 VID_EnableJoystick(false);
1872 VID_SetMouse(false, false, false);
1873 VID_RestoreSystemGamma();
1875 vid_initialized = false;
1876 isgl = gldll != NULL;
1881 gl_platformextensions = "";
1884 SelectObject(vid_softhdc, vid_softhdc_backup);
1885 ReleaseDC(mainwindow, vid_softhdc);
1888 vid_softhdc_backup = NULL;
1889 if (vid_softdibhandle)
1890 DeleteObject(vid_softdibhandle);
1891 vid_softdibhandle = NULL;
1892 vid.softpixels = NULL;
1893 if (vid.softdepthpixels)
1894 free(vid.softdepthpixels);
1895 vid.softdepthpixels = NULL;
1900 IDirect3DDevice9_EndScene(vid_d3d9dev);
1901 vid_begunscene = false;
1902 // Cmd_ExecuteString("r_texturestats", src_command, true);
1903 // Cmd_ExecuteString("memlist", src_command, true);
1904 IDirect3DDevice9_Release(vid_d3d9dev);
1908 IDirect3D9_Release(vid_d3d9);
1911 if (qwglMakeCurrent)
1912 qwglMakeCurrent(NULL, NULL);
1913 qwglMakeCurrent = NULL;
1914 if (baseRC && qwglDeleteContext)
1915 qwglDeleteContext(baseRC);
1916 qwglDeleteContext = NULL;
1917 // close the library before we get rid of the window
1919 if (baseDC && mainwindow)
1920 ReleaseDC(mainwindow, baseDC);
1922 AppActivate(false, false);
1924 DestroyWindow(mainwindow);
1926 if (vid_isfullscreen && isgl)
1927 ChangeDisplaySettings (NULL, CDS_FULLSCREEN);
1928 vid_isfullscreen = false;
1931 void VID_SetMouse(qboolean fullscreengrab, qboolean relative, qboolean hidecursor)
1933 static qboolean restore_spi;
1934 static int originalmouseparms[3];
1936 if (!mouseinitialized)
1941 if (!vid_usingmouse)
1943 vid_usingmouse = true;
1944 cl_ignoremousemoves = 2;
1945 #ifdef SUPPORTDIRECTX
1946 if (dinput && g_pMouse)
1948 IDirectInputDevice_Acquire(g_pMouse);
1949 dinput_acquired = true;
1955 window_rect.left = window_x;
1956 window_rect.top = window_y;
1957 window_rect.right = window_x + vid.width;
1958 window_rect.bottom = window_y + vid.height;
1960 // change mouse settings to turn off acceleration
1961 // COMMANDLINEOPTION: Windows GDI Input: -noforcemparms disables setting of mouse parameters (not used with -dinput, windows only)
1962 if (!COM_CheckParm ("-noforcemparms") && SystemParametersInfo (SPI_GETMOUSE, 0, originalmouseparms, 0))
1964 int newmouseparms[3];
1965 newmouseparms[0] = 0; // threshold to double movement (only if accel level is >= 1)
1966 newmouseparms[1] = 0; // threshold to quadruple movement (only if accel level is >= 2)
1967 newmouseparms[2] = 0; // maximum level of acceleration (0 = off)
1968 restore_spi = SystemParametersInfo (SPI_SETMOUSE, 0, newmouseparms, 0) != FALSE;
1971 restore_spi = false;
1972 SetCursorPos ((window_x + vid.width / 2), (window_y + vid.height / 2));
1974 SetCapture (mainwindow);
1975 ClipCursor (&window_rect);
1983 vid_usingmouse = false;
1984 cl_ignoremousemoves = 2;
1985 #ifdef SUPPORTDIRECTX
1986 if (dinput_acquired)
1988 IDirectInputDevice_Unacquire(g_pMouse);
1989 dinput_acquired = false;
1994 // restore system mouseparms if we changed them
1996 SystemParametersInfo (SPI_SETMOUSE, 0, originalmouseparms, 0);
1997 restore_spi = false;
2004 if (vid_usinghidecursor != hidecursor)
2006 vid_usinghidecursor = hidecursor;
2007 ShowCursor (!hidecursor);
2011 void VID_BuildJoyState(vid_joystate_t *joystate)
2013 VID_Shared_BuildJoyState_Begin(joystate);
2014 VID_Shared_BuildJoyState_Finish(joystate);
2017 void VID_EnableJoystick(qboolean enable)
2019 int index = joy_enable.integer > 0 ? joy_index.integer : -1;
2020 qboolean success = false;
2021 int sharedcount = 0;
2022 sharedcount = VID_Shared_SetJoystick(index);
2023 if (index >= 0 && index < sharedcount)
2026 // update cvar containing count of XInput joysticks
2027 if (joy_detected.integer != sharedcount)
2028 Cvar_SetValueQuick(&joy_detected, sharedcount);
2030 if (joy_active.integer != (success ? 1 : 0))
2031 Cvar_SetValueQuick(&joy_active, success ? 1 : 0);
2034 #ifdef SUPPORTDIRECTX
2040 static qboolean IN_InitDInput (void)
2043 DIPROPDWORD dipdw = {
2045 sizeof(DIPROPDWORD), // diph.dwSize
2046 sizeof(DIPROPHEADER), // diph.dwHeaderSize
2048 DIPH_DEVICE, // diph.dwHow
2050 DINPUT_BUFFERSIZE, // dwData
2055 hInstDI = LoadLibrary("dinput.dll");
2057 if (hInstDI == NULL)
2059 Con_Print("Couldn't load dinput.dll\n");
2064 if (!pDirectInputCreate)
2066 pDirectInputCreate = (HRESULT (__stdcall *)(HINSTANCE,DWORD,LPDIRECTINPUT *,LPUNKNOWN))GetProcAddress(hInstDI,"DirectInputCreateA");
2068 if (!pDirectInputCreate)
2070 Con_Print("Couldn't get DI proc addr\n");
2075 // register with DirectInput and get an IDirectInput to play with.
2076 hr = iDirectInputCreate(global_hInstance, DIRECTINPUT_VERSION, &g_pdi, NULL);
2083 // obtain an interface to the system mouse device.
2085 hr = IDirectInput_CreateDevice(g_pdi, GUID_SysMouse, &g_pMouse, NULL);
2087 hr = IDirectInput_CreateDevice(g_pdi, &GUID_SysMouse, &g_pMouse, NULL);
2092 Con_Print("Couldn't open DI mouse device\n");
2096 // set the data format to "mouse format".
2097 hr = IDirectInputDevice_SetDataFormat(g_pMouse, &c_dfDIMouse);
2101 Con_Print("Couldn't set DI mouse format\n");
2105 // set the cooperativity level.
2106 hr = IDirectInputDevice_SetCooperativeLevel(g_pMouse, mainwindow,
2107 DISCL_EXCLUSIVE | DISCL_FOREGROUND);
2111 Con_Print("Couldn't set DI coop level\n");
2116 // set the buffer size to DINPUT_BUFFERSIZE elements.
2117 // the buffer size is a DWORD property associated with the device
2118 hr = IDirectInputDevice_SetProperty(g_pMouse, DIPROP_BUFFERSIZE, &dipdw.diph);
2122 Con_Print("Couldn't set DI buffersize\n");
2136 static void IN_StartupMouse (void)
2138 if (COM_CheckParm ("-nomouse"))
2141 mouseinitialized = true;
2143 #ifdef SUPPORTDIRECTX
2144 // COMMANDLINEOPTION: Windows Input: -dinput enables DirectInput for mouse input
2145 if (COM_CheckParm ("-dinput"))
2146 dinput = IN_InitDInput ();
2149 Con_Print("DirectInput initialized\n");
2151 Con_Print("DirectInput not initialized\n");
2163 static void IN_MouseMove (void)
2167 GetCursorPos (¤t_pos);
2168 in_windowmouse_x = current_pos.x - window_x;
2169 in_windowmouse_y = current_pos.y - window_y;
2171 if (!vid_usingmouse)
2174 #ifdef SUPPORTDIRECTX
2175 if (dinput_acquired)
2178 DIDEVICEOBJECTDATA od;
2186 hr = IDirectInputDevice_GetDeviceData(g_pMouse,
2187 sizeof(DIDEVICEOBJECTDATA), &od, &dwElements, 0);
2189 if ((hr == DIERR_INPUTLOST) || (hr == DIERR_NOTACQUIRED))
2191 IDirectInputDevice_Acquire(g_pMouse);
2195 /* Unable to read data or no data available */
2196 if (FAILED(hr) || dwElements == 0)
2199 /* Look at the element to see what happened */
2201 if ((int)od.dwOfs == DIMOFS_X)
2202 in_mouse_x += (LONG) od.dwData;
2203 if ((int)od.dwOfs == DIMOFS_Y)
2204 in_mouse_y += (LONG) od.dwData;
2205 if ((int)od.dwOfs == DIMOFS_Z)
2207 if((LONG)od.dwData < 0)
2209 Key_Event(K_MWHEELDOWN, 0, true);
2210 Key_Event(K_MWHEELDOWN, 0, false);
2212 else if((LONG)od.dwData > 0)
2214 Key_Event(K_MWHEELUP, 0, true);
2215 Key_Event(K_MWHEELUP, 0, false);
2218 if ((int)od.dwOfs == DIMOFS_BUTTON0)
2219 mstate_di = (mstate_di & ~1) | ((od.dwData & 0x80) >> 7);
2220 if ((int)od.dwOfs == DIMOFS_BUTTON1)
2221 mstate_di = (mstate_di & ~2) | ((od.dwData & 0x80) >> 6);
2222 if ((int)od.dwOfs == DIMOFS_BUTTON2)
2223 mstate_di = (mstate_di & ~4) | ((od.dwData & 0x80) >> 5);
2224 if ((int)od.dwOfs == DIMOFS_BUTTON3)
2225 mstate_di = (mstate_di & ~8) | ((od.dwData & 0x80) >> 4);
2228 // perform button actions
2229 for (i=0 ; i<mouse_buttons && i < 16 ; i++)
2230 if ((mstate_di ^ mouse_oldbuttonstate) & (1<<i))
2231 Key_Event (buttonremap[i], 0, (mstate_di & (1<<i)) != 0);
2232 mouse_oldbuttonstate = mstate_di;
2237 in_mouse_x += in_windowmouse_x - (int)(vid.width / 2);
2238 in_mouse_y += in_windowmouse_y - (int)(vid.height / 2);
2240 // if the mouse has moved, force it to the center, so there's room to move
2241 if (in_mouse_x || in_mouse_y)
2242 SetCursorPos ((window_x + vid.width / 2), (window_y + vid.height / 2));
2254 vid_joystate_t joystate;
2255 if (vid_activewindow && !vid_reallyhidden)
2257 VID_EnableJoystick(true);
2258 VID_BuildJoyState(&joystate);
2259 VID_ApplyJoyState(&joystate);
2263 static void IN_Init(void)
2265 uiWheelMessage = RegisterWindowMessage ( "MSWHEEL_ROLLMSG" );
2266 Cvar_RegisterVariable (&vid_forcerefreshrate);
2269 static void IN_Shutdown(void)
2271 #ifdef SUPPORTDIRECTX
2273 IDirectInputDevice_Release(g_pMouse);
2277 IDirectInput_Release(g_pdi);
2282 vid_mode_t *VID_GetDesktopMode(void)
2284 return &desktop_mode;
2287 size_t VID_ListModes(vid_mode_t *modes, size_t maxcount)
2293 thismode.dmSize = sizeof(thismode);
2294 thismode.dmDriverExtra = 0;
2296 for(i = 0; EnumDisplaySettings(NULL, i, &thismode); ++i)
2298 if(~thismode.dmFields & (DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT | DM_DISPLAYFREQUENCY))
2300 Con_DPrintf("enumerating modes yielded a bogus item... please debug this\n");
2305 modes[k].width = thismode.dmPelsWidth;
2306 modes[k].height = thismode.dmPelsHeight;
2307 modes[k].bpp = thismode.dmBitsPerPel;
2308 modes[k].refreshrate = thismode.dmDisplayFrequency;
2309 modes[k].pixelheight_num = 1;
2310 modes[k].pixelheight_denom = 1; // Win32 apparently does not provide this (FIXME)