[Piglit] [PATCH] Add test to verify glDrawPixels with different pixel formats
Brian Paul
brianp at vmware.com
Mon Apr 2 07:32:31 PDT 2012
On 04/02/2012 01:06 AM, Anuj Phogat wrote:
>
> Signed-off-by: Anuj Phogat<anuj.phogat at gmail.com>
> ---
> tests/all.tests | 1 +
> tests/texturing/CMakeLists.gl.txt | 1 +
> tests/texturing/draw-pixels.c | 215 +++++++++++++++++++++++++++++++++++++
> 3 files changed, 217 insertions(+), 0 deletions(-)
> create mode 100644 tests/texturing/draw-pixels.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 5b3dc6b..f6e1c71 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -661,6 +661,7 @@ add_plain_test(texturing, 'depth-tex-modes-glsl')
> add_plain_test(texturing, 'depth-tex-modes-rg')
> add_plain_test(texturing, 'depth-tex-compare')
> add_plain_test(texturing, 'depth-cube-map')
> +add_plain_test(texturing, 'draw-pixels')
> add_plain_test(texturing, 'fragment-and-vertex-texturing')
> add_plain_test(texturing, 'fxt1-teximage')
> add_plain_test(texturing, 'gen-teximage')
> diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
> index 01fbe94..3c3c4b0 100644
> --- a/tests/texturing/CMakeLists.gl.txt
> +++ b/tests/texturing/CMakeLists.gl.txt
> @@ -24,6 +24,7 @@ IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
> ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
> add_executable (cubemap cubemap.c)
> add_executable (depth-level-clamp depth-level-clamp.c)
> +add_executable (draw-pixels draw-pixels.c)
> add_executable (gen-compressed-teximage gen-compressed-teximage.c)
> add_executable (gen-nonzero-unit gen-nonzero-unit.c)
> add_executable (gen-teximage gen-teximage.c)
> diff --git a/tests/texturing/draw-pixels.c b/tests/texturing/draw-pixels.c
> new file mode 100644
> index 0000000..ad628c8
> --- /dev/null
> +++ b/tests/texturing/draw-pixels.c
> @@ -0,0 +1,215 @@
> +/*
> + * Copyright 2011 VMware, Inc.
Copyright Intel?
> + *
> + * 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.
> + */
> +
> +/*
> + * file drawpixels.c
> + *
> + * Test to verify glDrawPixels() with various pixel formats
> + */
> +
> +#include "piglit-util.h"
> +#define TEX_SIZE 16
Maybe rename that to IMAGE_SIZE size you don't actually create any
textures with this size.
> +
> +int piglit_window_mode = GLUT_DOUBLE | GLUT_RGBA | GLUT_ALPHA |
> + GLUT_DEPTH | GLUT_STENCIL;
> +int piglit_width = TEX_SIZE, piglit_height = TEX_SIZE;
> +
> +static const GLfloat fcolor[15][4] = {
> + /* GL_RED */
> + {0.7, 0.0, 0.0, 1.0},
> + /* GL_GREEN */
> + {0.0, 0.7, 0.0, 1.0},
> + /* GL_BLUE */
> + {0.0, 0.0, 0.7, 1.0},
> + /* GL_ALPHA */
> + {0.0, 0.0, 0.0, 0.7},
> + /* GL_RG */
> + {0.4, 0.5, 0.0, 1.0},
> + /* GL_RGB */
> + {0.4, 0.8, 0.2, 1.0},
> + /* GL_BGR */
> + {0.2, 0.8, 0.4, 1.0},
> + /* GL_RGBA */
> + {0.5, 0.2, 0.8, 0.4},
> + /* GL_BGRA */
> + {0.8, 0.2, 0.5, 0.4},
> + /* GL_LUMINANCE */
> + {0.7, 0.7, 0.7, 1},
> + /* GL_LUMINANCE_ALPHA */
> + {0.4, 0.4, 0.4, 0.5},
> + /* GL_DEPTH_COMPONENT */
> + {0.7, 0.0, 0.0, 0.0},
> + /* GL_STENCIL_INDEX */
> + {2.0, 0.0, 0.0, 0.0},
> + {0.0, 0.0, 0.0, 1.0},
> + {1.0, 0.0, 0.0, 1.0}};
> +
> +GLfloat buf_rgba_color[TEX_SIZE][TEX_SIZE][4];
> +GLfloat buf_rgb_color[TEX_SIZE][TEX_SIZE][3];
> +GLfloat buf_rg_color[TEX_SIZE][TEX_SIZE][2];
> +GLfloat buf_color[TEX_SIZE][TEX_SIZE];
> +GLfloat buf_stencil[TEX_SIZE][TEX_SIZE];
> +
> +static const struct {
> + GLenum format;
> + GLvoid *pixels;
> + const GLfloat *expected;
> +} test_vectors[] = {
> + { GL_RED, buf_color, fcolor[0] },
> + { GL_GREEN, buf_color, fcolor[1] },
> + { GL_BLUE, buf_color, fcolor[2] },
> + { GL_ALPHA, buf_color, fcolor[3] },
> + { GL_RG, buf_rg_color, fcolor[4] },
> + { GL_RGB, buf_rgb_color, fcolor[5] },
> + { GL_BGR, buf_rgb_color, fcolor[6] },
> + { GL_RGBA, buf_rgba_color, fcolor[7] },
> + { GL_BGRA, buf_rgba_color, fcolor[8] },
> + { GL_LUMINANCE, buf_color, fcolor[9] },
> + { GL_LUMINANCE_ALPHA, buf_rg_color, fcolor[10] },
> + { GL_DEPTH_COMPONENT, buf_color, fcolor[11] },
> + { GL_STENCIL_INDEX, buf_stencil, fcolor[12] }
> +};
> +#define NUM_FORMATS (sizeof(test_vectors) / sizeof(test_vectors[0]))
You can just use the ARRAY_SIZE() macro in the code below.
> +
> +/* Initialize pixel data */
> +static void
> +pixelsInit(void)
> +{
> + int i, j;
> + for (i = 0; i< TEX_SIZE; i++) {
> + for (j = 0; j< TEX_SIZE; j++) {
> + buf_rgba_color[i][j][0] = 0.5;
> + buf_rgba_color[i][j][1] = 0.2;
> + buf_rgba_color[i][j][2] = 0.8;
> + buf_rgba_color[i][j][3] = 0.4;
> +
> + buf_rgb_color[i][j][0] = 0.4;
> + buf_rgb_color[i][j][1] = 0.8;
> + buf_rgb_color[i][j][2] = 0.2;
> +
> + buf_rg_color[i][j][0] = 0.4;
> + buf_rg_color[i][j][1] = 0.5;
> +
> + buf_color[i][j] = 0.7;
> + buf_stencil[i][j] = 2.0;
> + }
> + }
> +}
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + GLboolean pass = GL_TRUE;
> + int j;
> +
> + for (j = 0; j< NUM_FORMATS; j++) {
> +
> + glClear(GL_COLOR_BUFFER_BIT);
> + /* Draw a pixel rectangle with float color data. As per OpenGL 3.0
> + * specification integer formats are not allowed in glDrawPixels
> + */
> + pass = piglit_check_gl_error(GL_NO_ERROR)&& pass;
> +
> + switch(test_vectors[j].format) {
> + case GL_RED:
> + case GL_GREEN:
> + case GL_BLUE:
> + case GL_ALPHA:
> + case GL_LUMINANCE:
> + case GL_LUMINANCE_ALPHA:
> + case GL_RG:
> + case GL_RGB:
> + case GL_BGR:
> + case GL_RGBA:
> + case GL_BGRA:
For the RG format you should check if GL_ARB_texture_rg is supported.
> + glDrawPixels(TEX_SIZE, TEX_SIZE, test_vectors[j].format,
> + GL_FLOAT, test_vectors[j].pixels);
> +
> + pass = piglit_probe_rect_rgba(0, 0,
> + TEX_SIZE, TEX_SIZE,
> + test_vectors[j].expected)
> + && pass;
> + break;
> +
> + case GL_DEPTH_COMPONENT:
> + glEnable(GL_DEPTH_TEST);
> + glClearDepth(0.0);
> + glDepthFunc(GL_ALWAYS);
> + glClear(GL_DEPTH_BUFFER_BIT);
> + glDrawPixels(TEX_SIZE, TEX_SIZE, test_vectors[j].format,
> + GL_FLOAT, test_vectors[j].pixels);
> +
> + pass = piglit_probe_rect_depth(0, 0,
> + TEX_SIZE, TEX_SIZE,
> + test_vectors[j].expected[0])
> + && pass;
> + glDisable(GL_DEPTH_TEST);
> + break;
> +
> + case GL_STENCIL_INDEX:
> + glClearStencil(0.0);
> + glClear(GL_STENCIL_BUFFER_BIT);
> + glDrawPixels(TEX_SIZE, TEX_SIZE, test_vectors[j].format,
> + GL_FLOAT, test_vectors[j].pixels);
> + /* Probe stencil buffer */
> + pass = piglit_probe_rect_stencil(0, 0,
> + TEX_SIZE, TEX_SIZE,
> + test_vectors[j].expected[0])
> + && pass;
> +
> + glEnable(GL_STENCIL_TEST);
> + glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
> +
> + glStencilFunc(GL_EQUAL, 1, ~0);
> + glColor4f(1.0, 0.0, 0.0, 1.0);
> + piglit_draw_rect(0, 0, piglit_width, piglit_height);
> + /* Probe color buffer. Color buffer will stay
> + * unaffected by piglit_draw_rect()
> + */
> + pass = piglit_probe_rect_rgba(0, 0,
> + TEX_SIZE, TEX_SIZE,
> + test_vectors[j].expected + 4)
> + && pass;
> +
> + glStencilFunc(GL_EQUAL, 2, ~0);
> + piglit_draw_rect(0, 0, piglit_width, piglit_height);
> + pass = piglit_probe_rect_rgba(0, 0,
> + TEX_SIZE, TEX_SIZE,
> + test_vectors[j].expected + 8)
> + && pass;
> +
> + glDisable(GL_STENCIL_TEST);
> + break;
> + }
> + }
> + return (pass ? PIGLIT_PASS : PIGLIT_FAIL);
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + glClearColor(0.0, 0.0, 0.0, 1.0);
> + piglit_ortho_projection(piglit_width, piglit_height, GL_TRUE);
> + pixelsInit();
> +
> +}
Is the intention of this test to just do quick, basic glDrawPixels
testing? There are tons of format/type combinations for glDrawPixels
that, ideally, should be tested. Plus pixel transfer, etc.
-Brian
More information about the Piglit
mailing list