opengl: Remove pixels argument from NewTexture

This commit is contained in:
Hajime Hoshi 2018-02-25 23:34:34 +09:00
parent 85b133dad0
commit 86671f3337
4 changed files with 7 additions and 21 deletions

View File

@ -329,7 +329,7 @@ func (c *newImageCommand) Exec(indexOffsetInBytes int) error {
if h < 1 { if h < 1 {
return errors.New("graphics: height must be equal or more than 1.") return errors.New("graphics: height must be equal or more than 1.")
} }
native, err := opengl.GetContext().NewTexture(w, h, nil) native, err := opengl.GetContext().NewTexture(w, h)
if err != nil { if err != nil {
return err return err
} }

View File

@ -133,7 +133,7 @@ func (c *Context) BlendFunc(mode CompositeMode) {
}) })
} }
func (c *Context) NewTexture(width, height int, pixels []uint8) (Texture, error) { func (c *Context) NewTexture(width, height int) (Texture, error) {
var texture Texture var texture Texture
if err := c.runOnContextThread(func() error { if err := c.runOnContextThread(func() error {
var t uint32 var t uint32
@ -152,12 +152,7 @@ func (c *Context) NewTexture(width, height int, pixels []uint8) (Texture, error)
_ = 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)
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
var p interface{}
if pixels != nil {
p = pixels
}
gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(width), int32(height), 0, gl.RGBA, gl.UNSIGNED_BYTE, gl.Ptr(p))
return nil return nil
}) })
return texture, nil return texture, nil

View File

@ -131,7 +131,7 @@ func (c *Context) BlendFunc(mode CompositeMode) {
gl.BlendFunc(int(s), int(d)) gl.BlendFunc(int(s), int(d))
} }
func (c *Context) NewTexture(width, height int, pixels []uint8) (Texture, error) { func (c *Context) NewTexture(width, height int) (Texture, error) {
gl := c.gl gl := c.gl
t := gl.CreateTexture() t := gl.CreateTexture()
if t == nil { if t == nil {
@ -148,11 +148,7 @@ func (c *Context) NewTexture(width, height int, pixels []uint8) (Texture, error)
// void texImage2D(GLenum target, GLint level, GLenum internalformat, // void texImage2D(GLenum target, GLint level, GLenum internalformat,
// GLsizei width, GLsizei height, GLint border, GLenum format, // GLsizei width, GLsizei height, GLint border, GLenum format,
// GLenum type, ArrayBufferView? pixels); // GLenum type, ArrayBufferView? pixels);
var p interface{} gl.Call("texImage2D", gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)
if pixels != nil {
p = pixels
}
gl.Call("texImage2D", gl.TEXTURE_2D, 0, gl.RGBA, width, height, 0, gl.RGBA, gl.UNSIGNED_BYTE, p)
return t, nil return t, nil
} }

View File

@ -123,7 +123,7 @@ func (c *Context) BlendFunc(mode CompositeMode) {
gl.BlendFunc(mgl.Enum(s), mgl.Enum(d)) gl.BlendFunc(mgl.Enum(s), mgl.Enum(d))
} }
func (c *Context) NewTexture(width, height int, pixels []uint8) (Texture, error) { func (c *Context) NewTexture(width, height int) (Texture, error) {
gl := c.gl gl := c.gl
t := gl.CreateTexture() t := gl.CreateTexture()
if t.Value <= 0 { if t.Value <= 0 {
@ -134,12 +134,7 @@ func (c *Context) NewTexture(width, height int, pixels []uint8) (Texture, error)
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)
gl.TexImage2D(mgl.TEXTURE_2D, 0, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, nil)
var p []uint8
if pixels != nil {
p = pixels
}
gl.TexImage2D(mgl.TEXTURE_2D, 0, width, height, mgl.RGBA, mgl.UNSIGNED_BYTE, p)
return Texture(t), nil return Texture(t), nil
} }