From f1f9f74e5cecfb0ca79324caedfd23138a05fb6a Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 3 Apr 2022 18:43:22 +0900 Subject: [PATCH] internal/ui: bug fix: force to refresh the framebuffer by resizing the window very quickly Closes #2050 --- internal/ui/ui_glfw.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/internal/ui/ui_glfw.go b/internal/ui/ui_glfw.go index 8431a2956..d9a1c5cc6 100644 --- a/internal/ui/ui_glfw.go +++ b/internal/ui/ui_glfw.go @@ -75,6 +75,7 @@ type userInterfaceImpl struct { windowClosingHandled bool windowBeingClosed bool windowResizingMode WindowResizingMode + justAfterResized bool // setSizeCallbackEnabled must be accessed from the main thread. setSizeCallbackEnabled bool @@ -726,6 +727,9 @@ func (u *userInterfaceImpl) registerWindowSetSizeCallback() { if u.graphicsDriver.IsGL() { u.swapBuffers() } + + u.forceToRefreshIfNeeded() + u.justAfterResized = true }) } u.window.SetSizeCallback(u.sizeCallback) @@ -989,6 +993,11 @@ func (u *userInterfaceImpl) update() (float64, float64, error) { u.setFPSMode(u.fpsMode) } + if u.justAfterResized { + u.forceToRefreshIfNeeded() + } + u.justAfterResized = false + // Call updateVsync even though fpsMode is not updated. // The vsync state might be changed in other places (e.g., the SetSizeCallback). // Also, when toggling to fullscreen, vsync state might be reset unexpectedly (#1787). @@ -1589,3 +1598,22 @@ func (u *userInterfaceImpl) setOrigPos(x, y int) { u.origPosX = x u.origPosY = y } + +// forceToRefreshIfNeeded forces to refresh the framebuffer by resizing the window quickly. +// This is a very dirty but necessary hack for DirectX (#2050). +// With DirectX, the framebuffer is not rendered correctly when the window is resized by dragging +// or just after the resizing finishes by dragging. +// forceToRefreshIfNeeded must be called from the main thread. +func (u *userInterfaceImpl) forceToRefreshIfNeeded() { + if !u.graphicsDriver.IsDirectX() { + return + } + + x, y := u.window.GetPos() + u.window.SetPos(x+1,y+1) + glfw.PollEvents() + time.Sleep(time.Millisecond) + u.window.SetPos(x,y) + glfw.PollEvents() + time.Sleep(time.Millisecond) +}