Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Examples: Win32: Let the CPU and GPU chill when minimized #3907

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions examples/example_win32_directx10/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
static ID3D10Device* g_pd3dDevice = NULL;
static IDXGISwapChain* g_pSwapChain = NULL;
static ID3D10RenderTargetView* g_mainRenderTargetView = NULL;
static bool g_wndMinimized = false;

// Forward declarations of helper functions
bool CreateDeviceD3D(HWND hWnd);
Expand Down Expand Up @@ -97,6 +98,13 @@ int main(int, char**)
if (done)
break;

// Don't render if the window is minimized
if (g_wndMinimized)
{
Sleep(1); // Let the processor sleep a bit
continue;
}

// Start the Dear ImGui frame
ImGui_ImplDX10_NewFrame();
ImGui_ImplWin32_NewFrame();
Expand Down Expand Up @@ -229,6 +237,7 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0);
CreateRenderTarget();
}
g_wndMinimized = (wParam == SIZE_MINIMIZED);
return 0;
case WM_SYSCOMMAND:
if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
Expand Down
9 changes: 9 additions & 0 deletions examples/example_win32_directx11/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ static ID3D11Device* g_pd3dDevice = NULL;
static ID3D11DeviceContext* g_pd3dDeviceContext = NULL;
static IDXGISwapChain* g_pSwapChain = NULL;
static ID3D11RenderTargetView* g_mainRenderTargetView = NULL;
static bool g_wndMinimized = false;

// Forward declarations of helper functions
bool CreateDeviceD3D(HWND hWnd);
Expand Down Expand Up @@ -97,6 +98,13 @@ int main(int, char**)
if (done)
break;

// Don't render if the window is minimized
if (g_wndMinimized)
{
Sleep(1); // Let the processor sleep a bit
continue;
}

// Start the Dear ImGui frame
ImGui_ImplDX11_NewFrame();
ImGui_ImplWin32_NewFrame();
Expand Down Expand Up @@ -233,6 +241,7 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
g_pSwapChain->ResizeBuffers(0, (UINT)LOWORD(lParam), (UINT)HIWORD(lParam), DXGI_FORMAT_UNKNOWN, 0);
CreateRenderTarget();
}
g_wndMinimized = (wParam == SIZE_MINIMIZED);
return 0;
case WM_SYSCOMMAND:
if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
Expand Down
9 changes: 9 additions & 0 deletions examples/example_win32_directx12/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ static IDXGISwapChain3* g_pSwapChain = NULL;
static HANDLE g_hSwapChainWaitableObject = NULL;
static ID3D12Resource* g_mainRenderTargetResource[NUM_BACK_BUFFERS] = {};
static D3D12_CPU_DESCRIPTOR_HANDLE g_mainRenderTargetDescriptor[NUM_BACK_BUFFERS] = {};
static bool g_wndMinimized = false;

// Forward declarations of helper functions
bool CreateDeviceD3D(HWND hWnd);
Expand Down Expand Up @@ -136,6 +137,13 @@ int main(int, char**)
if (done)
break;

// Don't render if the window is minimized
if (g_wndMinimized)
{
Sleep(1); // Let the processor sleep a bit
continue;
}

// Start the Dear ImGui frame
ImGui_ImplDX12_NewFrame();
ImGui_ImplWin32_NewFrame();
Expand Down Expand Up @@ -478,6 +486,7 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
CreateRenderTarget();
ImGui_ImplDX12_CreateDeviceObjects();
}
g_wndMinimized = (wParam == SIZE_MINIMIZED);
return 0;
case WM_SYSCOMMAND:
if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
Expand Down
9 changes: 9 additions & 0 deletions examples/example_win32_directx9/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
static LPDIRECT3D9 g_pD3D = NULL;
static LPDIRECT3DDEVICE9 g_pd3dDevice = NULL;
static D3DPRESENT_PARAMETERS g_d3dpp = {};
static bool g_wndMinimized = false;

// Forward declarations of helper functions
bool CreateDeviceD3D(HWND hWnd);
Expand Down Expand Up @@ -95,6 +96,13 @@ int main(int, char**)
if (done)
break;

// Don't render if the window is minimized
if (g_wndMinimized)
{
Sleep(1); // Let the processor sleep a bit
continue;
}

// Start the Dear ImGui frame
ImGui_ImplDX9_NewFrame();
ImGui_ImplWin32_NewFrame();
Expand Down Expand Up @@ -223,6 +231,7 @@ LRESULT WINAPI WndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
g_d3dpp.BackBufferHeight = HIWORD(lParam);
ResetDevice();
}
g_wndMinimized = (wParam == SIZE_MINIMIZED);
return 0;
case WM_SYSCOMMAND:
if ((wParam & 0xfff0) == SC_KEYMENU) // Disable ALT application menu
Expand Down