ext_transform_feedback: document missing mode in usage
[piglit.git] / tests / general / line-smooth-stipple.c
blob0b54edeb6023c7325eaffe8e191a5f0b33ea46db
1 /*
2 * Copyright © 2022 Collabora Ltd
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 * Erik Faye-Lund <erik.faye-lund@collabora.com>
29 * Test the coverage of stippled multiple line-segments
32 #include "piglit-util-gl.h"
34 PIGLIT_GL_TEST_CONFIG_BEGIN
36 config.supports_gl_compat_version = 10;
38 config.window_width = 300;
39 config.window_height = 100;
40 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
42 PIGLIT_GL_TEST_CONFIG_END
44 float stipple_pattern(float counter, int factor)
46 counter += 0.5;
47 counter = counter - floor(counter / (2 * factor)) * 2 * factor;
48 return MIN2(MAX2(fabs(counter - 8.0) - (factor * 0.5) + 0.5,
49 0.0f), 1.0f);
52 enum piglit_result
53 piglit_display(void)
55 glClearColor(0.0, 0.0, 0.0, 0.0);
56 glClear(GL_COLOR_BUFFER_BIT);
58 glEnable(GL_LINE_SMOOTH);
59 /* GL AA lines produce an alpha value */
60 glEnable(GL_BLEND);
61 glBlendFunc(GL_SRC_ALPHA, GL_ONE);
63 glLineWidth(3.0f);
64 glEnable(GL_LINE_STIPPLE);
66 int y;
67 for (y = 0; y * 4 < piglit_height; y++) {
68 float offset = 1.0 + y / 4.0f;
69 glLineStipple(8, 0x5555);
70 glColor4f(0.5, 0.0, 0.5, 1.0);
71 glBegin(GL_LINES);
72 glVertex2f(offset, 1.5 + y * 4);
73 glVertex2f(piglit_width - 1.0, 1.5 + y * 4);
74 glEnd();
76 glLineStipple(8, ~0x5555);
77 glColor4f(0.0, 0.5, 0.0, 1.0);
78 glBegin(GL_LINES);
79 glVertex2f(offset, 1.5 + y * 4);
80 glVertex2f(piglit_width - 1.0, 1.5 + y * 4);
81 glEnd();
84 GLboolean pass = GL_TRUE;
86 float *expected = malloc(piglit_width * sizeof(float) * 3);
87 for (y = 0; y * 4 < piglit_height; y++) {
88 float offset = 1.0 + y / 4.0f;
89 int start_x = ceil(offset);
90 for (int x = 0; x < piglit_width; ++x) {
91 expected[x * 3 + 0] = stipple_pattern(x - offset - 4, 8) * 0.5;
92 expected[x * 3 + 1] = stipple_pattern(x - offset + 4, 8) * 0.5;
93 expected[x * 3 + 2] = stipple_pattern(x - offset - 4, 8) * 0.5;
95 pass = pass && piglit_probe_rect_rgb_varying(start_x, y * 4 + 1, piglit_width - start_x - 2, 1, expected + start_x * 3, 0);
97 free(expected);
99 piglit_present_results();
101 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
104 void
105 piglit_init(int argc, char **argv)
107 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);