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_Z24_X8
, /* Name */
335 "MESA_FORMAT_Z24_X8", /* StrName */
336 GL_DEPTH_COMPONENT
, /* BaseFormat */
337 GL_UNSIGNED_INT
, /* DataType */
338 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
339 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
340 1, 1, 4 /* BlockWidth/Height,Bytes */
343 MESA_FORMAT_Z32
, /* Name */
344 "MESA_FORMAT_Z32", /* StrName */
345 GL_DEPTH_COMPONENT
, /* BaseFormat */
346 GL_UNSIGNED_INT
, /* DataType */
347 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
348 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
349 1, 1, 4 /* BlockWidth/Height,Bytes */
352 MESA_FORMAT_S8
, /* Name */
353 "MESA_FORMAT_S8", /* StrName */
354 GL_STENCIL_INDEX
, /* BaseFormat */
355 GL_UNSIGNED_INT
, /* DataType */
356 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
357 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
358 1, 1, 1 /* BlockWidth/Height,Bytes */
364 GL_UNSIGNED_NORMALIZED
,
371 "MESA_FORMAT_SRGBA8",
373 GL_UNSIGNED_NORMALIZED
,
380 "MESA_FORMAT_SARGB8",
382 GL_UNSIGNED_NORMALIZED
,
391 GL_UNSIGNED_NORMALIZED
,
400 GL_UNSIGNED_NORMALIZED
,
406 MESA_FORMAT_SRGB_DXT1
, /* Name */
407 "MESA_FORMAT_SRGB_DXT1", /* StrName */
408 GL_RGB
, /* BaseFormat */
409 GL_UNSIGNED_NORMALIZED
, /* DataType */
410 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
411 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
412 4, 4, 8 /* 8 bytes per 4x4 block */
415 MESA_FORMAT_SRGBA_DXT1
,
416 "MESA_FORMAT_SRGBA_DXT1",
418 GL_UNSIGNED_NORMALIZED
,
421 4, 4, 8 /* 8 bytes per 4x4 block */
424 MESA_FORMAT_SRGBA_DXT3
,
425 "MESA_FORMAT_SRGBA_DXT3",
427 GL_UNSIGNED_NORMALIZED
,
430 4, 4, 16 /* 16 bytes per 4x4 block */
433 MESA_FORMAT_SRGBA_DXT5
,
434 "MESA_FORMAT_SRGBA_DXT5",
436 GL_UNSIGNED_NORMALIZED
,
439 4, 4, 16 /* 16 bytes per 4x4 block */
443 MESA_FORMAT_RGB_FXT1
,
444 "MESA_FORMAT_RGB_FXT1",
446 GL_UNSIGNED_NORMALIZED
,
447 4, 4, 4, 0, /* approx Red/Green/BlueBits */
449 8, 4, 16 /* 16 bytes per 8x4 block */
452 MESA_FORMAT_RGBA_FXT1
,
453 "MESA_FORMAT_RGBA_FXT1",
455 GL_UNSIGNED_NORMALIZED
,
456 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
458 8, 4, 16 /* 16 bytes per 8x4 block */
462 MESA_FORMAT_RGB_DXT1
, /* Name */
463 "MESA_FORMAT_RGB_DXT1", /* StrName */
464 GL_RGB
, /* BaseFormat */
465 GL_UNSIGNED_NORMALIZED
, /* DataType */
466 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
467 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
468 4, 4, 8 /* 8 bytes per 4x4 block */
471 MESA_FORMAT_RGBA_DXT1
,
472 "MESA_FORMAT_RGBA_DXT1",
474 GL_UNSIGNED_NORMALIZED
,
477 4, 4, 8 /* 8 bytes per 4x4 block */
480 MESA_FORMAT_RGBA_DXT3
,
481 "MESA_FORMAT_RGBA_DXT3",
483 GL_UNSIGNED_NORMALIZED
,
486 4, 4, 16 /* 16 bytes per 4x4 block */
489 MESA_FORMAT_RGBA_DXT5
,
490 "MESA_FORMAT_RGBA_DXT5",
492 GL_UNSIGNED_NORMALIZED
,
495 4, 4, 16 /* 16 bytes per 4x4 block */
498 MESA_FORMAT_RGBA_FLOAT32
,
499 "MESA_FORMAT_RGBA_FLOAT32",
507 MESA_FORMAT_RGBA_FLOAT16
,
508 "MESA_FORMAT_RGBA_FLOAT16",
516 MESA_FORMAT_RGB_FLOAT32
,
517 "MESA_FORMAT_RGB_FLOAT32",
525 MESA_FORMAT_RGB_FLOAT16
,
526 "MESA_FORMAT_RGB_FLOAT16",
534 MESA_FORMAT_ALPHA_FLOAT32
,
535 "MESA_FORMAT_ALPHA_FLOAT32",
543 MESA_FORMAT_ALPHA_FLOAT16
,
544 "MESA_FORMAT_ALPHA_FLOAT16",
552 MESA_FORMAT_LUMINANCE_FLOAT32
,
553 "MESA_FORMAT_LUMINANCE_FLOAT32",
561 MESA_FORMAT_LUMINANCE_FLOAT16
,
562 "MESA_FORMAT_LUMINANCE_FLOAT16",
570 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
571 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
579 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
580 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
588 MESA_FORMAT_INTENSITY_FLOAT32
,
589 "MESA_FORMAT_INTENSITY_FLOAT32",
597 MESA_FORMAT_INTENSITY_FLOAT16
,
598 "MESA_FORMAT_INTENSITY_FLOAT16",
609 GL_SIGNED_NORMALIZED
,
615 MESA_FORMAT_SIGNED_RGBA8888
,
616 "MESA_FORMAT_SIGNED_RGBA8888",
618 GL_SIGNED_NORMALIZED
,
624 MESA_FORMAT_SIGNED_RGBA8888_REV
,
625 "MESA_FORMAT_SIGNED_RGBA8888_REV",
627 GL_SIGNED_NORMALIZED
,
633 MESA_FORMAT_SIGNED_RGBA_16
,
634 "MESA_FORMAT_SIGNED_RGBA_16",
636 GL_SIGNED_NORMALIZED
,
645 static const struct gl_format_info
*
646 _mesa_get_format_info(gl_format format
)
648 const struct gl_format_info
*info
= &format_info
[format
];
649 assert(info
->Name
== format
);
654 /** Return string name of format (for debugging) */
656 _mesa_get_format_name(gl_format format
)
658 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
659 ASSERT(info
->BytesPerBlock
);
660 return info
->StrName
;
666 * Return bytes needed to store a block of pixels in the given format.
667 * Normally, a block is 1x1 (a single pixel). But for compressed formats
668 * a block may be 4x4 or 8x4, etc.
671 _mesa_get_format_bytes(gl_format format
)
673 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
674 ASSERT(info
->BytesPerBlock
);
675 return info
->BytesPerBlock
;
680 * Return bits per component for the given format.
681 * \param format one of MESA_FORMAT_x
682 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
685 _mesa_get_format_bits(gl_format format
, GLenum pname
)
687 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
691 case GL_TEXTURE_RED_SIZE
:
692 case GL_RENDERBUFFER_RED_SIZE_EXT
:
693 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
694 return info
->RedBits
;
696 case GL_TEXTURE_GREEN_SIZE
:
697 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
698 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
699 return info
->GreenBits
;
701 case GL_TEXTURE_BLUE_SIZE
:
702 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
703 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
704 return info
->BlueBits
;
706 case GL_TEXTURE_ALPHA_SIZE
:
707 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
708 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
709 return info
->AlphaBits
;
710 case GL_TEXTURE_INTENSITY_SIZE
:
711 return info
->IntensityBits
;
712 case GL_TEXTURE_LUMINANCE_SIZE
:
713 return info
->LuminanceBits
;
715 case GL_TEXTURE_INDEX_SIZE_EXT
:
716 return info
->IndexBits
;
718 case GL_TEXTURE_DEPTH_SIZE_ARB
:
719 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
720 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
721 return info
->DepthBits
;
722 case GL_STENCIL_BITS
:
723 case GL_TEXTURE_STENCIL_SIZE_EXT
:
724 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
725 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
726 return info
->StencilBits
;
728 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
735 * Return the data type (or more specifically, the data representation)
736 * for the given format.
737 * The return value will be one of:
738 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
739 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
740 * GL_UNSIGNED_INT = an ordinary unsigned integer
741 * GL_FLOAT = an ordinary float
744 _mesa_get_format_datatype(gl_format format
)
746 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
747 return info
->DataType
;
752 * Return the basic format for the given type. The result will be
753 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
754 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
755 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
758 _mesa_get_format_base_format(gl_format format
)
760 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
761 return info
->BaseFormat
;
766 * Return the block size (in pixels) for the given format. Normally
767 * the block size is 1x1. But compressed formats will have block sizes
768 * of 4x4 or 8x4 pixels, etc.
769 * \param bw returns block width in pixels
770 * \param bh returns block height in pixels
773 _mesa_get_format_block_size(gl_format format
, GLuint
*bw
, GLuint
*bh
)
775 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
776 *bw
= info
->BlockWidth
;
777 *bh
= info
->BlockHeight
;
781 /** Is the given format a compressed format? */
783 _mesa_is_format_compressed(gl_format format
)
785 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
786 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
791 * Return color encoding for given format.
792 * \return GL_LINEAR or GL_SRGB
795 _mesa_get_format_color_encoding(gl_format format
)
797 /* XXX this info should be encoded in gl_format_info */
799 case MESA_FORMAT_SRGB8
:
800 case MESA_FORMAT_SRGBA8
:
801 case MESA_FORMAT_SARGB8
:
802 case MESA_FORMAT_SL8
:
803 case MESA_FORMAT_SLA8
:
804 case MESA_FORMAT_SRGB_DXT1
:
805 case MESA_FORMAT_SRGBA_DXT1
:
806 case MESA_FORMAT_SRGBA_DXT3
:
807 case MESA_FORMAT_SRGBA_DXT5
:
816 * Return number of bytes needed to store an image of the given size
817 * in the given format.
820 _mesa_format_image_size(gl_format format
, GLsizei width
,
821 GLsizei height
, GLsizei depth
)
823 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
824 /* Strictly speaking, a conditional isn't needed here */
825 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
826 /* compressed format */
827 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
828 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
829 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
830 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
835 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
843 _mesa_format_row_stride(gl_format format
, GLsizei width
)
845 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
846 /* Strictly speaking, a conditional isn't needed here */
847 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
848 /* compressed format */
849 const GLuint bw
= info
->BlockWidth
;
850 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
851 const GLint stride
= wblocks
* info
->BytesPerBlock
;
855 const GLint stride
= width
* info
->BytesPerBlock
;
863 * Do sanity checking of the format info table.
866 _mesa_test_formats(void)
870 assert(Elements(format_info
) == MESA_FORMAT_COUNT
);
872 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
873 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
876 assert(info
->Name
== i
);
878 if (info
->Name
== MESA_FORMAT_NONE
)
881 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
882 if (info
->RedBits
> 0) {
883 GLuint t
= info
->RedBits
+ info
->GreenBits
884 + info
->BlueBits
+ info
->AlphaBits
;
885 assert(t
/ 8 == info
->BytesPerBlock
);
889 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
890 info
->DataType
== GL_SIGNED_NORMALIZED
||
891 info
->DataType
== GL_UNSIGNED_INT
||
892 info
->DataType
== GL_FLOAT
);
894 if (info
->BaseFormat
== GL_RGB
) {
895 assert(info
->RedBits
> 0);
896 assert(info
->GreenBits
> 0);
897 assert(info
->BlueBits
> 0);
898 assert(info
->AlphaBits
== 0);
899 assert(info
->LuminanceBits
== 0);
900 assert(info
->IntensityBits
== 0);
902 else if (info
->BaseFormat
== GL_RGBA
) {
903 assert(info
->RedBits
> 0);
904 assert(info
->GreenBits
> 0);
905 assert(info
->BlueBits
> 0);
906 assert(info
->AlphaBits
> 0);
907 assert(info
->LuminanceBits
== 0);
908 assert(info
->IntensityBits
== 0);
910 else if (info
->BaseFormat
== GL_LUMINANCE
) {
911 assert(info
->RedBits
== 0);
912 assert(info
->GreenBits
== 0);
913 assert(info
->BlueBits
== 0);
914 assert(info
->AlphaBits
== 0);
915 assert(info
->LuminanceBits
> 0);
916 assert(info
->IntensityBits
== 0);
918 else if (info
->BaseFormat
== GL_INTENSITY
) {
919 assert(info
->RedBits
== 0);
920 assert(info
->GreenBits
== 0);
921 assert(info
->BlueBits
== 0);
922 assert(info
->AlphaBits
== 0);
923 assert(info
->LuminanceBits
== 0);
924 assert(info
->IntensityBits
> 0);
933 * Return datatype and number of components per texel for the given gl_format.
934 * Only used for mipmap generation code.
937 _mesa_format_to_type_and_comps(gl_format format
,
938 GLenum
*datatype
, GLuint
*comps
)
941 case MESA_FORMAT_RGBA8888
:
942 case MESA_FORMAT_RGBA8888_REV
:
943 case MESA_FORMAT_ARGB8888
:
944 case MESA_FORMAT_ARGB8888_REV
:
945 case MESA_FORMAT_XRGB8888
:
946 *datatype
= GL_UNSIGNED_BYTE
;
949 case MESA_FORMAT_RGB888
:
950 case MESA_FORMAT_BGR888
:
951 *datatype
= GL_UNSIGNED_BYTE
;
954 case MESA_FORMAT_RGB565
:
955 case MESA_FORMAT_RGB565_REV
:
956 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
960 case MESA_FORMAT_ARGB4444
:
961 case MESA_FORMAT_ARGB4444_REV
:
962 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
966 case MESA_FORMAT_ARGB1555
:
967 case MESA_FORMAT_ARGB1555_REV
:
968 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
972 case MESA_FORMAT_AL88
:
973 case MESA_FORMAT_AL88_REV
:
974 *datatype
= GL_UNSIGNED_BYTE
;
977 case MESA_FORMAT_RGB332
:
978 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
985 case MESA_FORMAT_CI8
:
986 *datatype
= GL_UNSIGNED_BYTE
;
990 case MESA_FORMAT_YCBCR
:
991 case MESA_FORMAT_YCBCR_REV
:
992 *datatype
= GL_UNSIGNED_SHORT
;
996 case MESA_FORMAT_Z24_S8
:
997 *datatype
= GL_UNSIGNED_INT
;
998 *comps
= 1; /* XXX OK? */
1001 case MESA_FORMAT_S8_Z24
:
1002 *datatype
= GL_UNSIGNED_INT
;
1003 *comps
= 1; /* XXX OK? */
1006 case MESA_FORMAT_Z16
:
1007 *datatype
= GL_UNSIGNED_SHORT
;
1011 case MESA_FORMAT_X8_Z24
:
1012 *datatype
= GL_UNSIGNED_INT
;
1016 case MESA_FORMAT_Z24_X8
:
1017 *datatype
= GL_UNSIGNED_INT
;
1021 case MESA_FORMAT_Z32
:
1022 *datatype
= GL_UNSIGNED_INT
;
1026 case MESA_FORMAT_DUDV8
:
1027 *datatype
= GL_BYTE
;
1031 case MESA_FORMAT_SIGNED_RGBA8888
:
1032 case MESA_FORMAT_SIGNED_RGBA8888_REV
:
1033 *datatype
= GL_BYTE
;
1036 case MESA_FORMAT_SIGNED_RGBA_16
:
1037 *datatype
= GL_SHORT
;
1041 #if FEATURE_EXT_texture_sRGB
1042 case MESA_FORMAT_SRGB8
:
1043 *datatype
= GL_UNSIGNED_BYTE
;
1046 case MESA_FORMAT_SRGBA8
:
1047 case MESA_FORMAT_SARGB8
:
1048 *datatype
= GL_UNSIGNED_BYTE
;
1051 case MESA_FORMAT_SL8
:
1052 *datatype
= GL_UNSIGNED_BYTE
;
1055 case MESA_FORMAT_SLA8
:
1056 *datatype
= GL_UNSIGNED_BYTE
;
1061 #if FEATURE_texture_fxt1
1062 case MESA_FORMAT_RGB_FXT1
:
1063 case MESA_FORMAT_RGBA_FXT1
:
1065 #if FEATURE_texture_s3tc
1066 case MESA_FORMAT_RGB_DXT1
:
1067 case MESA_FORMAT_RGBA_DXT1
:
1068 case MESA_FORMAT_RGBA_DXT3
:
1069 case MESA_FORMAT_RGBA_DXT5
:
1070 #if FEATURE_EXT_texture_sRGB
1071 case MESA_FORMAT_SRGB_DXT1
:
1072 case MESA_FORMAT_SRGBA_DXT1
:
1073 case MESA_FORMAT_SRGBA_DXT3
:
1074 case MESA_FORMAT_SRGBA_DXT5
:
1076 /* XXX generate error instead? */
1077 *datatype
= GL_UNSIGNED_BYTE
;
1082 case MESA_FORMAT_RGBA_FLOAT32
:
1083 *datatype
= GL_FLOAT
;
1086 case MESA_FORMAT_RGBA_FLOAT16
:
1087 *datatype
= GL_HALF_FLOAT_ARB
;
1090 case MESA_FORMAT_RGB_FLOAT32
:
1091 *datatype
= GL_FLOAT
;
1094 case MESA_FORMAT_RGB_FLOAT16
:
1095 *datatype
= GL_HALF_FLOAT_ARB
;
1098 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
1099 *datatype
= GL_FLOAT
;
1102 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
1103 *datatype
= GL_HALF_FLOAT_ARB
;
1106 case MESA_FORMAT_ALPHA_FLOAT32
:
1107 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1108 case MESA_FORMAT_INTENSITY_FLOAT32
:
1109 *datatype
= GL_FLOAT
;
1112 case MESA_FORMAT_ALPHA_FLOAT16
:
1113 case MESA_FORMAT_LUMINANCE_FLOAT16
:
1114 case MESA_FORMAT_INTENSITY_FLOAT16
:
1115 *datatype
= GL_HALF_FLOAT_ARB
;
1120 _mesa_problem(NULL
, "bad format in _mesa_format_to_type_and_comps");