ebiten/texturefactory.go

64 lines
1.9 KiB
Go
Raw Normal View History

2014-12-09 14:09:22 +01:00
package ebiten
import (
"image"
)
2014-12-07 17:07:39 +01:00
// Filter represents the type of filter to be used when a texture or a render
// target is maginified or minified.
2014-05-02 17:06:20 +02:00
type Filter int
const (
FilterNearest Filter = iota
FilterLinear
)
2014-12-07 17:07:39 +01:00
// TextureID represents an ID of a texture.
2014-12-06 21:21:20 +01:00
type TextureID int
2014-05-02 17:06:20 +02:00
// IsNil returns true if the texture is nil.
func (i TextureID) IsNil() bool {
return i == 0
}
2014-12-07 17:07:39 +01:00
// RenderTargetID represents an ID of a render target.
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
// IsNil returns true if the render target is nil.
func (i RenderTargetID) IsNil() bool {
return i == 0
}
var currentTextureFactory TextureFactory
2014-12-07 17:07:39 +01:00
// A TextureFactory is the interface that creates a render target or a texture.
// This method is for the library and a game developer doesn't have to use this.
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)
}
2014-12-07 17:07:39 +01:00
// SetTextureFactory sets the current texture factory.
// This method is for the library and a game developer doesn't have to use this.
func SetTextureFactory(textureFactory TextureFactory) {
currentTextureFactory = textureFactory
}
2014-12-07 17:07:39 +01:00
// NewRenderTargetID returns an ID of a newly created render target.
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 17:07:39 +01:00
// NewRenderTargetID returns an ID of a newly created texture.
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)
}