android: Bug fix: Black flicking (#226)

This commit is contained in:
Hajime Hoshi 2016-06-07 02:24:36 +09:00
parent 9757319848
commit 83a96dc532
6 changed files with 25 additions and 4 deletions

View File

@ -75,7 +75,6 @@ func (c *graphicsContext) Update() error {
if IsRunningSlowly() { if IsRunningSlowly() {
return nil return nil
} }
// TODO: In WebGL, we don't need to clear the image here.
if err := c.defaultRenderTarget.Clear(); err != nil { if err := c.defaultRenderTarget.Clear(); err != nil {
return err return err
} }

View File

@ -62,6 +62,8 @@ func (q *commandQueue) Flush(context *opengl.Context) error {
return err return err
} }
} }
// Call glFlush to prevent black flicking (especially on Android (#226)).
context.Flush()
q.commands = []command{} q.commands = []command{}
return nil return nil
} }
@ -103,7 +105,6 @@ func (c *drawImageCommand) Exec(context *opengl.Context) error {
if n == 0 { if n == 0 {
return nil return nil
} }
p := programContext{ p := programContext{
state: &theOpenGLState, state: &theOpenGLState,
program: theOpenGLState.programTexture, program: theOpenGLState.programTexture,

View File

@ -454,3 +454,10 @@ func (c *Context) DrawElements(mode Mode, len int, offsetInBytes int) {
return nil return nil
}) })
} }
func (c *Context) Flush() {
c.RunOnContextThread(func() error {
gl.Flush()
return nil
})
}

View File

@ -370,3 +370,8 @@ func (c *Context) DrawElements(mode Mode, len int, offsetInBytes int) {
gl := c.gl gl := c.gl
gl.DrawElements(int(mode), len, gl.UNSIGNED_SHORT, offsetInBytes) gl.DrawElements(int(mode), len, gl.UNSIGNED_SHORT, offsetInBytes)
} }
func (c *Context) Flush() {
gl := c.gl
gl.Flush()
}

View File

@ -373,3 +373,8 @@ func (c *Context) DrawElements(mode Mode, len int, offsetInBytes int) {
gl := c.gl gl := c.gl
gl.DrawElements(mgl.Enum(mode), len, mgl.UNSIGNED_SHORT, offsetInBytes) gl.DrawElements(mgl.Enum(mode), len, mgl.UNSIGNED_SHORT, offsetInBytes)
} }
func (c *Context) Flush() {
gl := c.gl
gl.Flush()
}

View File

@ -44,8 +44,12 @@ loop:
return err return err
case <-worker.WorkAvailable(): case <-worker.WorkAvailable():
worker.DoWork() worker.DoWork()
default:
select {
case <-chRenderEnd: case <-chRenderEnd:
break loop break loop
default:
}
} }
} }
return nil return nil