mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
internal/ui: move some context-dependent processes to updateFrameImpl
This is a preparation to introduce an independent thread for rendering. Updates #2512
This commit is contained in:
parent
b9fb4e9f50
commit
0fc21470e2
@ -108,6 +108,8 @@ type userInterfaceImpl struct {
|
|||||||
defaultFramebufferSizeCallback glfw.FramebufferSizeCallback
|
defaultFramebufferSizeCallback glfw.FramebufferSizeCallback
|
||||||
framebufferSizeCallbackCh chan struct{}
|
framebufferSizeCallbackCh chan struct{}
|
||||||
|
|
||||||
|
glContextSetOnce sync.Once
|
||||||
|
|
||||||
mainThread threadInterface
|
mainThread threadInterface
|
||||||
m sync.RWMutex
|
m sync.RWMutex
|
||||||
}
|
}
|
||||||
@ -568,7 +570,6 @@ func (u *userInterfaceImpl) SetFPSMode(mode FPSModeType) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
u.setFPSMode(mode)
|
u.setFPSMode(mode)
|
||||||
u.updateVsync()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -685,10 +686,6 @@ func (u *userInterfaceImpl) createWindow(width, height int) error {
|
|||||||
// Ensure to consume this callback.
|
// Ensure to consume this callback.
|
||||||
u.waitForFramebufferSizeCallback(u.window, nil)
|
u.waitForFramebufferSizeCallback(u.window, nil)
|
||||||
|
|
||||||
if u.graphicsDriver.IsGL() {
|
|
||||||
u.window.MakeContextCurrent()
|
|
||||||
}
|
|
||||||
|
|
||||||
u.window.SetInputMode(glfw.CursorMode, driverCursorModeToGLFWCursorMode(u.getInitCursorMode()))
|
u.window.SetInputMode(glfw.CursorMode, driverCursorModeToGLFWCursorMode(u.getInitCursorMode()))
|
||||||
u.window.SetCursor(glfwSystemCursors[u.getCursorShape()])
|
u.window.SetCursor(glfwSystemCursors[u.getCursorShape()])
|
||||||
u.window.SetTitle(u.title)
|
u.window.SetTitle(u.title)
|
||||||
@ -979,10 +976,6 @@ func (u *userInterfaceImpl) update() (float64, float64, error) {
|
|||||||
u.setFPSMode(u.fpsMode)
|
u.setFPSMode(u.fpsMode)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Call updateVsync even though fpsMode is not updated.
|
|
||||||
// When toggling to fullscreen, vsync state might be reset unexpectedly (#1787).
|
|
||||||
u.updateVsync()
|
|
||||||
|
|
||||||
if u.fpsMode != FPSModeVsyncOffMinimum {
|
if u.fpsMode != FPSModeVsyncOffMinimum {
|
||||||
// TODO: Updating the input can be skipped when clock.Update returns 0 (#1367).
|
// TODO: Updating the input can be skipped when clock.Update returns 0 (#1367).
|
||||||
glfw.PollEvents()
|
glfw.PollEvents()
|
||||||
@ -1032,16 +1025,26 @@ func (u *userInterfaceImpl) updateGame() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u.glContextSetOnce.Do(func() {
|
||||||
|
u.mainThread.Call(func() {
|
||||||
|
if u.graphicsDriver.IsGL() {
|
||||||
|
u.window.MakeContextCurrent()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
if err := u.context.updateFrame(u.graphicsDriver, outsideWidth, outsideHeight, deviceScaleFactor, u); err != nil {
|
if err := u.context.updateFrame(u.graphicsDriver, outsideWidth, outsideHeight, deviceScaleFactor, u); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// swapBuffers also checks IsGL, so this condition is redundant.
|
u.mainThread.Call(func() {
|
||||||
// However, (*thread).Call is not good for performance due to channels.
|
// Call updateVsync even though fpsMode is not updated.
|
||||||
// Let's avoid this whenever possible (#1367).
|
// When toggling to fullscreen, vsync state might be reset unexpectedly (#1787).
|
||||||
if u.graphicsDriver.IsGL() {
|
u.updateVsync()
|
||||||
u.mainThread.Call(u.swapBuffers)
|
|
||||||
}
|
// This works only for OpenGL.
|
||||||
|
u.swapBuffers()
|
||||||
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user