2 * Copyright © 2013 LunarG, 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
23 * Author: Jon Ashburn <jon@lunarg.com>
27 * Tests GL_ARB_texture_view and validity of input parameters.
28 * Use both valid and invalid parameters, although mostly invalid
29 * parameters are tested since other tests use valid parameters.
30 * Only the parameters "texture", "origtexture", "minlevel", "numlevels",
31 * "minlayer", "numlayers" are tested for validity as per section 8.18 of
32 * OpenGL 4.3 Core spec.
33 * Tests formats.c and targets.c test the valid and invalid "format" and
34 * "target" input parameters respectively.
38 #include "piglit-util-gl.h"
40 PIGLIT_GL_TEST_CONFIG_BEGIN
42 config
.supports_gl_compat_version
= 15;
43 config
.supports_gl_core_version
= 31;
45 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
46 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
48 PIGLIT_GL_TEST_CONFIG_END
50 static const char *TestName
= "arb_texture_view-params";
53 * Test TextureView with various invalid arguments for "texture"
55 * Errors as per OpenGL core 4.3 spec section 8.18:
56 * "An INVALID_VALUE error is generated if origtexture is not the
58 * "An INVALID_OPERATION error is generated if the value of
59 * TEXTURE_IMMUTABLE_FORMAT for origtexture is not TRUE."
60 * "An INVALID_VALUE error is generated if texture is zero."
61 * "An INVALID_OPERATION error is generated if texture is not a valid name
62 * returned by GenTextures, or if texture has already been bound and
66 invalid_texture_param(void)
71 /* invalid original texture param (origtexture) */
72 glGenTextures(2, tex
);
73 glBindTexture(GL_TEXTURE_2D
, tex
[0]);
74 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
75 printf("%s Found gl errors prior to testing glTextureView\n",
80 /* origtexture IMMUTABLE_FORMAT == FALSE */
81 glTextureView(tex
[1], GL_TEXTURE_2D
, tex
[0], GL_R8
, 0, 1, 0, 1);
82 pass
= piglit_check_gl_error(GL_INVALID_OPERATION
) && pass
;
83 glDeleteTextures(1, &tex
[1]);
84 glTexStorage2D(GL_TEXTURE_2D
,2, GL_RGBA32F
, 16, 16);
85 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
87 glGenTextures(1, &tex
[1]);
88 /* origtexture is not the name of a texture */
89 glTextureView(tex
[1], GL_TEXTURE_2D
, 0, GL_RGBA32UI
, 0, 1, 0, 1);
90 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
91 glDeleteTextures(1, &tex
[1]);
93 /* invalid texture param (value is 0)*/
94 glTextureView(0, GL_TEXTURE_2D
, tex
[0], GL_RGBA32I
, 0, 1, 0 ,1);
95 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
97 glGenTextures(1, &tex
[1]);
98 glBindTexture(GL_TEXTURE_2D
, tex
[1]);
99 glTextureView(tex
[1], GL_TEXTURE_2D
, tex
[0], GL_RGBA32F
, 0, 1, 0, 1);
100 pass
= piglit_check_gl_error(GL_INVALID_OPERATION
) && pass
;
101 glDeleteTextures(2, tex
);
103 /* invalid texture param (value not a valid name from GenTextures)*/
104 glGenTextures(1, tex
);
105 glBindTexture(GL_TEXTURE_2D
, tex
[0]);
106 glTexStorage2D(GL_TEXTURE_2D
, 3, GL_RG16F
, 16, 16);
107 glTextureView(~tex
[0], GL_TEXTURE_2D
, tex
[0], GL_RGBA8
, 0,1,0,1);
108 pass
= piglit_check_gl_error(GL_INVALID_OPERATION
) && pass
;
109 glDeleteTextures(1, tex
);
111 /* orig texture not immutable */
112 glGenTextures(2, tex
);
113 glBindTexture(GL_TEXTURE_2D
, tex
[0]);
114 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB16
, 32, 32, 0, GL_RGB
,
116 glTexImage2D(GL_TEXTURE_2D
, 1, GL_RGB16
, 16, 16, 0, GL_RGB
,
118 glTextureView(tex
[1], GL_TEXTURE_2D
, tex
[0], GL_RGBA32F
, 0,1,0,1);
119 pass
= piglit_check_gl_error(GL_INVALID_OPERATION
) && pass
;
122 glDeleteTextures(2, tex
);
127 * Test TextureView with invalid arguments for "minlayer"
129 * Errors as per OpenGL core 4.3 spec section 8.18:
130 * "An INVALID_VALUE error is generated if minlevel or minlayer are larger
131 * than the greatest level or layer, respectively, of origtexture."
132 * "An INVALID_VALUE error is generated if target is TEXTURE_1D,
133 * TEXTURE_2D, TEXTURE_3D, TEXTURE_RECTANGLE, or TEXTURE_2D_-
134 * MULTISAMPLE and numlayers does not equal 1."
137 invalid_layer_param(GLenum target
)
143 /* invalid minlayer param */
144 glGenTextures(2, tex
);
145 glBindTexture(target
, tex
[0]);
146 if (target
== GL_TEXTURE_1D_ARRAY
) {
148 glTexStorage2D(target
, 7, GL_RGB16I
, 64, 4);
149 } else if (target
== GL_TEXTURE_2D_ARRAY
) {
151 glTexStorage3D(target
, 7, GL_RGB16F
, 64, 64, 4);
153 printf("%s: called with invalid target\n", TestName
);
156 glTextureView(tex
[1], target
, tex
[0], GL_RGB16UI
, 0, 7, 4, 2);
157 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
158 glDeleteTextures(1, &tex
[1]);
160 /* invalid numlayer param */
161 glGenTextures(1, &tex
[1]);
162 glTextureView(tex
[1], tar
, tex
[0], GL_RGB16I
, 1, 5, 0, 4);
163 pass
= piglit_check_gl_error(GL_INVALID_VALUE
) && pass
;
165 glDeleteTextures(2, tex
);
170 * Test TextureView with invalid argument for "minlevel"
171 * Errors as per OpenGL core 4.3 spec section 8.18:
172 * "An INVALID_VALUE error is generated if minlevel or minlayer are larger
173 * than the greatest level or layer, respectively, of origtexture."
176 invalid_level_param(void)
181 /* invalid minlevel param */
182 glGenTextures(2, tex
);
183 glBindTexture(GL_TEXTURE_1D
, tex
[0]);
184 glTexStorage1D(GL_TEXTURE_1D
, 6, GL_RGB16F
, 32);
185 glTextureView(tex
[1], GL_TEXTURE_1D
, tex
[0], GL_RGB16UI
, 7, 5, 1, 1);
186 if (!piglit_check_gl_error(GL_INVALID_VALUE
)) {
189 glDeleteTextures(2, tex
);
194 * Test TextureView with "minlevel" range over legal values and
195 * with "numlevels" clamped correctly.
196 * As per OpenGL 4.3 Core spec section 8.18:
197 * "TEXTURE_VIEW_MIN_LEVEL is set to minlevel plus the value of
198 * TEXTURE_VIEW_MIN_LEVEL for origtexture."
200 * "The minlevel and minlayer parameters are relative to the view
201 * of origtexture. If numlayers or numlevels extend beyond origtexture,
202 * they are clamped to the maximum extent of the original texture."
205 levels_clamping(void)
210 const GLuint numLevels
= 8;
212 glGenTextures(1, tex
);
213 glBindTexture(GL_TEXTURE_1D
, tex
[0]);
214 glTexStorage1D(GL_TEXTURE_1D
, numLevels
-1, GL_RG16
, 64);
215 for (i
= 0; i
< numLevels
- 1; i
++) {
216 glGenTextures(1, &tex
[1]);
217 glTextureView(tex
[1], GL_TEXTURE_1D_ARRAY
, tex
[0], GL_RG16I
,
218 i
, numLevels
-i
, 0, 3);
219 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
223 glBindTexture(GL_TEXTURE_1D_ARRAY
, tex
[1]);
224 glGetTexParameteriv(GL_TEXTURE_1D_ARRAY
,
225 GL_TEXTURE_VIEW_MIN_LEVEL
, &level
);
227 printf("failed at min_level=%d, queried view_min_level=%d\n",
232 glGetTexParameteriv(GL_TEXTURE_1D_ARRAY
,
233 GL_TEXTURE_VIEW_NUM_LEVELS
, &level
);
234 if (level
!= (numLevels
- 1 -i
)) {
235 printf("failed at min_level=%d, queried view_num_level=%d\n",
240 glDeleteTextures(1, &tex
[1]);
241 glBindTexture(GL_TEXTURE_1D
, tex
[0]);
244 glDeleteTextures(2, tex
);
249 * Test TextureView with "minlayer" range over legal values and
250 * with "numlayers" clamped correctly.
251 * As per OpenGL 4.3 Core spec section 8.18:
252 * "TEXTURE_VIEW_MIN_LAYER is set to minlayer plus the value of
253 * TEXTURE_VIEW_MIN_LAYER for origtexture."
255 * "The minlevel and minlayer parameters are relative to the view
256 * of origtexture. If numlayers or numlevels extend beyond origtexture,
257 * they are clamped to the maximum extent of the original texture."
260 layers_clamping(void)
266 glGenTextures(1, tex
);
267 glBindTexture(GL_TEXTURE_1D_ARRAY
, tex
[0]);
268 glTexStorage2D(GL_TEXTURE_1D_ARRAY
, 5, GL_RGBA16F
, 16, 4);
269 for (i
= 0; i
< 4; i
++) {
270 glGenTextures(1, &tex
[1]);
271 glTextureView(tex
[1], GL_TEXTURE_1D_ARRAY
, tex
[0], GL_RGBA16I
,
273 if (!piglit_check_gl_error(GL_NO_ERROR
)) {
277 glBindTexture(GL_TEXTURE_1D_ARRAY
, tex
[1]);
278 glGetTexParameteriv(GL_TEXTURE_1D_ARRAY
,
279 GL_TEXTURE_VIEW_MIN_LAYER
, &layer
);
281 printf("failed at min_layer=%d, queried view_min_layer=%d\n",
286 glGetTexParameteriv(GL_TEXTURE_1D_ARRAY
,
287 GL_TEXTURE_VIEW_NUM_LAYERS
, &layer
);
288 if (layer
!= (4-i
)) {
289 printf("failed at min_layer=%d, queried view_num_layer=%d\n",
294 glDeleteTextures(1, &tex
[1]);
295 glBindTexture(GL_TEXTURE_1D_ARRAY
, tex
[0]);
298 glDeleteTextures(2, tex
);
311 const bool subtest_pass = (f); \
312 piglit_report_subtest_result(subtest_pass \
313 ? PIGLIT_PASS : PIGLIT_FAIL, \
315 pass = pass && subtest_pass; \
320 piglit_init(int argc
, char **argv
)
324 piglit_require_extension("GL_ARB_texture_storage");
325 piglit_require_extension("GL_ARB_texture_view");
326 piglit_require_extension("GL_EXT_texture_integer");
327 piglit_require_extension("GL_ARB_texture_float");
328 piglit_require_extension("GL_EXT_texture_array");
330 if (!piglit_khr_no_error
) {
331 X(invalid_texture_param(), "Invalid texture or origtexture");
332 X(invalid_layer_param(GL_TEXTURE_1D_ARRAY
), "Invalid layer param 1D");
333 X(invalid_layer_param(GL_TEXTURE_2D_ARRAY
), "Invalid layer param 2D");
334 X(invalid_level_param(), "Invalid level param");
336 X(levels_clamping(), "Minlevel range and numlevel clamp");
337 X(layers_clamping(), "Minlayer range and numlayer clamp");
340 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
341 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);