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