mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-11-10 04:57:26 +01:00
internal/mipmap: refactoring
This commit is contained in:
parent
cbecbe2bad
commit
355dd453bd
@ -164,40 +164,40 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
|||||||
return img.img
|
return img.img
|
||||||
}
|
}
|
||||||
|
|
||||||
var w, h int
|
var srcW, srcH int
|
||||||
var src *buffered.Image
|
var src *buffered.Image
|
||||||
vs := make([]float32, 4*graphics.VertexFloatCount)
|
vs := make([]float32, 4*graphics.VertexFloatCount)
|
||||||
switch {
|
switch {
|
||||||
case level == 1:
|
case level == 1:
|
||||||
src = m.orig
|
src = m.orig
|
||||||
w = m.width
|
srcW = m.width
|
||||||
h = m.height
|
srcH = m.height
|
||||||
case level > 1:
|
case level > 1:
|
||||||
src = m.level(level - 1)
|
src = m.level(level - 1)
|
||||||
if src == nil {
|
if src == nil {
|
||||||
m.setImg(level, nil)
|
m.setImg(level, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
w = sizeForLevel(m.width, level-1)
|
srcW = sizeForLevel(m.width, level-1)
|
||||||
h = sizeForLevel(m.height, level-1)
|
srcH = sizeForLevel(m.height, level-1)
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("mipmap: invalid level: %d", level))
|
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)
|
graphics.QuadVerticesFromSrcAndMatrix(vs, 0, 0, float32(srcW), float32(srcH), 0.5, 0, 0, 0.5, 0, 0, 1, 1, 1, 1)
|
||||||
|
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
|
|
||||||
w2 := sizeForLevel(m.width, level)
|
dstW := sizeForLevel(m.width, level)
|
||||||
h2 := sizeForLevel(m.height, level)
|
dstH := sizeForLevel(m.height, level)
|
||||||
if w2 == 0 || h2 == 0 {
|
if dstW == 0 || dstH == 0 {
|
||||||
m.setImg(level, nil)
|
m.setImg(level, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
// buffered.NewImage panics with a too big size when actual allocation happens.
|
// buffered.NewImage panics with a too big size when actual allocation happens.
|
||||||
// 4096 should be a safe size in most environments (#1399).
|
// 4096 should be a safe size in most environments (#1399).
|
||||||
// Unfortunately a precise max image size cannot be obtained here since this requires GPU access.
|
// Unfortunately a precise max image size cannot be obtained here since this requires GPU access.
|
||||||
if w2 > 4096 || h2 > 4096 {
|
if dstW > 4096 || dstH > 4096 {
|
||||||
m.setImg(level, nil)
|
m.setImg(level, nil)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -207,11 +207,11 @@ func (m *Mipmap) level(level int) *buffered.Image {
|
|||||||
// As s is overwritten, this doesn't have to be cleared.
|
// As s is overwritten, this doesn't have to be cleared.
|
||||||
s = img.img
|
s = img.img
|
||||||
} else {
|
} else {
|
||||||
s = buffered.NewImage(w2, h2, m.imageType)
|
s = buffered.NewImage(dstW, dstH, m.imageType)
|
||||||
}
|
}
|
||||||
|
|
||||||
dstRegion := image.Rect(0, 0, w2, h2)
|
dstRegion := image.Rect(0, 0, dstW, dstH)
|
||||||
srcRegion := image.Rect(0, 0, w, h)
|
srcRegion := image.Rect(0, 0, srcW, srcH)
|
||||||
s.DrawTriangles([graphics.ShaderSrcImageCount]*buffered.Image{src}, vs, is, graphicsdriver.BlendCopy, dstRegion, [graphics.ShaderSrcImageCount]image.Rectangle{srcRegion}, atlas.LinearFilterShader, nil, graphicsdriver.FillRuleFillAll, restorable.HintOverwriteDstRegion)
|
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)
|
m.setImg(level, s)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user