fix: Make sure glfw waits properly on Wayland
This commit is contained in:
parent
99277d71cc
commit
d1fb41783d
@ -183,7 +183,6 @@ namespace hex {
|
|||||||
glfwWaitEvents();
|
glfwWaitEvents();
|
||||||
} else {
|
} else {
|
||||||
// If the application is visible, render a frame
|
// If the application is visible, render a frame
|
||||||
glfwPollEvents();
|
|
||||||
|
|
||||||
// If the application is in long sleep mode, only render a frame every 200ms
|
// If the application is in long sleep mode, only render a frame every 200ms
|
||||||
// Long sleep mode is enabled automatically after a few frames if the window content hasn't changed
|
// Long sleep mode is enabled automatically after a few frames if the window content hasn't changed
|
||||||
@ -193,10 +192,9 @@ namespace hex {
|
|||||||
constexpr static auto LongSleepFPS = 5.0;
|
constexpr static auto LongSleepFPS = 5.0;
|
||||||
const double timeout = std::max(0.0, (1.0 / LongSleepFPS) - (glfwGetTime() - m_lastStartFrameTime));
|
const double timeout = std::max(0.0, (1.0 / LongSleepFPS) - (glfwGetTime() - m_lastStartFrameTime));
|
||||||
|
|
||||||
auto endTime = std::chrono::steady_clock::now() + std::chrono::milliseconds(i64(timeout * 1000));
|
glfwWaitEventsTimeout(timeout);
|
||||||
while (!m_unlockFrameRate && std::chrono::steady_clock::now() < endTime) {
|
} else {
|
||||||
std::this_thread::sleep_for(std::chrono::microseconds(100));
|
glfwPollEvents();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,11 +220,13 @@ namespace hex {
|
|||||||
} else if (targetFPS > 200) {
|
} else if (targetFPS > 200) {
|
||||||
glfwSwapInterval(0);
|
glfwSwapInterval(0);
|
||||||
} else {
|
} else {
|
||||||
glfwSwapInterval(0);
|
if (!shouldLongSleep) {
|
||||||
const auto frameTime = glfwGetTime() - m_lastStartFrameTime;
|
glfwSwapInterval(0);
|
||||||
const auto targetFrameTime = 1.0 / targetFPS;
|
const auto frameTime = glfwGetTime() - m_lastStartFrameTime;
|
||||||
if (frameTime < targetFrameTime) {
|
const auto targetFrameTime = 1.0 / targetFPS;
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(i64((targetFrameTime - frameTime) * 1000)));
|
if (frameTime < targetFrameTime) {
|
||||||
|
glfwWaitEventsTimeout(targetFrameTime - frameTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -610,7 +610,13 @@ namespace hex {
|
|||||||
previousVtxDataSize = vtxDataSize;
|
previousVtxDataSize = vtxDataSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::UpdatePlatformWindows();
|
||||||
|
|
||||||
if (shouldRender) {
|
if (shouldRender) {
|
||||||
|
GLFWwindow *backupContext = glfwGetCurrentContext();
|
||||||
|
ImGui::RenderPlatformWindowsDefault();
|
||||||
|
glfwMakeContextCurrent(backupContext);
|
||||||
|
|
||||||
int displayWidth, displayHeight;
|
int displayWidth, displayHeight;
|
||||||
glfwGetFramebufferSize(m_window, &displayWidth, &displayHeight);
|
glfwGetFramebufferSize(m_window, &displayWidth, &displayHeight);
|
||||||
glViewport(0, 0, displayWidth, displayHeight);
|
glViewport(0, 0, displayWidth, displayHeight);
|
||||||
@ -623,10 +629,7 @@ namespace hex {
|
|||||||
m_unlockFrameRate = true;
|
m_unlockFrameRate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWwindow *backupContext = glfwGetCurrentContext();
|
glfwPollEvents();
|
||||||
ImGui::UpdatePlatformWindows();
|
|
||||||
ImGui::RenderPlatformWindowsDefault();
|
|
||||||
glfwMakeContextCurrent(backupContext);
|
|
||||||
|
|
||||||
// Process layout load requests
|
// Process layout load requests
|
||||||
// NOTE: This needs to be done before a new frame is started, otherwise ImGui won't handle docking correctly
|
// NOTE: This needs to be done before a new frame is started, otherwise ImGui won't handle docking correctly
|
||||||
@ -773,11 +776,6 @@ namespace hex {
|
|||||||
win->m_unlockFrameRate = true;
|
win->m_unlockFrameRate = true;
|
||||||
});
|
});
|
||||||
|
|
||||||
glfwSetMouseButtonCallback(m_window, [](GLFWwindow *window, int, int, int) {
|
|
||||||
auto win = static_cast<Window *>(glfwGetWindowUserPointer(window));
|
|
||||||
win->m_unlockFrameRate = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
glfwSetWindowFocusCallback(m_window, [](GLFWwindow *, int focused) {
|
glfwSetWindowFocusCallback(m_window, [](GLFWwindow *, int focused) {
|
||||||
EventWindowFocused::post(focused == GLFW_TRUE);
|
EventWindowFocused::post(focused == GLFW_TRUE);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user