mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 01:42:05 +01:00
internal/atlas: split EndFrame into EndFrame and SwapBuffers
This enables to do something asynchronously while executing SwapBuffers in a different goroutine. This is a preparation for HandleInput. Updates #1704
This commit is contained in:
parent
f1999e5742
commit
b94c3fa9bb
@ -756,7 +756,7 @@ func (i *Image) DumpScreenshot(graphicsDriver graphicsdriver.Graphics, path stri
|
|||||||
return i.backend.restorable.Dump(graphicsDriver, path, blackbg, image.Rect(0, 0, i.width, i.height))
|
return i.backend.restorable.Dump(graphicsDriver, path, blackbg, image.Rect(0, 0, i.width, i.height))
|
||||||
}
|
}
|
||||||
|
|
||||||
func EndFrame(graphicsDriver graphicsdriver.Graphics, swapBuffersForGL func()) error {
|
func EndFrame() error {
|
||||||
backendsM.Lock()
|
backendsM.Lock()
|
||||||
defer backendsM.Unlock()
|
defer backendsM.Unlock()
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -767,10 +767,6 @@ func EndFrame(graphicsDriver graphicsdriver.Graphics, swapBuffersForGL func()) e
|
|||||||
panic("atlas: inFrame must be true in EndFrame")
|
panic("atlas: inFrame must be true in EndFrame")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := restorable.EndFrame(graphicsDriver, swapBuffersForGL); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, b := range theBackends {
|
for _, b := range theBackends {
|
||||||
b.sourceInThisFrame = false
|
b.sourceInThisFrame = false
|
||||||
}
|
}
|
||||||
@ -778,6 +774,22 @@ func EndFrame(graphicsDriver graphicsdriver.Graphics, swapBuffersForGL func()) e
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SwapBuffers(graphicsDriver graphicsdriver.Graphics, swapBuffersForGL func()) error {
|
||||||
|
func() {
|
||||||
|
backendsM.Lock()
|
||||||
|
defer backendsM.Unlock()
|
||||||
|
|
||||||
|
if inFrame {
|
||||||
|
panic("atlas: inFrame must be false in SwapBuffer")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
if err := restorable.SwapBuffers(graphicsDriver, swapBuffersForGL); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func floorPowerOf2(x int) int {
|
func floorPowerOf2(x int) int {
|
||||||
if x <= 0 {
|
if x <= 0 {
|
||||||
return 0
|
return 0
|
||||||
|
@ -33,14 +33,6 @@ type Image struct {
|
|||||||
pixels []byte
|
pixels []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
func BeginFrame(graphicsDriver graphicsdriver.Graphics) error {
|
|
||||||
return atlas.BeginFrame(graphicsDriver)
|
|
||||||
}
|
|
||||||
|
|
||||||
func EndFrame(graphicsDriver graphicsdriver.Graphics, swapBuffersForGL func()) error {
|
|
||||||
return atlas.EndFrame(graphicsDriver, swapBuffersForGL)
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewImage(width, height int, imageType atlas.ImageType) *Image {
|
func NewImage(width, height int, imageType atlas.ImageType) *Image {
|
||||||
return &Image{
|
return &Image{
|
||||||
width: width,
|
width: width,
|
||||||
|
@ -56,7 +56,7 @@ var theImages = &images{
|
|||||||
shaders: map[*Shader]struct{}{},
|
shaders: map[*Shader]struct{}{},
|
||||||
}
|
}
|
||||||
|
|
||||||
func EndFrame(graphicsDriver graphicsdriver.Graphics, swapBuffersForGL func()) error {
|
func SwapBuffers(graphicsDriver graphicsdriver.Graphics, swapBuffersForGL func()) error {
|
||||||
if debug.IsDebug {
|
if debug.IsDebug {
|
||||||
debug.Logf("Internal image sizes:\n")
|
debug.Logf("Internal image sizes:\n")
|
||||||
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
|
imgs := make([]*graphicscommand.Image, 0, len(theImages.images))
|
||||||
|
@ -19,7 +19,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
"github.com/hajimehoshi/ebiten/v2/internal/atlas"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/buffered"
|
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/clock"
|
"github.com/hajimehoshi/ebiten/v2/internal/clock"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
"github.com/hajimehoshi/ebiten/v2/internal/debug"
|
||||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
"github.com/hajimehoshi/ebiten/v2/internal/graphicsdriver"
|
||||||
@ -102,14 +101,9 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
|
|||||||
|
|
||||||
debug.Logf("----\n")
|
debug.Logf("----\n")
|
||||||
|
|
||||||
if err := buffered.BeginFrame(graphicsDriver); err != nil {
|
if err := atlas.BeginFrame(graphicsDriver); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
defer func() {
|
|
||||||
if err1 := buffered.EndFrame(graphicsDriver, swapBuffersForGL); err == nil && err1 != nil {
|
|
||||||
err = err1
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Flush deferred functions, like reading pixels from GPU.
|
// Flush deferred functions, like reading pixels from GPU.
|
||||||
if err := c.flushDeferredFuncs(ui); err != nil {
|
if err := c.flushDeferredFuncs(ui); err != nil {
|
||||||
@ -164,6 +158,14 @@ func (c *context) updateFrameImpl(graphicsDriver graphicsdriver.Graphics, update
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := atlas.EndFrame(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := atlas.SwapBuffers(graphicsDriver, swapBuffersForGL); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user