Skip to content

Commit

Permalink
Examples: SDL2 (all), SDL3 (all), Win32+OpenGL3: Rework examples main…
Browse files Browse the repository at this point in the history
… loop to handle minimization without burning CPU or GPU by running unthrottled code. (#7844)
  • Loading branch information
ocornut committed Jul 31, 2024
1 parent dcf5478 commit 8874787
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ Breaking changes:

Other changes:

- Examples: SDL2 (all), SDL3 (all), Win32+OpenGL3: rework examples main loop to handle
minimization without burning CPU or GPU by running unthrottled code. (#7844)



-----------------------------------------------------------------------
VERSION 1.91.0 (Released 2024-07-30)
Expand Down
5 changes: 5 additions & 0 deletions examples/example_sdl2_directx11/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ int main(int, char**)
CreateRenderTarget();
}
}
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
{
SDL_Delay(10);
continue;
}

// Start the Dear ImGui frame
ImGui_ImplDX11_NewFrame();
Expand Down
5 changes: 5 additions & 0 deletions examples/example_sdl2_opengl2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ int main(int, char**)
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
done = true;
}
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
{
SDL_Delay(10);
continue;
}

// Start the Dear ImGui frame
ImGui_ImplOpenGL2_NewFrame();
Expand Down
5 changes: 5 additions & 0 deletions examples/example_sdl2_opengl3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ int main(int, char**)
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
done = true;
}
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
{
SDL_Delay(10);
continue;
}

// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
Expand Down
5 changes: 5 additions & 0 deletions examples/example_sdl2_sdlrenderer2/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@ int main(int, char**)
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
done = true;
}
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
{
SDL_Delay(10);
continue;
}

// Start the Dear ImGui frame
ImGui_ImplSDLRenderer2_NewFrame();
Expand Down
5 changes: 5 additions & 0 deletions examples/example_sdl2_vulkan/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,11 @@ int main(int, char**)
if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE && event.window.windowID == SDL_GetWindowID(window))
done = true;
}
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
{
SDL_Delay(10);
continue;
}

// Resize swap chain?
int fb_width, fb_height;
Expand Down
5 changes: 5 additions & 0 deletions examples/example_sdl3_opengl3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ int main(int, char**)
if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED && event.window.windowID == SDL_GetWindowID(window))
done = true;
}
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
{
SDL_Delay(10);
continue;
}

// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
Expand Down
5 changes: 5 additions & 0 deletions examples/example_sdl3_sdlrenderer3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ int main(int, char**)
if (event.type == SDL_EVENT_WINDOW_CLOSE_REQUESTED && event.window.windowID == SDL_GetWindowID(window))
done = true;
}
if (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED)
{
SDL_Delay(10);
continue;
}

// Start the Dear ImGui frame
ImGui_ImplSDLRenderer3_NewFrame();
Expand Down
5 changes: 5 additions & 0 deletions examples/example_win32_opengl3/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ int main(int, char**)
}
if (done)
break;
if (::IsIconic(hwnd))
{
::Sleep(10);
continue;
}

// Start the Dear ImGui frame
ImGui_ImplOpenGL3_NewFrame();
Expand Down

0 comments on commit 8874787

Please sign in to comment.