2013-12-02 16:15:01 +01:00
|
|
|
package graphics
|
|
|
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2014-12-06 19:28:50 +01:00
|
|
|
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.
|
2013-12-02 16:15:01 +01:00
|
|
|
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)
|
2013-12-02 16:15:01 +01:00
|
|
|
}
|
2014-12-06 19:28:50 +01:00
|
|
|
|
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.
|
2014-12-06 19:28:50 +01:00
|
|
|
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) {
|
2014-12-06 19:28:50 +01:00
|
|
|
if currentTextureFactory == nil {
|
2014-12-07 11:25:49 +01:00
|
|
|
panic("graphics.NewRenderTarget: currentTextureFactory is not set.")
|
2014-12-06 19:28:50 +01:00
|
|
|
}
|
2014-12-07 11:25:49 +01:00
|
|
|
return currentTextureFactory.NewRenderTargetID(width, height, filter)
|
2014-12-06 19:28:50 +01:00
|
|
|
}
|
|
|
|
|
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) {
|
2014-12-06 19:28:50 +01:00
|
|
|
if currentTextureFactory == nil {
|
2014-12-07 11:25:49 +01:00
|
|
|
panic("graphics.NewTexture: currentTextureFactory is not set")
|
2014-12-06 19:28:50 +01:00
|
|
|
}
|
2014-12-07 11:25:49 +01:00
|
|
|
return currentTextureFactory.NewTextureID(img, filter)
|
2014-12-06 19:28:50 +01:00
|
|
|
}
|