-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathshader_cache.go
More file actions
52 lines (43 loc) · 1.15 KB
/
shader_cache.go
File metadata and controls
52 lines (43 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package graphics
import (
_ "embed"
"github.com/hajimehoshi/ebiten/v2"
"github.com/quasilyte/ebitengine-graphics/internal/cache"
)
var (
//go:embed _shaders/circle.go
shaderCircleOutline []byte
//go:embed _shaders/dashed_circle.go
shaderDashedCircleOutline []byte
//go:embed _shaders/dotted_line.go
shaderDottedLine []byte
)
// CompileShaders prepares shaders bundled with this package.
// It should be called once if any of the shader-dependend objects
// are being used.
//
// Objects that require shaders so far:
// * Circle
// * DottedLine
func CompileShaders() {
if cache.Global.ShadersCompiled {
return
}
cache.Global.ShadersCompiled = true
mustCompileShader := func(src []byte) *ebiten.Shader {
s, err := ebiten.NewShader(src)
if err != nil {
panic(err)
}
return s
}
cache.Global.CircleOutlineShader = mustCompileShader(shaderCircleOutline)
cache.Global.DashedCircleOutlineShader = mustCompileShader(shaderDashedCircleOutline)
cache.Global.DottedLineShader = mustCompileShader(shaderDottedLine)
}
func requireShaders() {
if cache.Global.ShadersCompiled {
return
}
panic("call graphics.CompileShaders once to use this function")
}