mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-12 22:17:26 +01:00
44 lines
1.1 KiB
Go
44 lines
1.1 KiB
Go
package graphics
|
|
|
|
import (
|
|
"image"
|
|
)
|
|
|
|
type Filter int
|
|
|
|
const (
|
|
FilterNearest Filter = iota
|
|
FilterLinear
|
|
)
|
|
|
|
type TextureID int
|
|
|
|
// A render target is essentially same as a texture, but it is assumed that the
|
|
// all alpha of a render target is maximum.
|
|
type RenderTargetID int
|
|
|
|
var currentTextureFactory TextureFactory
|
|
|
|
type TextureFactory interface {
|
|
CreateRenderTarget(width, height int, filter Filter) (RenderTargetID, error)
|
|
CreateTexture(img image.Image, filter Filter) (TextureID, error)
|
|
}
|
|
|
|
func SetTextureFactory(textureFactory TextureFactory) {
|
|
currentTextureFactory = textureFactory
|
|
}
|
|
|
|
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)
|
|
}
|
|
|
|
func CreateTexture(img image.Image, filter Filter) (TextureID, error) {
|
|
if currentTextureFactory == nil {
|
|
panic("graphics.CreateTexture: currentTextureFactory is not set")
|
|
}
|
|
return currentTextureFactory.CreateTexture(img, filter)
|
|
}
|