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

Chad Versace chad.versace at linux.intel.com
Thu Aug 9 08:52:27 PDT 2012


On 08/08/2012 04:18 PM, Jordan Justen wrote:
> Signed-off-by: Jordan Justen <jordan.l.justen at intel.com>
> ---
>  examples/gl_basic.c |   20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 
> diff --git a/examples/gl_basic.c b/examples/gl_basic.c
> index 628c25d..940d651 100644
> --- a/examples/gl_basic.c
> +++ b/examples/gl_basic.c
> @@ -244,8 +244,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
> @@ -263,6 +264,23 @@ draw(struct waffle_window *window)
>  
>          glClear(GL_COLOR_BUFFER_BIT);
>          ok = waffle_window_swap_buffers(window);

After swap_buffers, the content of the back buffer is undefined. glReadPixels
will read garbage. The order should be: read then swap.

> +
> +        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)) {
> +              ok = false;

If a program abruptly quits on me, I like to know why. An error message should
be emitted here explaining the failure.

> +              break;
> +           }
> +        }
> +        free(colors);
> +
>          if (!ok)
>              return false;
>          nanosleep(&sleep_time, NULL);




More information about the waffle mailing list