graphicsdriver/opengl: Reduce glFlush calls

Fixes #981
This commit is contained in:
Hajime Hoshi 2019-11-14 01:19:57 +09:00
parent c2eae69b47
commit 8c54cf639a
2 changed files with 8 additions and 1 deletions

View File

@ -32,6 +32,9 @@ func Get() *Driver {
type Driver struct {
state openGLState
context context
// drawCalled is true just after Draw is called. This holds true until ReplacePixels is called.
drawCalled bool
}
func (d *Driver) SetThread(thread *thread.Thread) {
@ -108,6 +111,7 @@ func (d *Driver) SetVertices(vertices []float32, indices []uint16) {
}
func (d *Driver) Draw(indexLen int, indexOffset int, mode driver.CompositeMode, colorM *affine.ColorM, filter driver.Filter, address driver.Address) error {
d.drawCalled = true
if err := d.useProgram(mode, colorM, filter, address); err != nil {
return err
}

View File

@ -92,7 +92,10 @@ func (i *Image) ReplacePixels(p []byte, x, y, width, height int) {
// glFlush is necessary on Android.
// glTexSubImage2D didn't work without this hack at least on Nexus 5x and NuAns NEO [Reloaded] (#211).
if i.driver.drawCalled {
i.driver.context.flush()
}
i.driver.drawCalled = false
i.driver.context.texSubImage2D(i.textureNative, p, x, y, width, height)
}