瀏覽代碼

windows: Use wglSwapLayerBuffers if available.

It apparently works better (or can work better?) on multimonitor setups
than SwapBuffers.

This should be available back to Windows 95, but just in case, it falls
back to standard SwapBuffers if not available.

Fixes #13269.
Ryan C. Gordon 10 月之前
父節點
當前提交
f286558bae
共有 2 個文件被更改,包括 13 次插入2 次删除
  1. 11 2
      src/video/windows/SDL_windowsopengl.c
  2. 2 0
      src/video/windows/SDL_windowsopengl.h

+ 11 - 2
src/video/windows/SDL_windowsopengl.c

@@ -141,6 +141,9 @@ bool WIN_GL_LoadLibrary(SDL_VideoDevice *_this, const char *path)
         SDL_LoadFunction(handle, "wglMakeCurrent");
         SDL_LoadFunction(handle, "wglMakeCurrent");
     _this->gl_data->wglShareLists = (BOOL (WINAPI *)(HGLRC, HGLRC))
     _this->gl_data->wglShareLists = (BOOL (WINAPI *)(HGLRC, HGLRC))
         SDL_LoadFunction(handle, "wglShareLists");
         SDL_LoadFunction(handle, "wglShareLists");
+    _this->gl_data->wglSwapLayerBuffers = (BOOL (WINAPI *)(HDC, UINT))
+        SDL_LoadFunction(handle, "wglSwapLayerBuffers");
+
     /* *INDENT-ON* */ // clang-format on
     /* *INDENT-ON* */ // clang-format on
 
 
 #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
 #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
@@ -886,8 +889,14 @@ bool WIN_GL_SwapWindow(SDL_VideoDevice *_this, SDL_Window *window)
 {
 {
     HDC hdc = window->internal->hdc;
     HDC hdc = window->internal->hdc;
 
 
-    if (!SwapBuffers(hdc)) {
-        return WIN_SetError("SwapBuffers()");
+    if (_this->gl_data->wglSwapLayerBuffers) {
+        if (!_this->gl_data->wglSwapLayerBuffers(hdc, WGL_SWAP_MAIN_PLANE)) {
+            return WIN_SetError("wglSwapLayerBuffers()");
+        }
+    } else {
+        if (!SwapBuffers(hdc)) {
+            return WIN_SetError("SwapBuffers()");
+        }
     }
     }
     return true;
     return true;
 }
 }

+ 2 - 0
src/video/windows/SDL_windowsopengl.h

@@ -85,6 +85,8 @@ struct SDL_GLDriverData
     BOOL (WINAPI *wglGetPixelFormatAttribivARB)(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
     BOOL (WINAPI *wglGetPixelFormatAttribivARB)(HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
     BOOL (WINAPI *wglSwapIntervalEXT)(int interval);
     BOOL (WINAPI *wglSwapIntervalEXT)(int interval);
     int (WINAPI *wglGetSwapIntervalEXT)(void);
     int (WINAPI *wglGetSwapIntervalEXT)(void);
+    BOOL (WINAPI *wglSwapLayerBuffers)(HDC hdc, UINT flags);
+
 #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
 #if defined(SDL_PLATFORM_XBOXONE) || defined(SDL_PLATFORM_XBOXSERIES)
     BOOL (WINAPI *wglSwapBuffers)(HDC hdc);
     BOOL (WINAPI *wglSwapBuffers)(HDC hdc);
     int (WINAPI *wglDescribePixelFormat)(HDC hdc,
     int (WINAPI *wglDescribePixelFormat)(HDC hdc,