[waffle] [PATCH v2] examples/gl_basic: use glReadPixels to verify correct drawing

Jordan Justen jljusten at gmail.com
Mon Aug 13 17:17:10 PDT 2012


Whoops. Sorry, it appears I did not delete this patch before using git
send-email on the gbm series.

Please disregard this email.

-Jordan

On Mon, Aug 13, 2012 at 5:11 PM, Jordan Justen
<jordan.l.justen at intel.com> wrote:
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
>  examples/gl_basic.c |   28 +++++++++++++++++++++++++++-
>  1 file changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/examples/gl_basic.c b/examples/gl_basic.c
> index 628c25d..800756a 100644
> --- a/examples/gl_basic.c
> +++ b/examples/gl_basic.c
> @@ -91,6 +91,14 @@ error_waffle(void)
>  }
>
>  static void
> +gl_basic_error(const char *str)
> +{
> +    fflush(stdout);
> +    fprintf(stderr, "gl_basic: error: %s\n", str);
> +    exit(EXIT_FAILURE);
> +}
> +
> +static void
>  error_get_gl_symbol(const char *name)
>  {
>      fflush(stdout);
> @@ -244,8 +252,9 @@ parse_args(int argc, char *argv[], struct options *opts)
>  static bool
>  draw(struct waffle_window *window)
>  {
> -    int i;
> +    int i, j;
>      bool ok;
> +    unsigned char *colors;
>
>      static const struct timespec sleep_time = {
>           // 0.5 sec
> @@ -262,6 +271,23 @@ draw(struct waffle_window *window)
>          }
>
>          glClear(GL_COLOR_BUFFER_BIT);
> +
> +        colors = calloc(WINDOW_WIDTH * WINDOW_HEIGHT * 4, sizeof(*colors));
> +        glReadPixels(0, 0,
> +                     WINDOW_WIDTH, WINDOW_HEIGHT,
> +                     GL_RGBA, GL_UNSIGNED_BYTE,
> +                     colors);
> +        for (j = 0; j < WINDOW_WIDTH * WINDOW_HEIGHT * 4; j += 4) {
> +           if ((colors[j]   != (i == 0 ? 0xff : 0)) ||
> +               (colors[j+1] != (i == 1 ? 0xff : 0)) ||
> +               (colors[j+2] != (i == 2 ? 0xff : 0)) ||
> +               (colors[j+3] != 0xff)) {
> +              free(colors);
> +              gl_basic_error("glReadPixels returned unexpected result");
> +           }
> +        }
> +        free(colors);
> +
>          ok = waffle_window_swap_buffers(window);
>          if (!ok)
>              return false;
> --
> 1.7.9.5
>
> _______________________________________________
> waffle mailing list
> waffle at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/waffle


More information about the waffle mailing list