mesa: added _mesa_get_uncompressed_format(), _mesa_format_num_components()
[mesa.git] / src / mesa / main / formats.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.7
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
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 * 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.
24 */
25
26
27 #include "imports.h"
28 #include "formats.h"
29 #include "mfeatures.h"
30
31
32 /**
33 * Information about texture formats.
34 */
35 struct gl_format_info
36 {
37 gl_format Name;
38
39 /** text name for debugging */
40 const char *StrName;
41
42 /**
43 * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
44 * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
45 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL, GL_DUDV_ATI.
46 */
47 GLenum BaseFormat;
48
49 /**
50 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED,
51 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
52 */
53 GLenum DataType;
54
55 GLubyte RedBits;
56 GLubyte GreenBits;
57 GLubyte BlueBits;
58 GLubyte AlphaBits;
59 GLubyte LuminanceBits;
60 GLubyte IntensityBits;
61 GLubyte IndexBits;
62 GLubyte DepthBits;
63 GLubyte StencilBits;
64
65 /**
66 * To describe compressed formats. If not compressed, Width=Height=1.
67 */
68 GLubyte BlockWidth, BlockHeight;
69 GLubyte BytesPerBlock;
70 };
71
72
73 /**
74 * Info about each format.
75 * These must be in the same order as the MESA_FORMAT_* enums so that
76 * we can do lookups without searching.
77 */
78 static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
79 {
80 {
81 MESA_FORMAT_NONE, /* Name */
82 "MESA_FORMAT_NONE", /* StrName */
83 GL_NONE, /* BaseFormat */
84 GL_NONE, /* DataType */
85 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
86 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
87 0, 0, 0 /* BlockWidth/Height,Bytes */
88 },
89 {
90 MESA_FORMAT_RGBA8888, /* Name */
91 "MESA_FORMAT_RGBA8888", /* StrName */
92 GL_RGBA, /* BaseFormat */
93 GL_UNSIGNED_NORMALIZED, /* DataType */
94 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
95 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
96 1, 1, 4 /* BlockWidth/Height,Bytes */
97 },
98 {
99 MESA_FORMAT_RGBA8888_REV, /* Name */
100 "MESA_FORMAT_RGBA8888_REV", /* StrName */
101 GL_RGBA, /* BaseFormat */
102 GL_UNSIGNED_NORMALIZED, /* DataType */
103 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
104 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
105 1, 1, 4 /* BlockWidth/Height,Bytes */
106 },
107 {
108 MESA_FORMAT_ARGB8888, /* Name */
109 "MESA_FORMAT_ARGB8888", /* StrName */
110 GL_RGBA, /* BaseFormat */
111 GL_UNSIGNED_NORMALIZED, /* DataType */
112 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
113 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
114 1, 1, 4 /* BlockWidth/Height,Bytes */
115 },
116 {
117 MESA_FORMAT_ARGB8888_REV, /* Name */
118 "MESA_FORMAT_ARGB8888_REV", /* StrName */
119 GL_RGBA, /* BaseFormat */
120 GL_UNSIGNED_NORMALIZED, /* DataType */
121 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
122 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
123 1, 1, 4 /* BlockWidth/Height,Bytes */
124 },
125 {
126 MESA_FORMAT_XRGB8888, /* Name */
127 "MESA_FORMAT_XRGB8888", /* StrName */
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, 4 /* BlockWidth/Height,Bytes */
133 },
134 {
135 MESA_FORMAT_XRGB8888_REV, /* Name */
136 "MESA_FORMAT_XRGB8888_REV", /* StrName */
137 GL_RGB, /* BaseFormat */
138 GL_UNSIGNED_NORMALIZED, /* DataType */
139 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
140 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
141 1, 1, 4 /* BlockWidth/Height,Bytes */
142 },
143 {
144 MESA_FORMAT_RGB888, /* Name */
145 "MESA_FORMAT_RGB888", /* StrName */
146 GL_RGB, /* BaseFormat */
147 GL_UNSIGNED_NORMALIZED, /* DataType */
148 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
149 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
150 1, 1, 3 /* BlockWidth/Height,Bytes */
151 },
152 {
153 MESA_FORMAT_BGR888, /* Name */
154 "MESA_FORMAT_BGR888", /* StrName */
155 GL_RGB, /* BaseFormat */
156 GL_UNSIGNED_NORMALIZED, /* DataType */
157 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
158 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
159 1, 1, 3 /* BlockWidth/Height,Bytes */
160 },
161 {
162 MESA_FORMAT_RGB565, /* Name */
163 "MESA_FORMAT_RGB565", /* StrName */
164 GL_RGB, /* BaseFormat */
165 GL_UNSIGNED_NORMALIZED, /* DataType */
166 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
167 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
168 1, 1, 2 /* BlockWidth/Height,Bytes */
169 },
170 {
171 MESA_FORMAT_RGB565_REV, /* Name */
172 "MESA_FORMAT_RGB565_REV", /* StrName */
173 GL_RGB, /* BaseFormat */
174 GL_UNSIGNED_NORMALIZED, /* DataType */
175 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
176 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
177 1, 1, 2 /* BlockWidth/Height,Bytes */
178 },
179 {
180 MESA_FORMAT_ARGB4444, /* Name */
181 "MESA_FORMAT_ARGB4444", /* StrName */
182 GL_RGBA, /* BaseFormat */
183 GL_UNSIGNED_NORMALIZED, /* DataType */
184 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
185 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
186 1, 1, 2 /* BlockWidth/Height,Bytes */
187 },
188 {
189 MESA_FORMAT_ARGB4444_REV, /* Name */
190 "MESA_FORMAT_ARGB4444_REV", /* StrName */
191 GL_RGBA, /* BaseFormat */
192 GL_UNSIGNED_NORMALIZED, /* DataType */
193 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
194 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
195 1, 1, 2 /* BlockWidth/Height,Bytes */
196 },
197 {
198 MESA_FORMAT_RGBA5551, /* Name */
199 "MESA_FORMAT_RGBA5551", /* StrName */
200 GL_RGBA, /* BaseFormat */
201 GL_UNSIGNED_NORMALIZED, /* DataType */
202 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
203 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
204 1, 1, 2 /* BlockWidth/Height,Bytes */
205 },
206 {
207 MESA_FORMAT_ARGB1555, /* Name */
208 "MESA_FORMAT_ARGB1555", /* StrName */
209 GL_RGBA, /* BaseFormat */
210 GL_UNSIGNED_NORMALIZED, /* DataType */
211 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
212 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
213 1, 1, 2 /* BlockWidth/Height,Bytes */
214 },
215 {
216 MESA_FORMAT_ARGB1555_REV, /* Name */
217 "MESA_FORMAT_ARGB1555_REV", /* StrName */
218 GL_RGBA, /* BaseFormat */
219 GL_UNSIGNED_NORMALIZED, /* DataType */
220 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
221 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
222 1, 1, 2 /* BlockWidth/Height,Bytes */
223 },
224 {
225 MESA_FORMAT_AL44, /* Name */
226 "MESA_FORMAT_AL44", /* StrName */
227 GL_LUMINANCE_ALPHA, /* BaseFormat */
228 GL_UNSIGNED_NORMALIZED, /* DataType */
229 0, 0, 0, 4, /* Red/Green/Blue/AlphaBits */
230 4, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
231 1, 1, 1 /* BlockWidth/Height,Bytes */
232 },
233 {
234 MESA_FORMAT_AL88, /* Name */
235 "MESA_FORMAT_AL88", /* StrName */
236 GL_LUMINANCE_ALPHA, /* BaseFormat */
237 GL_UNSIGNED_NORMALIZED, /* DataType */
238 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
239 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
240 1, 1, 2 /* BlockWidth/Height,Bytes */
241 },
242 {
243 MESA_FORMAT_AL88_REV, /* Name */
244 "MESA_FORMAT_AL88_REV", /* StrName */
245 GL_LUMINANCE_ALPHA, /* BaseFormat */
246 GL_UNSIGNED_NORMALIZED, /* DataType */
247 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
248 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
249 1, 1, 2 /* BlockWidth/Height,Bytes */
250 },
251 {
252 MESA_FORMAT_AL1616, /* Name */
253 "MESA_FORMAT_AL1616", /* StrName */
254 GL_LUMINANCE_ALPHA, /* BaseFormat */
255 GL_UNSIGNED_NORMALIZED, /* DataType */
256 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
257 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
258 1, 1, 4 /* BlockWidth/Height,Bytes */
259 },
260 {
261 MESA_FORMAT_AL1616_REV, /* Name */
262 "MESA_FORMAT_AL1616_REV", /* StrName */
263 GL_LUMINANCE_ALPHA, /* BaseFormat */
264 GL_UNSIGNED_NORMALIZED, /* DataType */
265 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
266 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
267 1, 1, 4 /* BlockWidth/Height,Bytes */
268 },
269 {
270 MESA_FORMAT_RGB332, /* Name */
271 "MESA_FORMAT_RGB332", /* StrName */
272 GL_RGB, /* BaseFormat */
273 GL_UNSIGNED_NORMALIZED, /* DataType */
274 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
275 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
276 1, 1, 1 /* BlockWidth/Height,Bytes */
277 },
278 {
279 MESA_FORMAT_A8, /* Name */
280 "MESA_FORMAT_A8", /* StrName */
281 GL_ALPHA, /* BaseFormat */
282 GL_UNSIGNED_NORMALIZED, /* DataType */
283 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
284 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
285 1, 1, 1 /* BlockWidth/Height,Bytes */
286 },
287 {
288 MESA_FORMAT_A16, /* Name */
289 "MESA_FORMAT_A16", /* StrName */
290 GL_ALPHA, /* BaseFormat */
291 GL_UNSIGNED_NORMALIZED, /* DataType */
292 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
293 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
294 1, 1, 2 /* BlockWidth/Height,Bytes */
295 },
296 {
297 MESA_FORMAT_L8, /* Name */
298 "MESA_FORMAT_L8", /* StrName */
299 GL_LUMINANCE, /* BaseFormat */
300 GL_UNSIGNED_NORMALIZED, /* DataType */
301 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
302 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
303 1, 1, 1 /* BlockWidth/Height,Bytes */
304 },
305 {
306 MESA_FORMAT_L16, /* Name */
307 "MESA_FORMAT_L16", /* StrName */
308 GL_LUMINANCE, /* BaseFormat */
309 GL_UNSIGNED_NORMALIZED, /* DataType */
310 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
311 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
312 1, 1, 2 /* BlockWidth/Height,Bytes */
313 },
314 {
315 MESA_FORMAT_I8, /* Name */
316 "MESA_FORMAT_I8", /* StrName */
317 GL_INTENSITY, /* BaseFormat */
318 GL_UNSIGNED_NORMALIZED, /* DataType */
319 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
320 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
321 1, 1, 1 /* BlockWidth/Height,Bytes */
322 },
323 {
324 MESA_FORMAT_I16, /* Name */
325 "MESA_FORMAT_I16", /* StrName */
326 GL_INTENSITY, /* BaseFormat */
327 GL_UNSIGNED_NORMALIZED, /* DataType */
328 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
329 0, 16, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
330 1, 1, 2 /* BlockWidth/Height,Bytes */
331 },
332 {
333 MESA_FORMAT_YCBCR, /* Name */
334 "MESA_FORMAT_YCBCR", /* StrName */
335 GL_YCBCR_MESA, /* BaseFormat */
336 GL_UNSIGNED_NORMALIZED, /* DataType */
337 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
338 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
339 1, 1, 2 /* BlockWidth/Height,Bytes */
340 },
341 {
342 MESA_FORMAT_YCBCR_REV, /* Name */
343 "MESA_FORMAT_YCBCR_REV", /* StrName */
344 GL_YCBCR_MESA, /* BaseFormat */
345 GL_UNSIGNED_NORMALIZED, /* DataType */
346 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
347 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
348 1, 1, 2 /* BlockWidth/Height,Bytes */
349 },
350 {
351 MESA_FORMAT_R8,
352 "MESA_FORMAT_R8",
353 GL_RED,
354 GL_UNSIGNED_NORMALIZED,
355 8, 0, 0, 0,
356 0, 0, 0, 0, 0,
357 1, 1, 1
358 },
359 {
360 MESA_FORMAT_RG88,
361 "MESA_FORMAT_RG88",
362 GL_RG,
363 GL_UNSIGNED_NORMALIZED,
364 8, 8, 0, 0,
365 0, 0, 0, 0, 0,
366 1, 1, 2
367 },
368 {
369 MESA_FORMAT_RG88_REV,
370 "MESA_FORMAT_RG88_REV",
371 GL_RG,
372 GL_UNSIGNED_NORMALIZED,
373 8, 8, 0, 0,
374 0, 0, 0, 0, 0,
375 1, 1, 2
376 },
377 {
378 MESA_FORMAT_R16,
379 "MESA_FORMAT_R16",
380 GL_RED,
381 GL_UNSIGNED_NORMALIZED,
382 16, 0, 0, 0,
383 0, 0, 0, 0, 0,
384 1, 1, 2
385 },
386 {
387 MESA_FORMAT_RG1616,
388 "MESA_FORMAT_RG1616",
389 GL_RG,
390 GL_UNSIGNED_NORMALIZED,
391 16, 16, 0, 0,
392 0, 0, 0, 0, 0,
393 1, 1, 4
394 },
395 {
396 MESA_FORMAT_RG1616_REV,
397 "MESA_FORMAT_RG1616_REV",
398 GL_RG,
399 GL_UNSIGNED_NORMALIZED,
400 16, 16, 0, 0,
401 0, 0, 0, 0, 0,
402 1, 1, 4
403 },
404 {
405 MESA_FORMAT_ARGB2101010,
406 "MESA_FORMAT_ARGB2101010",
407 GL_RGBA,
408 GL_UNSIGNED_NORMALIZED,
409 10, 10, 10, 2,
410 0, 0, 0, 0, 0,
411 1, 1, 4
412 },
413 {
414 MESA_FORMAT_Z24_S8, /* Name */
415 "MESA_FORMAT_Z24_S8", /* StrName */
416 GL_DEPTH_STENCIL, /* BaseFormat */
417 GL_UNSIGNED_INT, /* DataType */
418 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
419 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
420 1, 1, 4 /* BlockWidth/Height,Bytes */
421 },
422 {
423 MESA_FORMAT_S8_Z24, /* Name */
424 "MESA_FORMAT_S8_Z24", /* StrName */
425 GL_DEPTH_STENCIL, /* BaseFormat */
426 GL_UNSIGNED_INT, /* DataType */
427 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
428 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
429 1, 1, 4 /* BlockWidth/Height,Bytes */
430 },
431 {
432 MESA_FORMAT_Z16, /* Name */
433 "MESA_FORMAT_Z16", /* StrName */
434 GL_DEPTH_COMPONENT, /* BaseFormat */
435 GL_UNSIGNED_INT, /* DataType */
436 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
437 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
438 1, 1, 2 /* BlockWidth/Height,Bytes */
439 },
440 {
441 MESA_FORMAT_X8_Z24, /* Name */
442 "MESA_FORMAT_X8_Z24", /* StrName */
443 GL_DEPTH_COMPONENT, /* BaseFormat */
444 GL_UNSIGNED_INT, /* DataType */
445 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
446 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
447 1, 1, 4 /* BlockWidth/Height,Bytes */
448 },
449 {
450 MESA_FORMAT_Z24_X8, /* Name */
451 "MESA_FORMAT_Z24_X8", /* StrName */
452 GL_DEPTH_COMPONENT, /* BaseFormat */
453 GL_UNSIGNED_INT, /* DataType */
454 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
455 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
456 1, 1, 4 /* BlockWidth/Height,Bytes */
457 },
458 {
459 MESA_FORMAT_Z32, /* Name */
460 "MESA_FORMAT_Z32", /* StrName */
461 GL_DEPTH_COMPONENT, /* BaseFormat */
462 GL_UNSIGNED_INT, /* DataType */
463 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
464 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
465 1, 1, 4 /* BlockWidth/Height,Bytes */
466 },
467 {
468 MESA_FORMAT_S8, /* Name */
469 "MESA_FORMAT_S8", /* StrName */
470 GL_STENCIL_INDEX, /* BaseFormat */
471 GL_UNSIGNED_INT, /* DataType */
472 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
473 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
474 1, 1, 1 /* BlockWidth/Height,Bytes */
475 },
476 {
477 MESA_FORMAT_SRGB8,
478 "MESA_FORMAT_SRGB8",
479 GL_RGB,
480 GL_UNSIGNED_NORMALIZED,
481 8, 8, 8, 0,
482 0, 0, 0, 0, 0,
483 1, 1, 3
484 },
485 {
486 MESA_FORMAT_SRGBA8,
487 "MESA_FORMAT_SRGBA8",
488 GL_RGBA,
489 GL_UNSIGNED_NORMALIZED,
490 8, 8, 8, 8,
491 0, 0, 0, 0, 0,
492 1, 1, 4
493 },
494 {
495 MESA_FORMAT_SARGB8,
496 "MESA_FORMAT_SARGB8",
497 GL_RGBA,
498 GL_UNSIGNED_NORMALIZED,
499 8, 8, 8, 8,
500 0, 0, 0, 0, 0,
501 1, 1, 4
502 },
503 {
504 MESA_FORMAT_SL8,
505 "MESA_FORMAT_SL8",
506 GL_LUMINANCE,
507 GL_UNSIGNED_NORMALIZED,
508 0, 0, 0, 0,
509 8, 0, 0, 0, 0,
510 1, 1, 1
511 },
512 {
513 MESA_FORMAT_SLA8,
514 "MESA_FORMAT_SLA8",
515 GL_LUMINANCE_ALPHA,
516 GL_UNSIGNED_NORMALIZED,
517 0, 0, 0, 8,
518 8, 0, 0, 0, 0,
519 1, 1, 2
520 },
521 {
522 MESA_FORMAT_SRGB_DXT1, /* Name */
523 "MESA_FORMAT_SRGB_DXT1", /* StrName */
524 GL_RGB, /* BaseFormat */
525 GL_UNSIGNED_NORMALIZED, /* DataType */
526 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
527 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
528 4, 4, 8 /* 8 bytes per 4x4 block */
529 },
530 {
531 MESA_FORMAT_SRGBA_DXT1,
532 "MESA_FORMAT_SRGBA_DXT1",
533 GL_RGBA,
534 GL_UNSIGNED_NORMALIZED,
535 4, 4, 4, 4,
536 0, 0, 0, 0, 0,
537 4, 4, 8 /* 8 bytes per 4x4 block */
538 },
539 {
540 MESA_FORMAT_SRGBA_DXT3,
541 "MESA_FORMAT_SRGBA_DXT3",
542 GL_RGBA,
543 GL_UNSIGNED_NORMALIZED,
544 4, 4, 4, 4,
545 0, 0, 0, 0, 0,
546 4, 4, 16 /* 16 bytes per 4x4 block */
547 },
548 {
549 MESA_FORMAT_SRGBA_DXT5,
550 "MESA_FORMAT_SRGBA_DXT5",
551 GL_RGBA,
552 GL_UNSIGNED_NORMALIZED,
553 4, 4, 4, 4,
554 0, 0, 0, 0, 0,
555 4, 4, 16 /* 16 bytes per 4x4 block */
556 },
557
558 {
559 MESA_FORMAT_RGB_FXT1,
560 "MESA_FORMAT_RGB_FXT1",
561 GL_RGB,
562 GL_UNSIGNED_NORMALIZED,
563 4, 4, 4, 0, /* approx Red/Green/BlueBits */
564 0, 0, 0, 0, 0,
565 8, 4, 16 /* 16 bytes per 8x4 block */
566 },
567 {
568 MESA_FORMAT_RGBA_FXT1,
569 "MESA_FORMAT_RGBA_FXT1",
570 GL_RGBA,
571 GL_UNSIGNED_NORMALIZED,
572 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
573 0, 0, 0, 0, 0,
574 8, 4, 16 /* 16 bytes per 8x4 block */
575 },
576
577 {
578 MESA_FORMAT_RGB_DXT1, /* Name */
579 "MESA_FORMAT_RGB_DXT1", /* StrName */
580 GL_RGB, /* BaseFormat */
581 GL_UNSIGNED_NORMALIZED, /* DataType */
582 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
583 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
584 4, 4, 8 /* 8 bytes per 4x4 block */
585 },
586 {
587 MESA_FORMAT_RGBA_DXT1,
588 "MESA_FORMAT_RGBA_DXT1",
589 GL_RGBA,
590 GL_UNSIGNED_NORMALIZED,
591 4, 4, 4, 4,
592 0, 0, 0, 0, 0,
593 4, 4, 8 /* 8 bytes per 4x4 block */
594 },
595 {
596 MESA_FORMAT_RGBA_DXT3,
597 "MESA_FORMAT_RGBA_DXT3",
598 GL_RGBA,
599 GL_UNSIGNED_NORMALIZED,
600 4, 4, 4, 4,
601 0, 0, 0, 0, 0,
602 4, 4, 16 /* 16 bytes per 4x4 block */
603 },
604 {
605 MESA_FORMAT_RGBA_DXT5,
606 "MESA_FORMAT_RGBA_DXT5",
607 GL_RGBA,
608 GL_UNSIGNED_NORMALIZED,
609 4, 4, 4, 4,
610 0, 0, 0, 0, 0,
611 4, 4, 16 /* 16 bytes per 4x4 block */
612 },
613 {
614 MESA_FORMAT_RGBA_FLOAT32,
615 "MESA_FORMAT_RGBA_FLOAT32",
616 GL_RGBA,
617 GL_FLOAT,
618 32, 32, 32, 32,
619 0, 0, 0, 0, 0,
620 1, 1, 16
621 },
622 {
623 MESA_FORMAT_RGBA_FLOAT16,
624 "MESA_FORMAT_RGBA_FLOAT16",
625 GL_RGBA,
626 GL_FLOAT,
627 16, 16, 16, 16,
628 0, 0, 0, 0, 0,
629 1, 1, 8
630 },
631 {
632 MESA_FORMAT_RGB_FLOAT32,
633 "MESA_FORMAT_RGB_FLOAT32",
634 GL_RGB,
635 GL_FLOAT,
636 32, 32, 32, 0,
637 0, 0, 0, 0, 0,
638 1, 1, 12
639 },
640 {
641 MESA_FORMAT_RGB_FLOAT16,
642 "MESA_FORMAT_RGB_FLOAT16",
643 GL_RGB,
644 GL_FLOAT,
645 16, 16, 16, 0,
646 0, 0, 0, 0, 0,
647 1, 1, 6
648 },
649 {
650 MESA_FORMAT_ALPHA_FLOAT32,
651 "MESA_FORMAT_ALPHA_FLOAT32",
652 GL_ALPHA,
653 GL_FLOAT,
654 0, 0, 0, 32,
655 0, 0, 0, 0, 0,
656 1, 1, 4
657 },
658 {
659 MESA_FORMAT_ALPHA_FLOAT16,
660 "MESA_FORMAT_ALPHA_FLOAT16",
661 GL_ALPHA,
662 GL_FLOAT,
663 0, 0, 0, 16,
664 0, 0, 0, 0, 0,
665 1, 1, 2
666 },
667 {
668 MESA_FORMAT_LUMINANCE_FLOAT32,
669 "MESA_FORMAT_LUMINANCE_FLOAT32",
670 GL_LUMINANCE,
671 GL_FLOAT,
672 0, 0, 0, 0,
673 32, 0, 0, 0, 0,
674 1, 1, 4
675 },
676 {
677 MESA_FORMAT_LUMINANCE_FLOAT16,
678 "MESA_FORMAT_LUMINANCE_FLOAT16",
679 GL_LUMINANCE,
680 GL_FLOAT,
681 0, 0, 0, 0,
682 16, 0, 0, 0, 0,
683 1, 1, 2
684 },
685 {
686 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
687 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
688 GL_LUMINANCE_ALPHA,
689 GL_FLOAT,
690 0, 0, 0, 32,
691 32, 0, 0, 0, 0,
692 1, 1, 8
693 },
694 {
695 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
696 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
697 GL_LUMINANCE_ALPHA,
698 GL_FLOAT,
699 0, 0, 0, 16,
700 16, 0, 0, 0, 0,
701 1, 1, 4
702 },
703 {
704 MESA_FORMAT_INTENSITY_FLOAT32,
705 "MESA_FORMAT_INTENSITY_FLOAT32",
706 GL_INTENSITY,
707 GL_FLOAT,
708 0, 0, 0, 0,
709 0, 32, 0, 0, 0,
710 1, 1, 4
711 },
712 {
713 MESA_FORMAT_INTENSITY_FLOAT16,
714 "MESA_FORMAT_INTENSITY_FLOAT16",
715 GL_INTENSITY,
716 GL_FLOAT,
717 0, 0, 0, 0,
718 0, 16, 0, 0, 0,
719 1, 1, 2
720 },
721 {
722 MESA_FORMAT_R_FLOAT32,
723 "MESA_FORMAT_R_FLOAT32",
724 GL_RED,
725 GL_FLOAT,
726 32, 0, 0, 0,
727 0, 0, 0, 0, 0,
728 1, 1, 4
729 },
730 {
731 MESA_FORMAT_R_FLOAT16,
732 "MESA_FORMAT_R_FLOAT16",
733 GL_RED,
734 GL_FLOAT,
735 16, 0, 0, 0,
736 0, 0, 0, 0, 0,
737 1, 1, 2
738 },
739 {
740 MESA_FORMAT_RG_FLOAT32,
741 "MESA_FORMAT_RG_FLOAT32",
742 GL_RG,
743 GL_FLOAT,
744 32, 32, 0, 0,
745 0, 0, 0, 0, 0,
746 1, 1, 8
747 },
748 {
749 MESA_FORMAT_RG_FLOAT16,
750 "MESA_FORMAT_RG_FLOAT16",
751 GL_RG,
752 GL_FLOAT,
753 16, 16, 0, 0,
754 0, 0, 0, 0, 0,
755 1, 1, 4
756 },
757
758 /* unnormalized signed int formats */
759 {
760 MESA_FORMAT_RGBA_INT8,
761 "MESA_FORMAT_RGBA_INT8",
762 GL_RGBA,
763 GL_INT,
764 8, 8, 8, 8,
765 0, 0, 0, 0, 0,
766 1, 1, 4
767 },
768 {
769 MESA_FORMAT_RGBA_INT16,
770 "MESA_FORMAT_RGBA_INT16",
771 GL_RGBA,
772 GL_INT,
773 16, 16, 16, 16,
774 0, 0, 0, 0, 0,
775 1, 1, 8
776 },
777 {
778 MESA_FORMAT_RGBA_INT32,
779 "MESA_FORMAT_RGBA_INT32",
780 GL_RGBA,
781 GL_INT,
782 32, 32, 32, 32,
783 0, 0, 0, 0, 0,
784 1, 1, 16
785 },
786
787 /* unnormalized unsigned int formats */
788 {
789 MESA_FORMAT_RGBA_UINT8,
790 "MESA_FORMAT_RGBA_UINT8",
791 GL_RGBA,
792 GL_UNSIGNED_INT,
793 8, 8, 8, 8,
794 0, 0, 0, 0, 0,
795 1, 1, 4
796 },
797 {
798 MESA_FORMAT_RGBA_UINT16,
799 "MESA_FORMAT_RGBA_UINT16",
800 GL_RGBA,
801 GL_UNSIGNED_INT,
802 16, 16, 16, 16,
803 0, 0, 0, 0, 0,
804 1, 1, 8
805 },
806 {
807 MESA_FORMAT_RGBA_UINT32,
808 "MESA_FORMAT_RGBA_UINT32",
809 GL_RGBA,
810 GL_UNSIGNED_INT,
811 32, 32, 32, 32,
812 0, 0, 0, 0, 0,
813 1, 1, 16
814 },
815
816
817 {
818 MESA_FORMAT_DUDV8,
819 "MESA_FORMAT_DUDV8",
820 GL_DUDV_ATI,
821 GL_SIGNED_NORMALIZED,
822 0, 0, 0, 0,
823 0, 0, 0, 0, 0,
824 1, 1, 2
825 },
826
827 /* Signed 8 bits / channel */
828 {
829 MESA_FORMAT_SIGNED_R8, /* Name */
830 "MESA_FORMAT_SIGNED_R8", /* StrName */
831 GL_RED, /* BaseFormat */
832 GL_SIGNED_NORMALIZED, /* DataType */
833 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
834 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
835 1, 1, 1 /* BlockWidth/Height,Bytes */
836 },
837 {
838 MESA_FORMAT_SIGNED_RG88_REV,
839 "MESA_FORMAT_SIGNED_RG88_REV",
840 GL_RG,
841 GL_SIGNED_NORMALIZED,
842 8, 8, 0, 0,
843 0, 0, 0, 0, 0,
844 1, 1, 2
845 },
846 {
847 MESA_FORMAT_SIGNED_RGBX8888,
848 "MESA_FORMAT_SIGNED_RGBX8888",
849 GL_RGB,
850 GL_SIGNED_NORMALIZED,
851 8, 8, 8, 0,
852 0, 0, 0, 0, 0,
853 1, 1, 4 /* 4 bpp, but no alpha */
854 },
855 {
856 MESA_FORMAT_SIGNED_RGBA8888,
857 "MESA_FORMAT_SIGNED_RGBA8888",
858 GL_RGBA,
859 GL_SIGNED_NORMALIZED,
860 8, 8, 8, 8,
861 0, 0, 0, 0, 0,
862 1, 1, 4
863 },
864 {
865 MESA_FORMAT_SIGNED_RGBA8888_REV,
866 "MESA_FORMAT_SIGNED_RGBA8888_REV",
867 GL_RGBA,
868 GL_SIGNED_NORMALIZED,
869 8, 8, 8, 8,
870 0, 0, 0, 0, 0,
871 1, 1, 4
872 },
873
874 /* Signed 16 bits / channel */
875 {
876 MESA_FORMAT_SIGNED_R16,
877 "MESA_FORMAT_SIGNED_R16",
878 GL_RED,
879 GL_SIGNED_NORMALIZED,
880 16, 0, 0, 0,
881 0, 0, 0, 0, 0,
882 1, 1, 2
883 },
884 {
885 MESA_FORMAT_SIGNED_GR1616,
886 "MESA_FORMAT_SIGNED_GR1616",
887 GL_RG,
888 GL_SIGNED_NORMALIZED,
889 16, 16, 0, 0,
890 0, 0, 0, 0, 0,
891 1, 1, 4
892 },
893 {
894 MESA_FORMAT_SIGNED_RGB_16,
895 "MESA_FORMAT_SIGNED_RGB_16",
896 GL_RGB,
897 GL_SIGNED_NORMALIZED,
898 16, 16, 16, 0,
899 0, 0, 0, 0, 0,
900 1, 1, 6
901 },
902 {
903 MESA_FORMAT_SIGNED_RGBA_16,
904 "MESA_FORMAT_SIGNED_RGBA_16",
905 GL_RGBA,
906 GL_SIGNED_NORMALIZED,
907 16, 16, 16, 16,
908 0, 0, 0, 0, 0,
909 1, 1, 8
910 },
911 {
912 MESA_FORMAT_RGBA_16,
913 "MESA_FORMAT_RGBA_16",
914 GL_RGBA,
915 GL_UNSIGNED_NORMALIZED,
916 16, 16, 16, 16,
917 0, 0, 0, 0, 0,
918 1, 1, 8
919 },
920 {
921 MESA_FORMAT_RED_RGTC1,
922 "MESA_FORMAT_RED_RGTC1",
923 GL_RED,
924 GL_UNSIGNED_NORMALIZED,
925 4, 0, 0, 0,
926 0, 0, 0, 0, 0,
927 4, 4, 8 /* 8 bytes per 4x4 block */
928 },
929 {
930 MESA_FORMAT_SIGNED_RED_RGTC1,
931 "MESA_FORMAT_SIGNED_RED_RGTC1",
932 GL_RED,
933 GL_SIGNED_NORMALIZED,
934 4, 0, 0, 0,
935 0, 0, 0, 0, 0,
936 4, 4, 8 /* 8 bytes per 4x4 block */
937 },
938 {
939 MESA_FORMAT_RG_RGTC2,
940 "MESA_FORMAT_RG_RGTC2",
941 GL_RG,
942 GL_UNSIGNED_NORMALIZED,
943 4, 4, 0, 0,
944 0, 0, 0, 0, 0,
945 4, 4, 16 /* 16 bytes per 4x4 block */
946 },
947 {
948 MESA_FORMAT_SIGNED_RG_RGTC2,
949 "MESA_FORMAT_SIGNED_RG_RGTC2",
950 GL_RG,
951 GL_SIGNED_NORMALIZED,
952 4, 4, 0, 0,
953 0, 0, 0, 0, 0,
954 4, 4, 16 /* 16 bytes per 4x4 block */
955 },
956 {
957 MESA_FORMAT_L_LATC1,
958 "MESA_FORMAT_L_LATC1",
959 GL_LUMINANCE,
960 GL_UNSIGNED_NORMALIZED,
961 0, 0, 0, 0,
962 4, 0, 0, 0, 0,
963 4, 4, 8 /* 8 bytes per 4x4 block */
964 },
965 {
966 MESA_FORMAT_SIGNED_L_LATC1,
967 "MESA_FORMAT_SIGNED_L_LATC1",
968 GL_LUMINANCE,
969 GL_SIGNED_NORMALIZED,
970 0, 0, 0, 0,
971 4, 0, 0, 0, 0,
972 4, 4, 8 /* 8 bytes per 4x4 block */
973 },
974 {
975 MESA_FORMAT_LA_LATC2,
976 "MESA_FORMAT_LA_LATC2",
977 GL_LUMINANCE_ALPHA,
978 GL_UNSIGNED_NORMALIZED,
979 0, 0, 0, 4,
980 4, 0, 0, 0, 0,
981 4, 4, 16 /* 16 bytes per 4x4 block */
982 },
983 {
984 MESA_FORMAT_SIGNED_LA_LATC2,
985 "MESA_FORMAT_SIGNED_LA_LATC2",
986 GL_LUMINANCE_ALPHA,
987 GL_SIGNED_NORMALIZED,
988 0, 0, 0, 4,
989 4, 0, 0, 0, 0,
990 4, 4, 16 /* 16 bytes per 4x4 block */
991 },
992
993 /* Signed formats from EXT_texture_snorm that are not in GL3.1 */
994 {
995 MESA_FORMAT_SIGNED_A8,
996 "MESA_FORMAT_SIGNED_A8",
997 GL_ALPHA,
998 GL_SIGNED_NORMALIZED,
999 0, 0, 0, 8,
1000 0, 0, 0, 0, 0,
1001 1, 1, 1
1002 },
1003 {
1004 MESA_FORMAT_SIGNED_L8,
1005 "MESA_FORMAT_SIGNED_L8",
1006 GL_LUMINANCE,
1007 GL_SIGNED_NORMALIZED,
1008 0, 0, 0, 0,
1009 8, 0, 0, 0, 0,
1010 1, 1, 1
1011 },
1012 {
1013 MESA_FORMAT_SIGNED_AL88,
1014 "MESA_FORMAT_SIGNED_AL88",
1015 GL_LUMINANCE_ALPHA,
1016 GL_SIGNED_NORMALIZED,
1017 0, 0, 0, 8,
1018 8, 0, 0, 0, 0,
1019 1, 1, 2
1020 },
1021 {
1022 MESA_FORMAT_SIGNED_I8,
1023 "MESA_FORMAT_SIGNED_I8",
1024 GL_INTENSITY,
1025 GL_SIGNED_NORMALIZED,
1026 0, 0, 0, 0,
1027 0, 8, 0, 0, 0,
1028 1, 1, 1
1029 },
1030 {
1031 MESA_FORMAT_SIGNED_A16,
1032 "MESA_FORMAT_SIGNED_A16",
1033 GL_ALPHA,
1034 GL_SIGNED_NORMALIZED,
1035 0, 0, 0, 16,
1036 0, 0, 0, 0, 0,
1037 1, 1, 2
1038 },
1039 {
1040 MESA_FORMAT_SIGNED_L16,
1041 "MESA_FORMAT_SIGNED_L16",
1042 GL_LUMINANCE,
1043 GL_SIGNED_NORMALIZED,
1044 0, 0, 0, 0,
1045 16, 0, 0, 0, 0,
1046 1, 1, 2
1047 },
1048 {
1049 MESA_FORMAT_SIGNED_AL1616,
1050 "MESA_FORMAT_SIGNED_AL1616",
1051 GL_LUMINANCE_ALPHA,
1052 GL_SIGNED_NORMALIZED,
1053 0, 0, 0, 16,
1054 16, 0, 0, 0, 0,
1055 1, 1, 4
1056 },
1057 {
1058 MESA_FORMAT_SIGNED_I16,
1059 "MESA_FORMAT_SIGNED_I16",
1060 GL_INTENSITY,
1061 GL_SIGNED_NORMALIZED,
1062 0, 0, 0, 0,
1063 0, 16, 0, 0, 0,
1064 1, 1, 2
1065 },
1066 {
1067 MESA_FORMAT_RGB9_E5_FLOAT,
1068 "MESA_FORMAT_RGB9_E5",
1069 GL_RGB,
1070 GL_FLOAT,
1071 9, 9, 9, 0,
1072 0, 0, 0, 0, 0,
1073 1, 1, 4
1074 },
1075 {
1076 MESA_FORMAT_R11_G11_B10_FLOAT,
1077 "MESA_FORMAT_R11_G11_B10_FLOAT",
1078 GL_RGB,
1079 GL_FLOAT,
1080 11, 11, 10, 0,
1081 0, 0, 0, 0, 0,
1082 1, 1, 4
1083 },
1084 /* ARB_depth_buffer_float */
1085 {
1086 MESA_FORMAT_Z32_FLOAT, /* Name */
1087 "MESA_FORMAT_Z32_FLOAT", /* StrName */
1088 GL_DEPTH_COMPONENT, /* BaseFormat */
1089 GL_FLOAT, /* DataType */
1090 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
1091 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
1092 1, 1, 4 /* BlockWidth/Height,Bytes */
1093 },
1094 {
1095 MESA_FORMAT_Z32_FLOAT_X24S8, /* Name */
1096 "MESA_FORMAT_Z32_FLOAT_X24S8", /* StrName */
1097 GL_DEPTH_STENCIL, /* BaseFormat */
1098 GL_NONE /* XXX */, /* DataType */
1099 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
1100 0, 0, 0, 32, 8, /* Lum/Int/Index/Depth/StencilBits */
1101 1, 1, 8 /* BlockWidth/Height,Bytes */
1102 },
1103 };
1104
1105
1106
1107 static const struct gl_format_info *
1108 _mesa_get_format_info(gl_format format)
1109 {
1110 const struct gl_format_info *info = &format_info[format];
1111 assert(info->Name == format);
1112 return info;
1113 }
1114
1115
1116 /** Return string name of format (for debugging) */
1117 const char *
1118 _mesa_get_format_name(gl_format format)
1119 {
1120 const struct gl_format_info *info = _mesa_get_format_info(format);
1121 return info->StrName;
1122 }
1123
1124
1125
1126 /**
1127 * Return bytes needed to store a block of pixels in the given format.
1128 * Normally, a block is 1x1 (a single pixel). But for compressed formats
1129 * a block may be 4x4 or 8x4, etc.
1130 *
1131 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
1132 */
1133 GLint
1134 _mesa_get_format_bytes(gl_format format)
1135 {
1136 const struct gl_format_info *info = _mesa_get_format_info(format);
1137 ASSERT(info->BytesPerBlock);
1138 return info->BytesPerBlock;
1139 }
1140
1141
1142 /**
1143 * Return bits per component for the given format.
1144 * \param format one of MESA_FORMAT_x
1145 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
1146 */
1147 GLint
1148 _mesa_get_format_bits(gl_format format, GLenum pname)
1149 {
1150 const struct gl_format_info *info = _mesa_get_format_info(format);
1151
1152 switch (pname) {
1153 case GL_RED_BITS:
1154 case GL_TEXTURE_RED_SIZE:
1155 case GL_RENDERBUFFER_RED_SIZE_EXT:
1156 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1157 return info->RedBits;
1158 case GL_GREEN_BITS:
1159 case GL_TEXTURE_GREEN_SIZE:
1160 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
1161 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1162 return info->GreenBits;
1163 case GL_BLUE_BITS:
1164 case GL_TEXTURE_BLUE_SIZE:
1165 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
1166 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1167 return info->BlueBits;
1168 case GL_ALPHA_BITS:
1169 case GL_TEXTURE_ALPHA_SIZE:
1170 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
1171 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1172 return info->AlphaBits;
1173 case GL_TEXTURE_INTENSITY_SIZE:
1174 return info->IntensityBits;
1175 case GL_TEXTURE_LUMINANCE_SIZE:
1176 return info->LuminanceBits;
1177 case GL_INDEX_BITS:
1178 return info->IndexBits;
1179 case GL_DEPTH_BITS:
1180 case GL_TEXTURE_DEPTH_SIZE_ARB:
1181 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
1182 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1183 return info->DepthBits;
1184 case GL_STENCIL_BITS:
1185 case GL_TEXTURE_STENCIL_SIZE_EXT:
1186 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
1187 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1188 return info->StencilBits;
1189 default:
1190 _mesa_problem(NULL, "bad pname in _mesa_get_format_bits()");
1191 return 0;
1192 }
1193 }
1194
1195
1196 /**
1197 * Return the data type (or more specifically, the data representation)
1198 * for the given format.
1199 * The return value will be one of:
1200 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
1201 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
1202 * GL_UNSIGNED_INT = an ordinary unsigned integer
1203 * GL_INT = an ordinary signed integer
1204 * GL_FLOAT = an ordinary float
1205 */
1206 GLenum
1207 _mesa_get_format_datatype(gl_format format)
1208 {
1209 const struct gl_format_info *info = _mesa_get_format_info(format);
1210 return info->DataType;
1211 }
1212
1213
1214 /**
1215 * Return the basic format for the given type. The result will be one of
1216 * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
1217 * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
1218 */
1219 GLenum
1220 _mesa_get_format_base_format(gl_format format)
1221 {
1222 const struct gl_format_info *info = _mesa_get_format_info(format);
1223 return info->BaseFormat;
1224 }
1225
1226
1227 /**
1228 * Return the block size (in pixels) for the given format. Normally
1229 * the block size is 1x1. But compressed formats will have block sizes
1230 * of 4x4 or 8x4 pixels, etc.
1231 * \param bw returns block width in pixels
1232 * \param bh returns block height in pixels
1233 */
1234 void
1235 _mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
1236 {
1237 const struct gl_format_info *info = _mesa_get_format_info(format);
1238 *bw = info->BlockWidth;
1239 *bh = info->BlockHeight;
1240 }
1241
1242
1243 /** Is the given format a compressed format? */
1244 GLboolean
1245 _mesa_is_format_compressed(gl_format format)
1246 {
1247 const struct gl_format_info *info = _mesa_get_format_info(format);
1248 return info->BlockWidth > 1 || info->BlockHeight > 1;
1249 }
1250
1251
1252 /**
1253 * Determine if the given format represents a packed depth/stencil buffer.
1254 */
1255 GLboolean
1256 _mesa_is_format_packed_depth_stencil(gl_format format)
1257 {
1258 const struct gl_format_info *info = _mesa_get_format_info(format);
1259
1260 return info->BaseFormat == GL_DEPTH_STENCIL;
1261 }
1262
1263
1264 /**
1265 * Is the given format a signed/unsigned integer color format?
1266 */
1267 GLboolean
1268 _mesa_is_format_integer_color(gl_format format)
1269 {
1270 const struct gl_format_info *info = _mesa_get_format_info(format);
1271 return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) &&
1272 info->BaseFormat != GL_DEPTH_COMPONENT &&
1273 info->BaseFormat != GL_DEPTH_STENCIL &&
1274 info->BaseFormat != GL_STENCIL_INDEX;
1275 }
1276
1277
1278 /**
1279 * Return color encoding for given format.
1280 * \return GL_LINEAR or GL_SRGB
1281 */
1282 GLenum
1283 _mesa_get_format_color_encoding(gl_format format)
1284 {
1285 /* XXX this info should be encoded in gl_format_info */
1286 switch (format) {
1287 case MESA_FORMAT_SRGB8:
1288 case MESA_FORMAT_SRGBA8:
1289 case MESA_FORMAT_SARGB8:
1290 case MESA_FORMAT_SL8:
1291 case MESA_FORMAT_SLA8:
1292 case MESA_FORMAT_SRGB_DXT1:
1293 case MESA_FORMAT_SRGBA_DXT1:
1294 case MESA_FORMAT_SRGBA_DXT3:
1295 case MESA_FORMAT_SRGBA_DXT5:
1296 return GL_SRGB;
1297 default:
1298 return GL_LINEAR;
1299 }
1300 }
1301
1302
1303 /**
1304 * For an sRGB format, return the corresponding linear color space format.
1305 * For non-sRGB formats, return the format as-is.
1306 */
1307 gl_format
1308 _mesa_get_srgb_format_linear(gl_format format)
1309 {
1310 switch (format) {
1311 case MESA_FORMAT_SRGB8:
1312 format = MESA_FORMAT_RGB888;
1313 break;
1314 case MESA_FORMAT_SRGBA8:
1315 format = MESA_FORMAT_RGBA8888;
1316 break;
1317 case MESA_FORMAT_SARGB8:
1318 format = MESA_FORMAT_ARGB8888;
1319 break;
1320 case MESA_FORMAT_SL8:
1321 format = MESA_FORMAT_L8;
1322 break;
1323 case MESA_FORMAT_SLA8:
1324 format = MESA_FORMAT_AL88;
1325 break;
1326 case MESA_FORMAT_SRGB_DXT1:
1327 format = MESA_FORMAT_RGB_DXT1;
1328 break;
1329 case MESA_FORMAT_SRGBA_DXT1:
1330 format = MESA_FORMAT_RGBA_DXT1;
1331 break;
1332 case MESA_FORMAT_SRGBA_DXT3:
1333 format = MESA_FORMAT_RGBA_DXT3;
1334 break;
1335 case MESA_FORMAT_SRGBA_DXT5:
1336 format = MESA_FORMAT_RGBA_DXT5;
1337 break;
1338 default:
1339 break;
1340 }
1341 return format;
1342 }
1343
1344
1345 /**
1346 * If the given format is a compressed format, return a corresponding
1347 * uncompressed format.
1348 */
1349 gl_format
1350 _mesa_get_uncompressed_format(gl_format format)
1351 {
1352 switch (format) {
1353 case MESA_FORMAT_RGB_FXT1:
1354 return MESA_FORMAT_RGB888;
1355 case MESA_FORMAT_RGBA_FXT1:
1356 return MESA_FORMAT_RGBA8888;
1357 case MESA_FORMAT_RGB_DXT1:
1358 case MESA_FORMAT_SRGB_DXT1:
1359 return MESA_FORMAT_RGB888;
1360 case MESA_FORMAT_RGBA_DXT1:
1361 case MESA_FORMAT_SRGBA_DXT1:
1362 return MESA_FORMAT_RGBA8888;
1363 case MESA_FORMAT_RGBA_DXT3:
1364 case MESA_FORMAT_SRGBA_DXT3:
1365 return MESA_FORMAT_RGBA8888;
1366 case MESA_FORMAT_RGBA_DXT5:
1367 case MESA_FORMAT_SRGBA_DXT5:
1368 return MESA_FORMAT_RGBA8888;
1369 case MESA_FORMAT_RED_RGTC1:
1370 return MESA_FORMAT_R8;
1371 case MESA_FORMAT_SIGNED_RED_RGTC1:
1372 return MESA_FORMAT_SIGNED_R8;
1373 case MESA_FORMAT_RG_RGTC2:
1374 return MESA_FORMAT_RG88;
1375 case MESA_FORMAT_SIGNED_RG_RGTC2:
1376 return MESA_FORMAT_SIGNED_RG88_REV;
1377 case MESA_FORMAT_L_LATC1:
1378 return MESA_FORMAT_L8;
1379 case MESA_FORMAT_SIGNED_L_LATC1:
1380 return MESA_FORMAT_SIGNED_L8;
1381 case MESA_FORMAT_LA_LATC2:
1382 return MESA_FORMAT_AL88;
1383 case MESA_FORMAT_SIGNED_LA_LATC2:
1384 return MESA_FORMAT_SIGNED_AL88;
1385 default:
1386 #ifdef DEBUG
1387 assert(!_mesa_is_format_compressed(format));
1388 #endif
1389 return format;
1390 }
1391 }
1392
1393
1394 GLuint
1395 _mesa_format_num_components(gl_format format)
1396 {
1397 const struct gl_format_info *info = _mesa_get_format_info(format);
1398 return ((info->RedBits > 0) +
1399 (info->GreenBits > 0) +
1400 (info->BlueBits > 0) +
1401 (info->AlphaBits > 0) +
1402 (info->LuminanceBits > 0) +
1403 (info->IntensityBits > 0) +
1404 (info->DepthBits > 0) +
1405 (info->StencilBits > 0));
1406 }
1407
1408
1409 /**
1410 * Return number of bytes needed to store an image of the given size
1411 * in the given format.
1412 */
1413 GLuint
1414 _mesa_format_image_size(gl_format format, GLsizei width,
1415 GLsizei height, GLsizei depth)
1416 {
1417 const struct gl_format_info *info = _mesa_get_format_info(format);
1418 /* Strictly speaking, a conditional isn't needed here */
1419 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1420 /* compressed format (2D only for now) */
1421 const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
1422 const GLuint wblocks = (width + bw - 1) / bw;
1423 const GLuint hblocks = (height + bh - 1) / bh;
1424 const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
1425 assert(depth == 1);
1426 return sz;
1427 }
1428 else {
1429 /* non-compressed */
1430 const GLuint sz = width * height * depth * info->BytesPerBlock;
1431 return sz;
1432 }
1433 }
1434
1435
1436 /**
1437 * Same as _mesa_format_image_size() but returns a 64-bit value to
1438 * accomodate very large textures.
1439 */
1440 uint64_t
1441 _mesa_format_image_size64(gl_format format, GLsizei width,
1442 GLsizei height, GLsizei depth)
1443 {
1444 const struct gl_format_info *info = _mesa_get_format_info(format);
1445 /* Strictly speaking, a conditional isn't needed here */
1446 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1447 /* compressed format (2D only for now) */
1448 const uint64_t bw = info->BlockWidth, bh = info->BlockHeight;
1449 const uint64_t wblocks = (width + bw - 1) / bw;
1450 const uint64_t hblocks = (height + bh - 1) / bh;
1451 const uint64_t sz = wblocks * hblocks * info->BytesPerBlock;
1452 assert(depth == 1);
1453 return sz;
1454 }
1455 else {
1456 /* non-compressed */
1457 const uint64_t sz = ((uint64_t) width *
1458 (uint64_t) height *
1459 (uint64_t) depth *
1460 info->BytesPerBlock);
1461 return sz;
1462 }
1463 }
1464
1465
1466
1467 GLint
1468 _mesa_format_row_stride(gl_format format, GLsizei width)
1469 {
1470 const struct gl_format_info *info = _mesa_get_format_info(format);
1471 /* Strictly speaking, a conditional isn't needed here */
1472 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1473 /* compressed format */
1474 const GLuint bw = info->BlockWidth;
1475 const GLuint wblocks = (width + bw - 1) / bw;
1476 const GLint stride = wblocks * info->BytesPerBlock;
1477 return stride;
1478 }
1479 else {
1480 const GLint stride = width * info->BytesPerBlock;
1481 return stride;
1482 }
1483 }
1484
1485
1486 /**
1487 * Debug/test: check that all formats are handled in the
1488 * _mesa_format_to_type_and_comps() function. When new pixel formats
1489 * are added to Mesa, that function needs to be updated.
1490 * This is a no-op after the first call.
1491 */
1492 static void
1493 check_format_to_type_and_comps(void)
1494 {
1495 gl_format f;
1496
1497 for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) {
1498 GLenum datatype = 0;
1499 GLuint comps = 0;
1500 /* This function will emit a problem/warning if the format is
1501 * not handled.
1502 */
1503 _mesa_format_to_type_and_comps(f, &datatype, &comps);
1504 }
1505 }
1506
1507
1508 /**
1509 * Do sanity checking of the format info table.
1510 */
1511 void
1512 _mesa_test_formats(void)
1513 {
1514 GLuint i;
1515
1516 assert(Elements(format_info) == MESA_FORMAT_COUNT);
1517
1518 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
1519 const struct gl_format_info *info = _mesa_get_format_info(i);
1520 assert(info);
1521
1522 assert(info->Name == i);
1523
1524 if (info->Name == MESA_FORMAT_NONE)
1525 continue;
1526
1527 if (info->BlockWidth == 1 && info->BlockHeight == 1) {
1528 if (info->RedBits > 0) {
1529 GLuint t = info->RedBits + info->GreenBits
1530 + info->BlueBits + info->AlphaBits;
1531 assert(t / 8 <= info->BytesPerBlock);
1532 (void) t;
1533 }
1534 }
1535
1536 assert(info->DataType == GL_UNSIGNED_NORMALIZED ||
1537 info->DataType == GL_SIGNED_NORMALIZED ||
1538 info->DataType == GL_UNSIGNED_INT ||
1539 info->DataType == GL_INT ||
1540 info->DataType == GL_FLOAT ||
1541 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
1542 info->DataType == GL_NONE);
1543
1544 if (info->BaseFormat == GL_RGB) {
1545 assert(info->RedBits > 0);
1546 assert(info->GreenBits > 0);
1547 assert(info->BlueBits > 0);
1548 assert(info->AlphaBits == 0);
1549 assert(info->LuminanceBits == 0);
1550 assert(info->IntensityBits == 0);
1551 }
1552 else if (info->BaseFormat == GL_RGBA) {
1553 assert(info->RedBits > 0);
1554 assert(info->GreenBits > 0);
1555 assert(info->BlueBits > 0);
1556 assert(info->AlphaBits > 0);
1557 assert(info->LuminanceBits == 0);
1558 assert(info->IntensityBits == 0);
1559 }
1560 else if (info->BaseFormat == GL_RG) {
1561 assert(info->RedBits > 0);
1562 assert(info->GreenBits > 0);
1563 assert(info->BlueBits == 0);
1564 assert(info->AlphaBits == 0);
1565 assert(info->LuminanceBits == 0);
1566 assert(info->IntensityBits == 0);
1567 }
1568 else if (info->BaseFormat == GL_RED) {
1569 assert(info->RedBits > 0);
1570 assert(info->GreenBits == 0);
1571 assert(info->BlueBits == 0);
1572 assert(info->AlphaBits == 0);
1573 assert(info->LuminanceBits == 0);
1574 assert(info->IntensityBits == 0);
1575 }
1576 else if (info->BaseFormat == GL_LUMINANCE) {
1577 assert(info->RedBits == 0);
1578 assert(info->GreenBits == 0);
1579 assert(info->BlueBits == 0);
1580 assert(info->AlphaBits == 0);
1581 assert(info->LuminanceBits > 0);
1582 assert(info->IntensityBits == 0);
1583 }
1584 else if (info->BaseFormat == GL_INTENSITY) {
1585 assert(info->RedBits == 0);
1586 assert(info->GreenBits == 0);
1587 assert(info->BlueBits == 0);
1588 assert(info->AlphaBits == 0);
1589 assert(info->LuminanceBits == 0);
1590 assert(info->IntensityBits > 0);
1591 }
1592 }
1593
1594 check_format_to_type_and_comps();
1595 }
1596
1597
1598
1599 /**
1600 * Return datatype and number of components per texel for the given gl_format.
1601 * Only used for mipmap generation code.
1602 */
1603 void
1604 _mesa_format_to_type_and_comps(gl_format format,
1605 GLenum *datatype, GLuint *comps)
1606 {
1607 switch (format) {
1608 case MESA_FORMAT_RGBA8888:
1609 case MESA_FORMAT_RGBA8888_REV:
1610 case MESA_FORMAT_ARGB8888:
1611 case MESA_FORMAT_ARGB8888_REV:
1612 case MESA_FORMAT_XRGB8888:
1613 case MESA_FORMAT_XRGB8888_REV:
1614 *datatype = GL_UNSIGNED_BYTE;
1615 *comps = 4;
1616 return;
1617 case MESA_FORMAT_RGB888:
1618 case MESA_FORMAT_BGR888:
1619 *datatype = GL_UNSIGNED_BYTE;
1620 *comps = 3;
1621 return;
1622 case MESA_FORMAT_RGB565:
1623 case MESA_FORMAT_RGB565_REV:
1624 *datatype = GL_UNSIGNED_SHORT_5_6_5;
1625 *comps = 3;
1626 return;
1627
1628 case MESA_FORMAT_ARGB4444:
1629 case MESA_FORMAT_ARGB4444_REV:
1630 *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
1631 *comps = 4;
1632 return;
1633
1634 case MESA_FORMAT_ARGB1555:
1635 case MESA_FORMAT_ARGB1555_REV:
1636 *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1637 *comps = 4;
1638 return;
1639
1640 case MESA_FORMAT_ARGB2101010:
1641 *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
1642 *comps = 4;
1643 return;
1644
1645 case MESA_FORMAT_RGBA5551:
1646 *datatype = GL_UNSIGNED_SHORT_5_5_5_1;
1647 *comps = 4;
1648 return;
1649
1650 case MESA_FORMAT_AL44:
1651 *datatype = MESA_UNSIGNED_BYTE_4_4;
1652 *comps = 2;
1653 return;
1654
1655 case MESA_FORMAT_AL88:
1656 case MESA_FORMAT_AL88_REV:
1657 case MESA_FORMAT_RG88:
1658 case MESA_FORMAT_RG88_REV:
1659 *datatype = GL_UNSIGNED_BYTE;
1660 *comps = 2;
1661 return;
1662
1663 case MESA_FORMAT_AL1616:
1664 case MESA_FORMAT_AL1616_REV:
1665 case MESA_FORMAT_RG1616:
1666 case MESA_FORMAT_RG1616_REV:
1667 *datatype = GL_UNSIGNED_SHORT;
1668 *comps = 2;
1669 return;
1670
1671 case MESA_FORMAT_R16:
1672 case MESA_FORMAT_A16:
1673 case MESA_FORMAT_L16:
1674 case MESA_FORMAT_I16:
1675 *datatype = GL_UNSIGNED_SHORT;
1676 *comps = 1;
1677 return;
1678
1679 case MESA_FORMAT_RGB332:
1680 *datatype = GL_UNSIGNED_BYTE_3_3_2;
1681 *comps = 3;
1682 return;
1683
1684 case MESA_FORMAT_A8:
1685 case MESA_FORMAT_L8:
1686 case MESA_FORMAT_I8:
1687 case MESA_FORMAT_R8:
1688 case MESA_FORMAT_S8:
1689 *datatype = GL_UNSIGNED_BYTE;
1690 *comps = 1;
1691 return;
1692
1693 case MESA_FORMAT_YCBCR:
1694 case MESA_FORMAT_YCBCR_REV:
1695 *datatype = GL_UNSIGNED_SHORT;
1696 *comps = 2;
1697 return;
1698
1699 case MESA_FORMAT_Z24_S8:
1700 *datatype = GL_UNSIGNED_INT;
1701 *comps = 1; /* XXX OK? */
1702 return;
1703
1704 case MESA_FORMAT_S8_Z24:
1705 *datatype = GL_UNSIGNED_INT;
1706 *comps = 1; /* XXX OK? */
1707 return;
1708
1709 case MESA_FORMAT_Z16:
1710 *datatype = GL_UNSIGNED_SHORT;
1711 *comps = 1;
1712 return;
1713
1714 case MESA_FORMAT_X8_Z24:
1715 *datatype = GL_UNSIGNED_INT;
1716 *comps = 1;
1717 return;
1718
1719 case MESA_FORMAT_Z24_X8:
1720 *datatype = GL_UNSIGNED_INT;
1721 *comps = 1;
1722 return;
1723
1724 case MESA_FORMAT_Z32:
1725 *datatype = GL_UNSIGNED_INT;
1726 *comps = 1;
1727 return;
1728
1729 case MESA_FORMAT_Z32_FLOAT:
1730 *datatype = GL_FLOAT;
1731 *comps = 1;
1732 return;
1733
1734 case MESA_FORMAT_Z32_FLOAT_X24S8:
1735 *datatype = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
1736 *comps = 1;
1737 return;
1738
1739 case MESA_FORMAT_DUDV8:
1740 *datatype = GL_BYTE;
1741 *comps = 2;
1742 return;
1743
1744 case MESA_FORMAT_SIGNED_R8:
1745 case MESA_FORMAT_SIGNED_A8:
1746 case MESA_FORMAT_SIGNED_L8:
1747 case MESA_FORMAT_SIGNED_I8:
1748 *datatype = GL_BYTE;
1749 *comps = 1;
1750 return;
1751 case MESA_FORMAT_SIGNED_RG88_REV:
1752 case MESA_FORMAT_SIGNED_AL88:
1753 *datatype = GL_BYTE;
1754 *comps = 2;
1755 return;
1756 case MESA_FORMAT_SIGNED_RGBA8888:
1757 case MESA_FORMAT_SIGNED_RGBA8888_REV:
1758 case MESA_FORMAT_SIGNED_RGBX8888:
1759 *datatype = GL_BYTE;
1760 *comps = 4;
1761 return;
1762
1763 case MESA_FORMAT_RGBA_16:
1764 *datatype = GL_UNSIGNED_SHORT;
1765 *comps = 4;
1766 return;
1767
1768 case MESA_FORMAT_SIGNED_R16:
1769 case MESA_FORMAT_SIGNED_A16:
1770 case MESA_FORMAT_SIGNED_L16:
1771 case MESA_FORMAT_SIGNED_I16:
1772 *datatype = GL_SHORT;
1773 *comps = 1;
1774 return;
1775 case MESA_FORMAT_SIGNED_GR1616:
1776 case MESA_FORMAT_SIGNED_AL1616:
1777 *datatype = GL_SHORT;
1778 *comps = 2;
1779 return;
1780 case MESA_FORMAT_SIGNED_RGB_16:
1781 *datatype = GL_SHORT;
1782 *comps = 3;
1783 return;
1784 case MESA_FORMAT_SIGNED_RGBA_16:
1785 *datatype = GL_SHORT;
1786 *comps = 4;
1787 return;
1788
1789 #if FEATURE_EXT_texture_sRGB
1790 case MESA_FORMAT_SRGB8:
1791 *datatype = GL_UNSIGNED_BYTE;
1792 *comps = 3;
1793 return;
1794 case MESA_FORMAT_SRGBA8:
1795 case MESA_FORMAT_SARGB8:
1796 *datatype = GL_UNSIGNED_BYTE;
1797 *comps = 4;
1798 return;
1799 case MESA_FORMAT_SL8:
1800 *datatype = GL_UNSIGNED_BYTE;
1801 *comps = 1;
1802 return;
1803 case MESA_FORMAT_SLA8:
1804 *datatype = GL_UNSIGNED_BYTE;
1805 *comps = 2;
1806 return;
1807 #endif
1808
1809 #if FEATURE_texture_fxt1
1810 case MESA_FORMAT_RGB_FXT1:
1811 case MESA_FORMAT_RGBA_FXT1:
1812 #endif
1813 #if FEATURE_texture_s3tc
1814 case MESA_FORMAT_RGB_DXT1:
1815 case MESA_FORMAT_RGBA_DXT1:
1816 case MESA_FORMAT_RGBA_DXT3:
1817 case MESA_FORMAT_RGBA_DXT5:
1818 #if FEATURE_EXT_texture_sRGB
1819 case MESA_FORMAT_SRGB_DXT1:
1820 case MESA_FORMAT_SRGBA_DXT1:
1821 case MESA_FORMAT_SRGBA_DXT3:
1822 case MESA_FORMAT_SRGBA_DXT5:
1823 #endif
1824 #endif
1825 case MESA_FORMAT_RED_RGTC1:
1826 case MESA_FORMAT_SIGNED_RED_RGTC1:
1827 case MESA_FORMAT_RG_RGTC2:
1828 case MESA_FORMAT_SIGNED_RG_RGTC2:
1829 case MESA_FORMAT_L_LATC1:
1830 case MESA_FORMAT_SIGNED_L_LATC1:
1831 case MESA_FORMAT_LA_LATC2:
1832 case MESA_FORMAT_SIGNED_LA_LATC2:
1833 /* XXX generate error instead? */
1834 *datatype = GL_UNSIGNED_BYTE;
1835 *comps = 0;
1836 return;
1837
1838 case MESA_FORMAT_RGBA_FLOAT32:
1839 *datatype = GL_FLOAT;
1840 *comps = 4;
1841 return;
1842 case MESA_FORMAT_RGBA_FLOAT16:
1843 *datatype = GL_HALF_FLOAT_ARB;
1844 *comps = 4;
1845 return;
1846 case MESA_FORMAT_RGB_FLOAT32:
1847 *datatype = GL_FLOAT;
1848 *comps = 3;
1849 return;
1850 case MESA_FORMAT_RGB_FLOAT16:
1851 *datatype = GL_HALF_FLOAT_ARB;
1852 *comps = 3;
1853 return;
1854 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
1855 case MESA_FORMAT_RG_FLOAT32:
1856 *datatype = GL_FLOAT;
1857 *comps = 2;
1858 return;
1859 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
1860 case MESA_FORMAT_RG_FLOAT16:
1861 *datatype = GL_HALF_FLOAT_ARB;
1862 *comps = 2;
1863 return;
1864 case MESA_FORMAT_ALPHA_FLOAT32:
1865 case MESA_FORMAT_LUMINANCE_FLOAT32:
1866 case MESA_FORMAT_INTENSITY_FLOAT32:
1867 case MESA_FORMAT_R_FLOAT32:
1868 *datatype = GL_FLOAT;
1869 *comps = 1;
1870 return;
1871 case MESA_FORMAT_ALPHA_FLOAT16:
1872 case MESA_FORMAT_LUMINANCE_FLOAT16:
1873 case MESA_FORMAT_INTENSITY_FLOAT16:
1874 case MESA_FORMAT_R_FLOAT16:
1875 *datatype = GL_HALF_FLOAT_ARB;
1876 *comps = 1;
1877 return;
1878
1879 case MESA_FORMAT_RGBA_INT8:
1880 *datatype = GL_BYTE;
1881 *comps = 4;
1882 return;
1883 case MESA_FORMAT_RGBA_INT16:
1884 *datatype = GL_SHORT;
1885 *comps = 4;
1886 return;
1887 case MESA_FORMAT_RGBA_INT32:
1888 *datatype = GL_INT;
1889 *comps = 4;
1890 return;
1891
1892 /**
1893 * \name Non-normalized unsigned integer formats.
1894 */
1895 case MESA_FORMAT_RGBA_UINT8:
1896 *datatype = GL_UNSIGNED_BYTE;
1897 *comps = 4;
1898 return;
1899 case MESA_FORMAT_RGBA_UINT16:
1900 *datatype = GL_UNSIGNED_SHORT;
1901 *comps = 4;
1902 return;
1903 case MESA_FORMAT_RGBA_UINT32:
1904 *datatype = GL_UNSIGNED_INT;
1905 *comps = 4;
1906 return;
1907
1908 case MESA_FORMAT_RGB9_E5_FLOAT:
1909 *datatype = GL_UNSIGNED_INT_5_9_9_9_REV;
1910 *comps = 3;
1911 return;
1912
1913 case MESA_FORMAT_R11_G11_B10_FLOAT:
1914 *datatype = GL_UNSIGNED_INT_10F_11F_11F_REV;
1915 *comps = 3;
1916 return;
1917
1918 case MESA_FORMAT_COUNT:
1919 assert(0);
1920 return;
1921
1922 case MESA_FORMAT_NONE:
1923 /* For debug builds, warn if any formats are not handled */
1924 #ifdef DEBUG
1925 default:
1926 #endif
1927 _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps",
1928 _mesa_get_format_name(format));
1929 *datatype = 0;
1930 *comps = 1;
1931 }
1932 }