Direct3D11: Reduce FPS instead of crashing when minimised

This commit is contained in:
UnknownShadow200 2021-11-04 19:21:25 +11:00
parent 114aa2f666
commit 2e72ffefa2
3 changed files with 23 additions and 1 deletions

View File

@ -942,6 +942,13 @@ void Gfx_EndFrame(void) {
// https://docs.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-present // https://docs.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgiswapchain-present
// gfx_vsync happens to match SyncInterval parameter // gfx_vsync happens to match SyncInterval parameter
HRESULT hr = IDXGISwapChain_Present(swapchain, gfx_vsync, 0); HRESULT hr = IDXGISwapChain_Present(swapchain, gfx_vsync, 0);
// run at reduced FPS when minimised
if (hr == DXGI_STATUS_OCCLUDED) {
TickReducedPerformance(); return;
}
EndReducedPerformance();
if (hr) Logger_Abort2(hr, "Failed to swap buffers"); if (hr) Logger_Abort2(hr, "Failed to swap buffers");
} }

View File

@ -3691,7 +3691,7 @@ static const struct ScreenVTABLE TexPackOverlay_VTABLE = {
void TexPackOverlay_Show(const cc_string* url) { void TexPackOverlay_Show(const cc_string* url) {
struct TexPackOverlay* s = &TexPackOverlay; struct TexPackOverlay* s = &TexPackOverlay;
s->grabsInput = true; s->grabsInput = true;
/* Too easy to accidentally ESC this important dialog*/ /* Too easy to accidentally ESC this important dialog */
/* s->closable= true; */ /* s->closable= true; */
s->VTABLE = &TexPackOverlay_VTABLE; s->VTABLE = &TexPackOverlay_VTABLE;

View File

@ -91,6 +91,21 @@ void Gfx_RecreateContext(void) {
Event_RaiseVoid(&GfxEvents.ContextRecreated); Event_RaiseVoid(&GfxEvents.ContextRecreated);
} }
cc_bool reducedPerformance;
static void TickReducedPerformance(void) {
Thread_Sleep(100); /* 10 FPS */
if (reducedPerformance) return;
reducedPerformance = true; /* TODO: also log a message in-game? */
Platform_LogConst("Entering reduced performance mode");
}
static void EndReducedPerformance(void) {
if (!reducedPerformance) return;
reducedPerformance = false;
Platform_LogConst("Exited reduced performance mode");
}
void Gfx_RecreateDynamicVb(GfxResourceID* vb, VertexFormat fmt, int maxVertices) { void Gfx_RecreateDynamicVb(GfxResourceID* vb, VertexFormat fmt, int maxVertices) {
Gfx_DeleteDynamicVb(vb); Gfx_DeleteDynamicVb(vb);