ebiten/graphics/texturefactory.go

44 lines
1.1 KiB
Go
Raw Normal View History

package graphics
import (
"image"
)
2014-05-02 17:06:20 +02:00
type Filter int
const (
FilterNearest Filter = iota
FilterLinear
)
2014-12-06 21:21:20 +01:00
type TextureID int
2014-05-02 17:06:20 +02:00
// A render target is essentially same as a texture, but it is assumed that the
// all alpha of a render target is maximum.
2014-12-06 21:21:20 +01:00
type RenderTargetID int
2014-05-02 17:06:20 +02:00
var currentTextureFactory TextureFactory
type TextureFactory interface {
2014-12-07 11:25:49 +01:00
NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error)
NewTextureID(img image.Image, filter Filter) (TextureID, error)
}
func SetTextureFactory(textureFactory TextureFactory) {
currentTextureFactory = textureFactory
}
2014-12-07 11:25:49 +01:00
func NewRenderTargetID(width, height int, filter Filter) (RenderTargetID, error) {
if currentTextureFactory == nil {
2014-12-07 11:25:49 +01:00
panic("graphics.NewRenderTarget: currentTextureFactory is not set.")
}
2014-12-07 11:25:49 +01:00
return currentTextureFactory.NewRenderTargetID(width, height, filter)
}
2014-12-07 11:25:49 +01:00
func NewTextureID(img image.Image, filter Filter) (TextureID, error) {
if currentTextureFactory == nil {
2014-12-07 11:25:49 +01:00
panic("graphics.NewTexture: currentTextureFactory is not set")
}
2014-12-07 11:25:49 +01:00
return currentTextureFactory.NewTextureID(img, filter)
}