Texturer to hold raw Go image.Image

This commit is contained in:
Noah 2021-06-13 19:59:54 -07:00
parent b4a1979a8b
commit d77f5056b7
3 changed files with 13 additions and 0 deletions

View File

@ -74,6 +74,11 @@ func (t *Texture) Size() render.Rect {
return render.NewRect(t.width, t.height)
}
// Image returns the underlying image.
func (t *Texture) Image() image.Image {
return nil
}
// LoadTexture recalls a cached texture image.
func (e *Engine) LoadTexture(name string) (render.Texturer, error) {
if tex, ok := e.textures[name]; ok {

View File

@ -49,6 +49,7 @@ type Engine interface {
// abstracting away its inner workings.
type Texturer interface {
Size() Rect
Image() image.Image
}
// Rect has a coordinate and a width and height.

View File

@ -24,6 +24,7 @@ func (r *Renderer) Copy(t render.Texturer, src, dst render.Rect) {
// Texture can hold on to SDL textures for caching and optimization.
type Texture struct {
tex *sdl.Texture
image image.Image
width int32
height int32
}
@ -64,6 +65,7 @@ func (r *Renderer) StoreTexture(name string, img image.Image) (render.Texturer,
width: surface.W,
height: surface.H,
tex: texture,
image: img,
}
r.textures[name] = tex
@ -75,6 +77,11 @@ func (t *Texture) Size() render.Rect {
return render.NewRect(int(t.width), int(t.height))
}
// Image returns the underlying Go image.Image.
func (t *Texture) Image() image.Image {
return t.image
}
// LoadTexture initializes a texture from a bitmap image.
func (r *Renderer) LoadTexture(name string) (render.Texturer, error) {
if tex, ok := r.textures[name]; ok {