[Piglit] [PATCH] gles1: add tests for GL_OES_draw_texture

Ian Romanick idr at freedesktop.org
Tue Sep 13 08:12:26 PDT 2011


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 09/11/2011 01:21 AM, Chia-I Wu wrote:
> If there are conventions I should follow or piglitutil functions
> that I should use, please let me know.

I think the test code should live in tests/spec/oes_draw_texture.

> This should be the first GLESv1 tests.  Not sure whether it should
> be in all.tests, or where it should be in all.tests.  Suggestions
> are appreciated.

Putting it in all.tests probably won't work.  Many people won't have
the ES1 library installed, so these tests would erroneously show up as
failing.  I think the ES1 tests (and ES2 tests when we have them)
should be in their own all_es1.tests.

Other than that issue and one comment below, this looks like a good,
basic test.

> --- tests/gles1/CMakeLists.gles1.txt |    4 + 
> tests/gles1/draw-tex.c           |  237
> ++++++++++++++++++++++++++++++++++++++ 2 files changed, 241
> insertions(+), 0 deletions(-) create mode 100644
> tests/gles1/draw-tex.c
> 
> diff --git a/tests/gles1/CMakeLists.gles1.txt
> b/tests/gles1/CMakeLists.gles1.txt index e78b487..ddcbd57 100644 
> --- a/tests/gles1/CMakeLists.gles1.txt +++
> b/tests/gles1/CMakeLists.gles1.txt @@ -12,4 +12,8 @@
> link_libraries( piglitutil_gles1 )
> 
> +add_executable(draw-tex +	draw-tex.c +	) + # vim: ft=cmake: diff
> --git a/tests/gles1/draw-tex.c b/tests/gles1/draw-tex.c new file
> mode 100644 index 0000000..6c5da1a --- /dev/null +++
> b/tests/gles1/draw-tex.c @@ -0,0 +1,237 @@ +/* + * Copyright © 2011
> LunarG, 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. + * + * Author: Chia-I Wu
> <olv at lunarg.com> + */ + +/** @file draw-tex.c + * + * Test
> GL_OES_draw_texture. + */ + +#include <EGL/egl.h> + +#include
> "piglit-util.h" + +#define TEXTURE_SIZE 2 + +int piglit_width =
> 100, piglit_height = 100; +int piglit_window_mode = GLUT_RGB |
> GLUT_ALPHA | GLUT_DEPTH | GLUT_DOUBLE; + +/* see
> piglit_rgbw_texture */ +static const float red[4] =   { 1.0f, 0.0f,
> 0.0f, 0.0f }; +static const float green[4] = { 0.0f, 1.0f, 0.0f,
> 0.25f }; +static const float blue[4] =  { 0.0f, 0.0f, 1.0f, 0.50f
> }; +static const float white[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; + 
> +static PFNGLDRAWTEXIOESPROC glDrawTexiOES;

Doing this is a bad, bad, bad idea.  You shouldn't have

int (*printf)(const char *format, ...);

in a program and expect things to not explode, would you?  GLEW gets
around this by naming things glew_FunctionPtr and wrapping it with a
marco.  The piglit function pointers are usually named
piglit_Function.  I'd recommend calling this piglit_DrawTexiOES.

> + +/** + * Test the basic use of glDrawTex + */ +static int 
> +test_basic(void) +{ +	const GLint crop[4] = { +		0, 0,
> TEXTURE_SIZE, TEXTURE_SIZE +	}; +	const int x = piglit_width / 2 -
> 2; +	const int y = piglit_height / 2 - 2; +	int pass; + +
> glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); + 
> +	/* draw the RGBW texture */ +	glDrawTexiOES(0, 0, 0,
> piglit_width, piglit_height); + +	pass = piglit_probe_pixel_rgb(x,
> y,     red); +	pass = piglit_probe_pixel_rgb(x + 5, y,     green)
> && pass; +	pass = piglit_probe_pixel_rgb(x,     y + 5, blue)  &&
> pass; +	pass = piglit_probe_pixel_rgb(x + 5, y + 5, white) &&
> pass; + +	if (!pass) +		fprintf(stderr, "glDrawTexiOES()
> failed\n"); + +	return pass; +} + +/** + * Test glDrawTex with a
> crop rectangle with negative width/height. + */ +static int 
> +test_negative_crop(void) +{ +	const GLint crop[4] = { +
> TEXTURE_SIZE, TEXTURE_SIZE, -TEXTURE_SIZE, -TEXTURE_SIZE +	}; +
> const int x = piglit_width / 2 - 2; +	const int y = piglit_height /
> 2 - 2; +	int pass; + +	glTexParameteriv(GL_TEXTURE_2D,
> GL_TEXTURE_CROP_RECT_OES, crop); + +	/* draw the RGBW texture with
> negative crop */ +	glDrawTexiOES(0, 0, 0, piglit_width,
> piglit_height); + +	pass = piglit_probe_pixel_rgb(x,     y,
> white); +	pass = piglit_probe_pixel_rgb(x + 5, y,     blue)  &&
> pass; +	pass = piglit_probe_pixel_rgb(x,     y + 5, green) &&
> pass; +	pass = piglit_probe_pixel_rgb(x + 5, y + 5, red)   &&
> pass; + +	if (!pass) +		fprintf(stderr, "negative crop width/height
> failed\n"); + +	return pass; +} + +/** + * Test glDrawTex with a
> small crop rectangle covering only the right-top of + * the
> texture. + */ +static int +test_right_top_crop(void) +{ +	const
> GLint crop[4] = { +		TEXTURE_SIZE / 2, TEXTURE_SIZE / 2, +
> TEXTURE_SIZE / 2, TEXTURE_SIZE / 2 +	}; +	const int x =
> piglit_width / 2 - 2; +	const int y = piglit_height / 2 - 2; +	int
> pass; + +	glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES,
> crop); + +	/* draw the right top quarter of RGBW texture */ +
> glDrawTexiOES(0, 0, 0, piglit_width, piglit_height); + +	pass =
> piglit_probe_pixel_rgb(x,     y,     white); +	pass =
> piglit_probe_pixel_rgb(x + 5, y,     white) && pass; +	pass =
> piglit_probe_pixel_rgb(x,     y + 5, white) && pass; +	pass =
> piglit_probe_pixel_rgb(x + 5, y + 5, white) && pass; + +	if
> (!pass) +		fprintf(stderr, "sub crop rect failed\n"); + +	return
> pass; +} + +/** + * Test glDrawTex with non-zero x and y. + */ 
> +static int +test_right_top_win(void) +{ +	const GLint crop[4] = { 
> +		0, 0, TEXTURE_SIZE, TEXTURE_SIZE +	}; +	const int half_width =
> piglit_width / 2; +	const int half_height = piglit_height / 2; +
> const int x = half_width + half_width / 2 - 2; +	const int y =
> half_height + half_height / 2 - 2; +	int pass; + +
> glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_CROP_RECT_OES, crop); + 
> +	/* draw the RGBW texture at the right top */ +
> glDrawTexiOES(half_width, half_height, 0, half_width,
> half_height); + +	pass = piglit_probe_pixel_rgb(x,     y,
> red); +	pass = piglit_probe_pixel_rgb(x + 5, y,     green) &&
> pass; +	pass = piglit_probe_pixel_rgb(x,     y + 5, blue)  &&
> pass; +	pass = piglit_probe_pixel_rgb(x + 5, y + 5, white) &&
> pass; + +	if (!pass) +		fprintf(stderr, "non-zero (x, y)
> failed\n"); + +	return pass; +} + +/** + * Test glDrawTex with
> non-zero z. + */ +static int +test_depth(void) +{ +	const GLint
> crop[4] = { +		0, 0, TEXTURE_SIZE, TEXTURE_SIZE +	}; +	const int x
> = piglit_width / 2 - 2; +	const int y = piglit_height / 2 - 2; +
> int pass; + +	glTexParameteriv(GL_TEXTURE_2D,
> GL_TEXTURE_CROP_RECT_OES, crop); + +	glEnable(GL_DEPTH_TEST); + +
> /* draw at near plane */ +	glDrawTexiOES(0, 0, 0, piglit_width,
> piglit_height); +	/* draw at far plane: should be no-op */ +
> glDrawTexiOES(0, 0, 1, piglit_width / 2, piglit_height / 2); + +
> glDisable(GL_DEPTH_TEST); + +	pass = piglit_probe_pixel_rgb(x, y,
> red); + +	if (!pass) +		fprintf(stderr, "non-zero depth
> failed\n"); + +	return pass; +} + +enum piglit_result 
> +piglit_display(void) +{ +	GLboolean pass = GL_TRUE; + +
> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + +	pass =
> test_basic(); +	pass = test_negative_crop() && pass; +	pass =
> test_right_top_win() && pass; +	pass = test_right_top_crop() &&
> pass; +	pass = test_depth() && pass; + +	glFinish(); +
> glutSwapBuffers(); + +	return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} 
> + +void +piglit_init(int argc, char **argv) +{ +	GLuint tex; + +
> piglit_require_extension("GL_OES_draw_texture"); +	glDrawTexiOES =
> (PFNGLDRAWTEXIOESPROC) +		eglGetProcAddress("glDrawTexiOES"); +	if
> (!glDrawTexiOES) +		piglit_report_result(PIGLIT_FAIL); + +
> piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE); + +
> tex = piglit_rgbw_texture(GL_RGBA, +			TEXTURE_SIZE, TEXTURE_SIZE,
> GL_FALSE, GL_TRUE, 0); + +	glBindTexture(GL_TEXTURE_2D, tex); +
> glEnable(GL_TEXTURE_2D); +}
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk5vctoACgkQX1gOwKyEAw/CuQCdFYmIObrzAWjXgWE0btiT0JeD
0kAAmgLK+PN4RJ0544IifAamRX0+UIGK
=uje4
-----END PGP SIGNATURE-----


More information about the Piglit mailing list