-
-
Notifications
You must be signed in to change notification settings - Fork 290
/
glmakie_refimages.jl
107 lines (97 loc) · 3.4 KB
/
glmakie_refimages.jl
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using GLMakie.Makie: Record
using GLMakie.GLFW
using GLMakie.ModernGL
using GLMakie.ShaderAbstractions
using GLMakie.ShaderAbstractions: Sampler
using GLMakie.GeometryBasics
using ReferenceTests.RNG
# A test case for wide lines and mitering at joints
@reference_test "Miter Joints for line rendering" begin
scene = Scene()
cam2d!(scene)
r = 4
sep = 4*r
scatter!(scene, (sep+2*r)*[-1,-1,1,1], (sep+2*r)*[-1,1,-1,1])
for i=-1:1
for j=-1:1
angle = pi/2 + pi/4*i
x = r*[-cos(angle/2),0,-cos(angle/2)]
y = r*[-sin(angle/2),0,sin(angle/2)]
linewidth = 40 * 2.0^j
lines!(scene, x .+ sep*i, y .+ sep*j, color=RGBAf(0,0,0,0.5), linewidth=linewidth)
lines!(scene, x .+ sep*i, y .+ sep*j, color=:red)
end
end
center!(scene)
scene
end
@reference_test "Sampler type" begin
# Directly access texture parameters:
x = Sampler(fill(to_color(:yellow), 100, 100), minfilter=:nearest)
scene = image(x)
# indexing will go straight to the GPU, while only transfering the changes
st = Stepper(scene)
x[1:10, 1:50] .= to_color(:red)
Makie.step!(st)
x[1:10, end] .= to_color(:green)
Makie.step!(st)
x[end, end] = to_color(:blue)
Makie.step!(st)
st
end
# Test for resizing of TextureBuffer
@reference_test "Dynamically adjusting number of particles in a meshscatter" begin
pos = Observable(RNG.rand(Point3f, 2))
rot = Observable(RNG.rand(Vec3f, 2))
color = Observable(RNG.rand(RGBf, 2))
size = Observable(0.1*RNG.rand(2))
makenew = Observable(1)
on(makenew) do i
pos[] = RNG.rand(Point3f, i)
rot[] = RNG.rand(Vec3f, i)
color[] = RNG.rand(RGBf, i)
size[] = 0.1*RNG.rand(i)
end
fig, ax, p = meshscatter(pos,
rotations=rot,
color=color,
markersize=size,
axis = (; scenekw = (;limits=Rect3f(Point3(0), Point3(1))))
)
update_cam!(ax.scene, Point3f(2.224431, 2.224431, 2.128731), Point3f(0.5957, 0.5957, 0.50000006))
Record(fig, [10, 5, 100, 60, 177]) do i
makenew[] = i
end
end
@reference_test "Explicit frame rendering" begin
function update_loop(m, buff, screen)
for i = 1:20
GLFW.PollEvents()
buff .= RNG.rand.(Point3f) .* 20f0
m[1] = buff
GLMakie.render_frame(screen)
GLFW.SwapBuffers(GLMakie.to_native(screen))
glFinish()
end
end
fig, ax, meshplot = meshscatter(RNG.rand(Point3f, 10^4) .* 20f0)
update_cam!(ax.scene, Point3f(45.383663, 45.38298, 43.136826), Point3f(12.246061, 12.245379, 9.999225))
screen = display(GLMakie.Screen(;renderloop=(screen) -> nothing, start_renderloop=false), fig.scene)
buff = RNG.rand(Point3f, 10^4) .* 20f0;
update_loop(meshplot, buff, screen)
@test isnothing(screen.rendertask)
GLMakie.destroy!(screen)
fig
end
@reference_test "Contour and isosurface with correct depth" begin
# Make sure shaders can recompile
GLMakie.closeall()
fig = Figure()
left = LScene(fig[1, 1])
contour!(left, [sin(i+j) * sin(j+k) * sin(i+k) for i in 1:10, j in 1:10, k in 1:10], enable_depth = true)
mesh!(left, Sphere(Point3f(5), 6f0))
right = LScene(fig[1, 2])
volume!(right, [sin(2i) * sin(2j) * sin(2k) for i in 1:10, j in 1:10, k in 1:10], algorithm = :iso, enable_depth = true)
mesh!(right, Sphere(Point3f(5), 6f0))
fig
end