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