Add more structure constructor tests.
[piglit/hramrach.git] / tests / general / pbo-read-argb8888.c
blob4651b8862dc92e3517111264138a55d2969498aa
1 /*
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
13 * Software.
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
21 * IN THE SOFTWARE.
23 * Authors:
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;
40 static GLboolean
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);
48 return GL_FALSE;
49 } else {
50 return GL_TRUE;
54 enum piglit_result
55 piglit_display(void)
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};
60 uint32_t *addr;
61 GLuint pbo;
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);
68 glColor4fv(green);
69 piglit_draw_rect(0, 0, piglit_width / 2, piglit_height);
70 glColor4fv(red);
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);
78 glutSwapBuffers();
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)
95 piglit_width = width;
96 piglit_height = height;
98 piglit_ortho_projection(width, height, GL_FALSE);
101 void
102 piglit_init(int argc, char **argv)
104 reshape(piglit_width, piglit_height);
105 piglit_require_extension("GL_ARB_pixel_buffer_object");