mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-25 03:08:54 +01:00
shareable: Remove (*Image).Size()
This commit is contained in:
parent
3023cc69c3
commit
bc4d092710
@ -257,10 +257,6 @@ func (i *Image) region() (x, y, width, height int) {
|
|||||||
return i.node.Region()
|
return i.node.Region()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *Image) Size() (width, height int) {
|
|
||||||
return i.width, i.height
|
|
||||||
}
|
|
||||||
|
|
||||||
// DrawTriangles draws triangles with the given image.
|
// DrawTriangles draws triangles with the given image.
|
||||||
//
|
//
|
||||||
// The vertex floats are:
|
// The vertex floats are:
|
||||||
|
48
mipmap.go
48
mipmap.go
@ -29,12 +29,16 @@ import (
|
|||||||
type levelToImage map[int]*shareable.Image
|
type levelToImage map[int]*shareable.Image
|
||||||
|
|
||||||
type mipmap struct {
|
type mipmap struct {
|
||||||
|
width int
|
||||||
|
height int
|
||||||
orig *shareable.Image
|
orig *shareable.Image
|
||||||
imgs map[image.Rectangle]levelToImage
|
imgs map[image.Rectangle]levelToImage
|
||||||
}
|
}
|
||||||
|
|
||||||
func newMipmap(width, height int) *mipmap {
|
func newMipmap(width, height int) *mipmap {
|
||||||
return &mipmap{
|
return &mipmap{
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
orig: shareable.NewImage(width, height),
|
orig: shareable.NewImage(width, height),
|
||||||
imgs: map[image.Rectangle]levelToImage{},
|
imgs: map[image.Rectangle]levelToImage{},
|
||||||
}
|
}
|
||||||
@ -42,6 +46,8 @@ func newMipmap(width, height int) *mipmap {
|
|||||||
|
|
||||||
func newScreenFramebufferMipmap(width, height int) *mipmap {
|
func newScreenFramebufferMipmap(width, height int) *mipmap {
|
||||||
return &mipmap{
|
return &mipmap{
|
||||||
|
width: width,
|
||||||
|
height: height,
|
||||||
orig: shareable.NewScreenFramebufferImage(width, height),
|
orig: shareable.NewScreenFramebufferImage(width, height),
|
||||||
imgs: map[image.Rectangle]levelToImage{},
|
imgs: map[image.Rectangle]levelToImage{},
|
||||||
}
|
}
|
||||||
@ -67,7 +73,7 @@ func (m *mipmap) replacePixels(pix []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (m *mipmap) size() (int, int) {
|
func (m *mipmap) size() (int, int) {
|
||||||
return m.orig.Size()
|
return m.width, m.height
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *mipmap) at(x, y int) (r, g, b, a byte) {
|
func (m *mipmap) at(x, y int) (r, g, b, a byte) {
|
||||||
@ -124,7 +130,7 @@ func (m *mipmap) drawImage(src *mipmap, bounds image.Rectangle, geom *GeoM, colo
|
|||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
m.orig.DrawTriangles(src.orig, vs, is, colorm, mode, filter, driver.AddressClampToZero)
|
m.orig.DrawTriangles(src.orig, vs, is, colorm, mode, filter, driver.AddressClampToZero)
|
||||||
} else if shared := src.level(bounds, level); shared != nil {
|
} else if shared := src.level(bounds, level); shared != nil {
|
||||||
w, h := shared.Size()
|
w, h := sizeForLevel(bounds.Dx(), bounds.Dy(), level)
|
||||||
s := pow2(level)
|
s := pow2(level)
|
||||||
a *= s
|
a *= s
|
||||||
b *= s
|
b *= s
|
||||||
@ -197,7 +203,7 @@ func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
|||||||
imgs[level] = nil
|
imgs[level] = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
w, h := src.Size()
|
w, h := sizeForLevel(r.Dx(), r.Dy(), level-1)
|
||||||
vs = quadVertices(0, 0, w, h, 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
vs = quadVertices(0, 0, w, h, 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||||
filter = driver.FilterLinear
|
filter = driver.FilterLinear
|
||||||
case level == -1:
|
case level == -1:
|
||||||
@ -210,7 +216,7 @@ func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
|||||||
imgs[level] = nil
|
imgs[level] = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
w, h := src.Size()
|
w, h := sizeForLevel(r.Dx(), r.Dy(), level+1)
|
||||||
vs = quadVertices(0, 0, w, h, 2, 0, 0, 2, 0, 0, 1, 1, 1, 1)
|
vs = quadVertices(0, 0, w, h, 2, 0, 0, 2, 0, 0, 1, 1, 1, 1)
|
||||||
filter = driver.FilterNearest
|
filter = driver.FilterNearest
|
||||||
default:
|
default:
|
||||||
@ -218,23 +224,11 @@ func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
|||||||
}
|
}
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
|
|
||||||
size := r.Size()
|
w2, h2 := sizeForLevel(r.Dx(), r.Dy(), level)
|
||||||
w2, h2 := size.X, size.Y
|
|
||||||
if level > 0 {
|
|
||||||
for i := 0; i < level; i++ {
|
|
||||||
w2 /= 2
|
|
||||||
h2 /= 2
|
|
||||||
if w2 == 0 || h2 == 0 {
|
if w2 == 0 || h2 == 0 {
|
||||||
imgs[level] = nil
|
imgs[level] = nil
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for i := 0; i < -level; i++ {
|
|
||||||
w2 *= 2
|
|
||||||
h2 *= 2
|
|
||||||
}
|
|
||||||
}
|
|
||||||
s := shareable.NewImage(w2, h2)
|
s := shareable.NewImage(w2, h2)
|
||||||
s.DrawTriangles(src, vs, is, nil, driver.CompositeModeCopy, filter, driver.AddressClampToZero)
|
s.DrawTriangles(src, vs, is, nil, driver.CompositeModeCopy, filter, driver.AddressClampToZero)
|
||||||
imgs[level] = s
|
imgs[level] = s
|
||||||
@ -242,6 +236,26 @@ func (m *mipmap) level(r image.Rectangle, level int) *shareable.Image {
|
|||||||
return imgs[level]
|
return imgs[level]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sizeForLevel(origWidth, origHeight int, level int) (width, height int) {
|
||||||
|
width = origWidth
|
||||||
|
height = origHeight
|
||||||
|
if level > 0 {
|
||||||
|
for i := 0; i < level; i++ {
|
||||||
|
width /= 2
|
||||||
|
height /= 2
|
||||||
|
if width == 0 || height == 0 {
|
||||||
|
return 0, 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for i := 0; i < -level; i++ {
|
||||||
|
width *= 2
|
||||||
|
height *= 2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (m *mipmap) isDisposed() bool {
|
func (m *mipmap) isDisposed() bool {
|
||||||
return m.orig == nil
|
return m.orig == nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user