arb_program_interface_query: set vs_input2[1][0] as valid name
[piglit.git] / tests / spec / glsl-1.30 / execution / clipping / fs-clip-distance-interpolated.shader_test
blob0721e7bbd28b21f6e13ea4e659aecda480489368
1 # From the GLSL 1.30 spec, section 7.2 (Fragment Shader Special
2 # Variables):
4 #   The built-in input variable gl_ClipDistance array contains
5 #   linearly interpolated values for the vertex values written by the
6 #   vertex shader to the gl_ClipDistance vertex output variable. This
7 #   array must be sized in the fragment shader either implicitly or
8 #   explicitly to be the same size as it was sized in the vertex
9 #   shader. Only elements in this array that have clipping enabled
10 #   will have defined values.
12 # This test checks proper operation of gl_ClipDistance in fragment
13 # shaders by setting each element of gl_ClipDistance to simple linear
14 # function of gl_Vertex (computed by taking the dot product of
15 # gl_Vertex with a uniform vector, and dividing the result by
16 # gl_Vertex's homogeneous coordinate).  gl_Vertex is also passed
17 # through to the fragment shader, which uses the same dot product to
18 # verify that gl_ClipDistance has been properly interpolated.
20 [require]
21 GLSL >= 1.30
23 [vertex shader]
24 #version 130
25 uniform vec4 transform[6];
26 out vec4 vertex;
27 out float gl_ClipDistance[6];
29 void main()
31   gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
33   // Set each value of gl_ClipDistance to a linear transformation of
34   // gl_Vertex.
35   for (int i = 0; i < 6; ++i) {
36     gl_ClipDistance[i] = dot(transform[i], gl_Vertex) / gl_Vertex.w;
37   }
39   // Pass through gl_Vertex to the fragment shader so that it can
40   // verify the interpolated values of gl_ClipDistance.
41   vertex = gl_Vertex;
44 [fragment shader]
45 #version 130
46 uniform vec4 transform[6];
47 in vec4 vertex;
48 in float gl_ClipDistance[6];
50 void main()
52   bool test_passed = true;
54   // Check that each value of gl_ClipDistance matches the value
55   // computed in the vertex shader.
56   for (int i = 0; i < 6; ++i) {
57     float expected_distance = dot(transform[i], vertex) / vertex.w;
58     float deviation = distance(gl_ClipDistance[i], expected_distance);
59     if (deviation > 1.0e-5) {
60       test_passed = false;
61     }
62   }
64   // Report pass/fail as a red or green pixel.
65   gl_FragColor = test_passed ? vec4(0.0, 1.0, 0.0, 1.0)
66                              : vec4(1.0, 0.0, 0.0, 1.0);
69 [test]
70 ortho 0 1 0 1
72 # Since the fragment shader's gl_ClipDistance array is only defined
73 # for elements that have clipping enabled, we need to enable all 6
74 # clip planes and carefully shoose the transform vectors to make sure
75 # that no pixels are actually clipped.
76 enable GL_CLIP_PLANE0
77 enable GL_CLIP_PLANE1
78 enable GL_CLIP_PLANE2
79 enable GL_CLIP_PLANE3
80 enable GL_CLIP_PLANE4
81 enable GL_CLIP_PLANE5
82 uniform vec4 transform[0]  1.0  1.0 0.0 0.0 # clipDistance[0] = x + y
83 uniform vec4 transform[1]  1.0  2.0 0.0 0.0 # clipDistance[1] = x + 2*y
84 uniform vec4 transform[2]  2.0  1.0 0.0 0.0 # clipDistance[2] = 2*x + y
85 uniform vec4 transform[3]  2.0  2.0 0.0 0.0 # clipDistance[3] = 2*x + 2*y
86 uniform vec4 transform[4] -1.0 -1.0 0.0 2.0 # clipDistance[4] = 2.0 - x - y
87 uniform vec4 transform[5] -1.0  1.0 0.0 1.0 # clipDistance[5] = 1.0 - x + y
89 draw rect -1 -1 2 2
90 probe all rgba 0.0 1.0 0.0 1.0