mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-26 02:42:02 +01:00
internal/atlas, initernal/graphics: Better buffer size calculation
This commit is contained in:
parent
d236d73a1f
commit
0238549cfb
@ -59,7 +59,7 @@ func temporaryPixelsByteSize(size int) int {
|
||||
// Be careful that the returned pixels might not be zero-cleared.
|
||||
func (t *temporaryPixels) alloc(size int) []byte {
|
||||
if len(t.pixels) < t.pos+size {
|
||||
t.pixels = make([]byte, temporaryPixelsByteSize(t.pos+size))
|
||||
t.pixels = make([]byte, max(len(t.pixels)*2, temporaryPixelsByteSize(size)))
|
||||
t.pos = 0
|
||||
}
|
||||
pix := t.pixels[t.pos : t.pos+size]
|
||||
|
@ -75,13 +75,20 @@ func verticesBackendFloat32Size(size int) int {
|
||||
return l
|
||||
}
|
||||
|
||||
func max(a, b int) int {
|
||||
if a > b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (v *verticesBackend) slice(n int) []float32 {
|
||||
v.m.Lock()
|
||||
defer v.m.Unlock()
|
||||
|
||||
need := n * VertexFloatNum
|
||||
if len(v.backend) < v.pos+need {
|
||||
v.backend = make([]float32, verticesBackendFloat32Size(v.pos+need))
|
||||
v.backend = make([]float32, max(len(v.backend)*2, verticesBackendFloat32Size(need)))
|
||||
v.pos = 0
|
||||
}
|
||||
s := v.backend[v.pos : v.pos+need]
|
||||
|
Loading…
Reference in New Issue
Block a user