Texturer to hold raw Go image.Image
This commit is contained in:
parent
b4a1979a8b
commit
d77f5056b7
|
@ -74,6 +74,11 @@ func (t *Texture) Size() render.Rect {
|
||||||
return render.NewRect(t.width, t.height)
|
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.
|
// LoadTexture recalls a cached texture image.
|
||||||
func (e *Engine) LoadTexture(name string) (render.Texturer, error) {
|
func (e *Engine) LoadTexture(name string) (render.Texturer, error) {
|
||||||
if tex, ok := e.textures[name]; ok {
|
if tex, ok := e.textures[name]; ok {
|
||||||
|
|
|
@ -49,6 +49,7 @@ type Engine interface {
|
||||||
// abstracting away its inner workings.
|
// abstracting away its inner workings.
|
||||||
type Texturer interface {
|
type Texturer interface {
|
||||||
Size() Rect
|
Size() Rect
|
||||||
|
Image() image.Image
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rect has a coordinate and a width and height.
|
// Rect has a coordinate and a width and height.
|
||||||
|
|
|
@ -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.
|
// Texture can hold on to SDL textures for caching and optimization.
|
||||||
type Texture struct {
|
type Texture struct {
|
||||||
tex *sdl.Texture
|
tex *sdl.Texture
|
||||||
|
image image.Image
|
||||||
width int32
|
width int32
|
||||||
height int32
|
height int32
|
||||||
}
|
}
|
||||||
|
@ -64,6 +65,7 @@ func (r *Renderer) StoreTexture(name string, img image.Image) (render.Texturer,
|
||||||
width: surface.W,
|
width: surface.W,
|
||||||
height: surface.H,
|
height: surface.H,
|
||||||
tex: texture,
|
tex: texture,
|
||||||
|
image: img,
|
||||||
}
|
}
|
||||||
r.textures[name] = tex
|
r.textures[name] = tex
|
||||||
|
|
||||||
|
@ -75,6 +77,11 @@ func (t *Texture) Size() render.Rect {
|
||||||
return render.NewRect(int(t.width), int(t.height))
|
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.
|
// LoadTexture initializes a texture from a bitmap image.
|
||||||
func (r *Renderer) LoadTexture(name string) (render.Texturer, error) {
|
func (r *Renderer) LoadTexture(name string) (render.Texturer, error) {
|
||||||
if tex, ok := r.textures[name]; ok {
|
if tex, ok := r.textures[name]; ok {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user