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.
40 /** text name for debugging */
44 * Base format is one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE,
45 * GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX,
46 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
51 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
52 * GL_UNSIGNED_INT, GL_SIGNED_INT, GL_FLOAT.
60 GLubyte LuminanceBits
;
61 GLubyte IntensityBits
;
67 * To describe compressed formats. If not compressed, Width=Height=1.
69 GLubyte BlockWidth
, BlockHeight
;
70 GLubyte BytesPerBlock
;
75 * Info about each format.
76 * These must be in the same order as the MESA_FORMAT_* enums so that
77 * we can do lookups without searching.
79 static struct gl_format_info format_info
[MESA_FORMAT_COUNT
] =
82 MESA_FORMAT_NONE
, /* Name */
83 "MESA_FORMAT_NONE", /* StrName */
84 GL_NONE
, /* BaseFormat */
85 GL_NONE
, /* DataType */
86 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
87 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
88 0, 0, 0 /* BlockWidth/Height,Bytes */
91 MESA_FORMAT_RGBA8888
, /* Name */
92 "MESA_FORMAT_RGBA8888", /* StrName */
93 GL_RGBA
, /* BaseFormat */
94 GL_UNSIGNED_NORMALIZED
, /* DataType */
95 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
96 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
97 1, 1, 4 /* BlockWidth/Height,Bytes */
100 MESA_FORMAT_RGBA8888_REV
, /* Name */
101 "MESA_FORMAT_RGBA8888_REV", /* StrName */
102 GL_RGBA
, /* BaseFormat */
103 GL_UNSIGNED_NORMALIZED
, /* DataType */
104 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
105 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
106 1, 1, 4 /* BlockWidth/Height,Bytes */
109 MESA_FORMAT_ARGB8888
, /* Name */
110 "MESA_FORMAT_ARGB8888", /* StrName */
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_ARGB8888_REV
, /* Name */
119 "MESA_FORMAT_ARGB8888_REV", /* StrName */
120 GL_RGBA
, /* BaseFormat */
121 GL_UNSIGNED_NORMALIZED
, /* DataType */
122 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
123 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
124 1, 1, 4 /* BlockWidth/Height,Bytes */
127 MESA_FORMAT_XRGB8888
, /* Name */
128 "MESA_FORMAT_XRGB8888", /* StrName */
129 GL_RGB
, /* BaseFormat */
130 GL_UNSIGNED_NORMALIZED
, /* DataType */
131 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
132 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
133 1, 1, 4 /* BlockWidth/Height,Bytes */
136 MESA_FORMAT_RGB888
, /* Name */
137 "MESA_FORMAT_RGB888", /* StrName */
138 GL_RGB
, /* BaseFormat */
139 GL_UNSIGNED_NORMALIZED
, /* DataType */
140 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
141 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
142 1, 1, 3 /* BlockWidth/Height,Bytes */
145 MESA_FORMAT_BGR888
, /* Name */
146 "MESA_FORMAT_BGR888", /* StrName */
147 GL_RGB
, /* BaseFormat */
148 GL_UNSIGNED_NORMALIZED
, /* DataType */
149 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
150 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
151 1, 1, 3 /* BlockWidth/Height,Bytes */
154 MESA_FORMAT_RGB565
, /* Name */
155 "MESA_FORMAT_RGB565", /* StrName */
156 GL_RGB
, /* BaseFormat */
157 GL_UNSIGNED_NORMALIZED
, /* DataType */
158 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
159 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
160 1, 1, 2 /* BlockWidth/Height,Bytes */
163 MESA_FORMAT_RGB565_REV
, /* Name */
164 "MESA_FORMAT_RGB565_REV", /* StrName */
165 GL_RGB
, /* BaseFormat */
166 GL_UNSIGNED_NORMALIZED
, /* DataType */
167 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
168 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
169 1, 1, 2 /* BlockWidth/Height,Bytes */
172 MESA_FORMAT_ARGB4444
, /* Name */
173 "MESA_FORMAT_ARGB4444", /* StrName */
174 GL_RGBA
, /* BaseFormat */
175 GL_UNSIGNED_NORMALIZED
, /* DataType */
176 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
177 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
178 1, 1, 2 /* BlockWidth/Height,Bytes */
181 MESA_FORMAT_ARGB4444_REV
, /* Name */
182 "MESA_FORMAT_ARGB4444_REV", /* StrName */
183 GL_RGBA
, /* BaseFormat */
184 GL_UNSIGNED_NORMALIZED
, /* DataType */
185 4, 4, 4, 4, /* 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_RGBA5551
, /* Name */
191 "MESA_FORMAT_RGBA5551", /* StrName */
192 GL_RGBA
, /* BaseFormat */
193 GL_UNSIGNED_NORMALIZED
, /* DataType */
194 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
195 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
196 1, 1, 2 /* BlockWidth/Height,Bytes */
199 MESA_FORMAT_ARGB1555
, /* Name */
200 "MESA_FORMAT_ARGB1555", /* StrName */
201 GL_RGBA
, /* BaseFormat */
202 GL_UNSIGNED_NORMALIZED
, /* DataType */
203 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
204 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
205 1, 1, 2 /* BlockWidth/Height,Bytes */
208 MESA_FORMAT_ARGB1555_REV
, /* Name */
209 "MESA_FORMAT_ARGB1555_REV", /* StrName */
210 GL_RGBA
, /* BaseFormat */
211 GL_UNSIGNED_NORMALIZED
, /* DataType */
212 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
213 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
214 1, 1, 2 /* BlockWidth/Height,Bytes */
217 MESA_FORMAT_AL88
, /* Name */
218 "MESA_FORMAT_AL88", /* StrName */
219 GL_LUMINANCE_ALPHA
, /* BaseFormat */
220 GL_UNSIGNED_NORMALIZED
, /* DataType */
221 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
222 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
223 1, 1, 2 /* BlockWidth/Height,Bytes */
226 MESA_FORMAT_AL88_REV
, /* Name */
227 "MESA_FORMAT_AL88_REV", /* StrName */
228 GL_LUMINANCE_ALPHA
, /* BaseFormat */
229 GL_UNSIGNED_NORMALIZED
, /* DataType */
230 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
231 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
232 1, 1, 2 /* BlockWidth/Height,Bytes */
235 MESA_FORMAT_RGB332
, /* Name */
236 "MESA_FORMAT_RGB332", /* StrName */
237 GL_RGB
, /* BaseFormat */
238 GL_UNSIGNED_NORMALIZED
, /* DataType */
239 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
240 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
241 1, 1, 1 /* BlockWidth/Height,Bytes */
244 MESA_FORMAT_A8
, /* Name */
245 "MESA_FORMAT_A8", /* StrName */
246 GL_ALPHA
, /* BaseFormat */
247 GL_UNSIGNED_NORMALIZED
, /* DataType */
248 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
249 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
250 1, 1, 1 /* BlockWidth/Height,Bytes */
253 MESA_FORMAT_L8
, /* Name */
254 "MESA_FORMAT_L8", /* StrName */
255 GL_LUMINANCE
, /* BaseFormat */
256 GL_UNSIGNED_NORMALIZED
, /* DataType */
257 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
258 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
259 1, 1, 1 /* BlockWidth/Height,Bytes */
262 MESA_FORMAT_I8
, /* Name */
263 "MESA_FORMAT_I8", /* StrName */
264 GL_INTENSITY
, /* BaseFormat */
265 GL_UNSIGNED_NORMALIZED
, /* DataType */
266 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
267 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
268 1, 1, 1 /* BlockWidth/Height,Bytes */
271 MESA_FORMAT_CI8
, /* Name */
272 "MESA_FORMAT_CI8", /* StrName */
273 GL_COLOR_INDEX
, /* BaseFormat */
274 GL_UNSIGNED_INT
, /* DataType */
275 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
276 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
277 1, 1, 1 /* BlockWidth/Height,Bytes */
280 MESA_FORMAT_YCBCR
, /* Name */
281 "MESA_FORMAT_YCBCR", /* StrName */
282 GL_YCBCR_MESA
, /* BaseFormat */
283 GL_UNSIGNED_NORMALIZED
, /* DataType */
284 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
285 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
286 1, 1, 2 /* BlockWidth/Height,Bytes */
289 MESA_FORMAT_YCBCR_REV
, /* Name */
290 "MESA_FORMAT_YCBCR_REV", /* StrName */
291 GL_YCBCR_MESA
, /* BaseFormat */
292 GL_UNSIGNED_NORMALIZED
, /* DataType */
293 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
294 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
295 1, 1, 2 /* BlockWidth/Height,Bytes */
298 MESA_FORMAT_Z24_S8
, /* Name */
299 "MESA_FORMAT_Z24_S8", /* StrName */
300 GL_DEPTH_STENCIL
, /* BaseFormat */
301 GL_UNSIGNED_INT
, /* DataType */
302 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
303 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
304 1, 1, 4 /* BlockWidth/Height,Bytes */
307 MESA_FORMAT_S8_Z24
, /* Name */
308 "MESA_FORMAT_S8_Z24", /* StrName */
309 GL_DEPTH_STENCIL
, /* BaseFormat */
310 GL_UNSIGNED_INT
, /* DataType */
311 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
312 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
313 1, 1, 4 /* BlockWidth/Height,Bytes */
316 MESA_FORMAT_Z16
, /* Name */
317 "MESA_FORMAT_Z16", /* StrName */
318 GL_DEPTH_COMPONENT
, /* BaseFormat */
319 GL_UNSIGNED_INT
, /* DataType */
320 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
321 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
322 1, 1, 2 /* BlockWidth/Height,Bytes */
325 MESA_FORMAT_X8_Z24
, /* Name */
326 "MESA_FORMAT_X8_Z24", /* StrName */
327 GL_DEPTH_COMPONENT
, /* BaseFormat */
328 GL_UNSIGNED_INT
, /* DataType */
329 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
330 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
331 1, 1, 4 /* BlockWidth/Height,Bytes */
334 MESA_FORMAT_Z32
, /* Name */
335 "MESA_FORMAT_Z32", /* StrName */
336 GL_DEPTH_COMPONENT
, /* BaseFormat */
337 GL_UNSIGNED_INT
, /* DataType */
338 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
339 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
340 1, 1, 4 /* BlockWidth/Height,Bytes */
343 MESA_FORMAT_S8
, /* Name */
344 "MESA_FORMAT_S8", /* StrName */
345 GL_STENCIL_INDEX
, /* BaseFormat */
346 GL_UNSIGNED_INT
, /* DataType */
347 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
348 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
349 1, 1, 1 /* BlockWidth/Height,Bytes */
355 GL_UNSIGNED_NORMALIZED
,
362 "MESA_FORMAT_SRGBA8",
364 GL_UNSIGNED_NORMALIZED
,
371 "MESA_FORMAT_SARGB8",
373 GL_UNSIGNED_NORMALIZED
,
382 GL_UNSIGNED_NORMALIZED
,
391 GL_UNSIGNED_NORMALIZED
,
397 MESA_FORMAT_SRGB_DXT1
, /* Name */
398 "MESA_FORMAT_SRGB_DXT1", /* StrName */
399 GL_RGB
, /* BaseFormat */
400 GL_UNSIGNED_NORMALIZED
, /* DataType */
401 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
402 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
403 4, 4, 8 /* 8 bytes per 4x4 block */
406 MESA_FORMAT_SRGBA_DXT1
,
407 "MESA_FORMAT_SRGBA_DXT1",
409 GL_UNSIGNED_NORMALIZED
,
412 4, 4, 8 /* 8 bytes per 4x4 block */
415 MESA_FORMAT_SRGBA_DXT3
,
416 "MESA_FORMAT_SRGBA_DXT3",
418 GL_UNSIGNED_NORMALIZED
,
421 4, 4, 16 /* 16 bytes per 4x4 block */
424 MESA_FORMAT_SRGBA_DXT5
,
425 "MESA_FORMAT_SRGBA_DXT5",
427 GL_UNSIGNED_NORMALIZED
,
430 4, 4, 16 /* 16 bytes per 4x4 block */
434 MESA_FORMAT_RGB_FXT1
,
435 "MESA_FORMAT_RGB_FXT1",
437 GL_UNSIGNED_NORMALIZED
,
440 8, 4, 16 /* 16 bytes per 8x4 block */
443 MESA_FORMAT_RGBA_FXT1
,
444 "MESA_FORMAT_RGBA_FXT1",
446 GL_UNSIGNED_NORMALIZED
,
449 8, 4, 16 /* 16 bytes per 8x4 block */
453 MESA_FORMAT_RGB_DXT1
, /* Name */
454 "MESA_FORMAT_RGB_DXT1", /* StrName */
455 GL_RGB
, /* BaseFormat */
456 GL_UNSIGNED_NORMALIZED
, /* DataType */
457 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
458 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
459 4, 4, 8 /* 8 bytes per 4x4 block */
462 MESA_FORMAT_RGBA_DXT1
,
463 "MESA_FORMAT_RGBA_DXT1",
465 GL_UNSIGNED_NORMALIZED
,
468 4, 4, 8 /* 8 bytes per 4x4 block */
471 MESA_FORMAT_RGBA_DXT3
,
472 "MESA_FORMAT_RGBA_DXT3",
474 GL_UNSIGNED_NORMALIZED
,
477 4, 4, 16 /* 16 bytes per 4x4 block */
480 MESA_FORMAT_RGBA_DXT5
,
481 "MESA_FORMAT_RGBA_DXT5",
483 GL_UNSIGNED_NORMALIZED
,
486 4, 4, 16 /* 16 bytes per 4x4 block */
489 MESA_FORMAT_RGBA_FLOAT32
,
490 "MESA_FORMAT_RGBA_FLOAT32",
498 MESA_FORMAT_RGBA_FLOAT16
,
499 "MESA_FORMAT_RGBA_FLOAT16",
507 MESA_FORMAT_RGB_FLOAT32
,
508 "MESA_FORMAT_RGB_FLOAT32",
516 MESA_FORMAT_RGB_FLOAT16
,
517 "MESA_FORMAT_RGB_FLOAT16",
525 MESA_FORMAT_ALPHA_FLOAT32
,
526 "MESA_FORMAT_ALPHA_FLOAT32",
534 MESA_FORMAT_ALPHA_FLOAT16
,
535 "MESA_FORMAT_ALPHA_FLOAT16",
543 MESA_FORMAT_LUMINANCE_FLOAT32
,
544 "MESA_FORMAT_LUMINANCE_FLOAT32",
552 MESA_FORMAT_LUMINANCE_FLOAT16
,
553 "MESA_FORMAT_LUMINANCE_FLOAT16",
561 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
562 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
570 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
571 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
579 MESA_FORMAT_INTENSITY_FLOAT32
,
580 "MESA_FORMAT_INTENSITY_FLOAT32",
588 MESA_FORMAT_INTENSITY_FLOAT16
,
589 "MESA_FORMAT_INTENSITY_FLOAT16",
600 GL_SIGNED_NORMALIZED
,
606 MESA_FORMAT_SIGNED_RGBA8888
,
607 "MESA_FORMAT_SIGNED_RGBA8888",
609 GL_SIGNED_NORMALIZED
,
615 MESA_FORMAT_SIGNED_RGBA8888_REV
,
616 "MESA_FORMAT_SIGNED_RGBA8888_REV",
618 GL_SIGNED_NORMALIZED
,
624 MESA_FORMAT_SIGNED_RGBA_16
,
625 "MESA_FORMAT_SIGNED_RGBA_16",
627 GL_SIGNED_NORMALIZED
,
636 static const struct gl_format_info
*
637 _mesa_get_format_info(gl_format format
)
639 const struct gl_format_info
*info
= &format_info
[format
];
640 assert(info
->Name
== format
);
645 /** Return string name of format (for debugging) */
647 _mesa_get_format_name(gl_format format
)
649 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
650 ASSERT(info
->BytesPerBlock
);
651 return info
->StrName
;
657 * Return bytes needed to store a block of pixels in the given format.
658 * Normally, a block is 1x1 (a single pixel). But for compressed formats
659 * a block may be 4x4 or 8x4, etc.
662 _mesa_get_format_bytes(gl_format format
)
664 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
665 ASSERT(info
->BytesPerBlock
);
666 return info
->BytesPerBlock
;
671 * Return bits per component for the given format.
672 * \param format one of MESA_FORMAT_x
673 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
676 _mesa_get_format_bits(gl_format format
, GLenum pname
)
678 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
682 case GL_TEXTURE_RED_SIZE
:
683 case GL_RENDERBUFFER_RED_SIZE_EXT
:
684 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
685 return info
->RedBits
;
687 case GL_TEXTURE_GREEN_SIZE
:
688 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
689 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
690 return info
->GreenBits
;
692 case GL_TEXTURE_BLUE_SIZE
:
693 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
694 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
695 return info
->BlueBits
;
697 case GL_TEXTURE_ALPHA_SIZE
:
698 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
699 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
700 return info
->AlphaBits
;
701 case GL_TEXTURE_INTENSITY_SIZE
:
702 return info
->IntensityBits
;
703 case GL_TEXTURE_LUMINANCE_SIZE
:
704 return info
->LuminanceBits
;
706 case GL_TEXTURE_INDEX_SIZE_EXT
:
707 return info
->IndexBits
;
709 case GL_TEXTURE_DEPTH_SIZE_ARB
:
710 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
711 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
712 return info
->DepthBits
;
713 case GL_STENCIL_BITS
:
714 case GL_TEXTURE_STENCIL_SIZE_EXT
:
715 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
716 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
717 return info
->StencilBits
;
719 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
726 * Return the data type (or more specifically, the data representation)
727 * for the given format.
728 * The return value will be one of:
729 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
730 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
731 * GL_UNSIGNED_INT = an ordinary unsigned integer
732 * GL_FLOAT = an ordinary float
735 _mesa_get_format_datatype(gl_format format
)
737 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
738 return info
->DataType
;
743 * Return the basic format for the given type. The result will be
744 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
745 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
746 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
749 _mesa_get_format_base_format(gl_format format
)
751 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
752 return info
->BaseFormat
;
757 * Return the block size (in pixels) for the given format. Normally
758 * the block size is 1x1. But compressed formats will have block sizes
759 * of 4x4 or 8x4 pixels, etc.
760 * \param bw returns block width in pixels
761 * \param bh returns block height in pixels
764 _mesa_get_format_block_size(gl_format format
, GLuint
*bw
, GLuint
*bh
)
766 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
767 *bw
= info
->BlockWidth
;
768 *bh
= info
->BlockHeight
;
772 /** Is the given format a compressed format? */
774 _mesa_is_format_compressed(gl_format format
)
776 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
777 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
782 * Return color encoding for given format.
783 * \return GL_LINEAR or GL_SRGB
786 _mesa_get_format_color_encoding(gl_format format
)
788 /* XXX this info should be encoded in gl_format_info */
790 case MESA_FORMAT_SRGB8
:
791 case MESA_FORMAT_SRGBA8
:
792 case MESA_FORMAT_SARGB8
:
793 case MESA_FORMAT_SL8
:
794 case MESA_FORMAT_SLA8
:
795 case MESA_FORMAT_SRGB_DXT1
:
796 case MESA_FORMAT_SRGBA_DXT1
:
797 case MESA_FORMAT_SRGBA_DXT3
:
798 case MESA_FORMAT_SRGBA_DXT5
:
807 * Return number of bytes needed to store an image of the given size
808 * in the given format.
811 _mesa_format_image_size(gl_format format
, GLsizei width
,
812 GLsizei height
, GLsizei depth
)
814 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
815 /* Strictly speaking, a conditional isn't needed here */
816 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
817 /* compressed format */
818 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
819 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
820 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
821 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
826 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
834 _mesa_format_row_stride(gl_format format
, GLsizei width
)
836 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
837 /* Strictly speaking, a conditional isn't needed here */
838 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
839 /* compressed format */
840 const GLuint bw
= info
->BlockWidth
;
841 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
842 const GLint stride
= wblocks
* info
->BytesPerBlock
;
846 const GLint stride
= width
* info
->BytesPerBlock
;
854 * Do sanity checking of the format info table.
857 _mesa_test_formats(void)
861 assert(Elements(format_info
) == MESA_FORMAT_COUNT
);
863 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
864 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
867 assert(info
->Name
== i
);
869 if (info
->Name
== MESA_FORMAT_NONE
)
872 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
873 if (info
->RedBits
> 0) {
874 GLuint t
= info
->RedBits
+ info
->GreenBits
875 + info
->BlueBits
+ info
->AlphaBits
;
876 assert(t
/ 8 == info
->BytesPerBlock
);
880 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
881 info
->DataType
== GL_SIGNED_NORMALIZED
||
882 info
->DataType
== GL_UNSIGNED_INT
||
883 info
->DataType
== GL_FLOAT
);
885 if (info
->BaseFormat
== GL_RGB
) {
886 assert(info
->RedBits
> 0);
887 assert(info
->GreenBits
> 0);
888 assert(info
->BlueBits
> 0);
889 assert(info
->AlphaBits
== 0);
890 assert(info
->LuminanceBits
== 0);
891 assert(info
->IntensityBits
== 0);
893 else if (info
->BaseFormat
== GL_RGBA
) {
894 assert(info
->RedBits
> 0);
895 assert(info
->GreenBits
> 0);
896 assert(info
->BlueBits
> 0);
897 assert(info
->AlphaBits
> 0);
898 assert(info
->LuminanceBits
== 0);
899 assert(info
->IntensityBits
== 0);
901 else if (info
->BaseFormat
== GL_LUMINANCE
) {
902 assert(info
->RedBits
== 0);
903 assert(info
->GreenBits
== 0);
904 assert(info
->BlueBits
== 0);
905 assert(info
->AlphaBits
== 0);
906 assert(info
->LuminanceBits
> 0);
907 assert(info
->IntensityBits
== 0);
909 else if (info
->BaseFormat
== GL_INTENSITY
) {
910 assert(info
->RedBits
== 0);
911 assert(info
->GreenBits
== 0);
912 assert(info
->BlueBits
== 0);
913 assert(info
->AlphaBits
== 0);
914 assert(info
->LuminanceBits
== 0);
915 assert(info
->IntensityBits
> 0);
924 * Return datatype and number of components per texel for the given gl_format.
925 * Only used for mipmap generation code.
928 _mesa_format_to_type_and_comps(gl_format format
,
929 GLenum
*datatype
, GLuint
*comps
)
932 case MESA_FORMAT_RGBA8888
:
933 case MESA_FORMAT_RGBA8888_REV
:
934 case MESA_FORMAT_ARGB8888
:
935 case MESA_FORMAT_ARGB8888_REV
:
936 case MESA_FORMAT_XRGB8888
:
937 *datatype
= GL_UNSIGNED_BYTE
;
940 case MESA_FORMAT_RGB888
:
941 case MESA_FORMAT_BGR888
:
942 *datatype
= GL_UNSIGNED_BYTE
;
945 case MESA_FORMAT_RGB565
:
946 case MESA_FORMAT_RGB565_REV
:
947 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
951 case MESA_FORMAT_ARGB4444
:
952 case MESA_FORMAT_ARGB4444_REV
:
953 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
957 case MESA_FORMAT_ARGB1555
:
958 case MESA_FORMAT_ARGB1555_REV
:
959 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
963 case MESA_FORMAT_AL88
:
964 case MESA_FORMAT_AL88_REV
:
965 *datatype
= GL_UNSIGNED_BYTE
;
968 case MESA_FORMAT_RGB332
:
969 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
976 case MESA_FORMAT_CI8
:
977 *datatype
= GL_UNSIGNED_BYTE
;
981 case MESA_FORMAT_YCBCR
:
982 case MESA_FORMAT_YCBCR_REV
:
983 *datatype
= GL_UNSIGNED_SHORT
;
987 case MESA_FORMAT_Z24_S8
:
988 *datatype
= GL_UNSIGNED_INT
;
989 *comps
= 1; /* XXX OK? */
992 case MESA_FORMAT_S8_Z24
:
993 *datatype
= GL_UNSIGNED_INT
;
994 *comps
= 1; /* XXX OK? */
997 case MESA_FORMAT_Z16
:
998 *datatype
= GL_UNSIGNED_SHORT
;
1002 case MESA_FORMAT_X8_Z24
:
1003 *datatype
= GL_UNSIGNED_INT
;
1007 case MESA_FORMAT_Z32
:
1008 *datatype
= GL_UNSIGNED_INT
;
1012 case MESA_FORMAT_DUDV8
:
1013 *datatype
= GL_BYTE
;
1017 case MESA_FORMAT_SIGNED_RGBA8888
:
1018 case MESA_FORMAT_SIGNED_RGBA8888_REV
:
1019 *datatype
= GL_BYTE
;
1022 case MESA_FORMAT_SIGNED_RGBA_16
:
1023 *datatype
= GL_SHORT
;
1027 #if FEATURE_EXT_texture_sRGB
1028 case MESA_FORMAT_SRGB8
:
1029 *datatype
= GL_UNSIGNED_BYTE
;
1032 case MESA_FORMAT_SRGBA8
:
1033 case MESA_FORMAT_SARGB8
:
1034 *datatype
= GL_UNSIGNED_BYTE
;
1037 case MESA_FORMAT_SL8
:
1038 *datatype
= GL_UNSIGNED_BYTE
;
1041 case MESA_FORMAT_SLA8
:
1042 *datatype
= GL_UNSIGNED_BYTE
;
1047 #if FEATURE_texture_fxt1
1048 case MESA_FORMAT_RGB_FXT1
:
1049 case MESA_FORMAT_RGBA_FXT1
:
1051 #if FEATURE_texture_s3tc
1052 case MESA_FORMAT_RGB_DXT1
:
1053 case MESA_FORMAT_RGBA_DXT1
:
1054 case MESA_FORMAT_RGBA_DXT3
:
1055 case MESA_FORMAT_RGBA_DXT5
:
1056 #if FEATURE_EXT_texture_sRGB
1057 case MESA_FORMAT_SRGB_DXT1
:
1058 case MESA_FORMAT_SRGBA_DXT1
:
1059 case MESA_FORMAT_SRGBA_DXT3
:
1060 case MESA_FORMAT_SRGBA_DXT5
:
1062 /* XXX generate error instead? */
1063 *datatype
= GL_UNSIGNED_BYTE
;
1068 case MESA_FORMAT_RGBA_FLOAT32
:
1069 *datatype
= GL_FLOAT
;
1072 case MESA_FORMAT_RGBA_FLOAT16
:
1073 *datatype
= GL_HALF_FLOAT_ARB
;
1076 case MESA_FORMAT_RGB_FLOAT32
:
1077 *datatype
= GL_FLOAT
;
1080 case MESA_FORMAT_RGB_FLOAT16
:
1081 *datatype
= GL_HALF_FLOAT_ARB
;
1084 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
1085 *datatype
= GL_FLOAT
;
1088 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
1089 *datatype
= GL_HALF_FLOAT_ARB
;
1092 case MESA_FORMAT_ALPHA_FLOAT32
:
1093 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1094 case MESA_FORMAT_INTENSITY_FLOAT32
:
1095 *datatype
= GL_FLOAT
;
1098 case MESA_FORMAT_ALPHA_FLOAT16
:
1099 case MESA_FORMAT_LUMINANCE_FLOAT16
:
1100 case MESA_FORMAT_INTENSITY_FLOAT16
:
1101 *datatype
= GL_HALF_FLOAT_ARB
;
1106 _mesa_problem(NULL
, "bad format in _mesa_format_to_type_and_comps");