2 * Copyright (c) 2014 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
26 * A test of using glClearTexSubImage to clear faces of a cube
27 * texture. Each face is cleared to a separate color and then all of
28 * the faces are rendered and probed.
31 #include "piglit-util-gl.h"
39 /* Color used for this face */
41 /* Texture coordinates needed to access this face */
47 static const struct face
49 { { 0.0f
, 0.0f
, 1.0f
}, { +1.0f
, 0.0f
, 0.0f
},
50 GL_TEXTURE_CUBE_MAP_POSITIVE_X
},
51 { { 0.0f
, 1.0f
, 0.0f
}, { -1.0f
, 0.0f
, 0.0f
},
52 GL_TEXTURE_CUBE_MAP_NEGATIVE_X
},
53 { { 0.0f
, 1.0f
, 1.0f
}, { 0.0f
, +1.0f
, 0.0f
},
54 GL_TEXTURE_CUBE_MAP_POSITIVE_Y
},
55 { { 1.0f
, 0.0f
, 0.0f
}, { 0.0f
, -1.0f
, 0.0f
},
56 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
},
57 { { 1.0f
, 0.0f
, 1.0f
}, { 0.0f
, 0.0f
, +1.0f
},
58 GL_TEXTURE_CUBE_MAP_POSITIVE_Z
},
59 { { 1.0f
, 1.0f
, 0.0f
}, { 0.0f
, 0.0f
, -1.0f
},
60 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
},
63 PIGLIT_GL_TEST_CONFIG_BEGIN
65 config
.supports_gl_compat_version
= 20;
66 config
.supports_gl_es_version
= 20;
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 glClearTexSubImage(tex
,
113 1, 1, 1, /* width/height/depth */
119 if (!piglit_check_gl_error(GL_NO_ERROR
))
120 piglit_report_result(PIGLIT_FAIL
);
129 static const char vs_source
[] =
130 "attribute float piglit_vertex;\n"
131 "attribute vec3 piglit_texcoord;\n"
132 "uniform vec2 fb_size;\n"
133 "varying vec3 tex_coord;\n"
137 " gl_Position = vec4(vec2(piglit_vertex, 0.5) * 2.0 /\n"
140 " tex_coord = piglit_texcoord;\n"
142 static const char fs_source
[] =
143 "uniform samplerCube tex;\n"
144 "varying vec3 tex_coord;\n"
148 " gl_FragColor = textureCube(tex, tex_coord);\n"
151 prog
= piglit_build_simple_program(vs_source
, fs_source
);
155 uniform
= glGetUniformLocation(prog
, "tex");
156 glUniform1i(uniform
, 0);
158 uniform
= glGetUniformLocation(prog
, "fb_size");
159 glUniform2f(uniform
, piglit_width
, piglit_height
);
163 piglit_init(int argc
, char **argv
)
165 /* glClearTexture is either in the GL_ARB_clear_texture
166 * extension or in core in GL 4.4
168 if (piglit_get_gl_version() < 44 &&
169 !piglit_is_extension_supported("GL_ARB_clear_texture")) {
170 printf("OpenGL 4.4 or GL_ARB_clear_texture is required.\n");
171 piglit_report_result(PIGLIT_SKIP
);
180 struct vertex vertices
[6];
183 for (i
= 0; i
< 6; i
++) {
184 vertices
[i
].pos
= i
+ 0.5f
;
185 memcpy(vertices
[i
].tex_coord
,
187 sizeof faces
[i
].tex_coord
);
190 glEnableVertexAttribArray(PIGLIT_ATTRIB_POS
);
191 glVertexAttribPointer(PIGLIT_ATTRIB_POS
,
194 GL_FALSE
, /* normalized */
197 glEnableVertexAttribArray(PIGLIT_ATTRIB_TEX
);
198 glVertexAttribPointer(PIGLIT_ATTRIB_TEX
,
201 GL_FALSE
, /* normalized */
203 vertices
[0].tex_coord
);
205 glDrawArrays(GL_POINTS
, 0, 6);
207 glDisableVertexAttribArray(PIGLIT_ATTRIB_POS
);
208 glDisableVertexAttribArray(PIGLIT_ATTRIB_TEX
);
218 tex
= create_texture();
222 glBindTexture(GL_TEXTURE_CUBE_MAP
, tex
);
226 glBindTexture(GL_TEXTURE_CUBE_MAP
, 0);
228 glDeleteTextures(1, &tex
);
230 for (i
= 0; i
< 6; i
++)
231 pass
&= piglit_probe_pixel_rgb(i
, 0, faces
[i
].color
);
233 piglit_present_results();
235 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;