Skip to content

Commit 20d70b4

Browse files
committed
Test noise mock
1 parent 3534ace commit 20d70b4

1 file changed

Lines changed: 22 additions & 2 deletions

File tree

src/volumetric_clouds/main.clj

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,7 @@
520520
(GLFW/glfwMakeContextCurrent window)
521521
(GL/createCapabilities)
522522

523+
523524
(defn make-shader [source shader-type]
524525
(let [shader (GL20/glCreateShader shader-type)]
525526
(GL20/glShaderSource shader source)
@@ -528,6 +529,7 @@
528529
(throw (Exception. (GL20/glGetShaderInfoLog shader 1024))))
529530
shader))
530531

532+
531533
(defn make-program [& shaders]
532534
(let [program (GL20/glCreateProgram)]
533535
(doseq [shader shaders]
@@ -538,6 +540,7 @@
538540
(throw (Exception. (GL20/glGetProgramInfoLog program 1024))))
539541
program))
540542

543+
541544
(def vertex-test "
542545
#version 130
543546
in vec3 point;
@@ -546,6 +549,7 @@ void main()
546549
gl_Position = vec4(point, 1);
547550
}")
548551

552+
549553
(def fragment-test "
550554
#version 130
551555
out vec4 fragColor;
@@ -554,6 +558,7 @@ void main()
554558
fragColor = vec4(1, 1, 1, 1);
555559
}")
556560

561+
557562
(defmacro def-make-buffer [method create-buffer]
558563
`(defn ~method [data#]
559564
(let [buffer# (~create-buffer (count data#))]
@@ -656,8 +661,10 @@ void main()
656661
(GL20/glDeleteProgram program)
657662
result)))
658663

664+
659665
(render-pixels [vertex-test] [fragment-test] 1 1)
660666

667+
661668
(def noise-mock
662669
"#version 130
663670
float noise (vec3 idx)
@@ -666,6 +673,7 @@ float noise (vec3 idx)
666673
return ((v.x == 1) == (v.y == 1)) == (v.z == 1) ? 1.0 : 0.0;
667674
}")
668675

676+
669677
(def noise-probe
670678
(template/fn [x y z]
671679
"#version 130
@@ -676,8 +684,20 @@ void main()
676684
fragColor = vec4(noise(vec3(<%= x %>, <%= y %>, <%= z %>)));
677685
}"))
678686

679-
(for [z [0 1] y [0 1] x [0 1]]
680-
(nth (render-pixels [vertex-test] [noise-mock (noise-probe x y z)] 1 1) 0))
687+
(noise-probe 1 2 3)
688+
689+
(tabular "Test noise mock"
690+
(fact (nth (render-pixels [vertex-test] [noise-mock (noise-probe ?x ?y ?z)] 1 1) 0) => ?result)
691+
?x ?y ?z ?result
692+
0 0 0 0.0
693+
1 0 0 1.0
694+
0 1 0 1.0
695+
1 1 0 0.0
696+
0 0 1 1.0
697+
1 0 1 0.0
698+
0 1 1 0.0
699+
1 1 1 1.0)
700+
681701

682702
(GLFW/glfwDestroyWindow window)
683703

0 commit comments

Comments
 (0)