From a1e3706c8f463e73f452c27f384b1943c8bcab84 Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 28 Dec 2023 18:55:54 +0300 Subject: [PATCH] Stop render when iconified --- src/engine.cpp | 12 +++++++++--- src/window/Window.cpp | 4 ++++ src/window/Window.h | 1 + 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/engine.cpp b/src/engine.cpp index 84583d77..ec647935 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -109,10 +109,16 @@ void Engine::mainloop() { gui->act(delta); screen->update(delta); - screen->draw(delta); - gui->draw(&batch, assets.get()); - Window::swapInterval(settings.display.swapInterval); + if (!Window::isIconified()) { + screen->draw(delta); + gui->draw(&batch, assets.get()); + Window::swapInterval(settings.display.swapInterval); + } else { + Window::swapInterval(1); + Window::swapBuffers(); + } + Window::swapBuffers(); Events::pollEvents(); } diff --git a/src/window/Window.cpp b/src/window/Window.cpp index 92d6cee8..856479b5 100644 --- a/src/window/Window.cpp +++ b/src/window/Window.cpp @@ -50,6 +50,10 @@ bool Window::isMaximized() { return glfwGetWindowAttrib(window, GLFW_MAXIMIZED); } +bool Window::isIconified() { + return glfwGetWindowAttrib(window, GLFW_ICONIFIED); +} + bool Window::isFocused() { return glfwGetWindowAttrib(window, GLFW_FOCUSED); diff --git a/src/window/Window.h b/src/window/Window.h index 05e0fb31..b4bb8786 100644 --- a/src/window/Window.h +++ b/src/window/Window.h @@ -39,6 +39,7 @@ public: static bool isFullscreen(); static bool isMaximized(); static bool isFocused(); + static bool isIconified(); static void pushScissor(glm::vec4 area); static void popScissor();