cl: Don't use device_infos if num_device_infos == 0
[piglit.git] / tests / general / copy-pixels.c
bloba45d8213ec18f6870e9ea46e321f2aabf05b7f7a
1 /*
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
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.
24 /**
25 * @file copy-pixels.c
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
34 #define OFFSET 16
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
44 bool
45 test_color_copypix(int x, int y)
47 bool pass = true;
48 GLuint tex;
50 float *expected = piglit_rgbw_image(GL_RGBA,
51 IMAGE_WIDTH, IMAGE_HEIGHT,
52 GL_FALSE, /* alpha */
53 GL_UNSIGNED_NORMALIZED);
55 /* Initialize color data */
56 tex = piglit_rgbw_texture(GL_RGBA, IMAGE_WIDTH, IMAGE_HEIGHT,
57 GL_FALSE, GL_FALSE,
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);
66 glRasterPos2i(x, y);
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;
70 free(expected);
71 return pass;
74 bool
75 test_depth_copypix(int x, int y)
77 int i;
78 bool pass = true;
79 float depth_val = 0.75;
80 float *buf = malloc(IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(float));
81 assert(buf);
83 /* Initialize depth data */
84 for (i = 0; i < IMAGE_WIDTH * IMAGE_HEIGHT; i++)
85 buf[i] = depth_val;
87 glEnable(GL_DEPTH_TEST);
88 glDepthFunc(GL_ALWAYS);
90 glRasterPos2i(0, 0);
91 glDrawPixels(IMAGE_WIDTH, IMAGE_HEIGHT,
92 GL_DEPTH_COMPONENT, GL_FLOAT, buf);
93 glRasterPos2i(x, y);
94 glCopyPixels(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, GL_DEPTH);
95 free(buf);
96 pass = piglit_probe_rect_depth(x, y, IMAGE_WIDTH, IMAGE_HEIGHT,
97 depth_val);
98 return pass;
101 bool
102 test_stencil_copypix(int x, int y)
104 int i;
105 bool pass = true;
106 float stencil_val = 2.0;
107 float *buf = malloc(IMAGE_WIDTH * IMAGE_HEIGHT * sizeof(float));
108 assert(buf);
110 /* Initialize stencil data */
111 for (i = 0; i < IMAGE_WIDTH * IMAGE_HEIGHT; i++)
112 buf[i] = stencil_val;
114 glRasterPos2i(0, 0);
115 glDrawPixels(IMAGE_WIDTH, IMAGE_HEIGHT,
116 GL_STENCIL_INDEX, GL_FLOAT, buf);
117 glRasterPos2i(x, y);
118 glCopyPixels(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT, GL_STENCIL);
119 free(buf);
120 pass = piglit_probe_rect_stencil(x, y, IMAGE_WIDTH, IMAGE_HEIGHT,
121 stencil_val);
122 return pass;
125 enum piglit_result
126 piglit_display(void)
128 bool pass = true;
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)
136 && pass;
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)
144 && pass;
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)
150 && pass;
151 pass = test_stencil_copypix(0, IMAGE_HEIGHT - OFFSET) && pass;
153 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
157 void
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);
167 glClearDepth(0.0);
168 glClearStencil(0.0);
170 piglit_ortho_projection(piglit_width, piglit_height, GL_FALSE);