1 /* Copyright © 2011 Intel Corporation
3 * Permission is hereby granted, free of charge, to any person obtaining a
4 * copy of this software and associated documentation files (the "Software"),
5 * to deal in the Software without restriction, including without limitation
6 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 * and/or sell copies of the Software, and to permit persons to whom the
8 * Software is furnished to do so, subject to the following conditions:
10 * The above copyright notice and this permission notice (including the next
11 * paragraph) shall be included in all copies or substantial portions of the
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 #include "piglit-util-gl.h"
24 #include "sized-internalformats.h"
27 * @file required-sized-formats.c
29 * Tests that the required sized internal formats for GL 3.0 are
30 * exposed. See page 180 of the GL 3.0 pdf (20080923), "Required
31 * Texture Formats". Notably:
33 * "In addition, implementations are required to support the
34 * following sized internal formats. Requesting one of these
35 * internal formats for any texture type will allocate exactly
36 * the internal component sizes and types shown for that format
37 * in tables 3.16- 3.17:"
39 * Note that table 3.18, sized internal depth and stencil formats, is
42 * In GL 3.1 this is changed to allow increased precision for the
43 * required sized formats. From page 118 of the GL 3.1 core spec PDF
46 * "In addition, implementations are required to support the
47 * following sized and compressed internal formats. Requesting
48 * one of these sized internal formats for any texture type will
49 * allocate at least the internal component sizes, and exactly
50 * the component types shown for that format in tables 3.12-
54 GLenum type_queries
[CHANNELS
] = {
56 GL_TEXTURE_GREEN_TYPE
,
58 GL_TEXTURE_ALPHA_TYPE
,
59 GL_TEXTURE_LUMINANCE_TYPE
,
60 GL_TEXTURE_INTENSITY_TYPE
,
61 GL_TEXTURE_DEPTH_TYPE
,
65 GLenum size_queries
[CHANNELS
] = {
67 GL_TEXTURE_GREEN_SIZE
,
69 GL_TEXTURE_ALPHA_SIZE
,
70 GL_TEXTURE_LUMINANCE_SIZE
,
71 GL_TEXTURE_INTENSITY_SIZE
,
72 GL_TEXTURE_DEPTH_SIZE
,
73 GL_TEXTURE_STENCIL_SIZE
,
76 static int target_version
;
86 GetTexLevelParameteriv(GLenum target
, GLuint level
, GLenum pname
, GLint
*value
)
88 const bool compat_profile
= !piglit_is_gles() &&
89 !piglit_is_core_profile
;
91 if (!compat_profile
) {
93 case GL_TEXTURE_LUMINANCE_SIZE
:
94 case GL_TEXTURE_INTENSITY_SIZE
:
95 case GL_TEXTURE_LUMINANCE_TYPE
:
96 case GL_TEXTURE_INTENSITY_TYPE
:
104 glGetTexLevelParameteriv(target
, level
, pname
, value
);
108 piglit_init(int argc
, char **argv
)
114 piglit_require_gl_version(target_version
);
116 glGenTextures(1, &tex
);
117 glBindTexture(GL_TEXTURE_2D
, tex
);
119 for (i
= 0; required_formats
[i
].token
!= GL_NONE
; i
++) {
120 GLint sizes
[CHANNELS
];
121 GLint types
[CHANNELS
];
122 bool format_pass
= true;
124 const struct sized_internalformat
*f
;
126 if (!valid_for_gl_version(&required_formats
[i
], target_version
))
129 f
= get_sized_internalformat(required_formats
[i
].token
);
131 printf("Failed to get sized format for %s\n",
132 piglit_get_gl_enum_name(required_formats
[i
].token
));
137 if (f
->token
== GL_DEPTH24_STENCIL8
||
138 f
->token
== GL_DEPTH32F_STENCIL8
) {
139 format
= GL_DEPTH_STENCIL
;
140 type
= GL_UNSIGNED_INT_24_8
;
141 } else if (get_channel_size(f
, D
)) {
142 format
= GL_DEPTH_COMPONENT
;
148 /* Have to specify integer data for integer textures. */
149 for (c
= R
; c
<= I
; c
++) {
150 if (get_channel_type(f
, c
) == GL_UNSIGNED_INT
||
151 get_channel_type(f
, c
) == GL_INT
) {
152 format
= GL_RGBA_INTEGER
;
153 type
= GL_UNSIGNED_INT
;
159 glTexImage2D(GL_TEXTURE_2D
, 0, f
->token
,
163 if (glGetError() != 0) {
164 printf("Unexpected error creating %s texture\n",
165 piglit_get_gl_enum_name(f
->token
));
170 for (c
= 0; c
< CHANNELS
; c
++) {
171 GetTexLevelParameteriv(GL_TEXTURE_2D
, 0,
172 size_queries
[c
], &sizes
[c
]);
175 GetTexLevelParameteriv(GL_TEXTURE_2D
, 0,
179 /* For stencil, there's no query for
180 * the type, so our table above
181 * records a type/size of unorm 8, and
182 * we'll just set the query result
183 * here to unorm so that we only look
187 types
[c
] = GL_UNSIGNED_NORMALIZED
;
192 /* We use ~0 as the signal for the compressed
193 * texture formats. While the colors being
194 * interpolated across the 4x4 blocks have 8
195 * bits in them, the spec suggests reporting
196 * some approximate value less than that.
197 * From page 319 of the GL 3.0 spec:
199 * "Queries of value of TEXTURE RED SIZE,
200 * TEXTURE GREEN SIZE, [...] return the
201 * actual resolutions of the stored image
202 * array components, not the resolutions
203 * specified when the image array was
204 * defined. For texture images with a
205 * compressed internal format, the
206 * resolutions returned specify the
207 * component resolution of an
208 * uncompressed internal format that
209 * produces an image of roughly the same
210 * quality as the compressed image in
211 * question. Since the quality of the
212 * implementation’s compression algorithm
213 * is likely data-dependent, the returned
214 * component sizes should be treated only
215 * as rough approximations.
217 if (f
->bits
[c
] == SCMP
||
218 f
->bits
[c
] == UCMP
) {
219 if (sizes
[c
] <= 0 || sizes
[c
] > 8)
221 } else if (target_version
== 30) {
222 if (sizes
[c
] != get_channel_size(f
, c
)) {
223 if ((c
== D
|| c
== S
) &&
224 get_channel_size(f
, c
) > 0) {
225 /* any non-zero size will do */
233 if (sizes
[c
] < get_channel_size(f
, c
)) {
238 if (types
[c
] != get_channel_type(f
, c
))
243 printf("format %s:\n",
244 piglit_get_gl_enum_name(f
->token
));
246 printf(" expected: ");
247 for (c
= 0; c
< CHANNELS
; c
++) {
248 print_bits(get_channel_size(f
, c
),
249 get_channel_type(f
, c
));
254 printf(" observed: ");
255 for (c
= 0; c
< CHANNELS
; c
++) {
256 print_bits(sizes
[c
], types
[c
]);
265 glDeleteTextures(1, &tex
);
267 piglit_report_result(pass
? PIGLIT_PASS
: PIGLIT_FAIL
);
270 PIGLIT_GL_TEST_CONFIG_BEGIN
271 setup_required_size_test(argc
, argv
, &config
);
272 target_version
= MAX2(config
.supports_gl_compat_version
,
273 config
.supports_gl_core_version
);
274 config
.khr_no_error_support
= PIGLIT_NO_ERRORS
;
275 PIGLIT_GL_TEST_CONFIG_END