mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 20:18:59 +01:00
shareable: Refactoring
This commit is contained in:
parent
7a399c1b82
commit
0cc49b6923
@ -34,6 +34,11 @@ func SetGraphicsDriver(graphics driver.Graphics) {
|
|||||||
graphicsDriver = graphics
|
graphicsDriver = graphics
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
minSize = 0
|
||||||
|
maxSize = 0
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var once sync.Once
|
var once sync.Once
|
||||||
hooks.AppendHookOnBeforeUpdate(func() error {
|
hooks.AppendHookOnBeforeUpdate(func() error {
|
||||||
@ -43,30 +48,19 @@ func init() {
|
|||||||
if len(theBackends) != 0 {
|
if len(theBackends) != 0 {
|
||||||
panic("shareable: all the images must be not-shared before the game starts")
|
panic("shareable: all the images must be not-shared before the game starts")
|
||||||
}
|
}
|
||||||
shareable = true
|
if graphicsDriver.HasHighPrecisionFloat() {
|
||||||
updateSizeLimit()
|
minSize = 1024
|
||||||
|
maxSize = 4096
|
||||||
|
} else {
|
||||||
|
minSize = 512
|
||||||
|
maxSize = 512
|
||||||
|
}
|
||||||
})
|
})
|
||||||
makeImagesShared()
|
makeImagesShared()
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
|
||||||
minSize = 512
|
|
||||||
maxSize = 512
|
|
||||||
)
|
|
||||||
|
|
||||||
func updateSizeLimit() {
|
|
||||||
if !graphicsDriver.HasHighPrecisionFloat() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// Before the game starts, the texture sizes are set in a very conservative way.
|
|
||||||
// If the graphics driver supports high precision float values, allow bigger texture sizes.
|
|
||||||
minSize = 1024
|
|
||||||
maxSize = 4096
|
|
||||||
}
|
|
||||||
|
|
||||||
// MaxCountForShare represents the time duration when the image can become shared.
|
// MaxCountForShare represents the time duration when the image can become shared.
|
||||||
//
|
//
|
||||||
// This value is expoted for testing.
|
// This value is expoted for testing.
|
||||||
@ -141,17 +135,15 @@ var (
|
|||||||
theBackends = []*backend{}
|
theBackends = []*backend{}
|
||||||
|
|
||||||
imagesToMakeShared = map[*Image]struct{}{}
|
imagesToMakeShared = map[*Image]struct{}{}
|
||||||
|
|
||||||
shareable = false
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// isShareable reports whether the new allocation can use the shareable backends.
|
// isShareable reports whether the new allocation can use the shareable backends.
|
||||||
//
|
//
|
||||||
// isShareable retruns false before the graphics driver is available.
|
// isShareable retruns false before the graphics driver is available.
|
||||||
// After the graphics driver is available, read-only images will be automatically on the shareable backends by
|
// After the graphics driver is available, read-only images will be automatically on the shareable backends by
|
||||||
// makeShared().
|
// (*Image).makeShared().
|
||||||
func isShareable() bool {
|
func isShareable() bool {
|
||||||
return shareable
|
return minSize > 0 && maxSize > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
|
Loading…
Reference in New Issue
Block a user