ui: Update GraphicsContext every frame (#490)

This commit is contained in:
Hajime Hoshi 2018-02-02 02:08:03 +09:00
parent 484d9797a3
commit 8b2ed6cddd
3 changed files with 44 additions and 26 deletions

View File

@ -422,6 +422,23 @@ func (u *userInterface) pollEvents() {
currentInput.update(u.window, u.getScale()*glfwScale())
}
func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
actualScale := 0.0
sizeChanged := false
_ = u.runOnMainThread(func() error {
if !u.sizeChanged {
return nil
}
u.sizeChanged = false
actualScale = u.actualScreenScale()
sizeChanged = true
return nil
})
if sizeChanged {
g.SetSize(u.width, u.height, actualScale)
}
}
func (u *userInterface) update(g GraphicsContext) error {
shouldClose := false
_ = u.runOnMainThread(func() error {
@ -441,20 +458,8 @@ func (u *userInterface) update(g GraphicsContext) error {
return nil
})
actualScale := 0.0
sizeChanged := false
_ = u.runOnMainThread(func() error {
if !u.sizeChanged {
return nil
}
u.sizeChanged = false
actualScale = u.actualScreenScale()
sizeChanged = true
return nil
})
if sizeChanged {
g.SetSize(u.width, u.height, actualScale)
}
// This call is needed for initialization.
u.updateGraphicsContext(g)
_ = u.runOnMainThread(func() error {
u.pollEvents()
@ -470,6 +475,8 @@ func (u *userInterface) update(g GraphicsContext) error {
})
if err := g.Update(func() {
currentInput.runeBuffer = currentInput.runeBuffer[:0]
// The offscreens must be updated every frame (#490).
u.updateGraphicsContext(g)
}); err != nil {
return err
}

View File

@ -123,6 +123,13 @@ func (u *userInterface) actualScreenScale() float64 {
return u.getScale() * devicescale.DeviceScale()
}
func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
if u.sizeChanged {
u.sizeChanged = false
g.SetSize(u.width, u.height, u.actualScreenScale())
}
}
func (u *userInterface) update(g GraphicsContext) error {
if !u.runnableInBackground && !u.windowFocus {
return nil
@ -132,13 +139,11 @@ func (u *userInterface) update(g GraphicsContext) error {
g.Invalidate()
}
currentInput.updateGamepads()
if u.sizeChanged {
u.sizeChanged = false
g.SetSize(u.width, u.height, u.actualScreenScale())
return nil
}
u.updateGraphicsContext(g)
if err := g.Update(func() {
currentInput.runeBuffer = nil
// The offscreens must be updated every frame (#490).
u.updateGraphicsContext(g)
}); err != nil {
return err
}

View File

@ -82,12 +82,7 @@ func Run(width, height int, scale float64, title string, g GraphicsContext) erro
}
}
func (u *userInterface) update(g GraphicsContext) error {
<-chRender
defer func() {
chRenderEnd <- struct{}{}
}()
func (u *userInterface) updateGraphicsContext(g GraphicsContext) {
sizeChanged := false
width, height := 0, 0
actualScale := 0.0
@ -106,8 +101,19 @@ func (u *userInterface) update(g GraphicsContext) error {
// Sizing also calls GL functions
g.SetSize(width, height, actualScale)
}
}
if err := g.Update(func() {}); err != nil {
func (u *userInterface) update(g GraphicsContext) error {
<-chRender
defer func() {
chRenderEnd <- struct{}{}
}()
u.updateGraphicsContext(g)
if err := g.Update(func() {
u.updateGraphicsContext(g)
}); err != nil {
return err
}
return nil