|
|
@@ -95,6 +95,7 @@ struct Window::Internal { |
|
|
|
int lastWindowHeight = 0; |
|
|
|
|
|
|
|
bool ignoreNextMouseDelta = false; |
|
|
|
int frameSwapInterval = -1; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
@@ -248,8 +249,7 @@ Window::Window() { |
|
|
|
glfwSetInputMode(win, GLFW_LOCK_KEY_MODS, 1); |
|
|
|
|
|
|
|
glfwMakeContextCurrent(win); |
|
|
|
// Enable v-sync |
|
|
|
glfwSwapInterval(settings::frameRateSync ? 1 : 0); |
|
|
|
glfwSwapInterval(1); |
|
|
|
|
|
|
|
// Set window callbacks |
|
|
|
glfwSetWindowSizeCallback(win, windowSizeCallback); |
|
|
@@ -333,8 +333,14 @@ void Window::run() { |
|
|
|
|
|
|
|
// Poll events |
|
|
|
glfwPollEvents(); |
|
|
|
// In case glfwPollEvents() set another OpenGL context |
|
|
|
|
|
|
|
// In case glfwPollEvents() sets another OpenGL context |
|
|
|
glfwMakeContextCurrent(win); |
|
|
|
if (settings::frameSwapInterval != internal->frameSwapInterval) { |
|
|
|
internal->frameSwapInterval = settings::frameSwapInterval; |
|
|
|
glfwSwapInterval(settings::frameSwapInterval); |
|
|
|
} |
|
|
|
|
|
|
|
// Call cursorPosCallback every frame, not just when the mouse moves |
|
|
|
{ |
|
|
|
double xpos, ypos; |
|
|
@@ -396,23 +402,13 @@ void Window::run() { |
|
|
|
glClearColor(0.0, 0.0, 0.0, 1.0); |
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); |
|
|
|
nvgEndFrame(vg); |
|
|
|
|
|
|
|
glfwSwapBuffers(win); |
|
|
|
} |
|
|
|
|
|
|
|
// Limit frame rate |
|
|
|
double frameTimeEnd = glfwGetTime(); |
|
|
|
if (settings::frameRateLimit > 0.0) { |
|
|
|
double frameDuration = frameTimeEnd - frameTimeStart; |
|
|
|
double waitDuration = 1.0 / settings::frameRateLimit - frameDuration; |
|
|
|
if (waitDuration > 0.0) { |
|
|
|
std::this_thread::sleep_for(std::chrono::duration<double>(waitDuration)); |
|
|
|
} |
|
|
|
} |
|
|
|
glfwSwapBuffers(win); |
|
|
|
|
|
|
|
// Compute actual frame rate |
|
|
|
frameTimeEnd = glfwGetTime(); |
|
|
|
// DEBUG("%g fps", 1 / (endTime - startTime)); |
|
|
|
double frameTimeEnd = glfwGetTime(); |
|
|
|
DEBUG("%g fps", 1 / (frameTimeEnd - frameTimeStart)); |
|
|
|
frame++; |
|
|
|
} |
|
|
|
} |
|
|
@@ -523,10 +519,12 @@ bool Window::isFullScreen() { |
|
|
|
} |
|
|
|
|
|
|
|
bool Window::isFrameOverdue() { |
|
|
|
if (settings::frameRateLimit == 0.0) |
|
|
|
if (settings::frameSwapInterval == 0) |
|
|
|
return false; |
|
|
|
double frameDuration = glfwGetTime() - frameTimeStart; |
|
|
|
return frameDuration > 1.0 / settings::frameRateLimit; |
|
|
|
// This is fudged a bit because it assumes the monitor refresh rate is 60 Hz. |
|
|
|
double frameDeadline = settings::frameSwapInterval / 60.0; |
|
|
|
return frameDuration > frameDeadline; |
|
|
|
} |
|
|
|
|
|
|
|
std::shared_ptr<Font> Window::loadFont(const std::string& filename) { |
|
|
|