mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-10 06:42:12 +00:00
Switch to the D3DSWAPEFFECT_FLIPEX swap model
This commit is contained in:
parent
43139276d1
commit
a9e6592feb
3 changed files with 19 additions and 18 deletions
|
@ -49,12 +49,12 @@ extern FString gpuStatOutput;
|
|||
|
||||
#ifdef WIN32
|
||||
void I_PolyPresentInit();
|
||||
uint8_t *I_PolyPresentLock(int w, int h, int &pitch);
|
||||
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch);
|
||||
void I_PolyPresentUnlock(int x, int y, int w, int h);
|
||||
void I_PolyPresentDeinit();
|
||||
#else
|
||||
void I_PolyPresentInit() { }
|
||||
uint8_t *I_PolyPresentLock(int w, int h, int &pitch) { pitch = 0; return nullptr; }
|
||||
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch) { pitch = 0; return nullptr; }
|
||||
void I_PolyPresentUnlock(int x, int y, int w, int h) { }
|
||||
void I_PolyPresentDeinit() { }
|
||||
#endif
|
||||
|
@ -157,7 +157,7 @@ void PolyFrameBuffer::Update()
|
|||
int pixelsize = 4;
|
||||
const uint8_t *src = (const uint8_t*)mCanvas->GetPixels();
|
||||
int pitch = 0;
|
||||
uint8_t *dst = I_PolyPresentLock(w, h, pitch);
|
||||
uint8_t *dst = I_PolyPresentLock(w, h, cur_vsync, pitch);
|
||||
if (dst)
|
||||
{
|
||||
#if 1
|
||||
|
@ -444,7 +444,7 @@ uint32_t PolyFrameBuffer::GetCaps()
|
|||
|
||||
void PolyFrameBuffer::SetVSync(bool vsync)
|
||||
{
|
||||
// This is handled in PolySwapChain::AcquireImage.
|
||||
cur_vsync = vsync;
|
||||
}
|
||||
|
||||
void PolyFrameBuffer::CleanForRestart()
|
||||
|
|
|
@ -83,6 +83,8 @@ private:
|
|||
std::unique_ptr<PolyDepthStencil> mDepthStencil;
|
||||
std::shared_ptr<DrawerCommandQueue> mDrawCommands;
|
||||
RenderMemory mFrameMemory;
|
||||
|
||||
bool cur_vsync = false;
|
||||
};
|
||||
|
||||
inline PolyFrameBuffer *GetPolyFrameBuffer() { return static_cast<PolyFrameBuffer*>(screen); }
|
||||
|
|
|
@ -19,14 +19,14 @@ namespace
|
|||
int ClientHeight = 0;
|
||||
bool CurrentVSync = false;
|
||||
|
||||
IDirect3D9 *d3d9 = nullptr;
|
||||
IDirect3DDevice9 *device = nullptr;
|
||||
IDirect3DSurface9 *surface = nullptr;
|
||||
IDirect3D9Ex *d3d9 = nullptr;
|
||||
IDirect3DDevice9Ex *device = nullptr;
|
||||
IDirect3DSurface9* surface = nullptr;
|
||||
}
|
||||
|
||||
void I_PolyPresentInit()
|
||||
{
|
||||
d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
|
||||
Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9);
|
||||
if (!d3d9)
|
||||
{
|
||||
I_FatalError("Direct3DCreate9 failed");
|
||||
|
@ -35,33 +35,32 @@ void I_PolyPresentInit()
|
|||
RECT rect = {};
|
||||
GetClientRect(Window, &rect);
|
||||
|
||||
CurrentVSync = vid_vsync;
|
||||
ClientWidth = rect.right;
|
||||
ClientHeight = rect.bottom;
|
||||
|
||||
D3DPRESENT_PARAMETERS pp = {};
|
||||
pp.Windowed = true;
|
||||
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
pp.SwapEffect = D3DSWAPEFFECT_FLIPEX;
|
||||
pp.BackBufferWidth = ClientWidth;
|
||||
pp.BackBufferHeight = ClientHeight;
|
||||
pp.BackBufferCount = 1;
|
||||
pp.hDeviceWindow = Window;
|
||||
pp.PresentationInterval = CurrentVSync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
pp.PresentationInterval = CurrentVSync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
|
||||
HRESULT result = d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &device);
|
||||
HRESULT result = d3d9->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, nullptr, &device);
|
||||
if (FAILED(result))
|
||||
{
|
||||
I_FatalError("IDirect3D9.CreateDevice failed");
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t *I_PolyPresentLock(int w, int h, int &pitch)
|
||||
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch)
|
||||
{
|
||||
HRESULT result;
|
||||
|
||||
RECT rect = {};
|
||||
GetClientRect(Window, &rect);
|
||||
if (rect.right != ClientWidth || rect.bottom != ClientHeight || CurrentVSync != vid_vsync)
|
||||
if (rect.right != ClientWidth || rect.bottom != ClientHeight || CurrentVSync != vsync)
|
||||
{
|
||||
if (surface)
|
||||
{
|
||||
|
@ -69,18 +68,18 @@ uint8_t *I_PolyPresentLock(int w, int h, int &pitch)
|
|||
surface = nullptr;
|
||||
}
|
||||
|
||||
CurrentVSync = vid_vsync;
|
||||
CurrentVSync = vsync;
|
||||
ClientWidth = rect.right;
|
||||
ClientHeight = rect.bottom;
|
||||
|
||||
D3DPRESENT_PARAMETERS pp = {};
|
||||
pp.Windowed = true;
|
||||
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
|
||||
pp.SwapEffect = D3DSWAPEFFECT_FLIPEX;
|
||||
pp.BackBufferWidth = ClientWidth;
|
||||
pp.BackBufferHeight = ClientHeight;
|
||||
pp.BackBufferCount = 1;
|
||||
pp.hDeviceWindow = Window;
|
||||
pp.PresentationInterval = CurrentVSync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
pp.PresentationInterval = CurrentVSync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE;
|
||||
device->Reset(&pp);
|
||||
}
|
||||
|
||||
|
@ -173,7 +172,7 @@ void I_PolyPresentUnlock(int x, int y, int width, int height)
|
|||
|
||||
result = device->EndScene();
|
||||
if (SUCCEEDED(result))
|
||||
device->Present(nullptr, nullptr, 0, nullptr);
|
||||
device->PresentEx(nullptr, nullptr, 0, nullptr, CurrentVSync ? 0 : D3DPRESENT_FORCEIMMEDIATE);
|
||||
}
|
||||
|
||||
backbuffer->Release();
|
||||
|
|
Loading…
Reference in a new issue