2 * Copyright 2015 Ilia Mirkin
3 * Copyright (c) 2021 Collabora Ltd
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
27 * A test to make sure that EXT_clear_texture respects texture views
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config
.supports_gl_es_version
= 31;
33 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
34 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
35 PIGLIT_GL_TEST_CONFIG_END
37 static const GLubyte red
[4] = {255, 0, 0, 255};
39 static const GLfloat green_test
[4] = {0.0, 1.0, 0, 1.0};
40 static const GLfloat red_test
[4] = {1.0, 0, 0, 1.0};
51 memcpy(&red4
[0], red
, sizeof(red
));
52 memcpy(&red4
[4], red
, sizeof(red
));
53 memcpy(&red4
[8], red
, sizeof(red
));
54 memcpy(&red4
[12], red
, sizeof(red
));
56 glGenTextures(1, &src
);
58 glBindTexture(GL_TEXTURE_2D
, src
);
59 glTexStorage2D(GL_TEXTURE_2D
, 2, GL_RGBA8
, 2, 2);
61 for (i
= 0; i
< 2; i
++) {
64 /* reset src to red */
65 glBindTexture(GL_TEXTURE_2D
, src
);
66 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 2, 2,
67 GL_RGBA
, GL_UNSIGNED_BYTE
, red4
);
68 glTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 1, 1,
69 GL_RGBA
, GL_UNSIGNED_BYTE
, red
);
71 /* create a single-level view */
72 glGenTextures(1, &view
);
73 glTextureView(view
, GL_TEXTURE_2D
, src
,
74 GL_RGBA8
, i
, 1, 0, 1);
76 glClearTexImageEXT(view
, 0, GL_RGBA
, GL_FLOAT
, green_test
);
78 /* check that the i'th level is cleared while others aren't */
79 for (j
= 0; j
< 2; j
++) {
80 pass
&= piglit_probe_texel_rect_rgba(
83 j
== i
? green_test
: red_test
);
85 glDeleteTextures(1, &view
);
88 glDeleteTextures(1, &src
);
100 memcpy(&red2
[0], red
, sizeof(red
));
101 memcpy(&red2
[4], red
, sizeof(red
));
103 glGenTextures(1, &src
);
105 glBindTexture(GL_TEXTURE_2D_ARRAY
, src
);
106 glTexStorage3D(GL_TEXTURE_2D_ARRAY
, 1, GL_RGBA8
, 1, 1, 2);
108 for (i
= 0; i
< 2; i
++) {
111 /* reset src to red */
112 glBindTexture(GL_TEXTURE_2D_ARRAY
, src
);
113 glTexSubImage3D(GL_TEXTURE_2D_ARRAY
, 0, 0, 0, 0,
115 GL_RGBA
, GL_UNSIGNED_BYTE
, red2
);
117 /* create view of the layer1 */
118 glGenTextures(1, &view
);
119 glTextureView(view
, GL_TEXTURE_2D_ARRAY
, src
,
120 GL_RGBA8
, 0, 1, i
, 1);
122 glClearTexImageEXT(view
, 0, GL_RGBA
, GL_FLOAT
, green_test
);
124 /* check that the i'th layer is cleared while others aren't */
125 for (j
= 0; j
< 2; j
++) {
126 pass
&= piglit_probe_texel_volume_rgba(
127 GL_TEXTURE_2D_ARRAY
, 0,
129 j
== i
? green_test
: red_test
);
131 glDeleteTextures(1, &view
);
134 glDeleteTextures(1, &src
);
139 piglit_init(int argc
, char **argv
)
142 piglit_require_extension("GL_EXT_clear_texture");
143 piglit_require_extension("GL_OES_texture_view");
146 if (piglit_is_extension_supported("GL_EXT_texture_array"))
147 pass
&= test_2d_array();
149 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);