2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
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:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
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 * BRIAN PAUL 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.
34 * Information about texture formats.
41 * Base format is one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE,
42 * GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_COLOR_INDEX, GL_DEPTH_COMPONENT.
47 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
48 * GL_UNSIGNED_INT, GL_SIGNED_INT, GL_FLOAT.
56 GLubyte LuminanceBits
;
57 GLubyte IntensityBits
;
63 * To describe compressed formats. If not compressed, Width=Height=1.
65 GLubyte BlockWidth
, BlockHeight
;
66 GLubyte BytesPerBlock
;
71 * Info about each format.
72 * These must be in the same order as the MESA_FORMAT_* enums so that
73 * we can do lookups without searching.
75 static struct gl_format_info format_info
[MESA_FORMAT_COUNT
] =
78 MESA_FORMAT_NONE
, /* Name */
79 GL_NONE
, /* BaseFormat */
80 GL_NONE
, /* DataType */
81 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
82 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
83 0, 0, 0 /* BlockWidth/Height,Bytes */
86 MESA_FORMAT_RGBA8888
, /* Name */
87 GL_RGBA
, /* BaseFormat */
88 GL_UNSIGNED_NORMALIZED
, /* DataType */
89 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
90 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
91 1, 1, 4 /* BlockWidth/Height,Bytes */
94 MESA_FORMAT_RGBA8888_REV
, /* Name */
95 GL_RGBA
, /* BaseFormat */
96 GL_UNSIGNED_NORMALIZED
, /* DataType */
97 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
98 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
99 1, 1, 4 /* BlockWidth/Height,Bytes */
102 MESA_FORMAT_ARGB8888
, /* Name */
103 GL_RGBA
, /* BaseFormat */
104 GL_UNSIGNED_NORMALIZED
, /* DataType */
105 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
106 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
107 1, 1, 4 /* BlockWidth/Height,Bytes */
110 MESA_FORMAT_ARGB8888_REV
, /* Name */
111 GL_RGBA
, /* BaseFormat */
112 GL_UNSIGNED_NORMALIZED
, /* DataType */
113 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
114 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
115 1, 1, 4 /* BlockWidth/Height,Bytes */
118 MESA_FORMAT_RGB888
, /* Name */
119 GL_RGB
, /* BaseFormat */
120 GL_UNSIGNED_NORMALIZED
, /* DataType */
121 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
122 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
123 1, 1, 3 /* BlockWidth/Height,Bytes */
126 MESA_FORMAT_BGR888
, /* Name */
127 GL_RGB
, /* BaseFormat */
128 GL_UNSIGNED_NORMALIZED
, /* DataType */
129 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
130 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
131 1, 1, 3 /* BlockWidth/Height,Bytes */
134 MESA_FORMAT_RGB565
, /* Name */
135 GL_RGB
, /* BaseFormat */
136 GL_UNSIGNED_NORMALIZED
, /* DataType */
137 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
138 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
139 1, 1, 2 /* BlockWidth/Height,Bytes */
142 MESA_FORMAT_RGB565_REV
, /* Name */
143 GL_RGB
, /* BaseFormat */
144 GL_UNSIGNED_NORMALIZED
, /* DataType */
145 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
146 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
147 1, 1, 2 /* BlockWidth/Height,Bytes */
150 MESA_FORMAT_ARGB4444
, /* Name */
151 GL_RGBA
, /* BaseFormat */
152 GL_UNSIGNED_NORMALIZED
, /* DataType */
153 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
154 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
155 1, 1, 2 /* BlockWidth/Height,Bytes */
158 MESA_FORMAT_ARGB4444_REV
, /* Name */
159 GL_RGBA
, /* BaseFormat */
160 GL_UNSIGNED_NORMALIZED
, /* DataType */
161 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
162 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
163 1, 1, 2 /* BlockWidth/Height,Bytes */
166 MESA_FORMAT_RGBA5551
, /* Name */
167 GL_RGBA
, /* BaseFormat */
168 GL_UNSIGNED_NORMALIZED
, /* DataType */
169 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
170 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
171 1, 1, 2 /* BlockWidth/Height,Bytes */
174 MESA_FORMAT_ARGB1555
, /* Name */
175 GL_RGBA
, /* BaseFormat */
176 GL_UNSIGNED_NORMALIZED
, /* DataType */
177 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
178 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
179 1, 1, 2 /* BlockWidth/Height,Bytes */
182 MESA_FORMAT_ARGB1555_REV
, /* Name */
183 GL_RGBA
, /* BaseFormat */
184 GL_UNSIGNED_NORMALIZED
, /* DataType */
185 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
186 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
187 1, 1, 2 /* BlockWidth/Height,Bytes */
190 MESA_FORMAT_AL88
, /* Name */
191 GL_LUMINANCE_ALPHA
, /* BaseFormat */
192 GL_UNSIGNED_NORMALIZED
, /* DataType */
193 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
194 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
195 1, 1, 2 /* BlockWidth/Height,Bytes */
198 MESA_FORMAT_AL88_REV
, /* Name */
199 GL_LUMINANCE_ALPHA
, /* BaseFormat */
200 GL_UNSIGNED_NORMALIZED
, /* DataType */
201 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
202 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
203 1, 1, 2 /* BlockWidth/Height,Bytes */
206 MESA_FORMAT_RGB332
, /* Name */
207 GL_RGB
, /* BaseFormat */
208 GL_UNSIGNED_NORMALIZED
, /* DataType */
209 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
210 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
211 1, 1, 1 /* BlockWidth/Height,Bytes */
214 MESA_FORMAT_A8
, /* Name */
215 GL_ALPHA
, /* BaseFormat */
216 GL_UNSIGNED_NORMALIZED
, /* DataType */
217 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
218 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
219 1, 1, 1 /* BlockWidth/Height,Bytes */
222 MESA_FORMAT_L8
, /* Name */
223 GL_LUMINANCE
, /* BaseFormat */
224 GL_UNSIGNED_NORMALIZED
, /* DataType */
225 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
226 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
227 1, 1, 1 /* BlockWidth/Height,Bytes */
230 MESA_FORMAT_I8
, /* Name */
231 GL_INTENSITY
, /* BaseFormat */
232 GL_UNSIGNED_NORMALIZED
, /* DataType */
233 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
234 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
235 1, 1, 1 /* BlockWidth/Height,Bytes */
238 MESA_FORMAT_CI8
, /* Name */
239 GL_COLOR_INDEX
, /* BaseFormat */
240 GL_UNSIGNED_INT
, /* DataType */
241 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
242 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
243 1, 1, 1 /* BlockWidth/Height,Bytes */
246 MESA_FORMAT_YCBCR
, /* Name */
247 GL_YCBCR_MESA
, /* BaseFormat */
248 GL_UNSIGNED_NORMALIZED
, /* DataType */
249 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
250 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
251 1, 1, 2 /* BlockWidth/Height,Bytes */
254 MESA_FORMAT_YCBCR_REV
, /* Name */
255 GL_YCBCR_MESA
, /* BaseFormat */
256 GL_UNSIGNED_NORMALIZED
, /* DataType */
257 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
258 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
259 1, 1, 2 /* BlockWidth/Height,Bytes */
262 MESA_FORMAT_Z24_S8
, /* Name */
263 GL_DEPTH_STENCIL
, /* BaseFormat */
264 GL_UNSIGNED_INT
, /* DataType */
265 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
266 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
267 1, 1, 4 /* BlockWidth/Height,Bytes */
270 MESA_FORMAT_S8_Z24
, /* Name */
271 GL_DEPTH_STENCIL
, /* BaseFormat */
272 GL_UNSIGNED_INT
, /* DataType */
273 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
274 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
275 1, 1, 4 /* BlockWidth/Height,Bytes */
278 MESA_FORMAT_Z16
, /* Name */
279 GL_DEPTH_COMPONENT
, /* BaseFormat */
280 GL_UNSIGNED_INT
, /* DataType */
281 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
282 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
283 1, 1, 2 /* BlockWidth/Height,Bytes */
286 MESA_FORMAT_Z32
, /* Name */
287 GL_DEPTH_COMPONENT
, /* BaseFormat */
288 GL_UNSIGNED_INT
, /* DataType */
289 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
290 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
291 1, 1, 4 /* BlockWidth/Height,Bytes */
294 MESA_FORMAT_S8
, /* Name */
295 GL_STENCIL_INDEX
, /* BaseFormat */
296 GL_UNSIGNED_INT
, /* DataType */
297 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
298 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
299 1, 1, 1 /* BlockWidth/Height,Bytes */
304 GL_UNSIGNED_NORMALIZED
,
312 GL_UNSIGNED_NORMALIZED
,
320 GL_UNSIGNED_NORMALIZED
,
328 GL_UNSIGNED_NORMALIZED
,
336 GL_UNSIGNED_NORMALIZED
,
342 MESA_FORMAT_SRGB_DXT1
, /* Name */
343 GL_RGB
, /* BaseFormat */
344 GL_UNSIGNED_NORMALIZED
, /* DataType */
345 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
346 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
347 4, 4, 8 /* 8 bytes per 4x4 block */
350 MESA_FORMAT_SRGBA_DXT1
,
352 GL_UNSIGNED_NORMALIZED
,
355 4, 4, 8 /* 8 bytes per 4x4 block */
358 MESA_FORMAT_SRGBA_DXT3
,
360 GL_UNSIGNED_NORMALIZED
,
363 4, 4, 16 /* 16 bytes per 4x4 block */
366 MESA_FORMAT_SRGBA_DXT5
,
368 GL_UNSIGNED_NORMALIZED
,
371 4, 4, 16 /* 16 bytes per 4x4 block */
375 MESA_FORMAT_RGB_FXT1
,
377 GL_UNSIGNED_NORMALIZED
,
380 8, 4, 16 /* 16 bytes per 8x4 block */
383 MESA_FORMAT_RGBA_FXT1
,
385 GL_UNSIGNED_NORMALIZED
,
388 8, 4, 16 /* 16 bytes per 8x4 block */
392 MESA_FORMAT_RGB_DXT1
, /* Name */
393 GL_RGB
, /* BaseFormat */
394 GL_UNSIGNED_NORMALIZED
, /* DataType */
395 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
396 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
397 4, 4, 8 /* 8 bytes per 4x4 block */
400 MESA_FORMAT_RGBA_DXT1
,
402 GL_UNSIGNED_NORMALIZED
,
405 4, 4, 8 /* 8 bytes per 4x4 block */
408 MESA_FORMAT_RGBA_DXT3
,
410 GL_UNSIGNED_NORMALIZED
,
413 4, 4, 16 /* 16 bytes per 4x4 block */
416 MESA_FORMAT_RGBA_DXT5
,
418 GL_UNSIGNED_NORMALIZED
,
421 4, 4, 16 /* 16 bytes per 4x4 block */
424 MESA_FORMAT_RGBA_FLOAT32
,
432 MESA_FORMAT_RGBA_FLOAT16
,
440 MESA_FORMAT_RGB_FLOAT32
,
448 MESA_FORMAT_RGB_FLOAT16
,
456 MESA_FORMAT_ALPHA_FLOAT32
,
464 MESA_FORMAT_ALPHA_FLOAT16
,
472 MESA_FORMAT_LUMINANCE_FLOAT32
,
480 MESA_FORMAT_LUMINANCE_FLOAT16
,
488 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
496 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
504 MESA_FORMAT_INTENSITY_FLOAT32
,
512 MESA_FORMAT_INTENSITY_FLOAT16
,
522 GL_SIGNED_NORMALIZED
,
528 MESA_FORMAT_SIGNED_RGBA8888
,
530 GL_SIGNED_NORMALIZED
,
536 MESA_FORMAT_SIGNED_RGBA8888_REV
,
538 GL_SIGNED_NORMALIZED
,
548 static const struct gl_format_info
*
549 _mesa_get_format_info(gl_format format
)
551 const struct gl_format_info
*info
= &format_info
[format
];
552 assert(info
->Name
== format
);
558 _mesa_get_format_bytes(gl_format format
)
560 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
561 ASSERT(info
->BytesPerBlock
);
562 return info
->BytesPerBlock
;
567 _mesa_get_format_bits(gl_format format
, GLenum pname
)
569 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
573 case GL_TEXTURE_RED_SIZE
:
574 case GL_RENDERBUFFER_RED_SIZE_EXT
:
575 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
576 return info
->RedBits
;
578 case GL_TEXTURE_GREEN_SIZE
:
579 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
580 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
581 return info
->GreenBits
;
583 case GL_TEXTURE_BLUE_SIZE
:
584 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
585 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
586 return info
->BlueBits
;
588 case GL_TEXTURE_ALPHA_SIZE
:
589 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
590 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
591 return info
->AlphaBits
;
592 case GL_TEXTURE_INTENSITY_SIZE
:
593 return info
->IntensityBits
;
594 case GL_TEXTURE_LUMINANCE_SIZE
:
595 return info
->LuminanceBits
;
597 case GL_TEXTURE_INDEX_SIZE_EXT
:
598 return info
->IndexBits
;
600 case GL_TEXTURE_DEPTH_SIZE_ARB
:
601 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
602 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
603 return info
->DepthBits
;
604 case GL_STENCIL_BITS
:
605 case GL_TEXTURE_STENCIL_SIZE_EXT
:
606 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
607 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
608 return info
->StencilBits
;
610 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
617 _mesa_get_format_datatype(gl_format format
)
619 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
620 return info
->DataType
;
625 _mesa_get_format_base_format(gl_format format
)
627 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
628 return info
->BaseFormat
;
633 _mesa_is_format_compressed(gl_format format
)
635 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
636 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
641 * Return color encoding for given format.
642 * \return GL_LINEAR or GL_SRGB
645 _mesa_get_format_color_encoding(gl_format format
)
647 /* XXX this info should be encoded in gl_format_info */
649 case MESA_FORMAT_SRGB8
:
650 case MESA_FORMAT_SRGBA8
:
651 case MESA_FORMAT_SARGB8
:
652 case MESA_FORMAT_SL8
:
653 case MESA_FORMAT_SLA8
:
654 case MESA_FORMAT_SRGB_DXT1
:
655 case MESA_FORMAT_SRGBA_DXT1
:
656 case MESA_FORMAT_SRGBA_DXT3
:
657 case MESA_FORMAT_SRGBA_DXT5
:
666 * Return number of bytes needed to store an image of the given size
667 * in the given format.
670 _mesa_format_image_size(gl_format format
, GLsizei width
,
671 GLsizei height
, GLsizei depth
)
673 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
674 /* Strictly speaking, a conditional isn't needed here */
675 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
676 /* compressed format */
677 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
678 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
679 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
680 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
685 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
693 _mesa_format_row_stride(gl_format format
, GLsizei width
)
695 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
696 /* Strictly speaking, a conditional isn't needed here */
697 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
698 /* compressed format */
699 const GLuint bw
= info
->BlockWidth
;
700 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
701 const GLint stride
= wblocks
* info
->BytesPerBlock
;
705 const GLint stride
= width
* info
->BytesPerBlock
;
713 * Do sanity checking of the format info table.
716 _mesa_test_formats(void)
720 assert(Elements(format_info
) == MESA_FORMAT_COUNT
);
722 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
723 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
726 assert(info
->Name
== i
);
728 if (info
->Name
== MESA_FORMAT_NONE
)
731 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
732 if (info
->RedBits
> 0) {
733 GLuint t
= info
->RedBits
+ info
->GreenBits
734 + info
->BlueBits
+ info
->AlphaBits
;
735 assert(t
/ 8 == info
->BytesPerBlock
);
739 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
740 info
->DataType
== GL_SIGNED_NORMALIZED
||
741 info
->DataType
== GL_UNSIGNED_INT
||
742 info
->DataType
== GL_FLOAT
);
744 if (info
->BaseFormat
== GL_RGB
) {
745 assert(info
->RedBits
> 0);
746 assert(info
->GreenBits
> 0);
747 assert(info
->BlueBits
> 0);
748 assert(info
->AlphaBits
== 0);
749 assert(info
->LuminanceBits
== 0);
750 assert(info
->IntensityBits
== 0);
752 else if (info
->BaseFormat
== GL_RGBA
) {
753 assert(info
->RedBits
> 0);
754 assert(info
->GreenBits
> 0);
755 assert(info
->BlueBits
> 0);
756 assert(info
->AlphaBits
> 0);
757 assert(info
->LuminanceBits
== 0);
758 assert(info
->IntensityBits
== 0);
760 else if (info
->BaseFormat
== GL_LUMINANCE
) {
761 assert(info
->RedBits
== 0);
762 assert(info
->GreenBits
== 0);
763 assert(info
->BlueBits
== 0);
764 assert(info
->AlphaBits
== 0);
765 assert(info
->LuminanceBits
> 0);
766 assert(info
->IntensityBits
== 0);
768 else if (info
->BaseFormat
== GL_INTENSITY
) {
769 assert(info
->RedBits
== 0);
770 assert(info
->GreenBits
== 0);
771 assert(info
->BlueBits
== 0);
772 assert(info
->AlphaBits
== 0);
773 assert(info
->LuminanceBits
== 0);
774 assert(info
->IntensityBits
> 0);
783 * Return datatype and number of components per texel for the given gl_format.
784 * Only used for mipmap generation code.
787 _mesa_format_to_type_and_comps(gl_format format
,
788 GLenum
*datatype
, GLuint
*comps
)
791 case MESA_FORMAT_RGBA8888
:
792 case MESA_FORMAT_RGBA8888_REV
:
793 case MESA_FORMAT_ARGB8888
:
794 case MESA_FORMAT_ARGB8888_REV
:
795 *datatype
= GL_UNSIGNED_BYTE
;
798 case MESA_FORMAT_RGB888
:
799 case MESA_FORMAT_BGR888
:
800 *datatype
= GL_UNSIGNED_BYTE
;
803 case MESA_FORMAT_RGB565
:
804 case MESA_FORMAT_RGB565_REV
:
805 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
809 case MESA_FORMAT_ARGB4444
:
810 case MESA_FORMAT_ARGB4444_REV
:
811 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
815 case MESA_FORMAT_ARGB1555
:
816 case MESA_FORMAT_ARGB1555_REV
:
817 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
821 case MESA_FORMAT_AL88
:
822 case MESA_FORMAT_AL88_REV
:
823 *datatype
= GL_UNSIGNED_BYTE
;
826 case MESA_FORMAT_RGB332
:
827 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
834 case MESA_FORMAT_CI8
:
835 *datatype
= GL_UNSIGNED_BYTE
;
839 case MESA_FORMAT_YCBCR
:
840 case MESA_FORMAT_YCBCR_REV
:
841 *datatype
= GL_UNSIGNED_SHORT
;
845 case MESA_FORMAT_Z24_S8
:
846 *datatype
= GL_UNSIGNED_INT
;
847 *comps
= 1; /* XXX OK? */
850 case MESA_FORMAT_S8_Z24
:
851 *datatype
= GL_UNSIGNED_INT
;
852 *comps
= 1; /* XXX OK? */
855 case MESA_FORMAT_Z16
:
856 *datatype
= GL_UNSIGNED_SHORT
;
860 case MESA_FORMAT_Z32
:
861 *datatype
= GL_UNSIGNED_INT
;
865 case MESA_FORMAT_DUDV8
:
870 case MESA_FORMAT_SIGNED_RGBA8888
:
871 case MESA_FORMAT_SIGNED_RGBA8888_REV
:
876 #if FEATURE_EXT_texture_sRGB
877 case MESA_FORMAT_SRGB8
:
878 *datatype
= GL_UNSIGNED_BYTE
;
881 case MESA_FORMAT_SRGBA8
:
882 case MESA_FORMAT_SARGB8
:
883 *datatype
= GL_UNSIGNED_BYTE
;
886 case MESA_FORMAT_SL8
:
887 *datatype
= GL_UNSIGNED_BYTE
;
890 case MESA_FORMAT_SLA8
:
891 *datatype
= GL_UNSIGNED_BYTE
;
896 #if FEATURE_texture_fxt1
897 case MESA_FORMAT_RGB_FXT1
:
898 case MESA_FORMAT_RGBA_FXT1
:
900 #if FEATURE_texture_s3tc
901 case MESA_FORMAT_RGB_DXT1
:
902 case MESA_FORMAT_RGBA_DXT1
:
903 case MESA_FORMAT_RGBA_DXT3
:
904 case MESA_FORMAT_RGBA_DXT5
:
905 #if FEATURE_EXT_texture_sRGB
906 case MESA_FORMAT_SRGB_DXT1
:
907 case MESA_FORMAT_SRGBA_DXT1
:
908 case MESA_FORMAT_SRGBA_DXT3
:
909 case MESA_FORMAT_SRGBA_DXT5
:
911 /* XXX generate error instead? */
912 *datatype
= GL_UNSIGNED_BYTE
;
917 case MESA_FORMAT_RGBA_FLOAT32
:
918 *datatype
= GL_FLOAT
;
921 case MESA_FORMAT_RGBA_FLOAT16
:
922 *datatype
= GL_HALF_FLOAT_ARB
;
925 case MESA_FORMAT_RGB_FLOAT32
:
926 *datatype
= GL_FLOAT
;
929 case MESA_FORMAT_RGB_FLOAT16
:
930 *datatype
= GL_HALF_FLOAT_ARB
;
933 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
934 *datatype
= GL_FLOAT
;
937 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
938 *datatype
= GL_HALF_FLOAT_ARB
;
941 case MESA_FORMAT_ALPHA_FLOAT32
:
942 case MESA_FORMAT_LUMINANCE_FLOAT32
:
943 case MESA_FORMAT_INTENSITY_FLOAT32
:
944 *datatype
= GL_FLOAT
;
947 case MESA_FORMAT_ALPHA_FLOAT16
:
948 case MESA_FORMAT_LUMINANCE_FLOAT16
:
949 case MESA_FORMAT_INTENSITY_FLOAT16
:
950 *datatype
= GL_HALF_FLOAT_ARB
;
955 _mesa_problem(NULL
, "bad format in _mesa_format_to_type_and_comps");