[Piglit] [PATCH] texture: add a 1:1 linear texture test case

Eric Anholt eric at anholt.net
Mon Oct 17 08:36:26 PDT 2011


On Mon, 17 Oct 2011 11:48:57 +0800, Yuanhan Liu <yuanhan.liu at linux.intel.com> wrote:
> To test that the 1:1 texture with filter set to linear it sampled
> correctly.
> 
> Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
> ---
>  tests/all.tests                      |    1 +
>  tests/texturing/1-1-linear-texture.c |  104 ++++++++++++++++++++++++++++++++++
>  tests/texturing/CMakeLists.gl.txt    |    1 +
>  3 files changed, 106 insertions(+), 0 deletions(-)
>  create mode 100644 tests/texturing/1-1-linear-texture.c
> 
> diff --git a/tests/texturing/1-1-linear-texture.c b/tests/texturing/1-1-linear-texture.c
> new file mode 100644
> index 0000000..348f180
> --- /dev/null
> +++ b/tests/texturing/1-1-linear-texture.c
> @@ -0,0 +1,104 @@
> +/*
> + * Copyright © 2011 Intel Corporation
> + *
> + * 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:
> + *    Yuanhan Liu <yuanhan.liu at linux.intel.com>
> + *
> + */
> +
> +/*
> + * Tests that the 1:1 texture with filter set to linear is sampled correctly.
> + */
> +
> +#include "piglit-util.h"
> +
> +int piglit_width = 100;
> +int piglit_height = 100;
> +int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
> +
> +#define DATA_SIZE	(piglit_width * piglit_height * 4)
> +
> +static void * make_tex_data(void)
> +{
> +	int i;
> +	GLubyte *data = malloc(DATA_SIZE);
> +
> +	for (i = 0; i < DATA_SIZE; i++) {
> +		if (i % 4 == 3)
> +			data[i] = 255;
> +		else
> +			data[i] = random() % 256;
> +	}
> +
> +	return data;
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	GLuint tex;
> +	GLboolean pass;
> +	void *tex_data = make_tex_data();
> +	void *out_data = malloc(DATA_SIZE);
> +
> +	glClearColor(0.0, 0.0, 0.0, 1.0);

ClearColor but no clear?

> +
> +	glGenTextures(1, &tex);
> +	glBindTexture(GL_TEXTURE_2D, tex);
> +	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, piglit_width, piglit_height,
> +	             0, GL_RGBA, GL_UNSIGNED_BYTE, tex_data);
> +
> +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
> +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
> +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
> +	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
> +

GL_CLAMP has at various points triggered driver fallbacks.
GL_CLAMP_TO_EDGE instead would ensure that you get hardware rendering,
which is what we really care about testing.

> +	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
> +	glEnable(GL_TEXTURE_2D);
> +
> +	glBegin(GL_QUADS);
> +	  glTexCoord2f(0.0, 0.0);
> +	  glVertex2f(-1.0, -1.0);
> +	  glTexCoord2f(1.0, 0.0);
> +	  glVertex2f(1.0, -1.0);
> +	  glTexCoord2f(1.0, 1.0);
> +	  glVertex2f(1.0,  1.0);
> +	  glTexCoord2f(0.0, 1.0);
> +	  glVertex2f(-1.0,  1.0);
> +	glEnd();
> +	glutSwapBuffers();
> +
> +	glReadPixels(0, 0, piglit_width, piglit_height, GL_RGBA, 
> +	             GL_UNSIGNED_BYTE, out_data);

After a swapbuffers, backbuffer data is undefined.  Put the swap after
the read to avoid failures in composited environments.

(Also, using piglit_present_results() instead of glutSwapBuffers() would
mean that the test could be added as a concurrent test to reduce test
runtime)

> +
> +	pass = memcmp(tex_data, out_data, DATA_SIZE) == 0;

There should be some sort of feedback -- at least what pixel failed and
some hex values.

> +
> +	free(tex_data);
> +	free(out_data);
> +
> +	return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{

Since you use rectangular textures here, you should require
GL_ARB_texture_rectangle.

> +}

-------------- 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/20111017/2b8a54dc/attachment.pgp>


More information about the Piglit mailing list