mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 11:18:54 +01:00
shareable: Remove InitializeGraphicsDriverState
This commit is contained in:
parent
3960a4bbdf
commit
b53279b1e1
@ -145,6 +145,7 @@ var (
|
||||
backendsM sync.Mutex
|
||||
|
||||
backendsOnce sync.Once
|
||||
initOnce sync.Once
|
||||
|
||||
// theBackends is a set of actually shared images.
|
||||
theBackends = []*backend{}
|
||||
@ -583,12 +584,6 @@ func NewScreenFramebufferImage(width, height int) *Image {
|
||||
return i
|
||||
}
|
||||
|
||||
func InitializeGraphicsDriverState() error {
|
||||
backendsM.Lock()
|
||||
defer backendsM.Unlock()
|
||||
return restorable.InitializeGraphicsDriverState()
|
||||
}
|
||||
|
||||
func EndFrame() error {
|
||||
backendsM.Lock()
|
||||
restorable.ResolveStaleImages()
|
||||
@ -613,6 +608,15 @@ func BeginFrame() error {
|
||||
backendsM.Unlock()
|
||||
}
|
||||
}()
|
||||
|
||||
var err error
|
||||
initOnce.Do(func() {
|
||||
err = restorable.InitializeGraphicsDriverState()
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return restorable.RestoreIfNeeded()
|
||||
}
|
||||
|
||||
|
14
uicontext.go
14
uicontext.go
@ -46,7 +46,6 @@ type uiContext struct {
|
||||
screenWidth int
|
||||
screenHeight int
|
||||
screenScale float64
|
||||
initialized bool
|
||||
offsetX float64
|
||||
offsetY float64
|
||||
}
|
||||
@ -75,25 +74,12 @@ func (c *uiContext) SetSize(screenWidth, screenHeight int, screenScale float64)
|
||||
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 {
|
||||
tps := int(MaxTPS())
|
||||
updateCount := clock.Update(tps)
|
||||
|
||||
// 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 {
|
||||
return err
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user