ext_gpu_shader4: add compiler tests for everything
[piglit.git] / tests / spec / arb_texture_stencil8 / stencil-texture.c
blob7db66c4004f9e299c23e01b8e9fdb3eba920bef7
1 /*
2 * Copyright © 2011 Intel Corporation
3 * Copyright © 2015 Red Hat
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 /**
26 * \file stencil-texture.c
27 * Create a stencil texture.
28 * based on ext_packed_depth_stencil/depth-stencil-texture.c test.
31 #include "piglit-util-gl.h"
33 PIGLIT_GL_TEST_CONFIG_BEGIN
35 config.supports_gl_core_version = 31;
37 config.window_visual = PIGLIT_GL_VISUAL_RGBA;
38 config.khr_no_error_support = PIGLIT_NO_ERRORS;
40 PIGLIT_GL_TEST_CONFIG_END
42 static bool has_cube_array;
44 static bool
45 try_TexImage(GLenum internalFormat)
47 bool pass = true;
48 GLuint tex[7];
49 unsigned i;
51 printf("Testing glTexImage with %s...\n",
52 piglit_get_gl_enum_name(internalFormat));
54 glGenTextures(ARRAY_SIZE(tex), tex);
56 glBindTexture(GL_TEXTURE_1D, tex[0]);
57 glTexImage1D(GL_TEXTURE_1D, 0, internalFormat,
58 16, 0,
59 GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, NULL);
60 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
62 glBindTexture(GL_TEXTURE_2D, tex[1]);
63 glTexImage2D(GL_TEXTURE_2D, 0, internalFormat,
64 16, 16, 0,
65 GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, NULL);
66 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
68 if (!piglit_khr_no_error) {
69 /* 3D texture is not in the list of supported STENCIL_INDEX */
70 glBindTexture(GL_TEXTURE_3D, tex[2]);
71 glTexImage3D(GL_TEXTURE_3D, 0, internalFormat,
72 8, 8, 8, 0,
73 GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, NULL);
74 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
77 glBindTexture(GL_TEXTURE_CUBE_MAP, tex[3]);
79 for (i = 0; i < 6; i++) {
80 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
81 0, internalFormat,
82 16, 16, 0,
83 GL_STENCIL_INDEX, GL_UNSIGNED_BYTE,
84 NULL);
85 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
88 glBindTexture(GL_TEXTURE_1D_ARRAY, tex[4]);
89 glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, internalFormat,
90 16, 16, 0,
91 GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, NULL);
92 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
94 glBindTexture(GL_TEXTURE_2D_ARRAY, tex[5]);
95 glTexImage3D(GL_TEXTURE_2D_ARRAY, 0, internalFormat,
96 8, 8, 8, 0,
97 GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, NULL);
98 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
100 if (has_cube_array) {
101 glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, tex[6]);
102 glTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 0, internalFormat,
103 8, 8, 6, 0,
104 GL_STENCIL_INDEX, GL_UNSIGNED_BYTE, NULL);
105 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
108 glBindTexture(GL_TEXTURE_1D, 0);
109 glBindTexture(GL_TEXTURE_2D, 0);
110 glBindTexture(GL_TEXTURE_3D, 0);
111 glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
112 glBindTexture(GL_TEXTURE_1D_ARRAY, 0);
113 glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
114 if (has_cube_array)
115 glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
117 glDeleteTextures(ARRAY_SIZE(tex), tex);
119 printf("Done.\n\n");
121 return pass;
124 static bool
125 try_TexStorage(GLenum internalFormat)
127 bool pass = true;
128 GLuint tex[7];
130 printf("Testing glTexStorage with %s...\n",
131 piglit_get_gl_enum_name(internalFormat));
133 glGenTextures(ARRAY_SIZE(tex), tex);
135 glBindTexture(GL_TEXTURE_1D, tex[0]);
136 glTexStorage1D(GL_TEXTURE_1D, 1, internalFormat, 16);
137 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
139 glBindTexture(GL_TEXTURE_2D, tex[1]);
140 glTexStorage2D(GL_TEXTURE_2D, 1, internalFormat, 16, 16);
141 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
143 if (!piglit_khr_no_error) {
144 glBindTexture(GL_TEXTURE_3D, tex[2]);
145 glTexStorage3D(GL_TEXTURE_3D, 1, internalFormat, 8, 8, 8);
146 pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass;
149 glBindTexture(GL_TEXTURE_CUBE_MAP, tex[3]);
150 glTexStorage2D(GL_TEXTURE_CUBE_MAP, 1, internalFormat, 16, 16);
151 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
153 glBindTexture(GL_TEXTURE_1D_ARRAY, tex[4]);
154 glTexStorage2D(GL_TEXTURE_1D_ARRAY, 1, internalFormat, 16, 16);
155 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
157 glBindTexture(GL_TEXTURE_2D_ARRAY, tex[5]);
158 glTexStorage3D(GL_TEXTURE_2D_ARRAY, 1, internalFormat, 16, 16, 8);
159 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
161 if (has_cube_array) {
162 glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, tex[6]);
163 glTexStorage3D(GL_TEXTURE_CUBE_MAP_ARRAY, 1, internalFormat, 16, 16, 6);
164 pass = piglit_check_gl_error(GL_NO_ERROR) && pass;
167 glBindTexture(GL_TEXTURE_1D, 0);
168 glBindTexture(GL_TEXTURE_2D, 0);
169 glBindTexture(GL_TEXTURE_3D, 0);
170 glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
171 glBindTexture(GL_TEXTURE_1D_ARRAY, 0);
172 glBindTexture(GL_TEXTURE_2D_ARRAY, 0);
173 if (has_cube_array)
174 glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY, 0);
176 glDeleteTextures(ARRAY_SIZE(tex), tex);
178 printf("Done.\n\n");
180 return pass;
183 void piglit_init(int argc, char **argv)
185 bool pass = true;
186 bool has_texture_storage;
188 piglit_require_extension("GL_ARB_texture_stencil8");
189 has_cube_array = piglit_get_gl_version() >= 40
190 || piglit_is_extension_supported("GL_ARB_texture_cube_map_array");
192 has_texture_storage = piglit_get_gl_version() >= 42
193 || piglit_is_extension_supported("GL_ARB_texture_storage");
195 pass = try_TexImage(GL_STENCIL_INDEX8) && pass;
197 if (has_texture_storage) {
198 pass = try_TexStorage(GL_STENCIL_INDEX8) && pass;
201 piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
204 enum piglit_result
205 piglit_display(void)
207 /* UNREACHED */
208 return PIGLIT_FAIL;