• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "macros.h"
31 #include "glformats.h"
32 
33 
34 /**
35  * Information about texture formats.
36  */
37 struct gl_format_info
38 {
39    gl_format Name;
40 
41    /** text name for debugging */
42    const char *StrName;
43 
44    /**
45     * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA,
46     * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA,
47     * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL, GL_DUDV_ATI.
48     */
49    GLenum BaseFormat;
50 
51    /**
52     * Logical data type: one of  GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED,
53     * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
54     */
55    GLenum DataType;
56 
57    GLubyte RedBits;
58    GLubyte GreenBits;
59    GLubyte BlueBits;
60    GLubyte AlphaBits;
61    GLubyte LuminanceBits;
62    GLubyte IntensityBits;
63    GLubyte IndexBits;
64    GLubyte DepthBits;
65    GLubyte StencilBits;
66 
67    /**
68     * To describe compressed formats.  If not compressed, Width=Height=1.
69     */
70    GLubyte BlockWidth, BlockHeight;
71    GLubyte BytesPerBlock;
72 };
73 
74 
75 /**
76  * Info about each format.
77  * These must be in the same order as the MESA_FORMAT_* enums so that
78  * we can do lookups without searching.
79  */
80 static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
81 {
82    {
83       MESA_FORMAT_NONE,            /* Name */
84       "MESA_FORMAT_NONE",          /* StrName */
85       GL_NONE,                     /* BaseFormat */
86       GL_NONE,                     /* DataType */
87       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
88       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
89       0, 0, 0                      /* BlockWidth/Height,Bytes */
90    },
91    {
92       MESA_FORMAT_RGBA8888,        /* Name */
93       "MESA_FORMAT_RGBA8888",      /* StrName */
94       GL_RGBA,                     /* BaseFormat */
95       GL_UNSIGNED_NORMALIZED,      /* DataType */
96       8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
97       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
98       1, 1, 4                      /* BlockWidth/Height,Bytes */
99    },
100    {
101       MESA_FORMAT_RGBA8888_REV,    /* Name */
102       "MESA_FORMAT_RGBA8888_REV",  /* StrName */
103       GL_RGBA,                     /* BaseFormat */
104       GL_UNSIGNED_NORMALIZED,      /* DataType */
105       8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
106       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
107       1, 1, 4                      /* BlockWidth/Height,Bytes */
108    },
109    {
110       MESA_FORMAT_ARGB8888,        /* Name */
111       "MESA_FORMAT_ARGB8888",      /* StrName */
112       GL_RGBA,                     /* BaseFormat */
113       GL_UNSIGNED_NORMALIZED,      /* DataType */
114       8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
115       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
116       1, 1, 4                      /* BlockWidth/Height,Bytes */
117    },
118    {
119       MESA_FORMAT_ARGB8888_REV,    /* Name */
120       "MESA_FORMAT_ARGB8888_REV",  /* StrName */
121       GL_RGBA,                     /* BaseFormat */
122       GL_UNSIGNED_NORMALIZED,      /* DataType */
123       8, 8, 8, 8,                  /* Red/Green/Blue/AlphaBits */
124       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
125       1, 1, 4                      /* BlockWidth/Height,Bytes */
126    },
127    {
128       MESA_FORMAT_RGBX8888,        /* Name */
129       "MESA_FORMAT_RGBX8888",      /* StrName */
130       GL_RGB,                      /* BaseFormat */
131       GL_UNSIGNED_NORMALIZED,      /* DataType */
132       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
133       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
134       1, 1, 4                      /* BlockWidth/Height,Bytes */
135    },
136    {
137       MESA_FORMAT_RGBX8888_REV,    /* Name */
138       "MESA_FORMAT_RGBX8888_REV",  /* StrName */
139       GL_RGB,                      /* BaseFormat */
140       GL_UNSIGNED_NORMALIZED,      /* DataType */
141       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
142       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
143       1, 1, 4                      /* BlockWidth/Height,Bytes */
144    },
145    {
146       MESA_FORMAT_XRGB8888,        /* Name */
147       "MESA_FORMAT_XRGB8888",      /* StrName */
148       GL_RGB,                      /* BaseFormat */
149       GL_UNSIGNED_NORMALIZED,      /* DataType */
150       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
151       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
152       1, 1, 4                      /* BlockWidth/Height,Bytes */
153    },
154    {
155       MESA_FORMAT_XRGB8888_REV,    /* Name */
156       "MESA_FORMAT_XRGB8888_REV",  /* StrName */
157       GL_RGB,                      /* BaseFormat */
158       GL_UNSIGNED_NORMALIZED,      /* DataType */
159       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
160       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
161       1, 1, 4                      /* BlockWidth/Height,Bytes */
162    },
163    {
164       MESA_FORMAT_RGB888,          /* Name */
165       "MESA_FORMAT_RGB888",        /* StrName */
166       GL_RGB,                      /* BaseFormat */
167       GL_UNSIGNED_NORMALIZED,      /* DataType */
168       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
169       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
170       1, 1, 3                      /* BlockWidth/Height,Bytes */
171    },
172    {
173       MESA_FORMAT_BGR888,          /* Name */
174       "MESA_FORMAT_BGR888",        /* StrName */
175       GL_RGB,                      /* BaseFormat */
176       GL_UNSIGNED_NORMALIZED,      /* DataType */
177       8, 8, 8, 0,                  /* Red/Green/Blue/AlphaBits */
178       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
179       1, 1, 3                      /* BlockWidth/Height,Bytes */
180    },
181    {
182       MESA_FORMAT_RGB565,          /* Name */
183       "MESA_FORMAT_RGB565",        /* StrName */
184       GL_RGB,                      /* BaseFormat */
185       GL_UNSIGNED_NORMALIZED,      /* DataType */
186       5, 6, 5, 0,                  /* Red/Green/Blue/AlphaBits */
187       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
188       1, 1, 2                      /* BlockWidth/Height,Bytes */
189    },
190    {
191       MESA_FORMAT_RGB565_REV,      /* Name */
192       "MESA_FORMAT_RGB565_REV",    /* StrName */
193       GL_RGB,                      /* BaseFormat */
194       GL_UNSIGNED_NORMALIZED,      /* DataType */
195       5, 6, 5, 0,                  /* Red/Green/Blue/AlphaBits */
196       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
197       1, 1, 2                      /* BlockWidth/Height,Bytes */
198    },
199    {
200       MESA_FORMAT_ARGB4444,        /* Name */
201       "MESA_FORMAT_ARGB4444",      /* StrName */
202       GL_RGBA,                     /* BaseFormat */
203       GL_UNSIGNED_NORMALIZED,      /* DataType */
204       4, 4, 4, 4,                  /* Red/Green/Blue/AlphaBits */
205       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
206       1, 1, 2                      /* BlockWidth/Height,Bytes */
207    },
208    {
209       MESA_FORMAT_ARGB4444_REV,    /* Name */
210       "MESA_FORMAT_ARGB4444_REV",  /* StrName */
211       GL_RGBA,                     /* BaseFormat */
212       GL_UNSIGNED_NORMALIZED,      /* DataType */
213       4, 4, 4, 4,                  /* Red/Green/Blue/AlphaBits */
214       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
215       1, 1, 2                      /* BlockWidth/Height,Bytes */
216    },
217    {
218       MESA_FORMAT_RGBA5551,        /* Name */
219       "MESA_FORMAT_RGBA5551",      /* StrName */
220       GL_RGBA,                     /* BaseFormat */
221       GL_UNSIGNED_NORMALIZED,      /* DataType */
222       5, 5, 5, 1,                  /* Red/Green/Blue/AlphaBits */
223       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
224       1, 1, 2                      /* BlockWidth/Height,Bytes */
225    },
226    {
227       MESA_FORMAT_ARGB1555,        /* Name */
228       "MESA_FORMAT_ARGB1555",      /* StrName */
229       GL_RGBA,                     /* BaseFormat */
230       GL_UNSIGNED_NORMALIZED,      /* DataType */
231       5, 5, 5, 1,                  /* Red/Green/Blue/AlphaBits */
232       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
233       1, 1, 2                      /* BlockWidth/Height,Bytes */
234    },
235    {
236       MESA_FORMAT_ARGB1555_REV,    /* Name */
237       "MESA_FORMAT_ARGB1555_REV",  /* StrName */
238       GL_RGBA,                     /* BaseFormat */
239       GL_UNSIGNED_NORMALIZED,      /* DataType */
240       5, 5, 5, 1,                  /* Red/Green/Blue/AlphaBits */
241       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
242       1, 1, 2                      /* BlockWidth/Height,Bytes */
243    },
244    {
245       MESA_FORMAT_AL44,            /* Name */
246       "MESA_FORMAT_AL44",          /* StrName */
247       GL_LUMINANCE_ALPHA,          /* BaseFormat */
248       GL_UNSIGNED_NORMALIZED,      /* DataType */
249       0, 0, 0, 4,                  /* Red/Green/Blue/AlphaBits */
250       4, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
251       1, 1, 1                      /* BlockWidth/Height,Bytes */
252    },
253    {
254       MESA_FORMAT_AL88,            /* Name */
255       "MESA_FORMAT_AL88",          /* StrName */
256       GL_LUMINANCE_ALPHA,          /* BaseFormat */
257       GL_UNSIGNED_NORMALIZED,      /* DataType */
258       0, 0, 0, 8,                  /* Red/Green/Blue/AlphaBits */
259       8, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
260       1, 1, 2                      /* BlockWidth/Height,Bytes */
261    },
262    {
263       MESA_FORMAT_AL88_REV,        /* Name */
264       "MESA_FORMAT_AL88_REV",      /* StrName */
265       GL_LUMINANCE_ALPHA,          /* BaseFormat */
266       GL_UNSIGNED_NORMALIZED,      /* DataType */
267       0, 0, 0, 8,                  /* Red/Green/Blue/AlphaBits */
268       8, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
269       1, 1, 2                      /* BlockWidth/Height,Bytes */
270    },
271    {
272       MESA_FORMAT_AL1616,          /* Name */
273       "MESA_FORMAT_AL1616",        /* StrName */
274       GL_LUMINANCE_ALPHA,          /* BaseFormat */
275       GL_UNSIGNED_NORMALIZED,      /* DataType */
276       0, 0, 0, 16,                 /* Red/Green/Blue/AlphaBits */
277       16, 0, 0, 0, 0,              /* Lum/Int/Index/Depth/StencilBits */
278       1, 1, 4                      /* BlockWidth/Height,Bytes */
279    },
280    {
281       MESA_FORMAT_AL1616_REV,      /* Name */
282       "MESA_FORMAT_AL1616_REV",    /* StrName */
283       GL_LUMINANCE_ALPHA,          /* BaseFormat */
284       GL_UNSIGNED_NORMALIZED,      /* DataType */
285       0, 0, 0, 16,                 /* Red/Green/Blue/AlphaBits */
286       16, 0, 0, 0, 0,              /* Lum/Int/Index/Depth/StencilBits */
287       1, 1, 4                      /* BlockWidth/Height,Bytes */
288    },
289    {
290       MESA_FORMAT_RGB332,          /* Name */
291       "MESA_FORMAT_RGB332",        /* StrName */
292       GL_RGB,                      /* BaseFormat */
293       GL_UNSIGNED_NORMALIZED,      /* DataType */
294       3, 3, 2, 0,                  /* Red/Green/Blue/AlphaBits */
295       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
296       1, 1, 1                      /* BlockWidth/Height,Bytes */
297    },
298    {
299       MESA_FORMAT_A8,              /* Name */
300       "MESA_FORMAT_A8",            /* StrName */
301       GL_ALPHA,                    /* BaseFormat */
302       GL_UNSIGNED_NORMALIZED,      /* DataType */
303       0, 0, 0, 8,                  /* Red/Green/Blue/AlphaBits */
304       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
305       1, 1, 1                      /* BlockWidth/Height,Bytes */
306    },
307    {
308       MESA_FORMAT_A16,             /* Name */
309       "MESA_FORMAT_A16",           /* StrName */
310       GL_ALPHA,                    /* BaseFormat */
311       GL_UNSIGNED_NORMALIZED,      /* DataType */
312       0, 0, 0, 16,                 /* Red/Green/Blue/AlphaBits */
313       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
314       1, 1, 2                      /* BlockWidth/Height,Bytes */
315    },
316    {
317       MESA_FORMAT_L8,              /* Name */
318       "MESA_FORMAT_L8",            /* StrName */
319       GL_LUMINANCE,                /* BaseFormat */
320       GL_UNSIGNED_NORMALIZED,      /* DataType */
321       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
322       8, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
323       1, 1, 1                      /* BlockWidth/Height,Bytes */
324    },
325    {
326       MESA_FORMAT_L16,             /* Name */
327       "MESA_FORMAT_L16",           /* StrName */
328       GL_LUMINANCE,                /* BaseFormat */
329       GL_UNSIGNED_NORMALIZED,      /* DataType */
330       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
331       16, 0, 0, 0, 0,              /* Lum/Int/Index/Depth/StencilBits */
332       1, 1, 2                      /* BlockWidth/Height,Bytes */
333    },
334    {
335       MESA_FORMAT_I8,              /* Name */
336       "MESA_FORMAT_I8",            /* StrName */
337       GL_INTENSITY,                /* BaseFormat */
338       GL_UNSIGNED_NORMALIZED,      /* DataType */
339       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
340       0, 8, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
341       1, 1, 1                      /* BlockWidth/Height,Bytes */
342    },
343    {
344       MESA_FORMAT_I16,             /* Name */
345       "MESA_FORMAT_I16",           /* StrName */
346       GL_INTENSITY,                /* BaseFormat */
347       GL_UNSIGNED_NORMALIZED,      /* DataType */
348       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
349       0, 16, 0, 0, 0,              /* Lum/Int/Index/Depth/StencilBits */
350       1, 1, 2                      /* BlockWidth/Height,Bytes */
351    },
352    {
353       MESA_FORMAT_YCBCR,           /* Name */
354       "MESA_FORMAT_YCBCR",         /* StrName */
355       GL_YCBCR_MESA,               /* BaseFormat */
356       GL_UNSIGNED_NORMALIZED,      /* DataType */
357       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
358       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
359       1, 1, 2                      /* BlockWidth/Height,Bytes */
360    },
361    {
362       MESA_FORMAT_YCBCR_REV,       /* Name */
363       "MESA_FORMAT_YCBCR_REV",     /* StrName */
364       GL_YCBCR_MESA,               /* BaseFormat */
365       GL_UNSIGNED_NORMALIZED,      /* DataType */
366       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
367       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
368       1, 1, 2                      /* BlockWidth/Height,Bytes */
369    },
370    {
371       MESA_FORMAT_R8,
372       "MESA_FORMAT_R8",
373       GL_RED,
374       GL_UNSIGNED_NORMALIZED,
375       8, 0, 0, 0,
376       0, 0, 0, 0, 0,
377       1, 1, 1
378    },
379    {
380       MESA_FORMAT_GR88,
381       "MESA_FORMAT_GR88",
382       GL_RG,
383       GL_UNSIGNED_NORMALIZED,
384       8, 8, 0, 0,
385       0, 0, 0, 0, 0,
386       1, 1, 2
387    },
388    {
389       MESA_FORMAT_RG88,
390       "MESA_FORMAT_RG88",
391       GL_RG,
392       GL_UNSIGNED_NORMALIZED,
393       8, 8, 0, 0,
394       0, 0, 0, 0, 0,
395       1, 1, 2
396    },
397    {
398       MESA_FORMAT_R16,
399       "MESA_FORMAT_R16",
400       GL_RED,
401       GL_UNSIGNED_NORMALIZED,
402       16, 0, 0, 0,
403       0, 0, 0, 0, 0,
404       1, 1, 2
405    },
406    {
407       MESA_FORMAT_RG1616,
408       "MESA_FORMAT_RG1616",
409       GL_RG,
410       GL_UNSIGNED_NORMALIZED,
411       16, 16, 0, 0,
412       0, 0, 0, 0, 0,
413       1, 1, 4
414    },
415    {
416       MESA_FORMAT_RG1616_REV,
417       "MESA_FORMAT_RG1616_REV",
418       GL_RG,
419       GL_UNSIGNED_NORMALIZED,
420       16, 16, 0, 0,
421       0, 0, 0, 0, 0,
422       1, 1, 4
423    },
424    {
425       MESA_FORMAT_ARGB2101010,
426       "MESA_FORMAT_ARGB2101010",
427       GL_RGBA,
428       GL_UNSIGNED_NORMALIZED,
429       10, 10, 10, 2,
430       0, 0, 0, 0, 0,
431       1, 1, 4
432    },
433    {
434       MESA_FORMAT_Z24_S8,          /* Name */
435       "MESA_FORMAT_Z24_S8",        /* StrName */
436       GL_DEPTH_STENCIL,            /* BaseFormat */
437       GL_UNSIGNED_NORMALIZED,      /* DataType */
438       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
439       0, 0, 0, 24, 8,              /* Lum/Int/Index/Depth/StencilBits */
440       1, 1, 4                      /* BlockWidth/Height,Bytes */
441    },
442    {
443       MESA_FORMAT_S8_Z24,          /* Name */
444       "MESA_FORMAT_S8_Z24",        /* StrName */
445       GL_DEPTH_STENCIL,            /* BaseFormat */
446       GL_UNSIGNED_NORMALIZED,      /* DataType */
447       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
448       0, 0, 0, 24, 8,              /* Lum/Int/Index/Depth/StencilBits */
449       1, 1, 4                      /* BlockWidth/Height,Bytes */
450    },
451    {
452       MESA_FORMAT_Z16,             /* Name */
453       "MESA_FORMAT_Z16",           /* StrName */
454       GL_DEPTH_COMPONENT,          /* BaseFormat */
455       GL_UNSIGNED_NORMALIZED,      /* DataType */
456       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
457       0, 0, 0, 16, 0,              /* Lum/Int/Index/Depth/StencilBits */
458       1, 1, 2                      /* BlockWidth/Height,Bytes */
459    },
460    {
461       MESA_FORMAT_X8_Z24,          /* Name */
462       "MESA_FORMAT_X8_Z24",        /* StrName */
463       GL_DEPTH_COMPONENT,          /* BaseFormat */
464       GL_UNSIGNED_NORMALIZED,      /* DataType */
465       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
466       0, 0, 0, 24, 0,              /* Lum/Int/Index/Depth/StencilBits */
467       1, 1, 4                      /* BlockWidth/Height,Bytes */
468    },
469    {
470       MESA_FORMAT_Z24_X8,          /* Name */
471       "MESA_FORMAT_Z24_X8",        /* StrName */
472       GL_DEPTH_COMPONENT,          /* BaseFormat */
473       GL_UNSIGNED_NORMALIZED,      /* DataType */
474       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
475       0, 0, 0, 24, 0,              /* Lum/Int/Index/Depth/StencilBits */
476       1, 1, 4                      /* BlockWidth/Height,Bytes */
477    },
478    {
479       MESA_FORMAT_Z32,             /* Name */
480       "MESA_FORMAT_Z32",           /* StrName */
481       GL_DEPTH_COMPONENT,          /* BaseFormat */
482       GL_UNSIGNED_NORMALIZED,      /* DataType */
483       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
484       0, 0, 0, 32, 0,              /* Lum/Int/Index/Depth/StencilBits */
485       1, 1, 4                      /* BlockWidth/Height,Bytes */
486    },
487    {
488       MESA_FORMAT_S8,              /* Name */
489       "MESA_FORMAT_S8",            /* StrName */
490       GL_STENCIL_INDEX,            /* BaseFormat */
491       GL_UNSIGNED_INT,             /* DataType */
492       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
493       0, 0, 0, 0, 8,               /* Lum/Int/Index/Depth/StencilBits */
494       1, 1, 1                      /* BlockWidth/Height,Bytes */
495    },
496    {
497       MESA_FORMAT_SRGB8,
498       "MESA_FORMAT_SRGB8",
499       GL_RGB,
500       GL_UNSIGNED_NORMALIZED,
501       8, 8, 8, 0,
502       0, 0, 0, 0, 0,
503       1, 1, 3
504    },
505    {
506       MESA_FORMAT_SRGBA8,
507       "MESA_FORMAT_SRGBA8",
508       GL_RGBA,
509       GL_UNSIGNED_NORMALIZED,
510       8, 8, 8, 8,
511       0, 0, 0, 0, 0,
512       1, 1, 4
513    },
514    {
515       MESA_FORMAT_SARGB8,
516       "MESA_FORMAT_SARGB8",
517       GL_RGBA,
518       GL_UNSIGNED_NORMALIZED,
519       8, 8, 8, 8,
520       0, 0, 0, 0, 0,
521       1, 1, 4
522    },
523    {
524       MESA_FORMAT_SL8,
525       "MESA_FORMAT_SL8",
526       GL_LUMINANCE,
527       GL_UNSIGNED_NORMALIZED,
528       0, 0, 0, 0,
529       8, 0, 0, 0, 0,
530       1, 1, 1
531    },
532    {
533       MESA_FORMAT_SLA8,
534       "MESA_FORMAT_SLA8",
535       GL_LUMINANCE_ALPHA,
536       GL_UNSIGNED_NORMALIZED,
537       0, 0, 0, 8,
538       8, 0, 0, 0, 0,
539       1, 1, 2
540    },
541    {
542       MESA_FORMAT_SRGB_DXT1,       /* Name */
543       "MESA_FORMAT_SRGB_DXT1",     /* StrName */
544       GL_RGB,                      /* BaseFormat */
545       GL_UNSIGNED_NORMALIZED,      /* DataType */
546       4, 4, 4, 0,                  /* approx Red/Green/Blue/AlphaBits */
547       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
548       4, 4, 8                      /* 8 bytes per 4x4 block */
549    },
550    {
551       MESA_FORMAT_SRGBA_DXT1,
552       "MESA_FORMAT_SRGBA_DXT1",
553       GL_RGBA,
554       GL_UNSIGNED_NORMALIZED,
555       4, 4, 4, 4,
556       0, 0, 0, 0, 0,
557       4, 4, 8                      /* 8 bytes per 4x4 block */
558    },
559    {
560       MESA_FORMAT_SRGBA_DXT3,
561       "MESA_FORMAT_SRGBA_DXT3",
562       GL_RGBA,
563       GL_UNSIGNED_NORMALIZED,
564       4, 4, 4, 4,
565       0, 0, 0, 0, 0,
566       4, 4, 16                     /* 16 bytes per 4x4 block */
567    },
568    {
569       MESA_FORMAT_SRGBA_DXT5,
570       "MESA_FORMAT_SRGBA_DXT5",
571       GL_RGBA,
572       GL_UNSIGNED_NORMALIZED,
573       4, 4, 4, 4,
574       0, 0, 0, 0, 0,
575       4, 4, 16                     /* 16 bytes per 4x4 block */
576    },
577 
578    {
579       MESA_FORMAT_RGB_FXT1,
580       "MESA_FORMAT_RGB_FXT1",
581       GL_RGB,
582       GL_UNSIGNED_NORMALIZED,
583       4, 4, 4, 0,                  /* approx Red/Green/BlueBits */
584       0, 0, 0, 0, 0,
585       8, 4, 16                     /* 16 bytes per 8x4 block */
586    },
587    {
588       MESA_FORMAT_RGBA_FXT1,
589       "MESA_FORMAT_RGBA_FXT1",
590       GL_RGBA,
591       GL_UNSIGNED_NORMALIZED,
592       4, 4, 4, 1,                  /* approx Red/Green/Blue/AlphaBits */
593       0, 0, 0, 0, 0,
594       8, 4, 16                     /* 16 bytes per 8x4 block */
595    },
596 
597    {
598       MESA_FORMAT_RGB_DXT1,        /* Name */
599       "MESA_FORMAT_RGB_DXT1",      /* StrName */
600       GL_RGB,                      /* BaseFormat */
601       GL_UNSIGNED_NORMALIZED,      /* DataType */
602       4, 4, 4, 0,                  /* approx Red/Green/Blue/AlphaBits */
603       0, 0, 0, 0, 0,               /* Lum/Int/Index/Depth/StencilBits */
604       4, 4, 8                      /* 8 bytes per 4x4 block */
605    },
606    {
607       MESA_FORMAT_RGBA_DXT1,
608       "MESA_FORMAT_RGBA_DXT1",
609       GL_RGBA,
610       GL_UNSIGNED_NORMALIZED,
611       4, 4, 4, 4,
612       0, 0, 0, 0, 0,
613       4, 4, 8                      /* 8 bytes per 4x4 block */
614    },
615    {
616       MESA_FORMAT_RGBA_DXT3,
617       "MESA_FORMAT_RGBA_DXT3",
618       GL_RGBA,
619       GL_UNSIGNED_NORMALIZED,
620       4, 4, 4, 4,
621       0, 0, 0, 0, 0,
622       4, 4, 16                     /* 16 bytes per 4x4 block */
623    },
624    {
625       MESA_FORMAT_RGBA_DXT5,
626       "MESA_FORMAT_RGBA_DXT5",
627       GL_RGBA,
628       GL_UNSIGNED_NORMALIZED,
629       4, 4, 4, 4,
630       0, 0, 0, 0, 0,
631       4, 4, 16                     /* 16 bytes per 4x4 block */
632    },
633    {
634       MESA_FORMAT_RGBA_FLOAT32,
635       "MESA_FORMAT_RGBA_FLOAT32",
636       GL_RGBA,
637       GL_FLOAT,
638       32, 32, 32, 32,
639       0, 0, 0, 0, 0,
640       1, 1, 16
641    },
642    {
643       MESA_FORMAT_RGBA_FLOAT16,
644       "MESA_FORMAT_RGBA_FLOAT16",
645       GL_RGBA,
646       GL_FLOAT,
647       16, 16, 16, 16,
648       0, 0, 0, 0, 0,
649       1, 1, 8
650    },
651    {
652       MESA_FORMAT_RGB_FLOAT32,
653       "MESA_FORMAT_RGB_FLOAT32",
654       GL_RGB,
655       GL_FLOAT,
656       32, 32, 32, 0,
657       0, 0, 0, 0, 0,
658       1, 1, 12
659    },
660    {
661       MESA_FORMAT_RGB_FLOAT16,
662       "MESA_FORMAT_RGB_FLOAT16",
663       GL_RGB,
664       GL_FLOAT,
665       16, 16, 16, 0,
666       0, 0, 0, 0, 0,
667       1, 1, 6
668    },
669    {
670       MESA_FORMAT_ALPHA_FLOAT32,
671       "MESA_FORMAT_ALPHA_FLOAT32",
672       GL_ALPHA,
673       GL_FLOAT,
674       0, 0, 0, 32,
675       0, 0, 0, 0, 0,
676       1, 1, 4
677    },
678    {
679       MESA_FORMAT_ALPHA_FLOAT16,
680       "MESA_FORMAT_ALPHA_FLOAT16",
681       GL_ALPHA,
682       GL_FLOAT,
683       0, 0, 0, 16,
684       0, 0, 0, 0, 0,
685       1, 1, 2
686    },
687    {
688       MESA_FORMAT_LUMINANCE_FLOAT32,
689       "MESA_FORMAT_LUMINANCE_FLOAT32",
690       GL_LUMINANCE,
691       GL_FLOAT,
692       0, 0, 0, 0,
693       32, 0, 0, 0, 0,
694       1, 1, 4
695    },
696    {
697       MESA_FORMAT_LUMINANCE_FLOAT16,
698       "MESA_FORMAT_LUMINANCE_FLOAT16",
699       GL_LUMINANCE,
700       GL_FLOAT,
701       0, 0, 0, 0,
702       16, 0, 0, 0, 0,
703       1, 1, 2
704    },
705    {
706       MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
707       "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
708       GL_LUMINANCE_ALPHA,
709       GL_FLOAT,
710       0, 0, 0, 32,
711       32, 0, 0, 0, 0,
712       1, 1, 8
713    },
714    {
715       MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
716       "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
717       GL_LUMINANCE_ALPHA,
718       GL_FLOAT,
719       0, 0, 0, 16,
720       16, 0, 0, 0, 0,
721       1, 1, 4
722    },
723    {
724       MESA_FORMAT_INTENSITY_FLOAT32,
725       "MESA_FORMAT_INTENSITY_FLOAT32",
726       GL_INTENSITY,
727       GL_FLOAT,
728       0, 0, 0, 0,
729       0, 32, 0, 0, 0,
730       1, 1, 4
731    },
732    {
733       MESA_FORMAT_INTENSITY_FLOAT16,
734       "MESA_FORMAT_INTENSITY_FLOAT16",
735       GL_INTENSITY,
736       GL_FLOAT,
737       0, 0, 0, 0,
738       0, 16, 0, 0, 0,
739       1, 1, 2
740    },
741    {
742       MESA_FORMAT_R_FLOAT32,
743       "MESA_FORMAT_R_FLOAT32",
744       GL_RED,
745       GL_FLOAT,
746       32, 0, 0, 0,
747       0, 0, 0, 0, 0,
748       1, 1, 4
749    },
750    {
751       MESA_FORMAT_R_FLOAT16,
752       "MESA_FORMAT_R_FLOAT16",
753       GL_RED,
754       GL_FLOAT,
755       16, 0, 0, 0,
756       0, 0, 0, 0, 0,
757       1, 1, 2
758    },
759    {
760       MESA_FORMAT_RG_FLOAT32,
761       "MESA_FORMAT_RG_FLOAT32",
762       GL_RG,
763       GL_FLOAT,
764       32, 32, 0, 0,
765       0, 0, 0, 0, 0,
766       1, 1, 8
767    },
768    {
769       MESA_FORMAT_RG_FLOAT16,
770       "MESA_FORMAT_RG_FLOAT16",
771       GL_RG,
772       GL_FLOAT,
773       16, 16, 0, 0,
774       0, 0, 0, 0, 0,
775       1, 1, 4
776    },
777 
778    /* unnormalized signed int formats */
779    /* unnormalized unsigned int formats */
780    {
781       MESA_FORMAT_ALPHA_UINT8,
782       "MESA_FORMAT_ALPHA_UINT8",
783       GL_ALPHA,
784       GL_UNSIGNED_INT,
785       0, 0, 0, 8,
786       0, 0, 0, 0, 0,
787       1, 1, 1
788    },
789    {
790       MESA_FORMAT_ALPHA_UINT16,
791       "MESA_FORMAT_ALPHA_UINT16",
792       GL_ALPHA,
793       GL_UNSIGNED_INT,
794       0, 0, 0, 16,
795       0, 0, 0, 0, 0,
796       1, 1, 2
797    },
798    {
799       MESA_FORMAT_ALPHA_UINT32,
800       "MESA_FORMAT_ALPHA_UINT32",
801       GL_ALPHA,
802       GL_UNSIGNED_INT,
803       0, 0, 0, 32,
804       0, 0, 0, 0, 0,
805       1, 1, 4
806    },
807    {
808       MESA_FORMAT_ALPHA_INT8,
809       "MESA_FORMAT_ALPHA_INT8",
810       GL_ALPHA,
811       GL_INT,
812       0, 0, 0, 8,
813       0, 0, 0, 0, 0,
814       1, 1, 1
815    },
816    {
817       MESA_FORMAT_ALPHA_INT16,
818       "MESA_FORMAT_ALPHA_INT16",
819       GL_ALPHA,
820       GL_INT,
821       0, 0, 0, 16,
822       0, 0, 0, 0, 0,
823       1, 1, 2
824    },
825    {
826       MESA_FORMAT_ALPHA_INT32,
827       "MESA_FORMAT_ALPHA_INT32",
828       GL_ALPHA,
829       GL_INT,
830       0, 0, 0, 32,
831       0, 0, 0, 0, 0,
832       1, 1, 4
833    },
834    {
835       MESA_FORMAT_INTENSITY_UINT8,
836       "MESA_FORMAT_INTENSITY_UINT8",
837       GL_INTENSITY,
838       GL_UNSIGNED_INT,
839       0, 0, 0, 0,
840       0, 8, 0, 0, 0,
841       1, 1, 1
842    },
843    {
844       MESA_FORMAT_INTENSITY_UINT16,
845       "MESA_FORMAT_INTENSITY_UINT16",
846       GL_INTENSITY,
847       GL_UNSIGNED_INT,
848       0, 0, 0, 0,
849       0, 16, 0, 0, 0,
850       1, 1, 2
851    },
852    {
853       MESA_FORMAT_INTENSITY_UINT32,
854       "MESA_FORMAT_INTENSITY_UINT32",
855       GL_INTENSITY,
856       GL_UNSIGNED_INT,
857       0, 0, 0, 0,
858       0, 32, 0, 0, 0,
859       1, 1, 4
860    },
861    {
862       MESA_FORMAT_INTENSITY_INT8,
863       "MESA_FORMAT_INTENSITY_INT8",
864       GL_INTENSITY,
865       GL_INT,
866       0, 0, 0, 0,
867       0, 8, 0, 0, 0,
868       1, 1, 1
869    },
870    {
871       MESA_FORMAT_INTENSITY_INT16,
872       "MESA_FORMAT_INTENSITY_INT16",
873       GL_INTENSITY,
874       GL_INT,
875       0, 0, 0, 0,
876       0, 16, 0, 0, 0,
877       1, 1, 2
878    },
879    {
880       MESA_FORMAT_INTENSITY_INT32,
881       "MESA_FORMAT_INTENSITY_INT32",
882       GL_INTENSITY,
883       GL_INT,
884       0, 0, 0, 0,
885       0, 32, 0, 0, 0,
886       1, 1, 4
887    },
888    {
889       MESA_FORMAT_LUMINANCE_UINT8,
890       "MESA_FORMAT_LUMINANCE_UINT8",
891       GL_LUMINANCE,
892       GL_UNSIGNED_INT,
893       0, 0, 0, 0,
894       8, 0, 0, 0, 0,
895       1, 1, 1
896    },
897    {
898       MESA_FORMAT_LUMINANCE_UINT16,
899       "MESA_FORMAT_LUMINANCE_UINT16",
900       GL_LUMINANCE,
901       GL_UNSIGNED_INT,
902       0, 0, 0, 0,
903       16, 0, 0, 0, 0,
904       1, 1, 2
905    },
906    {
907       MESA_FORMAT_LUMINANCE_UINT32,
908       "MESA_FORMAT_LUMINANCE_UINT32",
909       GL_LUMINANCE,
910       GL_UNSIGNED_INT,
911       0, 0, 0, 0,
912       32, 0, 0, 0, 0,
913       1, 1, 4
914    },
915    {
916       MESA_FORMAT_LUMINANCE_INT8,
917       "MESA_FORMAT_LUMINANCE_INT8",
918       GL_LUMINANCE,
919       GL_INT,
920       0, 0, 0, 0,
921       8, 0, 0, 0, 0,
922       1, 1, 1
923    },
924    {
925       MESA_FORMAT_LUMINANCE_INT16,
926       "MESA_FORMAT_LUMINANCE_INT16",
927       GL_LUMINANCE,
928       GL_INT,
929       0, 0, 0, 0,
930       16, 0, 0, 0, 0,
931       1, 1, 2
932    },
933    {
934       MESA_FORMAT_LUMINANCE_INT32,
935       "MESA_FORMAT_LUMINANCE_INT32",
936       GL_LUMINANCE,
937       GL_INT,
938       0, 0, 0, 0,
939       32, 0, 0, 0, 0,
940       1, 1, 4
941    },
942    {
943       MESA_FORMAT_LUMINANCE_ALPHA_UINT8,
944       "MESA_FORMAT_LUMINANCE_ALPHA_UINT8",
945       GL_LUMINANCE_ALPHA,
946       GL_UNSIGNED_INT,
947       0, 0, 0, 8,
948       8, 0, 0, 0, 0,
949       1, 1, 2
950    },
951    {
952       MESA_FORMAT_LUMINANCE_ALPHA_UINT16,
953       "MESA_FORMAT_LUMINANCE_ALPHA_UINT16",
954       GL_LUMINANCE_ALPHA,
955       GL_UNSIGNED_INT,
956       0, 0, 0, 16,
957       16, 0, 0, 0, 0,
958       1, 1, 4
959    },
960    {
961       MESA_FORMAT_LUMINANCE_ALPHA_UINT32,
962       "MESA_FORMAT_LUMINANCE_ALPHA_UINT32",
963       GL_LUMINANCE_ALPHA,
964       GL_UNSIGNED_INT,
965       0, 0, 0, 32,
966       32, 0, 0, 0, 0,
967       1, 1, 8
968    },
969    {
970       MESA_FORMAT_LUMINANCE_ALPHA_INT8,
971       "MESA_FORMAT_LUMINANCE_ALPHA_INT8",
972       GL_LUMINANCE_ALPHA,
973       GL_INT,
974       0, 0, 0, 8,
975       8, 0, 0, 0, 0,
976       1, 1, 2
977    },
978    {
979       MESA_FORMAT_LUMINANCE_ALPHA_INT16,
980       "MESA_FORMAT_LUMINANCE_ALPHA_INT16",
981       GL_LUMINANCE_ALPHA,
982       GL_INT,
983       0, 0, 0, 16,
984       16, 0, 0, 0, 0,
985       1, 1, 4
986    },
987    {
988       MESA_FORMAT_LUMINANCE_ALPHA_INT32,
989       "MESA_FORMAT_LUMINANCE_ALPHA_INT32",
990       GL_LUMINANCE_ALPHA,
991       GL_INT,
992       0, 0, 0, 32,
993       32, 0, 0, 0, 0,
994       1, 1, 8
995    },
996 
997    {
998       MESA_FORMAT_R_INT8,
999       "MESA_FORMAT_R_INT8",
1000       GL_RED,
1001       GL_INT,
1002       8, 0, 0, 0,
1003       0, 0, 0, 0, 0,
1004       1, 1, 1
1005    },
1006    {
1007       MESA_FORMAT_RG_INT8,
1008       "MESA_FORMAT_RG_INT8",
1009       GL_RG,
1010       GL_INT,
1011       8, 8, 0, 0,
1012       0, 0, 0, 0, 0,
1013       1, 1, 2
1014    },
1015    {
1016       MESA_FORMAT_RGB_INT8,
1017       "MESA_FORMAT_RGB_INT8",
1018       GL_RGB,
1019       GL_INT,
1020       8, 8, 8, 0,
1021       0, 0, 0, 0, 0,
1022       1, 1, 3
1023    },
1024    {
1025       MESA_FORMAT_RGBA_INT8,
1026       "MESA_FORMAT_RGBA_INT8",
1027       GL_RGBA,
1028       GL_INT,
1029       8, 8, 8, 8,
1030       0, 0, 0, 0, 0,
1031       1, 1, 4
1032    },
1033    {
1034       MESA_FORMAT_R_INT16,
1035       "MESA_FORMAT_R_INT16",
1036       GL_RED,
1037       GL_INT,
1038       16, 0, 0, 0,
1039       0, 0, 0, 0, 0,
1040       1, 1, 2
1041    },
1042    {
1043       MESA_FORMAT_RG_INT16,
1044       "MESA_FORMAT_RG_INT16",
1045       GL_RG,
1046       GL_INT,
1047       16, 16, 0, 0,
1048       0, 0, 0, 0, 0,
1049       1, 1, 4
1050    },
1051    {
1052       MESA_FORMAT_RGB_INT16,
1053       "MESA_FORMAT_RGB_INT16",
1054       GL_RGB,
1055       GL_INT,
1056       16, 16, 16, 0,
1057       0, 0, 0, 0, 0,
1058       1, 1, 6
1059    },
1060    {
1061       MESA_FORMAT_RGBA_INT16,
1062       "MESA_FORMAT_RGBA_INT16",
1063       GL_RGBA,
1064       GL_INT,
1065       16, 16, 16, 16,
1066       0, 0, 0, 0, 0,
1067       1, 1, 8
1068    },
1069    {
1070       MESA_FORMAT_R_INT32,
1071       "MESA_FORMAT_R_INT32",
1072       GL_RED,
1073       GL_INT,
1074       32, 0, 0, 0,
1075       0, 0, 0, 0, 0,
1076       1, 1, 4
1077    },
1078    {
1079       MESA_FORMAT_RG_INT32,
1080       "MESA_FORMAT_RG_INT32",
1081       GL_RG,
1082       GL_INT,
1083       32, 32, 0, 0,
1084       0, 0, 0, 0, 0,
1085       1, 1, 8
1086    },
1087    {
1088       MESA_FORMAT_RGB_INT32,
1089       "MESA_FORMAT_RGB_INT32",
1090       GL_RGB,
1091       GL_INT,
1092       32, 32, 32, 0,
1093       0, 0, 0, 0, 0,
1094       1, 1, 12
1095    },
1096    {
1097       MESA_FORMAT_RGBA_INT32,
1098       "MESA_FORMAT_RGBA_INT32",
1099       GL_RGBA,
1100       GL_INT,
1101       32, 32, 32, 32,
1102       0, 0, 0, 0, 0,
1103       1, 1, 16
1104    },
1105    {
1106       MESA_FORMAT_R_UINT8,
1107       "MESA_FORMAT_R_UINT8",
1108       GL_RED,
1109       GL_UNSIGNED_INT,
1110       8, 0, 0, 0,
1111       0, 0, 0, 0, 0,
1112       1, 1, 1
1113    },
1114    {
1115       MESA_FORMAT_RG_UINT8,
1116       "MESA_FORMAT_RG_UINT8",
1117       GL_RG,
1118       GL_UNSIGNED_INT,
1119       8, 8, 0, 0,
1120       0, 0, 0, 0, 0,
1121       1, 1, 2
1122    },
1123    {
1124       MESA_FORMAT_RGB_UINT8,
1125       "MESA_FORMAT_RGB_UINT8",
1126       GL_RGB,
1127       GL_UNSIGNED_INT,
1128       8, 8, 8, 0,
1129       0, 0, 0, 0, 0,
1130       1, 1, 3
1131    },
1132    {
1133       MESA_FORMAT_RGBA_UINT8,
1134       "MESA_FORMAT_RGBA_UINT8",
1135       GL_RGBA,
1136       GL_UNSIGNED_INT,
1137       8, 8, 8, 8,
1138       0, 0, 0, 0, 0,
1139       1, 1, 4
1140    },
1141    {
1142       MESA_FORMAT_R_UINT16,
1143       "MESA_FORMAT_R_UINT16",
1144       GL_RED,
1145       GL_UNSIGNED_INT,
1146       16, 0, 0, 0,
1147       0, 0, 0, 0, 0,
1148       1, 1, 2
1149    },
1150    {
1151       MESA_FORMAT_RG_UINT16,
1152       "MESA_FORMAT_RG_UINT16",
1153       GL_RG,
1154       GL_UNSIGNED_INT,
1155       16, 16, 0, 0,
1156       0, 0, 0, 0, 0,
1157       1, 1, 4
1158    },
1159    {
1160       MESA_FORMAT_RGB_UINT16,
1161       "MESA_FORMAT_RGB_UINT16",
1162       GL_RGB,
1163       GL_UNSIGNED_INT,
1164       16, 16, 16, 0,
1165       0, 0, 0, 0, 0,
1166       1, 1, 6
1167    },
1168    {
1169       MESA_FORMAT_RGBA_UINT16,
1170       "MESA_FORMAT_RGBA_UINT16",
1171       GL_RGBA,
1172       GL_UNSIGNED_INT,
1173       16, 16, 16, 16,
1174       0, 0, 0, 0, 0,
1175       1, 1, 8
1176    },
1177    {
1178       MESA_FORMAT_R_UINT32,
1179       "MESA_FORMAT_R_UINT32",
1180       GL_RED,
1181       GL_UNSIGNED_INT,
1182       32, 0, 0, 0,
1183       0, 0, 0, 0, 0,
1184       1, 1, 4
1185    },
1186    {
1187       MESA_FORMAT_RG_UINT32,
1188       "MESA_FORMAT_RG_UINT32",
1189       GL_RG,
1190       GL_UNSIGNED_INT,
1191       32, 32, 0, 0,
1192       0, 0, 0, 0, 0,
1193       1, 1, 8
1194    },
1195    {
1196       MESA_FORMAT_RGB_UINT32,
1197       "MESA_FORMAT_RGB_UINT32",
1198       GL_RGB,
1199       GL_UNSIGNED_INT,
1200       32, 32, 32, 0,
1201       0, 0, 0, 0, 0,
1202       1, 1, 12
1203    },
1204    {
1205       MESA_FORMAT_RGBA_UINT32,
1206       "MESA_FORMAT_RGBA_UINT32",
1207       GL_RGBA,
1208       GL_UNSIGNED_INT,
1209       32, 32, 32, 32,
1210       0, 0, 0, 0, 0,
1211       1, 1, 16
1212    },
1213 
1214 
1215    {
1216       MESA_FORMAT_DUDV8,
1217       "MESA_FORMAT_DUDV8",
1218       GL_DUDV_ATI,
1219       GL_SIGNED_NORMALIZED,
1220       0, 0, 0, 0,
1221       0, 0, 0, 0, 0,
1222       1, 1, 2
1223    },
1224 
1225    /* Signed 8 bits / channel */
1226    {
1227       MESA_FORMAT_SIGNED_R8,        /* Name */
1228       "MESA_FORMAT_SIGNED_R8",      /* StrName */
1229       GL_RED,                       /* BaseFormat */
1230       GL_SIGNED_NORMALIZED,         /* DataType */
1231       8, 0, 0, 0,                   /* Red/Green/Blue/AlphaBits */
1232       0, 0, 0, 0, 0,                /* Lum/Int/Index/Depth/StencilBits */
1233       1, 1, 1                       /* BlockWidth/Height,Bytes */
1234    },
1235    {
1236       MESA_FORMAT_SIGNED_RG88_REV,
1237       "MESA_FORMAT_SIGNED_RG88_REV",
1238       GL_RG,
1239       GL_SIGNED_NORMALIZED,
1240       8, 8, 0, 0,
1241       0, 0, 0, 0, 0,
1242       1, 1, 2
1243    },
1244    {
1245       MESA_FORMAT_SIGNED_RGBX8888,
1246       "MESA_FORMAT_SIGNED_RGBX8888",
1247       GL_RGB,
1248       GL_SIGNED_NORMALIZED,
1249       8, 8, 8, 0,
1250       0, 0, 0, 0, 0,
1251       1, 1, 4                       /* 4 bpp, but no alpha */
1252    },
1253    {
1254       MESA_FORMAT_SIGNED_RGBA8888,
1255       "MESA_FORMAT_SIGNED_RGBA8888",
1256       GL_RGBA,
1257       GL_SIGNED_NORMALIZED,
1258       8, 8, 8, 8,
1259       0, 0, 0, 0, 0,
1260       1, 1, 4
1261    },
1262    {
1263       MESA_FORMAT_SIGNED_RGBA8888_REV,
1264       "MESA_FORMAT_SIGNED_RGBA8888_REV",
1265       GL_RGBA,
1266       GL_SIGNED_NORMALIZED,
1267       8, 8, 8, 8,
1268       0, 0, 0, 0, 0,
1269       1, 1, 4
1270    },
1271 
1272    /* Signed 16 bits / channel */
1273    {
1274       MESA_FORMAT_SIGNED_R16,
1275       "MESA_FORMAT_SIGNED_R16",
1276       GL_RED,
1277       GL_SIGNED_NORMALIZED,
1278       16, 0, 0, 0,
1279       0, 0, 0, 0, 0,
1280       1, 1, 2
1281    },
1282    {
1283       MESA_FORMAT_SIGNED_GR1616,
1284       "MESA_FORMAT_SIGNED_GR1616",
1285       GL_RG,
1286       GL_SIGNED_NORMALIZED,
1287       16, 16, 0, 0,
1288       0, 0, 0, 0, 0,
1289       1, 1, 4
1290    },
1291    {
1292       MESA_FORMAT_SIGNED_RGB_16,
1293       "MESA_FORMAT_SIGNED_RGB_16",
1294       GL_RGB,
1295       GL_SIGNED_NORMALIZED,
1296       16, 16, 16, 0,
1297       0, 0, 0, 0, 0,
1298       1, 1, 6
1299    },
1300    {
1301       MESA_FORMAT_SIGNED_RGBA_16,
1302       "MESA_FORMAT_SIGNED_RGBA_16",
1303       GL_RGBA,
1304       GL_SIGNED_NORMALIZED,
1305       16, 16, 16, 16,
1306       0, 0, 0, 0, 0,
1307       1, 1, 8
1308    },
1309    {
1310       MESA_FORMAT_RGBA_16,
1311       "MESA_FORMAT_RGBA_16",
1312       GL_RGBA,
1313       GL_UNSIGNED_NORMALIZED,
1314       16, 16, 16, 16,
1315       0, 0, 0, 0, 0,
1316       1, 1, 8
1317    },
1318    {
1319      MESA_FORMAT_RED_RGTC1,
1320      "MESA_FORMAT_RED_RGTC1",
1321      GL_RED,
1322      GL_UNSIGNED_NORMALIZED,
1323      8, 0, 0, 0,
1324      0, 0, 0, 0, 0,
1325      4, 4, 8                     /* 8 bytes per 4x4 block */
1326    },
1327    {
1328      MESA_FORMAT_SIGNED_RED_RGTC1,
1329      "MESA_FORMAT_SIGNED_RED_RGTC1",
1330      GL_RED,
1331      GL_SIGNED_NORMALIZED,
1332      8, 0, 0, 0,
1333      0, 0, 0, 0, 0,
1334      4, 4, 8                     /* 8 bytes per 4x4 block */
1335    },
1336    {
1337      MESA_FORMAT_RG_RGTC2,
1338      "MESA_FORMAT_RG_RGTC2",
1339      GL_RG,
1340      GL_UNSIGNED_NORMALIZED,
1341      8, 8, 0, 0,
1342      0, 0, 0, 0, 0,
1343      4, 4, 16                     /* 16 bytes per 4x4 block */
1344    },
1345    {
1346      MESA_FORMAT_SIGNED_RG_RGTC2,
1347      "MESA_FORMAT_SIGNED_RG_RGTC2",
1348      GL_RG,
1349      GL_SIGNED_NORMALIZED,
1350      8, 8, 0, 0,
1351      0, 0, 0, 0, 0,
1352      4, 4, 16                     /* 16 bytes per 4x4 block */
1353    },
1354    {
1355      MESA_FORMAT_L_LATC1,
1356      "MESA_FORMAT_L_LATC1",
1357      GL_LUMINANCE,
1358      GL_UNSIGNED_NORMALIZED,
1359      0, 0, 0, 0,
1360      4, 0, 0, 0, 0,
1361      4, 4, 8                     /* 8 bytes per 4x4 block */
1362    },
1363    {
1364      MESA_FORMAT_SIGNED_L_LATC1,
1365      "MESA_FORMAT_SIGNED_L_LATC1",
1366      GL_LUMINANCE,
1367      GL_SIGNED_NORMALIZED,
1368      0, 0, 0, 0,
1369      4, 0, 0, 0, 0,
1370      4, 4, 8                     /* 8 bytes per 4x4 block */
1371    },
1372    {
1373      MESA_FORMAT_LA_LATC2,
1374      "MESA_FORMAT_LA_LATC2",
1375      GL_LUMINANCE_ALPHA,
1376      GL_UNSIGNED_NORMALIZED,
1377      0, 0, 0, 4,
1378      4, 0, 0, 0, 0,
1379      4, 4, 16                     /* 16 bytes per 4x4 block */
1380    },
1381    {
1382      MESA_FORMAT_SIGNED_LA_LATC2,
1383      "MESA_FORMAT_SIGNED_LA_LATC2",
1384      GL_LUMINANCE_ALPHA,
1385      GL_SIGNED_NORMALIZED,
1386      0, 0, 0, 4,
1387      4, 0, 0, 0, 0,
1388      4, 4, 16                     /* 16 bytes per 4x4 block */
1389    },
1390 
1391    {
1392       MESA_FORMAT_ETC1_RGB8,
1393       "MESA_FORMAT_ETC1_RGB8",
1394       GL_RGB,
1395       GL_UNSIGNED_NORMALIZED,
1396       8, 8, 8, 0,
1397       0, 0, 0, 0, 0,
1398       4, 4, 8                     /* 8 bytes per 4x4 block */
1399    },
1400 
1401    /* Signed formats from EXT_texture_snorm that are not in GL3.1 */
1402    {
1403       MESA_FORMAT_SIGNED_A8,
1404       "MESA_FORMAT_SIGNED_A8",
1405       GL_ALPHA,
1406       GL_SIGNED_NORMALIZED,
1407       0, 0, 0, 8,
1408       0, 0, 0, 0, 0,
1409       1, 1, 1
1410    },
1411    {
1412       MESA_FORMAT_SIGNED_L8,
1413       "MESA_FORMAT_SIGNED_L8",
1414       GL_LUMINANCE,
1415       GL_SIGNED_NORMALIZED,
1416       0, 0, 0, 0,
1417       8, 0, 0, 0, 0,
1418       1, 1, 1
1419    },
1420    {
1421       MESA_FORMAT_SIGNED_AL88,
1422       "MESA_FORMAT_SIGNED_AL88",
1423       GL_LUMINANCE_ALPHA,
1424       GL_SIGNED_NORMALIZED,
1425       0, 0, 0, 8,
1426       8, 0, 0, 0, 0,
1427       1, 1, 2
1428    },
1429    {
1430       MESA_FORMAT_SIGNED_I8,
1431       "MESA_FORMAT_SIGNED_I8",
1432       GL_INTENSITY,
1433       GL_SIGNED_NORMALIZED,
1434       0, 0, 0, 0,
1435       0, 8, 0, 0, 0,
1436       1, 1, 1
1437    },
1438    {
1439       MESA_FORMAT_SIGNED_A16,
1440       "MESA_FORMAT_SIGNED_A16",
1441       GL_ALPHA,
1442       GL_SIGNED_NORMALIZED,
1443       0, 0, 0, 16,
1444       0, 0, 0, 0, 0,
1445       1, 1, 2
1446    },
1447    {
1448       MESA_FORMAT_SIGNED_L16,
1449       "MESA_FORMAT_SIGNED_L16",
1450       GL_LUMINANCE,
1451       GL_SIGNED_NORMALIZED,
1452       0, 0, 0, 0,
1453       16, 0, 0, 0, 0,
1454       1, 1, 2
1455    },
1456    {
1457       MESA_FORMAT_SIGNED_AL1616,
1458       "MESA_FORMAT_SIGNED_AL1616",
1459       GL_LUMINANCE_ALPHA,
1460       GL_SIGNED_NORMALIZED,
1461       0, 0, 0, 16,
1462       16, 0, 0, 0, 0,
1463       1, 1, 4
1464    },
1465    {
1466       MESA_FORMAT_SIGNED_I16,
1467       "MESA_FORMAT_SIGNED_I16",
1468       GL_INTENSITY,
1469       GL_SIGNED_NORMALIZED,
1470       0, 0, 0, 0,
1471       0, 16, 0, 0, 0,
1472       1, 1, 2
1473    },
1474    {
1475       MESA_FORMAT_RGB9_E5_FLOAT,
1476       "MESA_FORMAT_RGB9_E5",
1477       GL_RGB,
1478       GL_FLOAT,
1479       9, 9, 9, 0,
1480       0, 0, 0, 0, 0,
1481       1, 1, 4
1482    },
1483    {
1484       MESA_FORMAT_R11_G11_B10_FLOAT,
1485       "MESA_FORMAT_R11_G11_B10_FLOAT",
1486       GL_RGB,
1487       GL_FLOAT,
1488       11, 11, 10, 0,
1489       0, 0, 0, 0, 0,
1490       1, 1, 4
1491    },
1492    /* ARB_depth_buffer_float */
1493    {
1494       MESA_FORMAT_Z32_FLOAT,       /* Name */
1495       "MESA_FORMAT_Z32_FLOAT",     /* StrName */
1496       GL_DEPTH_COMPONENT,          /* BaseFormat */
1497       GL_FLOAT,                    /* DataType */
1498       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
1499       0, 0, 0, 32, 0,              /* Lum/Int/Index/Depth/StencilBits */
1500       1, 1, 4                      /* BlockWidth/Height,Bytes */
1501    },
1502    {
1503       MESA_FORMAT_Z32_FLOAT_X24S8, /* Name */
1504       "MESA_FORMAT_Z32_FLOAT_X24S8", /* StrName */
1505       GL_DEPTH_STENCIL,            /* BaseFormat */
1506       /* DataType here is used to answer GL_TEXTURE_DEPTH_TYPE queries, and is
1507        * never used for stencil because stencil is always GL_UNSIGNED_INT.
1508        */
1509       GL_FLOAT,                    /* DataType */
1510       0, 0, 0, 0,                  /* Red/Green/Blue/AlphaBits */
1511       0, 0, 0, 32, 8,              /* Lum/Int/Index/Depth/StencilBits */
1512       1, 1, 8                      /* BlockWidth/Height,Bytes */
1513    },
1514    {
1515       MESA_FORMAT_ARGB2101010_UINT,
1516       "MESA_FORMAT_ARGB2101010_UINT",
1517       GL_RGBA,
1518       GL_UNSIGNED_INT,
1519       10, 10, 10, 2,
1520       0, 0, 0, 0, 0,
1521       1, 1, 4
1522    },
1523    {
1524       MESA_FORMAT_ABGR2101010_UINT,
1525       "MESA_FORMAT_ABGR2101010_UINT",
1526       GL_RGBA,
1527       GL_UNSIGNED_INT,
1528       10, 10, 10, 2,
1529       0, 0, 0, 0, 0,
1530       1, 1, 4
1531    },
1532 };
1533 
1534 
1535 
1536 static const struct gl_format_info *
_mesa_get_format_info(gl_format format)1537 _mesa_get_format_info(gl_format format)
1538 {
1539    const struct gl_format_info *info = &format_info[format];
1540    assert(info->Name == format);
1541    return info;
1542 }
1543 
1544 
1545 /** Return string name of format (for debugging) */
1546 const char *
_mesa_get_format_name(gl_format format)1547 _mesa_get_format_name(gl_format format)
1548 {
1549    const struct gl_format_info *info = _mesa_get_format_info(format);
1550    return info->StrName;
1551 }
1552 
1553 
1554 
1555 /**
1556  * Return bytes needed to store a block of pixels in the given format.
1557  * Normally, a block is 1x1 (a single pixel).  But for compressed formats
1558  * a block may be 4x4 or 8x4, etc.
1559  *
1560  * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
1561  */
1562 GLint
_mesa_get_format_bytes(gl_format format)1563 _mesa_get_format_bytes(gl_format format)
1564 {
1565    const struct gl_format_info *info = _mesa_get_format_info(format);
1566    ASSERT(info->BytesPerBlock);
1567    ASSERT(info->BytesPerBlock <= MAX_PIXEL_BYTES ||
1568           _mesa_is_format_compressed(format));
1569    return info->BytesPerBlock;
1570 }
1571 
1572 
1573 /**
1574  * Return bits per component for the given format.
1575  * \param format  one of MESA_FORMAT_x
1576  * \param pname  the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
1577  */
1578 GLint
_mesa_get_format_bits(gl_format format,GLenum pname)1579 _mesa_get_format_bits(gl_format format, GLenum pname)
1580 {
1581    const struct gl_format_info *info = _mesa_get_format_info(format);
1582 
1583    switch (pname) {
1584    case GL_RED_BITS:
1585    case GL_TEXTURE_RED_SIZE:
1586    case GL_RENDERBUFFER_RED_SIZE_EXT:
1587    case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1588       return info->RedBits;
1589    case GL_GREEN_BITS:
1590    case GL_TEXTURE_GREEN_SIZE:
1591    case GL_RENDERBUFFER_GREEN_SIZE_EXT:
1592    case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1593       return info->GreenBits;
1594    case GL_BLUE_BITS:
1595    case GL_TEXTURE_BLUE_SIZE:
1596    case GL_RENDERBUFFER_BLUE_SIZE_EXT:
1597    case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1598       return info->BlueBits;
1599    case GL_ALPHA_BITS:
1600    case GL_TEXTURE_ALPHA_SIZE:
1601    case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
1602    case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1603       return info->AlphaBits;
1604    case GL_TEXTURE_INTENSITY_SIZE:
1605       return info->IntensityBits;
1606    case GL_TEXTURE_LUMINANCE_SIZE:
1607       return info->LuminanceBits;
1608    case GL_INDEX_BITS:
1609       return info->IndexBits;
1610    case GL_DEPTH_BITS:
1611    case GL_TEXTURE_DEPTH_SIZE_ARB:
1612    case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
1613    case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1614       return info->DepthBits;
1615    case GL_STENCIL_BITS:
1616    case GL_TEXTURE_STENCIL_SIZE_EXT:
1617    case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
1618    case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1619       return info->StencilBits;
1620    default:
1621       _mesa_problem(NULL, "bad pname in _mesa_get_format_bits()");
1622       return 0;
1623    }
1624 }
1625 
1626 
1627 GLuint
_mesa_get_format_max_bits(gl_format format)1628 _mesa_get_format_max_bits(gl_format format)
1629 {
1630    const struct gl_format_info *info = _mesa_get_format_info(format);
1631    GLuint max = MAX2(info->RedBits, info->GreenBits);
1632    max = MAX2(max, info->BlueBits);
1633    max = MAX2(max, info->AlphaBits);
1634    max = MAX2(max, info->LuminanceBits);
1635    max = MAX2(max, info->IntensityBits);
1636    max = MAX2(max, info->DepthBits);
1637    max = MAX2(max, info->StencilBits);
1638    return max;
1639 }
1640 
1641 
1642 /**
1643  * Return the data type (or more specifically, the data representation)
1644  * for the given format.
1645  * The return value will be one of:
1646  *    GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
1647  *    GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
1648  *    GL_UNSIGNED_INT = an ordinary unsigned integer
1649  *    GL_INT = an ordinary signed integer
1650  *    GL_FLOAT = an ordinary float
1651  */
1652 GLenum
_mesa_get_format_datatype(gl_format format)1653 _mesa_get_format_datatype(gl_format format)
1654 {
1655    const struct gl_format_info *info = _mesa_get_format_info(format);
1656    return info->DataType;
1657 }
1658 
1659 
1660 /**
1661  * Return the basic format for the given type.  The result will be one of
1662  * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY,
1663  * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
1664  */
1665 GLenum
_mesa_get_format_base_format(gl_format format)1666 _mesa_get_format_base_format(gl_format format)
1667 {
1668    const struct gl_format_info *info = _mesa_get_format_info(format);
1669    return info->BaseFormat;
1670 }
1671 
1672 
1673 /**
1674  * Return the block size (in pixels) for the given format.  Normally
1675  * the block size is 1x1.  But compressed formats will have block sizes
1676  * of 4x4 or 8x4 pixels, etc.
1677  * \param bw  returns block width in pixels
1678  * \param bh  returns block height in pixels
1679  */
1680 void
_mesa_get_format_block_size(gl_format format,GLuint * bw,GLuint * bh)1681 _mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
1682 {
1683    const struct gl_format_info *info = _mesa_get_format_info(format);
1684    *bw = info->BlockWidth;
1685    *bh = info->BlockHeight;
1686 }
1687 
1688 
1689 /** Is the given format a compressed format? */
1690 GLboolean
_mesa_is_format_compressed(gl_format format)1691 _mesa_is_format_compressed(gl_format format)
1692 {
1693    const struct gl_format_info *info = _mesa_get_format_info(format);
1694    return info->BlockWidth > 1 || info->BlockHeight > 1;
1695 }
1696 
1697 
1698 /**
1699  * Determine if the given format represents a packed depth/stencil buffer.
1700  */
1701 GLboolean
_mesa_is_format_packed_depth_stencil(gl_format format)1702 _mesa_is_format_packed_depth_stencil(gl_format format)
1703 {
1704    const struct gl_format_info *info = _mesa_get_format_info(format);
1705 
1706    return info->BaseFormat == GL_DEPTH_STENCIL;
1707 }
1708 
1709 
1710 /**
1711  * Is the given format a signed/unsigned integer color format?
1712  */
1713 GLboolean
_mesa_is_format_integer_color(gl_format format)1714 _mesa_is_format_integer_color(gl_format format)
1715 {
1716    const struct gl_format_info *info = _mesa_get_format_info(format);
1717    return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) &&
1718       info->BaseFormat != GL_DEPTH_COMPONENT &&
1719       info->BaseFormat != GL_DEPTH_STENCIL &&
1720       info->BaseFormat != GL_STENCIL_INDEX;
1721 }
1722 
1723 
1724 /**
1725  * Is the given format an unsigned integer format?
1726  */
1727 GLboolean
_mesa_is_format_unsigned(gl_format format)1728 _mesa_is_format_unsigned(gl_format format)
1729 {
1730    const struct gl_format_info *info = _mesa_get_format_info(format);
1731    return _mesa_is_type_unsigned(info->DataType);
1732 }
1733 
1734 
1735 /**
1736  * Return color encoding for given format.
1737  * \return GL_LINEAR or GL_SRGB
1738  */
1739 GLenum
_mesa_get_format_color_encoding(gl_format format)1740 _mesa_get_format_color_encoding(gl_format format)
1741 {
1742    /* XXX this info should be encoded in gl_format_info */
1743    switch (format) {
1744    case MESA_FORMAT_SRGB8:
1745    case MESA_FORMAT_SRGBA8:
1746    case MESA_FORMAT_SARGB8:
1747    case MESA_FORMAT_SL8:
1748    case MESA_FORMAT_SLA8:
1749    case MESA_FORMAT_SRGB_DXT1:
1750    case MESA_FORMAT_SRGBA_DXT1:
1751    case MESA_FORMAT_SRGBA_DXT3:
1752    case MESA_FORMAT_SRGBA_DXT5:
1753       return GL_SRGB;
1754    default:
1755       return GL_LINEAR;
1756    }
1757 }
1758 
1759 
1760 /**
1761  * For an sRGB format, return the corresponding linear color space format.
1762  * For non-sRGB formats, return the format as-is.
1763  */
1764 gl_format
_mesa_get_srgb_format_linear(gl_format format)1765 _mesa_get_srgb_format_linear(gl_format format)
1766 {
1767    switch (format) {
1768    case MESA_FORMAT_SRGB8:
1769       format = MESA_FORMAT_RGB888;
1770       break;
1771    case MESA_FORMAT_SRGBA8:
1772       format = MESA_FORMAT_RGBA8888;
1773       break;
1774    case MESA_FORMAT_SARGB8:
1775       format = MESA_FORMAT_ARGB8888;
1776       break;
1777    case MESA_FORMAT_SL8:
1778       format = MESA_FORMAT_L8;
1779       break;
1780    case MESA_FORMAT_SLA8:
1781       format = MESA_FORMAT_AL88;
1782       break;
1783    case MESA_FORMAT_SRGB_DXT1:
1784       format = MESA_FORMAT_RGB_DXT1;
1785       break;
1786    case MESA_FORMAT_SRGBA_DXT1:
1787       format = MESA_FORMAT_RGBA_DXT1;
1788       break;
1789    case MESA_FORMAT_SRGBA_DXT3:
1790       format = MESA_FORMAT_RGBA_DXT3;
1791       break;
1792    case MESA_FORMAT_SRGBA_DXT5:
1793       format = MESA_FORMAT_RGBA_DXT5;
1794       break;
1795    default:
1796       break;
1797    }
1798    return format;
1799 }
1800 
1801 
1802 /**
1803  * If the given format is a compressed format, return a corresponding
1804  * uncompressed format.
1805  */
1806 gl_format
_mesa_get_uncompressed_format(gl_format format)1807 _mesa_get_uncompressed_format(gl_format format)
1808 {
1809    switch (format) {
1810    case MESA_FORMAT_RGB_FXT1:
1811       return MESA_FORMAT_RGB888;
1812    case MESA_FORMAT_RGBA_FXT1:
1813       return MESA_FORMAT_RGBA8888;
1814    case MESA_FORMAT_RGB_DXT1:
1815    case MESA_FORMAT_SRGB_DXT1:
1816       return MESA_FORMAT_RGB888;
1817    case MESA_FORMAT_RGBA_DXT1:
1818    case MESA_FORMAT_SRGBA_DXT1:
1819       return MESA_FORMAT_RGBA8888;
1820    case MESA_FORMAT_RGBA_DXT3:
1821    case MESA_FORMAT_SRGBA_DXT3:
1822       return MESA_FORMAT_RGBA8888;
1823    case MESA_FORMAT_RGBA_DXT5:
1824    case MESA_FORMAT_SRGBA_DXT5:
1825       return MESA_FORMAT_RGBA8888;
1826    case MESA_FORMAT_RED_RGTC1:
1827       return MESA_FORMAT_R8;
1828    case MESA_FORMAT_SIGNED_RED_RGTC1:
1829       return MESA_FORMAT_SIGNED_R8;
1830    case MESA_FORMAT_RG_RGTC2:
1831       return MESA_FORMAT_GR88;
1832    case MESA_FORMAT_SIGNED_RG_RGTC2:
1833       return MESA_FORMAT_SIGNED_RG88_REV;
1834    case MESA_FORMAT_L_LATC1:
1835       return MESA_FORMAT_L8;
1836    case MESA_FORMAT_SIGNED_L_LATC1:
1837       return MESA_FORMAT_SIGNED_L8;
1838    case MESA_FORMAT_LA_LATC2:
1839       return MESA_FORMAT_AL88;
1840    case MESA_FORMAT_SIGNED_LA_LATC2:
1841       return MESA_FORMAT_SIGNED_AL88;
1842    case MESA_FORMAT_ETC1_RGB8:
1843       return MESA_FORMAT_RGB888;
1844    default:
1845 #ifdef DEBUG
1846       assert(!_mesa_is_format_compressed(format));
1847 #endif
1848       return format;
1849    }
1850 }
1851 
1852 
1853 GLuint
_mesa_format_num_components(gl_format format)1854 _mesa_format_num_components(gl_format format)
1855 {
1856    const struct gl_format_info *info = _mesa_get_format_info(format);
1857    return ((info->RedBits > 0) +
1858            (info->GreenBits > 0) +
1859            (info->BlueBits > 0) +
1860            (info->AlphaBits > 0) +
1861            (info->LuminanceBits > 0) +
1862            (info->IntensityBits > 0) +
1863            (info->DepthBits > 0) +
1864            (info->StencilBits > 0));
1865 }
1866 
1867 
1868 /**
1869  * Return number of bytes needed to store an image of the given size
1870  * in the given format.
1871  */
1872 GLuint
_mesa_format_image_size(gl_format format,GLsizei width,GLsizei height,GLsizei depth)1873 _mesa_format_image_size(gl_format format, GLsizei width,
1874                         GLsizei height, GLsizei depth)
1875 {
1876    const struct gl_format_info *info = _mesa_get_format_info(format);
1877    /* Strictly speaking, a conditional isn't needed here */
1878    if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1879       /* compressed format (2D only for now) */
1880       const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
1881       const GLuint wblocks = (width + bw - 1) / bw;
1882       const GLuint hblocks = (height + bh - 1) / bh;
1883       const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
1884       return sz * depth;
1885    }
1886    else {
1887       /* non-compressed */
1888       const GLuint sz = width * height * depth * info->BytesPerBlock;
1889       return sz;
1890    }
1891 }
1892 
1893 
1894 /**
1895  * Same as _mesa_format_image_size() but returns a 64-bit value to
1896  * accomodate very large textures.
1897  */
1898 uint64_t
_mesa_format_image_size64(gl_format format,GLsizei width,GLsizei height,GLsizei depth)1899 _mesa_format_image_size64(gl_format format, GLsizei width,
1900                           GLsizei height, GLsizei depth)
1901 {
1902    const struct gl_format_info *info = _mesa_get_format_info(format);
1903    /* Strictly speaking, a conditional isn't needed here */
1904    if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1905       /* compressed format (2D only for now) */
1906       const uint64_t bw = info->BlockWidth, bh = info->BlockHeight;
1907       const uint64_t wblocks = (width + bw - 1) / bw;
1908       const uint64_t hblocks = (height + bh - 1) / bh;
1909       const uint64_t sz = wblocks * hblocks * info->BytesPerBlock;
1910       return sz * depth;
1911    }
1912    else {
1913       /* non-compressed */
1914       const uint64_t sz = ((uint64_t) width *
1915                            (uint64_t) height *
1916                            (uint64_t) depth *
1917                            info->BytesPerBlock);
1918       return sz;
1919    }
1920 }
1921 
1922 
1923 
1924 GLint
_mesa_format_row_stride(gl_format format,GLsizei width)1925 _mesa_format_row_stride(gl_format format, GLsizei width)
1926 {
1927    const struct gl_format_info *info = _mesa_get_format_info(format);
1928    /* Strictly speaking, a conditional isn't needed here */
1929    if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1930       /* compressed format */
1931       const GLuint bw = info->BlockWidth;
1932       const GLuint wblocks = (width + bw - 1) / bw;
1933       const GLint stride = wblocks * info->BytesPerBlock;
1934       return stride;
1935    }
1936    else {
1937       const GLint stride = width * info->BytesPerBlock;
1938       return stride;
1939    }
1940 }
1941 
1942 
1943 /**
1944  * Debug/test: check that all formats are handled in the
1945  * _mesa_format_to_type_and_comps() function.  When new pixel formats
1946  * are added to Mesa, that function needs to be updated.
1947  * This is a no-op after the first call.
1948  */
1949 static void
check_format_to_type_and_comps(void)1950 check_format_to_type_and_comps(void)
1951 {
1952    gl_format f;
1953 
1954    for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) {
1955       GLenum datatype = 0;
1956       GLuint comps = 0;
1957       /* This function will emit a problem/warning if the format is
1958        * not handled.
1959        */
1960       _mesa_format_to_type_and_comps(f, &datatype, &comps);
1961    }
1962 }
1963 
1964 
1965 /**
1966  * Do sanity checking of the format info table.
1967  */
1968 void
_mesa_test_formats(void)1969 _mesa_test_formats(void)
1970 {
1971    GLuint i;
1972 
1973    STATIC_ASSERT(Elements(format_info) == MESA_FORMAT_COUNT);
1974 
1975    for (i = 0; i < MESA_FORMAT_COUNT; i++) {
1976       const struct gl_format_info *info = _mesa_get_format_info(i);
1977       assert(info);
1978 
1979       assert(info->Name == i);
1980 
1981       if (info->Name == MESA_FORMAT_NONE)
1982          continue;
1983 
1984       if (info->BlockWidth == 1 && info->BlockHeight == 1) {
1985          if (info->RedBits > 0) {
1986             GLuint t = info->RedBits + info->GreenBits
1987                + info->BlueBits + info->AlphaBits;
1988             assert(t / 8 <= info->BytesPerBlock);
1989             (void) t;
1990          }
1991       }
1992 
1993       assert(info->DataType == GL_UNSIGNED_NORMALIZED ||
1994              info->DataType == GL_SIGNED_NORMALIZED ||
1995              info->DataType == GL_UNSIGNED_INT ||
1996              info->DataType == GL_INT ||
1997              info->DataType == GL_FLOAT ||
1998              /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
1999              info->DataType == GL_NONE);
2000 
2001       if (info->BaseFormat == GL_RGB) {
2002          assert(info->RedBits > 0);
2003          assert(info->GreenBits > 0);
2004          assert(info->BlueBits > 0);
2005          assert(info->AlphaBits == 0);
2006          assert(info->LuminanceBits == 0);
2007          assert(info->IntensityBits == 0);
2008       }
2009       else if (info->BaseFormat == GL_RGBA) {
2010          assert(info->RedBits > 0);
2011          assert(info->GreenBits > 0);
2012          assert(info->BlueBits > 0);
2013          assert(info->AlphaBits > 0);
2014          assert(info->LuminanceBits == 0);
2015          assert(info->IntensityBits == 0);
2016       }
2017       else if (info->BaseFormat == GL_RG) {
2018          assert(info->RedBits > 0);
2019          assert(info->GreenBits > 0);
2020          assert(info->BlueBits == 0);
2021          assert(info->AlphaBits == 0);
2022          assert(info->LuminanceBits == 0);
2023          assert(info->IntensityBits == 0);
2024       }
2025       else if (info->BaseFormat == GL_RED) {
2026          assert(info->RedBits > 0);
2027          assert(info->GreenBits == 0);
2028          assert(info->BlueBits == 0);
2029          assert(info->AlphaBits == 0);
2030          assert(info->LuminanceBits == 0);
2031          assert(info->IntensityBits == 0);
2032       }
2033       else if (info->BaseFormat == GL_LUMINANCE) {
2034          assert(info->RedBits == 0);
2035          assert(info->GreenBits == 0);
2036          assert(info->BlueBits == 0);
2037          assert(info->AlphaBits == 0);
2038          assert(info->LuminanceBits > 0);
2039          assert(info->IntensityBits == 0);
2040       }
2041       else if (info->BaseFormat == GL_INTENSITY) {
2042          assert(info->RedBits == 0);
2043          assert(info->GreenBits == 0);
2044          assert(info->BlueBits == 0);
2045          assert(info->AlphaBits == 0);
2046          assert(info->LuminanceBits == 0);
2047          assert(info->IntensityBits > 0);
2048       }
2049    }
2050 
2051    check_format_to_type_and_comps();
2052 }
2053 
2054 
2055 
2056 /**
2057  * Return datatype and number of components per texel for the given gl_format.
2058  * Only used for mipmap generation code.
2059  */
2060 void
_mesa_format_to_type_and_comps(gl_format format,GLenum * datatype,GLuint * comps)2061 _mesa_format_to_type_and_comps(gl_format format,
2062                                GLenum *datatype, GLuint *comps)
2063 {
2064    switch (format) {
2065    case MESA_FORMAT_RGBA8888:
2066    case MESA_FORMAT_RGBA8888_REV:
2067    case MESA_FORMAT_ARGB8888:
2068    case MESA_FORMAT_ARGB8888_REV:
2069    case MESA_FORMAT_RGBX8888:
2070    case MESA_FORMAT_RGBX8888_REV:
2071    case MESA_FORMAT_XRGB8888:
2072    case MESA_FORMAT_XRGB8888_REV:
2073       *datatype = GL_UNSIGNED_BYTE;
2074       *comps = 4;
2075       return;
2076    case MESA_FORMAT_RGB888:
2077    case MESA_FORMAT_BGR888:
2078       *datatype = GL_UNSIGNED_BYTE;
2079       *comps = 3;
2080       return;
2081    case MESA_FORMAT_RGB565:
2082    case MESA_FORMAT_RGB565_REV:
2083       *datatype = GL_UNSIGNED_SHORT_5_6_5;
2084       *comps = 3;
2085       return;
2086 
2087    case MESA_FORMAT_ARGB4444:
2088    case MESA_FORMAT_ARGB4444_REV:
2089       *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
2090       *comps = 4;
2091       return;
2092 
2093    case MESA_FORMAT_ARGB1555:
2094    case MESA_FORMAT_ARGB1555_REV:
2095       *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
2096       *comps = 4;
2097       return;
2098 
2099    case MESA_FORMAT_ARGB2101010:
2100       *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
2101       *comps = 4;
2102       return;
2103 
2104    case MESA_FORMAT_RGBA5551:
2105       *datatype = GL_UNSIGNED_SHORT_5_5_5_1;
2106       *comps = 4;
2107       return;
2108 
2109    case MESA_FORMAT_AL44:
2110       *datatype = MESA_UNSIGNED_BYTE_4_4;
2111       *comps = 2;
2112       return;
2113 
2114    case MESA_FORMAT_AL88:
2115    case MESA_FORMAT_AL88_REV:
2116    case MESA_FORMAT_GR88:
2117    case MESA_FORMAT_RG88:
2118       *datatype = GL_UNSIGNED_BYTE;
2119       *comps = 2;
2120       return;
2121 
2122    case MESA_FORMAT_AL1616:
2123    case MESA_FORMAT_AL1616_REV:
2124    case MESA_FORMAT_RG1616:
2125    case MESA_FORMAT_RG1616_REV:
2126       *datatype = GL_UNSIGNED_SHORT;
2127       *comps = 2;
2128       return;
2129 
2130    case MESA_FORMAT_R16:
2131    case MESA_FORMAT_A16:
2132    case MESA_FORMAT_L16:
2133    case MESA_FORMAT_I16:
2134       *datatype = GL_UNSIGNED_SHORT;
2135       *comps = 1;
2136       return;
2137 
2138    case MESA_FORMAT_RGB332:
2139       *datatype = GL_UNSIGNED_BYTE_3_3_2;
2140       *comps = 3;
2141       return;
2142 
2143    case MESA_FORMAT_A8:
2144    case MESA_FORMAT_L8:
2145    case MESA_FORMAT_I8:
2146    case MESA_FORMAT_R8:
2147    case MESA_FORMAT_S8:
2148       *datatype = GL_UNSIGNED_BYTE;
2149       *comps = 1;
2150       return;
2151 
2152    case MESA_FORMAT_YCBCR:
2153    case MESA_FORMAT_YCBCR_REV:
2154       *datatype = GL_UNSIGNED_SHORT;
2155       *comps = 2;
2156       return;
2157 
2158    case MESA_FORMAT_Z24_S8:
2159       *datatype = GL_UNSIGNED_INT_24_8_MESA;
2160       *comps = 2;
2161       return;
2162 
2163    case MESA_FORMAT_S8_Z24:
2164       *datatype = GL_UNSIGNED_INT_8_24_REV_MESA;
2165       *comps = 2;
2166       return;
2167 
2168    case MESA_FORMAT_Z16:
2169       *datatype = GL_UNSIGNED_SHORT;
2170       *comps = 1;
2171       return;
2172 
2173    case MESA_FORMAT_X8_Z24:
2174       *datatype = GL_UNSIGNED_INT;
2175       *comps = 1;
2176       return;
2177 
2178    case MESA_FORMAT_Z24_X8:
2179       *datatype = GL_UNSIGNED_INT;
2180       *comps = 1;
2181       return;
2182 
2183    case MESA_FORMAT_Z32:
2184       *datatype = GL_UNSIGNED_INT;
2185       *comps = 1;
2186       return;
2187 
2188    case MESA_FORMAT_Z32_FLOAT:
2189       *datatype = GL_FLOAT;
2190       *comps = 1;
2191       return;
2192 
2193    case MESA_FORMAT_Z32_FLOAT_X24S8:
2194       *datatype = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
2195       *comps = 1;
2196       return;
2197 
2198    case MESA_FORMAT_DUDV8:
2199       *datatype = GL_BYTE;
2200       *comps = 2;
2201       return;
2202 
2203    case MESA_FORMAT_SIGNED_R8:
2204    case MESA_FORMAT_SIGNED_A8:
2205    case MESA_FORMAT_SIGNED_L8:
2206    case MESA_FORMAT_SIGNED_I8:
2207       *datatype = GL_BYTE;
2208       *comps = 1;
2209       return;
2210    case MESA_FORMAT_SIGNED_RG88_REV:
2211    case MESA_FORMAT_SIGNED_AL88:
2212       *datatype = GL_BYTE;
2213       *comps = 2;
2214       return;
2215    case MESA_FORMAT_SIGNED_RGBA8888:
2216    case MESA_FORMAT_SIGNED_RGBA8888_REV:
2217    case MESA_FORMAT_SIGNED_RGBX8888:
2218       *datatype = GL_BYTE;
2219       *comps = 4;
2220       return;
2221 
2222    case MESA_FORMAT_RGBA_16:
2223       *datatype = GL_UNSIGNED_SHORT;
2224       *comps = 4;
2225       return;
2226 
2227    case MESA_FORMAT_SIGNED_R16:
2228    case MESA_FORMAT_SIGNED_A16:
2229    case MESA_FORMAT_SIGNED_L16:
2230    case MESA_FORMAT_SIGNED_I16:
2231       *datatype = GL_SHORT;
2232       *comps = 1;
2233       return;
2234    case MESA_FORMAT_SIGNED_GR1616:
2235    case MESA_FORMAT_SIGNED_AL1616:
2236       *datatype = GL_SHORT;
2237       *comps = 2;
2238       return;
2239    case MESA_FORMAT_SIGNED_RGB_16:
2240       *datatype = GL_SHORT;
2241       *comps = 3;
2242       return;
2243    case MESA_FORMAT_SIGNED_RGBA_16:
2244       *datatype = GL_SHORT;
2245       *comps = 4;
2246       return;
2247 
2248 #if FEATURE_EXT_texture_sRGB
2249    case MESA_FORMAT_SRGB8:
2250       *datatype = GL_UNSIGNED_BYTE;
2251       *comps = 3;
2252       return;
2253    case MESA_FORMAT_SRGBA8:
2254    case MESA_FORMAT_SARGB8:
2255       *datatype = GL_UNSIGNED_BYTE;
2256       *comps = 4;
2257       return;
2258    case MESA_FORMAT_SL8:
2259       *datatype = GL_UNSIGNED_BYTE;
2260       *comps = 1;
2261       return;
2262    case MESA_FORMAT_SLA8:
2263       *datatype = GL_UNSIGNED_BYTE;
2264       *comps = 2;
2265       return;
2266 #endif
2267 
2268 #if FEATURE_texture_fxt1
2269    case MESA_FORMAT_RGB_FXT1:
2270    case MESA_FORMAT_RGBA_FXT1:
2271 #endif
2272 #if FEATURE_texture_s3tc
2273    case MESA_FORMAT_RGB_DXT1:
2274    case MESA_FORMAT_RGBA_DXT1:
2275    case MESA_FORMAT_RGBA_DXT3:
2276    case MESA_FORMAT_RGBA_DXT5:
2277 #if FEATURE_EXT_texture_sRGB
2278    case MESA_FORMAT_SRGB_DXT1:
2279    case MESA_FORMAT_SRGBA_DXT1:
2280    case MESA_FORMAT_SRGBA_DXT3:
2281    case MESA_FORMAT_SRGBA_DXT5:
2282 #endif
2283 #endif
2284    case MESA_FORMAT_RED_RGTC1:
2285    case MESA_FORMAT_SIGNED_RED_RGTC1:
2286    case MESA_FORMAT_RG_RGTC2:
2287    case MESA_FORMAT_SIGNED_RG_RGTC2:
2288    case MESA_FORMAT_L_LATC1:
2289    case MESA_FORMAT_SIGNED_L_LATC1:
2290    case MESA_FORMAT_LA_LATC2:
2291    case MESA_FORMAT_SIGNED_LA_LATC2:
2292    case MESA_FORMAT_ETC1_RGB8:
2293       /* XXX generate error instead? */
2294       *datatype = GL_UNSIGNED_BYTE;
2295       *comps = 0;
2296       return;
2297 
2298    case MESA_FORMAT_RGBA_FLOAT32:
2299       *datatype = GL_FLOAT;
2300       *comps = 4;
2301       return;
2302    case MESA_FORMAT_RGBA_FLOAT16:
2303       *datatype = GL_HALF_FLOAT_ARB;
2304       *comps = 4;
2305       return;
2306    case MESA_FORMAT_RGB_FLOAT32:
2307       *datatype = GL_FLOAT;
2308       *comps = 3;
2309       return;
2310    case MESA_FORMAT_RGB_FLOAT16:
2311       *datatype = GL_HALF_FLOAT_ARB;
2312       *comps = 3;
2313       return;
2314    case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
2315    case MESA_FORMAT_RG_FLOAT32:
2316       *datatype = GL_FLOAT;
2317       *comps = 2;
2318       return;
2319    case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
2320    case MESA_FORMAT_RG_FLOAT16:
2321       *datatype = GL_HALF_FLOAT_ARB;
2322       *comps = 2;
2323       return;
2324    case MESA_FORMAT_ALPHA_FLOAT32:
2325    case MESA_FORMAT_LUMINANCE_FLOAT32:
2326    case MESA_FORMAT_INTENSITY_FLOAT32:
2327    case MESA_FORMAT_R_FLOAT32:
2328       *datatype = GL_FLOAT;
2329       *comps = 1;
2330       return;
2331    case MESA_FORMAT_ALPHA_FLOAT16:
2332    case MESA_FORMAT_LUMINANCE_FLOAT16:
2333    case MESA_FORMAT_INTENSITY_FLOAT16:
2334    case MESA_FORMAT_R_FLOAT16:
2335       *datatype = GL_HALF_FLOAT_ARB;
2336       *comps = 1;
2337       return;
2338 
2339    case MESA_FORMAT_ALPHA_UINT8:
2340    case MESA_FORMAT_LUMINANCE_UINT8:
2341    case MESA_FORMAT_INTENSITY_UINT8:
2342       *datatype = GL_UNSIGNED_BYTE;
2343       *comps = 1;
2344       return;
2345    case MESA_FORMAT_LUMINANCE_ALPHA_UINT8:
2346       *datatype = GL_UNSIGNED_BYTE;
2347       *comps = 2;
2348       return;
2349 
2350    case MESA_FORMAT_ALPHA_UINT16:
2351    case MESA_FORMAT_LUMINANCE_UINT16:
2352    case MESA_FORMAT_INTENSITY_UINT16:
2353       *datatype = GL_UNSIGNED_SHORT;
2354       *comps = 1;
2355       return;
2356    case MESA_FORMAT_LUMINANCE_ALPHA_UINT16:
2357       *datatype = GL_UNSIGNED_SHORT;
2358       *comps = 2;
2359       return;
2360    case MESA_FORMAT_ALPHA_UINT32:
2361    case MESA_FORMAT_LUMINANCE_UINT32:
2362    case MESA_FORMAT_INTENSITY_UINT32:
2363       *datatype = GL_UNSIGNED_INT;
2364       *comps = 1;
2365       return;
2366    case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
2367       *datatype = GL_UNSIGNED_INT;
2368       *comps = 2;
2369       return;
2370    case MESA_FORMAT_ALPHA_INT8:
2371    case MESA_FORMAT_LUMINANCE_INT8:
2372    case MESA_FORMAT_INTENSITY_INT8:
2373       *datatype = GL_BYTE;
2374       *comps = 1;
2375       return;
2376    case MESA_FORMAT_LUMINANCE_ALPHA_INT8:
2377       *datatype = GL_BYTE;
2378       *comps = 2;
2379       return;
2380 
2381    case MESA_FORMAT_ALPHA_INT16:
2382    case MESA_FORMAT_LUMINANCE_INT16:
2383    case MESA_FORMAT_INTENSITY_INT16:
2384       *datatype = GL_SHORT;
2385       *comps = 1;
2386       return;
2387    case MESA_FORMAT_LUMINANCE_ALPHA_INT16:
2388       *datatype = GL_SHORT;
2389       *comps = 2;
2390       return;
2391 
2392    case MESA_FORMAT_ALPHA_INT32:
2393    case MESA_FORMAT_LUMINANCE_INT32:
2394    case MESA_FORMAT_INTENSITY_INT32:
2395       *datatype = GL_INT;
2396       *comps = 1;
2397       return;
2398    case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
2399       *datatype = GL_INT;
2400       *comps = 2;
2401       return;
2402 
2403    case MESA_FORMAT_R_INT8:
2404       *datatype = GL_BYTE;
2405       *comps = 1;
2406       return;
2407    case MESA_FORMAT_RG_INT8:
2408       *datatype = GL_BYTE;
2409       *comps = 2;
2410       return;
2411    case MESA_FORMAT_RGB_INT8:
2412       *datatype = GL_BYTE;
2413       *comps = 3;
2414       return;
2415    case MESA_FORMAT_RGBA_INT8:
2416       *datatype = GL_BYTE;
2417       *comps = 4;
2418       return;
2419    case MESA_FORMAT_R_INT16:
2420       *datatype = GL_SHORT;
2421       *comps = 1;
2422       return;
2423    case MESA_FORMAT_RG_INT16:
2424       *datatype = GL_SHORT;
2425       *comps = 2;
2426       return;
2427    case MESA_FORMAT_RGB_INT16:
2428       *datatype = GL_SHORT;
2429       *comps = 3;
2430       return;
2431    case MESA_FORMAT_RGBA_INT16:
2432       *datatype = GL_SHORT;
2433       *comps = 4;
2434       return;
2435    case MESA_FORMAT_R_INT32:
2436       *datatype = GL_INT;
2437       *comps = 1;
2438       return;
2439    case MESA_FORMAT_RG_INT32:
2440       *datatype = GL_INT;
2441       *comps = 2;
2442       return;
2443    case MESA_FORMAT_RGB_INT32:
2444       *datatype = GL_INT;
2445       *comps = 3;
2446       return;
2447    case MESA_FORMAT_RGBA_INT32:
2448       *datatype = GL_INT;
2449       *comps = 4;
2450       return;
2451 
2452    /**
2453     * \name Non-normalized unsigned integer formats.
2454     */
2455    case MESA_FORMAT_R_UINT8:
2456       *datatype = GL_UNSIGNED_BYTE;
2457       *comps = 1;
2458       return;
2459    case MESA_FORMAT_RG_UINT8:
2460       *datatype = GL_UNSIGNED_BYTE;
2461       *comps = 2;
2462       return;
2463    case MESA_FORMAT_RGB_UINT8:
2464       *datatype = GL_UNSIGNED_BYTE;
2465       *comps = 3;
2466       return;
2467    case MESA_FORMAT_RGBA_UINT8:
2468       *datatype = GL_UNSIGNED_BYTE;
2469       *comps = 4;
2470       return;
2471    case MESA_FORMAT_R_UINT16:
2472       *datatype = GL_UNSIGNED_SHORT;
2473       *comps = 1;
2474       return;
2475    case MESA_FORMAT_RG_UINT16:
2476       *datatype = GL_UNSIGNED_SHORT;
2477       *comps = 2;
2478       return;
2479    case MESA_FORMAT_RGB_UINT16:
2480       *datatype = GL_UNSIGNED_SHORT;
2481       *comps = 3;
2482       return;
2483    case MESA_FORMAT_RGBA_UINT16:
2484       *datatype = GL_UNSIGNED_SHORT;
2485       *comps = 4;
2486       return;
2487    case MESA_FORMAT_R_UINT32:
2488       *datatype = GL_UNSIGNED_INT;
2489       *comps = 1;
2490       return;
2491    case MESA_FORMAT_RG_UINT32:
2492       *datatype = GL_UNSIGNED_INT;
2493       *comps = 2;
2494       return;
2495    case MESA_FORMAT_RGB_UINT32:
2496       *datatype = GL_UNSIGNED_INT;
2497       *comps = 3;
2498       return;
2499    case MESA_FORMAT_RGBA_UINT32:
2500       *datatype = GL_UNSIGNED_INT;
2501       *comps = 4;
2502       return;
2503 
2504    case MESA_FORMAT_RGB9_E5_FLOAT:
2505       *datatype = GL_UNSIGNED_INT_5_9_9_9_REV;
2506       *comps = 3;
2507       return;
2508 
2509    case MESA_FORMAT_R11_G11_B10_FLOAT:
2510       *datatype = GL_UNSIGNED_INT_10F_11F_11F_REV;
2511       *comps = 3;
2512       return;
2513 
2514    case MESA_FORMAT_ARGB2101010_UINT:
2515    case MESA_FORMAT_ABGR2101010_UINT:
2516       *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
2517       *comps = 4;
2518       return;
2519 
2520    case MESA_FORMAT_COUNT:
2521       assert(0);
2522       return;
2523 
2524    case MESA_FORMAT_NONE:
2525    /* For debug builds, warn if any formats are not handled */
2526 #ifdef DEBUG
2527    default:
2528 #endif
2529       _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps",
2530                     _mesa_get_format_name(format));
2531       *datatype = 0;
2532       *comps = 1;
2533    }
2534 }
2535 
2536 /**
2537  * Check if a gl_format exactly matches a GL formaat/type combination
2538  * such that we can use memcpy() from one to the other.
2539  * \param gl_format  a MESA_FORMAT_x value
2540  * \param format  the user-specified image format
2541  * \param type  the user-specified image datatype
2542  * \param swapBytes  typically the current pixel pack/unpack byteswap state
2543  * \return GL_TRUE if the formats match, GL_FALSE otherwise.
2544  */
2545 GLboolean
_mesa_format_matches_format_and_type(gl_format gl_format,GLenum format,GLenum type,GLboolean swapBytes)2546 _mesa_format_matches_format_and_type(gl_format gl_format,
2547 				     GLenum format, GLenum type,
2548                                      GLboolean swapBytes)
2549 {
2550    const GLboolean littleEndian = _mesa_little_endian();
2551 
2552    /* Note: When reading a GL format/type combination, the format lists channel
2553     * assignments from most significant channel in the type to least
2554     * significant.  A type with _REV indicates that the assignments are
2555     * swapped, so they are listed from least significant to most significant.
2556     *
2557     * For sanity, please keep this switch statement ordered the same as the
2558     * enums in formats.h.
2559     */
2560 
2561    switch (gl_format) {
2562 
2563    case MESA_FORMAT_NONE:
2564    case MESA_FORMAT_COUNT:
2565       return GL_FALSE;
2566 
2567    case MESA_FORMAT_RGBA8888:
2568       if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8 && !swapBytes)
2569          return GL_TRUE;
2570 
2571       if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV && swapBytes)
2572          return GL_TRUE;
2573 
2574       if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !littleEndian)
2575          return GL_TRUE;
2576 
2577       if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8_REV
2578           && !swapBytes)
2579          return GL_TRUE;
2580 
2581       if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8
2582           && swapBytes)
2583          return GL_TRUE;
2584 
2585       if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && littleEndian)
2586          return GL_TRUE;
2587 
2588       return GL_FALSE;
2589 
2590    case MESA_FORMAT_RGBA8888_REV:
2591       if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
2592           !swapBytes)
2593          return GL_TRUE;
2594 
2595       if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
2596          return GL_TRUE;
2597 
2598       if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && littleEndian)
2599          return GL_TRUE;
2600 
2601       if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8 &&
2602           !swapBytes)
2603          return GL_TRUE;
2604 
2605       if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
2606           swapBytes)
2607          return GL_TRUE;
2608 
2609       if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && !littleEndian)
2610          return GL_TRUE;
2611 
2612       return GL_FALSE;
2613 
2614    case MESA_FORMAT_ARGB8888:
2615       if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
2616           !swapBytes)
2617          return GL_TRUE;
2618 
2619       if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes)
2620          return GL_TRUE;
2621 
2622       if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && littleEndian)
2623          return GL_TRUE;
2624 
2625       return GL_FALSE;
2626 
2627    case MESA_FORMAT_ARGB8888_REV:
2628       if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8 && !swapBytes)
2629          return GL_TRUE;
2630 
2631       if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV &&
2632           swapBytes)
2633          return GL_TRUE;
2634 
2635       if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && !littleEndian)
2636          return GL_TRUE;
2637 
2638       return GL_FALSE;
2639 
2640    case MESA_FORMAT_RGBX8888:
2641    case MESA_FORMAT_RGBX8888_REV:
2642       return GL_FALSE;
2643 
2644    case MESA_FORMAT_XRGB8888:
2645    case MESA_FORMAT_XRGB8888_REV:
2646       return GL_FALSE;
2647 
2648    case MESA_FORMAT_RGB888:
2649       return format == GL_BGR && type == GL_UNSIGNED_BYTE && littleEndian;
2650 
2651    case MESA_FORMAT_BGR888:
2652       return format == GL_RGB && type == GL_UNSIGNED_BYTE && littleEndian;
2653 
2654    case MESA_FORMAT_RGB565:
2655       return format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5 && !swapBytes;
2656 
2657    case MESA_FORMAT_RGB565_REV:
2658       /* Some of the 16-bit MESA_FORMATs that would seem to correspond to
2659        * GL_UNSIGNED_SHORT_* are byte-swapped instead of channel-reversed,
2660        * according to formats.h, so they can't be matched.
2661        */
2662       return GL_FALSE;
2663 
2664    case MESA_FORMAT_ARGB4444:
2665       return format == GL_BGRA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV &&
2666          !swapBytes;
2667 
2668    case MESA_FORMAT_ARGB4444_REV:
2669       return GL_FALSE;
2670 
2671    case MESA_FORMAT_RGBA5551:
2672       return format == GL_RGBA && type == GL_UNSIGNED_SHORT_5_5_5_1 &&
2673          !swapBytes;
2674 
2675    case MESA_FORMAT_ARGB1555:
2676       return format == GL_BGRA && type == GL_UNSIGNED_SHORT_1_5_5_5_REV &&
2677          !swapBytes;
2678 
2679    case MESA_FORMAT_ARGB1555_REV:
2680       return GL_FALSE;
2681 
2682    case MESA_FORMAT_AL44:
2683       return GL_FALSE;
2684    case MESA_FORMAT_AL88:
2685       return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE && littleEndian;
2686    case MESA_FORMAT_AL88_REV:
2687       return GL_FALSE;
2688 
2689    case MESA_FORMAT_AL1616:
2690       return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_SHORT && littleEndian && !swapBytes;
2691    case MESA_FORMAT_AL1616_REV:
2692       return GL_FALSE;
2693 
2694    case MESA_FORMAT_RGB332:
2695       return format == GL_RGB && type == GL_UNSIGNED_BYTE_3_3_2;
2696 
2697    case MESA_FORMAT_A8:
2698       return format == GL_ALPHA && type == GL_UNSIGNED_BYTE;
2699    case MESA_FORMAT_A16:
2700       return format == GL_ALPHA && type == GL_UNSIGNED_SHORT &&
2701          littleEndian && !swapBytes;
2702    case MESA_FORMAT_L8:
2703       return format == GL_LUMINANCE && type == GL_UNSIGNED_BYTE;
2704    case MESA_FORMAT_L16:
2705       return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT &&
2706          littleEndian && !swapBytes;
2707    case MESA_FORMAT_I8:
2708       return format == GL_INTENSITY && type == GL_UNSIGNED_BYTE;
2709    case MESA_FORMAT_I16:
2710       return format == GL_INTENSITY && type == GL_UNSIGNED_SHORT &&
2711          littleEndian && !swapBytes;
2712 
2713    case MESA_FORMAT_YCBCR:
2714    case MESA_FORMAT_YCBCR_REV:
2715       return GL_FALSE;
2716 
2717    case MESA_FORMAT_R8:
2718       return format == GL_RED && type == GL_UNSIGNED_BYTE;
2719    case MESA_FORMAT_GR88:
2720       return format == GL_RG && type == GL_UNSIGNED_BYTE && littleEndian;
2721    case MESA_FORMAT_RG88:
2722       return GL_FALSE;
2723 
2724    case MESA_FORMAT_R16:
2725       return format == GL_RED && type == GL_UNSIGNED_SHORT && littleEndian &&
2726          !swapBytes;
2727    case MESA_FORMAT_RG1616:
2728       return format == GL_RG && type == GL_UNSIGNED_SHORT && littleEndian &&
2729          !swapBytes;
2730    case MESA_FORMAT_RG1616_REV:
2731       return GL_FALSE;
2732 
2733    case MESA_FORMAT_ARGB2101010:
2734       return format == GL_BGRA && type == GL_UNSIGNED_INT_2_10_10_10_REV &&
2735          !swapBytes;
2736 
2737    case MESA_FORMAT_Z24_S8:
2738       return format == GL_DEPTH_STENCIL && type == GL_UNSIGNED_INT_24_8 &&
2739          !swapBytes;
2740    case MESA_FORMAT_Z24_X8:
2741    case MESA_FORMAT_S8_Z24:
2742       return GL_FALSE;
2743 
2744    case MESA_FORMAT_Z16:
2745       return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_SHORT &&
2746          !swapBytes;
2747 
2748    case MESA_FORMAT_X8_Z24:
2749       return GL_FALSE;
2750 
2751    case MESA_FORMAT_Z32:
2752       return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_INT &&
2753          !swapBytes;
2754 
2755    case MESA_FORMAT_S8:
2756       return format == GL_STENCIL_INDEX && type == GL_UNSIGNED_BYTE;
2757 
2758    case MESA_FORMAT_SRGB8:
2759    case MESA_FORMAT_SRGBA8:
2760    case MESA_FORMAT_SARGB8:
2761    case MESA_FORMAT_SL8:
2762    case MESA_FORMAT_SLA8:
2763    case MESA_FORMAT_SRGB_DXT1:
2764    case MESA_FORMAT_SRGBA_DXT1:
2765    case MESA_FORMAT_SRGBA_DXT3:
2766    case MESA_FORMAT_SRGBA_DXT5:
2767       return GL_FALSE;
2768 
2769    case MESA_FORMAT_RGB_FXT1:
2770    case MESA_FORMAT_RGBA_FXT1:
2771    case MESA_FORMAT_RGB_DXT1:
2772    case MESA_FORMAT_RGBA_DXT1:
2773    case MESA_FORMAT_RGBA_DXT3:
2774    case MESA_FORMAT_RGBA_DXT5:
2775       return GL_FALSE;
2776 
2777    case MESA_FORMAT_RGBA_FLOAT32:
2778       return format == GL_RGBA && type == GL_FLOAT && !swapBytes;
2779    case MESA_FORMAT_RGBA_FLOAT16:
2780       return format == GL_RGBA && type == GL_HALF_FLOAT && !swapBytes;
2781 
2782    case MESA_FORMAT_RGB_FLOAT32:
2783       return format == GL_RGB && type == GL_FLOAT && !swapBytes;
2784    case MESA_FORMAT_RGB_FLOAT16:
2785       return format == GL_RGB && type == GL_HALF_FLOAT && !swapBytes;
2786 
2787    case MESA_FORMAT_ALPHA_FLOAT32:
2788       return format == GL_ALPHA && type == GL_FLOAT && !swapBytes;
2789    case MESA_FORMAT_ALPHA_FLOAT16:
2790       return format == GL_ALPHA && type == GL_HALF_FLOAT && !swapBytes;
2791 
2792    case MESA_FORMAT_LUMINANCE_FLOAT32:
2793       return format == GL_LUMINANCE && type == GL_FLOAT && !swapBytes;
2794    case MESA_FORMAT_LUMINANCE_FLOAT16:
2795       return format == GL_LUMINANCE && type == GL_HALF_FLOAT && !swapBytes;
2796 
2797    case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
2798       return format == GL_LUMINANCE_ALPHA && type == GL_FLOAT && !swapBytes;
2799    case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
2800       return format == GL_LUMINANCE_ALPHA && type == GL_HALF_FLOAT && !swapBytes;
2801 
2802    case MESA_FORMAT_INTENSITY_FLOAT32:
2803       return format == GL_INTENSITY && type == GL_FLOAT && !swapBytes;
2804    case MESA_FORMAT_INTENSITY_FLOAT16:
2805       return format == GL_INTENSITY && type == GL_HALF_FLOAT && !swapBytes;
2806 
2807    case MESA_FORMAT_R_FLOAT32:
2808       return format == GL_RED && type == GL_FLOAT && !swapBytes;
2809    case MESA_FORMAT_R_FLOAT16:
2810       return format == GL_RED && type == GL_HALF_FLOAT && !swapBytes;
2811 
2812    case MESA_FORMAT_RG_FLOAT32:
2813       return format == GL_RG && type == GL_FLOAT && !swapBytes;
2814    case MESA_FORMAT_RG_FLOAT16:
2815       return format == GL_RG && type == GL_HALF_FLOAT && !swapBytes;
2816 
2817       /* FINISHME: What do we want to do for GL_EXT_texture_integer? */
2818    case MESA_FORMAT_ALPHA_UINT8:
2819    case MESA_FORMAT_ALPHA_UINT16:
2820    case MESA_FORMAT_ALPHA_UINT32:
2821    case MESA_FORMAT_ALPHA_INT8:
2822    case MESA_FORMAT_ALPHA_INT16:
2823    case MESA_FORMAT_ALPHA_INT32:
2824       return GL_FALSE;
2825 
2826    case MESA_FORMAT_INTENSITY_UINT8:
2827    case MESA_FORMAT_INTENSITY_UINT16:
2828    case MESA_FORMAT_INTENSITY_UINT32:
2829    case MESA_FORMAT_INTENSITY_INT8:
2830    case MESA_FORMAT_INTENSITY_INT16:
2831    case MESA_FORMAT_INTENSITY_INT32:
2832       return GL_FALSE;
2833 
2834    case MESA_FORMAT_LUMINANCE_UINT8:
2835    case MESA_FORMAT_LUMINANCE_UINT16:
2836    case MESA_FORMAT_LUMINANCE_UINT32:
2837    case MESA_FORMAT_LUMINANCE_INT8:
2838    case MESA_FORMAT_LUMINANCE_INT16:
2839    case MESA_FORMAT_LUMINANCE_INT32:
2840       return GL_FALSE;
2841 
2842    case MESA_FORMAT_LUMINANCE_ALPHA_UINT8:
2843    case MESA_FORMAT_LUMINANCE_ALPHA_UINT16:
2844    case MESA_FORMAT_LUMINANCE_ALPHA_UINT32:
2845    case MESA_FORMAT_LUMINANCE_ALPHA_INT8:
2846    case MESA_FORMAT_LUMINANCE_ALPHA_INT16:
2847    case MESA_FORMAT_LUMINANCE_ALPHA_INT32:
2848       return GL_FALSE;
2849 
2850    case MESA_FORMAT_R_INT8:
2851    case MESA_FORMAT_RG_INT8:
2852    case MESA_FORMAT_RGB_INT8:
2853    case MESA_FORMAT_RGBA_INT8:
2854    case MESA_FORMAT_R_INT16:
2855    case MESA_FORMAT_RG_INT16:
2856    case MESA_FORMAT_RGB_INT16:
2857    case MESA_FORMAT_RGBA_INT16:
2858    case MESA_FORMAT_R_INT32:
2859    case MESA_FORMAT_RG_INT32:
2860    case MESA_FORMAT_RGB_INT32:
2861    case MESA_FORMAT_RGBA_INT32:
2862       return GL_FALSE;
2863 
2864    case MESA_FORMAT_R_UINT8:
2865    case MESA_FORMAT_RG_UINT8:
2866    case MESA_FORMAT_RGB_UINT8:
2867    case MESA_FORMAT_RGBA_UINT8:
2868    case MESA_FORMAT_R_UINT16:
2869    case MESA_FORMAT_RG_UINT16:
2870    case MESA_FORMAT_RGB_UINT16:
2871    case MESA_FORMAT_RGBA_UINT16:
2872    case MESA_FORMAT_R_UINT32:
2873    case MESA_FORMAT_RG_UINT32:
2874    case MESA_FORMAT_RGB_UINT32:
2875    case MESA_FORMAT_RGBA_UINT32:
2876       return GL_FALSE;
2877 
2878    case MESA_FORMAT_DUDV8:
2879    case MESA_FORMAT_SIGNED_R8:
2880    case MESA_FORMAT_SIGNED_RG88_REV:
2881    case MESA_FORMAT_SIGNED_RGBX8888:
2882       return GL_FALSE;
2883 
2884    case MESA_FORMAT_SIGNED_RGBA8888:
2885       if (format == GL_RGBA && type == GL_BYTE && !littleEndian)
2886          return GL_TRUE;
2887 
2888       if (format == GL_ABGR_EXT && type == GL_BYTE && littleEndian)
2889          return GL_TRUE;
2890 
2891       return GL_FALSE;
2892 
2893    case MESA_FORMAT_SIGNED_RGBA8888_REV:
2894       if (format == GL_RGBA && type == GL_BYTE && littleEndian)
2895          return GL_TRUE;
2896 
2897       if (format == GL_ABGR_EXT && type == GL_BYTE && !littleEndian)
2898          return GL_TRUE;
2899 
2900       return GL_FALSE;
2901 
2902    case MESA_FORMAT_SIGNED_R16:
2903    case MESA_FORMAT_SIGNED_GR1616:
2904    case MESA_FORMAT_SIGNED_RGB_16:
2905    case MESA_FORMAT_SIGNED_RGBA_16:
2906    case MESA_FORMAT_RGBA_16:
2907       /* FINISHME: SNORM */
2908       return GL_FALSE;
2909 
2910    case MESA_FORMAT_RED_RGTC1:
2911    case MESA_FORMAT_SIGNED_RED_RGTC1:
2912    case MESA_FORMAT_RG_RGTC2:
2913    case MESA_FORMAT_SIGNED_RG_RGTC2:
2914       return GL_FALSE;
2915 
2916    case MESA_FORMAT_L_LATC1:
2917    case MESA_FORMAT_SIGNED_L_LATC1:
2918    case MESA_FORMAT_LA_LATC2:
2919    case MESA_FORMAT_SIGNED_LA_LATC2:
2920       return GL_FALSE;
2921 
2922    case MESA_FORMAT_ETC1_RGB8:
2923       return GL_FALSE;
2924 
2925    case MESA_FORMAT_SIGNED_A8:
2926    case MESA_FORMAT_SIGNED_L8:
2927    case MESA_FORMAT_SIGNED_AL88:
2928    case MESA_FORMAT_SIGNED_I8:
2929    case MESA_FORMAT_SIGNED_A16:
2930    case MESA_FORMAT_SIGNED_L16:
2931    case MESA_FORMAT_SIGNED_AL1616:
2932    case MESA_FORMAT_SIGNED_I16:
2933       /* FINISHME: SNORM */
2934       return GL_FALSE;
2935 
2936    case MESA_FORMAT_ARGB2101010_UINT:
2937       return (format == GL_BGRA_INTEGER_EXT &&
2938               type == GL_UNSIGNED_INT_2_10_10_10_REV &&
2939               !swapBytes);
2940 
2941    case MESA_FORMAT_ABGR2101010_UINT:
2942       return (format == GL_RGBA_INTEGER_EXT &&
2943               type == GL_UNSIGNED_INT_2_10_10_10_REV &&
2944               !swapBytes);
2945 
2946    case MESA_FORMAT_RGB9_E5_FLOAT:
2947       return format == GL_RGB && type == GL_UNSIGNED_INT_5_9_9_9_REV &&
2948          !swapBytes;
2949 
2950    case MESA_FORMAT_R11_G11_B10_FLOAT:
2951       return format == GL_RGB && type == GL_UNSIGNED_INT_10F_11F_11F_REV &&
2952          !swapBytes;
2953 
2954    case MESA_FORMAT_Z32_FLOAT:
2955       return format == GL_DEPTH_COMPONENT && type == GL_FLOAT && !swapBytes;
2956 
2957    case MESA_FORMAT_Z32_FLOAT_X24S8:
2958       return GL_FALSE;
2959    }
2960 
2961    return GL_FALSE;
2962 }
2963 
2964