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-drawpixels.c
30 * Tests that using a PBO as the unpack buffer for glDrawPixels works correctly.
31 * Caught a bug with the Intel driver with the metaops drawpixels code.
34 #include "piglit-util-gl.h"
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 10;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
42 PIGLIT_GL_TEST_CONFIG_END
47 GLboolean pass
= GL_TRUE
;
48 static float red
[] = {1.0, 0.0, 0.0, 0.0};
49 static float green
[] = {0.0, 1.0, 0.0, 0.0};
50 static float blue
[] = {0.0, 0.0, 1.0, 0.0};
54 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);
56 glClearColor(0.5, 0.5, 0.5, 0.0);
57 glClear(GL_COLOR_BUFFER_BIT
);
59 glGenBuffersARB(1, &pbo
);
60 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, pbo
);
61 glBufferDataARB(GL_PIXEL_UNPACK_BUFFER
, 4 * 4 * sizeof(float),
62 NULL
, GL_STREAM_DRAW_ARB
);
63 pixels
= glMapBufferARB(GL_PIXEL_UNPACK_BUFFER
, GL_WRITE_ONLY_ARB
);
65 memcpy(pixels
+ 0, red
, sizeof(red
));
66 memcpy(pixels
+ 4, green
, sizeof(green
));
67 memcpy(pixels
+ 8, blue
, sizeof(blue
));
68 memcpy(pixels
+ 12, red
, sizeof(red
));
70 glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER
);
72 glRasterPos2i(10, 10);
73 glDrawPixels(2, 2, GL_RGBA
, GL_FLOAT
, 0);
75 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, 0);
76 glDeleteBuffersARB(1, &pbo
);
78 pass
&= piglit_probe_pixel_rgb(10, 10, red
);
79 pass
&= piglit_probe_pixel_rgb(11, 10, green
);
80 pass
&= piglit_probe_pixel_rgb(10, 11, blue
);
81 pass
&= piglit_probe_pixel_rgb(11, 11, red
);
83 piglit_present_results();
85 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
90 piglit_init(int argc
, char **argv
)
92 piglit_require_extension("GL_ARB_pixel_buffer_object");