summaryrefslogtreecommitdiff
path: root/tests/general
diff options
context:
space:
mode:
authorBrian Paul <brianp@vmware.com>2010-04-17 14:56:16 -0600
committerBrian Paul <brianp@vmware.com>2010-04-17 15:00:17 -0600
commit39385cc32f09b6baf280a5be39e5c5eff86f6ff4 (patch)
tree9329f59adde4bde54a36a8286766514a9899511f /tests/general
parent6440458010069fe69ce9c9e6c3c9fb4cf3a3718c (diff)
point-line-no-cull: check that points/lines aren't accidentally culled
Some drivers may decompose AA points/lines or wide points/lines into triangles. In this case, polygon culling, polygon stippling and polygon fill mode shouldn't effect the rendered points and lines. This test draws a number of AA and non-AA points and lines and checks that they always appear regardless of polygon rasterization state.
Diffstat (limited to 'tests/general')
-rw-r--r--tests/general/CMakeLists.txt1
-rw-r--r--tests/general/point-line-no-cull.c444
2 files changed, 445 insertions, 0 deletions
diff --git a/tests/general/CMakeLists.txt b/tests/general/CMakeLists.txt
index 03023218..bf1c717f 100644
--- a/tests/general/CMakeLists.txt
+++ b/tests/general/CMakeLists.txt
@@ -38,6 +38,7 @@ add_executable (pbo-readpixels-small pbo-readpixels-small.c)
add_executable (pbo-teximage pbo-teximage.c)
add_executable (pbo-teximage-tiling pbo-teximage-tiling.c)
add_executable (pbo-teximage-tiling-2 pbo-teximage-tiling-2.c)
+add_executable (point-line-no-cull point-line-no-cull.c)
add_executable (provoking-vertex provoking-vertex.c)
add_executable (oes-read-format oes-read-format.c)
add_executable (read-front read-front.c)
diff --git a/tests/general/point-line-no-cull.c b/tests/general/point-line-no-cull.c
new file mode 100644
index 00000000..b77284cb
--- /dev/null
+++ b/tests/general/point-line-no-cull.c
@@ -0,0 +1,444 @@
+/*
+ * Copyright (c) 2010 VMware, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * on the rights to use, copy, modify, merge, publish, distribute, sub
+ * license, and/or sell copies of the Software, and to permit persons to whom
+ * the Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORES OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
+ * USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/**
+ * @file
+ * Test that points and lines are not effected by polygon culling,
+ * polygon stippling or "unfilled" mode.
+ *
+ * @author Brian Paul
+ */
+
+
+#include "piglit-util.h"
+
+
+int piglit_width = 120, piglit_height = 120;
+int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
+
+
+/** test if the pixel at (x,y) is black */
+static GLboolean
+black_pixel(float x, float y)
+{
+ GLfloat pixel[4];
+
+ glReadPixels((int) x, (int) y, 1, 1, GL_RGB, GL_FLOAT, pixel);
+
+ if (pixel[0] == 0.0 &&
+ pixel[1] == 0.0 &&
+ pixel[2] == 0.0)
+ return GL_TRUE;
+ else
+ return GL_FALSE;
+}
+
+
+/** test that lines aren't effected by polygon culling */
+static GLboolean
+test_lines_no_culling(void)
+{
+ const GLfloat x0 = 5.0, x1 = 40.0, xmid = 0.5 * (x0 + x1);
+ const GLfloat x2 = 45.0, x3 = 85.0, xmid_aa = 0.5 * (x2 + x3);
+ const GLfloat y0 = 5.0, y1 = 15.0, y2 = 25.0;
+ GLboolean pass = GL_TRUE;
+
+ glLineWidth(3.0);
+ glEnable(GL_CULL_FACE);
+
+ /* Non-AA */
+
+ glCullFace(GL_FRONT);
+ glBegin(GL_LINES);
+ glVertex2f(x0, y0);
+ glVertex2f(x1, y0);
+ glEnd();
+ if (black_pixel(xmid, y0)) {
+ fprintf(stderr, "Error: Line culled by GL_CULL_FACE = GL_FRONT\n");
+ pass = GL_FALSE;
+ }
+
+ glCullFace(GL_BACK);
+ glBegin(GL_LINES);
+ glVertex2f(x0, y1);
+ glVertex2f(x1, y1);
+ glEnd();
+ if (black_pixel(xmid, y1)) {
+ fprintf(stderr, "Error: Line culled by GL_CULL_FACE = GL_BACK\n");
+ pass = GL_FALSE;
+ }
+
+ glCullFace(GL_FRONT_AND_BACK);
+ glBegin(GL_LINES);
+ glVertex2f(x0, y2);
+ glVertex2f(x1, y2);
+ glEnd();
+ if (black_pixel(xmid, y2)) {
+ fprintf(stderr, "Error: Line culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
+ pass = GL_FALSE;
+ }
+
+
+ /* AA */
+ glEnable(GL_LINE_SMOOTH);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glCullFace(GL_FRONT);
+ glBegin(GL_LINES);
+ glVertex2f(x2, y0);
+ glVertex2f(x3, y0);
+ glEnd();
+ if (black_pixel(xmid_aa, y0)) {
+ fprintf(stderr, "Error: AA Line culled by GL_CULL_FACE = GL_FRONT\n");
+ pass = GL_FALSE;
+ }
+
+ glCullFace(GL_BACK);
+ glBegin(GL_LINES);
+ glVertex2f(x2, y1);
+ glVertex2f(x3, y1);
+ glEnd();
+ if (black_pixel(xmid_aa, y1)) {
+ fprintf(stderr, "Error: AA Line culled by GL_CULL_FACE = GL_BACK\n");
+ pass = GL_FALSE;
+ }
+
+ glCullFace(GL_FRONT_AND_BACK);
+ glBegin(GL_LINES);
+ glVertex2f(x2, y2);
+ glVertex2f(x3, y2);
+ glEnd();
+ if (black_pixel(xmid_aa, y2)) {
+ fprintf(stderr, "Error: AA Line culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
+ pass = GL_FALSE;
+ }
+
+ glDisable(GL_BLEND);
+ glDisable(GL_LINE_SMOOTH);
+ glDisable(GL_CULL_FACE);
+ glLineWidth(1.0);
+
+ return pass;
+}
+
+
+/** test that points aren't effected by polygon culling */
+static GLboolean
+test_points_no_culling(void)
+{
+ const GLfloat x0 = 100.0, x1 = 110.0;
+ const GLfloat y0 = 5.0, y1 = 15.0, y2 = 25.0;
+ GLboolean pass = GL_TRUE;
+
+ glPointSize(5.0);
+ glEnable(GL_CULL_FACE);
+
+ /* Non-AA */
+
+ glCullFace(GL_FRONT);
+ glBegin(GL_POINTS);
+ glVertex2f(x0, y0);
+ glEnd();
+ if (black_pixel(x0, y0)) {
+ fprintf(stderr, "Error: Point culled by GL_CULL_FACE = GL_FRONT\n");
+ pass = GL_FALSE;
+ }
+
+ glCullFace(GL_BACK);
+ glBegin(GL_POINTS);
+ glVertex2f(x0, y1);
+ glEnd();
+ if (black_pixel(x0, y1)) {
+ fprintf(stderr, "Error: Point culled by GL_CULL_FACE = GL_BACK\n");
+ pass = GL_FALSE;
+ }
+
+ glCullFace(GL_FRONT_AND_BACK);
+ glBegin(GL_POINTS);
+ glVertex2f(x0, y2);
+ glEnd();
+ if (black_pixel(x0, y2)) {
+ fprintf(stderr, "Error: Point culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
+ pass = GL_FALSE;
+ }
+
+ /* AA */
+ glEnable(GL_POINT_SMOOTH);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glCullFace(GL_FRONT);
+ glBegin(GL_POINTS);
+ glVertex2f(x1, y0);
+ glEnd();
+ if (black_pixel(x1, y0)) {
+ fprintf(stderr, "Error: AA Point culled by GL_CULL_FACE = GL_FRONT\n");
+ pass = GL_FALSE;
+ }
+
+ glCullFace(GL_BACK);
+ glBegin(GL_POINTS);
+ glVertex2f(x1, y1);
+ glEnd();
+ if (black_pixel(x1, y1)) {
+ fprintf(stderr, "Error: AA Point culled by GL_CULL_FACE = GL_BACK\n");
+ pass = GL_FALSE;
+ }
+
+ glCullFace(GL_FRONT_AND_BACK);
+ glBegin(GL_POINTS);
+ glVertex2f(x1, y2);
+ glEnd();
+ if (black_pixel(x1, y2)) {
+ fprintf(stderr, "Error: AA Point culled by GL_CULL_FACE = GL_FRONT_AND_BACK\n");
+ pass = GL_FALSE;
+ }
+
+ glDisable(GL_BLEND);
+ glDisable(GL_POINT_SMOOTH);
+ glDisable(GL_CULL_FACE);
+ glPointSize(1.0);
+
+ return pass;
+}
+
+
+/** test that lines aren't effected by polygon stipple */
+static GLboolean
+test_lines_no_stippling(void)
+{
+ const GLfloat x0 = 5.0, x1 = 40.0, xmid = 0.5 * (x0 + x1);
+ const GLfloat x2 = 45.0, x3 = 85.0, xmid_aa = 0.5 * (x2 + x3);
+ const GLfloat y0 = 50.0;
+ GLubyte stipple[4 * 32];
+ GLboolean pass = GL_TRUE;
+
+ memset(stipple, 0, sizeof(stipple));
+ glPolygonStipple(stipple);
+ glEnable(GL_POLYGON_STIPPLE);
+
+ glLineWidth(3.0);
+
+ /* Non-AA */
+ glBegin(GL_LINES);
+ glVertex2f(x0, y0);
+ glVertex2f(x1, y0);
+ glEnd();
+ if (black_pixel(xmid, y0)) {
+ fprintf(stderr, "Error: Line not drawn because of polygon stipple.\n");
+ pass = GL_FALSE;
+ }
+
+ /* AA */
+ glEnable(GL_LINE_SMOOTH);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glBegin(GL_LINES);
+ glVertex2f(x2, y0);
+ glVertex2f(x3, y0);
+ glEnd();
+ if (black_pixel(xmid_aa, y0)) {
+ fprintf(stderr, "Error: AA Line not drawn because of polygon stipple.\n");
+ pass = GL_FALSE;
+ }
+
+ glDisable(GL_BLEND);
+ glDisable(GL_LINE_SMOOTH);
+ glDisable(GL_POLYGON_STIPPLE);
+ glLineWidth(1.0);
+
+ return pass;
+}
+
+
+/** test that points aren't effected by polygon stipple */
+static GLboolean
+test_points_no_stippling(void)
+{
+ const GLfloat x0 = 100.0, x1 = 110.0;
+ const GLfloat y0 = 50.0;
+ GLubyte stipple[4 * 32];
+ GLboolean pass = GL_TRUE;
+
+ memset(stipple, 0, sizeof(stipple));
+ glPolygonStipple(stipple);
+ glEnable(GL_POLYGON_STIPPLE);
+
+ glPointSize(5.0);
+
+ /* Non-AA */
+ glBegin(GL_POINTS);
+ glVertex2f(x0, y0);
+ glEnd();
+ if (black_pixel(x0, y0)) {
+ fprintf(stderr, "Error: Point not drawn because of polygon stipple.\n");
+ pass = GL_FALSE;
+ }
+
+ /* AA */
+ glEnable(GL_POINT_SMOOTH);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glBegin(GL_POINTS);
+ glVertex2f(x1, y0);
+ glEnd();
+ if (black_pixel(x1, y0)) {
+ fprintf(stderr, "Error: AA Point not drawn because of polygon stipple.\n");
+ pass = GL_FALSE;
+ }
+
+ glDisable(GL_BLEND);
+ glDisable(GL_POINT_SMOOTH);
+ glDisable(GL_POLYGON_STIPPLE);
+ glPointSize(1.0);
+
+ return pass;
+}
+
+
+/** test that lines aren't effected by glPolygonMode */
+static GLboolean
+test_lines_no_pgonmode(void)
+{
+ const GLfloat x0 = 5.0, x1 = 40.0, xmid = 0.5 * (x0 + x1);
+ const GLfloat x2 = 45.0, x3 = 85.0, xmid_aa = 0.5 * (x2 + x3);
+ const GLfloat y0 = 80.0;
+ GLboolean pass = GL_TRUE;
+
+ glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
+ glLineWidth(3.0);
+
+ /* Non-AA */
+ glBegin(GL_LINES);
+ glVertex2f(x0, y0);
+ glVertex2f(x1, y0);
+ glEnd();
+ if (black_pixel(xmid, y0)) {
+ fprintf(stderr, "Error: Line not drawn because of polygon mode.\n");
+ pass = GL_FALSE;
+ }
+
+ /* AA */
+ glEnable(GL_LINE_SMOOTH);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glBegin(GL_LINES);
+ glVertex2f(x2, y0);
+ glVertex2f(x3, y0);
+ glEnd();
+ if (black_pixel(xmid_aa, y0)) {
+ fprintf(stderr, "Error: Line not drawn because of polygon mode.\n");
+ pass = GL_FALSE;
+ }
+
+ glDisable(GL_BLEND);
+ glDisable(GL_LINE_SMOOTH);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ glLineWidth(1.0);
+
+ return pass;
+}
+
+
+/** test that points aren't effected by glPolygonMode */
+static GLboolean
+test_points_no_pgonmode(void)
+{
+ const GLfloat x0 = 100.0, x1 = 110.0;
+ const GLfloat y0 = 80.0;
+ GLboolean pass = GL_TRUE;
+
+ glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+ glPointSize(5.0);
+
+ /* Non-AA */
+ glBegin(GL_POINTS);
+ glVertex2f(x0, y0);
+ glEnd();
+ if (black_pixel(x0, y0)) {
+ fprintf(stderr, "Error: Line not drawn because of polygon mode.\n");
+ pass = GL_FALSE;
+ }
+
+ /* AA */
+ glEnable(GL_POINT_SMOOTH);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ glBegin(GL_POINTS);
+ glVertex2f(x1, y0);
+ glEnd();
+ if (black_pixel(x1, y0)) {
+ fprintf(stderr, "Error: AA Line not drawn because of polygon mode.\n");
+ pass = GL_FALSE;
+ }
+
+ glDisable(GL_BLEND);
+ glDisable(GL_POINT_SMOOTH);
+ glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+ glPointSize(1.0);
+
+ return pass;
+}
+
+
+enum piglit_result
+piglit_display(void)
+{
+ GLboolean pass = GL_TRUE;
+
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ pass = test_lines_no_culling() && pass;
+ pass = test_points_no_culling() && pass;
+ pass = test_lines_no_stippling() && pass;
+ pass = test_points_no_stippling() && pass;
+ pass = test_lines_no_pgonmode() && pass;
+ pass = test_points_no_pgonmode() && pass;
+
+ glutSwapBuffers();
+
+ return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
+}
+
+
+static void
+reshape(int width, int height)
+{
+ piglit_width = width;
+ piglit_height = height;
+ glViewport(0, 0, width, height);
+ piglit_ortho_projection(width, height, GL_FALSE);
+}
+
+
+void
+piglit_init(int argc, char **argv)
+{
+ glutReshapeFunc(reshape);
+ reshape(piglit_width, piglit_height);
+}