fix the spelling in whole piglit
[piglit.git] / tests / spec / arb_get_texture_sub_image / errors.c
bloba733d6c202a62ad8bbba9319c3763434c4454d21
1 /*
2 * Copyright 2015 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
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 * Test glGetTextureSubImage and glGetCompressedTextureSubImage error checking.
28 #include "piglit-util-gl.h"
30 PIGLIT_GL_TEST_CONFIG_BEGIN
31 config.supports_gl_compat_version = 20;
32 config.window_visual = PIGLIT_GL_VISUAL_RGBA;
33 config.khr_no_error_support = PIGLIT_HAS_ERRORS;
34 PIGLIT_GL_TEST_CONFIG_END
37 static bool
38 test_texture_id(void)
40 GLubyte buffer[8*8*4];
41 GLuint tex = 42;
42 bool pass = true;
44 /* Test get with bad texture ID */
45 glGetTextureSubImage(tex, 0,
46 0, 0, 0, /* offset */
47 8, 8, 1, /* size */
48 GL_RGBA, GL_UNSIGNED_BYTE,
49 sizeof(buffer), buffer);
50 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
51 pass = false;
53 /* Test compressed get with bad texture ID */
54 glGetCompressedTextureSubImage(tex, 0,
55 0, 0, 0, /* offset */
56 8, 8, 1, /* size */
57 sizeof(buffer), buffer);
58 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
59 pass = false;
61 /* Test get with undefined texture */
62 glGenTextures(1, &tex);
63 glGetTextureSubImage(tex, 0,
64 0, 0, 0, /* offset */
65 8, 8, 1, /* size */
66 GL_RGBA, GL_UNSIGNED_BYTE,
67 sizeof(buffer), buffer);
68 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
69 pass = false;
71 /* Test compressed get with undefined texture */
72 glGetCompressedTextureSubImage(tex, 0,
73 0, 0, 0, /* offset */
74 8, 8, 1, /* size */
75 sizeof(buffer), buffer);
76 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
77 pass = false;
79 glDeleteTextures(1, &tex);
81 return pass;
85 static bool
86 test_buffer_size(void)
88 GLubyte buffer[8*8*4];
89 GLubyte quadrant_buffer[4*4*4];
90 GLuint tex = 42;
91 bool pass = true;
93 /* setup 8x8 texture */
94 glGenTextures(1, &tex);
95 glBindTexture(GL_TEXTURE_2D, tex);
96 glTexStorage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 8, 8);
98 /* Test too small of dest buffer */
99 glGetTextureSubImage(tex, 0,
100 0, 0, 0, /* offset */
101 8, 8, 1, /* size */
102 GL_RGBA, GL_UNSIGNED_BYTE,
103 sizeof(buffer) - 1, buffer);
104 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
105 pass = false;
107 /* Test with pixel unpack params, sufficient buffer size */
108 glPixelStorei(GL_PACK_SKIP_ROWS, 4);
109 glPixelStorei(GL_PACK_SKIP_PIXELS, 4);
110 glPixelStorei(GL_PACK_ROW_LENGTH, 8);
111 glGetTextureSubImage(tex, 0,
112 4, 4, 0, /* offset */
113 4, 4, 1, /* size */
114 GL_RGBA, GL_UNSIGNED_BYTE,
115 sizeof(buffer), buffer);
116 if (!piglit_check_gl_error(GL_NO_ERROR))
117 pass = false;
119 /* Test with pixel unpack params, insufficient buffer size */
120 glGetTextureSubImage(tex, 0,
121 4, 4, 0, /* offset */
122 4, 4, 1, /* size */
123 GL_RGBA, GL_UNSIGNED_BYTE,
124 sizeof(buffer) - 1, buffer);
125 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
126 pass = false;
128 /* Test getting a quadrant, sufficient buffer size */
129 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
130 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
131 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
132 glGetTextureSubImage(tex, 0,
133 4, 4, 0, /* offset */
134 4, 4, 1, /* size */
135 GL_RGBA, GL_UNSIGNED_BYTE,
136 sizeof(quadrant_buffer), quadrant_buffer);
137 if (!piglit_check_gl_error(GL_NO_ERROR))
138 pass = false;
140 /* Test getting a quadrant, insufficient buffer size */
141 glPixelStorei(GL_PACK_SKIP_ROWS, 0);
142 glPixelStorei(GL_PACK_SKIP_PIXELS, 0);
143 glPixelStorei(GL_PACK_ROW_LENGTH, 0);
144 glGetTextureSubImage(tex, 0,
145 4, 4, 0, /* offset */
146 4, 4, 1, /* size */
147 GL_RGBA, GL_UNSIGNED_BYTE,
148 sizeof(quadrant_buffer) - 1, quadrant_buffer);
149 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
150 pass = false;
152 glDeleteTextures(1, &tex);
154 return pass;
158 static bool
159 test_invalid_values(void)
161 GLubyte buffer[8*8*4];
162 GLuint tex = 42;
163 bool pass = true;
165 /* setup 8x8 texture */
166 glGenTextures(1, &tex);
167 glBindTexture(GL_TEXTURE_2D, tex);
168 glTexStorage2D(GL_TEXTURE_2D, 4, GL_RGBA8, 8, 8);
170 /* Test bad format/type */
171 glGetTextureSubImage(tex, 0,
172 0, 0, 0, /* offset */
173 8, 8, 1, /* size */
174 GL_RGBA, GL_DEPTH_FUNC, /* bad enum */
175 sizeof(buffer), buffer);
176 if (!piglit_check_gl_error(GL_INVALID_ENUM))
177 pass = false;
179 /* Test getting invalid negative level */
180 glGetTextureSubImage(tex, -1,
181 0, 0, 0, /* offset */
182 1, 1, 1, /* size */
183 GL_RGBA, GL_UNSIGNED_BYTE,
184 sizeof(buffer), buffer);
185 if (!piglit_check_gl_error(GL_INVALID_VALUE))
186 pass = false;
188 /* Test getting invalid large level */
189 glGetTextureSubImage(tex, 99,
190 0, 0, 0, /* offset */
191 1, 1, 1, /* size */
192 GL_RGBA, GL_UNSIGNED_BYTE,
193 sizeof(buffer), buffer);
194 if (!piglit_check_gl_error(GL_INVALID_VALUE))
195 pass = false;
197 /* Test non-existent level */
198 glGetTextureSubImage(tex, 4,
199 0, 0, 0, /* offset */
200 8, 8, 1, /* size */
201 GL_RGBA, GL_FLOAT, /* bad enum */
202 sizeof(buffer), buffer);
203 if (!piglit_check_gl_error(GL_INVALID_VALUE))
204 pass = false;
206 /* Test getting invalid offset */
207 glGetTextureSubImage(tex, 0,
208 -1, 0, 0, /* offset */
209 1, 1, 1, /* size */
210 GL_RGBA, GL_UNSIGNED_BYTE,
211 sizeof(buffer), buffer);
212 if (!piglit_check_gl_error(GL_INVALID_VALUE))
213 pass = false;
215 /* Test getting invalid size */
216 glGetTextureSubImage(tex, 0,
217 0, 0, 0, /* offset */
218 -1, 1, 1, /* size */
219 GL_RGBA, GL_UNSIGNED_BYTE,
220 sizeof(buffer), buffer);
221 if (!piglit_check_gl_error(GL_INVALID_VALUE))
222 pass = false;
224 /* Test getting zero size - not an error */
225 glGetTextureSubImage(tex, 0,
226 0, 0, 0, /* offset */
227 0, 1, 1, /* size */
228 GL_RGBA, GL_UNSIGNED_BYTE,
229 sizeof(buffer), buffer);
230 if (!piglit_check_gl_error(GL_NO_ERROR))
231 pass = false;
233 glDeleteTextures(1, &tex);
235 return pass;
239 static bool
240 test_cubemap_faces(void)
242 GLubyte results[8*8*6*4];
243 GLuint tex = 42;
244 bool pass = true;
245 int face;
247 glGenTextures(1, &tex);
248 glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
250 /* create 5 cube faces, purposely omitting 6th face */
251 for (face = 0; face < 5; face++) {
252 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + face,
253 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_FLOAT, NULL);
256 /* try to query incomplete cube map, should fail */
257 glGetTextureSubImage(tex, 0,
258 0, 0, 0,
259 8, 8, 5,
260 GL_RGBA, GL_UNSIGNED_BYTE,
261 sizeof(results), results);
262 if (!piglit_check_gl_error(GL_INVALID_OPERATION))
263 pass = false;
265 /* upload final face */
266 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + 5,
267 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_FLOAT, NULL);
269 /* try to query complete cube map, should now pass */
270 glGetTextureSubImage(tex, 0,
271 0, 0, 0,
272 8, 8, 5,
273 GL_RGBA, GL_UNSIGNED_BYTE,
274 sizeof(results), results);
275 if (!piglit_check_gl_error(GL_NO_ERROR))
276 pass = false;
278 glDeleteTextures(1, &tex);
280 return pass;
284 static bool
285 test_zero_size_image(void)
287 GLubyte image[8*8*4];
288 GLuint tex;
289 bool pass = true;
291 glGenTextures(1, &tex);
292 glBindTexture(GL_TEXTURE_2D, tex);
294 glTexImage2D(GL_TEXTURE_2D,
295 0, GL_RGBA, 8, 8, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
297 /* getting 0x0 image from 8x8 source should work */
298 glGetTextureSubImage(tex, 0,
299 0, 0, 0,
300 0, 0, 1,
301 GL_RGBA, GL_UNSIGNED_BYTE,
302 sizeof(image), image);
303 if (!piglit_check_gl_error(GL_NO_ERROR))
304 pass = false;
306 /* replace image with 0x0 image (deallocates old one) */
307 glTexImage2D(GL_TEXTURE_2D,
308 0, GL_RGBA, 0, 0, 0, GL_RGBA, GL_UNSIGNED_BYTE, image);
310 /* getting 0x0 image from 0x0 source should work */
311 glGetTextureSubImage(tex, 0,
312 0, 0, 0,
313 0, 0, 1,
314 GL_RGBA, GL_UNSIGNED_BYTE,
315 sizeof(image), image);
316 if (!piglit_check_gl_error(GL_NO_ERROR))
317 pass = false;
319 /* getting 0x0 image at an offset from 0x0 source should error */
320 glGetTextureSubImage(tex, 0,
321 1, 2, 0, /* offset */
322 0, 0, 1,
323 GL_RGBA, GL_UNSIGNED_BYTE,
324 sizeof(image), image);
325 if (!piglit_check_gl_error(GL_INVALID_VALUE))
326 pass = false;
328 /* getting 2x2 image from 0x0 source should generate error */
329 glGetTextureSubImage(tex, 0,
330 0, 0, 0,
331 2, 2, 1,
332 GL_RGBA, GL_UNSIGNED_BYTE,
333 sizeof(image), image);
334 if (!piglit_check_gl_error(GL_INVALID_VALUE))
335 pass = false;
337 glDeleteTextures(1, &tex);
339 return pass;
343 void
344 piglit_init(int argc, char **argv)
346 bool pass;
348 piglit_require_extension("GL_ARB_get_texture_sub_image");
349 piglit_require_extension("GL_ARB_texture_storage");
351 pass = test_texture_id();
352 pass = test_buffer_size() && pass;
353 pass = test_invalid_values() && pass;
354 pass = test_cubemap_faces() && pass;
355 pass = test_zero_size_image() && pass;
357 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
361 enum piglit_result
362 piglit_display(void)
364 /* never called */
365 return PIGLIT_PASS;