2 * Copyright © 2016 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
27 * Test to verify glCopyPixels with GL_COLOR, GL_DEPTH and GL_STENCIL
30 #include "piglit-util-gl.h"
32 #define IMAGE_WIDTH 60
33 #define IMAGE_HEIGHT 60
36 PIGLIT_GL_TEST_CONFIG_BEGIN
38 config
.supports_gl_compat_version
= 10;
40 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
| PIGLIT_GL_VISUAL_STENCIL
| PIGLIT_GL_VISUAL_DEPTH
;
42 PIGLIT_GL_TEST_CONFIG_END
45 test_color_copypix(int x
, int y
)
50 float *expected
= piglit_rgbw_image(GL_RGBA
,
51 IMAGE_WIDTH
, IMAGE_HEIGHT
,
53 GL_UNSIGNED_NORMALIZED
);
55 /* Initialize color data */
56 tex
= piglit_rgbw_texture(GL_RGBA
, IMAGE_WIDTH
, IMAGE_HEIGHT
,
58 GL_UNSIGNED_NORMALIZED
);
59 glBindTexture(GL_TEXTURE_2D
, tex
);
60 glEnable(GL_TEXTURE_2D
);
62 piglit_draw_rect_tex(0, 0, IMAGE_WIDTH
, IMAGE_HEIGHT
, 0, 0, 1, 1);
64 glDisable(GL_TEXTURE_2D
);
67 glCopyPixels(0, 0, IMAGE_WIDTH
, IMAGE_HEIGHT
, GL_COLOR
);
68 pass
= piglit_probe_image_color(x
, y
, IMAGE_WIDTH
, IMAGE_HEIGHT
,
69 GL_RGBA
, expected
) && pass
;
75 test_depth_copypix(int x
, int y
)
79 float depth_val
= 0.75;
80 float *buf
= malloc(IMAGE_WIDTH
* IMAGE_HEIGHT
* sizeof(float));
83 /* Initialize depth data */
84 for (i
= 0; i
< IMAGE_WIDTH
* IMAGE_HEIGHT
; i
++)
87 glEnable(GL_DEPTH_TEST
);
88 glDepthFunc(GL_ALWAYS
);
91 glDrawPixels(IMAGE_WIDTH
, IMAGE_HEIGHT
,
92 GL_DEPTH_COMPONENT
, GL_FLOAT
, buf
);
94 glCopyPixels(0, 0, IMAGE_WIDTH
, IMAGE_HEIGHT
, GL_DEPTH
);
96 pass
= piglit_probe_rect_depth(x
, y
, IMAGE_WIDTH
, IMAGE_HEIGHT
,
102 test_stencil_copypix(int x
, int y
)
106 float stencil_val
= 2.0;
107 float *buf
= malloc(IMAGE_WIDTH
* IMAGE_HEIGHT
* sizeof(float));
110 /* Initialize stencil data */
111 for (i
= 0; i
< IMAGE_WIDTH
* IMAGE_HEIGHT
; i
++)
112 buf
[i
] = stencil_val
;
115 glDrawPixels(IMAGE_WIDTH
, IMAGE_HEIGHT
,
116 GL_STENCIL_INDEX
, GL_FLOAT
, buf
);
118 glCopyPixels(0, 0, IMAGE_WIDTH
, IMAGE_HEIGHT
, GL_STENCIL
);
120 pass
= piglit_probe_rect_stencil(x
, y
, IMAGE_WIDTH
, IMAGE_HEIGHT
,
130 /* Test overlapping and non-overlapping copypixels with color, depth
131 * and stencil buffers.
133 glClear(GL_COLOR_BUFFER_BIT
);
134 pass
= test_color_copypix(IMAGE_WIDTH
, 0) && pass
;
135 pass
= test_color_copypix(IMAGE_WIDTH
+ OFFSET
, IMAGE_HEIGHT
+ OFFSET
)
137 pass
= test_color_copypix(0, IMAGE_HEIGHT
- OFFSET
) && pass
;
139 piglit_present_results();
141 glClear(GL_DEPTH_BUFFER_BIT
);
142 pass
= test_depth_copypix(IMAGE_WIDTH
, 0) && pass
;
143 pass
= test_depth_copypix(IMAGE_WIDTH
+ OFFSET
, IMAGE_HEIGHT
+ OFFSET
)
145 pass
= test_depth_copypix(0, IMAGE_HEIGHT
- OFFSET
) && pass
;
147 glClear(GL_STENCIL_BUFFER_BIT
);
148 pass
= test_stencil_copypix(IMAGE_WIDTH
, 0) && pass
;
149 pass
= test_stencil_copypix(IMAGE_WIDTH
+ OFFSET
, IMAGE_HEIGHT
+ OFFSET
)
151 pass
= test_stencil_copypix(0, IMAGE_HEIGHT
- OFFSET
) && pass
;
153 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
158 piglit_init(int argc
, char **argv
)
160 if ((piglit_get_gl_version() < 14) &&
161 !piglit_is_extension_supported("GL_ARB_window_pos")) {
162 printf("Requires GL 1.4 or GL_ARB_window_pos");
163 piglit_report_result(PIGLIT_SKIP
);
166 glClearColor(0.25, 0.25, 0.25, 1.0);
170 piglit_ortho_projection(piglit_width
, piglit_height
, GL_FALSE
);