internal/ui: bug fix: force to refresh the framebuffer by resizing the window very quickly

Closes #2050
This commit is contained in:
Hajime Hoshi 2022-04-03 18:43:22 +09:00
parent 65094c61b1
commit f1f9f74e5c

View File

@ -75,6 +75,7 @@ type userInterfaceImpl struct {
windowClosingHandled bool windowClosingHandled bool
windowBeingClosed bool windowBeingClosed bool
windowResizingMode WindowResizingMode windowResizingMode WindowResizingMode
justAfterResized bool
// setSizeCallbackEnabled must be accessed from the main thread. // setSizeCallbackEnabled must be accessed from the main thread.
setSizeCallbackEnabled bool setSizeCallbackEnabled bool
@ -726,6 +727,9 @@ func (u *userInterfaceImpl) registerWindowSetSizeCallback() {
if u.graphicsDriver.IsGL() { if u.graphicsDriver.IsGL() {
u.swapBuffers() u.swapBuffers()
} }
u.forceToRefreshIfNeeded()
u.justAfterResized = true
}) })
} }
u.window.SetSizeCallback(u.sizeCallback) u.window.SetSizeCallback(u.sizeCallback)
@ -989,6 +993,11 @@ func (u *userInterfaceImpl) update() (float64, float64, error) {
u.setFPSMode(u.fpsMode) u.setFPSMode(u.fpsMode)
} }
if u.justAfterResized {
u.forceToRefreshIfNeeded()
}
u.justAfterResized = false
// Call updateVsync even though fpsMode is not updated. // Call updateVsync even though fpsMode is not updated.
// The vsync state might be changed in other places (e.g., the SetSizeCallback). // 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). // 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.origPosX = x
u.origPosY = y 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)
}