Browse Source

Use actual monitor refresh rate instead of 60 Hz as frame rate reference.

tags/v1.1.5
Andrew Belt 5 years ago
parent
commit
ee876efa88
3 changed files with 11 additions and 4 deletions
  1. +1
    -0
      include/window.hpp
  2. +2
    -2
      src/app/MenuBar.cpp
  3. +8
    -2
      src/window.cpp

+ 1
- 0
include/window.hpp View File

@@ -90,6 +90,7 @@ struct Window {
void setFullScreen(bool fullScreen); void setFullScreen(bool fullScreen);
bool isFullScreen(); bool isFullScreen();
bool isFrameOverdue(); bool isFrameOverdue();
double getMonitorRefreshRate();


std::shared_ptr<Font> loadFont(const std::string& filename); std::shared_ptr<Font> loadFont(const std::string& filename);
std::shared_ptr<Image> loadImage(const std::string& filename); std::shared_ptr<Image> loadImage(const std::string& filename);


+ 2
- 2
src/app/MenuBar.cpp View File

@@ -339,11 +339,11 @@ struct FrameRateItem : ui::MenuItem {
ui::Menu* menu = new ui::Menu; ui::Menu* menu = new ui::Menu;


for (int i = 1; i <= 6; i++) { for (int i = 1; i <= 6; i++) {
float frameRate = 60.f / i;
double frameRate = APP->window->getMonitorRefreshRate() / i;


FrameRateValueItem* item = new FrameRateValueItem; FrameRateValueItem* item = new FrameRateValueItem;
item->frameSwapInterval = i; item->frameSwapInterval = i;
item->text = string::f("%.0f Hz", frameRate);
item->text = string::f("%.0lf Hz", frameRate);
item->rightText += CHECKMARK(settings::frameSwapInterval == i); item->rightText += CHECKMARK(settings::frameSwapInterval == i);
menu->addChild(item); menu->addChild(item);
} }


+ 8
- 2
src/window.cpp View File

@@ -96,6 +96,7 @@ struct Window::Internal {


bool ignoreNextMouseDelta = false; bool ignoreNextMouseDelta = false;
int frameSwapInterval = -1; int frameSwapInterval = -1;
double monitorRefreshRate = -1;
}; };




@@ -250,6 +251,8 @@ Window::Window() {


glfwMakeContextCurrent(win); glfwMakeContextCurrent(win);
glfwSwapInterval(1); glfwSwapInterval(1);
const GLFWvidmode* monitorMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
internal->monitorRefreshRate = monitorMode->refreshRate;


// Set window callbacks // Set window callbacks
glfwSetWindowSizeCallback(win, windowSizeCallback); glfwSetWindowSizeCallback(win, windowSizeCallback);
@@ -522,11 +525,14 @@ bool Window::isFrameOverdue() {
if (settings::frameSwapInterval == 0) if (settings::frameSwapInterval == 0)
return false; return false;
double frameDuration = glfwGetTime() - frameTimeStart; double frameDuration = glfwGetTime() - frameTimeStart;
// This is fudged a bit because it assumes the monitor refresh rate is 60 Hz.
double frameDeadline = settings::frameSwapInterval / 60.0;
double frameDeadline = settings::frameSwapInterval / internal->monitorRefreshRate;
return frameDuration > frameDeadline; return frameDuration > frameDeadline;
} }


double Window::getMonitorRefreshRate() {
return internal->monitorRefreshRate;
}

std::shared_ptr<Font> Window::loadFont(const std::string& filename) { std::shared_ptr<Font> Window::loadFont(const std::string& filename) {
auto sp = fontCache[filename].lock(); auto sp = fontCache[filename].lock();
if (!sp) { if (!sp) {


Loading…
Cancel
Save