mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
internal/uidriver/glfw: Wait for a FramebufferSize callback for the initial temporary window
Updates #1847
This commit is contained in:
parent
2f2ccbbe55
commit
6f29e57378
@ -186,6 +186,7 @@ func initialize() error {
|
|||||||
}
|
}
|
||||||
defer w.Destroy()
|
defer w.Destroy()
|
||||||
initializeWindowAfterCreation(w)
|
initializeWindowAfterCreation(w)
|
||||||
|
theUI.waitForFramebufferSizeCallback(w, nil)
|
||||||
|
|
||||||
m := initialMonitor(w)
|
m := initialMonitor(w)
|
||||||
theUI.initMonitor = m
|
theUI.initMonitor = m
|
||||||
@ -731,7 +732,7 @@ func (u *UserInterface) createWindow() error {
|
|||||||
|
|
||||||
// Even just after a window creation, FramebufferSize callback might be invoked (#1847).
|
// Even just after a window creation, FramebufferSize callback might be invoked (#1847).
|
||||||
// Ensure to consume this callback.
|
// Ensure to consume this callback.
|
||||||
u.waitForFramebufferSizeCallback(nil)
|
u.waitForFramebufferSizeCallback(u.window, nil)
|
||||||
|
|
||||||
if u.Graphics().IsGL() {
|
if u.Graphics().IsGL() {
|
||||||
u.window.MakeContextCurrent()
|
u.window.MakeContextCurrent()
|
||||||
@ -825,11 +826,11 @@ func (u *UserInterface) registerWindowCloseCallback() {
|
|||||||
// If the callback is not invoked for a while, waitForFramebufferSizeCallback times out and return.
|
// If the callback is not invoked for a while, waitForFramebufferSizeCallback times out and return.
|
||||||
//
|
//
|
||||||
// waitForFramebufferSizeCallback must be called from the main thread.
|
// waitForFramebufferSizeCallback must be called from the main thread.
|
||||||
func (u *UserInterface) waitForFramebufferSizeCallback(f func()) {
|
func (u *UserInterface) waitForFramebufferSizeCallback(window *glfw.Window, f func()) {
|
||||||
u.framebufferSizeCallbackCh = make(chan struct{}, 1)
|
u.framebufferSizeCallbackCh = make(chan struct{}, 1)
|
||||||
|
|
||||||
if u.framebufferSizeCallback == 0 {
|
if u.framebufferSizeCallback == 0 {
|
||||||
u.framebufferSizeCallback = glfw.ToFramebufferSizeCallback(func(_ *glfw.Window, w, h int) {
|
u.framebufferSizeCallback = glfw.ToFramebufferSizeCallback(func(_ *glfw.Window, _, _ int) {
|
||||||
// This callback can be invoked multiple times by one PollEvents in theory (#1618).
|
// This callback can be invoked multiple times by one PollEvents in theory (#1618).
|
||||||
// Allow the case when the channel is full.
|
// Allow the case when the channel is full.
|
||||||
select {
|
select {
|
||||||
@ -838,7 +839,7 @@ func (u *UserInterface) waitForFramebufferSizeCallback(f func()) {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
u.window.SetFramebufferSizeCallback(u.framebufferSizeCallback)
|
window.SetFramebufferSizeCallback(u.framebufferSizeCallback)
|
||||||
|
|
||||||
if f != nil {
|
if f != nil {
|
||||||
f()
|
f()
|
||||||
@ -860,7 +861,7 @@ event:
|
|||||||
time.Sleep(time.Millisecond)
|
time.Sleep(time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
u.window.SetFramebufferSizeCallback(glfw.ToFramebufferSizeCallback(nil))
|
window.SetFramebufferSizeCallback(glfw.ToFramebufferSizeCallback(nil))
|
||||||
close(u.framebufferSizeCallbackCh)
|
close(u.framebufferSizeCallbackCh)
|
||||||
u.framebufferSizeCallbackCh = nil
|
u.framebufferSizeCallbackCh = nil
|
||||||
}
|
}
|
||||||
@ -1343,7 +1344,7 @@ func (u *UserInterface) setWindowSizeInDIPImpl(width, height int, fullscreen boo
|
|||||||
if oldW != newW || oldH != newH {
|
if oldW != newW || oldH != newH {
|
||||||
// Just after SetSize, GetSize is not reliable especially on Linux/UNIX.
|
// Just after SetSize, GetSize is not reliable especially on Linux/UNIX.
|
||||||
// Let's wait for FramebufferSize callback in any cases.
|
// Let's wait for FramebufferSize callback in any cases.
|
||||||
u.waitForFramebufferSizeCallback(func() {
|
u.waitForFramebufferSizeCallback(u.window, func() {
|
||||||
u.window.SetSize(newW, newH)
|
u.window.SetSize(newW, newH)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user