2 * Copyright © 2011 Intel Corporation
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
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 DEALINGS
25 * \file clip-flag-behavior.c
27 * This test verifies the following basic behaviors of the GL_CLIP_PLANEi
30 * - There are exactly MAX_CLIP_PLANES of them, and trying to access a
31 * nonexistent flag produces a GL_INVALID_ENUM error.
33 * - They default to false.
35 * - Their behavior under glGetBooleanv, glIsEnabled, glEnable, and
36 * glDisable is consistent.
39 #include "piglit-util-gl.h"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config
.supports_gl_compat_version
= 10;
44 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
45 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
47 PIGLIT_GL_TEST_CONFIG_END
55 static char *bool_to_string(bool b
)
64 check_bool(GLboolean b
, bool expected
)
66 /* Negate the bools before comparing so that distinct nonzero
67 * values compare equal.
69 if ((!b
) == (!expected
)) {
72 printf("Expected %s, got %s\n", bool_to_string(expected
),
79 * Print "OK" and return true. This is helpful in chaining with the
80 * functions above, e.g.:
82 * bool pass = piglit_check_gl_error(...) && check_bool(...) && print_ok();
92 check_enable_state(char *enum_name
, GLenum enum_value
, bool expected
)
97 printf("Trying glIsEnabled(%s): ", enum_name
);
98 b
= glIsEnabled(enum_value
);
99 pass
= piglit_check_gl_error(GL_NO_ERROR
) && check_bool(b
, expected
)
100 && print_ok() && pass
;
102 printf("Trying glGetBooleanv(%s): ", enum_name
);
103 glGetBooleanv(enum_value
, &b
);
104 pass
= piglit_check_gl_error(GL_NO_ERROR
) && check_bool(b
, expected
)
105 && print_ok() && pass
;
111 piglit_init(int argc
, char **argv
)
113 GLint max_clip_planes
;
120 printf("Querying GL_MAX_CLIP_PLANES: ");
121 glGetIntegerv(GL_MAX_CLIP_PLANES
, &max_clip_planes
);
122 if (!piglit_check_gl_error(GL_NO_ERROR
))
123 piglit_report_result(PIGLIT_FAIL
);
124 printf("%d\n", max_clip_planes
);
125 if (max_clip_planes
< 0) {
126 printf("Error: GL_MAX_CLIP_PLANES must be >= 0\n");
127 piglit_report_result(PIGLIT_FAIL
);
130 /* Check behavior of GL_CLIP_PLANE0 + i where i < max_clip_planes */
131 for (plane
= 0; plane
< max_clip_planes
; ++plane
) {
132 enum_value
= GL_CLIP_PLANE0
+ plane
;
133 sprintf(enum_name
, "GL_CLIP_PLANE0 + %d", plane
);
135 pass
= check_enable_state(enum_name
, enum_value
, false) && pass
;
137 printf("Trying glEnable(%s): ", enum_name
);
138 glEnable(enum_value
);
139 pass
= piglit_check_gl_error(GL_NO_ERROR
) && print_ok() && pass
;
141 pass
= check_enable_state(enum_name
, enum_value
, true) && pass
;
143 printf("Trying glDisable(%s): ", enum_name
);
144 glDisable(enum_value
);
145 pass
= piglit_check_gl_error(GL_NO_ERROR
) && print_ok() && pass
;
147 pass
= check_enable_state(enum_name
, enum_value
, false) && pass
;
150 if (!piglit_khr_no_error
) {
151 /* Check behavior of GL_CLIP_PLANE0 + n where n == max_clip_planes */
152 enum_value
= GL_CLIP_PLANE0
+ max_clip_planes
;
153 sprintf(enum_name
, "GL_CLIP_PLANE0 + %d", max_clip_planes
);
155 printf("Trying glIsEnabled(%s): ", enum_name
);
156 b
= glIsEnabled(enum_value
);
157 pass
= piglit_check_gl_error(GL_INVALID_ENUM
) && print_ok() && pass
;
159 printf("Trying glGetBooleanv(%s): ", enum_name
);
160 glGetBooleanv(enum_value
, &b
);
161 pass
= piglit_check_gl_error(GL_INVALID_ENUM
) && print_ok() && pass
;
163 printf("Trying glEnable(%s): ", enum_name
);
164 glEnable(enum_value
);
165 pass
= piglit_check_gl_error(GL_INVALID_ENUM
) && print_ok() && pass
;
167 printf("Trying glDisable(%s): ", enum_name
);
168 glDisable(enum_value
);
169 pass
= piglit_check_gl_error(GL_INVALID_ENUM
) && print_ok() && pass
;
172 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);