fbo-mrt-alphatest: Actually require MRTs to be available.
[piglit.git] / tests / general / pbo-readpixels-small.c
blob245d22683e6deac580b7e8355f53db02b87878d7
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-gl.h"
41 PIGLIT_GL_TEST_CONFIG_BEGIN
43 config.supports_gl_compat_version = 10;
44 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
46 PIGLIT_GL_TEST_CONFIG_END
48 static GLboolean
49 probe(int x, int y, uint8_t *expected, uint8_t *observed)
51 if (expected[0] != observed[0] ||
52 expected[1] != observed[1] ||
53 expected[2] != observed[2]) {
54 printf("Probe color at (%i,%i)\n", x, y);
55 printf(" Expected: b = 0x%02x g = 0x%02x r = 0x%02x a = 0x%02x\n",
56 expected[0], expected[1], expected[2], expected[3]);
57 printf(" Observed: b = 0x%02x g = 0x%02x r = 0x%02x a = 0x%02x\n",
58 observed[0], observed[1], observed[2], observed[3]);
60 return GL_FALSE;
61 } else {
62 return GL_TRUE;
66 enum piglit_result
67 piglit_display(void)
69 GLboolean pass = GL_TRUE;
70 uint8_t *addr;
71 GLuint pbo;
72 static uint8_t green[] = {0x00, 0xFF, 0x00, 0x00};
73 static uint8_t blue[] = {0xFF, 0x00, 0x00, 0x00};
75 glClearColor(0.0, 0.0, 0.0, 0.0);
76 glClear(GL_COLOR_BUFFER_BIT);
78 glGenBuffersARB(1, &pbo);
79 glBindBufferARB(GL_PIXEL_PACK_BUFFER, pbo);
80 glBufferDataARB(GL_PIXEL_PACK_BUFFER, 4 * 4, NULL, GL_STREAM_DRAW_ARB);
81 glPixelStorei(GL_PACK_ALIGNMENT, 1);
83 glViewport(0, 0, 2, 2);
84 piglit_ortho_projection(2, 2, GL_FALSE);
86 /* bottom: green. top: blue. */
87 glColor4f(0.0, 1.0, 0.0, 0.0);
88 piglit_draw_rect(0, 0, 2, 1);
89 glColor4f(0.0, 0.0, 1.0, 0.0);
90 piglit_draw_rect(0, 1, 2, 1);
92 /* Read the whole buffer. */
93 glReadPixels(0, 0, 2, 2,
94 GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)0);
95 addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
97 pass &= probe(0, 0, green, addr);
98 pass &= probe(1, 0, green, addr + 4);
99 pass &= probe(0, 1, blue, addr + 8);
100 pass &= probe(1, 1, blue, addr + 12);
101 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
103 /* Read with an offset. */
104 glReadPixels(1, 0, 1, 1,
105 GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
106 addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
107 pass &= probe(1, 0, green, addr + 4);
108 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
110 /* Read with an offset. */
111 glReadPixels(1, 1, 1, 1,
112 GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
113 addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
114 pass &= probe(1, 1, blue, addr + 4);
115 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
117 piglit_present_results();
119 glDeleteBuffersARB(1, &pbo);
121 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
125 static void reshape(int width, int height)
127 piglit_width = width;
128 piglit_height = height;
130 piglit_ortho_projection(width, height, GL_FALSE);
133 void
134 piglit_init(int argc, char **argv)
136 reshape(piglit_width, piglit_height);
137 piglit_require_extension("GL_ARB_pixel_buffer_object");