diff options
author | Brian Paul <brianp@vmware.com> | 2010-01-29 09:35:35 -0700 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2010-01-29 09:35:38 -0700 |
commit | fca71800219c9eb5af1ff64643361f1ee6bb5477 (patch) | |
tree | 5b81a7164b726b812caa70cafbc855f51eeee99e | |
parent | 9b530deee236842fa80371a3f2c72167e24f9474 (diff) |
draw-elements-vs-inputs: glDraw[Range]Elements regression test
This checks a bug that was recently fixed in Mesa. See comments in
file for details.
-rw-r--r-- | tests/general/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/general/draw-elements-vs-inputs.c | 174 |
2 files changed, 175 insertions, 0 deletions
diff --git a/tests/general/CMakeLists.txt b/tests/general/CMakeLists.txt index 6fbf1dee..8667f884 100644 --- a/tests/general/CMakeLists.txt +++ b/tests/general/CMakeLists.txt @@ -29,6 +29,7 @@ add_executable (dlist-fdo3129-02 dlist-fdo3129-02.c) add_executable (depth_clamp depth_clamp.c) add_executable (depthrange-clear depthrange-clear.c) add_executable (draw-elements-base-vertex draw-elements-base-vertex.c) +add_executable (draw-elements-vs-inputs draw-elements-vs-inputs.c) add_executable (linestipple linestipple.c) add_executable (pbo-drawpixels pbo-drawpixels.c) add_executable (pbo-read-argb8888 pbo-read-argb8888.c) diff --git a/tests/general/draw-elements-vs-inputs.c b/tests/general/draw-elements-vs-inputs.c new file mode 100644 index 00000000..d11df663 --- /dev/null +++ b/tests/general/draw-elements-vs-inputs.c @@ -0,0 +1,174 @@ +/* + * Copyright © 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 + * 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: + * Brian Paul + */ + + +/** + * @file draw-elements-vs-inputs.c + * + * Test that state validation is properly done between calls to + * glDrawRangeElements() / glDrawElements() when VS inputs change between + * calls (with regard to per-vertex vs. per-primitive values). + * + * This is a regression test for a bug in Mesa/gallium/softpipe which + * was fixed with commit 3cba779e16935f7c3a0bfd8af48bd5e015068e96. + */ + + +#include "piglit-util.h" + + +int piglit_width = 300, piglit_height = 300; +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE; + + +void +piglit_init(int argc, char **argv) +{ + GLfloat red[4] = {1, 0, 0, 1}; + + glewInit(); + + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, red); + + glEnable(GL_DEPTH_TEST); + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + + glEnable(GL_NORMALIZE); + + glClearColor(0.5, 0.5, 0.5, 0.5); + + /* + printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); + printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); + */ +} + + +static void +draw_quad(GLboolean normals, GLboolean rangeElements) +{ + static GLfloat norms[4][3] = { + { -0.1, -0.1, 1 }, + { 0.1, -0.1, 1 }, + { 0.1, 0.1, 1 }, + { -0.1, 0.1, 1 } + }; + static GLfloat verts[4][3] = { + { -25, -25, 0.0 }, + { 25, -25, 0.0 }, + { 25, 25, 0.0 }, + { -25, 25, 0.0 } + }; + static GLuint indexes[4] = { 0, 1, 2, 3 }; + + if (normals) { + glNormalPointer(GL_FLOAT, 0, norms); + glEnableClientState(GL_NORMAL_ARRAY); + } + else { + glNormal3f(1, 1, 1); + } + glVertexPointer(3, GL_FLOAT, 0, verts); + glEnableClientState(GL_VERTEX_ARRAY); + if (rangeElements) + glDrawRangeElements(GL_QUADS, 0, 3, 4, GL_UNSIGNED_INT, indexes); + else + glDrawElements(GL_QUADS, 4, GL_UNSIGNED_INT, indexes); + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); +} + + +enum piglit_result +piglit_display(void) +{ + const GLfloat expected1[3] = { 1.0, 0.039, 0.039, }; + const GLfloat expected2[3] = { 0.615, 0.039, 0.039, }; + GLint row; + GLboolean pass = GL_TRUE; + + glViewport(0, 0, piglit_width, piglit_height); + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glOrtho(0, piglit_width, 0, piglit_height, -1.0, 1.0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + /* first row = glDrawElements, second row = glDrawRangeElements */ + for (row = 0; row < 2; row++) { + GLint x0 = piglit_width/4; + GLint x1 = piglit_width/2; + GLint x2 = piglit_width*3/4; + GLint y = (piglit_height / 3) * (row + 1); + GLboolean rangeElements = row == 1; + + /* quad with per-vertex normals */ + if (1) { + glPushMatrix(); + glTranslatef(x0, y, 0); + draw_quad(GL_TRUE, rangeElements); + glPopMatrix(); + glFlush(); + } + + /* quad with one normal */ + if (1) { + glPushMatrix(); + glTranslatef(x1, y, 0); + glNormal3f(1, 0.5, 0.25); + draw_quad(GL_FALSE, rangeElements); + glPopMatrix(); + glFlush(); + } + + /* another quad with per-vertex normals */ + if (1) { + glPushMatrix(); + glTranslatef(x2, y, 0); + draw_quad(GL_TRUE, rangeElements); + glPopMatrix(); + } + + /* left quad */ + pass = piglit_probe_pixel_rgb(x0, y, expected1) && pass; + + /* middle quad */ + pass = piglit_probe_pixel_rgb(x1, y, expected2) && pass; + + /* right quad */ + pass = piglit_probe_pixel_rgb(x2, y, expected1) && pass; + } + + glutSwapBuffers(); + + return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE; +} + |