mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-24 09:52:03 +01:00
internal/mipmap: refactoring
This commit is contained in:
parent
6389db14a2
commit
cbecbe2bad
@ -164,24 +164,28 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
||||
return img.img
|
||||
}
|
||||
|
||||
var w, h int
|
||||
var src *buffered.Image
|
||||
vs := make([]float32, 4*graphics.VertexFloatCount)
|
||||
switch {
|
||||
case level == 1:
|
||||
src = m.orig
|
||||
graphics.QuadVerticesFromSrcAndMatrix(vs, 0, 0, float32(m.width), float32(m.height), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||
w = m.width
|
||||
h = m.height
|
||||
case level > 1:
|
||||
src = m.level(level - 1)
|
||||
if src == nil {
|
||||
m.setImg(level, nil)
|
||||
return nil
|
||||
}
|
||||
w := sizeForLevel(m.width, level-1)
|
||||
h := sizeForLevel(m.height, level-1)
|
||||
graphics.QuadVerticesFromSrcAndMatrix(vs, 0, 0, float32(w), float32(h), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||
w = sizeForLevel(m.width, level-1)
|
||||
h = sizeForLevel(m.height, level-1)
|
||||
default:
|
||||
panic(fmt.Sprintf("mipmap: invalid level: %d", level))
|
||||
}
|
||||
|
||||
graphics.QuadVerticesFromSrcAndMatrix(vs, 0, 0, float32(w), float32(h), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||
|
||||
is := graphics.QuadIndices()
|
||||
|
||||
w2 := sizeForLevel(m.width, level)
|
||||
@ -207,8 +211,6 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
||||
}
|
||||
|
||||
dstRegion := image.Rect(0, 0, w2, h2)
|
||||
w := sizeForLevel(m.width, level-1)
|
||||
h := sizeForLevel(m.height, level-1)
|
||||
srcRegion := image.Rect(0, 0, w, h)
|
||||
s.DrawTriangles([graphics.ShaderSrcImageCount]*buffered.Image{src}, vs, is, graphicsdriver.BlendCopy, dstRegion, [graphics.ShaderSrcImageCount]image.Rectangle{srcRegion}, atlas.LinearFilterShader, nil, graphicsdriver.FillRuleFillAll, restorable.HintOverwriteDstRegion)
|
||||
m.setImg(level, s)
|
||||
|
Loading…
Reference in New Issue
Block a user