[Piglit] [PATCH] Add functions to probe int, uint rgba buffer data
Brian Paul
brian.e.paul at gmail.com
Mon Dec 19 12:03:23 PST 2011
On Mon, Dec 19, 2011 at 12:50 PM, Anuj Phogat <anuj.phogat at gmail.com> wrote:
> Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
> ---
> tests/spec/gl-3.0/api/clearbuffer-common.c | 28 ++++++++++++
> tests/spec/gl-3.0/api/clearbuffer-common.h | 4 ++
> tests/util/piglit-util-gl.c | 64 ++++++++++++++++++++++++++++
> tests/util/piglit-util.h | 2 +
> 4 files changed, 98 insertions(+), 0 deletions(-)
>
> diff --git a/tests/spec/gl-3.0/api/clearbuffer-common.c b/tests/spec/gl-3.0/api/clearbuffer-common.c
> index 0c1fc06..ad983ce 100644
> --- a/tests/spec/gl-3.0/api/clearbuffer-common.c
> +++ b/tests/spec/gl-3.0/api/clearbuffer-common.c
> @@ -173,6 +173,34 @@ simple_probe(bool color, const float *color_value,
> return pass;
> }
>
> +/* Read pixel color values from multiple format color buffers */
The comment should say more about the format/type parameters.
> +bool
> +probe_rect_color(int x, int y, int w, int h,
> + GLenum format, GLenum type,
Is 'format' actually used?
> + GLvoid *refcolor)
const-qualify?
> +{
> + if (type == GL_FLOAT) {
> + if (!piglit_probe_rect_rgba(0, 0,
> + piglit_width, piglit_height,
> + (GLfloat*)refcolor))
> + return false;
> + }
> + else if (type == GL_UNSIGNED_INT) {
> + if (!piglit_probe_rect_rgba_uint(0, 0,
> + piglit_width, piglit_height,
> + (GLuint*)refcolor))
> + return false;
> + }
> + else if (type == GL_INT) {
> + if (!piglit_probe_rect_rgba_int(0, 0,
> + piglit_width, piglit_height,
> + (GLint*)refcolor))
> + return false;
> +
> + }
Maybe assert if type is anything else?
> + return true;
> +}
> +
> enum piglit_result
> piglit_display(void)
> {
> diff --git a/tests/spec/gl-3.0/api/clearbuffer-common.h b/tests/spec/gl-3.0/api/clearbuffer-common.h
> index e5afc51..1cfd972 100644
> --- a/tests/spec/gl-3.0/api/clearbuffer-common.h
> +++ b/tests/spec/gl-3.0/api/clearbuffer-common.h
> @@ -31,3 +31,7 @@ extern bool
> simple_probe(bool color, const float *color_value,
> bool stencil, int stencil_value,
> bool depth, float depth_value);
> +
> +extern bool
> +probe_rect_color(int x, int y, int width, int height,
> + GLenum format, GLenum type, GLvoid *refcolor);
> diff --git a/tests/util/piglit-util-gl.c b/tests/util/piglit-util-gl.c
> index 2a88ef5..f066500 100644
> --- a/tests/util/piglit-util-gl.c
> +++ b/tests/util/piglit-util-gl.c
> @@ -142,6 +142,70 @@ piglit_probe_rect_rgba(int x, int y, int w, int h, const float *expected)
> }
>
> int
> +piglit_probe_rect_rgba_int(int x, int y, int w, int h, const int *expected)
> +{
> + int i, j, p;
> + GLint *probe;
> + GLint *pixels = malloc(w*h*4*sizeof(int));
> +
> + glReadPixels(x, y, w, h, GL_RGBA_INTEGER, GL_INT, pixels);
> +
> + for (j = 0; j < h; j++) {
> + for (i = 0; i < w; i++) {
> + probe = &pixels[(j*w+i)*4];
> +
> + for (p = 0; p < 4; ++p) {
> + if (fabs(probe[p] - expected[p]) >= piglit_tolerance[p]) {
> + printf("Probe at (%d,%d)\n", x+i, y+j);
> + printf(" Expected: %d %d %d %d\n",
> + expected[0], expected[1], expected[2], expected[3]);
> + printf(" Observed: %d %d %d %d\n",
> + probe[0], probe[1], probe[2], probe[3]);
> +
> + free(pixels);
> + return 0;
> + }
> + }
> + }
> + }
> +
> + free(pixels);
> + return 1;
> +}
> +
> +int
> +piglit_probe_rect_rgba_uint(int x, int y, int w, int h, const unsigned int *expected)
> +{
> + int i, j, p;
> + GLuint *probe;
> + GLuint *pixels = malloc(w*h*4*sizeof(unsigned int));
> +
> + glReadPixels(x, y, w, h, GL_RGBA_INTEGER, GL_UNSIGNED_INT, pixels);
> +
> + for (j = 0; j < h; j++) {
> + for (i = 0; i < w; i++) {
> + probe = &pixels[(j*w+i)*4];
> +
> + for (p = 0; p < 4; ++p) {
> + if (fabs(probe[p] - expected[p]) >= piglit_tolerance[p]) {
> + printf("Probe at (%d,%d)\n", x+i, y+j);
> + printf(" Expected: %d %d %d %d\n",
> + expected[0], expected[1], expected[2], expected[3]);
> + printf(" Observed: %d %d %d %d\n",
> + probe[0], probe[1], probe[2], probe[3]);
We should use %u format for unsigned values.
> +
> + free(pixels);
> + return 0;
> + }
> + }
> + }
> + }
> +
> + free(pixels);
> + return 1;
> +}
> +
> +int
> piglit_probe_image_rgb(int x, int y, int w, int h, const float *image)
> {
> int i, j, p;
> diff --git a/tests/util/piglit-util.h b/tests/util/piglit-util.h
> index 15eb42a..964b0f8 100755
> --- a/tests/util/piglit-util.h
> +++ b/tests/util/piglit-util.h
> @@ -193,6 +193,8 @@ int piglit_probe_pixel_rgb(int x, int y, const float* expected);
> int piglit_probe_pixel_rgba(int x, int y, const float* expected);
> int piglit_probe_rect_rgb(int x, int y, int w, int h, const float* expected);
> int piglit_probe_rect_rgba(int x, int y, int w, int h, const float* expected);
> +int piglit_probe_rect_rgba_int(int x, int y, int w, int h, const int* expected);
> +int piglit_probe_rect_rgba_uint(int x, int y, int w, int h, const unsigned int* expected);
> int piglit_probe_image_rgb(int x, int y, int w, int h, const float *image);
> int piglit_probe_image_rgba(int x, int y, int w, int h, const float *image);
> int piglit_probe_texel_rect_rgb(int target, int level, int x, int y,
> --
> 1.7.7.4
>
> _______________________________________________
> Piglit mailing list
> Piglit at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/piglit
More information about the Piglit
mailing list