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
package gpu_tests
import gpu ".."
import particles "../particles"
import "core:testing"
@(test)
test_particles_producer_auto_emit_and_frame_packets :: proc(t: ^testing.T) {
config := particles.Config {
max_particles = 4,
emission_rate = 100,
lifetime = {1, 1},
speed = {0, 0},
direction = {0, -1},
spread = 0,
start_color = {1, 0, 0, 1},
end_color = {1, 0, 0, 1},
start_size = 10,
end_size = 10,
gravity = {0, 0},
}
system, ok := particles.init(config, seed = 1)
testing.expect(t, ok)
defer particles.destroy(&system)
particles.update(&system, {10, 20}, 0.02)
testing.expect_value(t, particles.alive_count(&system), u32(2))
ctx := gpu.init_context(width = 640, height = 480)
frame := gpu.begin_frame(ctx)
defer gpu.destroy_frame(&frame)
_ = gpu.begin_target(&frame, gpu.present_target(ctx))
_ = gpu.push_layer(&frame, {name = "particles", order = .Sortable})
particles.draw_2d(&frame, &system)
plan := gpu.frame_runtime_plan(&frame)
defer gpu.destroy_frame_runtime_plan(&plan)
testing.expect_value(t, len(plan), 2)
mode, mode_ok := gpu.frame_runtime_mode(&frame)
testing.expect(t, mode_ok)
testing.expect(t, mode == .Generated_2D)
testing.expect(t, gpu.submit(&frame))
}
@(test)
test_particles_producer_burst_caps_at_capacity :: proc(t: ^testing.T) {
config := particles.default_config()
config.max_particles = 3
config.emission_rate = 0
config.lifetime = {1, 1}
config.speed = {0, 0}
system, ok := particles.init(config, seed = 1)
testing.expect(t, ok)
defer particles.destroy(&system)
particles.emit(&system, {0, 0}, 10)
testing.expect_value(t, particles.alive_count(&system), u32(3))
}