fefa9c441054e32ede586ff32d86e67023d7cf5f
[mesa.git] / src / mesa / main / glformats.c
1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (c) 2008-2009 VMware, Inc.
6 * Copyright (c) 2012 Intel Corporation
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26
27 #include "context.h"
28 #include "glformats.h"
29
30
31 /**
32 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
33 */
34 GLboolean
35 _mesa_type_is_packed(GLenum type)
36 {
37 switch (type) {
38 case GL_UNSIGNED_BYTE_3_3_2:
39 case GL_UNSIGNED_BYTE_2_3_3_REV:
40 case MESA_UNSIGNED_BYTE_4_4:
41 case GL_UNSIGNED_SHORT_5_6_5:
42 case GL_UNSIGNED_SHORT_5_6_5_REV:
43 case GL_UNSIGNED_SHORT_4_4_4_4:
44 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
45 case GL_UNSIGNED_SHORT_5_5_5_1:
46 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
47 case GL_UNSIGNED_INT_8_8_8_8:
48 case GL_UNSIGNED_INT_8_8_8_8_REV:
49 case GL_UNSIGNED_INT_10_10_10_2:
50 case GL_UNSIGNED_INT_2_10_10_10_REV:
51 case GL_UNSIGNED_SHORT_8_8_MESA:
52 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
53 case GL_UNSIGNED_INT_24_8_EXT:
54 case GL_UNSIGNED_INT_5_9_9_9_REV:
55 case GL_UNSIGNED_INT_10F_11F_11F_REV:
56 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
57 return GL_TRUE;
58 }
59
60 return GL_FALSE;
61 }
62
63
64 /**
65 * Get the size of a GL data type.
66 *
67 * \param type GL data type.
68 *
69 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
70 * if an invalid type enum.
71 */
72 GLint
73 _mesa_sizeof_type(GLenum type)
74 {
75 switch (type) {
76 case GL_BITMAP:
77 return 0;
78 case GL_UNSIGNED_BYTE:
79 return sizeof(GLubyte);
80 case GL_BYTE:
81 return sizeof(GLbyte);
82 case GL_UNSIGNED_SHORT:
83 return sizeof(GLushort);
84 case GL_SHORT:
85 return sizeof(GLshort);
86 case GL_UNSIGNED_INT:
87 return sizeof(GLuint);
88 case GL_INT:
89 return sizeof(GLint);
90 case GL_FLOAT:
91 return sizeof(GLfloat);
92 case GL_DOUBLE:
93 return sizeof(GLdouble);
94 case GL_HALF_FLOAT_ARB:
95 return sizeof(GLhalfARB);
96 case GL_FIXED:
97 return sizeof(GLfixed);
98 default:
99 return -1;
100 }
101 }
102
103
104 /**
105 * Same as _mesa_sizeof_type() but also accepting the packed pixel
106 * format data types.
107 */
108 GLint
109 _mesa_sizeof_packed_type(GLenum type)
110 {
111 switch (type) {
112 case GL_BITMAP:
113 return 0;
114 case GL_UNSIGNED_BYTE:
115 return sizeof(GLubyte);
116 case GL_BYTE:
117 return sizeof(GLbyte);
118 case GL_UNSIGNED_SHORT:
119 return sizeof(GLushort);
120 case GL_SHORT:
121 return sizeof(GLshort);
122 case GL_UNSIGNED_INT:
123 return sizeof(GLuint);
124 case GL_INT:
125 return sizeof(GLint);
126 case GL_HALF_FLOAT_ARB:
127 return sizeof(GLhalfARB);
128 case GL_FLOAT:
129 return sizeof(GLfloat);
130 case GL_UNSIGNED_BYTE_3_3_2:
131 case GL_UNSIGNED_BYTE_2_3_3_REV:
132 case MESA_UNSIGNED_BYTE_4_4:
133 return sizeof(GLubyte);
134 case GL_UNSIGNED_SHORT_5_6_5:
135 case GL_UNSIGNED_SHORT_5_6_5_REV:
136 case GL_UNSIGNED_SHORT_4_4_4_4:
137 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
138 case GL_UNSIGNED_SHORT_5_5_5_1:
139 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
140 case GL_UNSIGNED_SHORT_8_8_MESA:
141 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
142 return sizeof(GLushort);
143 case GL_UNSIGNED_INT_8_8_8_8:
144 case GL_UNSIGNED_INT_8_8_8_8_REV:
145 case GL_UNSIGNED_INT_10_10_10_2:
146 case GL_UNSIGNED_INT_2_10_10_10_REV:
147 case GL_UNSIGNED_INT_24_8_EXT:
148 case GL_UNSIGNED_INT_5_9_9_9_REV:
149 case GL_UNSIGNED_INT_10F_11F_11F_REV:
150 return sizeof(GLuint);
151 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
152 return 8;
153 default:
154 return -1;
155 }
156 }
157
158
159 /**
160 * Get the number of components in a pixel format.
161 *
162 * \param format pixel format.
163 *
164 * \return the number of components in the given format, or -1 if a bad format.
165 */
166 GLint
167 _mesa_components_in_format(GLenum format)
168 {
169 switch (format) {
170 case GL_COLOR_INDEX:
171 case GL_STENCIL_INDEX:
172 case GL_DEPTH_COMPONENT:
173 case GL_RED:
174 case GL_RED_INTEGER_EXT:
175 case GL_GREEN:
176 case GL_GREEN_INTEGER_EXT:
177 case GL_BLUE:
178 case GL_BLUE_INTEGER_EXT:
179 case GL_ALPHA:
180 case GL_ALPHA_INTEGER_EXT:
181 case GL_LUMINANCE:
182 case GL_LUMINANCE_INTEGER_EXT:
183 case GL_INTENSITY:
184 return 1;
185
186 case GL_LUMINANCE_ALPHA:
187 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
188 case GL_RG:
189 case GL_YCBCR_MESA:
190 case GL_DEPTH_STENCIL_EXT:
191 case GL_DUDV_ATI:
192 case GL_DU8DV8_ATI:
193 case GL_RG_INTEGER:
194 return 2;
195
196 case GL_RGB:
197 case GL_BGR:
198 case GL_RGB_INTEGER_EXT:
199 case GL_BGR_INTEGER_EXT:
200 return 3;
201
202 case GL_RGBA:
203 case GL_BGRA:
204 case GL_ABGR_EXT:
205 case GL_RGBA_INTEGER_EXT:
206 case GL_BGRA_INTEGER_EXT:
207 return 4;
208
209 default:
210 return -1;
211 }
212 }
213
214
215 /**
216 * Get the bytes per pixel of pixel format type pair.
217 *
218 * \param format pixel format.
219 * \param type pixel type.
220 *
221 * \return bytes per pixel, or -1 if a bad format or type was given.
222 */
223 GLint
224 _mesa_bytes_per_pixel(GLenum format, GLenum type)
225 {
226 GLint comps = _mesa_components_in_format(format);
227 if (comps < 0)
228 return -1;
229
230 switch (type) {
231 case GL_BITMAP:
232 return 0; /* special case */
233 case GL_BYTE:
234 case GL_UNSIGNED_BYTE:
235 return comps * sizeof(GLubyte);
236 case GL_SHORT:
237 case GL_UNSIGNED_SHORT:
238 return comps * sizeof(GLshort);
239 case GL_INT:
240 case GL_UNSIGNED_INT:
241 return comps * sizeof(GLint);
242 case GL_FLOAT:
243 return comps * sizeof(GLfloat);
244 case GL_HALF_FLOAT_ARB:
245 return comps * sizeof(GLhalfARB);
246 case GL_UNSIGNED_BYTE_3_3_2:
247 case GL_UNSIGNED_BYTE_2_3_3_REV:
248 if (format == GL_RGB || format == GL_BGR ||
249 format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
250 return sizeof(GLubyte);
251 else
252 return -1; /* error */
253 case GL_UNSIGNED_SHORT_5_6_5:
254 case GL_UNSIGNED_SHORT_5_6_5_REV:
255 if (format == GL_RGB || format == GL_BGR ||
256 format == GL_RGB_INTEGER_EXT || format == GL_BGR_INTEGER_EXT)
257 return sizeof(GLushort);
258 else
259 return -1; /* error */
260 case GL_UNSIGNED_SHORT_4_4_4_4:
261 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
262 case GL_UNSIGNED_SHORT_5_5_5_1:
263 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
264 if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
265 format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
266 return sizeof(GLushort);
267 else
268 return -1;
269 case GL_UNSIGNED_INT_8_8_8_8:
270 case GL_UNSIGNED_INT_8_8_8_8_REV:
271 case GL_UNSIGNED_INT_10_10_10_2:
272 case GL_UNSIGNED_INT_2_10_10_10_REV:
273 if (format == GL_RGBA || format == GL_BGRA || format == GL_ABGR_EXT ||
274 format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT)
275 return sizeof(GLuint);
276 else
277 return -1;
278 case GL_UNSIGNED_SHORT_8_8_MESA:
279 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
280 if (format == GL_YCBCR_MESA)
281 return sizeof(GLushort);
282 else
283 return -1;
284 case GL_UNSIGNED_INT_24_8_EXT:
285 if (format == GL_DEPTH_STENCIL_EXT)
286 return sizeof(GLuint);
287 else
288 return -1;
289 case GL_UNSIGNED_INT_5_9_9_9_REV:
290 if (format == GL_RGB)
291 return sizeof(GLuint);
292 else
293 return -1;
294 case GL_UNSIGNED_INT_10F_11F_11F_REV:
295 if (format == GL_RGB)
296 return sizeof(GLuint);
297 else
298 return -1;
299 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
300 if (format == GL_DEPTH_STENCIL)
301 return 8;
302 else
303 return -1;
304 default:
305 return -1;
306 }
307 }
308
309
310 /**
311 * Test if the given format is an integer (non-normalized) format.
312 */
313 GLboolean
314 _mesa_is_enum_format_integer(GLenum format)
315 {
316 switch (format) {
317 /* generic integer formats */
318 case GL_RED_INTEGER_EXT:
319 case GL_GREEN_INTEGER_EXT:
320 case GL_BLUE_INTEGER_EXT:
321 case GL_ALPHA_INTEGER_EXT:
322 case GL_RGB_INTEGER_EXT:
323 case GL_RGBA_INTEGER_EXT:
324 case GL_BGR_INTEGER_EXT:
325 case GL_BGRA_INTEGER_EXT:
326 case GL_LUMINANCE_INTEGER_EXT:
327 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
328 case GL_RG_INTEGER:
329 /* specific integer formats */
330 case GL_RGBA32UI_EXT:
331 case GL_RGB32UI_EXT:
332 case GL_RG32UI:
333 case GL_R32UI:
334 case GL_ALPHA32UI_EXT:
335 case GL_INTENSITY32UI_EXT:
336 case GL_LUMINANCE32UI_EXT:
337 case GL_LUMINANCE_ALPHA32UI_EXT:
338 case GL_RGBA16UI_EXT:
339 case GL_RGB16UI_EXT:
340 case GL_RG16UI:
341 case GL_R16UI:
342 case GL_ALPHA16UI_EXT:
343 case GL_INTENSITY16UI_EXT:
344 case GL_LUMINANCE16UI_EXT:
345 case GL_LUMINANCE_ALPHA16UI_EXT:
346 case GL_RGBA8UI_EXT:
347 case GL_RGB8UI_EXT:
348 case GL_RG8UI:
349 case GL_R8UI:
350 case GL_ALPHA8UI_EXT:
351 case GL_INTENSITY8UI_EXT:
352 case GL_LUMINANCE8UI_EXT:
353 case GL_LUMINANCE_ALPHA8UI_EXT:
354 case GL_RGBA32I_EXT:
355 case GL_RGB32I_EXT:
356 case GL_RG32I:
357 case GL_R32I:
358 case GL_ALPHA32I_EXT:
359 case GL_INTENSITY32I_EXT:
360 case GL_LUMINANCE32I_EXT:
361 case GL_LUMINANCE_ALPHA32I_EXT:
362 case GL_RGBA16I_EXT:
363 case GL_RGB16I_EXT:
364 case GL_RG16I:
365 case GL_R16I:
366 case GL_ALPHA16I_EXT:
367 case GL_INTENSITY16I_EXT:
368 case GL_LUMINANCE16I_EXT:
369 case GL_LUMINANCE_ALPHA16I_EXT:
370 case GL_RGBA8I_EXT:
371 case GL_RGB8I_EXT:
372 case GL_RG8I:
373 case GL_R8I:
374 case GL_ALPHA8I_EXT:
375 case GL_INTENSITY8I_EXT:
376 case GL_LUMINANCE8I_EXT:
377 case GL_LUMINANCE_ALPHA8I_EXT:
378 case GL_RGB10_A2UI:
379 return GL_TRUE;
380 default:
381 return GL_FALSE;
382 }
383 }
384
385
386 /**
387 * Test if the given type is an integer (non-normalized) format.
388 */
389 GLboolean
390 _mesa_is_type_integer(GLenum type)
391 {
392 switch (type) {
393 case GL_INT:
394 case GL_UNSIGNED_INT:
395 case GL_SHORT:
396 case GL_UNSIGNED_SHORT:
397 case GL_BYTE:
398 case GL_UNSIGNED_BYTE:
399 return GL_TRUE;
400 default:
401 return GL_FALSE;
402 }
403 }
404
405
406 /**
407 * Test if the given format or type is an integer (non-normalized) format.
408 */
409 extern GLboolean
410 _mesa_is_enum_format_or_type_integer(GLenum format, GLenum type)
411 {
412 return _mesa_is_enum_format_integer(format) || _mesa_is_type_integer(type);
413 }
414
415
416 GLboolean
417 _mesa_is_type_unsigned(GLenum type)
418 {
419 switch (type) {
420 case GL_UNSIGNED_INT:
421 case GL_UNSIGNED_INT_8_8_8_8:
422 case GL_UNSIGNED_INT_8_8_8_8_REV:
423 case GL_UNSIGNED_INT_10_10_10_2:
424 case GL_UNSIGNED_INT_2_10_10_10_REV:
425
426 case GL_UNSIGNED_SHORT:
427 case GL_UNSIGNED_SHORT_4_4_4_4:
428 case GL_UNSIGNED_SHORT_5_5_5_1:
429 case GL_UNSIGNED_SHORT_5_6_5:
430 case GL_UNSIGNED_SHORT_5_6_5_REV:
431 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
432 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
433 case GL_UNSIGNED_SHORT_8_8_MESA:
434 case GL_UNSIGNED_SHORT_8_8_REV_MESA:
435
436 case GL_UNSIGNED_BYTE:
437 case GL_UNSIGNED_BYTE_3_3_2:
438 case GL_UNSIGNED_BYTE_2_3_3_REV:
439 return GL_TRUE;
440
441 default:
442 return GL_FALSE;
443 }
444 }
445
446
447 /**
448 * Test if the given image format is a color/RGBA format (i.e., not color
449 * index, depth, stencil, etc).
450 * \param format the image format value (may by an internal texture format)
451 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
452 */
453 GLboolean
454 _mesa_is_color_format(GLenum format)
455 {
456 switch (format) {
457 case GL_RED:
458 case GL_GREEN:
459 case GL_BLUE:
460 case GL_ALPHA:
461 case GL_ALPHA4:
462 case GL_ALPHA8:
463 case GL_ALPHA12:
464 case GL_ALPHA16:
465 case 1:
466 case GL_LUMINANCE:
467 case GL_LUMINANCE4:
468 case GL_LUMINANCE8:
469 case GL_LUMINANCE12:
470 case GL_LUMINANCE16:
471 case 2:
472 case GL_LUMINANCE_ALPHA:
473 case GL_LUMINANCE4_ALPHA4:
474 case GL_LUMINANCE6_ALPHA2:
475 case GL_LUMINANCE8_ALPHA8:
476 case GL_LUMINANCE12_ALPHA4:
477 case GL_LUMINANCE12_ALPHA12:
478 case GL_LUMINANCE16_ALPHA16:
479 case GL_INTENSITY:
480 case GL_INTENSITY4:
481 case GL_INTENSITY8:
482 case GL_INTENSITY12:
483 case GL_INTENSITY16:
484 case GL_R8:
485 case GL_R16:
486 case GL_RG:
487 case GL_RG8:
488 case GL_RG16:
489 case 3:
490 case GL_RGB:
491 case GL_BGR:
492 case GL_R3_G3_B2:
493 case GL_RGB4:
494 case GL_RGB5:
495 case GL_RGB565:
496 case GL_RGB8:
497 case GL_RGB10:
498 case GL_RGB12:
499 case GL_RGB16:
500 case 4:
501 case GL_ABGR_EXT:
502 case GL_RGBA:
503 case GL_BGRA:
504 case GL_RGBA2:
505 case GL_RGBA4:
506 case GL_RGB5_A1:
507 case GL_RGBA8:
508 case GL_RGB10_A2:
509 case GL_RGBA12:
510 case GL_RGBA16:
511 /* float texture formats */
512 case GL_ALPHA16F_ARB:
513 case GL_ALPHA32F_ARB:
514 case GL_LUMINANCE16F_ARB:
515 case GL_LUMINANCE32F_ARB:
516 case GL_LUMINANCE_ALPHA16F_ARB:
517 case GL_LUMINANCE_ALPHA32F_ARB:
518 case GL_INTENSITY16F_ARB:
519 case GL_INTENSITY32F_ARB:
520 case GL_R16F:
521 case GL_R32F:
522 case GL_RG16F:
523 case GL_RG32F:
524 case GL_RGB16F_ARB:
525 case GL_RGB32F_ARB:
526 case GL_RGBA16F_ARB:
527 case GL_RGBA32F_ARB:
528 /* compressed formats */
529 case GL_COMPRESSED_ALPHA:
530 case GL_COMPRESSED_LUMINANCE:
531 case GL_COMPRESSED_LUMINANCE_ALPHA:
532 case GL_COMPRESSED_INTENSITY:
533 case GL_COMPRESSED_RED:
534 case GL_COMPRESSED_RG:
535 case GL_COMPRESSED_RGB:
536 case GL_COMPRESSED_RGBA:
537 case GL_RGB_S3TC:
538 case GL_RGB4_S3TC:
539 case GL_RGBA_S3TC:
540 case GL_RGBA4_S3TC:
541 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
542 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
543 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
544 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
545 case GL_COMPRESSED_RGB_FXT1_3DFX:
546 case GL_COMPRESSED_RGBA_FXT1_3DFX:
547 case GL_SRGB_EXT:
548 case GL_SRGB8_EXT:
549 case GL_SRGB_ALPHA_EXT:
550 case GL_SRGB8_ALPHA8_EXT:
551 case GL_SLUMINANCE_ALPHA_EXT:
552 case GL_SLUMINANCE8_ALPHA8_EXT:
553 case GL_SLUMINANCE_EXT:
554 case GL_SLUMINANCE8_EXT:
555 case GL_COMPRESSED_SRGB_EXT:
556 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
557 case GL_COMPRESSED_SRGB_ALPHA_EXT:
558 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
559 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
560 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
561 case GL_COMPRESSED_SLUMINANCE_EXT:
562 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
563 case GL_COMPRESSED_RED_RGTC1:
564 case GL_COMPRESSED_SIGNED_RED_RGTC1:
565 case GL_COMPRESSED_RG_RGTC2:
566 case GL_COMPRESSED_SIGNED_RG_RGTC2:
567 case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
568 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
569 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
570 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
571 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
572 case GL_ETC1_RGB8_OES:
573 case GL_COMPRESSED_RGB8_ETC2:
574 case GL_COMPRESSED_SRGB8_ETC2:
575 case GL_COMPRESSED_RGBA8_ETC2_EAC:
576 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
577 case GL_COMPRESSED_R11_EAC:
578 case GL_COMPRESSED_RG11_EAC:
579 case GL_COMPRESSED_SIGNED_R11_EAC:
580 case GL_COMPRESSED_SIGNED_RG11_EAC:
581 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
582 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
583 /* generic integer formats */
584 case GL_RED_INTEGER_EXT:
585 case GL_GREEN_INTEGER_EXT:
586 case GL_BLUE_INTEGER_EXT:
587 case GL_ALPHA_INTEGER_EXT:
588 case GL_RGB_INTEGER_EXT:
589 case GL_RGBA_INTEGER_EXT:
590 case GL_BGR_INTEGER_EXT:
591 case GL_BGRA_INTEGER_EXT:
592 case GL_RG_INTEGER:
593 case GL_LUMINANCE_INTEGER_EXT:
594 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
595 /* sized integer formats */
596 case GL_RGBA32UI_EXT:
597 case GL_RGB32UI_EXT:
598 case GL_RG32UI:
599 case GL_R32UI:
600 case GL_ALPHA32UI_EXT:
601 case GL_INTENSITY32UI_EXT:
602 case GL_LUMINANCE32UI_EXT:
603 case GL_LUMINANCE_ALPHA32UI_EXT:
604 case GL_RGBA16UI_EXT:
605 case GL_RGB16UI_EXT:
606 case GL_RG16UI:
607 case GL_R16UI:
608 case GL_ALPHA16UI_EXT:
609 case GL_INTENSITY16UI_EXT:
610 case GL_LUMINANCE16UI_EXT:
611 case GL_LUMINANCE_ALPHA16UI_EXT:
612 case GL_RGBA8UI_EXT:
613 case GL_RGB8UI_EXT:
614 case GL_RG8UI:
615 case GL_R8UI:
616 case GL_ALPHA8UI_EXT:
617 case GL_INTENSITY8UI_EXT:
618 case GL_LUMINANCE8UI_EXT:
619 case GL_LUMINANCE_ALPHA8UI_EXT:
620 case GL_RGBA32I_EXT:
621 case GL_RGB32I_EXT:
622 case GL_RG32I:
623 case GL_R32I:
624 case GL_ALPHA32I_EXT:
625 case GL_INTENSITY32I_EXT:
626 case GL_LUMINANCE32I_EXT:
627 case GL_LUMINANCE_ALPHA32I_EXT:
628 case GL_RGBA16I_EXT:
629 case GL_RGB16I_EXT:
630 case GL_RG16I:
631 case GL_R16I:
632 case GL_ALPHA16I_EXT:
633 case GL_INTENSITY16I_EXT:
634 case GL_LUMINANCE16I_EXT:
635 case GL_LUMINANCE_ALPHA16I_EXT:
636 case GL_RGBA8I_EXT:
637 case GL_RGB8I_EXT:
638 case GL_RG8I:
639 case GL_R8I:
640 case GL_ALPHA8I_EXT:
641 case GL_INTENSITY8I_EXT:
642 case GL_LUMINANCE8I_EXT:
643 case GL_LUMINANCE_ALPHA8I_EXT:
644 /* signed, normalized texture formats */
645 case GL_RED_SNORM:
646 case GL_R8_SNORM:
647 case GL_R16_SNORM:
648 case GL_RG_SNORM:
649 case GL_RG8_SNORM:
650 case GL_RG16_SNORM:
651 case GL_RGB_SNORM:
652 case GL_RGB8_SNORM:
653 case GL_RGB16_SNORM:
654 case GL_RGBA_SNORM:
655 case GL_RGBA8_SNORM:
656 case GL_RGBA16_SNORM:
657 case GL_ALPHA_SNORM:
658 case GL_ALPHA8_SNORM:
659 case GL_ALPHA16_SNORM:
660 case GL_LUMINANCE_SNORM:
661 case GL_LUMINANCE8_SNORM:
662 case GL_LUMINANCE16_SNORM:
663 case GL_LUMINANCE_ALPHA_SNORM:
664 case GL_LUMINANCE8_ALPHA8_SNORM:
665 case GL_LUMINANCE16_ALPHA16_SNORM:
666 case GL_INTENSITY_SNORM:
667 case GL_INTENSITY8_SNORM:
668 case GL_INTENSITY16_SNORM:
669 case GL_RGB9_E5:
670 case GL_R11F_G11F_B10F:
671 case GL_RGB10_A2UI:
672 return GL_TRUE;
673 case GL_YCBCR_MESA: /* not considered to be RGB */
674 /* fall-through */
675 default:
676 return GL_FALSE;
677 }
678 }
679
680
681 /**
682 * Test if the given image format is a depth component format.
683 */
684 GLboolean
685 _mesa_is_depth_format(GLenum format)
686 {
687 switch (format) {
688 case GL_DEPTH_COMPONENT:
689 case GL_DEPTH_COMPONENT16:
690 case GL_DEPTH_COMPONENT24:
691 case GL_DEPTH_COMPONENT32:
692 case GL_DEPTH_COMPONENT32F:
693 return GL_TRUE;
694 default:
695 return GL_FALSE;
696 }
697 }
698
699
700 /**
701 * Test if the given image format is a stencil format.
702 */
703 GLboolean
704 _mesa_is_stencil_format(GLenum format)
705 {
706 switch (format) {
707 case GL_STENCIL_INDEX:
708 return GL_TRUE;
709 default:
710 return GL_FALSE;
711 }
712 }
713
714
715 /**
716 * Test if the given image format is a YCbCr format.
717 */
718 GLboolean
719 _mesa_is_ycbcr_format(GLenum format)
720 {
721 switch (format) {
722 case GL_YCBCR_MESA:
723 return GL_TRUE;
724 default:
725 return GL_FALSE;
726 }
727 }
728
729
730 /**
731 * Test if the given image format is a depth+stencil format.
732 */
733 GLboolean
734 _mesa_is_depthstencil_format(GLenum format)
735 {
736 switch (format) {
737 case GL_DEPTH24_STENCIL8_EXT:
738 case GL_DEPTH_STENCIL_EXT:
739 case GL_DEPTH32F_STENCIL8:
740 return GL_TRUE;
741 default:
742 return GL_FALSE;
743 }
744 }
745
746
747 /**
748 * Test if the given image format is a depth or stencil format.
749 */
750 GLboolean
751 _mesa_is_depth_or_stencil_format(GLenum format)
752 {
753 switch (format) {
754 case GL_DEPTH_COMPONENT:
755 case GL_DEPTH_COMPONENT16:
756 case GL_DEPTH_COMPONENT24:
757 case GL_DEPTH_COMPONENT32:
758 case GL_STENCIL_INDEX:
759 case GL_STENCIL_INDEX1_EXT:
760 case GL_STENCIL_INDEX4_EXT:
761 case GL_STENCIL_INDEX8_EXT:
762 case GL_STENCIL_INDEX16_EXT:
763 case GL_DEPTH_STENCIL_EXT:
764 case GL_DEPTH24_STENCIL8_EXT:
765 case GL_DEPTH_COMPONENT32F:
766 case GL_DEPTH32F_STENCIL8:
767 return GL_TRUE;
768 default:
769 return GL_FALSE;
770 }
771 }
772
773
774 /**
775 * Test if the given image format is a dudv format.
776 */
777 GLboolean
778 _mesa_is_dudv_format(GLenum format)
779 {
780 switch (format) {
781 case GL_DUDV_ATI:
782 case GL_DU8DV8_ATI:
783 return GL_TRUE;
784 default:
785 return GL_FALSE;
786 }
787 }
788
789
790 /**
791 * Test if an image format is a supported compressed format.
792 * \param format the internal format token provided by the user.
793 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
794 */
795 GLboolean
796 _mesa_is_compressed_format(struct gl_context *ctx, GLenum format)
797 {
798 switch (format) {
799 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
800 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
801 return ctx->Extensions.EXT_texture_compression_s3tc;
802 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
803 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
804 return (_mesa_is_desktop_gl(ctx) &&
805 ctx->Extensions.EXT_texture_compression_s3tc) ||
806 (ctx->API == API_OPENGLES2 &&
807 ctx->Extensions.ANGLE_texture_compression_dxt);
808 case GL_RGB_S3TC:
809 case GL_RGB4_S3TC:
810 case GL_RGBA_S3TC:
811 case GL_RGBA4_S3TC:
812 return _mesa_is_desktop_gl(ctx) && ctx->Extensions.S3_s3tc;
813 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
814 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
815 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
816 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
817 return _mesa_is_desktop_gl(ctx)
818 && ctx->Extensions.EXT_texture_sRGB
819 && ctx->Extensions.EXT_texture_compression_s3tc;
820 case GL_COMPRESSED_RGB_FXT1_3DFX:
821 case GL_COMPRESSED_RGBA_FXT1_3DFX:
822 return _mesa_is_desktop_gl(ctx)
823 && ctx->Extensions.TDFX_texture_compression_FXT1;
824 case GL_COMPRESSED_RED_RGTC1:
825 case GL_COMPRESSED_SIGNED_RED_RGTC1:
826 case GL_COMPRESSED_RG_RGTC2:
827 case GL_COMPRESSED_SIGNED_RG_RGTC2:
828 return _mesa_is_desktop_gl(ctx)
829 && ctx->Extensions.ARB_texture_compression_rgtc;
830 case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
831 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
832 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
833 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
834 return ctx->API == API_OPENGL_COMPAT
835 && ctx->Extensions.EXT_texture_compression_latc;
836 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
837 return ctx->API == API_OPENGL_COMPAT
838 && ctx->Extensions.ATI_texture_compression_3dc;
839 case GL_ETC1_RGB8_OES:
840 return _mesa_is_gles(ctx)
841 && ctx->Extensions.OES_compressed_ETC1_RGB8_texture;
842 case GL_COMPRESSED_RGB8_ETC2:
843 case GL_COMPRESSED_SRGB8_ETC2:
844 case GL_COMPRESSED_RGBA8_ETC2_EAC:
845 case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
846 case GL_COMPRESSED_R11_EAC:
847 case GL_COMPRESSED_RG11_EAC:
848 case GL_COMPRESSED_SIGNED_R11_EAC:
849 case GL_COMPRESSED_SIGNED_RG11_EAC:
850 case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
851 case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
852 return _mesa_is_gles3(ctx);
853 case GL_PALETTE4_RGB8_OES:
854 case GL_PALETTE4_RGBA8_OES:
855 case GL_PALETTE4_R5_G6_B5_OES:
856 case GL_PALETTE4_RGBA4_OES:
857 case GL_PALETTE4_RGB5_A1_OES:
858 case GL_PALETTE8_RGB8_OES:
859 case GL_PALETTE8_RGBA8_OES:
860 case GL_PALETTE8_R5_G6_B5_OES:
861 case GL_PALETTE8_RGBA4_OES:
862 case GL_PALETTE8_RGB5_A1_OES:
863 return ctx->API == API_OPENGLES;
864 default:
865 return GL_FALSE;
866 }
867 }
868
869
870 /**
871 * Convert various base formats to the cooresponding integer format.
872 */
873 GLenum
874 _mesa_base_format_to_integer_format(GLenum format)
875 {
876 switch(format) {
877 case GL_RED:
878 return GL_RED_INTEGER;
879 case GL_GREEN:
880 return GL_GREEN_INTEGER;
881 case GL_BLUE:
882 return GL_BLUE_INTEGER;
883 case GL_RG:
884 return GL_RG_INTEGER;
885 case GL_RGB:
886 return GL_RGB_INTEGER;
887 case GL_RGBA:
888 return GL_RGBA_INTEGER;
889 case GL_BGR:
890 return GL_BGR_INTEGER;
891 case GL_BGRA:
892 return GL_BGRA_INTEGER;
893 case GL_ALPHA:
894 return GL_ALPHA_INTEGER;
895 case GL_LUMINANCE:
896 return GL_LUMINANCE_INTEGER_EXT;
897 case GL_LUMINANCE_ALPHA:
898 return GL_LUMINANCE_ALPHA_INTEGER_EXT;
899 }
900
901 return format;
902 }
903
904
905 /**
906 * Does the given base texture/renderbuffer format have the channel
907 * named by 'pname'?
908 */
909 GLboolean
910 _mesa_base_format_has_channel(GLenum base_format, GLenum pname)
911 {
912 switch (pname) {
913 case GL_TEXTURE_RED_SIZE:
914 case GL_TEXTURE_RED_TYPE:
915 case GL_RENDERBUFFER_RED_SIZE_EXT:
916 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
917 if (base_format == GL_RED ||
918 base_format == GL_RG ||
919 base_format == GL_RGB ||
920 base_format == GL_RGBA) {
921 return GL_TRUE;
922 }
923 return GL_FALSE;
924 case GL_TEXTURE_GREEN_SIZE:
925 case GL_TEXTURE_GREEN_TYPE:
926 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
927 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
928 if (base_format == GL_RG ||
929 base_format == GL_RGB ||
930 base_format == GL_RGBA) {
931 return GL_TRUE;
932 }
933 return GL_FALSE;
934 case GL_TEXTURE_BLUE_SIZE:
935 case GL_TEXTURE_BLUE_TYPE:
936 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
937 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
938 if (base_format == GL_RGB ||
939 base_format == GL_RGBA) {
940 return GL_TRUE;
941 }
942 return GL_FALSE;
943 case GL_TEXTURE_ALPHA_SIZE:
944 case GL_TEXTURE_ALPHA_TYPE:
945 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
946 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
947 if (base_format == GL_RGBA ||
948 base_format == GL_ALPHA ||
949 base_format == GL_LUMINANCE_ALPHA) {
950 return GL_TRUE;
951 }
952 return GL_FALSE;
953 case GL_TEXTURE_LUMINANCE_SIZE:
954 case GL_TEXTURE_LUMINANCE_TYPE:
955 if (base_format == GL_LUMINANCE ||
956 base_format == GL_LUMINANCE_ALPHA) {
957 return GL_TRUE;
958 }
959 return GL_FALSE;
960 case GL_TEXTURE_INTENSITY_SIZE:
961 case GL_TEXTURE_INTENSITY_TYPE:
962 if (base_format == GL_INTENSITY) {
963 return GL_TRUE;
964 }
965 return GL_FALSE;
966 case GL_TEXTURE_DEPTH_SIZE:
967 case GL_TEXTURE_DEPTH_TYPE:
968 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
969 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
970 if (base_format == GL_DEPTH_STENCIL ||
971 base_format == GL_DEPTH_COMPONENT) {
972 return GL_TRUE;
973 }
974 return GL_FALSE;
975 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
976 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
977 if (base_format == GL_DEPTH_STENCIL ||
978 base_format == GL_STENCIL_INDEX) {
979 return GL_TRUE;
980 }
981 return GL_FALSE;
982 default:
983 _mesa_warning(NULL, "%s: Unexpected channel token 0x%x\n",
984 __FUNCTION__, pname);
985 return GL_FALSE;
986 }
987
988 return GL_FALSE;
989 }
990
991
992 /**
993 * If format is a generic compressed format, return the corresponding
994 * non-compressed format. For other formats, return the format as-is.
995 */
996 GLenum
997 _mesa_generic_compressed_format_to_uncompressed_format(GLenum format)
998 {
999 switch (format) {
1000 case GL_COMPRESSED_RED:
1001 return GL_RED;
1002 case GL_COMPRESSED_RG:
1003 return GL_RG;
1004 case GL_COMPRESSED_RGB:
1005 return GL_RGB;
1006 case GL_COMPRESSED_RGBA:
1007 return GL_RGBA;
1008 case GL_COMPRESSED_ALPHA:
1009 return GL_ALPHA;
1010 case GL_COMPRESSED_LUMINANCE:
1011 return GL_LUMINANCE;
1012 case GL_COMPRESSED_LUMINANCE_ALPHA:
1013 return GL_LUMINANCE_ALPHA;
1014 case GL_COMPRESSED_INTENSITY:
1015 return GL_INTENSITY;
1016 /* sRGB formats */
1017 case GL_COMPRESSED_SRGB:
1018 return GL_SRGB;
1019 case GL_COMPRESSED_SRGB_ALPHA:
1020 return GL_SRGB_ALPHA;
1021 case GL_COMPRESSED_SLUMINANCE:
1022 return GL_SLUMINANCE;
1023 case GL_COMPRESSED_SLUMINANCE_ALPHA:
1024 return GL_SLUMINANCE_ALPHA;
1025 default:
1026 return format;
1027 }
1028 }
1029
1030
1031 /**
1032 * Return the equivalent non-generic internal format.
1033 * This is useful for comparing whether two internal formats are equivalent.
1034 */
1035 GLenum
1036 _mesa_get_nongeneric_internalformat(GLenum format)
1037 {
1038 switch (format) {
1039 /* GL 1.1 formats. */
1040 case 4:
1041 case GL_RGBA:
1042 return GL_RGBA8;
1043
1044 case 3:
1045 case GL_RGB:
1046 return GL_RGB8;
1047
1048 case 2:
1049 case GL_LUMINANCE_ALPHA:
1050 return GL_LUMINANCE8_ALPHA8;
1051
1052 case 1:
1053 case GL_LUMINANCE:
1054 return GL_LUMINANCE8;
1055
1056 case GL_ALPHA:
1057 return GL_ALPHA8;
1058
1059 case GL_INTENSITY:
1060 return GL_INTENSITY8;
1061
1062 /* GL_ARB_texture_rg */
1063 case GL_RED:
1064 return GL_R8;
1065
1066 case GL_RG:
1067 return GL_RG8;
1068
1069 /* GL_EXT_texture_sRGB */
1070 case GL_SRGB:
1071 return GL_SRGB8;
1072
1073 case GL_SRGB_ALPHA:
1074 return GL_SRGB8_ALPHA8;
1075
1076 case GL_SLUMINANCE:
1077 return GL_SLUMINANCE8;
1078
1079 case GL_SLUMINANCE_ALPHA:
1080 return GL_SLUMINANCE8_ALPHA8;
1081
1082 /* GL_EXT_texture_snorm */
1083 case GL_RGBA_SNORM:
1084 return GL_RGBA8_SNORM;
1085
1086 case GL_RGB_SNORM:
1087 return GL_RGB8_SNORM;
1088
1089 case GL_RG_SNORM:
1090 return GL_RG8_SNORM;
1091
1092 case GL_RED_SNORM:
1093 return GL_R8_SNORM;
1094
1095 case GL_LUMINANCE_ALPHA_SNORM:
1096 return GL_LUMINANCE8_ALPHA8_SNORM;
1097
1098 case GL_LUMINANCE_SNORM:
1099 return GL_LUMINANCE8_SNORM;
1100
1101 case GL_ALPHA_SNORM:
1102 return GL_ALPHA8_SNORM;
1103
1104 case GL_INTENSITY_SNORM:
1105 return GL_INTENSITY8_SNORM;
1106
1107 default:
1108 return format;
1109 }
1110 }
1111
1112
1113 /**
1114 * Convert an sRGB internal format to linear.
1115 */
1116 GLenum
1117 _mesa_get_linear_internalformat(GLenum format)
1118 {
1119 switch (format) {
1120 case GL_SRGB:
1121 return GL_RGB;
1122
1123 case GL_SRGB_ALPHA:
1124 return GL_RGBA;
1125
1126 case GL_SRGB8:
1127 return GL_RGB8;
1128
1129 case GL_SRGB8_ALPHA8:
1130 return GL_RGBA8;
1131
1132 case GL_SLUMINANCE:
1133 return GL_LUMINANCE8;
1134
1135 case GL_SLUMINANCE_ALPHA:
1136 return GL_LUMINANCE8_ALPHA8;
1137
1138 default:
1139 return format;
1140 }
1141 }
1142
1143
1144 /**
1145 * Do error checking of format/type combinations for glReadPixels,
1146 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
1147 * and type values, we may either generate GL_INVALID_OPERATION or
1148 * GL_INVALID_ENUM.
1149 *
1150 * \param format pixel format.
1151 * \param type pixel type.
1152 *
1153 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
1154 */
1155 GLenum
1156 _mesa_error_check_format_and_type(const struct gl_context *ctx,
1157 GLenum format, GLenum type)
1158 {
1159 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
1160 switch (type) {
1161 case GL_BITMAP:
1162 if (format != GL_COLOR_INDEX && format != GL_STENCIL_INDEX) {
1163 return GL_INVALID_ENUM;
1164 }
1165 break;
1166
1167 case GL_UNSIGNED_BYTE_3_3_2:
1168 case GL_UNSIGNED_BYTE_2_3_3_REV:
1169 case GL_UNSIGNED_SHORT_5_6_5:
1170 case GL_UNSIGNED_SHORT_5_6_5_REV:
1171 if (format == GL_RGB) {
1172 break; /* OK */
1173 }
1174 if (format == GL_RGB_INTEGER_EXT &&
1175 ctx->Extensions.ARB_texture_rgb10_a2ui) {
1176 break; /* OK */
1177 }
1178 return GL_INVALID_OPERATION;
1179
1180 case GL_UNSIGNED_SHORT_4_4_4_4:
1181 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
1182 case GL_UNSIGNED_SHORT_5_5_5_1:
1183 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
1184 case GL_UNSIGNED_INT_8_8_8_8:
1185 case GL_UNSIGNED_INT_8_8_8_8_REV:
1186 case GL_UNSIGNED_INT_10_10_10_2:
1187 case GL_UNSIGNED_INT_2_10_10_10_REV:
1188 if (format == GL_RGBA ||
1189 format == GL_BGRA ||
1190 format == GL_ABGR_EXT) {
1191 break; /* OK */
1192 }
1193 if ((format == GL_RGBA_INTEGER_EXT || format == GL_BGRA_INTEGER_EXT) &&
1194 ctx->Extensions.ARB_texture_rgb10_a2ui) {
1195 break; /* OK */
1196 }
1197 return GL_INVALID_OPERATION;
1198
1199 case GL_UNSIGNED_INT_24_8:
1200 if (!ctx->Extensions.EXT_packed_depth_stencil) {
1201 return GL_INVALID_ENUM;
1202 }
1203 if (format != GL_DEPTH_STENCIL) {
1204 return GL_INVALID_OPERATION;
1205 }
1206 return GL_NO_ERROR;
1207
1208 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
1209 if (!ctx->Extensions.ARB_depth_buffer_float) {
1210 return GL_INVALID_ENUM;
1211 }
1212 if (format != GL_DEPTH_STENCIL) {
1213 return GL_INVALID_OPERATION;
1214 }
1215 return GL_NO_ERROR;
1216
1217 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1218 if (!ctx->Extensions.EXT_packed_float) {
1219 return GL_INVALID_ENUM;
1220 }
1221 if (format != GL_RGB) {
1222 return GL_INVALID_OPERATION;
1223 }
1224 return GL_NO_ERROR;
1225
1226 default:
1227 ; /* fall-through */
1228 }
1229
1230 /* now, for each format, check the type for compatibility */
1231 switch (format) {
1232 case GL_COLOR_INDEX:
1233 case GL_STENCIL_INDEX:
1234 switch (type) {
1235 case GL_BITMAP:
1236 case GL_BYTE:
1237 case GL_UNSIGNED_BYTE:
1238 case GL_SHORT:
1239 case GL_UNSIGNED_SHORT:
1240 case GL_INT:
1241 case GL_UNSIGNED_INT:
1242 case GL_FLOAT:
1243 return GL_NO_ERROR;
1244 case GL_HALF_FLOAT:
1245 return ctx->Extensions.ARB_half_float_pixel
1246 ? GL_NO_ERROR : GL_INVALID_ENUM;
1247 default:
1248 return GL_INVALID_ENUM;
1249 }
1250
1251 case GL_RED:
1252 case GL_GREEN:
1253 case GL_BLUE:
1254 case GL_ALPHA:
1255 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
1256 case GL_INTENSITY:
1257 #endif
1258 case GL_LUMINANCE:
1259 case GL_LUMINANCE_ALPHA:
1260 case GL_DEPTH_COMPONENT:
1261 switch (type) {
1262 case GL_BYTE:
1263 case GL_UNSIGNED_BYTE:
1264 case GL_SHORT:
1265 case GL_UNSIGNED_SHORT:
1266 case GL_INT:
1267 case GL_UNSIGNED_INT:
1268 case GL_FLOAT:
1269 return GL_NO_ERROR;
1270 case GL_HALF_FLOAT:
1271 return ctx->Extensions.ARB_half_float_pixel
1272 ? GL_NO_ERROR : GL_INVALID_ENUM;
1273 default:
1274 return GL_INVALID_ENUM;
1275 }
1276
1277 case GL_RG:
1278 if (!ctx->Extensions.ARB_texture_rg)
1279 return GL_INVALID_ENUM;
1280 switch (type) {
1281 case GL_BYTE:
1282 case GL_UNSIGNED_BYTE:
1283 case GL_SHORT:
1284 case GL_UNSIGNED_SHORT:
1285 case GL_INT:
1286 case GL_UNSIGNED_INT:
1287 case GL_FLOAT:
1288 return GL_NO_ERROR;
1289 case GL_HALF_FLOAT:
1290 return ctx->Extensions.ARB_half_float_pixel
1291 ? GL_NO_ERROR : GL_INVALID_ENUM;
1292 default:
1293 return GL_INVALID_ENUM;
1294 }
1295
1296 case GL_RGB:
1297 switch (type) {
1298 case GL_BYTE:
1299 case GL_UNSIGNED_BYTE:
1300 case GL_SHORT:
1301 case GL_UNSIGNED_SHORT:
1302 case GL_INT:
1303 case GL_UNSIGNED_INT:
1304 case GL_FLOAT:
1305 case GL_UNSIGNED_BYTE_3_3_2:
1306 case GL_UNSIGNED_BYTE_2_3_3_REV:
1307 case GL_UNSIGNED_SHORT_5_6_5:
1308 case GL_UNSIGNED_SHORT_5_6_5_REV:
1309 return GL_NO_ERROR;
1310 case GL_HALF_FLOAT:
1311 return ctx->Extensions.ARB_half_float_pixel
1312 ? GL_NO_ERROR : GL_INVALID_ENUM;
1313 case GL_UNSIGNED_INT_5_9_9_9_REV:
1314 return ctx->Extensions.EXT_texture_shared_exponent
1315 ? GL_NO_ERROR : GL_INVALID_ENUM;
1316 case GL_UNSIGNED_INT_10F_11F_11F_REV:
1317 return ctx->Extensions.EXT_packed_float
1318 ? GL_NO_ERROR : GL_INVALID_ENUM;
1319 default:
1320 return GL_INVALID_ENUM;
1321 }
1322
1323 case GL_BGR:
1324 switch (type) {
1325 /* NOTE: no packed types are supported with BGR. That's
1326 * intentional, according to the GL spec.
1327 */
1328 case GL_BYTE:
1329 case GL_UNSIGNED_BYTE:
1330 case GL_SHORT:
1331 case GL_UNSIGNED_SHORT:
1332 case GL_INT:
1333 case GL_UNSIGNED_INT:
1334 case GL_FLOAT:
1335 return GL_NO_ERROR;
1336 case GL_HALF_FLOAT:
1337 return ctx->Extensions.ARB_half_float_pixel
1338 ? GL_NO_ERROR : GL_INVALID_ENUM;
1339 default:
1340 return GL_INVALID_ENUM;
1341 }
1342
1343 case GL_RGBA:
1344 case GL_BGRA:
1345 case GL_ABGR_EXT:
1346 switch (type) {
1347 case GL_BYTE:
1348 case GL_UNSIGNED_BYTE:
1349 case GL_SHORT:
1350 case GL_UNSIGNED_SHORT:
1351 case GL_INT:
1352 case GL_UNSIGNED_INT:
1353 case GL_FLOAT:
1354 case GL_UNSIGNED_SHORT_4_4_4_4:
1355 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
1356 case GL_UNSIGNED_SHORT_5_5_5_1:
1357 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
1358 case GL_UNSIGNED_INT_8_8_8_8:
1359 case GL_UNSIGNED_INT_8_8_8_8_REV:
1360 case GL_UNSIGNED_INT_10_10_10_2:
1361 case GL_UNSIGNED_INT_2_10_10_10_REV:
1362 return GL_NO_ERROR;
1363 case GL_HALF_FLOAT:
1364 return ctx->Extensions.ARB_half_float_pixel
1365 ? GL_NO_ERROR : GL_INVALID_ENUM;
1366 default:
1367 return GL_INVALID_ENUM;
1368 }
1369
1370 case GL_YCBCR_MESA:
1371 if (!ctx->Extensions.MESA_ycbcr_texture)
1372 return GL_INVALID_ENUM;
1373 if (type == GL_UNSIGNED_SHORT_8_8_MESA ||
1374 type == GL_UNSIGNED_SHORT_8_8_REV_MESA)
1375 return GL_NO_ERROR;
1376 else
1377 return GL_INVALID_OPERATION;
1378
1379 case GL_DEPTH_STENCIL_EXT:
1380 if (ctx->Extensions.EXT_packed_depth_stencil &&
1381 type == GL_UNSIGNED_INT_24_8)
1382 return GL_NO_ERROR;
1383 else if (ctx->Extensions.ARB_depth_buffer_float &&
1384 type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV)
1385 return GL_NO_ERROR;
1386 else
1387 return GL_INVALID_ENUM;
1388
1389 case GL_DUDV_ATI:
1390 case GL_DU8DV8_ATI:
1391 if (!ctx->Extensions.ATI_envmap_bumpmap)
1392 return GL_INVALID_ENUM;
1393 switch (type) {
1394 case GL_BYTE:
1395 case GL_UNSIGNED_BYTE:
1396 case GL_SHORT:
1397 case GL_UNSIGNED_SHORT:
1398 case GL_INT:
1399 case GL_UNSIGNED_INT:
1400 case GL_FLOAT:
1401 return GL_NO_ERROR;
1402 default:
1403 return GL_INVALID_ENUM;
1404 }
1405
1406 /* integer-valued formats */
1407 case GL_RED_INTEGER_EXT:
1408 case GL_GREEN_INTEGER_EXT:
1409 case GL_BLUE_INTEGER_EXT:
1410 case GL_ALPHA_INTEGER_EXT:
1411 case GL_RG_INTEGER:
1412 switch (type) {
1413 case GL_BYTE:
1414 case GL_UNSIGNED_BYTE:
1415 case GL_SHORT:
1416 case GL_UNSIGNED_SHORT:
1417 case GL_INT:
1418 case GL_UNSIGNED_INT:
1419 return (ctx->Version >= 30 ||
1420 ctx->Extensions.EXT_texture_integer)
1421 ? GL_NO_ERROR : GL_INVALID_ENUM;
1422 default:
1423 return GL_INVALID_ENUM;
1424 }
1425
1426 case GL_RGB_INTEGER_EXT:
1427 switch (type) {
1428 case GL_BYTE:
1429 case GL_UNSIGNED_BYTE:
1430 case GL_SHORT:
1431 case GL_UNSIGNED_SHORT:
1432 case GL_INT:
1433 case GL_UNSIGNED_INT:
1434 return (ctx->Version >= 30 ||
1435 ctx->Extensions.EXT_texture_integer)
1436 ? GL_NO_ERROR : GL_INVALID_ENUM;
1437 case GL_UNSIGNED_BYTE_3_3_2:
1438 case GL_UNSIGNED_BYTE_2_3_3_REV:
1439 case GL_UNSIGNED_SHORT_5_6_5:
1440 case GL_UNSIGNED_SHORT_5_6_5_REV:
1441 return ctx->Extensions.ARB_texture_rgb10_a2ui
1442 ? GL_NO_ERROR : GL_INVALID_ENUM;
1443 default:
1444 return GL_INVALID_ENUM;
1445 }
1446
1447 case GL_BGR_INTEGER_EXT:
1448 switch (type) {
1449 case GL_BYTE:
1450 case GL_UNSIGNED_BYTE:
1451 case GL_SHORT:
1452 case GL_UNSIGNED_SHORT:
1453 case GL_INT:
1454 case GL_UNSIGNED_INT:
1455 /* NOTE: no packed formats w/ BGR format */
1456 return (ctx->Version >= 30 ||
1457 ctx->Extensions.EXT_texture_integer)
1458 ? GL_NO_ERROR : GL_INVALID_ENUM;
1459 default:
1460 return GL_INVALID_ENUM;
1461 }
1462
1463 case GL_RGBA_INTEGER_EXT:
1464 case GL_BGRA_INTEGER_EXT:
1465 switch (type) {
1466 case GL_BYTE:
1467 case GL_UNSIGNED_BYTE:
1468 case GL_SHORT:
1469 case GL_UNSIGNED_SHORT:
1470 case GL_INT:
1471 case GL_UNSIGNED_INT:
1472 return (ctx->Version >= 30 ||
1473 ctx->Extensions.EXT_texture_integer)
1474 ? GL_NO_ERROR : GL_INVALID_ENUM;
1475 case GL_UNSIGNED_SHORT_4_4_4_4:
1476 case GL_UNSIGNED_SHORT_4_4_4_4_REV:
1477 case GL_UNSIGNED_SHORT_5_5_5_1:
1478 case GL_UNSIGNED_SHORT_1_5_5_5_REV:
1479 case GL_UNSIGNED_INT_8_8_8_8:
1480 case GL_UNSIGNED_INT_8_8_8_8_REV:
1481 case GL_UNSIGNED_INT_10_10_10_2:
1482 case GL_UNSIGNED_INT_2_10_10_10_REV:
1483 return ctx->Extensions.ARB_texture_rgb10_a2ui
1484 ? GL_NO_ERROR : GL_INVALID_ENUM;
1485 default:
1486 return GL_INVALID_ENUM;
1487 }
1488
1489 case GL_LUMINANCE_INTEGER_EXT:
1490 case GL_LUMINANCE_ALPHA_INTEGER_EXT:
1491 switch (type) {
1492 case GL_BYTE:
1493 case GL_UNSIGNED_BYTE:
1494 case GL_SHORT:
1495 case GL_UNSIGNED_SHORT:
1496 case GL_INT:
1497 case GL_UNSIGNED_INT:
1498 return ctx->Extensions.EXT_texture_integer
1499 ? GL_NO_ERROR : GL_INVALID_ENUM;
1500 default:
1501 return GL_INVALID_ENUM;
1502 }
1503
1504 default:
1505 return GL_INVALID_ENUM;
1506 }
1507 return GL_NO_ERROR;
1508 }
1509
1510
1511 /**
1512 * Do error checking of format/type combinations for OpenGL ES glReadPixels
1513 * and glTex[Sub]Image.
1514 * \return error code, or GL_NO_ERROR.
1515 */
1516 GLenum
1517 _mesa_es_error_check_format_and_type(GLenum format, GLenum type,
1518 unsigned dimensions)
1519 {
1520 GLboolean type_valid = GL_TRUE;
1521
1522 switch (format) {
1523 case GL_ALPHA:
1524 case GL_LUMINANCE:
1525 case GL_LUMINANCE_ALPHA:
1526 type_valid = (type == GL_UNSIGNED_BYTE
1527 || type == GL_FLOAT
1528 || type == GL_HALF_FLOAT_OES);
1529 break;
1530
1531 case GL_RGB:
1532 type_valid = (type == GL_UNSIGNED_BYTE
1533 || type == GL_UNSIGNED_SHORT_5_6_5
1534 || type == GL_FLOAT
1535 || type == GL_HALF_FLOAT_OES);
1536 break;
1537
1538 case GL_RGBA:
1539 type_valid = (type == GL_UNSIGNED_BYTE
1540 || type == GL_UNSIGNED_SHORT_4_4_4_4
1541 || type == GL_UNSIGNED_SHORT_5_5_5_1
1542 || type == GL_FLOAT
1543 || type == GL_HALF_FLOAT_OES
1544 || type == GL_UNSIGNED_INT_2_10_10_10_REV);
1545 break;
1546
1547 case GL_DEPTH_COMPONENT:
1548 /* This format is filtered against invalid dimensionalities elsewhere.
1549 */
1550 type_valid = (type == GL_UNSIGNED_SHORT
1551 || type == GL_UNSIGNED_INT);
1552 break;
1553
1554 case GL_DEPTH_STENCIL:
1555 /* This format is filtered against invalid dimensionalities elsewhere.
1556 */
1557 type_valid = (type == GL_UNSIGNED_INT_24_8);
1558 break;
1559
1560 case GL_BGRA_EXT:
1561 type_valid = (type == GL_UNSIGNED_BYTE);
1562
1563 /* This feels like a bug in the EXT_texture_format_BGRA8888 spec, but
1564 * the format does not appear to be allowed for 3D textures in OpenGL
1565 * ES.
1566 */
1567 if (dimensions != 2)
1568 return GL_INVALID_VALUE;
1569
1570 break;
1571
1572 default:
1573 return GL_INVALID_VALUE;
1574 }
1575
1576 return type_valid ? GL_NO_ERROR : GL_INVALID_OPERATION;
1577 }