Browse Source

Try to preserve refresh rate when switching display mode on Windows

rdb 9 years ago
parent
commit
83d54bcdaf
2 changed files with 27 additions and 1 deletions
  1. 1 0
      doc/ReleaseNotes
  2. 26 1
      panda/src/windisplay/winGraphicsWindow.cxx

+ 1 - 0
doc/ReleaseNotes

@@ -48,6 +48,7 @@ This issue fixes several bugs that were still found in 1.9.2.
 * Fix exception when trying to pickle NodePathCollection objects
 * Fix exception when trying to pickle NodePathCollection objects
 * Fix error when trying to raise vectors to a power
 * Fix error when trying to raise vectors to a power
 * GLSL: fix error when legacy matrix generator inputs are mat3
 * GLSL: fix error when legacy matrix generator inputs are mat3
+* Now tries to preserve refresh rate when switching fullscreen on Windows
 
 
 ------------------------  RELEASE 1.9.2  ------------------------
 ------------------------  RELEASE 1.9.2  ------------------------
 
 

+ 26 - 1
panda/src/windisplay/winGraphicsWindow.cxx

@@ -2357,7 +2357,15 @@ hide_or_show_cursor(bool hide_cursor) {
 bool WinGraphicsWindow::
 bool WinGraphicsWindow::
 find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight, DWORD bpp,
 find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight, DWORD bpp,
                              DEVMODE &dm) {
                              DEVMODE &dm) {
+
+  // Get the current mode.  We'll try to match the refresh rate.
+  DEVMODE cur_dm;
+  ZeroMemory(&cur_dm, sizeof(cur_dm));
+  cur_dm.dmSize = sizeof(cur_dm);
+  EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &cur_dm);
+
   int modenum = 0;
   int modenum = 0;
+  int saved_modenum = -1;
 
 
   while (1) {
   while (1) {
     ZeroMemory(&dm, sizeof(dm));
     ZeroMemory(&dm, sizeof(dm));
@@ -2369,11 +2377,28 @@ find_acceptable_display_mode(DWORD dwWidth, DWORD dwHeight, DWORD bpp,
 
 
     if ((dm.dmPelsWidth == dwWidth) && (dm.dmPelsHeight == dwHeight) &&
     if ((dm.dmPelsWidth == dwWidth) && (dm.dmPelsHeight == dwHeight) &&
         (dm.dmBitsPerPel == bpp)) {
         (dm.dmBitsPerPel == bpp)) {
-      return true;
+      // If this also matches in refresh rate, we're done here.  Otherwise,
+      // save this as a second choice for later.
+      if (dm.dmDisplayFrequency == cur_dm.dmDisplayFrequency) {
+        return true;
+      } else if (saved_modenum == -1) {
+        saved_modenum = modenum;
+      }
     }
     }
     modenum++;
     modenum++;
   }
   }
 
 
+  // Failed to find an exact match, but we do have a match that didn't match
+  // the refresh rate.
+  if (saved_modenum != -1) {
+    ZeroMemory(&dm, sizeof(dm));
+    dm.dmSize = sizeof(dm);
+
+    if (EnumDisplaySettings(NULL, saved_modenum, &dm)) {
+      return true;
+    }
+  }
+
   return false;
   return false;
 }
 }