diff options
author | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2016-10-10 11:08:53 +0200 |
---|---|---|
committer | Nicolai Hähnle <nicolai.haehnle@amd.com> | 2016-10-18 11:03:11 +0200 |
commit | 2c9096bc4e2e31254080433f6125a56fdea2a08c (patch) | |
tree | 43da7e874acd7a674aa12d5d775ab6cf7c0c86f1 /tests/util | |
parent | 54cf899720542e527f4263f28e9bcd83a5bf235c (diff) |
piglit-util-gl: add piglit_quads_texture
Like checkerboard, but allows specifying different colors for each quadrant
of a 2x2 tile block; basically a superset of the checkerboard and rgbw texture
functions.
Diffstat (limited to 'tests/util')
-rw-r--r-- | tests/util/piglit-util-gl.c | 101 | ||||
-rw-r--r-- | tests/util/piglit-util-gl.h | 7 |
2 files changed, 86 insertions, 22 deletions
diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c index 95eadd0a7..d94a40fb2 100644 --- a/tests/util/piglit-util-gl.c +++ b/tests/util/piglit-util-gl.c @@ -2240,7 +2240,8 @@ piglit_draw_triangle_z(float z, float x1, float y1, float x2, float y2, } /** - * Generate a checkerboard texture + * Generate an extended checkerboard texture where the color of each quadrant + * in a 2x2 block of tiles can be specified individually. * * \param tex Name of the texture to be used. If \c tex is * zero, a new texture name will be generated. @@ -2249,12 +2250,12 @@ piglit_draw_triangle_z(float z, float x1, float y1, float x2, float y2, * \param height Height of the texture image * \param horiz_square_size Size of each checkerboard tile along the X axis * \param vert_square_size Size of each checkerboard tile along the Y axis - * \param black RGBA color to be used for "black" tiles - * \param white RGBA color to be used for "white" tiles + * \param bl RGBA color to be used for "bottom-left" tiles + * \param br RGBA color to be used for "bottom-right" tiles + * \param tl RGBA color to be used for "top-left" tiles + * \param tr RGBA color to be used for "top-right" tiles * - * A texture with alternating black and white squares in a checkerboard - * pattern is generated. The texture data is written to LOD \c level of - * the texture \c tex. + * The texture data is written to LOD \c level of the texture \c tex. * * If \c tex is zero, a new texture created. This texture will have several * texture parameters set to non-default values: @@ -2271,11 +2272,12 @@ piglit_draw_triangle_z(float z, float x1, float y1, float x2, float y2, * \c GL_TEXTURE_2D target of the currently active texture unit. */ GLuint -piglit_checkerboard_texture(GLuint tex, unsigned level, - unsigned width, unsigned height, - unsigned horiz_square_size, - unsigned vert_square_size, - const float *black, const float *white) +piglit_quads_texture(GLuint tex, unsigned level, + unsigned width, unsigned height, + unsigned horiz_square_size, + unsigned vert_square_size, + const float *bl, const float *br, + const float *tl, const float *tr) { static const GLfloat border_color[4] = { 1.0, 0.0, 0.0, 1.0 }; unsigned i; @@ -2283,21 +2285,27 @@ piglit_checkerboard_texture(GLuint tex, unsigned level, void *tex_data; char *texel; unsigned pixel_size; - GLubyte black_b[4], white_b[4]; - const void *black_data, *white_data; + GLubyte bl_b[4], br_b[4], tl_b[4], tr_b[4]; + const void *bl_data, *br_data, *tl_data, *tr_data; if (piglit_is_gles()) { pixel_size = 4 * sizeof(GLubyte); for (i = 0; i < 4; i++) { - black_b[i] = black[i] * 255; - white_b[i] = white[i] * 255; + bl_b[i] = bl[i] * 255; + br_b[i] = br[i] * 255; + tl_b[i] = tl[i] * 255; + tr_b[i] = tr[i] * 255; } - black_data = black_b; - white_data = white_b; + bl_data = bl_b; + br_data = br_b; + tl_data = tl_b; + tr_data = tr_b; } else { pixel_size = 4 * sizeof(float); - black_data = black; - white_data = white; + bl_data = bl; + br_data = br; + tl_data = tl; + tr_data = tr; } texel = tex_data = malloc(width * height * pixel_size); @@ -2307,10 +2315,16 @@ piglit_checkerboard_texture(GLuint tex, unsigned level, for (j = 0; j < width; j++) { const unsigned col = j / horiz_square_size; - if ((row ^ col) & 1) { - memcpy(texel, white_data, pixel_size); + if (row & 1) { + if (col & 1) + memcpy(texel, tr_data, pixel_size); + else + memcpy(texel, tl_data, pixel_size); } else { - memcpy(texel, black_data, pixel_size); + if (col & 1) + memcpy(texel, br_data, pixel_size); + else + memcpy(texel, bl_data, pixel_size); } texel += pixel_size; @@ -2350,6 +2364,49 @@ piglit_checkerboard_texture(GLuint tex, unsigned level, } /** + * Generate a checkerboard texture + * + * \param tex Name of the texture to be used. If \c tex is + * zero, a new texture name will be generated. + * \param level Mipmap level the checkerboard should be written to + * \param width Width of the texture image + * \param height Height of the texture image + * \param horiz_square_size Size of each checkerboard tile along the X axis + * \param vert_square_size Size of each checkerboard tile along the Y axis + * \param black RGBA color to be used for "black" tiles + * \param white RGBA color to be used for "white" tiles + * + * A texture with alternating black and white squares in a checkerboard + * pattern is generated. The texture data is written to LOD \c level of + * the texture \c tex. + * + * If \c tex is zero, a new texture created. This texture will have several + * texture parameters set to non-default values: + * + * - Min and mag filter will be set to \c GL_NEAREST. + * - For GL: + * - S and T wrap modes will be set to \c GL_CLAMP_TO_BORDER. + * - Border color will be set to { 1.0, 0.0, 0.0, 1.0 }. + * - For GLES: + * - S and T wrap modes will be set to \c GL_CLAMP_TO_EDGE. + * + * \return + * Name of the texture. In addition, this texture will be bound to the + * \c GL_TEXTURE_2D target of the currently active texture unit. + */ +GLuint +piglit_checkerboard_texture(GLuint tex, unsigned level, + unsigned width, unsigned height, + unsigned horiz_square_size, + unsigned vert_square_size, + const float *black, const float *white) +{ + return piglit_quads_texture(tex, level, width, height, + horiz_square_size, vert_square_size, + black, white, white, black); +} + +/** * Generates a 8x8 mipmapped texture whose layers contain solid r, g, b, and w. */ GLuint diff --git a/tests/util/piglit-util-gl.h b/tests/util/piglit-util-gl.h index 78390c13c..4fc6c5750 100644 --- a/tests/util/piglit-util-gl.h +++ b/tests/util/piglit-util-gl.h @@ -284,6 +284,13 @@ void piglit_gen_ortho_uniform(GLint location, double left, double right, double far_val); void piglit_ortho_uniform(GLint location, int w, int h); +GLuint +piglit_quads_texture(GLuint tex, unsigned level, + unsigned width, unsigned height, + unsigned horiz_square_size, + unsigned vert_square_size, + const float *bl, const float *br, + const float *tl, const float *tr); GLuint piglit_checkerboard_texture(GLuint tex, unsigned level, unsigned width, unsigned height, unsigned horiz_square_size, unsigned vert_square_size, |