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