Skip to content

Commit

Permalink
D3D9: Allow vsync change at runtime.
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownbrackets committed Mar 1, 2020
1 parent 6f86b6f commit bc90fae
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Windows/GPU/D3D9Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ static void GetRes(HWND hWnd, int &xres, int &yres) {
}

void D3D9Context::SwapInterval(int interval) {
// Dummy
swapInterval_ = interval;
}

bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
Expand Down Expand Up @@ -159,7 +159,7 @@ bool D3D9Context::Init(HINSTANCE hInst, HWND wnd, std::string *error_message) {
presentParams_.hDeviceWindow = wnd;
presentParams_.EnableAutoDepthStencil = true;
presentParams_.AutoDepthStencilFormat = D3DFMT_D24S8;
presentParams_.PresentationInterval = (g_Config.bVSync) ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
presentParams_.PresentationInterval = swapInterval_ == 1 ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;

if (has9Ex_) {
if (windowed && IsWin7OrLater()) {
Expand Down Expand Up @@ -205,16 +205,19 @@ void D3D9Context::Resize() {
// This should only be called from the emu thread.
int xres, yres;
GetRes(hWnd_, xres, yres);
uint32_t newInterval = swapInterval_ == 1 ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;;
bool w_changed = presentParams_.BackBufferWidth != xres;
bool h_changed = presentParams_.BackBufferHeight != yres;
bool i_changed = presentParams_.PresentationInterval != newInterval;

if (device_ && (w_changed || h_changed)) {
if (device_ && (w_changed || h_changed || i_changed)) {
draw_->HandleEvent(Draw::Event::LOST_BACKBUFFER, 0, 0, nullptr);
presentParams_.BackBufferWidth = xres;
presentParams_.BackBufferHeight = yres;
presentParams_.PresentationInterval = newInterval;
HRESULT hr = device_->Reset(&presentParams_);
if (FAILED(hr)) {
// Had to remove DXGetErrorStringA calls here because dxerr.lib is deprecated and will not link with VS 2015.
// Had to remove DXGetErrorStringA calls here because dxerr.lib is deprecated and will not link with VS 2015.
PanicAlert("Unable to reset D3D9 device");
}
draw_->HandleEvent(Draw::Event::GOT_BACKBUFFER, 0, 0, nullptr);
Expand Down
1 change: 1 addition & 0 deletions Windows/GPU/D3D9Context.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ class D3D9Context : public WindowsGraphicsContext {
HWND hWnd_; // Holds Our Window Handle
HMODULE hD3D9_;
D3DPRESENT_PARAMETERS presentParams_;
int swapInterval_ = 0;
};

0 comments on commit bc90fae

Please sign in to comment.