ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_cull_distance / fs-cull-distance-interpolated.shader_test
blob3dba7e1a909875c1fc4213b6e65aea144a636c7d
1 # From the ARB_cull_distance spec:
3 #   In the fragment language, gl_CullDistance array contains linearly
4 #   interpolated values for the vertex values written by a shader to the
5 #   gl_CullDistance vertex output variable.
7 # This test checks proper operation of gl_CullDistance in fragment
8 # shaders by setting each element of gl_CullDistance to simple linear
9 # function of gl_Vertex (computed by taking the dot product of
10 # gl_Vertex with a uniform vector, and dividing the result by
11 # gl_Vertex's homogeneous coordinate).  gl_Vertex is also passed
12 # through to the fragment shader, which uses the same dot product to
13 # verify that gl_CullDistance has been properly interpolated.
15 [require]
16 GLSL >= 1.30
17 GL_ARB_cull_distance
19 [vertex shader]
20 #version 130
21 #extension GL_ARB_cull_distance: enable
22 uniform vec4 transform[6];
23 out vec4 vertex;
24 out float gl_CullDistance[6];
26 void main()
28   gl_Position = gl_Vertex;
30   // Set each value of gl_CullDistance to a linear transformation of
31   // gl_Vertex.
32   for (int i = 0; i < 6; ++i) {
33     gl_CullDistance[i] = dot(transform[i], gl_Vertex) / gl_Vertex.w;
34   }
36   // Pass through gl_Vertex to the fragment shader so that it can
37   // verify the interpolated values of gl_CullDistance.
38   vertex = gl_Vertex;
41 [fragment shader]
42 #version 130
43 #extension GL_ARB_cull_distance: enable
44 uniform vec4 transform[6];
45 in vec4 vertex;
46 in float gl_CullDistance[6];
48 void main()
50   bool test_passed = true;
52   // Check that each value of gl_CullDistance matches the value
53   // computed in the vertex shader.
54   for (int i = 0; i < 6; ++i) {
55     float expected_distance = dot(transform[i], vertex) / vertex.w;
56     float deviation = distance(gl_CullDistance[i], expected_distance);
57     if (deviation > 1.0e-5) {
58       test_passed = false;
59     }
60   }
62   // Report pass/fail as a red or green pixel.
63   gl_FragColor = test_passed ? vec4(0.0, 1.0, 0.0, 1.0)
64                              : vec4(1.0, 0.0, 0.0, 1.0);
67 [test]
68 uniform vec4 transform[0]  1.0  1.0 0.0 0.0 # cullDistance[0] = x + y
69 uniform vec4 transform[1]  1.0  2.0 0.0 0.0 # cullDistance[1] = x + 2*y
70 uniform vec4 transform[2]  2.0  1.0 0.0 0.0 # cullDistance[2] = 2*x + y
71 uniform vec4 transform[3]  2.0  2.0 0.0 0.0 # cullDistance[3] = 2*x + 2*y
72 uniform vec4 transform[4] -1.0 -1.0 0.0 2.0 # cullDistance[4] = 2.0 - x - y
73 uniform vec4 transform[5] -1.0  1.0 0.0 1.0 # cullDistance[5] = 1.0 - x + y
75 draw rect -1 -1 2 2
76 probe all rgba 0.0 1.0 0.0 1.0