Add more structure constructor tests.
[piglit/hramrach.git] / tests / general / pbo-readpixels-small.c
blobfe7af2373de12436f979b1a0c48591557b0e651e
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-readpixels-small.c
30 * Tests that reading 2x2 BGRA UNSIGNED_BYTE buffers work correctly.
32 * This is the corresponding test to fbo-pbo-readpixels-small test to
33 * make sure I didn't break any of the coordinate flipping (sure
34 * enough, I did).
36 * https://bugs.freedesktop.org/show_bug.cgi?id=25921
39 #include "piglit-util.h"
41 int piglit_width = 2, piglit_height = 2;
42 int piglit_window_mode = GLUT_RGB | GLUT_DOUBLE;
44 static GLboolean
45 probe(int x, int y, uint32_t expected, uint32_t observed)
47 if ((expected & 0xffffff) != (observed & 0xffffff)) {
48 printf("Probe at (%i,%i)\n", x, y);
49 printf(" Expected: 0x%08x\n", expected);
50 printf(" Observed: 0x%08x\n", observed);
52 return GL_FALSE;
53 } else {
54 return GL_TRUE;
58 enum piglit_result
59 piglit_display(void)
61 GLboolean pass = GL_TRUE;
62 uint32_t *addr;
63 GLuint pbo;
65 glClearColor(0.0, 0.0, 0.0, 0.0);
66 glClear(GL_COLOR_BUFFER_BIT);
68 glGenBuffersARB(1, &pbo);
69 glBindBufferARB(GL_PIXEL_PACK_BUFFER, pbo);
70 glBufferDataARB(GL_PIXEL_PACK_BUFFER, 4 * 4, NULL, GL_STREAM_DRAW_ARB);
71 glPixelStorei(GL_PACK_ALIGNMENT, 1);
73 glViewport(0, 0, 2, 2);
74 piglit_ortho_projection(2, 2, GL_FALSE);
76 /* bottom: green. top: blue. */
77 glColor4f(0.0, 1.0, 0.0, 0.0);
78 piglit_draw_rect(0, 0, 2, 1);
79 glColor4f(0.0, 0.0, 1.0, 0.0);
80 piglit_draw_rect(0, 1, 2, 1);
82 /* Read the whole buffer. */
83 glReadPixels(0, 0, 2, 2,
84 GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)0);
85 addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
86 pass &= probe(0, 0, 0x0000ff00, addr[0]);
87 pass &= probe(1, 0, 0x0000ff00, addr[1]);
88 pass &= probe(0, 1, 0x000000ff, addr[2]);
89 pass &= probe(1, 1, 0x000000ff, addr[3]);
90 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
92 /* Read with an offset. */
93 glReadPixels(1, 0, 1, 1,
94 GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
95 addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
96 pass &= probe(1, 0, 0x0000ff00, addr[1]);
97 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
99 /* Read with an offset. */
100 glReadPixels(1, 1, 1, 1,
101 GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
102 addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
103 pass &= probe(1, 1, 0x000000ff, addr[1]);
104 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
106 glutSwapBuffers();
108 glDeleteBuffersARB(1, &pbo);
110 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
114 static void reshape(int width, int height)
116 piglit_width = width;
117 piglit_height = height;
119 piglit_ortho_projection(width, height, GL_FALSE);
122 void
123 piglit_init(int argc, char **argv)
125 reshape(piglit_width, piglit_height);
126 piglit_require_extension("GL_ARB_pixel_buffer_object");