[Piglit] [PATCH 1/1] Add a test for viewport clipping.

Brian Paul brianp at vmware.com
Fri Nov 2 07:13:50 PDT 2012


On 11/01/2012 07:00 PM, Stuart Abercrombie wrote:
> This was failing on Sandy Bridge with guard band clipping enabled.
> ---
>   tests/general/CMakeLists.gl.txt |    1 +
>   tests/general/viewport-clip.c   |   51 +++++++++++++++++++++++++++++++++++++++
>   2 files changed, 52 insertions(+), 0 deletions(-)
>   create mode 100644 tests/general/viewport-clip.c

Update the all.tests file?


>
> diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt
> index 11da25f..e1dcf23 100644
> --- a/tests/general/CMakeLists.gl.txt
> +++ b/tests/general/CMakeLists.gl.txt
> @@ -134,5 +134,6 @@ piglit_add_executable (occlusion-query-discard occlusion-query-discard.c)
>   piglit_add_executable (quad-invariance quad-invariance.c)
>   piglit_add_executable (clear-accum clear-accum.c)
>   piglit_add_executable (vs-point_size-zero vs-point_size-zero.c)
> +piglit_add_executable (viewport-clip viewport-clip.c)
>
>   # vim: ft=cmake:
> diff --git a/tests/general/viewport-clip.c b/tests/general/viewport-clip.c
> new file mode 100644
> index 0000000..d4dcdc1
> --- /dev/null
> +++ b/tests/general/viewport-clip.c
> @@ -0,0 +1,51 @@
> +/** @file viewport-clip.c
> + *
> + * Tests whether rendering is clipped to the viewport.

Just to be clear, the viewport defines a coordinate transformation, 
not a clipping rectangle.  We clip against the sides of the NDC cube 
which in turn get mapped to the viewport coords.  It works out that 
triangles effectively get clipped to the viewport bounds, but points, 
lines, glDrawPixels, glBlitFramebuffer, glClear, etc. can all draw 
outside the viewport.

Maybe you could clarify your comment above that you're specifically 
concerned with guardband clipping so there's more context as to what's 
being tested here.

Maybe also rename the test to be more specific, like 
triangle-guardband-viewport.c, or something like that.

BTW, how does the i965 driver handle this situation?  Is a scissor 
rect set up to match the viewport?  If so, we should probably have a 
test that checks that glDrawPixels, glBlit, sprite points, etc. 
_aren't_ clipped to the viewport in that situation.

A few more comments below would be good...


> + */
> +
> +#include "piglit-util-gl-common.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 10;
> +
> +	config.window_width = 100;
> +	config.window_height = 100;
> +	config.window_visual = PIGLIT_GL_VISUAL_DOUBLE | PIGLIT_GL_VISUAL_RGB;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	GLboolean pass = GL_TRUE;
> +	static float green[] = {0.0, 1.0, 0.0, 0.0};
> +	static float blue[]  = {0.0, 0.0, 1.0, 0.0};
> +
> +	/* whole window green. */
> +	glClearColor(0.0, 1.0, 0.0, 0.0);
> +	glClear(GL_COLOR_BUFFER_BIT);
> +

	/* Viewport is left half of window */
> +	glViewport(0, 0, piglit_width / 2, piglit_height);
> +
> +	glColor4fv(blue);

	/* draw rect extending beyond right edge of frustum */
> +	piglit_draw_rect(-1.0, -1.0, 4.0, 2.0);
> +

	/* check that right half of window is still the clear color */
> +	pass&= piglit_probe_rect_rgb(piglit_width/2, 0,
> +				piglit_width/2, piglit_height, green);
> +
> +
> +	piglit_present_results();
> +
> +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	glMatrixMode(GL_PROJECTION);
> +	glLoadIdentity();
> +
> +	glMatrixMode(GL_MODELVIEW);
> +	glLoadIdentity();
> +}

Reviewed-by: Brian Paul <brianp at vmware.com>


More information about the Piglit mailing list