mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-26 03:38:55 +01:00
internal/ui: show window after first draw on glfw (#2875)
Fixes #2725 by avoiding the flash in the first place. Showing the window this way was already default on macOS; This makes it default for all glfw platforms. Closes #2725
This commit is contained in:
parent
338b8957e8
commit
5774cf808f
@ -104,6 +104,7 @@ type userInterfaceImpl struct {
|
|||||||
framebufferSizeCallbackCh chan struct{}
|
framebufferSizeCallbackCh chan struct{}
|
||||||
|
|
||||||
darwinInitOnce sync.Once
|
darwinInitOnce sync.Once
|
||||||
|
showWindowOnce sync.Once
|
||||||
bufferOnceSwappedOnce sync.Once
|
bufferOnceSwappedOnce sync.Once
|
||||||
|
|
||||||
m sync.RWMutex
|
m sync.RWMutex
|
||||||
@ -1077,6 +1078,11 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Window is shown after the first buffer swap.
|
||||||
|
if err := glfw.WindowHint(glfw.Visible, glfw.False); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// On macOS, window decoration should be initialized once after buffers are swapped (#2600).
|
// On macOS, window decoration should be initialized once after buffers are swapped (#2600).
|
||||||
if runtime.GOOS != "darwin" {
|
if runtime.GOOS != "darwin" {
|
||||||
decorated := glfw.False
|
decorated := glfw.False
|
||||||
@ -1170,13 +1176,6 @@ func (u *UserInterface) initOnMainThread(options *RunOptions) error {
|
|||||||
_ = u.skipTaskbar()
|
_ = u.skipTaskbar()
|
||||||
}
|
}
|
||||||
|
|
||||||
// On macOS, the window is shown once after buffers are swapped at update.
|
|
||||||
if runtime.GOOS != "darwin" {
|
|
||||||
if err := u.window.Show(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
switch g := u.graphicsDriver.(type) {
|
switch g := u.graphicsDriver.(type) {
|
||||||
case interface{ SetGLFWWindow(window *glfw.Window) }:
|
case interface{ SetGLFWWindow(window *glfw.Window) }:
|
||||||
g.SetGLFWWindow(u.window)
|
g.SetGLFWWindow(u.window)
|
||||||
@ -1321,8 +1320,16 @@ func (u *UserInterface) update() (float64, float64, error) {
|
|||||||
if err = u.window.SetAttrib(glfw.Decorated, decorated); err != nil {
|
if err = u.window.SetAttrib(glfw.Decorated, decorated); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return 0, 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// The window is not shown at the initialization on macOS. Show the window here.
|
if u.bufferOnceSwapped {
|
||||||
|
var err error
|
||||||
|
u.showWindowOnce.Do(func() {
|
||||||
|
// Show the window after first buffer swap to avoid flash of white especially on Windows.
|
||||||
if err = u.window.Show(); err != nil {
|
if err = u.window.Show(); err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user