[Piglit] [PATCH] general: Add a spot light sanity check
Brian Paul
brianp at vmware.com
Mon Aug 22 14:34:37 UTC 2016
On 08/19/2016 09:20 PM, Daniel Scharrer wrote:
> Signed-off-by: Daniel Scharrer <daniel at constexpr.org>
> ---
>
> This tests for the bug fixed by the Mesa patch at
> https://patchwork.freedesktop.org/patch/106411/
>
> The test passes on amdgpu-pro, llvmpipe (patched and unpatched)
> and radeonsi (patched). It fails on unpatched radeonsi.
>
> tests/all.py | 1 +
> tests/general/CMakeLists.gl.txt | 1 +
> tests/general/spot-light.c | 131 ++++++++++++++++++++++++++++++++++++++++
We're trying to get away from dumping new tests in the general/, bugs/
etc. directories.
How about putting this into tests/spec/gl-1.0/ ?
> 3 files changed, 133 insertions(+)
> create mode 100644 tests/general/spot-light.c
>
> diff --git a/tests/all.py b/tests/all.py
> index e110f59..8b94c48 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -876,6 +876,7 @@ with profile.group_manager(
> run_concurrent=False)
> g(['select', 'scissor'], 'GL_SELECT - scissor-test enabled',
> run_concurrent=False)
> + g(['spot-light'], run_concurrent=False)
> g(['stencil-drawpixels'], run_concurrent=False)
> g(['texgen'], run_concurrent=False)
> g(['two-sided-lighting'], run_concurrent=False)
> diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
> index 3a46fb0..6adacee 100644
> --- a/tests/general/CMakeLists.gl.txt
> +++ b/tests/general/CMakeLists.gl.txt
> @@ -108,6 +108,7 @@ piglit_add_executable (scissor-offscreen scissor-offscreen.c)
> piglit_add_executable (scissor-polygon scissor-polygon.c)
> piglit_add_executable (scissor-stencil-clear scissor-stencil-clear.c)
> piglit_add_executable (select select.c)
> +piglit_add_executable (spot-light spot-light.c)
> piglit_add_executable (stencil-drawpixels stencil-drawpixels.c)
> piglit_add_executable (stencil-twoside stencil-twoside.c)
> piglit_add_executable (stencil-wrap stencil-wrap.c)
> diff --git a/tests/general/spot-light.c b/tests/general/spot-light.c
> new file mode 100644
> index 0000000..a800aca
> --- /dev/null
> +++ b/tests/general/spot-light.c
> @@ -0,0 +1,131 @@
> +/*
> + * Copyright (C) 2016 Daniel Scharrer <daniel at constexpr.org>
> + *
> + * 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.
> + */
> +
> +/** @file spot-light.c
> + *
> + * This is a simple sanity test for fixed function spot lights in OpenGL.
> + *
> + * It tests that vertices directly in front of the spot light are lit with
> + * full intensity and that lighting of vertices beyond the spot cutoff,
> + * and especially of those behind the spot light, is not affected by the
> + * spot light. This is done for three spot lights with different exponents.
> + */
> +
> +#include "piglit-util-gl.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> + config.supports_gl_compat_version = 10;
> +
> + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +static GLfloat pos[4] = {5.0, 5.0, 0.0, 1.0}; /* center */
> +static GLfloat light0_dir[3] = {-1.0, 0.0, 0.0}; /* left */
> +static GLfloat light1_dir[3] = {0.0, 1.0, 0.0}; /* up */
> +static GLfloat light2_dir[3] = {1.0, 0.0, 0.0}; /* right */
> +static GLfloat light0_ambient[4] = {1.0, 0.0, 0.0, 1.0};
> +static GLfloat light1_ambient[4] = {0.0, 1.0, 0.0, 1.0};
> +static GLfloat light2_ambient[4] = {0.0, 0.0, 1.0, 1.0};
> +static GLfloat global_ambient[4] = {0.2, 0.2, 0.2, 1.0};
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + GLboolean pass = GL_TRUE;
Nowadays we try to use bool/true/false.
> + GLfloat expected_left[4] = {1.0, 0.2, 0.2, 1.0};
> + GLfloat expected_bottom[4] = {0.2, 0.2, 0.2, 1.0};
> + GLfloat expected_right[4] = {0.2, 0.2, 1.0, 1.0};
> + GLfloat expected_top[4] = {0.2, 1.0, 0.2, 1.0};
> + GLfloat expected_bottom_left[4] = {0.2, 0.2, 0.2, 1.0};
> + GLfloat expected_top_left[4] = {0.2, 1.0, 0.2, 1.0};
> + GLfloat expected_bottom_right[4] = {0.2, 0.2, 0.2, 1.0};
> + GLfloat expected_top_right[4] = {0.2, 1.0, 0.2, 1.0};
Those could be declared static const, but not a big deal.
> +
> + glClear(GL_COLOR_BUFFER_BIT);
> +
> + glPointSize(1);
> + glBegin(GL_POINTS);
> + for(int x = 0; x < 11; x++)
> + for(int y = 0; y < 11; y++)
More indentation.
> + {
> + glVertex2f(x, y);
> + }
> + glEnd();
> +
> + pass = pass && piglit_probe_pixel_rgba( 0, 5, expected_left);
> + pass = pass && piglit_probe_pixel_rgba( 5, 0, expected_bottom);
> + pass = pass && piglit_probe_pixel_rgba(10, 5, expected_right);
> + pass = pass && piglit_probe_pixel_rgba( 5, 10, expected_top);
> + pass = pass && piglit_probe_pixel_rgba( 0, 0, expected_bottom_left);
> + pass = pass && piglit_probe_pixel_rgba( 0, 10, expected_top_left);
> + pass = pass && piglit_probe_pixel_rgba(10, 0, expected_bottom_right);
> + pass = pass && piglit_probe_pixel_rgba(10, 10, expected_top_right);
We have to really careful when probing the color drawn by 1-pixel
points. Minor differences in rasterization from one driver to another
could cause the points to be drawn at different locations.
IIRC, a 0.375 translation with an orthographic projection is supposed to
be reliable.
Otherwise, you might consider spreading out the primitives and drawing
small quads at each location, or larger points.
> +
> + piglit_present_results();
> +
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + GLfloat zero[4] = {0.0, 0.0, 0.0, 1.0};
> + GLfloat one[4] = {1.0, 1.0, 1.0, 1.0};
> +
> + glClearColor(0.0, 0.0, 0.0, 1.0);
> +
> + glEnable(GL_LIGHT0);
> + glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 44.0);
> + glLightf(GL_LIGHT0, GL_SPOT_EXPONENT, 1.0);
> + glLightfv(GL_LIGHT0, GL_POSITION, pos);
> + glLightfv(GL_LIGHT0, GL_SPOT_DIRECTION, light0_dir);
> + glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
> +
> + glEnable(GL_LIGHT1);
> + glLightf(GL_LIGHT1, GL_SPOT_CUTOFF, 60.0);
> + glLightf(GL_LIGHT1, GL_SPOT_EXPONENT, 0.0);
> + glLightfv(GL_LIGHT1, GL_POSITION, pos);
> + glLightfv(GL_LIGHT1, GL_SPOT_DIRECTION, light1_dir);
> + glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
> +
> + glEnable(GL_LIGHT2);
> + glLightf(GL_LIGHT2, GL_SPOT_CUTOFF, 44.0);
> + glLightf(GL_LIGHT2, GL_SPOT_EXPONENT, 5.0);
> + glLightfv(GL_LIGHT2, GL_POSITION, pos);
> + glLightfv(GL_LIGHT2, GL_SPOT_DIRECTION, light2_dir);
> + glLightfv(GL_LIGHT2, GL_AMBIENT, light2_ambient);
> +
> + glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);
> + glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0);
> +
> + /* We are not interested in testing diffuse lighting, enable only the ambient term. */
> + glMaterialfv(GL_FRONT, GL_DIFFUSE, zero);
> + glMaterialfv(GL_FRONT, GL_AMBIENT, one);
> +
> + glEnable(GL_LIGHTING);
> +
> + piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
> +}
>
More information about the Piglit
mailing list