2 * Copyright © 2014 VMware, Inc.
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
25 * Test GL_EXT_packed_depth_stencil with glRead/DrawPixels
26 * Based on an original Glean test written by Brian Paul.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config
.supports_gl_compat_version
= 12;
33 config
.window_visual
= (PIGLIT_GL_VISUAL_RGBA
|
34 PIGLIT_GL_VISUAL_DEPTH
|
35 PIGLIT_GL_VISUAL_STENCIL
);
36 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
37 PIGLIT_GL_TEST_CONFIG_END
41 test_readdrawpixels(void)
43 /*reference image data */
44 static const GLuint image
[4] = {
51 GLuint stencilMap
[2] = { 2, 2 }; /* map all stencil values to 2 */
55 glDrawPixels(2, 2, GL_DEPTH_STENCIL_EXT
,
56 GL_UNSIGNED_INT_24_8_EXT
, image
);
57 if (!piglit_check_gl_error(GL_NO_ERROR
))
60 glReadPixels(0, 0, 2, 2, GL_DEPTH_STENCIL_EXT
,
61 GL_UNSIGNED_INT_24_8_EXT
, readback
);
62 if (!piglit_check_gl_error(GL_NO_ERROR
))
65 for (i
= 0; i
< 4; i
++) {
66 if (image
[i
] != readback
[i
]) {
67 printf("Image returned by glReadPixels didn't match"
68 " the expected result (0x%x != 0x%x)\n",
69 readback
[i
], image
[i
]);
74 /* test depth scale/bias and stencil mapping (in a trivial way) */
75 glPixelTransferf(GL_DEPTH_SCALE
, 0.0); /* map all depths to 1.0 */
76 glPixelTransferf(GL_DEPTH_BIAS
, 1.0);
77 glPixelMapuiv(GL_PIXEL_MAP_S_TO_S
, 2, stencilMap
);
78 glPixelTransferi(GL_MAP_STENCIL
, 1);
79 glReadPixels(0, 0, 2, 2, GL_DEPTH_STENCIL_EXT
,
80 GL_UNSIGNED_INT_24_8_EXT
, readback
);
81 if (!piglit_check_gl_error(GL_NO_ERROR
))
84 for (i
= 0; i
< 4; i
++) {
85 if (readback
[i
] != 0xffffff02) {
86 printf("Image returned by glReadPixels didn't match"
87 " the expected result (0x%x != 0xffffff02)\n",
92 glPixelTransferf(GL_DEPTH_SCALE
, 1.0);
93 glPixelTransferf(GL_DEPTH_BIAS
, 0.0);
94 glPixelTransferi(GL_MAP_STENCIL
, 0);
101 piglit_init(int argc
, char **argv
)
105 piglit_require_extension("GL_EXT_packed_depth_stencil");
107 pass
= test_readdrawpixels() && pass
;
109 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);