From f2c922724365d650cf612be73d0db9ebd6bd07dc Mon Sep 17 00:00:00 2001 From: Randy Heit Date: Tue, 19 Feb 2008 02:48:56 +0000 Subject: [PATCH] - Added vid_refreshrate cvar to override Windows' automatic refresh rate selection. SVN r754 (trunk) --- docs/rh-log.txt | 2 ++ src/v_video.cpp | 22 ++++++++++++++++++++++ src/v_video.h | 3 +++ src/win32/fb_d3d9.cpp | 40 ++++++++++++++++++++++++++++++++++++++-- src/win32/fb_ddraw.cpp | 18 ++++++++++++++++-- src/win32/win32iface.h | 2 ++ 6 files changed, 83 insertions(+), 4 deletions(-) diff --git a/docs/rh-log.txt b/docs/rh-log.txt index 70319e140..a7dc803b9 100644 --- a/docs/rh-log.txt +++ b/docs/rh-log.txt @@ -1,4 +1,6 @@ February 18, 2008 +- Added vid_refreshrate cvar to override Windows' automatic refresh rate + selection. - Singleplayers maps using allowrespawn now filter respawn inventory like coop games, since that's essentially what they are. - Fixed m_alloc.cpp compilation on Linux. diff --git a/src/v_video.cpp b/src/v_video.cpp index 34d7e03b4..00d40c1d3 100644 --- a/src/v_video.cpp +++ b/src/v_video.cpp @@ -150,6 +150,7 @@ CVAR (Int, vid_defbits, 8, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) CVAR (Bool, vid_fps, false, 0) CVAR (Bool, ticker, false, 0) CVAR (Int, vid_showpalette, 0, 0) + CUSTOM_CVAR (Bool, vid_vsync, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) { if (screen != NULL) @@ -158,6 +159,14 @@ CUSTOM_CVAR (Bool, vid_vsync, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) } } +CUSTOM_CVAR (Int, vid_refreshrate, 0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) +{ + if (screen != NULL) + { + screen->NewRefreshRate(); + } +} + CUSTOM_CVAR (Float, dimamount, 0.2f, CVAR_ARCHIVE) { if (self < 0.f) @@ -1075,6 +1084,19 @@ void DFrameBuffer::SetVSync (bool vsync) { } +//========================================================================== +// +// DFrameBuffer :: NewRefreshRate +// +// Sets the fullscreen display to the new refresh rate in vid_refreshrate, +// if possible. +// +//========================================================================== + +void DFrameBuffer::NewRefreshRate () +{ +} + //========================================================================== // // DFrameBuffer :: SetBlendingRect diff --git a/src/v_video.h b/src/v_video.h index 3eaff3830..8f38f15d1 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -344,6 +344,9 @@ public: // Changes the vsync setting, if supported by the device. virtual void SetVSync (bool vsync); + // Tells the device to recreate itself with the new setting from vid_refreshrate. + virtual void NewRefreshRate (); + // Set the rect defining the area effected by blending. virtual void SetBlendingRect (int x1, int y1, int x2, int y2); diff --git a/src/win32/fb_d3d9.cpp b/src/win32/fb_d3d9.cpp index 4dd813dd6..b2c8a65c4 100644 --- a/src/win32/fb_d3d9.cpp +++ b/src/win32/fb_d3d9.cpp @@ -197,6 +197,7 @@ EXTERN_CVAR (Bool, fullscreen) EXTERN_CVAR (Float, Gamma) EXTERN_CVAR (Bool, vid_vsync) EXTERN_CVAR (Float, transsouls) +EXTERN_CVAR (Int, vid_refreshrate) extern IDirect3D9 *D3D; @@ -304,7 +305,19 @@ D3DFB::D3DFB (int width, int height, bool fullscreen) if (FAILED(D3D->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3dpp, &D3DDevice))) { - D3DDevice = NULL; + if (d3dpp.FullScreen_RefreshRateInHz != 0) + { + d3dpp.FullScreen_RefreshRateInHz = 0; + if (FAILED(hr = D3D->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, + D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3dpp, &D3DDevice))) + { + if (FAILED(D3D->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, + D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3dpp, &D3DDevice))) + { + D3DDevice = NULL; + } + } + } } } if (D3DDevice != NULL) @@ -386,6 +399,10 @@ void D3DFB::FillPresentParameters (D3DPRESENT_PARAMETERS *pp, bool fullscreen, b pp->BackBufferFormat = fullscreen ? D3DFMT_A8R8G8B8 : D3DFMT_UNKNOWN; pp->hDeviceWindow = Window; pp->PresentationInterval = vsync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE; + if (fullscreen) + { + pp->FullScreen_RefreshRateInHz = vid_refreshrate; + } } bool D3DFB::CreateResources () @@ -531,7 +548,18 @@ bool D3DFB::Reset () FillPresentParameters (&d3dpp, !Windowed, VSync); if (!SUCCEEDED(D3DDevice->Reset (&d3dpp))) { - return false; + if (d3dpp.FullScreen_RefreshRateInHz != 0) + { + d3dpp.FullScreen_RefreshRateInHz = 0; + if (!SUCCEEDED(D3DDevice->Reset (&d3dpp))) + { + return false; + } + } + else + { + return false; + } } LOG("Device was reset\n"); if (!CreateFBTexture() || !CreateVertexes()) @@ -1090,6 +1118,14 @@ void D3DFB::SetVSync (bool vsync) } } +void D3DFB::NewRefreshRate () +{ + if (!Windowed) + { + Reset(); + } +} + void D3DFB::Blank () { // Only used by movie player, which isn't working with D3D9 yet. diff --git a/src/win32/fb_ddraw.cpp b/src/win32/fb_ddraw.cpp index c362173ac..a1738cc15 100644 --- a/src/win32/fb_ddraw.cpp +++ b/src/win32/fb_ddraw.cpp @@ -80,6 +80,7 @@ extern bool VidResizing; EXTERN_CVAR (Bool, fullscreen) EXTERN_CVAR (Float, Gamma) +EXTERN_CVAR (Int, vid_refreshrate) extern IDirectDraw2 *DDraw; @@ -224,6 +225,7 @@ bool DDrawFB::CreateResources () DDSURFACEDESC ddsd = { sizeof(ddsd), }; HRESULT hr; int bits; + int refresh; BufferCount = 1; @@ -241,13 +243,18 @@ bool DDrawFB::CreateResources () break; } } - hr = DDraw->SetDisplayMode (Width, TrueHeight, bits = vid_displaybits, 0, 0); + hr = DDraw->SetDisplayMode (Width, TrueHeight, bits = vid_displaybits, vid_refreshrate, 0); if (FAILED(hr)) { + hr = DDraw->SetDisplayMode (Width, TrueHeight, bits = vid_displaybits, 0, 0); bits = 32; while (FAILED(hr) && bits >= 8) { - hr = DDraw->SetDisplayMode (Width, Height, bits, 0, 0); + hr = DDraw->SetDisplayMode (Width, Height, bits, vid_refreshrate, 0); + if (FAILED(hr)) + { + hr = DDraw->SetDisplayMode (Width, Height, bits, 0, 0); + } bits -= 8; } if (FAILED(hr)) @@ -1270,6 +1277,13 @@ void DDrawFB::SetVSync (bool vsync) FlipFlags = vsync ? DDFLIP_WAIT : DDFLIP_WAIT|DDFLIP_NOVSYNC; } +void DDrawFB::NewRefreshRate() +{ + if (!Windowed) + { + NeedResRecreate = true; + } +} void DDrawFB::Blank () { diff --git a/src/win32/win32iface.h b/src/win32/win32iface.h index 7468e072c..c54e4d40e 100644 --- a/src/win32/win32iface.h +++ b/src/win32/win32iface.h @@ -159,6 +159,7 @@ public: int QueryNewPalette (); void PaletteChanged (); void SetVSync (bool vsync); + void NewRefreshRate(); HRESULT GetHR (); void Blank (); @@ -240,6 +241,7 @@ public: void Blank (); bool PaintToWindow (); void SetVSync (bool vsync); + void NewRefreshRate(); void GetScreenshotBuffer(const BYTE *&buffer, int &pitch, ESSType &color_type); void ReleaseScreenshotBuffer(); void SetBlendingRect (int x1, int y1, int x2, int y2);