2 * Copyright 2015 Ilia Mirkin
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
26 * A test to make sure that ARB_copy_image respects texture views on
27 * both the source and destination ends.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
32 config
.supports_gl_compat_version
= 13;
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 float green
[4] = {0.0, 1.0, 0.0, 1.0};
38 static const float red
[4] = {1.0, 0.0, 0.0, 1.0};
48 memcpy(&red4
[0], red
, sizeof(red
));
49 memcpy(&red4
[4], red
, sizeof(red
));
50 memcpy(&red4
[8], red
, sizeof(red
));
51 memcpy(&red4
[12], red
, sizeof(red
));
53 glGenTextures(1, &src
);
55 glBindTexture(GL_TEXTURE_2D
, src
);
56 glTexStorage2D(GL_TEXTURE_2D
, 2, GL_RGBA8
, 2, 2);
58 for (i
= 0; i
< 2; i
++) {
61 /* reset src to red */
62 glBindTexture(GL_TEXTURE_2D
, src
);
63 glTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 2, 2,
64 GL_RGBA
, GL_FLOAT
, red4
);
65 glTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 1, 1,
66 GL_RGBA
, GL_FLOAT
, red
);
68 /* create a single-level view */
69 glGenTextures(1, &view
);
70 glTextureView(view
, GL_TEXTURE_2D
, src
,
71 GL_RGBA8
, i
, 1, 0, 1);
73 glClearTexImage(view
, 0, GL_RGBA
, GL_FLOAT
, green
);
75 /* check that the i'th level is cleared while others aren't */
76 for (j
= 0; j
< 2; j
++) {
77 pass
&= piglit_probe_texel_rect_rgba(
80 j
== i
? green
: red
);
82 glDeleteTextures(1, &view
);
85 glDeleteTextures(1, &src
);
97 memcpy(&red2
[0], red
, sizeof(red
));
98 memcpy(&red2
[4], red
, sizeof(red
));
100 glGenTextures(1, &src
);
102 glBindTexture(GL_TEXTURE_2D_ARRAY
, src
);
103 glTexStorage3D(GL_TEXTURE_2D_ARRAY
, 1, GL_RGBA8
, 1, 1, 2);
105 for (i
= 0; i
< 2; i
++) {
108 /* reset src to red */
109 glBindTexture(GL_TEXTURE_2D_ARRAY
, src
);
110 glTexSubImage3D(GL_TEXTURE_2D_ARRAY
, 0, 0, 0, 0,
112 GL_RGBA
, GL_FLOAT
, red2
);
114 /* create view of the layer1 */
115 glGenTextures(1, &view
);
116 glTextureView(view
, GL_TEXTURE_2D_ARRAY
, src
,
117 GL_RGBA8
, 0, 1, i
, 1);
119 glClearTexImage(view
, 0, GL_RGBA
, GL_FLOAT
, green
);
121 /* check that the i'th layer is cleared while others aren't */
122 for (j
= 0; j
< 2; j
++) {
123 pass
&= piglit_probe_texel_volume_rgba(
124 GL_TEXTURE_2D_ARRAY
, 0,
126 j
== i
? green
: red
);
128 glDeleteTextures(1, &view
);
131 glDeleteTextures(1, &src
);
136 piglit_init(int argc
, char **argv
)
139 piglit_require_extension("GL_ARB_clear_texture");
140 piglit_require_extension("GL_ARB_texture_view");
141 piglit_require_extension("GL_ARB_texture_storage");
144 if (piglit_is_extension_supported("GL_EXT_texture_array"))
145 pass
&= test_2d_array();
147 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);