updated ebiten version from 2.7.9 to 2.9.9

This commit is contained in:
2026-06-15 19:06:55 +02:00
parent 21edbc41c4
commit db1b625069
405 changed files with 31913 additions and 12595 deletions
+8 -7
View File
@@ -24,8 +24,9 @@ import (
// ManagedBytes is useful when its lifetime is explicit, as the underlying byte slice can be reused for another ManagedBytes later.
// This can reduce allocations and GCs.
type ManagedBytes struct {
bytes []byte
pool *bytesPool
bytes []byte
pool *bytesPool
cleanup runtime.Cleanup
}
// Len returns the length of the slice.
@@ -55,7 +56,7 @@ func (m *ManagedBytes) GetAndRelease() ([]byte, func()) {
m.bytes = nil
return bs, func() {
m.pool.put(bs)
runtime.SetFinalizer(m, nil)
m.cleanup.Stop()
}
}
@@ -65,7 +66,7 @@ func (m *ManagedBytes) GetAndRelease() ([]byte, func()) {
func (m *ManagedBytes) Release() {
m.pool.put(m.bytes)
m.bytes = nil
runtime.SetFinalizer(m, nil)
m.cleanup.Stop()
}
// NewManagedBytes returns a managed byte slice initialized by the given constructor f.
@@ -94,9 +95,9 @@ func (b *bytesPool) get(size int) *ManagedBytes {
bytes: bs,
pool: b,
}
runtime.SetFinalizer(m, func(m *ManagedBytes) {
b.put(m.bytes)
})
m.cleanup = runtime.AddCleanup(m, func(bytes []byte) {
b.put(bytes)
}, m.bytes)
return m
}
+25 -8
View File
@@ -89,9 +89,9 @@ var __imageSrcRegionSizes [%[1]d]vec2
func imageSrcRegionOnTexture() (vec2, vec2) {
return __imageSrcRegionOrigins[0], __imageSrcRegionSizes[0]
}
`, ShaderImageCount)
`, ShaderSrcImageCount)
for i := 0; i < ShaderImageCount; i++ {
for i := 0; i < ShaderSrcImageCount; i++ {
shaderSuffix += fmt.Sprintf(`
// imageSrc%[1]dOrigin returns the source image's region origin on its texture.
// The unit is the source texture's pixel or texel.
@@ -154,15 +154,15 @@ func imageSrc%[1]dAt(pos vec2) vec4 {
shaderSuffix += `
var __projectionMatrix mat4
func __vertex(dstPos vec2, srcPos vec2, color vec4) (vec4, vec2, vec4) {
return __projectionMatrix * vec4(dstPos, 0, 1), srcPos, color
func __vertex(dstPos vec2, srcPos vec2, color vec4, custom vec4) (vec4, vec2, vec4, vec4) {
return __projectionMatrix * vec4(dstPos, 0, 1), srcPos, color, custom
}
`
return shaderSuffix, nil
}
func CompileShader(src []byte) (*shaderir.Program, error) {
unit, err := shader.ParseCompilerDirectives(src)
func completeShaderSource(fragmentSrc []byte) ([]byte, error) {
unit, err := shader.ParseCompilerDirectives(fragmentSrc)
if err != nil {
return nil, err
}
@@ -172,14 +172,23 @@ func CompileShader(src []byte) (*shaderir.Program, error) {
}
var buf bytes.Buffer
buf.Write(src)
buf.Write(fragmentSrc)
buf.WriteString(suffix)
return buf.Bytes(), nil
}
func CompileShader(fragmentSrc []byte) (*shaderir.Program, error) {
src, err := completeShaderSource(fragmentSrc)
if err != nil {
return nil, err
}
const (
vert = "__vertex"
frag = "Fragment"
)
ir, err := shader.Compile(buf.Bytes(), vert, frag, ShaderImageCount)
ir, err := shader.Compile(src, vert, frag, ShaderSrcImageCount)
if err != nil {
return nil, err
}
@@ -193,3 +202,11 @@ func CompileShader(src []byte) (*shaderir.Program, error) {
return ir, nil
}
func CalcSourceHash(fragmentSrc []byte) (shaderir.SourceHash, error) {
src, err := completeShaderSource(fragmentSrc)
if err != nil {
return shaderir.SourceHash{}, err
}
return shaderir.CalcSourceHash(src), nil
}
+88 -34
View File
@@ -15,7 +15,7 @@
package graphics
const (
ShaderImageCount = 4
ShaderSrcImageCount = 4
// PreservedUniformVariablesCount represents the number of preserved uniform variables.
// Any shaders in Ebitengine must have these uniform variables.
@@ -29,17 +29,24 @@ const (
ProjectionMatrixUniformVariableIndex = 6
PreservedUniformUint32Count = 2 + // the destination texture size
2*ShaderImageCount + // the source texture sizes array
PreservedUniformDwordCount = 2 + // the destination texture size
2*ShaderSrcImageCount + // the source texture sizes array
2 + // the destination image region origin
2 + // the destination image region size
2*ShaderImageCount + // the source image region origins array
2*ShaderImageCount + // the source image region sizes array
2*ShaderSrcImageCount + // the source image region origins array
2*ShaderSrcImageCount + // the source image region sizes array
16 // the projection matrix
ProjectionMatrixUniformDwordIndex = 2 +
2*ShaderSrcImageCount +
2 +
2 +
2*ShaderSrcImageCount +
2*ShaderSrcImageCount
)
const (
VertexFloatCount = 8
VertexFloatCount = 12
)
var (
@@ -50,16 +57,16 @@ func QuadIndices() []uint32 {
return quadIndices
}
// QuadVertices sets a float32 slice for a quadrangle.
// QuadVertices sets a slice that never overlaps with other slices returned this function,
// and users can do optimization based on this fact.
func QuadVertices(dst []float32, sx0, sy0, sx1, sy1 float32, a, b, c, d, tx, ty float32, cr, cg, cb, ca float32) {
// QuadVerticesFromSrcAndMatrix sets a float32 slice for a quadrangle.
func QuadVerticesFromSrcAndMatrix(dst []float32, sx0, sy0, sx1, sy1 float32, a, b, c, d, tx, ty float32, cr, cg, cb, ca float32) {
x := sx1 - sx0
y := sy1 - sy0
ax, by, cx, dy := a*x, b*y, c*x, d*y
u0, v0, u1, v1 := sx0, sy0, sx1, sy1
// This function is very performance-sensitive and implement in a very dumb way.
// Remove the boundary check.
dst = dst[:4*VertexFloatCount]
dst[0] = adjustDestinationPixel(tx)
@@ -71,32 +78,79 @@ func QuadVertices(dst []float32, sx0, sy0, sx1, sy1 float32, a, b, c, d, tx, ty
dst[6] = cb
dst[7] = ca
dst[8] = adjustDestinationPixel(ax + tx)
dst[9] = adjustDestinationPixel(cx + ty)
dst[10] = u1
dst[11] = v0
dst[12] = cr
dst[13] = cg
dst[14] = cb
dst[15] = ca
dst[VertexFloatCount] = adjustDestinationPixel(ax + tx)
dst[VertexFloatCount+1] = adjustDestinationPixel(cx + ty)
dst[VertexFloatCount+2] = u1
dst[VertexFloatCount+3] = v0
dst[VertexFloatCount+4] = cr
dst[VertexFloatCount+5] = cg
dst[VertexFloatCount+6] = cb
dst[VertexFloatCount+7] = ca
dst[16] = adjustDestinationPixel(by + tx)
dst[17] = adjustDestinationPixel(dy + ty)
dst[18] = u0
dst[19] = v1
dst[20] = cr
dst[21] = cg
dst[22] = cb
dst[23] = ca
dst[2*VertexFloatCount] = adjustDestinationPixel(by + tx)
dst[2*VertexFloatCount+1] = adjustDestinationPixel(dy + ty)
dst[2*VertexFloatCount+2] = u0
dst[2*VertexFloatCount+3] = v1
dst[2*VertexFloatCount+4] = cr
dst[2*VertexFloatCount+5] = cg
dst[2*VertexFloatCount+6] = cb
dst[2*VertexFloatCount+7] = ca
dst[24] = adjustDestinationPixel(ax + by + tx)
dst[25] = adjustDestinationPixel(cx + dy + ty)
dst[26] = u1
dst[27] = v1
dst[28] = cr
dst[29] = cg
dst[30] = cb
dst[31] = ca
dst[3*VertexFloatCount] = adjustDestinationPixel(ax + by + tx)
dst[3*VertexFloatCount+1] = adjustDestinationPixel(cx + dy + ty)
dst[3*VertexFloatCount+2] = u1
dst[3*VertexFloatCount+3] = v1
dst[3*VertexFloatCount+4] = cr
dst[3*VertexFloatCount+5] = cg
dst[3*VertexFloatCount+6] = cb
dst[3*VertexFloatCount+7] = ca
}
// QuadVerticesFromDstAndSrc sets a float32 slice for a quadrangle.
func QuadVerticesFromDstAndSrc(dst []float32, dx0, dy0, dx1, dy1, sx0, sy0, sx1, sy1, cr, cg, cb, ca float32) {
dx0 = adjustDestinationPixel(dx0)
dy0 = adjustDestinationPixel(dy0)
dx1 = adjustDestinationPixel(dx1)
dy1 = adjustDestinationPixel(dy1)
// Remove the boundary check.
dst = dst[:4*VertexFloatCount]
dst[0] = dx0
dst[1] = dy0
dst[2] = sx0
dst[3] = sy0
dst[4] = cr
dst[5] = cg
dst[6] = cb
dst[7] = ca
dst[VertexFloatCount] = dx1
dst[VertexFloatCount+1] = dy0
dst[VertexFloatCount+2] = sx1
dst[VertexFloatCount+3] = sy0
dst[VertexFloatCount+4] = cr
dst[VertexFloatCount+5] = cg
dst[VertexFloatCount+6] = cb
dst[VertexFloatCount+7] = ca
dst[2*VertexFloatCount] = dx0
dst[2*VertexFloatCount+1] = dy1
dst[2*VertexFloatCount+2] = sx0
dst[2*VertexFloatCount+3] = sy1
dst[2*VertexFloatCount+4] = cr
dst[2*VertexFloatCount+5] = cg
dst[2*VertexFloatCount+6] = cb
dst[2*VertexFloatCount+7] = ca
dst[3*VertexFloatCount] = dx1
dst[3*VertexFloatCount+1] = dy1
dst[3*VertexFloatCount+2] = sx1
dst[3*VertexFloatCount+3] = sy1
dst[3*VertexFloatCount+4] = cr
dst[3*VertexFloatCount+5] = cg
dst[3*VertexFloatCount+6] = cb
dst[3*VertexFloatCount+7] = ca
}
func adjustDestinationPixel(x float32) float32 {