updated ebiten version from 2.7.9 to 2.9.9
This commit is contained in:
+28
-62
@@ -15,43 +15,41 @@
|
||||
package atlas
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"runtime"
|
||||
|
||||
"golang.org/x/sync/errgroup"
|
||||
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/builtinshader"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphics"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/graphicscommand"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/restorable"
|
||||
"github.com/hajimehoshi/ebiten/v2/internal/shaderir"
|
||||
)
|
||||
|
||||
type Shader struct {
|
||||
ir *shaderir.Program
|
||||
shader *graphicscommand.Shader
|
||||
ir *shaderir.Program
|
||||
shader *restorable.Shader
|
||||
unit shaderir.Unit
|
||||
name string
|
||||
cleanup runtime.Cleanup
|
||||
}
|
||||
|
||||
func NewShader(ir *shaderir.Program) *Shader {
|
||||
func NewShader(ir *shaderir.Program, name string) *Shader {
|
||||
// A shader is initialized lazily, and the lock is not needed.
|
||||
return &Shader{
|
||||
ir: ir,
|
||||
ir: ir,
|
||||
name: name,
|
||||
unit: ir.Unit,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shader) finalize() {
|
||||
// A function from finalizer must not be blocked, but disposing operation can be blocked.
|
||||
// Defer this operation until it becomes safe. (#913)
|
||||
appendDeferred(func() {
|
||||
s.deallocate()
|
||||
})
|
||||
}
|
||||
|
||||
func (s *Shader) ensureShader() *graphicscommand.Shader {
|
||||
func (s *Shader) ensureShader() *restorable.Shader {
|
||||
if s.shader != nil {
|
||||
return s.shader
|
||||
}
|
||||
s.shader = graphicscommand.NewShader(s.ir)
|
||||
runtime.SetFinalizer(s, (*Shader).finalize)
|
||||
s.shader = restorable.NewShader(s.ir, s.name)
|
||||
s.cleanup = runtime.AddCleanup(s, func(shader *restorable.Shader) {
|
||||
// A function from cleanup must not be blocked, but disposing operation can be blocked.
|
||||
// Defer this operation until it becomes safe. (#913)
|
||||
appendDeferred(func() {
|
||||
shader.Dispose()
|
||||
})
|
||||
}, s.shader)
|
||||
return s.shader
|
||||
}
|
||||
|
||||
@@ -71,7 +69,7 @@ func (s *Shader) Deallocate() {
|
||||
}
|
||||
|
||||
func (s *Shader) deallocate() {
|
||||
runtime.SetFinalizer(s, nil)
|
||||
s.cleanup.Stop()
|
||||
if s.shader == nil {
|
||||
return
|
||||
}
|
||||
@@ -80,44 +78,12 @@ func (s *Shader) deallocate() {
|
||||
}
|
||||
|
||||
var (
|
||||
NearestFilterShader *Shader
|
||||
LinearFilterShader *Shader
|
||||
clearShader *Shader
|
||||
)
|
||||
|
||||
func init() {
|
||||
var wg errgroup.Group
|
||||
wg.Go(func() error {
|
||||
ir, err := graphics.CompileShader([]byte(builtinshader.Shader(builtinshader.FilterNearest, builtinshader.AddressUnsafe, false)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("atlas: compiling the nearest shader failed: %w", err)
|
||||
}
|
||||
NearestFilterShader = NewShader(ir)
|
||||
return nil
|
||||
})
|
||||
wg.Go(func() error {
|
||||
ir, err := graphics.CompileShader([]byte(builtinshader.Shader(builtinshader.FilterLinear, builtinshader.AddressUnsafe, false)))
|
||||
if err != nil {
|
||||
return fmt.Errorf("atlas: compiling the linear shader failed: %w", err)
|
||||
}
|
||||
LinearFilterShader = NewShader(ir)
|
||||
return nil
|
||||
})
|
||||
wg.Go(func() error {
|
||||
ir, err := graphics.CompileShader([]byte(`//kage:unit pixels
|
||||
|
||||
package main
|
||||
|
||||
func Fragment(dstPos vec4, srcPos vec2, color vec4) vec4 {
|
||||
return vec4(0)
|
||||
}`))
|
||||
if err != nil {
|
||||
return fmt.Errorf("atlas: compiling the clear shader failed: %w", err)
|
||||
}
|
||||
clearShader = NewShader(ir)
|
||||
return nil
|
||||
})
|
||||
if err := wg.Wait(); err != nil {
|
||||
panic(err)
|
||||
NearestFilterShader = &Shader{
|
||||
shader: restorable.NearestFilterShader,
|
||||
unit: restorable.NearestFilterShader.Unit(),
|
||||
}
|
||||
}
|
||||
LinearFilterShader = &Shader{
|
||||
shader: restorable.LinearFilterShader,
|
||||
unit: restorable.LinearFilterShader.Unit(),
|
||||
}
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user