[Piglit] [PATCH 2/2] gles2: new glReadPixels unit test

Eric Anholt eric at anholt.net
Wed Nov 28 12:13:23 PST 2012


Tom Gall <tom.gall at linaro.org> writes:

> Unit test for glReadPixels specifically for OpenGL v2.0. Covers a
> variety of formats and types, both valid and invalid.
>
> A few variations are commented out due to the results are incorrect
> and need to be followed up with Mesa, such as modifying the buffer
> even tho the format is invalid, incorrect returned data. These
> can be addressed in time and I thought it best to include the
> variations but in their commented out form.
>
> Signed-off-by: Tom Gall <tom.gall at linaro.org>
> ---
>  tests/all_es2.tests                   |    1 +
>  tests/gles2/CMakeLists.gles2.txt      |    3 +
>  tests/gles2/gles2_unit_glReadPixels.c |  702 +++++++++++++++++++++++++++++++++
>  3 files changed, 706 insertions(+)
>  create mode 100644 tests/gles2/gles2_unit_glReadPixels.c
>
> diff --git a/tests/all_es2.tests b/tests/all_es2.tests
> index 61a2329..699186a 100644
> --- a/tests/all_es2.tests
> +++ b/tests/all_es2.tests
> @@ -24,5 +24,6 @@ oes_compressed_etc1_rgb8_texture['miptree'] = PlainExecTest(['oes_compressed_etc
>  gles2_tests = Group()
>  spec['gles2_tests'] = gles2_tests
>  gles2_tests['gles2_simple_triangle'] =  PlainExecTest(['gles2_simple_triangle', '-auto'])
> +gles2_tests['gles2_unit_glReadPixels'] =  PlainExecTest(['gles2_unit_glReadPixels', '-auto'])
>  

trailing whitespace

>  profile.tests['spec'] = spec
> diff --git a/tests/gles2/CMakeLists.gles2.txt b/tests/gles2/CMakeLists.gles2.txt
> index 633a2ed..7be1131 100644
> --- a/tests/gles2/CMakeLists.gles2.txt
> +++ b/tests/gles2/CMakeLists.gles2.txt
> @@ -16,5 +16,8 @@ piglit_add_executable(gles2_shader_runner
>  piglit_add_executable(gles2_simple_triangle
>  	gles2_simple_triangle.c
>  	)
> +piglit_add_executable(gles2_unit_glReadPixels
> +	gles2_unit_glReadPixels.c
> +	)

Generally we keep these on a single line

>  
>  # vim: ft=cmake:
> diff --git a/tests/gles2/gles2_unit_glReadPixels.c b/tests/gles2/gles2_unit_glReadPixels.c
> new file mode 100644
> index 0000000..762bf7d
> --- /dev/null
> +++ b/tests/gles2/gles2_unit_glReadPixels.c
> @@ -0,0 +1,702 @@
> +/*
> + * Copyright © 2012 Linaro 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.
> + */
> +
> +/**
> + * This is a unit test to exercise glReadPixels
> + * as specified by the OpenGL ES 2.0 spec.
> + *
> + * Todo: GL_PACK_ALIGHNMENT via glPixelStorei isn't tested

spelling

> + *       reading from GL_COLOR_ATTACHMENT0 when the default framebuffer
> + *          isn't bound is not tested
> + *       combo of GL_IMPLEMENTATION_COLOR_READ_FORMAT
> + *          GL_IMPLEMENTATION_COLOR_READ_TYPE is not tested
> + *
> + * \author Tom Gall <tom.gall at linaro.org>
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <stdlib.h>
> +#include <stdio.h>
> +#include "piglit-util-gl-common.h"
> +
> +#define WIDTH 320
> +#define HEIGHT 200
> +#define TEST_PATTERN_BYTE 0xA5
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_es2 = true;
> +	config.requires_displayed_window = true;
> +
> +	config.window_width = WIDTH;
> +	config.window_height = HEIGHT;
> +	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DEPTH;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +GLuint prog;
> +GLuint frag;
> +GLuint vert;
> +/* pad a bit so we can do a request larger than the viewport */
> +GLubyte buffer[HEIGHT+50][WIDTH][4];
> +
> +char vertex_shader [] = "\
> +attribute vec4 vPosition; \
> +void main() \
> +{ \
> +	gl_Position = vPosition; \
> +}"; 

trailing whitespace

Please chmod +x .git/hooks/pre-commit so we don't have to tell you each
time.

> +char fragment_shader [] = "\
> +precision mediump float; \
> +void main() \
> +{ \
> +	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); \
> +}"; 

Just use string concatenation, it's more portable and consistent with
the project.

const char fragment_shader [] =
	"precision mediump float;\n"
	"void main()\n"
	"{\n"
	"	gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);\n"
	"}\n"

> +GLenum
> +check_for_glError(char *message)
> +{
> +	GLenum err;
> +
> +	err = glGetError();
> +	if (err) {
> +		GLchar *info;
> +		GLint size;
> +
> +		printf("%s: 0x%04x\n",message, err);
> +
> +		glGetProgramiv(prog, GL_INFO_LOG_LENGTH, &size);
> +		info = malloc(size);
> +
> +		glGetProgramInfoLog(prog, size, NULL, info);
> +		fprintf(stderr, "Info log: %s\n", info);
> +
> +		piglit_report_result(PIGLIT_FAIL);
> +		free(info);
> +		return err;
> +	}
> +	return err;
> +}

This isn't checking for glerror, this is checking for compile errors for
some weird reason.

> +void
> +clear_buffer(void)
> +{
> +	memset(&buffer,TEST_PATTERN_BYTE,WIDTH*(HEIGHT+50)*4);
> +}

Spaces after commas.

> +	/* check that the triangle was rendered correctly */
> +	for (i=148;i>49;i--) {
> +		linestart=159;
> +		lineend=160;
> +		for(j=linestart;j<=lineend;j++) {
> +			p888=(pixel_f888 *)(((GLubyte *)buffer)+(((i*WIDTH)+j)*3));
> +			if (p888->red!=0xff && p888->green!=0x00 && p888->blue!=0x00)
> +				return PIGLIT_FAIL;
> +		}
> +	linestart--;
> +	lineend++;
> +	}

What is up with this triangle probing?  Render nice rectangles for sanity.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20121128/5e25584f/attachment.pgp>


More information about the Piglit mailing list