glsl-1.10: test mesa bug with forward declaration
[piglit.git] / tests / glx / glx-visuals-stencil.c
blob65287a778036287ff1b0090ba88fbc02e14e1f6f
1 /*
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
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 DEALINGS
21 * IN THE SOFTWARE.
23 * Authors:
24 * Eric Anholt <eric@anholt.net>
28 /**
29 * @file glx-visuals-stencil.c
31 * Tests that when a stencil buffer is reported as present in the GLX
32 * visual that it behaves appropriately (can set a value in it with
33 * drawing, and use the stencil test on that value), and that when a
34 * stencil buffer is not present the stencil test always passes even
35 * if we try to enable it.
38 #include "piglit-util-gl.h"
39 #include "piglit-glx-util.h"
41 int piglit_width = 20;
42 int piglit_height = 20;
44 enum piglit_result
45 draw(Display *dpy, GLXFBConfig config)
47 int sbits;
48 float green[3] = {0.0, 1.0, 0.0};
49 float blue[3] = {0.0, 0.0, 1.0};
50 float *left, *right;
51 bool pass = true;
53 piglit_dispatch_default_init(PIGLIT_DISPATCH_GL);
54 glXGetFBConfigAttrib(dpy, config, GLX_STENCIL_SIZE, &sbits);
56 piglit_ortho_projection(piglit_width, piglit_height, false);
58 glEnable(GL_STENCIL_TEST);
60 /* Set half the FB to stencil value 0, half to 1, and everything blue */
61 glColor3fv(blue);
62 glStencilFunc(GL_ALWAYS, 0, ~0);
63 glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);
64 piglit_draw_rect(0, 0,
65 piglit_width / 2, piglit_height);
66 glStencilFunc(GL_ALWAYS, 1, ~0);
67 piglit_draw_rect(piglit_width / 2, 0,
68 piglit_width, piglit_height);
70 /* Now draw a rect trying to set just the 1 values to green. */
71 glColor3fv(green);
72 glStencilFunc(GL_EQUAL, 1, ~0);
73 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
74 piglit_draw_rect(0, 0, piglit_width, piglit_height);
76 /* If there was a stencil buffer, then we get half the window
77 * set to green. Otherwise, the stencil test always passes
78 * and the whole thing should have been set green.
80 if (sbits) {
81 left = blue;
82 right = green;
83 } else {
84 left = green;
85 right = green;
88 pass = pass && piglit_probe_rect_rgb(0, 0,
89 piglit_width / 2, piglit_height,
90 left);
91 pass = pass && piglit_probe_rect_rgb(piglit_width / 2, 0,
92 piglit_width - piglit_width / 2,
93 piglit_height,
94 right);
96 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
99 int
100 main(int argc, char **argv)
102 enum piglit_result result;
104 for (int i = 1; i < argc; i++) {
105 if (!strcmp(argv[i], "-auto"))
106 piglit_automatic = 1;
107 else
108 fprintf(stderr, "Unknown option: %s\n", argv[i]);
111 if (argc > 1 && strcmp(argv[1], "-pixmap") == 0)
112 result = piglit_glx_iterate_pixmap_fbconfigs(draw);
113 else
114 result = piglit_glx_iterate_visuals(draw);
116 piglit_report_result(result);
118 return 0; /* UNREACHED */