mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
graphics: Simplify mipmap calculation
This commit is contained in:
parent
d17a6dde9b
commit
bac0431c9f
12
image.go
12
image.go
@ -275,18 +275,18 @@ func (i *Image) DrawImage(img *Image, options *DrawImageOptions) error {
|
||||
b *= float32(s)
|
||||
c *= float32(s)
|
||||
d *= float32(s)
|
||||
sx0 = int(math.Ceil(float64(sx0) / float64(s)))
|
||||
sy0 = int(math.Ceil(float64(sy0) / float64(s)))
|
||||
sx1 = int(math.Ceil(float64(sx1) / float64(s)))
|
||||
sy1 = int(math.Ceil(float64(sy1) / float64(s)))
|
||||
sx0 = sx0 / s
|
||||
sy0 = sy0 / s
|
||||
sx1 = sx1 / s
|
||||
sy1 = sy1 / s
|
||||
}
|
||||
|
||||
w, h = img.shareableImages[len(img.shareableImages)-1].Size()
|
||||
for len(img.shareableImages) < level+1 {
|
||||
lastl := len(img.shareableImages) - 1
|
||||
src := img.shareableImages[lastl]
|
||||
w2 := int(math.Ceil(float64(w) / 2.0))
|
||||
h2 := int(math.Ceil(float64(h) / 2.0))
|
||||
w2 := w / 2
|
||||
h2 := h / 2
|
||||
if w2 == 0 || h2 == 0 {
|
||||
break
|
||||
}
|
||||
|
@ -863,10 +863,6 @@ func TestSprites(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMipmap(t *testing.T) {
|
||||
ceilDiv := func(x, y int) int {
|
||||
return int(math.Ceil(float64(x) / float64(y)))
|
||||
}
|
||||
|
||||
src, _, err := openEbitenImage()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@ -874,14 +870,14 @@ func TestMipmap(t *testing.T) {
|
||||
}
|
||||
w, h := src.Size()
|
||||
|
||||
l1, _ := NewImage(ceilDiv(w, 2), ceilDiv(h, 2), FilterDefault)
|
||||
l1, _ := NewImage(w/2, h/2, FilterDefault)
|
||||
op := &DrawImageOptions{}
|
||||
op.GeoM.Scale(1/2.0, 1/2.0)
|
||||
op.Filter = FilterLinear
|
||||
l1.DrawImage(src, op)
|
||||
|
||||
l1w, l1h := l1.Size()
|
||||
l2, _ := NewImage(ceilDiv(l1w, 2), ceilDiv(l1h, 2), FilterDefault)
|
||||
l2, _ := NewImage(l1w/2, l1h/2, FilterDefault)
|
||||
op = &DrawImageOptions{}
|
||||
op.GeoM.Scale(1/2.0, 1/2.0)
|
||||
op.Filter = FilterLinear
|
||||
|
Loading…
Reference in New Issue
Block a user