ovr_multiview: add some basic glsl tests
[piglit.git] / tests / spec / ext_clear_texture / cube.c
blob041455ccdf9a3d3a2db2b8379dda49683914cdc8
1 /*
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
14 * Software.
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
22 * IN THE SOFTWARE.
25 /** @file cube.c
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.
32 #include "common.h"
34 struct vertex {
35 float pos[2];
36 float tex_coord[3];
39 struct face {
40 /* Color used for this face */
41 float color[3];
42 /* Texture coordinates needed to access this face */
43 float tex_coord[3];
45 GLenum target;
48 static const struct face
49 faces[] = {
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
73 static GLuint
74 create_texture(void)
76 GLuint tex;
77 int i;
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,
86 0, /* level */
87 GL_RGB32F,
88 1, 1, /* width/height */
89 0, /* border */
90 GL_RGB,
91 GL_FLOAT,
92 NULL);
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);
101 return tex;
104 static void
105 clear_texture(GLuint tex)
107 int i;
109 for (i = 0; i < 6; i++) {
110 glClearTexSubImageEXT(tex,
111 0, /* level */
112 0, 0, i,
113 1, 1, 1,
114 GL_RGB,
115 GL_FLOAT,
116 faces[i].color);
119 if (!piglit_check_gl_error(GL_NO_ERROR))
120 piglit_report_result(PIGLIT_FAIL);
123 void
124 piglit_init(int argc, char **argv)
126 piglit_require_extension("GL_EXT_clear_texture");
127 init_program("Cube");
130 static void
131 draw_faces(void)
133 struct vertex vertices[6];
134 int i;
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,
140 faces[i].tex_coord,
141 sizeof faces[i].tex_coord);
144 glEnableVertexAttribArray(PIGLIT_ATTRIB_POS);
145 glVertexAttribPointer(PIGLIT_ATTRIB_POS,
146 2, /* size */
147 GL_FLOAT,
148 GL_FALSE, /* normalized */
149 sizeof vertices[0],
150 &vertices[0].pos);
151 glEnableVertexAttribArray(PIGLIT_ATTRIB_TEX);
152 glVertexAttribPointer(PIGLIT_ATTRIB_TEX,
153 3, /* size */
154 GL_FLOAT,
155 GL_FALSE, /* normalized */
156 sizeof vertices[0],
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);
169 enum piglit_result
170 piglit_display(void)
172 bool pass = true;
173 GLuint tex;
174 int i;
176 tex = create_texture();
178 clear_texture(tex);
180 glBindTexture(GL_TEXTURE_CUBE_MAP, tex);
182 draw_faces();
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;