mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-11 19:48:54 +01:00
graphics: Remove 'Resume'
This commit is contained in:
parent
5fbbb6dc6a
commit
a1fbf2cd2d
@ -16,6 +16,7 @@ package ebiten
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/hajimehoshi/ebiten/internal/graphics"
|
"github.com/hajimehoshi/ebiten/internal/graphics"
|
||||||
|
"github.com/hajimehoshi/ebiten/internal/graphics/opengl"
|
||||||
"github.com/hajimehoshi/ebiten/internal/ui"
|
"github.com/hajimehoshi/ebiten/internal/ui"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -54,6 +55,16 @@ func (c *graphicsContext) SetSize(screenWidth, screenHeight, screenScale int) er
|
|||||||
return nil
|
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 {
|
func (c *graphicsContext) Update() error {
|
||||||
if !c.initialized {
|
if !c.initialized {
|
||||||
if err := graphics.Initialize(ui.GLContext()); err != nil {
|
if err := graphics.Initialize(ui.GLContext()); err != nil {
|
||||||
@ -61,6 +72,15 @@ func (c *graphicsContext) Update() error {
|
|||||||
}
|
}
|
||||||
c.initialized = true
|
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 {
|
if err := c.screen.Clear(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -104,7 +124,7 @@ func (c *graphicsContext) flush() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *graphicsContext) Resume() error {
|
func (c *graphicsContext) restore() error {
|
||||||
imageM.Lock()
|
imageM.Lock()
|
||||||
defer imageM.Unlock()
|
defer imageM.Unlock()
|
||||||
ui.GLContext().Resume()
|
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)
|
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.
|
// A DrawImageOptions represents options to render an image on an image.
|
||||||
type DrawImageOptions struct {
|
type DrawImageOptions struct {
|
||||||
ImageParts ImageParts
|
ImageParts ImageParts
|
||||||
|
@ -107,3 +107,7 @@ func (i *Image) ReplacePixels(p []uint8) error {
|
|||||||
theCommandQueue.Enqueue(c)
|
theCommandQueue.Enqueue(c)
|
||||||
return nil
|
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) {
|
func (c *Context) TexSubImage2D(p []uint8, width, height int) {
|
||||||
c.RunOnContextThread(func() error {
|
c.RunOnContextThread(func() error {
|
||||||
gl.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p))
|
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)
|
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) {
|
func (c *Context) TexSubImage2D(p []uint8, width, height int) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
// 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))
|
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) {
|
func (c *Context) TexSubImage2D(p []uint8, width, height int) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
gl.TexSubImage2D(mgl.TEXTURE_2D, 0, 0, 0, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, p)
|
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 {
|
type GraphicsContext interface {
|
||||||
SetSize(width, height, scale int) error
|
SetSize(width, height, scale int) error
|
||||||
Update() error
|
Update() error
|
||||||
Resume() error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Run(g GraphicsContext, width, height, scale int, title string, fps int) 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
|
frames = 0
|
||||||
}
|
}
|
||||||
e.Done <- struct{}{}
|
e.Done <- struct{}{}
|
||||||
case ui.ResumeEvent:
|
|
||||||
if err := g.Resume(); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
e.Done <- struct{}{}
|
|
||||||
default:
|
default:
|
||||||
panic("not reach")
|
panic("not reach")
|
||||||
}
|
}
|
||||||
|
@ -27,11 +27,3 @@ type ScreenSizeEvent struct {
|
|||||||
type RenderEvent struct {
|
type RenderEvent struct {
|
||||||
Done chan 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
|
// TODO: Check this is called on the rendering thread
|
||||||
select {
|
select {
|
||||||
case <-chResumeStart:
|
|
||||||
if err := doGLWorks(chError, chResumeEnd); err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
case chRender <- struct{}{}:
|
case chRender <- struct{}{}:
|
||||||
return doGLWorks(chError, chRenderEnd)
|
return doGLWorks(chError, chRenderEnd)
|
||||||
case <-time.After(500 * time.Millisecond):
|
case <-time.After(500 * time.Millisecond):
|
||||||
@ -81,9 +76,6 @@ type userInterface struct {
|
|||||||
var (
|
var (
|
||||||
chRender = make(chan struct{})
|
chRender = make(chan struct{})
|
||||||
chRenderEnd = make(chan struct{})
|
chRenderEnd = make(chan struct{})
|
||||||
chResume = make(chan struct{})
|
|
||||||
chResumeStart = make(chan struct{})
|
|
||||||
chResumeEnd = make(chan struct{})
|
|
||||||
currentUI = &userInterface{
|
currentUI = &userInterface{
|
||||||
sizeChanged: true,
|
sizeChanged: true,
|
||||||
}
|
}
|
||||||
@ -117,13 +109,8 @@ func (u *userInterface) Update() (interface{}, error) {
|
|||||||
}
|
}
|
||||||
return e, nil
|
return e, nil
|
||||||
}
|
}
|
||||||
select {
|
<-chRender
|
||||||
case <-chRender:
|
|
||||||
return RenderEvent{chRenderEnd}, nil
|
return RenderEvent{chRenderEnd}, nil
|
||||||
case <-chResume:
|
|
||||||
chResumeStart <- struct{}{}
|
|
||||||
return ResumeEvent{chResumeEnd}, nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u *userInterface) SwapBuffers() error {
|
func (u *userInterface) SwapBuffers() error {
|
||||||
@ -148,16 +135,6 @@ func (u *userInterface) actualScreenScale() int {
|
|||||||
return u.scale
|
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) {
|
func UpdateTouches(touches []Touch) {
|
||||||
currentInput.updateTouches(touches)
|
currentInput.updateTouches(touches)
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,6 @@ type EventDispatcher interface {
|
|||||||
SetScreenSize(width, height int)
|
SetScreenSize(width, height int)
|
||||||
SetScreenScale(scale int)
|
SetScreenScale(scale int)
|
||||||
Render() error
|
Render() error
|
||||||
Resume()
|
|
||||||
TouchDown(id int, x, y int)
|
TouchDown(id int, x, y int)
|
||||||
TouchMove(id int, x, y int)
|
TouchMove(id int, x, y int)
|
||||||
TouchUp(id int)
|
TouchUp(id int)
|
||||||
@ -69,10 +68,6 @@ func (e *eventDispatcher) Render() error {
|
|||||||
return ui.Render(chError)
|
return ui.Render(chError)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *eventDispatcher) Resume() {
|
|
||||||
ui.Resume()
|
|
||||||
}
|
|
||||||
|
|
||||||
// touch implements ui.Touch.
|
// touch implements ui.Touch.
|
||||||
type touch struct {
|
type touch struct {
|
||||||
id int
|
id int
|
||||||
|
Loading…
Reference in New Issue
Block a user