2 * Copyright © 2009 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24 * Eric Anholt <eric@anholt.net>
28 /** @file pbo-read-argb8888.c
30 * Tests that reading 1x1 BGRA UNSIGNED_BYTE buffers work correctly.
32 * This test should hit the blit-based readpixels in the intel driver.
35 #include "piglit-util.h"
37 int piglit_width
= 100, piglit_height
= 100;
38 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
;
41 probe(int x
, int y
, uint32_t expected
, uint32_t observed
)
43 if ((expected
& 0xffffff) != (observed
& 0xffffff)) {
44 printf("Probe at (%i,%i)\n", x
, y
);
45 printf(" Expected: 0x%08x\n", expected
);
46 printf(" Observed: 0x%08x\n", observed
);
57 GLboolean pass
= GL_TRUE
;
58 static float red
[] = {1.0, 0.0, 0.0, 0.0};
59 static float green
[] = {0.0, 1.0, 0.0, 0.0};
63 glGenBuffersARB(1, &pbo
);
64 glBindBufferARB(GL_PIXEL_PACK_BUFFER
, pbo
);
65 glBufferDataARB(GL_PIXEL_PACK_BUFFER
, 2 * 4, NULL
, GL_STREAM_DRAW_ARB
);
66 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
69 piglit_draw_rect(0, 0, piglit_width
/ 2, piglit_height
);
71 piglit_draw_rect(piglit_width
/ 2, 0, piglit_width
/ 2, piglit_height
);
73 glReadPixels(10, 10, 1, 1,
74 GL_BGRA
, GL_UNSIGNED_BYTE
, (void *)(uintptr_t)0);
75 glReadPixels(piglit_width
- 10, 10, 1, 1,
76 GL_BGRA
, GL_UNSIGNED_BYTE
, (void *)(uintptr_t)4);
80 addr
= glMapBufferARB(GL_PIXEL_PACK_BUFFER
, GL_READ_ONLY_ARB
);
82 pass
&= probe(10, 10, 0x0000ff00, addr
[0]);
83 pass
&= probe(10, 10, 0x00ff0000, addr
[1]);
85 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER
);
87 glDeleteBuffersARB(1, &pbo
);
89 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
93 static void reshape(int width
, int height
)
96 piglit_height
= height
;
98 piglit_ortho_projection(width
, height
, GL_FALSE
);
102 piglit_init(int argc
, char **argv
)
104 reshape(piglit_width
, piglit_height
);
105 piglit_require_extension("GL_ARB_pixel_buffer_object");