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
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 * \file blit-corrupts-state.c
26 * Tests for a bug in glBlitFramebuffer corrupting GL_DEPTH_STENCIL_TEXTURE_MODE
28 * The default state for GL_DEPTH_STENCIL_TEXTURE_MODE is GL_DEPTH_COMPONENT.
29 * Create two GL_DEPTH_STENCIL textures and two framebuffer objects. Attach
30 * one texture to each of the FBOs, and blit stencil from one to the other.
31 * After the blit operation verify that the state of
32 * GL_DEPTH_STENCIL_TEXTURE_MODE has not changed.
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_compat_version
= 30;
40 config
.supports_gl_core_version
= 31;
42 PIGLIT_GL_TEST_CONFIG_END
45 check_texture_state(GLenum target
, unsigned line
)
49 glGetTexParameteriv(target
,
50 GL_DEPTH_STENCIL_TEXTURE_MODE
,
52 if (value
!= GL_DEPTH_COMPONENT
) {
53 printf("%s, %d: Expected GL_DEPTH_COMPONENT, got %s "
56 piglit_get_gl_enum_name(value
),
65 setup_texture(GLenum target
)
67 /* All of the non-multisample targets should have the minification and
68 * the magnification set to GL_NEAREST. Setting the filters for
69 * multisample targets results in a GL error.
71 if (target
!= GL_TEXTURE_2D_MULTISAMPLE
&&
72 target
!= GL_TEXTURE_2D_MULTISAMPLE_ARRAY
) {
73 glTexParameteri(target
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
74 glTexParameteri(target
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
90 case GL_TEXTURE_RECTANGLE
:
91 case GL_TEXTURE_1D_ARRAY
:
103 case GL_TEXTURE_CUBE_MAP
:
104 for (unsigned i
= 0; i
< 6; i
++) {
105 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X
+ i
,
112 GL_UNSIGNED_INT_24_8
,
117 case GL_TEXTURE_2D_ARRAY
:
118 case GL_TEXTURE_CUBE_MAP_ARRAY
:
127 GL_UNSIGNED_INT_24_8
,
131 case GL_TEXTURE_2D_MULTISAMPLE
:
132 glTexImage2DMultisample(target
,
137 GL_TRUE
/* fixedsamplelocations */);
140 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
141 glTexImage3DMultisample(target
,
147 GL_TRUE
/* fixedsamplelocations */);
153 setup_fbo(GLenum target
, GLenum textarget
, GLuint attachment
)
159 glFramebufferTexture1D(target
, GL_DEPTH_STENCIL_ATTACHMENT
,
160 textarget
, attachment
,
165 case GL_TEXTURE_2D_MULTISAMPLE
:
166 case GL_TEXTURE_RECTANGLE
:
167 glFramebufferTexture2D(target
, GL_DEPTH_STENCIL_ATTACHMENT
,
168 textarget
, attachment
,
172 case GL_TEXTURE_1D_ARRAY
:
173 case GL_TEXTURE_2D_ARRAY
:
174 case GL_TEXTURE_2D_MULTISAMPLE_ARRAY
:
175 case GL_TEXTURE_CUBE_MAP
:
176 case GL_TEXTURE_CUBE_MAP_ARRAY
:
177 glFramebufferTextureLayer(target
, GL_DEPTH_STENCIL_ATTACHMENT
,
184 status
= glCheckFramebufferStatus(target
);
185 if (status
!= GL_FRAMEBUFFER_COMPLETE
) {
186 printf("Framebuffer incomplete: %s (0x%04x).\n",
187 piglit_get_gl_enum_name(status
),
189 piglit_report_result(PIGLIT_FAIL
);
193 static const struct {
195 const char *required_extension
;
197 { GL_TEXTURE_1D
, NULL
},
198 { GL_TEXTURE_2D
, NULL
},
200 { GL_TEXTURE_RECTANGLE
, "GL_ARB_texture_rectangle" },
201 { GL_TEXTURE_2D_MULTISAMPLE
, "GL_ARB_texture_multisample" },
202 { GL_TEXTURE_2D_MULTISAMPLE_ARRAY
, "GL_ARB_texture_multisample" },
205 * These do not require any extensions because they are part of OpenGL
206 * 3.0. This is especially important for GL_TEXTURE_CUBE_MAP. This
207 * target existed before 3.0, but it could not be used for
208 * GL_DEPTH_COMPONENT or GL_DEPTH_STENCIL formats before then.
211 { GL_TEXTURE_1D_ARRAY
, NULL
},
212 { GL_TEXTURE_2D_ARRAY
, NULL
},
213 { GL_TEXTURE_CUBE_MAP
, NULL
},
216 { GL_TEXTURE_CUBE_MAP_ARRAY
, "GL_ARB_texture_cube_map_array" },
220 usage_and_exit(const char *name
)
222 printf("Usage: %s <target>\n\n"
223 "Where <target> is one of:\n",
226 for (unsigned i
= 0; i
< ARRAY_SIZE(test_vectors
); i
++) {
227 const char *target_name
=
228 piglit_get_gl_enum_name(test_vectors
[i
].target
);
229 if (test_vectors
[i
].required_extension
== NULL
)
233 printf("\t%s (requires %s)\n",
235 test_vectors
[i
].required_extension
);
238 piglit_report_result(PIGLIT_FAIL
);
242 piglit_init(int argc
, char **argv
)
249 piglit_require_extension("GL_ARB_stencil_texturing");
252 usage_and_exit(argv
[0]);
254 for (unsigned i
= 0; i
< ARRAY_SIZE(test_vectors
); i
++) {
255 if (strcmp(piglit_get_gl_enum_name(test_vectors
[i
].target
),
257 if (test_vectors
[i
].required_extension
!= NULL
)
258 piglit_require_extension(test_vectors
[i
].required_extension
);
260 target
= test_vectors
[i
].target
;
266 usage_and_exit(argv
[0]);
268 glGenTextures(ARRAY_SIZE(tex
), tex
);
269 glGenFramebuffers(ARRAY_SIZE(fbo
), fbo
);
271 glBindTexture(target
, tex
[0]);
272 setup_texture(target
);
273 pass
= check_texture_state(target
, __LINE__
) && pass
;
275 glBindTexture(target
, tex
[1]);
276 setup_texture(target
);
277 pass
= check_texture_state(target
, __LINE__
) && pass
;
279 glBindTexture(target
, 0);
281 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, fbo
[0]);
282 glBindFramebuffer(GL_READ_FRAMEBUFFER
, fbo
[1]);
284 setup_fbo(GL_DRAW_FRAMEBUFFER
, target
, tex
[0]);
285 setup_fbo(GL_READ_FRAMEBUFFER
, target
, tex
[1]);
287 glBlitFramebuffer(0, 0, 15, 15,
289 GL_STENCIL_BUFFER_BIT
, GL_NEAREST
);
291 glBindTexture(target
, tex
[0]);
292 pass
= check_texture_state(target
, __LINE__
) && pass
;
294 glBindTexture(target
, tex
[1]);
295 pass
= check_texture_state(target
, __LINE__
) && pass
;
297 glBindTexture(target
, 0);
298 glBindFramebuffer(GL_DRAW_FRAMEBUFFER
, 0);
299 glBindFramebuffer(GL_READ_FRAMEBUFFER
, 0);
300 glDeleteTextures(ARRAY_SIZE(tex
), tex
);
301 glDeleteFramebuffers(ARRAY_SIZE(fbo
), fbo
);
303 pass
= piglit_check_gl_error(GL_NO_ERROR
) && pass
;
305 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);