opengl: Add context.DoWork (mobile)

This commit is contained in:
Hajime Hoshi 2016-07-04 01:25:35 +09:00
parent 61ba8dad17
commit 55bfe19bf8
2 changed files with 21 additions and 26 deletions

View File

@ -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 {

View File

@ -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