mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/ui: bug fix: force to refresh the framebuffer by resizing the window very quickly
Closes #2050
This commit is contained in:
parent
65094c61b1
commit
f1f9f74e5c
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user