[glfw] Reduce memory use when window loses focus
This commit is contained in:
@@ -102,6 +102,7 @@ GLFWView::GLFWView(bool fullscreen_, bool benchmark_)
|
||||
glfwSetFramebufferSizeCallback(window, onFramebufferResize);
|
||||
glfwSetScrollCallback(window, onScroll);
|
||||
glfwSetKeyCallback(window, onKey);
|
||||
glfwSetWindowFocusCallback(window, onWindowFocus);
|
||||
|
||||
glfwGetWindowSize(window, &width, &height);
|
||||
|
||||
@@ -559,6 +560,13 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) {
|
||||
view->lastY = y;
|
||||
}
|
||||
|
||||
void GLFWView::onWindowFocus(GLFWwindow *window, int focused) {
|
||||
if (focused == GLFW_FALSE) { // Focus lost.
|
||||
auto *view = reinterpret_cast<GLFWView *>(glfwGetWindowUserPointer(window));
|
||||
view->rendererFrontend->getRenderer()->reduceMemoryUse();
|
||||
}
|
||||
}
|
||||
|
||||
void GLFWView::run() {
|
||||
auto callback = [&] {
|
||||
if (glfwWindowShouldClose(window)) {
|
||||
|
||||
@@ -68,6 +68,7 @@ private:
|
||||
static void onFramebufferResize(GLFWwindow *window, int width, int height);
|
||||
static void onMouseClick(GLFWwindow *window, int button, int action, int modifiers);
|
||||
static void onMouseMove(GLFWwindow *window, double x, double y);
|
||||
static void onWindowFocus(GLFWwindow *window, int focused);
|
||||
|
||||
// Internal
|
||||
void report(float duration);
|
||||
|
||||
Reference in New Issue
Block a user