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 queries of new state added by this extension
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config
.supports_gl_compat_version
= 15;
36 config
.supports_gl_core_version
= 31;
37 config
.supports_gl_es_version
= 31;
39 config
.window_visual
= PIGLIT_GL_VISUAL_RGBA
| PIGLIT_GL_VISUAL_DOUBLE
;
40 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
42 PIGLIT_GL_TEST_CONFIG_END
45 * make sure default intial state is correct for textureView
46 * In OpenGL Core 4.3 spec see table 23.15 for default values.
49 query_default_state(void)
56 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
[0]);
57 glTexStorage2D(GL_TEXTURE_CUBE_MAP
, 7, GL_R32F
, 64, 64);
58 glTextureView(tex
[1], GL_TEXTURE_CUBE_MAP
, tex
[0], GL_RG16I
, 2, 4, 0, 6);
59 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
[1]);
60 glDeleteTextures(1, &tex
[1]);
61 /* tex[1] which is bound to GL_TEXTURE_CUBE_MAP is deleted */
63 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_VIEW_MIN_LEVEL
,
66 printf("bad default of min_level, expected 0 got %u\n", param
);
69 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_VIEW_NUM_LEVELS
,
72 printf("bad default of num_levels, expected 0 got %u\n", param
);
75 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_VIEW_MIN_LAYER
,
78 printf("bad default of min_layer, expected 0 got %u\n", param
);
81 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_VIEW_NUM_LAYERS
,
84 printf("bad default of num_layers, expected 0 got %u\n", param
);
87 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_IMMUTABLE_FORMAT
,
90 printf("bad default of immutable_format, expected 0 got %u\n",
94 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_IMMUTABLE_LEVELS
,
97 printf("bad default of immutable_levels, expected 0 got %u\n",
101 glDeleteTextures(1, tex
);
107 * This tests min_levels, num_levels, immutable_levels and imutable_format.
108 * note: see params test for more min/num level query testing
110 * In OpenGL Core 4.3 spec see section 8.18:
111 * "The minlevel and minlayer parameters are relative to the view of
112 * origtexture. If numlayers or numlevels extend beyond origtexture, they
113 * are clamped to the maximum extent of the original texture.
114 * If the command is successful, the texture parameters in <texture> are
115 * updated as follows:
116 * - TEXTURE_IMMUTABLE_FORMAT is set to TRUE.
118 * - TEXTURE_IMMUTABLE_LEVELS is set to the value of
119 * TEXTURE_IMMUTABLE_LEVELS from the original texture.
121 * - TEXTURE_VIEW_MIN_LEVEL is set to <minlevel> plus the value of
122 * TEXTURE_VIEW_MIN_LEVEL from the original texture.
124 * - TEXTURE_VIEW_NUM_LEVELS is set to the lesser of numlevels and the
125 * value of TEXTURE_VIEW_NUM_LEVELS for origtexture minus minlevels."
126 * In the ARB_texture_view extension registry spec see this for chained views:
127 * "(3) Is it possible to create a texture view using an original texture
128 * which is itself a view? And if so, how are the level/layer values
131 * RESOLVED: It is legal. For example, let's say texture 1 is a 2D_ARRAY
132 * texture with 200 layers. It will have TEXTURE_VIEW_MIN_LAYER=0,
133 * TEXTURE_VIEW_NUM_LAYERS=200. Then we create texture 2 from texture 1 using
134 * <minlayer>=100, <numlayers>=100. It will have TEXTURE_VIEW_MIN_LAYER=100,
135 * TEXTURE_VIEW_NUM_LAYERS=100. Then we create texture 3 from texture 2 using
136 * <minlayer>=50, <numlayers>=50. It will have TEXTURE_VIEW_MIN_LAYER=150,
137 * TEXTURE_VIEW_NUM_LAYERS=50."
140 query_levels_test(void)
142 GLuint tex
[2], viewtex
, l
;
146 glGenTextures(2, tex
);
148 /* test the view causes immutable_format to be set */
149 glBindTexture(GL_TEXTURE_2D
, tex
[0]);
150 glTexStorage2D(GL_TEXTURE_2D
, 6, GL_R32F
, 16, 32);
151 glTextureView(tex
[1], GL_TEXTURE_2D
, tex
[0], GL_RG16F
, 0, 1, 0, 1);
152 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
154 glBindTexture(GL_TEXTURE_2D
, tex
[1]);
155 glGetTexParameteriv(GL_TEXTURE_2D
, GL_TEXTURE_IMMUTABLE_FORMAT
, ¶m
);
156 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
158 if (param
!= GL_TRUE
) {
159 printf("bad query of immutable_format\n");
162 glDeleteTextures(2,tex
);
165 * test min_levels are additive using chained views
166 * test immutable_levels get set correctly based on origtexture
167 * test num_levels are correct for chained views
169 glGenTextures(2,tex
);
170 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
[0]);
171 glTexStorage2D(GL_TEXTURE_CUBE_MAP
, 7, GL_R32F
, 64, 64);
172 glTextureView(tex
[1], GL_TEXTURE_CUBE_MAP
,tex
[0], GL_RG16I
, 2, 4, 0, 6);
173 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
175 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
[1]);
176 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_IMMUTABLE_LEVELS
,
179 printf("bad query of immutable_levels, expected 7 got %u\n",
183 for (l
= 0; l
< 4; l
++) {
184 glGenTextures(1, &viewtex
);
185 glTextureView(viewtex
, GL_TEXTURE_CUBE_MAP
, tex
[1], GL_RG16F
,
187 glBindTexture(GL_TEXTURE_CUBE_MAP
, viewtex
);
188 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
,
189 GL_TEXTURE_VIEW_MIN_LEVEL
, ¶m
);
190 if (param
!= (2 + l
)) {
191 glDeleteTextures(1, &viewtex
);
192 printf("bad query of view_min_level expected %u got %u\n",
197 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
,
198 GL_TEXTURE_IMMUTABLE_LEVELS
, ¶m
);
200 glDeleteTextures(1, &viewtex
);
201 printf("query of immutable_levels not tracking orig, expected 7 got %u\n",
206 glGetTexParameteriv(GL_TEXTURE_CUBE_MAP
,
207 GL_TEXTURE_VIEW_NUM_LEVELS
, ¶m
);
208 if (param
!= (4 - l
)) {
209 glDeleteTextures(1, &viewtex
);
210 printf("bad query of view_num_levels expected %u got %u\n",
215 glDeleteTextures(1, &viewtex
);
217 glDeleteTextures(2, tex
);
219 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
227 * This tests correct queries of min_layers, num_layers.
228 * note: see params test for more min/num layers query testing
230 * In OpenGL Core 4.3 spec see section 8.18:
231 * "The minlevel and minlayer parameters are relative to the view of
232 * origtexture. If numlayers or numlevels extend beyond origtexture, they
233 * are clamped to the maximum extent of the original texture.
234 * If the command is successful, the texture parameters in <texture> are
235 * updated as follows:
236 * - TEXTURE_VIEW_MIN_LAYER is set to <minlayer> plus the value of
237 * TEXTURE_VIEW_MIN_LAYER from the original texture.
239 * - TEXTURE_VIEW_NUM_LAYERS is set to the lesser of numlayerss and the
240 * value of TEXTURE_VIEW_NUM_LAYERS for origtexture minus minlayers."
244 query_layers_state(void)
247 GLuint tex
[2], viewtex
, l
;
250 glGenTextures(2, tex
);
251 glBindTexture(GL_TEXTURE_2D_ARRAY
, tex
[0]);
252 glTexStorage3D(GL_TEXTURE_2D_ARRAY
, 7, GL_RG16F
, 64, 64, 10);
253 glTextureView(tex
[1], GL_TEXTURE_2D_ARRAY
,tex
[0], GL_RG16I
, 0, 3, 1, 8);
254 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
255 for (l
= 0; l
< 4; l
++) {
256 glGenTextures(1, &viewtex
);
257 glTextureView(viewtex
, GL_TEXTURE_2D_ARRAY
, tex
[1], GL_RG16UI
,
259 glBindTexture(GL_TEXTURE_2D_ARRAY
, viewtex
);
261 /* test min_layers are additive using chained views */
262 glGetTexParameteriv(GL_TEXTURE_2D_ARRAY
,
263 GL_TEXTURE_VIEW_MIN_LAYER
, ¶m
);
265 if (param
!= (1 + l
)) {
266 glDeleteTextures(1, &viewtex
);
267 printf("bad query of view_min_layer expected %u got %u\n",
272 /* test num_layers are correct for chained views */
273 glGetTexParameteriv(GL_TEXTURE_2D_ARRAY
,
274 GL_TEXTURE_VIEW_NUM_LAYERS
, ¶m
);
275 if (param
!= (8 - l
)) {
276 glDeleteTextures(1, &viewtex
);
277 printf("bad query of view_num_layers expected %u got %u\n",
283 glDeleteTextures(1, &viewtex
);
285 glDeleteTextures(2, tex
);
297 piglit_init(int argc
, char **argv
)
300 #ifdef PIGLIT_USE_OPENGL
301 piglit_require_extension("GL_ARB_texture_storage");
302 piglit_require_extension("GL_ARB_texture_view");
304 piglit_require_extension("GL_OES_texture_view");
307 pass
= query_levels_test();
308 pass
= query_layers_state() && pass
;
309 pass
= query_default_state() && pass
;
311 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
312 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);