glx_arb_create_context: Fix build against older GL headers.
[piglit.git] / tests / spec / glx_arb_create_context / no-error.c
blob8c1645facea456cee2bf1e02cfd05a9e7aee878f
1 /* Copyright 2017 Grigori Goronzy <greg@chown.ath.cx>
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
12 * Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
20 * IN THE SOFTWARE.
22 #include "piglit-util.h"
23 #include "piglit-util-gl.h"
24 #include "piglit-glx-util.h"
25 #include "common.h"
27 #define BOOLSTR(x) ((x) ? "yes" : "no")
29 #ifndef GLX_CONTEXT_OPENGL_NO_ERROR_ARB
30 #define GLX_CONTEXT_OPENGL_NO_ERROR_ARB 0x31B3
31 #endif
33 static enum piglit_result check_no_error(bool debug, bool robust)
35 int ctx_flags = 0;
36 ctx_flags |= debug ? GLX_CONTEXT_DEBUG_BIT_ARB : 0;
37 ctx_flags |= robust ? GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB : 0;
38 const int attribs[] = {
39 GLX_CONTEXT_MAJOR_VERSION_ARB, 2,
40 GLX_CONTEXT_MINOR_VERSION_ARB, 0,
41 GLX_CONTEXT_OPENGL_NO_ERROR_ARB, 1,
42 GLX_CONTEXT_FLAGS_ARB, ctx_flags,
43 None
45 static bool is_dispatch_init = false;
46 GLXContext ctx;
47 enum piglit_result result = PIGLIT_SKIP;
49 printf("info: debug=%s, robustness=%s\n", BOOLSTR(debug), BOOLSTR(robust));
51 if (robust && !piglit_is_glx_extension_supported(dpy, "GLX_ARB_create_context_robustness")) {
52 printf("info: GLX_ARB_create_context_robustness not supported\n");
53 result = PIGLIT_SKIP;
54 goto done;
57 ctx = glXCreateContextAttribsARB(dpy, fbconfig, NULL, True, attribs);
58 XSync(dpy, 0);
60 if (glx_error_code != 0) {
61 if (debug || robust) {
62 /* KHR_no_error doesn't allow the no error mode to be enabled
63 * with KHR_debug or ARB_robustness, so context creation is
64 * expected to fail in these cases.
66 printf("info: context creation failed (expected)\n");
67 result = PIGLIT_PASS;
68 goto done;
71 /* Most likely the API/version is not supported. */
72 result = PIGLIT_SKIP;
73 goto done;
75 if (ctx == NULL) {
76 printf("error: context creation failed\n");
77 result = PIGLIT_FAIL;
78 goto done;
81 if (!glXMakeContextCurrent(dpy, glxWin, glxWin, ctx)) {
82 printf("error: created OpenGL context, but could not make it "
83 "current\n");
84 result = PIGLIT_FAIL;
85 goto done;
88 if (!is_dispatch_init) {
89 /* We must postpone initialization of piglit-dispatch until
90 * a context is current.
92 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
93 is_dispatch_init = true;
96 if (!piglit_is_extension_supported("GL_KHR_no_error")) {
97 printf("warning: context does not report GL_KHR_no_error "
98 "availability\n");
99 result = PIGLIT_WARN;
100 goto done;
103 if (piglit_get_gl_version() >= 30) {
104 GLint context_flags = 0;
105 glGetIntegerv(GL_CONTEXT_FLAGS, &context_flags);
106 if (!(context_flags & GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR)) {
107 printf("error: context does not have "
108 "GL_CONTEXT_FLAG_NO_ERROR_BIT_KHR set\n");
109 result = PIGLIT_FAIL;
110 goto done;
114 result = PIGLIT_PASS;
115 done:
116 printf("info: %s\n", piglit_result_to_string(result));
117 glXMakeContextCurrent(dpy, None, None, NULL);
118 glXDestroyContext(dpy, ctx);
119 return result;
122 int main(int argc, char **argv)
124 enum piglit_result result = PIGLIT_SKIP;
126 GLX_ARB_create_context_setup();
127 piglit_require_glx_extension(dpy, "GLX_ARB_create_context_no_error");
129 /* Check that KHR_no_error gets enabled and its interaction with debug and
130 * robustness context flags. */
131 piglit_merge_result(&result, check_no_error(false, false));
132 piglit_merge_result(&result, check_no_error(true, false));
133 piglit_merge_result(&result, check_no_error(false, true));
134 piglit_merge_result(&result, check_no_error(true, true));
136 GLX_ARB_create_context_teardown();
138 piglit_report_result(result);