From 841353670f31794f0cc65337a9a47844c5cb88a6 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Fri, 2 Nov 2018 03:43:42 +0900 Subject: [PATCH] opengl: Unexport BindTexture --- internal/graphicscommand/command.go | 3 +-- internal/opengl/context.go | 2 +- internal/opengl/context_desktop.go | 5 +++-- internal/opengl/context_js.go | 5 +++-- internal/opengl/context_mobile.go | 5 +++-- internal/opengl/program.go | 2 +- 6 files changed, 12 insertions(+), 10 deletions(-) diff --git a/internal/graphicscommand/command.go b/internal/graphicscommand/command.go index 8952e1635..d9adba4d9 100644 --- a/internal/graphicscommand/command.go +++ b/internal/graphicscommand/command.go @@ -311,8 +311,7 @@ func (c *replacePixelsCommand) Exec(indexOffsetInBytes int) error { // glFlush is necessary on Android. // glTexSubImage2D didn't work without this hack at least on Nexus 5x and NuAns NEO [Reloaded] (#211). opengl.GetContext().Flush() - opengl.GetContext().BindTexture(c.dst.texture) - opengl.GetContext().TexSubImage2D(c.pixels, c.x, c.y, c.width, c.height) + opengl.GetContext().TexSubImage2D(c.dst.texture, c.pixels, c.x, c.y, c.width, c.height) return nil } diff --git a/internal/opengl/context.go b/internal/opengl/context.go index f88c5638a..7de459750 100644 --- a/internal/opengl/context.go +++ b/internal/opengl/context.go @@ -80,7 +80,7 @@ func GetContext() *Context { return theContext } -func (c *Context) BindTexture(t Texture) { +func (c *Context) bindTexture(t Texture) { if c.lastTexture == t { return } diff --git a/internal/opengl/context_desktop.go b/internal/opengl/context_desktop.go index 78bd64b61..6d97b84af 100644 --- a/internal/opengl/context_desktop.go +++ b/internal/opengl/context_desktop.go @@ -150,7 +150,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) { }); err != nil { return 0, err } - c.BindTexture(texture) + c.bindTexture(texture) _ = c.runOnContextThread(func() error { gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) @@ -220,7 +220,8 @@ func (c *Context) IsTexture(t Texture) bool { return r } -func (c *Context) TexSubImage2D(p []byte, x, y, width, height int) { +func (c *Context) TexSubImage2D(t Texture, p []byte, x, y, width, height int) { + c.bindTexture(t) _ = c.runOnContextThread(func() error { gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(x), int32(y), int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p)) return nil diff --git a/internal/opengl/context_js.go b/internal/opengl/context_js.go index 077362c59..519d6e159 100644 --- a/internal/opengl/context_js.go +++ b/internal/opengl/context_js.go @@ -180,7 +180,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) { return Texture(js.Null()), errors.New("opengl: glGenTexture failed") } gl.Call("pixelStorei", unpackAlignment, 4) - c.BindTexture(Texture(t)) + c.bindTexture(Texture(t)) gl.Call("texParameteri", texture2d, textureMagFilter, nearest) gl.Call("texParameteri", texture2d, textureMinFilter, nearest) @@ -241,7 +241,8 @@ func (c *Context) IsTexture(t Texture) bool { return gl.Call("isTexture", js.Value(t)).Bool() } -func (c *Context) TexSubImage2D(pixels []byte, x, y, width, height int) { +func (c *Context) TexSubImage2D(t Texture, pixels []byte, x, y, width, height int) { + c.bindTexture(t) gl := c.gl // void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, // GLsizei width, GLsizei height, diff --git a/internal/opengl/context_mobile.go b/internal/opengl/context_mobile.go index 251b7e7c0..f7d5026d4 100644 --- a/internal/opengl/context_mobile.go +++ b/internal/opengl/context_mobile.go @@ -140,7 +140,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) { return Texture{}, errors.New("opengl: creating texture failed") } gl.PixelStorei(mgl.UNPACK_ALIGNMENT, 4) - c.BindTexture(Texture(t)) + c.bindTexture(Texture(t)) gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MAG_FILTER, mgl.NEAREST) gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MIN_FILTER, mgl.NEAREST) @@ -191,7 +191,8 @@ func (c *Context) IsTexture(t Texture) bool { return gl.IsTexture(mgl.Texture(t)) } -func (c *Context) TexSubImage2D(p []byte, x, y, width, height int) { +func (c *Context) TexSubImage2D(t Texture, p []byte, x, y, width, height int) { + c.bindTexture(t) gl := c.gl gl.TexSubImage2D(mgl.TEXTURE_2D, 0, x, y, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, p) } diff --git a/internal/opengl/program.go b/internal/opengl/program.go index c01f12614..77b08040d 100644 --- a/internal/opengl/program.go +++ b/internal/opengl/program.go @@ -352,5 +352,5 @@ func (s *openGLState) useProgram(proj []float32, texture Texture, dstW, dstH, sr // We don't have to call gl.ActiveTexture here: GL_TEXTURE0 is the default active texture // See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml - c.BindTexture(texture) + c.bindTexture(texture) }