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
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 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
40 GLubyte buffer
[8*8*4];
44 /* Test get with bad texture ID */
45 glGetTextureSubImage(tex
, 0,
48 GL_RGBA
, GL_UNSIGNED_BYTE
,
49 sizeof(buffer
), buffer
);
50 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
53 /* Test compressed get with bad texture ID */
54 glGetCompressedTextureSubImage(tex
, 0,
57 sizeof(buffer
), buffer
);
58 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
61 /* Test get with undefined texture */
62 glGenTextures(1, &tex
);
63 glGetTextureSubImage(tex
, 0,
66 GL_RGBA
, GL_UNSIGNED_BYTE
,
67 sizeof(buffer
), buffer
);
68 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
71 /* Test compressed get with undefined texture */
72 glGetCompressedTextureSubImage(tex
, 0,
75 sizeof(buffer
), buffer
);
76 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
79 glDeleteTextures(1, &tex
);
86 test_buffer_size(void)
88 GLubyte buffer
[8*8*4];
89 GLubyte quadrant_buffer
[4*4*4];
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 */
102 GL_RGBA
, GL_UNSIGNED_BYTE
,
103 sizeof(buffer
) - 1, buffer
);
104 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
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 */
114 GL_RGBA
, GL_UNSIGNED_BYTE
,
115 sizeof(buffer
), buffer
);
116 if (!piglit_check_gl_error(GL_NO_ERROR
))
119 /* Test with pixel unpack params, insufficient buffer size */
120 glGetTextureSubImage(tex
, 0,
121 4, 4, 0, /* offset */
123 GL_RGBA
, GL_UNSIGNED_BYTE
,
124 sizeof(buffer
) - 1, buffer
);
125 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
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 */
135 GL_RGBA
, GL_UNSIGNED_BYTE
,
136 sizeof(quadrant_buffer
), quadrant_buffer
);
137 if (!piglit_check_gl_error(GL_NO_ERROR
))
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 */
147 GL_RGBA
, GL_UNSIGNED_BYTE
,
148 sizeof(quadrant_buffer
) - 1, quadrant_buffer
);
149 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
152 glDeleteTextures(1, &tex
);
159 test_invalid_values(void)
161 GLubyte buffer
[8*8*4];
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 */
174 GL_RGBA
, GL_DEPTH_FUNC
, /* bad enum */
175 sizeof(buffer
), buffer
);
176 if (!piglit_check_gl_error(GL_INVALID_ENUM
))
179 /* Test getting invalid negative level */
180 glGetTextureSubImage(tex
, -1,
181 0, 0, 0, /* offset */
183 GL_RGBA
, GL_UNSIGNED_BYTE
,
184 sizeof(buffer
), buffer
);
185 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
188 /* Test getting invalid large level */
189 glGetTextureSubImage(tex
, 99,
190 0, 0, 0, /* offset */
192 GL_RGBA
, GL_UNSIGNED_BYTE
,
193 sizeof(buffer
), buffer
);
194 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
197 /* Test non-existent level */
198 glGetTextureSubImage(tex
, 4,
199 0, 0, 0, /* offset */
201 GL_RGBA
, GL_FLOAT
, /* bad enum */
202 sizeof(buffer
), buffer
);
203 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
206 /* Test getting invalid offset */
207 glGetTextureSubImage(tex
, 0,
208 -1, 0, 0, /* offset */
210 GL_RGBA
, GL_UNSIGNED_BYTE
,
211 sizeof(buffer
), buffer
);
212 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
215 /* Test getting invalid size */
216 glGetTextureSubImage(tex
, 0,
217 0, 0, 0, /* offset */
219 GL_RGBA
, GL_UNSIGNED_BYTE
,
220 sizeof(buffer
), buffer
);
221 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
224 /* Test getting zero size - not an error */
225 glGetTextureSubImage(tex
, 0,
226 0, 0, 0, /* offset */
228 GL_RGBA
, GL_UNSIGNED_BYTE
,
229 sizeof(buffer
), buffer
);
230 if (!piglit_check_gl_error(GL_NO_ERROR
))
233 glDeleteTextures(1, &tex
);
240 test_cubemap_faces(void)
242 GLubyte results
[8*8*6*4];
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,
260 GL_RGBA
, GL_UNSIGNED_BYTE
,
261 sizeof(results
), results
);
262 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
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,
273 GL_RGBA
, GL_UNSIGNED_BYTE
,
274 sizeof(results
), results
);
275 if (!piglit_check_gl_error(GL_NO_ERROR
))
278 glDeleteTextures(1, &tex
);
285 test_zero_size_image(void)
287 GLubyte image
[8*8*4];
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,
301 GL_RGBA
, GL_UNSIGNED_BYTE
,
302 sizeof(image
), image
);
303 if (!piglit_check_gl_error(GL_NO_ERROR
))
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,
314 GL_RGBA
, GL_UNSIGNED_BYTE
,
315 sizeof(image
), image
);
316 if (!piglit_check_gl_error(GL_NO_ERROR
))
319 /* getting 0x0 image at an offset from 0x0 source should error */
320 glGetTextureSubImage(tex
, 0,
321 1, 2, 0, /* offset */
323 GL_RGBA
, GL_UNSIGNED_BYTE
,
324 sizeof(image
), image
);
325 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
328 /* getting 2x2 image from 0x0 source should generate error */
329 glGetTextureSubImage(tex
, 0,
332 GL_RGBA
, GL_UNSIGNED_BYTE
,
333 sizeof(image
), image
);
334 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
337 glDeleteTextures(1, &tex
);
344 piglit_init(int argc
, char **argv
)
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
);