mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
Revert "internal/restorable: integrate Image.Extend into internal/atlas"
This reverts commit 6151fd313f
.
Updates #3083
This commit is contained in:
parent
54c117b0de
commit
104cc18477
@ -122,39 +122,14 @@ func (b *backend) tryAlloc(width, height int) (*packing.Node, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
b.extendIfNeeded(b.page.Size())
|
||||
w, h := b.page.Size()
|
||||
b.restorable = b.restorable.Extend(w, h)
|
||||
b.width = w
|
||||
b.height = h
|
||||
|
||||
return n, true
|
||||
}
|
||||
|
||||
// extendIfNeeded extends the image by the given size if necessary.
|
||||
// extendIfNeeded creates a new image with the given size and copies the pixels of the given source image.
|
||||
// extendIfNeeded disposes an old image after its call when a new image is created.
|
||||
func (b *backend) extendIfNeeded(width, height int) {
|
||||
if b.width >= width && b.height >= height {
|
||||
return
|
||||
}
|
||||
|
||||
// Assume that the screen image is never extended.
|
||||
newImg := restorable.NewImage(width, height, false)
|
||||
|
||||
// Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
|
||||
// information.
|
||||
srcs := [graphics.ShaderSrcImageCount]*graphicscommand.Image{b.restorable.Image}
|
||||
sw, sh := b.restorable.Image.InternalSize()
|
||||
vs := make([]float32, 4*graphics.VertexFloatCount)
|
||||
graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := image.Rect(0, 0, sw, sh)
|
||||
newImg.Image.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, NearestFilterShader.ensureShader().Shader, nil, graphicsdriver.FillRuleFillAll)
|
||||
b.restorable.Image.Dispose()
|
||||
b.restorable.Image = nil
|
||||
|
||||
b.restorable = newImg
|
||||
b.width = width
|
||||
b.height = height
|
||||
}
|
||||
|
||||
var (
|
||||
// backendsM is a mutex for critical sections of the backend and packing.Node objects.
|
||||
backendsM sync.Mutex
|
||||
|
@ -52,6 +52,32 @@ func NewImage(width, height int, screen bool) *Image {
|
||||
return i
|
||||
}
|
||||
|
||||
// Extend extends the image by the given size.
|
||||
// Extend creates a new image with the given size and copies the pixels of the given source image.
|
||||
// Extend disposes itself after its call.
|
||||
func (i *Image) Extend(width, height int) *Image {
|
||||
if i.width >= width && i.height >= height {
|
||||
return i
|
||||
}
|
||||
|
||||
// Assume that the screen image is never extended.
|
||||
newImg := NewImage(width, height, false)
|
||||
|
||||
// Use DrawTriangles instead of WritePixels because the image i might be stale and not have its pixels
|
||||
// information.
|
||||
srcs := [graphics.ShaderSrcImageCount]*graphicscommand.Image{i.Image}
|
||||
sw, sh := i.Image.InternalSize()
|
||||
vs := make([]float32, 4*graphics.VertexFloatCount)
|
||||
graphics.QuadVerticesFromDstAndSrc(vs, 0, 0, float32(sw), float32(sh), 0, 0, float32(sw), float32(sh), 1, 1, 1, 1)
|
||||
is := graphics.QuadIndices()
|
||||
dr := image.Rect(0, 0, sw, sh)
|
||||
newImg.Image.DrawTriangles(srcs, vs, is, graphicsdriver.BlendCopy, dr, [graphics.ShaderSrcImageCount]image.Rectangle{}, NearestFilterShader.Shader, nil, graphicsdriver.FillRuleFillAll)
|
||||
i.Image.Dispose()
|
||||
i.Image = nil
|
||||
|
||||
return newImg
|
||||
}
|
||||
|
||||
func clearImage(i *graphicscommand.Image, region image.Rectangle) {
|
||||
vs := make([]float32, 4*graphics.VertexFloatCount)
|
||||
graphics.QuadVerticesFromDstAndSrc(vs, float32(region.Min.X), float32(region.Min.Y), float32(region.Max.X), float32(region.Max.Y), 0, 0, 0, 0, 0, 0, 0, 0)
|
||||
|
Loading…
Reference in New Issue
Block a user