-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShader.go
85 lines (71 loc) · 1.92 KB
/
Shader.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package bone
import (
"github.com/EngoEngine/ecs"
"github.com/EngoEngine/engo/common"
)
var (
DragonBoneHUDShader = NewDragonBoneShader(common.HUDShader)
DragonBoneDefaultShader = NewDragonBoneShader(common.HUDShader)
)
type DragonBoneShader struct {
wrappedShader common.Shader
meshShader *basicMeshShader
culling common.CullingShader
isRenderMesh bool
}
func NewDragonBoneShader(shader common.Shader) *DragonBoneShader {
if culling, ok := shader.(common.CullingShader); ok {
return &DragonBoneShader{wrappedShader: shader, culling: culling}
}
return &DragonBoneShader{wrappedShader: shader}
}
func (db *DragonBoneShader) PrepareCulling() {
if db.culling != nil {
db.culling.PrepareCulling()
}
if db.meshShader != nil {
db.meshShader.PrepareCulling()
}
}
func (db *DragonBoneShader) ShouldDraw(rc *common.RenderComponent, sc *common.SpaceComponent) bool {
// todo
return true
}
func (db *DragonBoneShader) Pre() {
if db.meshShader == nil {
db.meshShader = &basicMeshShader{}
db.meshShader.Setup()
}
db.wrappedShader.Pre()
}
func (db *DragonBoneShader) Draw(rc *common.RenderComponent, sc *common.SpaceComponent) {
display, ok := rc.Drawable.(IDisplay)
if !ok {
return
}
display.UpdateTransform(true)
db.DrawDisplay(rc.Drawable.(IDisplay))
}
func (db *DragonBoneShader) DrawDisplay(iDisplay IDisplay) {
children := iDisplay.GetChildren()
for _, subDisplay := range children {
db.DrawDisplay(subDisplay)
}
switch display := iDisplay.(type) {
case *Sprite:
if !display.Hidden && display.Drawable != nil {
db.meshShader.Pre()
db.meshShader.Draw(display, &display.SpaceComponent)
db.meshShader.Post()
//db.wrappedShader.Draw(&display.RenderComponent, &display.SpaceComponent)
}
}
}
func (db *DragonBoneShader) Post() {
db.wrappedShader.Post()
}
func (db *DragonBoneShader) Setup(w *ecs.World) error {
return nil
}
func (db *DragonBoneShader) SetCamera(cs *common.CameraSystem) {
}