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_YCBCR_MESA, GL_COLOR_INDEX,
43 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
48 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
49 * GL_UNSIGNED_INT, GL_SIGNED_INT, GL_FLOAT.
57 GLubyte LuminanceBits
;
58 GLubyte IntensityBits
;
64 * To describe compressed formats. If not compressed, Width=Height=1.
66 GLubyte BlockWidth
, BlockHeight
;
67 GLubyte BytesPerBlock
;
72 * Info about each format.
73 * These must be in the same order as the MESA_FORMAT_* enums so that
74 * we can do lookups without searching.
76 static struct gl_format_info format_info
[MESA_FORMAT_COUNT
] =
79 MESA_FORMAT_NONE
, /* Name */
80 GL_NONE
, /* BaseFormat */
81 GL_NONE
, /* DataType */
82 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
83 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
84 0, 0, 0 /* BlockWidth/Height,Bytes */
87 MESA_FORMAT_RGBA8888
, /* Name */
88 GL_RGBA
, /* BaseFormat */
89 GL_UNSIGNED_NORMALIZED
, /* DataType */
90 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
91 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
92 1, 1, 4 /* BlockWidth/Height,Bytes */
95 MESA_FORMAT_RGBA8888_REV
, /* Name */
96 GL_RGBA
, /* BaseFormat */
97 GL_UNSIGNED_NORMALIZED
, /* DataType */
98 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
99 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
100 1, 1, 4 /* BlockWidth/Height,Bytes */
103 MESA_FORMAT_ARGB8888
, /* Name */
104 GL_RGBA
, /* BaseFormat */
105 GL_UNSIGNED_NORMALIZED
, /* DataType */
106 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
107 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
108 1, 1, 4 /* BlockWidth/Height,Bytes */
111 MESA_FORMAT_ARGB8888_REV
, /* Name */
112 GL_RGBA
, /* BaseFormat */
113 GL_UNSIGNED_NORMALIZED
, /* DataType */
114 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
115 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
116 1, 1, 4 /* BlockWidth/Height,Bytes */
119 MESA_FORMAT_XRGB8888
, /* Name */
120 GL_RGB
, /* BaseFormat */
121 GL_UNSIGNED_NORMALIZED
, /* DataType */
122 8, 8, 8, 0, /* 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_RGB888
, /* Name */
128 GL_RGB
, /* BaseFormat */
129 GL_UNSIGNED_NORMALIZED
, /* DataType */
130 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
131 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
132 1, 1, 3 /* BlockWidth/Height,Bytes */
135 MESA_FORMAT_BGR888
, /* Name */
136 GL_RGB
, /* BaseFormat */
137 GL_UNSIGNED_NORMALIZED
, /* DataType */
138 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
139 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
140 1, 1, 3 /* BlockWidth/Height,Bytes */
143 MESA_FORMAT_RGB565
, /* Name */
144 GL_RGB
, /* BaseFormat */
145 GL_UNSIGNED_NORMALIZED
, /* DataType */
146 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
147 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
148 1, 1, 2 /* BlockWidth/Height,Bytes */
151 MESA_FORMAT_RGB565_REV
, /* Name */
152 GL_RGB
, /* BaseFormat */
153 GL_UNSIGNED_NORMALIZED
, /* DataType */
154 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
155 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
156 1, 1, 2 /* BlockWidth/Height,Bytes */
159 MESA_FORMAT_ARGB4444
, /* Name */
160 GL_RGBA
, /* BaseFormat */
161 GL_UNSIGNED_NORMALIZED
, /* DataType */
162 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
163 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
164 1, 1, 2 /* BlockWidth/Height,Bytes */
167 MESA_FORMAT_ARGB4444_REV
, /* Name */
168 GL_RGBA
, /* BaseFormat */
169 GL_UNSIGNED_NORMALIZED
, /* DataType */
170 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
171 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
172 1, 1, 2 /* BlockWidth/Height,Bytes */
175 MESA_FORMAT_RGBA5551
, /* Name */
176 GL_RGBA
, /* BaseFormat */
177 GL_UNSIGNED_NORMALIZED
, /* DataType */
178 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
179 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
180 1, 1, 2 /* BlockWidth/Height,Bytes */
183 MESA_FORMAT_ARGB1555
, /* Name */
184 GL_RGBA
, /* BaseFormat */
185 GL_UNSIGNED_NORMALIZED
, /* DataType */
186 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
187 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
188 1, 1, 2 /* BlockWidth/Height,Bytes */
191 MESA_FORMAT_ARGB1555_REV
, /* Name */
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_AL88
, /* Name */
200 GL_LUMINANCE_ALPHA
, /* BaseFormat */
201 GL_UNSIGNED_NORMALIZED
, /* DataType */
202 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
203 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
204 1, 1, 2 /* BlockWidth/Height,Bytes */
207 MESA_FORMAT_AL88_REV
, /* Name */
208 GL_LUMINANCE_ALPHA
, /* BaseFormat */
209 GL_UNSIGNED_NORMALIZED
, /* DataType */
210 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
211 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
212 1, 1, 2 /* BlockWidth/Height,Bytes */
215 MESA_FORMAT_RGB332
, /* Name */
216 GL_RGB
, /* BaseFormat */
217 GL_UNSIGNED_NORMALIZED
, /* DataType */
218 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
219 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
220 1, 1, 1 /* BlockWidth/Height,Bytes */
223 MESA_FORMAT_A8
, /* Name */
224 GL_ALPHA
, /* BaseFormat */
225 GL_UNSIGNED_NORMALIZED
, /* DataType */
226 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
227 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
228 1, 1, 1 /* BlockWidth/Height,Bytes */
231 MESA_FORMAT_L8
, /* Name */
232 GL_LUMINANCE
, /* BaseFormat */
233 GL_UNSIGNED_NORMALIZED
, /* DataType */
234 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
235 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
236 1, 1, 1 /* BlockWidth/Height,Bytes */
239 MESA_FORMAT_I8
, /* Name */
240 GL_INTENSITY
, /* BaseFormat */
241 GL_UNSIGNED_NORMALIZED
, /* DataType */
242 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
243 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
244 1, 1, 1 /* BlockWidth/Height,Bytes */
247 MESA_FORMAT_CI8
, /* Name */
248 GL_COLOR_INDEX
, /* BaseFormat */
249 GL_UNSIGNED_INT
, /* DataType */
250 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
251 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
252 1, 1, 1 /* BlockWidth/Height,Bytes */
255 MESA_FORMAT_YCBCR
, /* Name */
256 GL_YCBCR_MESA
, /* BaseFormat */
257 GL_UNSIGNED_NORMALIZED
, /* DataType */
258 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
259 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
260 1, 1, 2 /* BlockWidth/Height,Bytes */
263 MESA_FORMAT_YCBCR_REV
, /* Name */
264 GL_YCBCR_MESA
, /* BaseFormat */
265 GL_UNSIGNED_NORMALIZED
, /* DataType */
266 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
267 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
268 1, 1, 2 /* BlockWidth/Height,Bytes */
271 MESA_FORMAT_Z24_S8
, /* Name */
272 GL_DEPTH_STENCIL
, /* BaseFormat */
273 GL_UNSIGNED_INT
, /* DataType */
274 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
275 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
276 1, 1, 4 /* BlockWidth/Height,Bytes */
279 MESA_FORMAT_S8_Z24
, /* Name */
280 GL_DEPTH_STENCIL
, /* BaseFormat */
281 GL_UNSIGNED_INT
, /* DataType */
282 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
283 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
284 1, 1, 4 /* BlockWidth/Height,Bytes */
287 MESA_FORMAT_Z16
, /* Name */
288 GL_DEPTH_COMPONENT
, /* BaseFormat */
289 GL_UNSIGNED_INT
, /* DataType */
290 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
291 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
292 1, 1, 2 /* BlockWidth/Height,Bytes */
295 MESA_FORMAT_X8_Z24
, /* Name */
296 GL_DEPTH_COMPONENT
, /* BaseFormat */
297 GL_UNSIGNED_INT
, /* DataType */
298 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
299 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
300 1, 1, 4 /* BlockWidth/Height,Bytes */
303 MESA_FORMAT_Z32
, /* Name */
304 GL_DEPTH_COMPONENT
, /* BaseFormat */
305 GL_UNSIGNED_INT
, /* DataType */
306 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
307 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
308 1, 1, 4 /* BlockWidth/Height,Bytes */
311 MESA_FORMAT_S8
, /* Name */
312 GL_STENCIL_INDEX
, /* BaseFormat */
313 GL_UNSIGNED_INT
, /* DataType */
314 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
315 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
316 1, 1, 1 /* BlockWidth/Height,Bytes */
321 GL_UNSIGNED_NORMALIZED
,
329 GL_UNSIGNED_NORMALIZED
,
337 GL_UNSIGNED_NORMALIZED
,
345 GL_UNSIGNED_NORMALIZED
,
353 GL_UNSIGNED_NORMALIZED
,
359 MESA_FORMAT_SRGB_DXT1
, /* Name */
360 GL_RGB
, /* BaseFormat */
361 GL_UNSIGNED_NORMALIZED
, /* DataType */
362 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
363 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
364 4, 4, 8 /* 8 bytes per 4x4 block */
367 MESA_FORMAT_SRGBA_DXT1
,
369 GL_UNSIGNED_NORMALIZED
,
372 4, 4, 8 /* 8 bytes per 4x4 block */
375 MESA_FORMAT_SRGBA_DXT3
,
377 GL_UNSIGNED_NORMALIZED
,
380 4, 4, 16 /* 16 bytes per 4x4 block */
383 MESA_FORMAT_SRGBA_DXT5
,
385 GL_UNSIGNED_NORMALIZED
,
388 4, 4, 16 /* 16 bytes per 4x4 block */
392 MESA_FORMAT_RGB_FXT1
,
394 GL_UNSIGNED_NORMALIZED
,
397 8, 4, 16 /* 16 bytes per 8x4 block */
400 MESA_FORMAT_RGBA_FXT1
,
402 GL_UNSIGNED_NORMALIZED
,
405 8, 4, 16 /* 16 bytes per 8x4 block */
409 MESA_FORMAT_RGB_DXT1
, /* Name */
410 GL_RGB
, /* BaseFormat */
411 GL_UNSIGNED_NORMALIZED
, /* DataType */
412 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
413 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
414 4, 4, 8 /* 8 bytes per 4x4 block */
417 MESA_FORMAT_RGBA_DXT1
,
419 GL_UNSIGNED_NORMALIZED
,
422 4, 4, 8 /* 8 bytes per 4x4 block */
425 MESA_FORMAT_RGBA_DXT3
,
427 GL_UNSIGNED_NORMALIZED
,
430 4, 4, 16 /* 16 bytes per 4x4 block */
433 MESA_FORMAT_RGBA_DXT5
,
435 GL_UNSIGNED_NORMALIZED
,
438 4, 4, 16 /* 16 bytes per 4x4 block */
441 MESA_FORMAT_RGBA_FLOAT32
,
449 MESA_FORMAT_RGBA_FLOAT16
,
457 MESA_FORMAT_RGB_FLOAT32
,
465 MESA_FORMAT_RGB_FLOAT16
,
473 MESA_FORMAT_ALPHA_FLOAT32
,
481 MESA_FORMAT_ALPHA_FLOAT16
,
489 MESA_FORMAT_LUMINANCE_FLOAT32
,
497 MESA_FORMAT_LUMINANCE_FLOAT16
,
505 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
,
513 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
,
521 MESA_FORMAT_INTENSITY_FLOAT32
,
529 MESA_FORMAT_INTENSITY_FLOAT16
,
539 GL_SIGNED_NORMALIZED
,
545 MESA_FORMAT_SIGNED_RGBA8888
,
547 GL_SIGNED_NORMALIZED
,
553 MESA_FORMAT_SIGNED_RGBA8888_REV
,
555 GL_SIGNED_NORMALIZED
,
561 MESA_FORMAT_SIGNED_RGBA_16
,
563 GL_SIGNED_NORMALIZED
,
572 static const struct gl_format_info
*
573 _mesa_get_format_info(gl_format format
)
575 const struct gl_format_info
*info
= &format_info
[format
];
576 assert(info
->Name
== format
);
582 * Return bytes needed to store a block of pixels in the given format.
583 * Normally, a block is 1x1 (a single pixel). But for compressed formats
584 * a block may be 4x4 or 8x4, etc.
587 _mesa_get_format_bytes(gl_format format
)
589 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
590 ASSERT(info
->BytesPerBlock
);
591 return info
->BytesPerBlock
;
596 * Return bits per component for the given format.
597 * \param format one of MESA_FORMAT_x
598 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
601 _mesa_get_format_bits(gl_format format
, GLenum pname
)
603 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
607 case GL_TEXTURE_RED_SIZE
:
608 case GL_RENDERBUFFER_RED_SIZE_EXT
:
609 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
610 return info
->RedBits
;
612 case GL_TEXTURE_GREEN_SIZE
:
613 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
614 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
615 return info
->GreenBits
;
617 case GL_TEXTURE_BLUE_SIZE
:
618 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
619 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
620 return info
->BlueBits
;
622 case GL_TEXTURE_ALPHA_SIZE
:
623 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
624 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
625 return info
->AlphaBits
;
626 case GL_TEXTURE_INTENSITY_SIZE
:
627 return info
->IntensityBits
;
628 case GL_TEXTURE_LUMINANCE_SIZE
:
629 return info
->LuminanceBits
;
631 case GL_TEXTURE_INDEX_SIZE_EXT
:
632 return info
->IndexBits
;
634 case GL_TEXTURE_DEPTH_SIZE_ARB
:
635 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
636 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
637 return info
->DepthBits
;
638 case GL_STENCIL_BITS
:
639 case GL_TEXTURE_STENCIL_SIZE_EXT
:
640 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
641 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
642 return info
->StencilBits
;
644 _mesa_problem(NULL
, "bad pname in _mesa_get_format_bits()");
651 * Return the data type (or more specifically, the data representation)
652 * for the given format.
653 * The return value will be one of:
654 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
655 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
656 * GL_UNSIGNED_INT = an ordinary unsigned integer
657 * GL_FLOAT = an ordinary float
660 _mesa_get_format_datatype(gl_format format
)
662 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
663 return info
->DataType
;
668 * Return the basic format for the given type. The result will be
669 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
670 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
671 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
674 _mesa_get_format_base_format(gl_format format
)
676 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
677 return info
->BaseFormat
;
681 /** Is the given format a compressed format? */
683 _mesa_is_format_compressed(gl_format format
)
685 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
686 return info
->BlockWidth
> 1 || info
->BlockHeight
> 1;
691 * Return color encoding for given format.
692 * \return GL_LINEAR or GL_SRGB
695 _mesa_get_format_color_encoding(gl_format format
)
697 /* XXX this info should be encoded in gl_format_info */
699 case MESA_FORMAT_SRGB8
:
700 case MESA_FORMAT_SRGBA8
:
701 case MESA_FORMAT_SARGB8
:
702 case MESA_FORMAT_SL8
:
703 case MESA_FORMAT_SLA8
:
704 case MESA_FORMAT_SRGB_DXT1
:
705 case MESA_FORMAT_SRGBA_DXT1
:
706 case MESA_FORMAT_SRGBA_DXT3
:
707 case MESA_FORMAT_SRGBA_DXT5
:
716 * Return number of bytes needed to store an image of the given size
717 * in the given format.
720 _mesa_format_image_size(gl_format format
, GLsizei width
,
721 GLsizei height
, GLsizei depth
)
723 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
724 /* Strictly speaking, a conditional isn't needed here */
725 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
726 /* compressed format */
727 const GLuint bw
= info
->BlockWidth
, bh
= info
->BlockHeight
;
728 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
729 const GLuint hblocks
= (height
+ bh
- 1) / bh
;
730 const GLuint sz
= wblocks
* hblocks
* info
->BytesPerBlock
;
735 const GLuint sz
= width
* height
* depth
* info
->BytesPerBlock
;
743 _mesa_format_row_stride(gl_format format
, GLsizei width
)
745 const struct gl_format_info
*info
= _mesa_get_format_info(format
);
746 /* Strictly speaking, a conditional isn't needed here */
747 if (info
->BlockWidth
> 1 || info
->BlockHeight
> 1) {
748 /* compressed format */
749 const GLuint bw
= info
->BlockWidth
;
750 const GLuint wblocks
= (width
+ bw
- 1) / bw
;
751 const GLint stride
= wblocks
* info
->BytesPerBlock
;
755 const GLint stride
= width
* info
->BytesPerBlock
;
763 * Do sanity checking of the format info table.
766 _mesa_test_formats(void)
770 assert(Elements(format_info
) == MESA_FORMAT_COUNT
);
772 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
773 const struct gl_format_info
*info
= _mesa_get_format_info(i
);
776 assert(info
->Name
== i
);
778 if (info
->Name
== MESA_FORMAT_NONE
)
781 if (info
->BlockWidth
== 1 && info
->BlockHeight
== 1) {
782 if (info
->RedBits
> 0) {
783 GLuint t
= info
->RedBits
+ info
->GreenBits
784 + info
->BlueBits
+ info
->AlphaBits
;
785 assert(t
/ 8 == info
->BytesPerBlock
);
789 assert(info
->DataType
== GL_UNSIGNED_NORMALIZED
||
790 info
->DataType
== GL_SIGNED_NORMALIZED
||
791 info
->DataType
== GL_UNSIGNED_INT
||
792 info
->DataType
== GL_FLOAT
);
794 if (info
->BaseFormat
== GL_RGB
) {
795 assert(info
->RedBits
> 0);
796 assert(info
->GreenBits
> 0);
797 assert(info
->BlueBits
> 0);
798 assert(info
->AlphaBits
== 0);
799 assert(info
->LuminanceBits
== 0);
800 assert(info
->IntensityBits
== 0);
802 else if (info
->BaseFormat
== GL_RGBA
) {
803 assert(info
->RedBits
> 0);
804 assert(info
->GreenBits
> 0);
805 assert(info
->BlueBits
> 0);
806 assert(info
->AlphaBits
> 0);
807 assert(info
->LuminanceBits
== 0);
808 assert(info
->IntensityBits
== 0);
810 else if (info
->BaseFormat
== GL_LUMINANCE
) {
811 assert(info
->RedBits
== 0);
812 assert(info
->GreenBits
== 0);
813 assert(info
->BlueBits
== 0);
814 assert(info
->AlphaBits
== 0);
815 assert(info
->LuminanceBits
> 0);
816 assert(info
->IntensityBits
== 0);
818 else if (info
->BaseFormat
== GL_INTENSITY
) {
819 assert(info
->RedBits
== 0);
820 assert(info
->GreenBits
== 0);
821 assert(info
->BlueBits
== 0);
822 assert(info
->AlphaBits
== 0);
823 assert(info
->LuminanceBits
== 0);
824 assert(info
->IntensityBits
> 0);
833 * Return datatype and number of components per texel for the given gl_format.
834 * Only used for mipmap generation code.
837 _mesa_format_to_type_and_comps(gl_format format
,
838 GLenum
*datatype
, GLuint
*comps
)
841 case MESA_FORMAT_RGBA8888
:
842 case MESA_FORMAT_RGBA8888_REV
:
843 case MESA_FORMAT_ARGB8888
:
844 case MESA_FORMAT_ARGB8888_REV
:
845 case MESA_FORMAT_XRGB8888
:
846 *datatype
= GL_UNSIGNED_BYTE
;
849 case MESA_FORMAT_RGB888
:
850 case MESA_FORMAT_BGR888
:
851 *datatype
= GL_UNSIGNED_BYTE
;
854 case MESA_FORMAT_RGB565
:
855 case MESA_FORMAT_RGB565_REV
:
856 *datatype
= GL_UNSIGNED_SHORT_5_6_5
;
860 case MESA_FORMAT_ARGB4444
:
861 case MESA_FORMAT_ARGB4444_REV
:
862 *datatype
= GL_UNSIGNED_SHORT_4_4_4_4
;
866 case MESA_FORMAT_ARGB1555
:
867 case MESA_FORMAT_ARGB1555_REV
:
868 *datatype
= GL_UNSIGNED_SHORT_1_5_5_5_REV
;
872 case MESA_FORMAT_AL88
:
873 case MESA_FORMAT_AL88_REV
:
874 *datatype
= GL_UNSIGNED_BYTE
;
877 case MESA_FORMAT_RGB332
:
878 *datatype
= GL_UNSIGNED_BYTE_3_3_2
;
885 case MESA_FORMAT_CI8
:
886 *datatype
= GL_UNSIGNED_BYTE
;
890 case MESA_FORMAT_YCBCR
:
891 case MESA_FORMAT_YCBCR_REV
:
892 *datatype
= GL_UNSIGNED_SHORT
;
896 case MESA_FORMAT_Z24_S8
:
897 *datatype
= GL_UNSIGNED_INT
;
898 *comps
= 1; /* XXX OK? */
901 case MESA_FORMAT_S8_Z24
:
902 *datatype
= GL_UNSIGNED_INT
;
903 *comps
= 1; /* XXX OK? */
906 case MESA_FORMAT_Z16
:
907 *datatype
= GL_UNSIGNED_SHORT
;
911 case MESA_FORMAT_X8_Z24
:
912 *datatype
= GL_UNSIGNED_INT
;
916 case MESA_FORMAT_Z32
:
917 *datatype
= GL_UNSIGNED_INT
;
921 case MESA_FORMAT_DUDV8
:
926 case MESA_FORMAT_SIGNED_RGBA8888
:
927 case MESA_FORMAT_SIGNED_RGBA8888_REV
:
931 case MESA_FORMAT_SIGNED_RGBA_16
:
932 *datatype
= GL_SHORT
;
936 #if FEATURE_EXT_texture_sRGB
937 case MESA_FORMAT_SRGB8
:
938 *datatype
= GL_UNSIGNED_BYTE
;
941 case MESA_FORMAT_SRGBA8
:
942 case MESA_FORMAT_SARGB8
:
943 *datatype
= GL_UNSIGNED_BYTE
;
946 case MESA_FORMAT_SL8
:
947 *datatype
= GL_UNSIGNED_BYTE
;
950 case MESA_FORMAT_SLA8
:
951 *datatype
= GL_UNSIGNED_BYTE
;
956 #if FEATURE_texture_fxt1
957 case MESA_FORMAT_RGB_FXT1
:
958 case MESA_FORMAT_RGBA_FXT1
:
960 #if FEATURE_texture_s3tc
961 case MESA_FORMAT_RGB_DXT1
:
962 case MESA_FORMAT_RGBA_DXT1
:
963 case MESA_FORMAT_RGBA_DXT3
:
964 case MESA_FORMAT_RGBA_DXT5
:
965 #if FEATURE_EXT_texture_sRGB
966 case MESA_FORMAT_SRGB_DXT1
:
967 case MESA_FORMAT_SRGBA_DXT1
:
968 case MESA_FORMAT_SRGBA_DXT3
:
969 case MESA_FORMAT_SRGBA_DXT5
:
971 /* XXX generate error instead? */
972 *datatype
= GL_UNSIGNED_BYTE
;
977 case MESA_FORMAT_RGBA_FLOAT32
:
978 *datatype
= GL_FLOAT
;
981 case MESA_FORMAT_RGBA_FLOAT16
:
982 *datatype
= GL_HALF_FLOAT_ARB
;
985 case MESA_FORMAT_RGB_FLOAT32
:
986 *datatype
= GL_FLOAT
;
989 case MESA_FORMAT_RGB_FLOAT16
:
990 *datatype
= GL_HALF_FLOAT_ARB
;
993 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
:
994 *datatype
= GL_FLOAT
;
997 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
:
998 *datatype
= GL_HALF_FLOAT_ARB
;
1001 case MESA_FORMAT_ALPHA_FLOAT32
:
1002 case MESA_FORMAT_LUMINANCE_FLOAT32
:
1003 case MESA_FORMAT_INTENSITY_FLOAT32
:
1004 *datatype
= GL_FLOAT
;
1007 case MESA_FORMAT_ALPHA_FLOAT16
:
1008 case MESA_FORMAT_LUMINANCE_FLOAT16
:
1009 case MESA_FORMAT_INTENSITY_FLOAT16
:
1010 *datatype
= GL_HALF_FLOAT_ARB
;
1015 _mesa_problem(NULL
, "bad format in _mesa_format_to_type_and_comps");