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