From 0c611d875b2fc1bb0ec726f897a3648f0af41d72 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sun, 10 Jul 2016 05:59:21 +0900 Subject: [PATCH] graphics: Bug fix: glTexSubImage2D on Android now works (#211) --- image.go | 2 -- internal/graphics/command.go | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/image.go b/image.go index c8bea2cc0..665a2bef8 100644 --- a/image.go +++ b/image.go @@ -182,8 +182,6 @@ func (i *Image) Dispose() error { // This function may be slow (as for implementation, this calls glTexSubImage2D). // // This function is concurrent-safe. -// -// BUG(hajimehoshi) ReplacePixels might not work on Android (#211). func (i *Image) ReplacePixels(p []uint8) error { return i.impl.ReplacePixels(p) } diff --git a/internal/graphics/command.go b/internal/graphics/command.go index dae275ed7..06ba84d49 100644 --- a/internal/graphics/command.go +++ b/internal/graphics/command.go @@ -157,6 +157,10 @@ func (c *replacePixelsCommand) Exec(context *opengl.Context) error { if err := context.FillFramebuffer(0, 0, 0.5, 1); err != nil { return err } + // This is necessary on Android. We can't call glClear just before glTexSubImage2D without + // glFlush. glTexSubImage2D didn't work without this hack at least on Nexus 5x (#211). + // TODO: Can we have a better way like optimizing commands? + context.Flush() context.BindTexture(c.dst.texture.native) context.TexSubImage2D(c.pixels, c.dst.width, c.dst.height) return nil