2 * Copyright (c) The Piglit project 2008
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the 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 NON-INFRINGEMENT. IN NO EVENT SHALL
18 * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Test basic line stippling functionality.
29 #include "piglit-util.h"
31 int piglit_width
= 128, piglit_height
= 128;
32 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
;
34 static void probe_pixel(int x
, int y
, const float* expected
)
36 if (!piglit_probe_pixel_rgb(x
, y
, expected
)) {
38 piglit_report_result(PIGLIT_FAILURE
);
53 struct vertex
*vertices
;
56 static const int basex
= 10;
57 static const int basey
= 10;
59 static float background
[3] = { 0, 0, 0 };
62 * @note Only horizontal and vertical lines supported right now.
64 static GLuint
probe_line(const struct stipple_line
*line
, const struct vertex
*v1
, const struct vertex
*v2
, GLuint fragment
)
68 int length
, dx
= 0, dy
= 0;
75 length
= (v2
->x
- v1
->x
)*dx
;
81 length
= (v2
->y
- v1
->y
)*dy
;
85 GLuint s
= (fragment
/line
->factor
) & 15;
86 if (line
->pattern
& (1 << s
))
87 probe_pixel(basex
+x
, basey
+y
, line
->color
);
89 probe_pixel(basex
+x
, basey
+y
, background
);
100 static void test_line(const struct stipple_line
*line
)
104 glLineStipple(line
->factor
, line
->pattern
);
105 glColor3f(line
->color
[0], line
->color
[1], line
->color
[2]);
106 glBegin(line
->primitive
);
107 for(i
= 0; i
< line
->nvertices
; ++i
)
108 glVertex2f(line
->vertices
[i
].x
+ 0.5, line
->vertices
[i
].y
+ 0.5);
111 glReadBuffer(GL_BACK
);
112 if (line
->primitive
== GL_LINES
) {
113 for(i
= 0; i
+1 < line
->nvertices
; i
+= 2)
114 probe_line(line
, &line
->vertices
[i
], &line
->vertices
[i
+1], 0);
117 for(i
= 0; i
+1 < line
->nvertices
; ++i
)
118 fragment
= probe_line(line
, &line
->vertices
[i
], &line
->vertices
[i
+1], fragment
);
119 if (line
->primitive
== GL_LINE_LOOP
)
120 probe_line(line
, &line
->vertices
[i
], &line
->vertices
[0], fragment
);
124 static struct vertex BaselineVertices
[] = { { 0, 0 }, { 24, 0 } };
125 static struct vertex RestartVertices
[] = { { 0, 2 }, { 24, 2 }, { 0, 4 }, { 24, 4 } };
126 static struct vertex LinestripVertices
[] = { { 0, 6 }, { 24, 6 }, { 24, 30 } };
127 static struct vertex LineloopVertices
[] = { { 26, 0 }, { 46, 0 }, { 46, 20 }, { 26, 20 } };
128 static struct vertex Factor2Vertices
[] = { { 0, 32 }, { 32, 32 }, { 32, 33 }, { 0, 33 } };
129 static struct vertex Factor3Vertices
[] = { { 0, 35 }, { 63, 35 }, { 63, 36 }, { 0, 36 } };
130 static struct stipple_line Lines
[] = {
132 1, 0xffff, { 1.0, 1.0, 1.0 },
136 { /* Restarting lines within a single Begin/End block */
137 1, 0x00ff, { 1.0, 0.0, 0.0 },
142 1, 0x0f8f, { 1.0, 1.0, 0.0 },
147 1, 0x8cef, { 0.0, 1.0, 0.0 },
152 2, 0x838f, { 0.0, 0.0, 1.0 },
157 3, 0xf731, { 0.0, 1.0, 1.0 },
163 static void test(void)
167 glClearColor(0.0, 0.0, 0.0, 1.0);
168 glClear(GL_COLOR_BUFFER_BIT
);
170 glEnable(GL_LINE_STIPPLE
);
173 glTranslatef(basex
, basey
, 0.0);
175 for(i
= 0; i
< sizeof(Lines
)/sizeof(Lines
[0]); ++i
)
176 test_line(&Lines
[i
]);
188 return PIGLIT_SUCCESS
;
192 static void Reshape(int width
, int height
)
194 piglit_width
= width
;
195 piglit_height
= height
;
196 glViewport(0, 0, width
, height
);
197 piglit_ortho_projection(width
, height
, GL_FALSE
);
201 void piglit_init(int argc
, char **argv
)
203 glutReshapeFunc(Reshape
);
204 Reshape(piglit_width
, piglit_height
);