diff --git a/graphics/opengl/shader/draw_texture.go b/graphics/opengl/shader/draw_texture.go index 37e068d5f..c16e1a0a1 100644 --- a/graphics/opengl/shader/draw_texture.go +++ b/graphics/opengl/shader/draw_texture.go @@ -22,7 +22,8 @@ func DrawTexture(native texture.Native, projectionMatrix [16]float32, quads []gt return } shaderProgram := use(projectionMatrix, geometryMatrix, colorMatrix) - // This state affects the other functions, so can't disable here... + defer C.glUseProgram(0) + C.glBindTexture(C.GL_TEXTURE_2D, C.GLuint(native)) defer C.glBindTexture(C.GL_TEXTURE_2D, 0) diff --git a/graphics/opengl/shader/program.go b/graphics/opengl/shader/program.go index c6b136d21..e494be35f 100644 --- a/graphics/opengl/shader/program.go +++ b/graphics/opengl/shader/program.go @@ -103,7 +103,11 @@ func getUniformLocation(program C.GLuint, name string) C.GLint { return getLocation(program, name, qualifierVariableTypeUniform) } -func use(projectionMatrix [16]float32, geometryMatrix matrix.Geometry, colorMatrix matrix.Color) C.GLuint { +func program() { +} + +func use(projectionMatrix [16]float32, + geometryMatrix matrix.Geometry, colorMatrix matrix.Color) C.GLuint { program := programRegular if !colorMatrix.IsIdentity() { program = programColorMatrix diff --git a/graphics/texture/texture.go b/graphics/texture/texture.go index debdb6837..17079dc8b 100644 --- a/graphics/texture/texture.go +++ b/graphics/texture/texture.go @@ -23,6 +23,25 @@ type Texture struct { height int } +func AdjustImage(img image.Image, width, height int) *image.NRGBA { + adjustedImageBounds := image.Rectangle{ + image.ZP, + image.Point{width, height}, + } + if nrgba := img.(*image.NRGBA); nrgba != nil && + img.Bounds() == adjustedImageBounds { + return nrgba + } + + adjustedImage := image.NewNRGBA(adjustedImageBounds) + dstBounds := image.Rectangle{ + image.ZP, + img.Bounds().Size(), + } + draw.Draw(adjustedImage, dstBounds, img, image.ZP, draw.Src) + return adjustedImage +} + func New(width, height int, create func(textureWidth, textureHeight int) ( interface{}, error)) (*Texture, error) { texture := &Texture{ @@ -46,16 +65,7 @@ func NewFromImage(img image.Image, create func(img *image.NRGBA) ( width: width, height: height, } - adjustedImageBound := image.Rectangle{ - image.ZP, - image.Point{texture.textureWidth(), texture.textureHeight()}, - } - adjustedImage := image.NewNRGBA(adjustedImageBound) - dstBound := image.Rectangle{ - image.ZP, - img.Bounds().Size(), - } - draw.Draw(adjustedImage, dstBound, img, image.ZP, draw.Src) + adjustedImage := AdjustImage(img, texture.textureWidth(), texture.textureHeight()) var err error texture.native, err = create(adjustedImage) if err != nil {