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.h"
36 int piglit_width
= 100, piglit_height
= 100;
37 int piglit_window_mode
= GLUT_RGB
| GLUT_DOUBLE
;
42 GLboolean pass
= GL_TRUE
;
43 static float red
[] = {1.0, 0.0, 0.0, 0.0};
44 static float green
[] = {0.0, 1.0, 0.0, 0.0};
45 static float blue
[] = {0.0, 0.0, 1.0, 0.0};
49 glClearColor(0.5, 0.5, 0.5, 0.0);
50 glClear(GL_COLOR_BUFFER_BIT
);
52 glGenBuffersARB(1, &pbo
);
53 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, pbo
);
54 glBufferDataARB(GL_PIXEL_UNPACK_BUFFER
, 4 * 4 * sizeof(float),
55 NULL
, GL_STREAM_DRAW_ARB
);
56 pixels
= glMapBufferARB(GL_PIXEL_UNPACK_BUFFER
, GL_WRITE_ONLY_ARB
);
58 memcpy(pixels
+ 0, red
, sizeof(red
));
59 memcpy(pixels
+ 4, green
, sizeof(green
));
60 memcpy(pixels
+ 8, blue
, sizeof(blue
));
61 memcpy(pixels
+ 12, red
, sizeof(red
));
63 glUnmapBufferARB(GL_PIXEL_UNPACK_BUFFER
);
65 glRasterPos2i(10, 10);
66 glDrawPixels(2, 2, GL_RGBA
, GL_FLOAT
, 0);
68 glBindBufferARB(GL_PIXEL_UNPACK_BUFFER
, 0);
69 glDeleteBuffersARB(1, &pbo
);
71 pass
&= piglit_probe_pixel_rgb(10, 10, red
);
72 pass
&= piglit_probe_pixel_rgb(11, 10, green
);
73 pass
&= piglit_probe_pixel_rgb(10, 11, blue
);
74 pass
&= piglit_probe_pixel_rgb(11, 11, red
);
78 return pass
? PIGLIT_SUCCESS
: PIGLIT_FAILURE
;
82 static void reshape(int width
, int height
)
85 piglit_height
= height
;
87 piglit_ortho_projection(width
, height
, GL_FALSE
);
91 piglit_init(int argc
, char **argv
)
93 reshape(piglit_width
, piglit_height
);
94 piglit_require_extension("GL_ARB_pixel_buffer_object");