mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +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
|
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 {
|
func (c *Context) Reset() error {
|
||||||
c.locationCache = newLocationCache()
|
c.locationCache = newLocationCache()
|
||||||
c.lastFramebuffer = invalidFramebuffer
|
c.lastFramebuffer = invalidFramebuffer
|
||||||
@ -85,10 +105,6 @@ func (c *Context) Reset() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Context) Worker() mgl.Worker {
|
|
||||||
return c.worker
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *Context) BlendFunc(mode CompositeMode) {
|
func (c *Context) BlendFunc(mode CompositeMode) {
|
||||||
gl := c.gl
|
gl := c.gl
|
||||||
if c.lastCompositeMode == mode {
|
if c.lastCompositeMode == mode {
|
||||||
|
@ -42,34 +42,13 @@ 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 chRender <- struct{}{}:
|
case chRender <- struct{}{}:
|
||||||
return doGLWorks(chError, chRenderEnd)
|
return glContext.DoWork(chError, chRenderEnd)
|
||||||
case <-time.After(500 * time.Millisecond):
|
case <-time.After(500 * time.Millisecond):
|
||||||
// This function must not be blocked. We need to break for timeout.
|
// This function must not be blocked. We need to break for timeout.
|
||||||
return nil
|
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 {
|
type userInterface struct {
|
||||||
width int
|
width int
|
||||||
height int
|
height int
|
||||||
|
Loading…
Reference in New Issue
Block a user