mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 10:48:53 +01:00
opengl: Add context.DoWork (mobile)
This commit is contained in:
parent
61ba8dad17
commit
55bfe19bf8
@ -71,6 +71,26 @@ func NewContext() (*Context, error) {
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *Context) DoWork(chError <-chan error, chDone <-chan struct{}) error {
|
||||
// TODO: Check this is called on the rendering thread
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case err := <-chError:
|
||||
return err
|
||||
case <-c.worker.WorkAvailable():
|
||||
c.worker.DoWork()
|
||||
default:
|
||||
select {
|
||||
case <-chDone:
|
||||
break loop
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Context) Reset() error {
|
||||
c.locationCache = newLocationCache()
|
||||
c.lastFramebuffer = invalidFramebuffer
|
||||
@ -85,10 +105,6 @@ func (c *Context) Reset() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Context) Worker() mgl.Worker {
|
||||
return c.worker
|
||||
}
|
||||
|
||||
func (c *Context) BlendFunc(mode CompositeMode) {
|
||||
gl := c.gl
|
||||
if c.lastCompositeMode == mode {
|
||||
|
@ -42,34 +42,13 @@ func Render(chError <-chan error) error {
|
||||
// TODO: Check this is called on the rendering thread
|
||||
select {
|
||||
case chRender <- struct{}{}:
|
||||
return doGLWorks(chError, chRenderEnd)
|
||||
return glContext.DoWork(chError, chRenderEnd)
|
||||
case <-time.After(500 * time.Millisecond):
|
||||
// This function must not be blocked. We need to break for timeout.
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
func doGLWorks(chError <-chan error, chDone <-chan struct{}) error {
|
||||
// TODO: Check this is called on the rendering thread
|
||||
worker := glContext.Worker()
|
||||
loop:
|
||||
for {
|
||||
select {
|
||||
case err := <-chError:
|
||||
return err
|
||||
case <-worker.WorkAvailable():
|
||||
worker.DoWork()
|
||||
default:
|
||||
select {
|
||||
case <-chDone:
|
||||
break loop
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type userInterface struct {
|
||||
width int
|
||||
height int
|
||||
|
Loading…
Reference in New Issue
Block a user