opengl: Unexport BindTexture

This commit is contained in:
Hajime Hoshi 2018-11-02 03:43:42 +09:00
parent 6dceeb343c
commit 841353670f
6 changed files with 12 additions and 10 deletions

View File

@ -311,8 +311,7 @@ func (c *replacePixelsCommand) Exec(indexOffsetInBytes int) error {
// glFlush is necessary on Android. // glFlush is necessary on Android.
// glTexSubImage2D didn't work without this hack at least on Nexus 5x and NuAns NEO [Reloaded] (#211). // glTexSubImage2D didn't work without this hack at least on Nexus 5x and NuAns NEO [Reloaded] (#211).
opengl.GetContext().Flush() opengl.GetContext().Flush()
opengl.GetContext().BindTexture(c.dst.texture) opengl.GetContext().TexSubImage2D(c.dst.texture, c.pixels, c.x, c.y, c.width, c.height)
opengl.GetContext().TexSubImage2D(c.pixels, c.x, c.y, c.width, c.height)
return nil return nil
} }

View File

@ -80,7 +80,7 @@ func GetContext() *Context {
return theContext return theContext
} }
func (c *Context) BindTexture(t Texture) { func (c *Context) bindTexture(t Texture) {
if c.lastTexture == t { if c.lastTexture == t {
return return
} }

View File

@ -150,7 +150,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) {
}); err != nil { }); err != nil {
return 0, err return 0, err
} }
c.BindTexture(texture) c.bindTexture(texture)
_ = c.runOnContextThread(func() error { _ = c.runOnContextThread(func() error {
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_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 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 { _ = 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)) gl.TexSubImage2D(gl.TEXTURE_2D, 0, int32(x), int32(y), int32(width), int32(height), gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p))
return nil return nil

View File

@ -180,7 +180,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) {
return Texture(js.Null()), errors.New("opengl: glGenTexture failed") return Texture(js.Null()), errors.New("opengl: glGenTexture failed")
} }
gl.Call("pixelStorei", unpackAlignment, 4) gl.Call("pixelStorei", unpackAlignment, 4)
c.BindTexture(Texture(t)) c.bindTexture(Texture(t))
gl.Call("texParameteri", texture2d, textureMagFilter, nearest) gl.Call("texParameteri", texture2d, textureMagFilter, nearest)
gl.Call("texParameteri", texture2d, textureMinFilter, 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() 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 gl := c.gl
// void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, // void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
// GLsizei width, GLsizei height, // GLsizei width, GLsizei height,

View File

@ -140,7 +140,7 @@ func (c *Context) NewTexture(width, height int) (Texture, error) {
return Texture{}, errors.New("opengl: creating texture failed") return Texture{}, errors.New("opengl: creating texture failed")
} }
gl.PixelStorei(mgl.UNPACK_ALIGNMENT, 4) 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_MAG_FILTER, mgl.NEAREST)
gl.TexParameteri(mgl.TEXTURE_2D, mgl.TEXTURE_MIN_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)) 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 := c.gl
gl.TexSubImage2D(mgl.TEXTURE_2D, 0, x, y, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, p) gl.TexSubImage2D(mgl.TEXTURE_2D, 0, x, y, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, p)
} }

View File

@ -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 // 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 // See also: https://www.opengl.org/sdk/docs/man2/xhtml/glActiveTexture.xml
c.BindTexture(texture) c.bindTexture(texture)
} }