fix the spelling in whole piglit
[piglit.git] / tests / general / pbo-read-argb8888.c
blobea73adac1737c8601963a03a132ab737820498a7
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-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config.supports_gl_compat_version = 10;
41 config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE;
43 PIGLIT_GL_TEST_CONFIG_END
45 static GLboolean
46 probe(int x, int y, uint8_t *expected, uint8_t *observed)
48 if (expected[0] != observed[0] ||
49 expected[1] != observed[1] ||
50 expected[2] != observed[2]) {
51 printf("Probe color at (%i,%i)\n", x, y);
52 printf(" Expected: b = 0x%02x g = 0x%02x r = 0x%02x a = 0x%02x\n",
53 expected[0], expected[1], expected[2], expected[3]);
54 printf(" Observed: b = 0x%02x g = 0x%02x r = 0x%02x a = 0x%02x\n",
55 observed[0], observed[1], observed[2], observed[3]);
57 return GL_FALSE;
58 } else {
59 return GL_TRUE;
63 enum piglit_result
64 piglit_display(void)
66 GLboolean pass = GL_TRUE;
67 static float red[] = {1.0, 0.0, 0.0, 0.0};
68 static float green[] = {0.0, 1.0, 0.0, 0.0};
69 uint8_t *addr;
70 static uint8_t exp_green[] = {0x00, 0xFF, 0x00, 0x00};
71 static uint8_t exp_red[] = {0x00, 0x00, 0xFF, 0x00};
72 GLuint pbo;
74 glGenBuffersARB(1, &pbo);
75 glBindBufferARB(GL_PIXEL_PACK_BUFFER, pbo);
76 glBufferDataARB(GL_PIXEL_PACK_BUFFER, 2 * 4, NULL, GL_STREAM_DRAW_ARB);
77 glPixelStorei(GL_PACK_ALIGNMENT, 1);
79 glColor4fv(green);
80 piglit_draw_rect(0, 0, piglit_width / 2, piglit_height);
81 glColor4fv(red);
82 piglit_draw_rect(piglit_width / 2, 0, piglit_width / 2, piglit_height);
84 glReadPixels(10, 10, 1, 1,
85 GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)0);
86 glReadPixels(piglit_width - 10, 10, 1, 1,
87 GL_BGRA, GL_UNSIGNED_BYTE, (void *)(uintptr_t)4);
89 piglit_present_results();
91 addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB);
93 pass &= probe(10, 10, exp_green, addr);
94 pass &= probe(10, 10, exp_red, addr + 4);
96 glUnmapBufferARB(GL_PIXEL_PACK_BUFFER);
98 glDeleteBuffersARB(1, &pbo);
100 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
104 static void reshape(int width, int height)
106 piglit_width = width;
107 piglit_height = height;
109 piglit_ortho_projection(width, height, GL_FALSE);
112 void
113 piglit_init(int argc, char **argv)
115 reshape(piglit_width, piglit_height);
116 piglit_require_extension("GL_ARB_pixel_buffer_object");