diff options
author | Eric Anholt <eric@anholt.net> | 2010-01-26 17:26:16 -0800 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2010-01-26 17:28:14 -0800 |
commit | 30a5e6b46b53fed619ca39988593e4f7010dcf9a (patch) | |
tree | 43348be051620692c16d74d886f5686ee40c43bc | |
parent | b2b8fbf92fe1e89bf7a35ac2d35e329c0e00965f (diff) |
scissor-bitmap: Test glScissor vs glBitmap.
-rw-r--r-- | tests/all.tests | 1 | ||||
-rw-r--r-- | tests/general/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/general/scissor-bitmap.c | 304 | ||||
-rw-r--r-- | tests/util/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/util/fdo-bitmap.c | 58 | ||||
-rw-r--r-- | tests/util/piglit-util.h | 4 |
6 files changed, 369 insertions, 0 deletions
diff --git a/tests/all.tests b/tests/all.tests index 9f51b6cc5..3266af4fd 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -102,6 +102,7 @@ add_plain_test(general, 'pbo-teximage') add_plain_test(general, 'provoking-vertex') add_plain_test(general, 'oes-read-format') add_plain_test(general, 'read-front') +add_plain_test(general, 'scissor-bitmap') add_plain_test(general, 'scissor-copypixels') add_plain_test(general, 'scissor-depth-clear') add_plain_test(general, 'scissor-many') diff --git a/tests/general/CMakeLists.txt b/tests/general/CMakeLists.txt index 6a65907d5..6fbf1dee6 100644 --- a/tests/general/CMakeLists.txt +++ b/tests/general/CMakeLists.txt @@ -37,6 +37,7 @@ add_executable (pbo-teximage pbo-teximage.c) add_executable (provoking-vertex provoking-vertex.c) add_executable (oes-read-format oes-read-format.c) add_executable (read-front read-front.c) +add_executable (scissor-bitmap scissor-bitmap.c) add_executable (scissor-copypixels scissor-copypixels.c) add_executable (scissor-depth-clear scissor-depth-clear.c) add_executable (scissor-many scissor-many.c) diff --git a/tests/general/scissor-bitmap.c b/tests/general/scissor-bitmap.c new file mode 100644 index 000000000..c4fd9fa26 --- /dev/null +++ b/tests/general/scissor-bitmap.c @@ -0,0 +1,304 @@ +/* + * Copyright © 2008 Intel Corporation + * + * 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 + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * 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 NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS 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. + * + * Authors: + * Eric Anholt <eric@anholt.net> + * + */ + +/** @file scissor-bitmap.c + * + * Tests that clipping of glBitmap to the backbuffer works correctly, whether + * it's to window boundaries or glScissor. + */ + +#include "piglit-util.h" +#include "piglit-framework.h" + +int piglit_width = 400; +int piglit_height = 400; +int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB; + +struct probes { + struct test_position { + const GLfloat *color; + const char *name; + int x; + int y; + int bitmap_x_off; + int bitmap_y_off; + int width; + int height; + } probes[30]; + int n_probes; +}; + +static void +add_probe(struct probes *probes, + const char *name, const GLfloat *color, + int x, int y, int width, int height, + int bitmap_x_off, int bitmap_y_off) +{ + probes->probes[probes->n_probes].color = color; + probes->probes[probes->n_probes].name = name; + probes->probes[probes->n_probes].x = x; + probes->probes[probes->n_probes].y = y; + probes->probes[probes->n_probes].bitmap_x_off = bitmap_x_off; + probes->probes[probes->n_probes].bitmap_y_off = bitmap_y_off; + probes->probes[probes->n_probes].width = width; + probes->probes[probes->n_probes].height = height; + probes->n_probes++; +} + +static GLboolean +get_bitmap_bit(int x, int y) +{ + const uint8_t *row = &fdo_bitmap[y * fdo_bitmap_width / 8]; + + return (row[x / 8] >> (7 - x % 8)) & 1; +} + +static GLboolean +verify_bitmap_pixel(struct probes *probes, int i, int x, int y) +{ + const GLfloat black[4] = {0.0, 0.0, 0.0, 0.0}; + int x1 = probes->probes[i].x; + int y1 = probes->probes[i].y; + int bitmap_x1 = probes->probes[i].bitmap_x_off; + int bitmap_y1 = probes->probes[i].bitmap_y_off; + const GLfloat *expected; + GLboolean pass; + + if (probes->probes[i].color == NULL) { + expected = black; + } else { + GLboolean on; + + on = get_bitmap_bit(x - x1 + bitmap_x1, + y - y1 + bitmap_y1); + /* Verify that the region is black if unset, or the foreground + * color otherwise. + */ + if (on) + expected = probes->probes[i].color; + else + expected = black; + } + + /* Make sure the region is black */ + pass = piglit_probe_pixel_rgb(x, y, expected); + if (!pass) + printf("glBitmap error in %s (test offset %d,%d)\n", + probes->probes[i].name, + x - probes->probes[i].x, + y - probes->probes[i].y); + return pass; +} + +static GLboolean +verify_bitmap_contents(struct probes *probes, int i) +{ + int x, y; + int x1 = probes->probes[i].x; + int y1 = probes->probes[i].y; + int x2 = probes->probes[i].x + probes->probes[i].width; + int y2 = probes->probes[i].y + probes->probes[i].height; + GLboolean pass = GL_TRUE; + + for (y = y1; y < y2; y++) { + if (y < 0 || y >= piglit_height) + continue; + for (x = x1; x < x2; x++) { + if (x < 0 || x >= piglit_width) + continue; + + pass &= verify_bitmap_pixel(probes, i, x, y); + if (!pass) + return pass; + } + } + + return pass; +} + +enum piglit_result +piglit_display() +{ + const GLfloat red[4] = {1.0, 0.0, 0.0, 0.0}; + const GLfloat green[4] = {0.0, 1.0, 0.0, 0.0}; + const GLfloat blue[4] = {0.0, 0.0, 1.0, 0.0}; + int i; + int center_x_start = (piglit_width - fdo_bitmap_width) / 2; + int center_y_start = (piglit_height - fdo_bitmap_height) / 2; + int start_x, start_y; + struct probes probes; + GLboolean pass; + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + + memset(&probes, 0, sizeof(probes)); + + glClearColor(0, 0, 0, 0); + glClear(GL_COLOR_BUFFER_BIT); + + glColor4fv(red); + /* Center: full image */ + glRasterPos2f(center_x_start, center_y_start); + glBitmap(fdo_bitmap_width, fdo_bitmap_height, 0, 0, 0, 0, fdo_bitmap); + add_probe(&probes, "center full", red, + center_x_start, center_y_start, + fdo_bitmap_width, fdo_bitmap_height, + 0, 0); + + glEnable(GL_SCISSOR_TEST); + glColor4fv(green); + /* Left clipped */ + start_x = center_x_start - fdo_bitmap_width - 10; + start_y = center_y_start; + glScissor(start_x + fdo_bitmap_width / 4, + start_y, + fdo_bitmap_width, + fdo_bitmap_height); + glRasterPos2f(start_x, start_y); + glBitmap(fdo_bitmap_width, fdo_bitmap_height, 0, 0, 0, 0, fdo_bitmap); + add_probe(&probes, "left glscissor clipped area", NULL, + start_x, start_y, + fdo_bitmap_width / 4, fdo_bitmap_height, + 0, 0); + add_probe(&probes, "left glscissor unclipped area", green, + start_x + fdo_bitmap_width / 4, start_y, + fdo_bitmap_width * 3 / 4, fdo_bitmap_height, + fdo_bitmap_width / 4, 0); + + /* Right clipped */ + start_x = center_x_start + fdo_bitmap_width + 10; + start_y = center_y_start; + glScissor(start_x, + start_y, + fdo_bitmap_width * 3 / 4, + fdo_bitmap_height); + glRasterPos2f(start_x, start_y); + glBitmap(fdo_bitmap_width, fdo_bitmap_height, 0, 0, 0, 0, fdo_bitmap); + add_probe(&probes, "right glscissor clipped area", NULL, + start_x + fdo_bitmap_width * 3 /4, + start_y, + fdo_bitmap_width / 4, + fdo_bitmap_height, + 0, 0); + add_probe(&probes, "right glscissor unclipped area", green, + start_x, start_y, + fdo_bitmap_width * 3 / 4, fdo_bitmap_height, + 0, 0); + + /* Top clipped */ + start_x = center_x_start; + start_y = center_y_start + fdo_bitmap_height + 10; + glScissor(start_x, + start_y, + fdo_bitmap_width, + fdo_bitmap_height * 3 / 4); + glRasterPos2f(start_x, start_y); + glBitmap(fdo_bitmap_width, fdo_bitmap_height, 0, 0, 0, 0, fdo_bitmap); + add_probe(&probes, "top glscissor clipped area", NULL, + start_x, + start_y + fdo_bitmap_height * 3 /4, + fdo_bitmap_width, + fdo_bitmap_height / 4, + 0, 0); + add_probe(&probes, "top glscissor unclipped area", green, + start_x, start_y, + fdo_bitmap_width, fdo_bitmap_height * 3 / 4, + 0, 0); + + /* Bottom clipped */ + start_x = center_x_start; + start_y = center_y_start - fdo_bitmap_height - 10; + glScissor(start_x, + start_y + fdo_bitmap_height / 4, + fdo_bitmap_width, + fdo_bitmap_height); + glRasterPos2f(start_x, start_y); + glBitmap(fdo_bitmap_width, fdo_bitmap_height, 0, 0, 0, 0, fdo_bitmap); + add_probe(&probes, "bottom glscissor clipped area", NULL, + start_x, start_y, + fdo_bitmap_width, fdo_bitmap_height / 4, + 0, 0); + add_probe(&probes, "bottom glscissor unclipped area", green, + start_x, start_y + fdo_bitmap_height / 4, + fdo_bitmap_width, fdo_bitmap_height * 3 / 4, + 0, fdo_bitmap_height / 4); + + glDisable(GL_SCISSOR_TEST); + glColor4fv(blue); + /* Left side of window (not drawn due to invalid pos) */ + start_x = -fdo_bitmap_width / 4; + start_y = center_y_start; + glRasterPos2f(start_x, start_y); + glBitmap(fdo_bitmap_width, fdo_bitmap_height, 0, 0, 0, 0, fdo_bitmap); + add_probe(&probes, "left window clipped area", NULL, + start_x + fdo_bitmap_width / 4, start_y, + fdo_bitmap_width * 3 / 4, fdo_bitmap_height, + fdo_bitmap_width / 4, 0); + /* Right side of window */ + start_x = piglit_width - fdo_bitmap_width * 3 / 4; + start_y = center_y_start; + glRasterPos2f(start_x, start_y); + glBitmap(fdo_bitmap_width, fdo_bitmap_height, 0, 0, 0, 0, fdo_bitmap); + add_probe(&probes, "right window unclipped area", blue, + start_x, start_y, + fdo_bitmap_width * 3 / 4, fdo_bitmap_height, + 0, 0); + + /* Top of window */ + start_x = center_x_start; + start_y = piglit_height - fdo_bitmap_height * 3 / 4; + glRasterPos2f(start_x, start_y); + glBitmap(fdo_bitmap_width, fdo_bitmap_height, 0, 0, 0, 0, fdo_bitmap); + add_probe(&probes, "top window unclipped area", blue, + start_x, start_y, + fdo_bitmap_width, fdo_bitmap_height * 3 / 4, + 0, 0); + /* Bottom of window (not drawn due to invalid pos) */ + start_x = center_x_start; + start_y = -fdo_bitmap_height / 4; + glRasterPos2f(start_x, start_y); + glBitmap(fdo_bitmap_width, fdo_bitmap_height, 0, 0, 0, 0, fdo_bitmap); + add_probe(&probes, "bottom window clipped area", NULL, + start_x, start_y, + fdo_bitmap_width, fdo_bitmap_height * 3 / 4, + 0, 0); + + glutSwapBuffers(); + glFlush(); + + for (i = 0; i < probes.n_probes; i++) { + pass = pass && verify_bitmap_contents(&probes, i); + } + + return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE; +} + + +void +piglit_init(int argc, char **argv) +{ + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); +} diff --git a/tests/util/CMakeLists.txt b/tests/util/CMakeLists.txt index 809a743aa..2d036a725 100644 --- a/tests/util/CMakeLists.txt +++ b/tests/util/CMakeLists.txt @@ -8,6 +8,7 @@ include_directories( ) add_library (piglitutil + fdo-bitmap.c piglit-util.c shader-load.c piglit-framework.c diff --git a/tests/util/fdo-bitmap.c b/tests/util/fdo-bitmap.c new file mode 100644 index 000000000..34d65aea0 --- /dev/null +++ b/tests/util/fdo-bitmap.c @@ -0,0 +1,58 @@ +#include <stdint.h> +const uint8_t fdo_bitmap[] = { + 0x00, 0x07, 0xfc, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x18, 0x07, 0xc0, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x30, 0x00, 0x7c, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0x00, 0x07, 0x80, 0x00, 0x00, 0x00, + 0x00, 0x83, 0xfc, 0x00, 0x78, 0x00, 0x00, 0x00, + 0x01, 0x87, 0xff, 0xc0, 0x07, 0x80, 0x00, 0x00, + 0x01, 0x0f, 0xff, 0xfc, 0x00, 0xf8, 0x00, 0x00, + 0x03, 0x1f, 0xff, 0xff, 0xc0, 0x0f, 0x80, 0x00, + 0x02, 0x3f, 0xff, 0xff, 0xfc, 0x00, 0xf8, 0x00, + 0x02, 0x3f, 0xff, 0xff, 0xff, 0xc0, 0x0f, 0x00, + 0x02, 0x7f, 0xff, 0xff, 0xff, 0xf8, 0x03, 0xc0, + 0x04, 0x7f, 0xff, 0xfe, 0xff, 0xff, 0x80, 0x30, + 0x04, 0x7f, 0xff, 0xfc, 0x1f, 0xff, 0xf8, 0x18, + 0x04, 0x7f, 0xff, 0xfc, 0x03, 0xff, 0xfe, 0x08, + 0x04, 0xff, 0xff, 0xf8, 0x07, 0xff, 0xff, 0x84, + 0x08, 0xff, 0xff, 0xf8, 0x07, 0xff, 0xff, 0xc6, + 0x08, 0xff, 0xff, 0xfc, 0x07, 0xff, 0xff, 0xc2, + 0x08, 0xff, 0xff, 0xff, 0x8f, 0xff, 0xff, 0xe2, + 0x19, 0xff, 0xff, 0xf7, 0xff, 0xff, 0xff, 0xe3, + 0x11, 0xff, 0xff, 0xe3, 0xff, 0xff, 0xff, 0xe1, + 0x11, 0xff, 0xff, 0xc7, 0xf1, 0xff, 0xff, 0xf1, + 0x11, 0xff, 0xff, 0x8f, 0xf9, 0xff, 0xff, 0xf3, + 0x33, 0xff, 0xff, 0x1f, 0xf8, 0xff, 0xff, 0xe3, + 0x23, 0xf1, 0xfe, 0x3f, 0xfc, 0x7f, 0xff, 0xe2, + 0x23, 0xf0, 0x1f, 0xff, 0xfe, 0x7f, 0xff, 0xe2, + 0x23, 0xe0, 0x01, 0xff, 0xfe, 0x3f, 0xff, 0xe2, + 0x67, 0xe0, 0x00, 0x3f, 0xff, 0x7f, 0xff, 0xe4, + 0x47, 0xe0, 0x00, 0x3f, 0xff, 0xff, 0xff, 0xc4, + 0x47, 0xe0, 0x00, 0x3f, 0xff, 0x87, 0xff, 0xc4, + 0x47, 0xc0, 0x00, 0x3f, 0xff, 0x80, 0x7f, 0xcc, + 0x4f, 0xc0, 0x00, 0x61, 0xff, 0x00, 0x0f, 0xc8, + 0x8f, 0xc0, 0x00, 0x60, 0x03, 0x00, 0x0f, 0x88, + 0x8f, 0xc0, 0x00, 0x78, 0x03, 0x00, 0x0f, 0x88, + 0xc7, 0xc0, 0x00, 0xff, 0xff, 0x00, 0x0f, 0x98, + 0x47, 0xf0, 0x00, 0xff, 0xfe, 0x00, 0x0f, 0x10, + 0x47, 0xff, 0x00, 0xff, 0xfe, 0x00, 0x1f, 0x10, + 0x43, 0xff, 0xe0, 0xff, 0xff, 0x00, 0x1f, 0x10, + 0x21, 0xff, 0xff, 0xff, 0xff, 0xf0, 0x1f, 0x30, + 0x30, 0xff, 0xff, 0xff, 0xff, 0xff, 0x3e, 0x20, + 0x18, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x20, + 0x0c, 0x03, 0xff, 0xff, 0xff, 0xff, 0xfe, 0x20, + 0x07, 0x00, 0x7f, 0xff, 0xff, 0xff, 0xfe, 0x60, + 0x01, 0xe0, 0x07, 0xff, 0xff, 0xff, 0xfc, 0x40, + 0x00, 0x3e, 0x00, 0x7f, 0xff, 0xff, 0xfc, 0x40, + 0x00, 0x03, 0xc0, 0x07, 0xff, 0xff, 0xf8, 0x40, + 0x00, 0x00, 0x3c, 0x00, 0x7f, 0xff, 0xf8, 0x80, + 0x00, 0x00, 0x03, 0xc0, 0x07, 0xff, 0xf0, 0x80, + 0x00, 0x00, 0x00, 0x7c, 0x00, 0xff, 0xc1, 0x00, + 0x00, 0x00, 0x00, 0x07, 0xc0, 0x00, 0x03, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x7c, 0x00, 0x06, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x07, 0x80, 0x18, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x7f, 0xf0, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00, +}; +const unsigned int fdo_bitmap_width = 64; +const unsigned int fdo_bitmap_height = 53; diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h index 36307e7ee..c694caead 100644 --- a/tests/util/piglit-util.h +++ b/tests/util/piglit-util.h @@ -68,6 +68,10 @@ enum piglit_result { #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) +extern const uint8_t fdo_bitmap[]; +extern const unsigned int fdo_bitmap_width; +extern const unsigned int fdo_bitmap_height; + int FindLine(const char *program, int position); void piglit_report_result(enum piglit_result result); void piglit_require_extension(const char *name); |