remove error return value from NewTexture
This commit is contained in:
parent
2848ee5c0c
commit
7a4fce3b75
|
@ -5,7 +5,6 @@ import (
|
||||||
"image/draw"
|
"image/draw"
|
||||||
|
|
||||||
"github.com/faiface/pixel/pixelgl"
|
"github.com/faiface/pixel/pixelgl"
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Picture is a raster picture. It is usually used with sprites.
|
// Picture is a raster picture. It is usually used with sprites.
|
||||||
|
@ -31,16 +30,12 @@ func NewPicture(img image.Image, smooth bool) *Picture {
|
||||||
|
|
||||||
var texture *pixelgl.Texture
|
var texture *pixelgl.Texture
|
||||||
pixelgl.Do(func() {
|
pixelgl.Do(func() {
|
||||||
var err error
|
texture = pixelgl.NewTexture(
|
||||||
texture, err = pixelgl.NewTexture(
|
|
||||||
img.Bounds().Dx(),
|
img.Bounds().Dx(),
|
||||||
img.Bounds().Dy(),
|
img.Bounds().Dy(),
|
||||||
smooth,
|
smooth,
|
||||||
rgba.Pix,
|
rgba.Pix,
|
||||||
)
|
)
|
||||||
if err != nil {
|
|
||||||
panic(errors.Wrap(err, "failed to create picture"))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
return &Picture{
|
return &Picture{
|
||||||
|
|
|
@ -12,10 +12,14 @@ type Texture struct {
|
||||||
width, height int
|
width, height int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTexture creates a new texture with the specified width and height.
|
// NewTexture creates a new texture with the specified width and height with some initial
|
||||||
// The pixels must be a sequence of RGBA values.
|
// pixel values. The pixels must be a sequence of RGBA values.
|
||||||
func NewTexture(width, height int, smooth bool, pixels []uint8) (*Texture, error) {
|
func NewTexture(width, height int, smooth bool, pixels []uint8) *Texture {
|
||||||
texture := &Texture{
|
if len(pixels) != width*height*4 {
|
||||||
|
panic("failed to create new texture: wrong number of pixels")
|
||||||
|
}
|
||||||
|
|
||||||
|
tex := &Texture{
|
||||||
tex: binder{
|
tex: binder{
|
||||||
restoreLoc: gl.TEXTURE_BINDING_2D,
|
restoreLoc: gl.TEXTURE_BINDING_2D,
|
||||||
bindFunc: func(obj uint32) {
|
bindFunc: func(obj uint32) {
|
||||||
|
@ -26,10 +30,10 @@ func NewTexture(width, height int, smooth bool, pixels []uint8) (*Texture, error
|
||||||
height: height,
|
height: height,
|
||||||
}
|
}
|
||||||
|
|
||||||
gl.GenTextures(1, &texture.tex.obj)
|
gl.GenTextures(1, &tex.tex.obj)
|
||||||
|
|
||||||
texture.Begin()
|
tex.Begin()
|
||||||
defer texture.End()
|
defer tex.End()
|
||||||
|
|
||||||
gl.TexImage2D(
|
gl.TexImage2D(
|
||||||
gl.TEXTURE_2D,
|
gl.TEXTURE_2D,
|
||||||
|
@ -56,9 +60,9 @@ func NewTexture(width, height int, smooth bool, pixels []uint8) (*Texture, error
|
||||||
|
|
||||||
gl.GenerateMipmap(gl.TEXTURE_2D)
|
gl.GenerateMipmap(gl.TEXTURE_2D)
|
||||||
|
|
||||||
runtime.SetFinalizer(texture, (*Texture).delete)
|
runtime.SetFinalizer(tex, (*Texture).delete)
|
||||||
|
|
||||||
return texture, nil
|
return tex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Texture) delete() {
|
func (t *Texture) delete() {
|
||||||
|
|
Loading…
Reference in New Issue