-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfadeEffect.sj
81 lines (64 loc) · 2.32 KB
/
fadeEffect.sj
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
fadeShader : shader("shaders/v3f-t2f.vert", "shaders/fade.frag")
@heap
fadeEffect #effect (
alpha := 1.0f
_rect := rect()
_vertexBuffer := empty'boxVertexBuffer
_scenebuffer := empty'scenebuffer
_innerScene : scene2d()
setAlpha(a : 'f32) { alpha = a; void }
animateAlpha(a : 'f32, duration : 'i32) {
animator.animations.add(
heap animation!f32(
startValue : alpha
endValue : a
start : animator.current
end : animator.current + duration
setValue : parent.setAlpha
) as #animation
)
void
}
getRect()'rect { _rect }
setRect(rect_ : 'rect, cb : '(:rect)void) {
if _rect != rect_ {
_rect = rect_
ifValid t1 : _scenebuffer {
if t1.size != size(_rect.w, _rect.h) {
_scenebuffer = empty'frameBuffer
}
}
_vertexBuffer = empty'boxVertexBuffer
}
cb(rect(0, 0, _rect.w, _rect.h))
void
}
render(scene : 'scene2d, cb : '(:scene2d)void) {
if isEmpty(_vertexBuffer) {
_vertexBuffer = valid(boxVertexBuffer(
rect : _rect
))
void
}
if isEmpty(_scenebuffer) {
_scenebuffer = valid(scenebuffer(size(_rect.w, _rect.h)))
}
ifValid f1 : _scenebuffer, v : _vertexBuffer {
glPushFramebuffer(f1.framebuffer)
_innerScene.setSize(f1.size)
_innerScene.start()
cb(_innerScene)
_innerScene.end()
glPopFramebuffer(f1.framebuffer)
glBindTexture(glTexture.GL_TEXTURE_2D, f1.texture)
glUseProgram(fadeShader)
glBlendFunc(glBlendFuncType.GL_SRC_ALPHA, glBlendFuncType.GL_ONE_MINUS_SRC_ALPHA)
glUniformI32(glGetUniformLocation(fadeShader, "texture"), 0)
glUniformF32(glGetUniformLocation(fadeShader, "alpha"), alpha)
glUniformMat4(glGetUniformLocation(fadeShader, "model"), scene.model)
glUniformMat4(glGetUniformLocation(fadeShader, "view"), scene.view)
glUniformMat4(glGetUniformLocation(fadeShader, "projection"), scene.projection)
v.render(scene)
}
}
) { this }