mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Remove 'Resume'
This commit is contained in:
parent
5fbbb6dc6a
commit
a1fbf2cd2d
@ -16,6 +16,7 @@ package ebiten
|
||||
|
||||
import (
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||
)
|
||||
|
||||
@ -54,6 +55,16 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight, screenScale int) er
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *graphicsContext) needsRestoring(context *opengl.Context) (bool, error) {
|
||||
imageM.Lock()
|
||||
defer imageM.Unlock()
|
||||
// FlushCommands is required because c.screen.impl might not have an actual texture.
|
||||
if err := graphics.FlushCommands(ui.GLContext()); err != nil {
|
||||
return false, err
|
||||
}
|
||||
return c.screen.impl.isInvalidated(context), nil
|
||||
}
|
||||
|
||||
func (c *graphicsContext) Update() error {
|
||||
if !c.initialized {
|
||||
if err := graphics.Initialize(ui.GLContext()); err != nil {
|
||||
@ -61,6 +72,15 @@ func (c *graphicsContext) Update() error {
|
||||
}
|
||||
c.initialized = true
|
||||
}
|
||||
r, err := c.needsRestoring(ui.GLContext())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if r {
|
||||
if err := c.restore(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := c.screen.Clear(); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -104,7 +124,7 @@ func (c *graphicsContext) flush() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *graphicsContext) Resume() error {
|
||||
func (c *graphicsContext) restore() error {
|
||||
imageM.Lock()
|
||||
defer imageM.Unlock()
|
||||
ui.GLContext().Resume()
|
||||
|
4
image.go
4
image.go
@ -347,6 +347,10 @@ func (i *imageImpl) ReplacePixels(p []uint8) error {
|
||||
return i.image.ReplacePixels(p)
|
||||
}
|
||||
|
||||
func (i *imageImpl) isInvalidated(context *opengl.Context) bool {
|
||||
return i.image.IsInvalidated(context)
|
||||
}
|
||||
|
||||
// A DrawImageOptions represents options to render an image on an image.
|
||||
type DrawImageOptions struct {
|
||||
ImageParts ImageParts
|
||||
|
@ -107,3 +107,7 @@ func (i *Image) ReplacePixels(p []uint8) error {
|
||||
theCommandQueue.Enqueue(c)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (i *Image) IsInvalidated(context *opengl.Context) bool {
|
||||
return !context.IsTexture(i.texture.native)
|
||||
}
|
||||
|
@ -195,6 +195,15 @@ func (c *Context) DeleteTexture(t Texture) {
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Context) IsTexture(t Texture) bool {
|
||||
r := false
|
||||
c.RunOnContextThread(func() error {
|
||||
r = gl.IsTexture(uint32(t))
|
||||
return nil
|
||||
})
|
||||
return r
|
||||
}
|
||||
|
||||
func (c *Context) TexSubImage2D(p []uint8, width, height int) {
|
||||
c.RunOnContextThread(func() error {
|
||||
gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p))
|
||||
|
@ -196,6 +196,11 @@ func (c *Context) DeleteTexture(t Texture) {
|
||||
gl.DeleteTexture(t.Object)
|
||||
}
|
||||
|
||||
func (c *Context) IsTexture(t Texture) bool {
|
||||
gl := c.gl
|
||||
return gl.IsTexture(t.Object)
|
||||
}
|
||||
|
||||
func (c *Context) TexSubImage2D(p []uint8, width, height int) {
|
||||
gl := c.gl
|
||||
// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
|
@ -162,6 +162,11 @@ func (c *Context) DeleteTexture(t Texture) {
|
||||
gl.DeleteTexture(mgl.Texture(t))
|
||||
}
|
||||
|
||||
func (c *Context) IsTexture(t Texture) bool {
|
||||
gl := c.gl
|
||||
return gl.IsTexture(mgl.Texture(t))
|
||||
}
|
||||
|
||||
func (c *Context) TexSubImage2D(p []uint8, width, height int) {
|
||||
gl := c.gl
|
||||
gl.TexSubImage2D(mgl.TEXTURE_2D, 0, 0, 0, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, p)
|
||||
|
@ -96,7 +96,6 @@ func (c *runContext) setRunningSlowly(isRunningSlowly bool) {
|
||||
type GraphicsContext interface {
|
||||
SetSize(width, height, scale int) error
|
||||
Update() error
|
||||
Resume() error
|
||||
}
|
||||
|
||||
func Run(g GraphicsContext, width, height, scale int, title string, fps int) error {
|
||||
@ -165,11 +164,6 @@ func Run(g GraphicsContext, width, height, scale int, title string, fps int) err
|
||||
frames = 0
|
||||
}
|
||||
e.Done <- struct{}{}
|
||||
case ui.ResumeEvent:
|
||||
if err := g.Resume(); err != nil {
|
||||
return err
|
||||
}
|
||||
e.Done <- struct{}{}
|
||||
default:
|
||||
panic("not reach")
|
||||
}
|
||||
|
@ -27,11 +27,3 @@ type ScreenSizeEvent struct {
|
||||
type RenderEvent struct {
|
||||
Done chan struct{}
|
||||
}
|
||||
|
||||
type PauseEvent struct {
|
||||
Done chan struct{}
|
||||
}
|
||||
|
||||
type ResumeEvent struct {
|
||||
Done chan struct{}
|
||||
}
|
||||
|
@ -37,11 +37,6 @@ func Render(chError <-chan error) error {
|
||||
}
|
||||
// TODO: Check this is called on the rendering thread
|
||||
select {
|
||||
case <-chResumeStart:
|
||||
if err := doGLWorks(chError, chResumeEnd); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
case chRender <- struct{}{}:
|
||||
return doGLWorks(chError, chRenderEnd)
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
@ -79,12 +74,9 @@ type userInterface struct {
|
||||
}
|
||||
|
||||
var (
|
||||
chRender = make(chan struct{})
|
||||
chRenderEnd = make(chan struct{})
|
||||
chResume = make(chan struct{})
|
||||
chResumeStart = make(chan struct{})
|
||||
chResumeEnd = make(chan struct{})
|
||||
currentUI = &userInterface{
|
||||
chRender = make(chan struct{})
|
||||
chRenderEnd = make(chan struct{})
|
||||
currentUI = &userInterface{
|
||||
sizeChanged: true,
|
||||
}
|
||||
)
|
||||
@ -117,13 +109,8 @@ func (u *userInterface) Update() (interface{}, error) {
|
||||
}
|
||||
return e, nil
|
||||
}
|
||||
select {
|
||||
case <-chRender:
|
||||
return RenderEvent{chRenderEnd}, nil
|
||||
case <-chResume:
|
||||
chResumeStart <- struct{}{}
|
||||
return ResumeEvent{chResumeEnd}, nil
|
||||
}
|
||||
<-chRender
|
||||
return RenderEvent{chRenderEnd}, nil
|
||||
}
|
||||
|
||||
func (u *userInterface) SwapBuffers() error {
|
||||
@ -148,16 +135,6 @@ func (u *userInterface) actualScreenScale() int {
|
||||
return u.scale
|
||||
}
|
||||
|
||||
// TODO: Remove Resume() and do resuming in Update instead.
|
||||
// In Update, we'd be able to detect GL context lost by glIsTexture or something,
|
||||
// and we can do resuming when detecting it.
|
||||
|
||||
func Resume() error {
|
||||
chResume <- struct{}{}
|
||||
// Don't have to wait for resumeing done.
|
||||
return nil
|
||||
}
|
||||
|
||||
func UpdateTouches(touches []Touch) {
|
||||
currentInput.updateTouches(touches)
|
||||
}
|
||||
|
@ -29,7 +29,6 @@ type EventDispatcher interface {
|
||||
SetScreenSize(width, height int)
|
||||
SetScreenScale(scale int)
|
||||
Render() error
|
||||
Resume()
|
||||
TouchDown(id int, x, y int)
|
||||
TouchMove(id int, x, y int)
|
||||
TouchUp(id int)
|
||||
@ -69,10 +68,6 @@ func (e *eventDispatcher) Render() error {
|
||||
return ui.Render(chError)
|
||||
}
|
||||
|
||||
func (e *eventDispatcher) Resume() {
|
||||
ui.Resume()
|
||||
}
|
||||
|
||||
// touch implements ui.Touch.
|
||||
type touch struct {
|
||||
id int
|
||||
|
Loading…
Reference in New Issue
Block a user