From 2a626860b74345335f33c055db357e35c5d4ea14 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Wed, 10 Aug 2011 20:36:36 +0200 Subject: Add GL_SELECT render mode tests --- tests/all.tests | 5 + tests/general/CMakeLists.gl.txt | 1 + tests/general/select.c | 260 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+) create mode 100644 tests/general/select.c diff --git a/tests/all.tests b/tests/all.tests index de64e7ec..b7560ed0 100644 --- a/tests/all.tests +++ b/tests/all.tests @@ -257,6 +257,11 @@ add_plain_test(general, 'scissor-depth-clear') add_plain_test(general, 'scissor-many') add_plain_test(general, 'scissor-offscreen') add_plain_test(general, 'scissor-stencil-clear') +general['GL_SELECT - no test function'] = PlainExecTest(['select', 'general']) +general['GL_SELECT - depth-test enabled'] = PlainExecTest(['select', 'depth']) +general['GL_SELECT - stencil-test enabled'] = PlainExecTest(['select', 'stencil']) +general['GL_SELECT - alpha-test enabled'] = PlainExecTest(['select', 'alpha']) +general['GL_SELECT - scissor-test enabled'] = PlainExecTest(['select', 'scissor']) add_plain_test(general, 'stencil-drawpixels') add_plain_test(general, 'stencil-twoside') add_plain_test(general, 'stencil-wrap') diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt index c6275bee..d6e73cf1 100644 --- a/tests/general/CMakeLists.gl.txt +++ b/tests/general/CMakeLists.gl.txt @@ -87,6 +87,7 @@ add_executable (scissor-depth-clear scissor-depth-clear.c) add_executable (scissor-many scissor-many.c) add_executable (scissor-offscreen scissor-offscreen.c) add_executable (scissor-stencil-clear scissor-stencil-clear.c) +add_executable (select select.c) add_executable (stencil-drawpixels stencil-drawpixels.c) add_executable (stencil-twoside stencil-twoside.c) add_executable (stencil-wrap stencil-wrap.c) diff --git a/tests/general/select.c b/tests/general/select.c new file mode 100644 index 00000000..fa60e39d --- /dev/null +++ b/tests/general/select.c @@ -0,0 +1,260 @@ +/* + * Copyright © 2011 + * + * 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: + * Pierre-Eric Pelloux-Prayer + * + * Description: + * This test represents a simple usage of GL_SELECT rendering mode. + * It draws several squares to screen, with various GL_..._TEST active, + * and then verifies the number of hits and the content of the select buffer. + * Based on this documentation: http://glprogramming.com/red/chapter13.html + * + */ + +#include "piglit-util.h" +#include "piglit-framework.h" + +int piglit_width = 100; +int piglit_height = 100; +int piglit_window_mode = GLUT_RGB | GLUT_ALPHA | GLUT_DEPTH | GLUT_STENCIL; + +GLuint ReferenceHitEntries[3][64]; +#define NAME_STACK_DEPTH 0 +#define MIN_Z 1 +#define MAX_Z 2 +#define NAME_STACK_0 3 + +/** + * Draw 4 objects and handle name stack + */ +static void +draw_objects() +{ + float zscale = (float)(~0u); + glInitNames(); + + /* no draw call issued for name '0' */ + glPushName(0); + + /* OBJECT 1 */ + glPushName(1); + /* draw object */ + glColor3f(1.0, 0.0, 0.0); + piglit_draw_rect_z(0.8, 10, 30, 50, 50); + /* fill reference buffer */ + ReferenceHitEntries[0][NAME_STACK_DEPTH] = 2; + ReferenceHitEntries[0][MIN_Z] = (GLuint)roundf(zscale * ((1 - 0.8) * 0.5)); + ReferenceHitEntries[0][MAX_Z] = ReferenceHitEntries[0][MIN_Z]; + ReferenceHitEntries[0][NAME_STACK_0] = 0; + ReferenceHitEntries[0][NAME_STACK_0 + 1] = 1; + + /* OBJECT 2 */ + /* 2 draw calls for name '2' */ + glPushName(2); + glColor3f(0.0, 1.0, 0.0); + piglit_draw_rect_z(0.5, 40, 5, 25, 30); + piglit_draw_rect_z(0.4, 10, 75, 25, 10); + /* fill reference buffer */ + ReferenceHitEntries[1][NAME_STACK_DEPTH] = 3; + ReferenceHitEntries[1][MIN_Z] = (GLuint)roundf(zscale * ((1 - 0.5)*0.5)); + ReferenceHitEntries[1][MAX_Z] = (GLuint)roundf(zscale * ((1 - 0.4)*0.5)); + ReferenceHitEntries[1][NAME_STACK_0] = 0; + ReferenceHitEntries[1][NAME_STACK_0 + 1] = 1; + ReferenceHitEntries[1][NAME_STACK_0 + 2] = 2; + + /* OBJECT 3 */ + glPopName(); + glPushName(3); + /* drawn offscreen */ + piglit_draw_rect_z(0.3, 250, 45, 280, 20); + + /* OBJECT 4 */ + /* glLoadName instead of glPushName */ + glLoadName(4); + glColor3f(0.0, 0.0, 1.0); + piglit_draw_rect_z(0.2, 50, 45, 80, 20); + /* fill reference buffer */ + ReferenceHitEntries[2][NAME_STACK_DEPTH] = 3; + ReferenceHitEntries[2][MIN_Z] = (GLuint)roundf(zscale * ((1 - 0.2)*0.5)); + ReferenceHitEntries[2][MAX_Z] = ReferenceHitEntries[2][MIN_Z]; + ReferenceHitEntries[2][NAME_STACK_0] = 0; + ReferenceHitEntries[2][NAME_STACK_0 + 1] = 1; + ReferenceHitEntries[2][NAME_STACK_0 + 2] = 4; +} + +/** + * Helper function to compare 2 hit records + */ +static bool +compare_hit_record(GLuint* hit1, GLuint* hit2) +{ + int i; + float zscale = (float)(~0u); + float diffz; + + if (hit1[NAME_STACK_DEPTH] != hit2[NAME_STACK_DEPTH]) { + printf("\t%s : Incorrect name stack depth : %u %u\n", + __FUNCTION__, + hit1[NAME_STACK_DEPTH], + hit2[NAME_STACK_DEPTH]); + return false; + } + + diffz = abs(hit1[MIN_Z] - hit2[MIN_Z])/zscale; + if (diffz > 0.1) { + printf("\t%s : Incorrect Minz : %u %u (%f %f) %f\n", + __FUNCTION__, + hit1[MIN_Z], + hit2[MIN_Z], + hit1[MIN_Z] / zscale, + hit2[MIN_Z] / zscale, + diffz); + return false; + } + + diffz = abs(hit1[MAX_Z] - hit2[MAX_Z])/zscale; + if (diffz > 0.1) { + printf("\t%s : Incorrect Maxz : %u %u (%f %f) %f\n", + __FUNCTION__, + hit1[MAX_Z], + hit2[MAX_Z], + hit1[MAX_Z] / zscale, + hit2[MAX_Z] / zscale, + diffz); + return false; + } + + for (i=0; i