2 * Copyright © 2011 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
21 * DEALINGS IN THE SOFTWARE.
24 #include "piglit-util-gl.h"
26 PIGLIT_GL_TEST_CONFIG_BEGIN
28 config
.supports_gl_es_version
= 10;
30 config
.window_width
= 100;
31 config
.window_height
= 100;
32 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
34 PIGLIT_GL_TEST_CONFIG_END
37 GLenum internal_format
;
41 unsigned palette_size
;
44 static const struct test_vector t
[] = {
45 { GL_PALETTE4_RGB8_OES
, GL_RGB
, GL_UNSIGNED_BYTE
, 1, 3 * 16 },
46 { GL_PALETTE4_RGBA8_OES
, GL_RGBA
, GL_UNSIGNED_BYTE
, 1, 4 * 16 },
47 { GL_PALETTE4_R5_G6_B5_OES
, GL_RGB
, GL_UNSIGNED_BYTE
, 1, 2 * 16 },
48 { GL_PALETTE4_RGBA4_OES
, GL_RGBA
, GL_UNSIGNED_BYTE
, 1, 2 * 16 },
49 { GL_PALETTE4_RGB5_A1_OES
, GL_RGBA
, GL_UNSIGNED_BYTE
, 1, 2 * 16 },
50 { GL_PALETTE8_RGB8_OES
, GL_RGB
, GL_UNSIGNED_BYTE
, 0, 3 * 256 },
51 { GL_PALETTE8_RGBA8_OES
, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 4 * 256 },
52 { GL_PALETTE8_R5_G6_B5_OES
, GL_RGB
, GL_UNSIGNED_BYTE
, 0, 2 * 256 },
53 { GL_PALETTE8_RGBA4_OES
, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 2 * 256 },
54 { GL_PALETTE8_RGB5_A1_OES
, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 2 * 256 },
64 piglit_init(int argc
, char **argv
)
66 GLubyte buffer
[512 + (16 * 16)];
71 piglit_require_extension("GL_OES_compressed_paletted_texture");
73 glGenTextures(1, &tex
);
74 glBindTexture(GL_TEXTURE_2D
, tex
);
76 /* The OES_compressed_paletted_texture spec says:
78 * "INVALID_OPERATION is generated by TexImage2D,
79 * CompressedTexSubImage2D, CopyTexSubImage2D if <internalformat>
80 * is PALETTE4_RGB8_OES, PALETTE4_RGBA8_OES,
81 * PALETTE4_R5_G6_B5_OES, PALETTE4_RGBA4_OES,
82 * PALETTE4_RGB5_A1_OES, PALETTE8_RG8_OES, PALETTE8_RGBA8_OES,
83 * PALETTE8_R5_G6_B5_OES, PALETTE8_RGBA4_OES, or
84 * PALETTE8_RGB5_A1_OES."
86 * However, page 73 (page 83 of the PDF) of the OpenGL ES 1.1
89 * "Specifying a value for internalformat that is not one of the
90 * above values generates the error INVALID_VALUE. If
91 * internalformat does not match format, the error
92 * INVALID_OPERATION is generated."
94 * The OES_compressed_paletted_texture spec doesn't add any entries to
95 * table 3.8. It seems logical to expect the core behavior to take
96 * precedence over the extension error.
98 printf("Trying glTexImage2D...\n");
99 for (i
= 0; i
< ARRAY_SIZE(t
); i
++) {
100 glTexImage2D(GL_TEXTURE_2D
, 0, t
[i
].internal_format
,
102 t
[i
].internal_format
, t
[i
].type
, buffer
);
103 #if defined(PIGLIT_USE_OPENGL_ES1) || defined(PIGLIT_USE_OPENGL_ES2)
105 GLenum error
= glGetError();
106 if (error
!= GL_INVALID_VALUE
&& error
!= GL_INVALID_OPERATION
) {
107 printf("Unexpected GL error: %s 0x%x\n",
108 piglit_get_gl_error_name(error
), error
);
109 printf("(Error at %s:%u)\n", __func__
, __LINE__
);
110 printf("Expected GL error: %s 0x%x or %s 0x%x\n",
111 piglit_get_gl_error_name(GL_INVALID_VALUE
), GL_INVALID_VALUE
,
112 piglit_get_gl_error_name(GL_INVALID_OPERATION
), GL_INVALID_OPERATION
);
113 piglit_report_result(PIGLIT_FAIL
);
117 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
118 piglit_report_result(PIGLIT_FAIL
);
123 printf("Trying glCompressedTexImage2D...\n");
124 for (i
= 0; i
< ARRAY_SIZE(t
); i
++) {
125 size
= (16 * 16) >> t
[i
].shift
;
127 /* The GL_ARB_texture_compression spec says:
129 * "If the <imageSize> parameter is not consistent with
130 * the format, dimensions, and contents of the compressed
131 * image, an INVALID_VALUE error results."
133 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, t
[i
].internal_format
,
135 size
+ t
[i
].palette_size
- 1, buffer
);
136 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
137 piglit_report_result(PIGLIT_FAIL
);
139 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, t
[i
].internal_format
,
141 size
+ t
[i
].palette_size
, buffer
);
142 if (!piglit_check_gl_error(GL_NO_ERROR
))
143 piglit_report_result(PIGLIT_FAIL
);
145 /* The OES_compressed_paletted_texture spec says:
147 * "INVALID_VALUE is generated by CompressedTexImage2D if
148 * if <internalformat> is PALETTE4_RGB8_OES,
149 * PALETTE4_RGBA8_OES, PALETTE4_R5_G6_B5_OES,
150 * PALETTE4_RGBA4_OES, PALETTE4_RGB5_A1_OES,
151 * PALETTE8_RGB8_OES, PALETTE8_RGBA8_OES,
152 * PALETTE8_R5_G6_B5_OES, PALETTE8_RGBA4_OES, or
153 * PALETTE8_RGB5_A1_OES and <level> value is neither zero
154 * or a negative value."
156 size
= (8 * 8) >> t
[i
].shift
;
157 glCompressedTexImage2D(GL_TEXTURE_2D
, 1, t
[i
].internal_format
,
159 size
+ t
[i
].palette_size
, buffer
);
160 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
161 piglit_report_result(PIGLIT_FAIL
);
163 /* The OES_compressed_paletted_texture spec says:
165 * "Compressed paletted textures support only 2D images
166 * without borders. CompressedTexImage2D will produce an
167 * INVALID_OPERATION error if <border> is non-zero."
169 * However, page 74 (page 84 of the PDF) of the OpenGL ES 1.1
172 * "If the border argument to TexImage2D is not zero, then
173 * the error INVALID_VALUE is generated."
175 * Even though this is for glTexImage2D, page 78 (page 88 of
176 * the PDF) of the OpenGL ES 1.1 spec says:
178 * "The target, level, internalformat, width, height, and
179 * border parameters have the same meaning as in
182 * It seems logical to expect the core behavior to take
183 * precedence over the extension error.
185 size
= (17 * 17) >> t
[i
].shift
;
186 glCompressedTexImage2D(GL_TEXTURE_2D
, 0, t
[i
].internal_format
,
188 size
+ t
[i
].palette_size
, buffer
);
189 #if defined(PIGLIT_USE_OPENGL_ES1) || defined(PIGLIT_USE_OPENGL_ES2)
190 if (!piglit_check_gl_error(GL_INVALID_VALUE
))
191 piglit_report_result(PIGLIT_FAIL
);
193 if (!piglit_check_gl_error(GL_INVALID_OPERATION
))
194 piglit_report_result(PIGLIT_FAIL
);
199 piglit_report_result(PIGLIT_PASS
);