diff options
author | Laura Ekstrand <laura@jlekstrand.net> | 2014-10-09 17:30:43 -0700 |
---|---|---|
committer | Laura Ekstrand <laura@jlekstrand.net> | 2014-10-09 17:30:43 -0700 |
commit | ba5571ae4184ab7bfcf452699c526efa8a351ee5 (patch) | |
tree | 72aa3db3fac159456a7b5c39184482f10fee13b5 | |
parent | 39477219925bfc14a38ae8ea23a27ab5a4695450 (diff) |
Moving orthpos test over to Piglit, bit by bit.
-rw-r--r-- | tests/spec/laura_orthpos/orthpos.c | 211 |
1 files changed, 205 insertions, 6 deletions
diff --git a/tests/spec/laura_orthpos/orthpos.c b/tests/spec/laura_orthpos/orthpos.c index 0e17ffac6..d871df517 100644 --- a/tests/spec/laura_orthpos/orthpos.c +++ b/tests/spec/laura_orthpos/orthpos.c @@ -35,6 +35,12 @@ #include "piglit-util-gl.h" +#include <stdlib.h> +#include <stdio.h> + +#define drawingSize windowSize - 2 +#define windowSize piglit_width + PIGLIT_GL_TEST_CONFIG_BEGIN config.supports_gl_compat_version = 13; @@ -43,12 +49,9 @@ PIGLIT_GL_TEST_CONFIG_BEGIN PIGLIT_GL_TEST_CONFIG_END -void -piglit_init(int argc, char **argv) -{ - /* Common setup */ - -} +struct orthpos_result { + bool hasGaps, hasOverlaps, hasBadEdges; +}; /* After a side-by-side check, all of the following setup is exactly the same * for each test: */ @@ -83,6 +86,202 @@ piglit_init(int argc, char **argv) * * glClearColor(0, 0, 0, 0); //default */ +void +piglit_init(int argc, char **argv) +{ + srand(0); + + /* Common setup */ + glFrontFace(GL_CCW); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + glEnable(GL_BLEND); + glDisable(GL_DITHER); + glCullFace(GL_BACK); + glEnable(GL_CULL_FACE); + glShadeModel(GL_FLAT); +} + +void +logStats1(const char* title, struct orthpos_result* r) { + printf("\t%s: ", title); + if (r->hasGaps || r->hasOverlaps || r->hasBadEdges) { + printf("%s %s %s\n", (r->hasGaps? "Gaps.": ""), + (r->hasOverlaps? " Overlaps.": ""), + (r->hasBadEdges? " Incorrect edges.": "")); + + } else { + printf(" No gaps, overlaps, or incorrect edges.\n"); + } +} /* logStats1 */ + +GLubyte +logicalSum(GLubyte* start, int stride, int count) { + GLubyte* p = start; + GLubyte sum = 0; + int i; + for (i = 0; i < count; ++i) { + sum |= p[0]; + sum |= p[1]; + sum |= p[2]; + p += stride; + } + return sum; +} + +void +verifyOrthPos(const GLubyte* img, GLsizei imgRowSizeInBytes, + struct orthpos_result* res, const char* title) { + + /* + * All of the tests in this group are constructed so that the + * "correct" image covers a square of exactly drawingSize by + * drawingSize pixels, embedded in a window that's two pixels + * larger in both dimensions. The border consists of pixels + * with all components set to zero. Within the image, all + * pixels should be either red (only the red component is + * nonzero) or green (only the green component is nonzero). If + * any pixels with all zero components are found, that indicates + * the presence of gaps. If any pixels with both red and green + * nonzero components are found, that indicates the presence of + * overlaps. + */ + + res->hasGaps = false; + res->hasOverlaps = false; + res->hasBadEdges = false; + + /* For examining edges */ + GLubyte* row0 = img; + GLubyte* row1 = row0 + imgRowSizeInBytes; + GLubyte* rowLast = row0 + (windowSize - 1) * imgRowSizeInBytes; + GLubyte* rowNextLast = rowLast - imgRowSizeInBytes; + + /* For examining the drawing area */ + GLubyte* row = row1 + 3; /* lower-left pixel in drawing area */ + int i, j; + GLubyte* p = row; + + /* Check the bottom horizontal edge; it must be all zero. */ + if (logicalSum(row0, 3, windowSize)) { + printf("\t%s: bottom border (at Y==0) was touched\n", title); + res->hasBadEdges = true; + } + /* Repeat the process for the top horizontal edge. */ + if (logicalSum(rowLast, 3, windowSize)) { + printf("\t%s: top border (at Y==%i) was touched\n", + title, windowSize - 1); + res->hasBadEdges = true; + } + /* + * Check the second row; there must be at least one nonzero + * pixel in the "drawn" region (excluding the first and last + * column). + */ + if (!logicalSum(row1 + 3/*skip first pixel's RGB*/, 3, drawingSize)) { + printf("\t%s: first row (at Y==1) was not drawn\n", title); + res->hasBadEdges = true; + } + /* Repeat the process for the last row. */ + if (!logicalSum(rowNextLast + 3, 3, drawingSize)) { + printf("\t%s: last row (at Y==%i) was not drawn\n", + title, windowSize - 2); + res->hasBadEdges = true; + } + + /* Check the left-hand vertical edge; it must be all zero. */ + if (logicalSum(row0, imgRowSizeInBytes, windowSize)) { + printf("\t%s: left border (at X==0) was touched\n", title); + res->hasBadEdges = true; + } + /* Repeat for the right-hand vertical edge. */ + if (logicalSum(row0 + 3 * (windowSize - 1), imgRowSizeInBytes, + windowSize)) { + printf("\t%s: right border (at X==%i) was touched\n", + title, windowSize - 1); + res->hasBadEdges = true; + } + /* Check the left-hand column; something must be nonzero. */ + if (!logicalSum(row1 + 3, imgRowSizeInBytes, drawingSize)) { + printf("\t%s: first column (at X==1) was not drawn\n", title); + res->hasBadEdges = true; + } + /* And repeat for the right-hand column: */ + if (!logicalSum(row1 + 3 * (drawingSize - 1), imgRowSizeInBytes, + drawingSize)) { + printf("\t%s: last column (at X==%i) was not drawn\n", + title, windowSize - 2); + res->hasBadEdges = true; + } + + /* + * Scan the drawing area. Anytime we find a pixel with all zero + * components, that's a gap. Anytime we find a pixel with both + * red and green components nonzero, that's an overlap. + */ + for (i = 0; i < drawingSize; ++i) { + for (j = 0; j < drawingSize; ++j) { + if (!p[0] && !p[1] && !p[2]) { + if (!res->hasGaps) { + printf("\t%s: found first gap at X==%i, Y==%i\n", + title, j + 1, i + 1); + res->hasGaps = true; + } + } + if (p[0] && p[1]) { + if (!res->hasOverlaps) { + printf("\t%s: found first overlap at X==%i, Y==%i\n", + title, j + 1, i + 1); + res->hasOverlaps = true; + } + } + p += 3; + } + row += imgRowSizeInBytes; + } + +} /* verifyOrthPos */ + +void +subdivideRects(int minX, int maxX, int minY, int maxY, + bool splitHoriz, bool drawInRed) { + /* + * Basically we're just splitting the input rectangle + * recursively. At each step we alternate between splitting + * horizontally (dividing along Y) or vertically (along X). We + * also toggle colors (between red and green) at various times, + * in order to give us some adjacent edges of different colors + * that we can check for overlaps. Recursion bottoms out when + * the axis of interest drops below 30 pixels in length. + */ + + int min = splitHoriz? minY: minX; + int max = splitHoriz? maxY: maxX; + if (min + 30 > max) { + glColor4f(drawInRed? 1.0: 0.0, drawInRed? 0.0: 1.0, + 0.0, 0.5); + glBegin(GL_QUADS); + glVertex2i(minX, minY); + glVertex2i(maxX, minY); + glVertex2i(maxX, maxY); + glVertex2i(minX, maxY); + glEnd(); + return; + } + + int split = min + (int) ((max - min) * + ((float) rand() / RAND_MAX)); /* Float in range [0.0f, 1.0f] */ + if (splitHoriz) { + subdivideRects(minX, maxX, minY, split, + !splitHoriz, drawInRed); + subdivideRects(minX, maxX, split, maxY, + !splitHoriz, !drawInRed); + } else { + subdivideRects(minX, split, minY, maxY, + !splitHoriz, drawInRed); + subdivideRects(split, maxX, minY, maxY, + !splitHoriz, !drawInRed); + } +} enum piglit_result piglit_display(void) |