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-06 21:21:20 +01:00
CreateRenderTarget(width, height int, filter Filter) (RenderTargetID, error)
CreateTexture(img image.Image, filter Filter) (TextureID, error)
}
func SetTextureFactory(textureFactory TextureFactory) {
currentTextureFactory = textureFactory
}
2014-12-06 21:21:20 +01:00
func CreateRenderTarget(width, height int, filter Filter) (RenderTargetID, error) {
if currentTextureFactory == nil {
panic("graphics.CreateRenderTarget: currentTextureFactory is not set.")
}
return currentTextureFactory.CreateRenderTarget(width, height, filter)
}
2014-12-06 21:21:20 +01:00
func CreateTexture(img image.Image, filter Filter) (TextureID, error) {
if currentTextureFactory == nil {
panic("graphics.CreateTexture: currentTextureFactory is not set")
}
return currentTextureFactory.CreateTexture(img, filter)
}