mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
Rename Texture -> Image (#29)
This commit is contained in:
parent
480289cd5d
commit
3a9a7fed87
@ -24,7 +24,7 @@ import (
|
||||
// ColorMatrixDim is a dimension of a ColorMatrix.
|
||||
const ColorMatrixDim = 5
|
||||
|
||||
// A ColorMatrix represents a matrix to transform coloring when rendering a texture or a render target.
|
||||
// A ColorMatrix represents a matrix to transform coloring when rendering an image.
|
||||
type ColorMatrix struct {
|
||||
Elements [ColorMatrixDim - 1][ColorMatrixDim]float64
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
type debugPrintState struct {
|
||||
textTexture *ebiten.Texture
|
||||
textTexture *ebiten.Image
|
||||
debugPrintRenderTarget *ebiten.RenderTarget
|
||||
y int
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func NewTextureFromFile(path string, filter ebiten.Filter) (*ebiten.Texture, image.Image, error) {
|
||||
func NewTextureFromFile(path string, filter ebiten.Filter) (*ebiten.Image, image.Image, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
@ -32,7 +32,7 @@ const (
|
||||
type Game struct {
|
||||
count int
|
||||
tmpRenderTarget *ebiten.RenderTarget
|
||||
ebitenTexture *ebiten.Texture
|
||||
ebitenTexture *ebiten.Image
|
||||
}
|
||||
|
||||
func (g *Game) Update(r *ebiten.RenderTarget) error {
|
||||
|
@ -37,7 +37,7 @@ type nameSize struct {
|
||||
type Textures struct {
|
||||
texturePaths chan namePath
|
||||
renderTargetSizes chan nameSize
|
||||
textures map[string]*ebiten.Texture
|
||||
textures map[string]*ebiten.Image
|
||||
renderTargets map[string]*ebiten.RenderTarget
|
||||
sync.RWMutex
|
||||
}
|
||||
@ -46,7 +46,7 @@ func NewTextures() *Textures {
|
||||
textures := &Textures{
|
||||
texturePaths: make(chan namePath),
|
||||
renderTargetSizes: make(chan nameSize),
|
||||
textures: map[string]*ebiten.Texture{},
|
||||
textures: map[string]*ebiten.Image{},
|
||||
renderTargets: map[string]*ebiten.RenderTarget{},
|
||||
}
|
||||
go func() {
|
||||
@ -123,7 +123,7 @@ func (t *Textures) Has(name string) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
func (t *Textures) GetTexture(name string) *ebiten.Texture {
|
||||
func (t *Textures) GetTexture(name string) *ebiten.Image {
|
||||
t.RLock()
|
||||
defer t.RUnlock()
|
||||
return t.textures[name]
|
||||
|
@ -33,7 +33,7 @@ type Game struct {
|
||||
count int
|
||||
horizontalCount int
|
||||
verticalCount int
|
||||
gophersTexture *ebiten.Texture
|
||||
gophersTexture *ebiten.Image
|
||||
}
|
||||
|
||||
func (g *Game) Update(r *ebiten.RenderTarget) error {
|
||||
|
@ -31,7 +31,7 @@ const (
|
||||
const mosaicRatio = 16
|
||||
|
||||
type Game struct {
|
||||
gophersTexture *ebiten.Texture
|
||||
gophersTexture *ebiten.Image
|
||||
gophersRenderTarget *ebiten.RenderTarget
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ const (
|
||||
)
|
||||
|
||||
type Game struct {
|
||||
gophersTexture *ebiten.Texture
|
||||
gophersTexture *ebiten.Image
|
||||
}
|
||||
|
||||
func (g *Game) Update(r *ebiten.RenderTarget) error {
|
||||
|
@ -53,6 +53,6 @@ func NewRenderTarget(width, height int, filter Filter) (*RenderTarget, error) {
|
||||
}
|
||||
|
||||
// NewImage returns a new image.
|
||||
func NewImage(img image.Image, filter Filter) (*Texture, error) {
|
||||
return currentUI.newTexture(img, glFilter(filter))
|
||||
func NewImage(img image.Image, filter Filter) (*Image, error) {
|
||||
return currentUI.newImage(img, glFilter(filter))
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ import (
|
||||
// GeometryMatrixDim is a dimension of a GeometryMatrix.
|
||||
const GeometryMatrixDim = 3
|
||||
|
||||
// A GeometryMatrix represents a matrix to transform geometry when rendering a texture or a render target.
|
||||
// A GeometryMatrix represents a matrix to transform geometry when rendering an image.
|
||||
type GeometryMatrix struct {
|
||||
Elements [GeometryMatrixDim - 1][GeometryMatrixDim]float64
|
||||
}
|
||||
|
18
graphics.go
18
graphics.go
@ -35,15 +35,15 @@ type ImagePart struct {
|
||||
}
|
||||
|
||||
// DrawWholeImage draws the whole image.
|
||||
func DrawWholeImage(r *RenderTarget, texture *Texture, geo GeometryMatrix, color ColorMatrix) error {
|
||||
w, h := texture.Size()
|
||||
func DrawWholeImage(r *RenderTarget, image *Image, geo GeometryMatrix, color ColorMatrix) error {
|
||||
w, h := image.Size()
|
||||
parts := []ImagePart{
|
||||
{Rect{0, 0, float64(w), float64(h)}, Rect{0, 0, float64(w), float64(h)}},
|
||||
}
|
||||
return r.DrawImage(texture, parts, geo, color)
|
||||
return r.DrawImage(image, parts, geo, color)
|
||||
}
|
||||
|
||||
// Filter represents the type of filter to be used when a texture is maginified or minified.
|
||||
// Filter represents the type of filter to be used when an image is maginified or minified.
|
||||
type Filter int
|
||||
|
||||
// Filters
|
||||
@ -52,12 +52,12 @@ const (
|
||||
FilterLinear
|
||||
)
|
||||
|
||||
// Texture represents a texture.
|
||||
type Texture struct {
|
||||
// An Image represents an image to be rendered.
|
||||
type Image struct {
|
||||
glTexture *opengl.Texture
|
||||
}
|
||||
|
||||
// Size returns the size of the texture.
|
||||
func (t *Texture) Size() (width int, height int) {
|
||||
return t.glTexture.Size()
|
||||
// Size returns the size of the image.
|
||||
func (i *Image) Size() (width int, height int) {
|
||||
return i.glTexture.Size()
|
||||
}
|
||||
|
@ -27,7 +27,7 @@ import (
|
||||
|
||||
type innerRenderTarget struct {
|
||||
glRenderTarget *opengl.RenderTarget
|
||||
image *Texture
|
||||
image *Image
|
||||
}
|
||||
|
||||
func newInnerRenderTarget(width, height int, filter int) (*innerRenderTarget, error) {
|
||||
@ -41,8 +41,8 @@ func newInnerRenderTarget(width, height int, filter int) (*innerRenderTarget, er
|
||||
return nil, err
|
||||
}
|
||||
|
||||
texture := &Texture{glTexture}
|
||||
return &innerRenderTarget{glRenderTarget, texture}, nil
|
||||
image := &Image{glTexture}
|
||||
return &innerRenderTarget{glRenderTarget, image}, nil
|
||||
}
|
||||
|
||||
func (r *innerRenderTarget) size() (width, height int) {
|
||||
@ -68,11 +68,11 @@ func (r *innerRenderTarget) Fill(clr color.Color) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *innerRenderTarget) DrawImage(texture *Texture, parts []ImagePart, geo GeometryMatrix, color ColorMatrix) error {
|
||||
func (r *innerRenderTarget) DrawImage(image *Image, parts []ImagePart, geo GeometryMatrix, color ColorMatrix) error {
|
||||
if err := r.glRenderTarget.SetAsViewport(); err != nil {
|
||||
return err
|
||||
}
|
||||
glTexture := texture.glTexture
|
||||
glTexture := image.glTexture
|
||||
w, h := glTexture.Size()
|
||||
quads := textureQuads(parts, w, h)
|
||||
targetNativeTexture := gl.Texture(0)
|
||||
@ -119,7 +119,7 @@ type RenderTarget struct {
|
||||
inner *innerRenderTarget
|
||||
}
|
||||
|
||||
func (r *RenderTarget) Image() *Texture {
|
||||
func (r *RenderTarget) Image() *Image {
|
||||
return r.inner.image
|
||||
}
|
||||
|
||||
@ -141,9 +141,9 @@ func (r *RenderTarget) Fill(clr color.Color) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (r *RenderTarget) DrawImage(texture *Texture, parts []ImagePart, geo GeometryMatrix, color ColorMatrix) (err error) {
|
||||
func (r *RenderTarget) DrawImage(image *Image, parts []ImagePart, geo GeometryMatrix, color ColorMatrix) (err error) {
|
||||
r.syncer.Sync(func() {
|
||||
err = r.inner.DrawImage(texture, parts, geo, color)
|
||||
err = r.inner.DrawImage(image, parts, geo, color)
|
||||
})
|
||||
return
|
||||
}
|
||||
|
8
ui.go
8
ui.go
@ -131,17 +131,17 @@ func (u *ui) draw(f func(*RenderTarget) error) (err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func (u *ui) newTexture(img image.Image, filter int) (*Texture, error) {
|
||||
var texture *Texture
|
||||
func (u *ui) newImage(img image.Image, filter int) (*Image, error) {
|
||||
var i *Image
|
||||
var err error
|
||||
u.use(func() {
|
||||
glTexture, err := opengl.NewTextureFromImage(img, filter)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
texture = &Texture{glTexture}
|
||||
i = &Image{glTexture}
|
||||
})
|
||||
return texture, err
|
||||
return i, err
|
||||
}
|
||||
|
||||
func (u *ui) newRenderTarget(width, height int, filter int) (*RenderTarget, error) {
|
||||
|
Loading…
Reference in New Issue
Block a user