mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 20:42:07 +01:00
shareable: Remove InitializeGraphicsDriverState
This commit is contained in:
parent
3960a4bbdf
commit
b53279b1e1
@ -145,6 +145,7 @@ var (
|
|||||||
backendsM sync.Mutex
|
backendsM sync.Mutex
|
||||||
|
|
||||||
backendsOnce sync.Once
|
backendsOnce sync.Once
|
||||||
|
initOnce sync.Once
|
||||||
|
|
||||||
// theBackends is a set of actually shared images.
|
// theBackends is a set of actually shared images.
|
||||||
theBackends = []*backend{}
|
theBackends = []*backend{}
|
||||||
@ -583,12 +584,6 @@ func NewScreenFramebufferImage(width, height int) *Image {
|
|||||||
return i
|
return i
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitializeGraphicsDriverState() error {
|
|
||||||
backendsM.Lock()
|
|
||||||
defer backendsM.Unlock()
|
|
||||||
return restorable.InitializeGraphicsDriverState()
|
|
||||||
}
|
|
||||||
|
|
||||||
func EndFrame() error {
|
func EndFrame() error {
|
||||||
backendsM.Lock()
|
backendsM.Lock()
|
||||||
restorable.ResolveStaleImages()
|
restorable.ResolveStaleImages()
|
||||||
@ -613,6 +608,15 @@ func BeginFrame() error {
|
|||||||
backendsM.Unlock()
|
backendsM.Unlock()
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
initOnce.Do(func() {
|
||||||
|
err = restorable.InitializeGraphicsDriverState()
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return restorable.RestoreIfNeeded()
|
return restorable.RestoreIfNeeded()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
14
uicontext.go
14
uicontext.go
@ -46,7 +46,6 @@ type uiContext struct {
|
|||||||
screenWidth int
|
screenWidth int
|
||||||
screenHeight int
|
screenHeight int
|
||||||
screenScale float64
|
screenScale float64
|
||||||
initialized bool
|
|
||||||
offsetX float64
|
offsetX float64
|
||||||
offsetY float64
|
offsetY float64
|
||||||
}
|
}
|
||||||
@ -75,25 +74,12 @@ func (c *uiContext) SetSize(screenWidth, screenHeight int, screenScale float64)
|
|||||||
c.offsetY = py0
|
c.offsetY = py0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *uiContext) initializeIfNeeded() error {
|
|
||||||
if !c.initialized {
|
|
||||||
if err := shareable.InitializeGraphicsDriverState(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
c.initialized = true
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *uiContext) Update(afterFrameUpdate func()) error {
|
func (c *uiContext) Update(afterFrameUpdate func()) error {
|
||||||
tps := int(MaxTPS())
|
tps := int(MaxTPS())
|
||||||
updateCount := clock.Update(tps)
|
updateCount := clock.Update(tps)
|
||||||
|
|
||||||
// TODO: If updateCount is 0 and vsync is disabled, swapping buffers can be skipped.
|
// TODO: If updateCount is 0 and vsync is disabled, swapping buffers can be skipped.
|
||||||
|
|
||||||
if err := c.initializeIfNeeded(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if err := shareable.BeginFrame(); err != nil {
|
if err := shareable.BeginFrame(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user