diff options
author | Brian Paul <brianp@vmware.com> | 2018-01-17 13:12:45 -0700 |
---|---|---|
committer | Brian Paul <brianp@vmware.com> | 2018-01-18 16:33:00 -0700 |
commit | d7bc75f18f0ccbaedfcdb0d2fcda44866a3d6acc (patch) | |
tree | bc20aff0074a1735266724a3c793c43b16fbbec7 /tests | |
parent | 829e440fca05bf20c5d9b8aee4584f3a126f3642 (diff) |
gl-1.0-dlist-materials: new test of materials in display lists
This exercises two code paths in Mesa's display list VBO code.
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/all.py | 1 | ||||
-rw-r--r-- | tests/spec/gl-1.0/CMakeLists.gl.txt | 1 | ||||
-rw-r--r-- | tests/spec/gl-1.0/dlist-materials.c | 164 |
3 files changed, 166 insertions, 0 deletions
diff --git a/tests/all.py b/tests/all.py index cd16ce9f5..2a2c31aee 100644 --- a/tests/all.py +++ b/tests/all.py @@ -717,6 +717,7 @@ with profile.test_list.group_manager( g(['gl-1.0-beginend-coverage']) g(['gl-1.0-dlist-beginend']) g(['gl-1.0-dlist-bitmap']) + g(['gl-1.0-dlist-materials']) g(['gl-1.0-dlist-shademodel']) g(['gl-1.0-drawpixels-color-index']) g(['gl-1.0-drawpixels-depth-test']) diff --git a/tests/spec/gl-1.0/CMakeLists.gl.txt b/tests/spec/gl-1.0/CMakeLists.gl.txt index 2df3a8cf4..e5986968c 100644 --- a/tests/spec/gl-1.0/CMakeLists.gl.txt +++ b/tests/spec/gl-1.0/CMakeLists.gl.txt @@ -13,6 +13,7 @@ piglit_add_executable (gl-1.0-beginend-coverage beginend-coverage.c) piglit_add_executable (gl-1.0-blend-func blend.c) piglit_add_executable (gl-1.0-dlist-beginend dlist-beginend.c) piglit_add_executable (gl-1.0-dlist-bitmap dlist-bitmap.c) +piglit_add_executable (gl-1.0-dlist-materials dlist-materials.c) piglit_add_executable (gl-1.0-dlist-shademodel dlist-shademodel.c) piglit_add_executable (gl-1.0-drawbuffer-modes drawbuffer-modes.c) piglit_add_executable (gl-1.0-drawpixels-color-index drawpixels-color-index.c) diff --git a/tests/spec/gl-1.0/dlist-materials.c b/tests/spec/gl-1.0/dlist-materials.c new file mode 100644 index 000000000..70036ae67 --- /dev/null +++ b/tests/spec/gl-1.0/dlist-materials.c @@ -0,0 +1,164 @@ +/* + * Copyright (C) 2018 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. + */ + +/** + * Test glMaterial calls in a display list. + */ + +#include "piglit-util-gl.h" + + +PIGLIT_GL_TEST_CONFIG_BEGIN + config.supports_gl_compat_version = 10; + config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGBA; + config.khr_no_error_support = PIGLIT_NO_ERRORS; +PIGLIT_GL_TEST_CONFIG_END + + +static const GLfloat red[] = {1.0, 0.0, 0.0, 1.0}; +static const GLfloat green[] = {0.0, 1.0, 0.0, 1.0}; +static const GLfloat black[] = {0.0, 0.0, 0.0, 1.0}; +static const GLfloat white[] = {1.0, 1.0, 1.0, 1.0}; + + +/** + * Build display list to draw two quads with a triangle strip + * using glMaterial calls to set vertex colors. + * \param set_all If true, set the material attribs for all vertices. + * Otherwise, just set the material attribs for two + * provoking vertices. + * + * Note: the set_all parameter controls whether Mesa hits the "loopback" code. + */ +static GLuint +make_list(GLenum mat, bool set_all) +{ + GLuint list; + + list = glGenLists(1); + glNewList(list, GL_COMPILE); + + /* + * Draw tri strip drawing two quads - left=red, right=green. + */ + glShadeModel(GL_FLAT); + glBegin(GL_TRIANGLE_STRIP); + glNormal3f(0, 0, 1); + + /* v0 */ + if (set_all) + glMaterialfv(GL_FRONT_AND_BACK, mat, red); + glVertex2f(-1, -1); + + /* v1 */ + if (set_all) + glMaterialfv(GL_FRONT_AND_BACK, mat, red); + glVertex2f(-1, 1); + + /* v2 */ + glMaterialfv(GL_FRONT_AND_BACK, mat, red); + glVertex2f( 0, -1); + + /* v3 */ + if (set_all) + glMaterialfv(GL_FRONT_AND_BACK, mat, red); + glVertex2f( 0, 1); + + /* v4 */ + glMaterialfv(GL_FRONT_AND_BACK, mat, green); + glVertex2f( 1, -1); + + /* v5 */ + if (set_all) + glMaterialfv(GL_FRONT_AND_BACK, mat, green); + glVertex2f( 1, 1); + + glEnd(); + + glEndList(); + + return list; +} + + +static bool +test_material(GLenum mat, bool set_all) +{ + bool pass = true; + GLint w = piglit_width; + GLint h = piglit_height; + + glClear(GL_COLOR_BUFFER_BIT); + + /* init all material coefficients to black */ + glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, black); + glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, black); + glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, black); + glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, black); + + GLuint list = make_list(mat, set_all); + glCallList(list); + glDeleteLists(list, 1); + + pass = piglit_probe_pixel_rgb(w/2-2, h/2, red) && pass; + pass = piglit_probe_pixel_rgb(w/2+2, h/2, green) && pass; + + piglit_present_results(); + + if (!pass) { + printf("Failed testing %s material (set_all = %u)\n", + piglit_get_gl_enum_name(mat), set_all); + } + + return pass; +} + + +enum piglit_result +piglit_display(void) +{ + bool pass = true; + + pass = test_material(GL_AMBIENT, false) && pass; + pass = test_material(GL_DIFFUSE, false) && pass; + pass = test_material(GL_SPECULAR, false) && pass; + pass = test_material(GL_EMISSION, false) && pass; + + pass = test_material(GL_AMBIENT, true) && pass; + pass = test_material(GL_DIFFUSE, true) && pass; + pass = test_material(GL_SPECULAR, true) && pass; + pass = test_material(GL_EMISSION, true) && pass; + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + + +void +piglit_init(int argc, char **argv) +{ + glEnable(GL_LIGHTING); + glEnable(GL_LIGHT0); + glLightfv(GL_LIGHT0, GL_AMBIENT, white); + glLightfv(GL_LIGHT0, GL_DIFFUSE, white); + glLightfv(GL_LIGHT0, GL_SPECULAR, white); +} |