mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-13 12:32:05 +01:00
Revert "shareable: Implement extending shareable texture again"
This reverts commit b474946619
.
Reason: #567
This commit is contained in:
parent
2110191794
commit
b92bc6f21c
@ -34,43 +34,6 @@ type backend struct {
|
|||||||
page *packing.Page
|
page *packing.Page
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *backend) TryAlloc(width, height int) (*packing.Node, bool) {
|
|
||||||
// If the region is allocated without any extention, it's fine.
|
|
||||||
if n := b.page.Alloc(width, height); n != nil {
|
|
||||||
return n, true
|
|
||||||
}
|
|
||||||
|
|
||||||
// Simulate the extending the page and calculate the appropriate page size.
|
|
||||||
page := b.page.Clone()
|
|
||||||
nExtended := 0
|
|
||||||
for {
|
|
||||||
if !page.Extend() {
|
|
||||||
// The page can't be extended any more. Return as failure.
|
|
||||||
return nil, false
|
|
||||||
}
|
|
||||||
nExtended++
|
|
||||||
if n := page.Alloc(width, height); n != nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for i := 0; i < nExtended; i++ {
|
|
||||||
b.page.Extend()
|
|
||||||
}
|
|
||||||
s := b.page.Size()
|
|
||||||
newImg := restorable.NewImage(s, s, false)
|
|
||||||
w, h := b.restorable.Size()
|
|
||||||
newImg.DrawImage(b.restorable, 0, 0, w, h, nil, nil, opengl.CompositeModeCopy, graphics.FilterNearest)
|
|
||||||
b.restorable.Dispose()
|
|
||||||
b.restorable = newImg
|
|
||||||
|
|
||||||
n := b.page.Alloc(width, height)
|
|
||||||
if n == nil {
|
|
||||||
panic("not reached")
|
|
||||||
}
|
|
||||||
return n, true
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// backendsM is a mutex for critical sections of the backend and packing.Node objects.
|
// backendsM is a mutex for critical sections of the backend and packing.Node objects.
|
||||||
backendsM sync.Mutex
|
backendsM sync.Mutex
|
||||||
@ -216,10 +179,7 @@ func (s *Image) IsInvalidated() (bool, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewImage(width, height int) *Image {
|
func NewImage(width, height int) *Image {
|
||||||
const (
|
const maxSize = 2048
|
||||||
initSize = 1024
|
|
||||||
maxSize = 4096
|
|
||||||
)
|
|
||||||
|
|
||||||
backendsM.Lock()
|
backendsM.Lock()
|
||||||
defer backendsM.Unlock()
|
defer backendsM.Unlock()
|
||||||
@ -233,34 +193,26 @@ func NewImage(width, height int) *Image {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, b := range theBackends {
|
for _, s := range theBackends {
|
||||||
if n, ok := b.TryAlloc(width, height); ok {
|
if n := s.page.Alloc(width, height); n != nil {
|
||||||
return &Image{
|
return &Image{
|
||||||
backend: b,
|
backend: s,
|
||||||
node: n,
|
node: n,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size := initSize
|
s := &backend{
|
||||||
for width > size || height > size {
|
restorable: restorable.NewImage(maxSize, maxSize, false),
|
||||||
if size == maxSize {
|
page: packing.NewPage(maxSize, maxSize), // TODO: Utilize 'Extend' page.
|
||||||
panic("not reached")
|
|
||||||
}
|
|
||||||
size *= 2
|
|
||||||
}
|
}
|
||||||
|
theBackends = append(theBackends, s)
|
||||||
|
|
||||||
b := &backend{
|
n := s.page.Alloc(width, height)
|
||||||
restorable: restorable.NewImage(size, size, false),
|
|
||||||
page: packing.NewPage(size, maxSize),
|
|
||||||
}
|
|
||||||
theBackends = append(theBackends, b)
|
|
||||||
|
|
||||||
n := b.page.Alloc(width, height)
|
|
||||||
if n == nil {
|
if n == nil {
|
||||||
panic("not reached")
|
panic("not reached")
|
||||||
}
|
}
|
||||||
i := &Image{
|
i := &Image{
|
||||||
backend: b,
|
backend: s,
|
||||||
node: n,
|
node: n,
|
||||||
}
|
}
|
||||||
runtime.SetFinalizer(i, (*Image).Dispose)
|
runtime.SetFinalizer(i, (*Image).Dispose)
|
||||||
|
Loading…
Reference in New Issue
Block a user