]> git.tdb.fi Git - libs/gl.git/blobdiff - tests/glsl/empty_loop_removal.glsl
Remove conditional and iteration statements with no effect from GLSL
[libs/gl.git] / tests / glsl / empty_loop_removal.glsl
diff --git a/tests/glsl/empty_loop_removal.glsl b/tests/glsl/empty_loop_removal.glsl
new file mode 100644 (file)
index 0000000..5a4cf84
--- /dev/null
@@ -0,0 +1,60 @@
+uniform Lighting
+{
+       vec4 light_dir[2];
+};
+uniform Transform
+{
+       mat4 vp;
+       mat4 model;
+};
+const bool use_light = false;
+
+#pragma MSP stage(vertex)
+layout(location=0) in vec4 vertex;
+layout(location=1) in vec3 normal;
+out vec3 world_light_dir[2];
+void main()
+{
+       vec4 world_vertex = model*vertex;
+       out vec3 world_normal = mat3(model)*normal;
+       gl_Position = vp*world_vertex;
+       for(int i=0; i<2; ++i)
+               world_light_dir[i] = light_dir[i].xyz-world_vertex.xyz*light_dir[i].w;
+}
+
+#pragma MSP stage(fragment)
+layout(location=0) out vec4 frag_color;
+void main()
+{
+       vec3 color = vec3(0.1);
+       if(use_light)
+       {
+               for(int i=0; i<2; ++i)
+               {
+                       float intensity = max(dot(normalize(world_normal), world_light_dir[i]), 0.0);
+                       color += intensity;
+               }
+       }
+       frag_color = vec4(color, 1.0);
+}
+
+/* Expected output: vertex
+layout(binding=48) uniform Transform
+{
+       mat4 vp;
+       mat4 model;
+};
+layout(location=0) in vec4 vertex;
+void main()
+{
+       gl_Position = vp*model*vertex;
+}
+*/
+
+/* Expected output: fragment
+layout(location=0) out vec4 frag_color;
+void main()
+{
+       frag_color = vec4(vec3(0.1), 1.0);
+}
+*/