2 * Copyright (c) 2014 Intel Corporation
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 of using glClearTexSubImage to clear faces of a cube
28 * texture. Each face is cleared to a separate color and then all of
29 * the faces are rendered and probed.
40 /* Color used for this face */
42 /* Texture coordinates needed to access this face */
48 static const struct face
50 { { 0.0f
, 0.0f
, 1.0f
}, { +1.0f
, 0.0f
, 0.0f
},
51 GL_TEXTURE_CUBE_MAP_POSITIVE_X
},
52 { { 0.0f
, 1.0f
, 0.0f
}, { -1.0f
, 0.0f
, 0.0f
},
53 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
},
54 { { 0.0f
, 1.0f
, 1.0f
}, { 0.0f
, +1.0f
, 0.0f
},
55 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
},
56 { { 1.0f
, 0.0f
, 0.0f
}, { 0.0f
, -1.0f
, 0.0f
},
57 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
},
58 { { 1.0f
, 0.0f
, 1.0f
}, { 0.0f
, 0.0f
, +1.0f
},
59 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
},
60 { { 1.0f
, 1.0f
, 0.0f
}, { 0.0f
, 0.0f
, -1.0f
},
61 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
},
64 PIGLIT_GL_TEST_CONFIG_BEGIN
66 config
.supports_gl_es_version
= 31;
68 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
69 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
71 PIGLIT_GL_TEST_CONFIG_END
79 glGenTextures(1, &tex
);
80 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
);
82 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
84 for (i
= 0; i
< 6; i
++) {
85 glTexImage2D(faces
[i
].target
,
88 1, 1, /* width/height */
95 glTexParameteri(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
96 glTexParameteri(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
98 if (!piglit_check_gl_error(GL_NO_ERROR
))
99 piglit_report_result(PIGLIT_FAIL
);
105 clear_texture(GLuint tex
)
109 for (i
= 0; i
< 6; i
++) {
110 glClearTexSubImageEXT(tex
,
119 if (!piglit_check_gl_error(GL_NO_ERROR
))
120 piglit_report_result(PIGLIT_FAIL
);
124 piglit_init(int argc
, char **argv
)
126 piglit_require_extension("GL_EXT_clear_texture");
127 init_program("Cube");
133 struct vertex vertices
[6];
136 for (i
= 0; i
< 6; i
++) {
137 vertices
[i
].pos
[0] = i
+ 0.5f
;
138 vertices
[i
].pos
[1] = 0.5;
139 memcpy(vertices
[i
].tex_coord
,
141 sizeof faces
[i
].tex_coord
);
144 glEnableVertexAttribArray(PIGLIT_ATTRIB_POS
);
145 glVertexAttribPointer(PIGLIT_ATTRIB_POS
,
148 GL_FALSE
, /* normalized */
151 glEnableVertexAttribArray(PIGLIT_ATTRIB_TEX
);
152 glVertexAttribPointer(PIGLIT_ATTRIB_TEX
,
155 GL_FALSE
, /* normalized */
157 vertices
[0].tex_coord
);
159 glDrawArrays(GL_POINTS
, 0, 6);
161 glDisableVertexAttribArray(PIGLIT_ATTRIB_POS
);
162 glDisableVertexAttribArray(PIGLIT_ATTRIB_TEX
);
164 if (!piglit_check_gl_error(GL_NO_ERROR
))
165 piglit_report_result(PIGLIT_FAIL
);
176 tex
= create_texture();
180 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
);
184 for (i
= 0; i
< 6; i
++)
185 pass
&= piglit_probe_pixel_rgb(i
, 0, faces
[i
].color
);
187 glBindTexture(GL_TEXTURE_CUBE_MAP
, 0);
189 glDeleteTextures(1, &tex
);
191 piglit_present_results();
193 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;