[Piglit] [PATCH 1/2] port ttexrect.cpp to piglit from glean

Brian Paul brianp at vmware.com
Fri Feb 8 07:12:04 PST 2013


On 02/07/2013 10:45 PM, Tom Gall wrote:
> This ported test goes into tests/spec/arb_texture_rectangle. It
> tests the ARB_texture_rectangle extension.
>
> Create a 255x127 texture of varying colors and bind it as a
> GL_ARB_texture_recangle target.  Draw that rectangle to the window, and
> check that the texture was drawn correctly.  The common failure to be
> caught with this test is not adjusting the non-normalized coordinates on
> hardware that expects normalized coordinates.
>
> To all.tests, add new texrect_simple_arb_texrect
>
> v2: add PIGLIT_GL_VISUAL_DOUBLE to the window_visual, move various
> setup bits to piglit_init and add forgotten all.tests change.
> v3: use piglit_present_results, and piglit_probe_image_rgb
>

I keep finding more little things to fix...


> Signed-off-by: Tom Gall<tom.gall at linaro.org>
> ---
>   tests/all.tests                                    |    1 +
>   tests/spec/CMakeLists.txt                          |    1 +
>   tests/spec/arb_texture_rectangle/CMakeLists.gl.txt |   13 ++
>   tests/spec/arb_texture_rectangle/CMakeLists.txt    |    1 +
>   tests/spec/arb_texture_rectangle/texrect-simple.c  |  127 ++++++++++++++++++++
>   5 files changed, 143 insertions(+)
>   create mode 100644 tests/spec/arb_texture_rectangle/CMakeLists.gl.txt
>   create mode 100644 tests/spec/arb_texture_rectangle/CMakeLists.txt
>   create mode 100644 tests/spec/arb_texture_rectangle/texrect-simple.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 3e2d3f8..9b9be9f 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -1128,6 +1128,7 @@ arb_texture_rectangle['copyteximage RECT'] = PlainExecTest(['copyteximage', '-au
>   add_concurrent_test(arb_texture_rectangle, '1-1-linear-texture')
>   add_plain_test(arb_texture_rectangle, 'texrect-many')
>   add_concurrent_test(arb_texture_rectangle, 'getteximage-targets RECT')
> +add_plain_test(arb_texture_rectangle, 'texrect_simple_arb_texrect')
>
>   arb_texture_storage = Group()
>   spec['ARB_texture_storage'] = arb_texture_storage
> diff --git a/tests/spec/CMakeLists.txt b/tests/spec/CMakeLists.txt
> index df87181..1b72040 100644
> --- a/tests/spec/CMakeLists.txt
> +++ b/tests/spec/CMakeLists.txt
> @@ -24,6 +24,7 @@ add_subdirectory (arb_texture_buffer_object)
>   add_subdirectory (arb_texture_compression)
>   add_subdirectory (arb_texture_cube_map_array)
>   add_subdirectory (arb_texture_float)
> +add_subdirectory (arb_texture_rectangle)
>   add_subdirectory (arb_texture_storage)
>   add_subdirectory (arb_timer_query)
>   add_subdirectory (arb_transform_feedback2)
> diff --git a/tests/spec/arb_texture_rectangle/CMakeLists.gl.txt b/tests/spec/arb_texture_rectangle/CMakeLists.gl.txt
> new file mode 100644
> index 0000000..d84a850
> --- /dev/null
> +++ b/tests/spec/arb_texture_rectangle/CMakeLists.gl.txt
> @@ -0,0 +1,13 @@
> +include_directories(
> +	${GLEXT_INCLUDE_DIR}
> +	${OPENGL_INCLUDE_PATH}
> +	${piglit_SOURCE_DIR}/tests/mesa/util
> +)
> +
> +link_libraries (
> +	piglitutil_${piglit_target_api}
> +	${OPENGL_gl_LIBRARY}
> +	${OPENGL_glu_LIBRARY}
> +)
> +
> +piglit_add_executable (texrect_simple_arb_texrect texrect-simple.c)
> diff --git a/tests/spec/arb_texture_rectangle/CMakeLists.txt b/tests/spec/arb_texture_rectangle/CMakeLists.txt
> new file mode 100644
> index 0000000..144a306
> --- /dev/null
> +++ b/tests/spec/arb_texture_rectangle/CMakeLists.txt
> @@ -0,0 +1 @@
> +piglit_include_target_api()
> diff --git a/tests/spec/arb_texture_rectangle/texrect-simple.c b/tests/spec/arb_texture_rectangle/texrect-simple.c
> new file mode 100644
> index 0000000..1b6d66b
> --- /dev/null
> +++ b/tests/spec/arb_texture_rectangle/texrect-simple.c
> @@ -0,0 +1,127 @@
> +/* Copyright © 2013 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.
> + */
> +
> +/**
> + * Ported from glean ttexrect.cpp into piglit.
> + * Test the ARB_texture_rectangle extension
> + *   Create a 255x127 texture of varying colors and bind it as a
> + *   GL_ARB_texture_recangle target.  Draw that rectangle to the window, and
> + *   check that the texture was drawn correctly.  The common failure to be
> + *   caught with this test is not adjusting the non-normalized coordinates on
> + *   hardware that expects normalized coordinates.
> + * \author: Eric Anholt<eric at anholt.net>  (original)
> + * \author: Tom Gall<tom.gall at linaro.org>  (port)
> + */
> +#include "piglit-util-gl-common.h"
> +
> +#define TEXTURE_WIDTH   255
> +#define TEXTURE_HEIGHT  127
> +#define WINDOW_SIZE     256
> +
> +float image[TEXTURE_WIDTH * TEXTURE_HEIGHT * 3];
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 10;
> +	config.window_width = WINDOW_SIZE;
> +	config.window_height = WINDOW_SIZE;
> +	config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DEPTH
> +		| PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	enum piglit_result final_result = PIGLIT_PASS;
> +
> +	/* Draw our texture to the window such that each texel should map
> +	 * to the corresponding pixel of the window.
> +	 */
> +	glBegin(GL_POLYGON);
> +	glTexCoord2f(0, 0);
> +	glVertex2f(0, 0);
> +
> +	glTexCoord2f(TEXTURE_WIDTH, 0);
> +	glVertex2f(TEXTURE_WIDTH, 0);
> +
> +	glTexCoord2f(TEXTURE_WIDTH, TEXTURE_HEIGHT);
> +	glVertex2f(TEXTURE_WIDTH, TEXTURE_HEIGHT);
> +
> +	glTexCoord2f(0, TEXTURE_HEIGHT);
> +	glVertex2f(0, TEXTURE_HEIGHT);
> +	glEnd();

I think you could use piglit_draw_rect_tex() here.


> +
> +	/* returns 0 when the images don't match and 1 when they do) */
> +	final_result = !(piglit_probe_image_rgb(0, 0, TEXTURE_WIDTH, TEXTURE_HEIGHT,
> +		(const float *)&image));

final_result is a piglit_result enum, not a boolean, so doing "!" is 
questionable.

How about:

   if (!piglit_probe_image_rgb(...))
       final_result = PIGLIT_FAIL;


And maybe s/final_result/result/.


> +
> +	piglit_present_results();
> +
> +	piglit_report_result(final_result);
> +	return final_result;

You can omit the piglit_report_result() call since the return value 
from piglit_display() is enough.


> +}
> +
> +
> +void
> +piglit_init(int argc, char *argv[])
> +{
> +	int x,y,i;
> +
> +	/* Set up a texture that it's color ramps with red to black top to
> +	 * bottom and green to black left to right.
> +	 */
> +	for (y = 0; y<  TEXTURE_HEIGHT; y++) {
> +		for (x = 0; x<  TEXTURE_WIDTH; x++) {
> +			i = (y * TEXTURE_WIDTH + x) * 3;
> +
> +			image[i + 0] = (float)x / (TEXTURE_WIDTH - 1);
> +			image[i + 1] = 1.0 - ((float)  y / (TEXTURE_HEIGHT - 1));
> +			image[i + 2] = 0.0;
> +		}
> +	}
> +
> +	glClearColor(0.0, 0.0, 0.0, 0.0);

The default clear color is (0,0,0,0) so this can be removed.


> +	glClear(GL_COLOR_BUFFER_BIT);

The glClear() should be in the piglit_display() function.


> +
> +	glShadeModel(GL_FLAT);

You can remove that call.


> +
> +	glMatrixMode(GL_PROJECTION);
> +	glLoadIdentity();
> +	glOrtho(0, WINDOW_SIZE, 0, WINDOW_SIZE, -1, 1);
> +	glMatrixMode(GL_MODELVIEW);
> +	glLoadIdentity();
> +	glViewport(0, 0, WINDOW_SIZE, WINDOW_SIZE);

You can remove all the matrix/viewport lines if you put
piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);
at the top of the piglit_display() function.


> +
> +	glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGB,
> +		TEXTURE_WIDTH, TEXTURE_HEIGHT, 0, GL_RGB, GL_FLOAT, image);
> +	glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER,
> +		GL_NEAREST);
> +	glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER,
> +		GL_NEAREST);
> +	glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
> +	glEnable(GL_TEXTURE_RECTANGLE_ARB);
> +
> +	glDrawBuffer(GL_BACK);
> +	glReadBuffer(GL_BACK);

You can remove those two lines too.

> +}



More information about the Piglit mailing list