mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
internal/atlas: refactoring: use moveTo to make an image isolated
This reduces backend allocations by &backend{...}. Updates #2581
This commit is contained in:
parent
0720ec2251
commit
d947cf0da0
@ -256,47 +256,24 @@ func (i *Image) ensureIsolated() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ox, oy, w, h := i.regionWithPadding()
|
newI := NewImage(i.width, i.height, i.imageType)
|
||||||
dx0 := float32(0)
|
|
||||||
dy0 := float32(0)
|
// Call allocate explicitly in order to have an isolated backend.
|
||||||
dx1 := float32(w)
|
newI.allocate(false)
|
||||||
dy1 := float32(h)
|
|
||||||
sx0 := float32(ox)
|
w, h := float32(i.width), float32(i.height)
|
||||||
sy0 := float32(oy)
|
vs := make([]float32, 4*graphics.VertexFloatCount)
|
||||||
sx1 := float32(ox + w)
|
graphics.QuadVertices(vs, 0, 0, w, h, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1)
|
||||||
sy1 := float32(oy + h)
|
|
||||||
sw, sh := i.backend.restorable.InternalSize()
|
|
||||||
sx0 /= float32(sw)
|
|
||||||
sy0 /= float32(sh)
|
|
||||||
sx1 /= float32(sw)
|
|
||||||
sy1 /= float32(sh)
|
|
||||||
typ := restorable.ImageTypeRegular
|
|
||||||
if i.imageType == ImageTypeVolatile {
|
|
||||||
typ = restorable.ImageTypeVolatile
|
|
||||||
}
|
|
||||||
newImg := restorable.NewImage(w, h, typ)
|
|
||||||
vs := []float32{
|
|
||||||
dx0, dy0, sx0, sy0, 1, 1, 1, 1,
|
|
||||||
dx1, dy0, sx1, sy0, 1, 1, 1, 1,
|
|
||||||
dx0, dy1, sx0, sy1, 1, 1, 1, 1,
|
|
||||||
dx1, dy1, sx1, sy1, 1, 1, 1, 1,
|
|
||||||
}
|
|
||||||
is := graphics.QuadIndices()
|
is := graphics.QuadIndices()
|
||||||
srcs := [graphics.ShaderImageCount]*restorable.Image{i.backend.restorable}
|
dr := graphicsdriver.Region{
|
||||||
var offsets [graphics.ShaderImageCount - 1][2]float32
|
X: 0,
|
||||||
dstRegion := graphicsdriver.Region{
|
Y: 0,
|
||||||
X: float32(i.paddingSize()),
|
Width: w,
|
||||||
Y: float32(i.paddingSize()),
|
Height: h,
|
||||||
Width: float32(w - 2*i.paddingSize()),
|
|
||||||
Height: float32(h - 2*i.paddingSize()),
|
|
||||||
}
|
|
||||||
newImg.DrawTriangles(srcs, offsets, vs, is, graphicsdriver.BlendCopy, dstRegion, graphicsdriver.Region{}, NearestFilterShader.shader, nil, false)
|
|
||||||
|
|
||||||
i.dispose(false)
|
|
||||||
i.backend = &backend{
|
|
||||||
restorable: newImg,
|
|
||||||
}
|
}
|
||||||
|
newI.drawTriangles([graphics.ShaderImageCount]*Image{i}, vs, is, graphicsdriver.BlendCopy, dr, graphicsdriver.Region{}, [graphics.ShaderImageCount - 1][2]float32{}, NearestFilterShader, nil, false, true)
|
||||||
|
|
||||||
|
newI.moveTo(i)
|
||||||
i.isolatedCount++
|
i.isolatedCount++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user