Added mutex to access of uniform.

This commit is contained in:
Daniel Schmidt 2023-05-12 17:45:50 +02:00
parent 3b3e9a8282
commit e7dd7bbee9
3 changed files with 14 additions and 1 deletions

View File

@ -87,6 +87,9 @@ type CrtBasic struct {
}
func (b *CrtBasic) Apply(screen *ebiten.Image, buffer *ebiten.Image) error {
b.Lock()
defer b.Unlock()
b.tick += 1 / 60.0
var options ebiten.DrawRectShaderOptions
options.GeoM.Translate(0, 0)

View File

@ -310,6 +310,9 @@ type CrtLotte struct {
}
func (s *CrtLotte) Apply(screen *ebiten.Image, buffer *ebiten.Image) error {
s.Lock()
defer s.Unlock()
s.Uniforms["ScreenSize"] = []float32{float32(screen.Bounds().Dx()), float32(screen.Bounds().Dy())}
s.Uniforms["TextureSize"] = []float32{float32(buffer.Bounds().Dx()), float32(buffer.Bounds().Dy())}

View File

@ -1,17 +1,24 @@
package shader
import "github.com/hajimehoshi/ebiten/v2"
import (
"github.com/hajimehoshi/ebiten/v2"
"sync"
)
type Shader interface {
Apply(screen *ebiten.Image, buffer *ebiten.Image) error
}
type BaseShader struct {
sync.Mutex
Shader *ebiten.Shader
Uniforms map[string]any
}
func (b *BaseShader) Apply(screen *ebiten.Image, buffer *ebiten.Image) error {
b.Lock()
defer b.Unlock()
var options ebiten.DrawRectShaderOptions
options.GeoM.Translate(0, 0)
options.Images[0] = buffer