ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_cull_distance / max-distances.c
blob6eeb54b6d01dccd458423b590509fac2ffc92383
1 /*
2 * Copyright © 2015 Tobias Klausmann <tobias.johannes.klausmann@mni.thm.de>
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * \file max-distances.c
27 * From the ARB_cull_distance spec:
29 * Modify Section 7.3, Built-In Constants
31 * (add to the list of implementation-dependent constants after
32 * gl_MaxClipDistances on p. 132)
34 * const int gl_MaxCullDistances = 8;
35 * const int gl_MaxCombinedClipAndCullDistances = 8;
38 * New Implementation Dependent State
40 * (add to table 23.53, Implementation Dependent Values)
42 * Get Value Type Get Command Min. value Description
43 * ------------------------------------ ---- ----------- ---------- ------------------------------
44 * MAX_CULL_DISTANCES Z+ GetIntegerv 8 Max no. of user culling planes
45 * MAX_COMBINED_CLIP_AND_CULL_DISTANCES Z+ GetIntegerv 8 Max combined no. of user
46 * clipping and culling planes
48 * This test verifies that glGetIntegerv() returns the appropriate values for
49 * the tokens MAX_CULL_DISTANCES and MAX_COMBINED_CLIP_AND_CULL_DISTANCES, that
50 * these values matches the values of gl_MaxCullDistances, respectively
51 * gl_MaxCombinedClipAndCullDistances defined in the vertex and fragment shader
52 * and that these values are at least 8.
54 #include "piglit-util-gl.h"
56 PIGLIT_GL_TEST_CONFIG_BEGIN
58 config.supports_gl_compat_version = 10;
59 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
61 PIGLIT_GL_TEST_CONFIG_END
63 static const char vert[] =
64 "#version 130\n"
65 "#extension GL_ARB_cull_distance: enable\n"
66 "uniform int expected_value;\n"
67 "uniform bool test_distances;\n"
68 "uniform bool test_in_vs;\n"
69 "void main()\n"
70 "{\n"
71 " gl_Position = gl_Vertex;\n"
72 " if (test_in_vs) {\n"
73 " int value = test_distances ? gl_MaxCullDistances\n"
74 " : gl_MaxCombinedClipAndCullDistances;\n"
75 " gl_FrontColor = (value == expected_value)\n"
76 " ? vec4(0.0, 1.0, 0.0, 1.0)\n"
77 " : vec4(1.0, 0.0, 0.0, 1.0);\n"
78 " }\n"
79 "}\n";
81 static const char frag[] =
82 "#version 130\n"
83 "#extension GL_ARB_cull_distance: enable\n"
84 "uniform int expected_value;\n"
85 "uniform bool test_distances;\n"
86 "uniform bool test_in_vs;\n"
87 "void main()\n"
88 "{\n"
89 " if (test_in_vs) {\n"
90 " gl_FragColor = gl_Color;\n"
91 " } else {\n"
92 " int value = test_distances ? gl_MaxCullDistances\n"
93 " : gl_MaxCombinedClipAndCullDistances;\n"
94 " gl_FragColor = (value == expected_value)\n"
95 " ? vec4(0.0, 1.0, 0.0, 1.0)\n"
96 " : vec4(1.0, 0.0, 0.0, 1.0);\n"
97 " }\n"
98 "}\n";
100 GLuint prog;
102 enum piglit_result
103 piglit_display(void)
105 GLint max_cull_distances;
106 GLint max_combined_clip_and_cull_distances;
107 GLint expected_value;
108 GLint test_distances, test_in_vs;
109 float green[] = { 0.0, 1.0, 0.0, 1.0 };
110 GLint loc;
112 enum piglit_result result = PIGLIT_PASS;
114 glGetIntegerv(GL_MAX_CULL_DISTANCES, &max_cull_distances);
115 printf("GL_MAX_CULL_DISTANCES = %d\n", max_cull_distances);
116 if (max_cull_distances < 8) {
117 printf("GL_MAX_CULL_DISTANCES < 8\n");
118 piglit_report_result(PIGLIT_FAIL);
121 glGetIntegerv(GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES,
122 &max_combined_clip_and_cull_distances);
123 printf("GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES = %d\n",
124 max_combined_clip_and_cull_distances);
125 if (max_combined_clip_and_cull_distances < 8) {
126 printf("GL_MAX_COMBINED_CLIP_AND_CULL_DISTANCES < 8\n");
127 piglit_report_result(PIGLIT_FAIL);
130 expected_value = max_cull_distances;
131 loc = glGetUniformLocation(prog, "expected_value");
132 glUniform1i(loc, expected_value);
134 for (test_distances = 0; test_distances <= 1; ++test_distances) {
135 loc = glGetUniformLocation(prog, "test_distances");
136 glUniform1i(loc, test_distances);
137 for (test_in_vs = 0; test_in_vs <= 1; ++test_in_vs) {
138 bool pass;
139 loc = glGetUniformLocation(prog, "test_in_vs");
140 glUniform1i(loc, test_in_vs);
141 piglit_draw_rect(-1, -1, 2, 2);
142 pass = piglit_probe_rect_rgba(0, 0, piglit_width,
143 piglit_height, green);
144 if (test_distances) {
145 printf("Checking that gl_MaxCullDistances == %d in %s: %s\n",
146 expected_value,
147 test_in_vs ? "VS" : "FS",
148 pass ? "pass" : "fail");
150 else {
151 printf("Checking that gl_MaxCombinedClipAndCullDistances "
152 "== %d in %s: %s\n",
153 expected_value,
154 test_in_vs ? "VS" : "FS",
155 pass ? "pass" : "fail");
157 if (!pass) {
158 result = PIGLIT_FAIL;
162 return result;
165 void
166 piglit_init(int argc, char **argv)
168 piglit_require_gl_version(30);
169 piglit_require_GLSL();
170 piglit_require_GLSL_version(130);
171 piglit_require_extension("GL_ARB_cull_distance");
172 prog = piglit_build_simple_program(vert, frag);
173 glUseProgram(prog);