Merge branch 'glsl-to-tgsi'
[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 /* ARB_depth_buffer_float */
1095 {
1096 MESA_FORMAT_Z32_FLOAT, /* Name */
1097 "MESA_FORMAT_Z32_FLOAT", /* StrName */
1098 GL_DEPTH_COMPONENT, /* BaseFormat */
1099 GL_FLOAT, /* DataType */
1100 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
1101 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
1102 1, 1, 4 /* BlockWidth/Height,Bytes */
1103 },
1104 {
1105 MESA_FORMAT_Z32_FLOAT_X24S8, /* Name */
1106 "MESA_FORMAT_Z32_FLOAT_X24S8", /* StrName */
1107 GL_DEPTH_STENCIL, /* BaseFormat */
1108 GL_NONE /* XXX */, /* DataType */
1109 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
1110 0, 0, 0, 32, 8, /* Lum/Int/Index/Depth/StencilBits */
1111 1, 1, 8 /* BlockWidth/Height,Bytes */
1112 },
1113 };
1114
1115
1116
1117 static const struct gl_format_info *
1118 _mesa_get_format_info(gl_format format)
1119 {
1120 const struct gl_format_info *info = &format_info[format];
1121 assert(info->Name == format);
1122 return info;
1123 }
1124
1125
1126 /** Return string name of format (for debugging) */
1127 const char *
1128 _mesa_get_format_name(gl_format format)
1129 {
1130 const struct gl_format_info *info = _mesa_get_format_info(format);
1131 return info->StrName;
1132 }
1133
1134
1135
1136 /**
1137 * Return bytes needed to store a block of pixels in the given format.
1138 * Normally, a block is 1x1 (a single pixel). But for compressed formats
1139 * a block may be 4x4 or 8x4, etc.
1140 *
1141 * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351
1142 */
1143 GLint
1144 _mesa_get_format_bytes(gl_format format)
1145 {
1146 const struct gl_format_info *info = _mesa_get_format_info(format);
1147 ASSERT(info->BytesPerBlock);
1148 return info->BytesPerBlock;
1149 }
1150
1151
1152 /**
1153 * Return bits per component for the given format.
1154 * \param format one of MESA_FORMAT_x
1155 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
1156 */
1157 GLint
1158 _mesa_get_format_bits(gl_format format, GLenum pname)
1159 {
1160 const struct gl_format_info *info = _mesa_get_format_info(format);
1161
1162 switch (pname) {
1163 case GL_RED_BITS:
1164 case GL_TEXTURE_RED_SIZE:
1165 case GL_RENDERBUFFER_RED_SIZE_EXT:
1166 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
1167 return info->RedBits;
1168 case GL_GREEN_BITS:
1169 case GL_TEXTURE_GREEN_SIZE:
1170 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
1171 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
1172 return info->GreenBits;
1173 case GL_BLUE_BITS:
1174 case GL_TEXTURE_BLUE_SIZE:
1175 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
1176 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
1177 return info->BlueBits;
1178 case GL_ALPHA_BITS:
1179 case GL_TEXTURE_ALPHA_SIZE:
1180 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
1181 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
1182 return info->AlphaBits;
1183 case GL_TEXTURE_INTENSITY_SIZE:
1184 return info->IntensityBits;
1185 case GL_TEXTURE_LUMINANCE_SIZE:
1186 return info->LuminanceBits;
1187 case GL_INDEX_BITS:
1188 case GL_TEXTURE_INDEX_SIZE_EXT:
1189 return info->IndexBits;
1190 case GL_DEPTH_BITS:
1191 case GL_TEXTURE_DEPTH_SIZE_ARB:
1192 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
1193 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
1194 return info->DepthBits;
1195 case GL_STENCIL_BITS:
1196 case GL_TEXTURE_STENCIL_SIZE_EXT:
1197 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
1198 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
1199 return info->StencilBits;
1200 default:
1201 _mesa_problem(NULL, "bad pname in _mesa_get_format_bits()");
1202 return 0;
1203 }
1204 }
1205
1206
1207 /**
1208 * Return the data type (or more specifically, the data representation)
1209 * for the given format.
1210 * The return value will be one of:
1211 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
1212 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
1213 * GL_UNSIGNED_INT = an ordinary unsigned integer
1214 * GL_INT = an ordinary signed integer
1215 * GL_FLOAT = an ordinary float
1216 */
1217 GLenum
1218 _mesa_get_format_datatype(gl_format format)
1219 {
1220 const struct gl_format_info *info = _mesa_get_format_info(format);
1221 return info->DataType;
1222 }
1223
1224
1225 /**
1226 * Return the basic format for the given type. The result will be
1227 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
1228 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
1229 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
1230 */
1231 GLenum
1232 _mesa_get_format_base_format(gl_format format)
1233 {
1234 const struct gl_format_info *info = _mesa_get_format_info(format);
1235 return info->BaseFormat;
1236 }
1237
1238
1239 /**
1240 * Return the block size (in pixels) for the given format. Normally
1241 * the block size is 1x1. But compressed formats will have block sizes
1242 * of 4x4 or 8x4 pixels, etc.
1243 * \param bw returns block width in pixels
1244 * \param bh returns block height in pixels
1245 */
1246 void
1247 _mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
1248 {
1249 const struct gl_format_info *info = _mesa_get_format_info(format);
1250 *bw = info->BlockWidth;
1251 *bh = info->BlockHeight;
1252 }
1253
1254
1255 /** Is the given format a compressed format? */
1256 GLboolean
1257 _mesa_is_format_compressed(gl_format format)
1258 {
1259 const struct gl_format_info *info = _mesa_get_format_info(format);
1260 return info->BlockWidth > 1 || info->BlockHeight > 1;
1261 }
1262
1263
1264 /**
1265 * Determine if the given format represents a packed depth/stencil buffer.
1266 */
1267 GLboolean
1268 _mesa_is_format_packed_depth_stencil(gl_format format)
1269 {
1270 const struct gl_format_info *info = _mesa_get_format_info(format);
1271
1272 return info->BaseFormat == GL_DEPTH_STENCIL;
1273 }
1274
1275
1276 /**
1277 * Is the given format a signed/unsigned integer color format?
1278 */
1279 GLboolean
1280 _mesa_is_format_integer_color(gl_format format)
1281 {
1282 const struct gl_format_info *info = _mesa_get_format_info(format);
1283 return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) &&
1284 info->BaseFormat != GL_DEPTH_COMPONENT &&
1285 info->BaseFormat != GL_DEPTH_STENCIL &&
1286 info->BaseFormat != GL_STENCIL_INDEX;
1287 }
1288
1289
1290 /**
1291 * Return color encoding for given format.
1292 * \return GL_LINEAR or GL_SRGB
1293 */
1294 GLenum
1295 _mesa_get_format_color_encoding(gl_format format)
1296 {
1297 /* XXX this info should be encoded in gl_format_info */
1298 switch (format) {
1299 case MESA_FORMAT_SRGB8:
1300 case MESA_FORMAT_SRGBA8:
1301 case MESA_FORMAT_SARGB8:
1302 case MESA_FORMAT_SL8:
1303 case MESA_FORMAT_SLA8:
1304 case MESA_FORMAT_SRGB_DXT1:
1305 case MESA_FORMAT_SRGBA_DXT1:
1306 case MESA_FORMAT_SRGBA_DXT3:
1307 case MESA_FORMAT_SRGBA_DXT5:
1308 return GL_SRGB;
1309 default:
1310 return GL_LINEAR;
1311 }
1312 }
1313
1314
1315 /**
1316 * For an sRGB format, return the corresponding linear color space format.
1317 * For non-sRGB formats, return the format as-is.
1318 */
1319 gl_format
1320 _mesa_get_srgb_format_linear(gl_format format)
1321 {
1322 switch (format) {
1323 case MESA_FORMAT_SRGB8:
1324 format = MESA_FORMAT_RGB888;
1325 break;
1326 case MESA_FORMAT_SRGBA8:
1327 format = MESA_FORMAT_RGBA8888;
1328 break;
1329 case MESA_FORMAT_SARGB8:
1330 format = MESA_FORMAT_ARGB8888;
1331 break;
1332 case MESA_FORMAT_SL8:
1333 format = MESA_FORMAT_L8;
1334 break;
1335 case MESA_FORMAT_SLA8:
1336 format = MESA_FORMAT_AL88;
1337 break;
1338 case MESA_FORMAT_SRGB_DXT1:
1339 format = MESA_FORMAT_RGB_DXT1;
1340 break;
1341 case MESA_FORMAT_SRGBA_DXT1:
1342 format = MESA_FORMAT_RGBA_DXT1;
1343 break;
1344 case MESA_FORMAT_SRGBA_DXT3:
1345 format = MESA_FORMAT_RGBA_DXT3;
1346 break;
1347 case MESA_FORMAT_SRGBA_DXT5:
1348 format = MESA_FORMAT_RGBA_DXT5;
1349 break;
1350 default:
1351 break;
1352 }
1353 return format;
1354 }
1355
1356
1357 /**
1358 * Return number of bytes needed to store an image of the given size
1359 * in the given format.
1360 */
1361 GLuint
1362 _mesa_format_image_size(gl_format format, GLsizei width,
1363 GLsizei height, GLsizei depth)
1364 {
1365 const struct gl_format_info *info = _mesa_get_format_info(format);
1366 /* Strictly speaking, a conditional isn't needed here */
1367 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1368 /* compressed format (2D only for now) */
1369 const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
1370 const GLuint wblocks = (width + bw - 1) / bw;
1371 const GLuint hblocks = (height + bh - 1) / bh;
1372 const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
1373 assert(depth == 1);
1374 return sz;
1375 }
1376 else {
1377 /* non-compressed */
1378 const GLuint sz = width * height * depth * info->BytesPerBlock;
1379 return sz;
1380 }
1381 }
1382
1383
1384 /**
1385 * Same as _mesa_format_image_size() but returns a 64-bit value to
1386 * accomodate very large textures.
1387 */
1388 uint64_t
1389 _mesa_format_image_size64(gl_format format, GLsizei width,
1390 GLsizei height, GLsizei depth)
1391 {
1392 const struct gl_format_info *info = _mesa_get_format_info(format);
1393 /* Strictly speaking, a conditional isn't needed here */
1394 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1395 /* compressed format (2D only for now) */
1396 const uint64_t bw = info->BlockWidth, bh = info->BlockHeight;
1397 const uint64_t wblocks = (width + bw - 1) / bw;
1398 const uint64_t hblocks = (height + bh - 1) / bh;
1399 const uint64_t sz = wblocks * hblocks * info->BytesPerBlock;
1400 assert(depth == 1);
1401 return sz;
1402 }
1403 else {
1404 /* non-compressed */
1405 const uint64_t sz = ((uint64_t) width *
1406 (uint64_t) height *
1407 (uint64_t) depth *
1408 info->BytesPerBlock);
1409 return sz;
1410 }
1411 }
1412
1413
1414
1415 GLint
1416 _mesa_format_row_stride(gl_format format, GLsizei width)
1417 {
1418 const struct gl_format_info *info = _mesa_get_format_info(format);
1419 /* Strictly speaking, a conditional isn't needed here */
1420 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1421 /* compressed format */
1422 const GLuint bw = info->BlockWidth;
1423 const GLuint wblocks = (width + bw - 1) / bw;
1424 const GLint stride = wblocks * info->BytesPerBlock;
1425 return stride;
1426 }
1427 else {
1428 const GLint stride = width * info->BytesPerBlock;
1429 return stride;
1430 }
1431 }
1432
1433
1434 /**
1435 * Debug/test: check that all formats are handled in the
1436 * _mesa_format_to_type_and_comps() function. When new pixel formats
1437 * are added to Mesa, that function needs to be updated.
1438 * This is a no-op after the first call.
1439 */
1440 static void
1441 check_format_to_type_and_comps(void)
1442 {
1443 gl_format f;
1444
1445 for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) {
1446 GLenum datatype = 0;
1447 GLuint comps = 0;
1448 /* This function will emit a problem/warning if the format is
1449 * not handled.
1450 */
1451 _mesa_format_to_type_and_comps(f, &datatype, &comps);
1452 }
1453 }
1454
1455
1456 /**
1457 * Do sanity checking of the format info table.
1458 */
1459 void
1460 _mesa_test_formats(void)
1461 {
1462 GLuint i;
1463
1464 assert(Elements(format_info) == MESA_FORMAT_COUNT);
1465
1466 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
1467 const struct gl_format_info *info = _mesa_get_format_info(i);
1468 assert(info);
1469
1470 assert(info->Name == i);
1471
1472 if (info->Name == MESA_FORMAT_NONE)
1473 continue;
1474
1475 if (info->BlockWidth == 1 && info->BlockHeight == 1) {
1476 if (info->RedBits > 0) {
1477 GLuint t = info->RedBits + info->GreenBits
1478 + info->BlueBits + info->AlphaBits;
1479 assert(t / 8 <= info->BytesPerBlock);
1480 (void) t;
1481 }
1482 }
1483
1484 assert(info->DataType == GL_UNSIGNED_NORMALIZED ||
1485 info->DataType == GL_SIGNED_NORMALIZED ||
1486 info->DataType == GL_UNSIGNED_INT ||
1487 info->DataType == GL_INT ||
1488 info->DataType == GL_FLOAT ||
1489 /* Z32_FLOAT_X24S8 has DataType of GL_NONE */
1490 info->DataType == GL_NONE);
1491
1492 if (info->BaseFormat == GL_RGB) {
1493 assert(info->RedBits > 0);
1494 assert(info->GreenBits > 0);
1495 assert(info->BlueBits > 0);
1496 assert(info->AlphaBits == 0);
1497 assert(info->LuminanceBits == 0);
1498 assert(info->IntensityBits == 0);
1499 }
1500 else if (info->BaseFormat == GL_RGBA) {
1501 assert(info->RedBits > 0);
1502 assert(info->GreenBits > 0);
1503 assert(info->BlueBits > 0);
1504 assert(info->AlphaBits > 0);
1505 assert(info->LuminanceBits == 0);
1506 assert(info->IntensityBits == 0);
1507 }
1508 else if (info->BaseFormat == GL_RG) {
1509 assert(info->RedBits > 0);
1510 assert(info->GreenBits > 0);
1511 assert(info->BlueBits == 0);
1512 assert(info->AlphaBits == 0);
1513 assert(info->LuminanceBits == 0);
1514 assert(info->IntensityBits == 0);
1515 }
1516 else if (info->BaseFormat == GL_RED) {
1517 assert(info->RedBits > 0);
1518 assert(info->GreenBits == 0);
1519 assert(info->BlueBits == 0);
1520 assert(info->AlphaBits == 0);
1521 assert(info->LuminanceBits == 0);
1522 assert(info->IntensityBits == 0);
1523 }
1524 else if (info->BaseFormat == GL_LUMINANCE) {
1525 assert(info->RedBits == 0);
1526 assert(info->GreenBits == 0);
1527 assert(info->BlueBits == 0);
1528 assert(info->AlphaBits == 0);
1529 assert(info->LuminanceBits > 0);
1530 assert(info->IntensityBits == 0);
1531 }
1532 else if (info->BaseFormat == GL_INTENSITY) {
1533 assert(info->RedBits == 0);
1534 assert(info->GreenBits == 0);
1535 assert(info->BlueBits == 0);
1536 assert(info->AlphaBits == 0);
1537 assert(info->LuminanceBits == 0);
1538 assert(info->IntensityBits > 0);
1539 }
1540 }
1541
1542 check_format_to_type_and_comps();
1543 }
1544
1545
1546
1547 /**
1548 * Return datatype and number of components per texel for the given gl_format.
1549 * Only used for mipmap generation code.
1550 */
1551 void
1552 _mesa_format_to_type_and_comps(gl_format format,
1553 GLenum *datatype, GLuint *comps)
1554 {
1555 switch (format) {
1556 case MESA_FORMAT_RGBA8888:
1557 case MESA_FORMAT_RGBA8888_REV:
1558 case MESA_FORMAT_ARGB8888:
1559 case MESA_FORMAT_ARGB8888_REV:
1560 case MESA_FORMAT_XRGB8888:
1561 case MESA_FORMAT_XRGB8888_REV:
1562 *datatype = GL_UNSIGNED_BYTE;
1563 *comps = 4;
1564 return;
1565 case MESA_FORMAT_RGB888:
1566 case MESA_FORMAT_BGR888:
1567 *datatype = GL_UNSIGNED_BYTE;
1568 *comps = 3;
1569 return;
1570 case MESA_FORMAT_RGB565:
1571 case MESA_FORMAT_RGB565_REV:
1572 *datatype = GL_UNSIGNED_SHORT_5_6_5;
1573 *comps = 3;
1574 return;
1575
1576 case MESA_FORMAT_ARGB4444:
1577 case MESA_FORMAT_ARGB4444_REV:
1578 *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
1579 *comps = 4;
1580 return;
1581
1582 case MESA_FORMAT_ARGB1555:
1583 case MESA_FORMAT_ARGB1555_REV:
1584 *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1585 *comps = 4;
1586 return;
1587
1588 case MESA_FORMAT_ARGB2101010:
1589 *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
1590 *comps = 4;
1591 return;
1592
1593 case MESA_FORMAT_RGBA5551:
1594 *datatype = GL_UNSIGNED_SHORT_5_5_5_1;
1595 *comps = 4;
1596 return;
1597
1598 case MESA_FORMAT_AL44:
1599 *datatype = MESA_UNSIGNED_BYTE_4_4;
1600 *comps = 2;
1601 return;
1602
1603 case MESA_FORMAT_AL88:
1604 case MESA_FORMAT_AL88_REV:
1605 case MESA_FORMAT_RG88:
1606 case MESA_FORMAT_RG88_REV:
1607 *datatype = GL_UNSIGNED_BYTE;
1608 *comps = 2;
1609 return;
1610
1611 case MESA_FORMAT_AL1616:
1612 case MESA_FORMAT_AL1616_REV:
1613 case MESA_FORMAT_RG1616:
1614 case MESA_FORMAT_RG1616_REV:
1615 *datatype = GL_UNSIGNED_SHORT;
1616 *comps = 2;
1617 return;
1618
1619 case MESA_FORMAT_R16:
1620 case MESA_FORMAT_A16:
1621 case MESA_FORMAT_L16:
1622 case MESA_FORMAT_I16:
1623 *datatype = GL_UNSIGNED_SHORT;
1624 *comps = 1;
1625 return;
1626
1627 case MESA_FORMAT_RGB332:
1628 *datatype = GL_UNSIGNED_BYTE_3_3_2;
1629 *comps = 3;
1630 return;
1631
1632 case MESA_FORMAT_A8:
1633 case MESA_FORMAT_L8:
1634 case MESA_FORMAT_I8:
1635 case MESA_FORMAT_CI8:
1636 case MESA_FORMAT_R8:
1637 case MESA_FORMAT_S8:
1638 *datatype = GL_UNSIGNED_BYTE;
1639 *comps = 1;
1640 return;
1641
1642 case MESA_FORMAT_YCBCR:
1643 case MESA_FORMAT_YCBCR_REV:
1644 *datatype = GL_UNSIGNED_SHORT;
1645 *comps = 2;
1646 return;
1647
1648 case MESA_FORMAT_Z24_S8:
1649 *datatype = GL_UNSIGNED_INT;
1650 *comps = 1; /* XXX OK? */
1651 return;
1652
1653 case MESA_FORMAT_S8_Z24:
1654 *datatype = GL_UNSIGNED_INT;
1655 *comps = 1; /* XXX OK? */
1656 return;
1657
1658 case MESA_FORMAT_Z16:
1659 *datatype = GL_UNSIGNED_SHORT;
1660 *comps = 1;
1661 return;
1662
1663 case MESA_FORMAT_X8_Z24:
1664 *datatype = GL_UNSIGNED_INT;
1665 *comps = 1;
1666 return;
1667
1668 case MESA_FORMAT_Z24_X8:
1669 *datatype = GL_UNSIGNED_INT;
1670 *comps = 1;
1671 return;
1672
1673 case MESA_FORMAT_Z32:
1674 *datatype = GL_UNSIGNED_INT;
1675 *comps = 1;
1676 return;
1677
1678 case MESA_FORMAT_Z32_FLOAT:
1679 *datatype = GL_FLOAT;
1680 *comps = 1;
1681 return;
1682
1683 case MESA_FORMAT_Z32_FLOAT_X24S8:
1684 *datatype = GL_FLOAT_32_UNSIGNED_INT_24_8_REV;
1685 *comps = 1;
1686 return;
1687
1688 case MESA_FORMAT_DUDV8:
1689 *datatype = GL_BYTE;
1690 *comps = 2;
1691 return;
1692
1693 case MESA_FORMAT_SIGNED_R8:
1694 case MESA_FORMAT_SIGNED_A8:
1695 case MESA_FORMAT_SIGNED_L8:
1696 case MESA_FORMAT_SIGNED_I8:
1697 *datatype = GL_BYTE;
1698 *comps = 1;
1699 return;
1700 case MESA_FORMAT_SIGNED_RG88_REV:
1701 case MESA_FORMAT_SIGNED_AL88:
1702 *datatype = GL_BYTE;
1703 *comps = 2;
1704 return;
1705 case MESA_FORMAT_SIGNED_RGBA8888:
1706 case MESA_FORMAT_SIGNED_RGBA8888_REV:
1707 case MESA_FORMAT_SIGNED_RGBX8888:
1708 *datatype = GL_BYTE;
1709 *comps = 4;
1710 return;
1711
1712 case MESA_FORMAT_RGBA_16:
1713 *datatype = GL_UNSIGNED_SHORT;
1714 *comps = 4;
1715 return;
1716
1717 case MESA_FORMAT_SIGNED_R16:
1718 case MESA_FORMAT_SIGNED_A16:
1719 case MESA_FORMAT_SIGNED_L16:
1720 case MESA_FORMAT_SIGNED_I16:
1721 *datatype = GL_SHORT;
1722 *comps = 1;
1723 return;
1724 case MESA_FORMAT_SIGNED_GR1616:
1725 case MESA_FORMAT_SIGNED_AL1616:
1726 *datatype = GL_SHORT;
1727 *comps = 2;
1728 return;
1729 case MESA_FORMAT_SIGNED_RGB_16:
1730 *datatype = GL_SHORT;
1731 *comps = 3;
1732 return;
1733 case MESA_FORMAT_SIGNED_RGBA_16:
1734 *datatype = GL_SHORT;
1735 *comps = 4;
1736 return;
1737
1738 #if FEATURE_EXT_texture_sRGB
1739 case MESA_FORMAT_SRGB8:
1740 *datatype = GL_UNSIGNED_BYTE;
1741 *comps = 3;
1742 return;
1743 case MESA_FORMAT_SRGBA8:
1744 case MESA_FORMAT_SARGB8:
1745 *datatype = GL_UNSIGNED_BYTE;
1746 *comps = 4;
1747 return;
1748 case MESA_FORMAT_SL8:
1749 *datatype = GL_UNSIGNED_BYTE;
1750 *comps = 1;
1751 return;
1752 case MESA_FORMAT_SLA8:
1753 *datatype = GL_UNSIGNED_BYTE;
1754 *comps = 2;
1755 return;
1756 #endif
1757
1758 #if FEATURE_texture_fxt1
1759 case MESA_FORMAT_RGB_FXT1:
1760 case MESA_FORMAT_RGBA_FXT1:
1761 #endif
1762 #if FEATURE_texture_s3tc
1763 case MESA_FORMAT_RGB_DXT1:
1764 case MESA_FORMAT_RGBA_DXT1:
1765 case MESA_FORMAT_RGBA_DXT3:
1766 case MESA_FORMAT_RGBA_DXT5:
1767 #if FEATURE_EXT_texture_sRGB
1768 case MESA_FORMAT_SRGB_DXT1:
1769 case MESA_FORMAT_SRGBA_DXT1:
1770 case MESA_FORMAT_SRGBA_DXT3:
1771 case MESA_FORMAT_SRGBA_DXT5:
1772 #endif
1773 #endif
1774 case MESA_FORMAT_RED_RGTC1:
1775 case MESA_FORMAT_SIGNED_RED_RGTC1:
1776 case MESA_FORMAT_RG_RGTC2:
1777 case MESA_FORMAT_SIGNED_RG_RGTC2:
1778 case MESA_FORMAT_L_LATC1:
1779 case MESA_FORMAT_SIGNED_L_LATC1:
1780 case MESA_FORMAT_LA_LATC2:
1781 case MESA_FORMAT_SIGNED_LA_LATC2:
1782 /* XXX generate error instead? */
1783 *datatype = GL_UNSIGNED_BYTE;
1784 *comps = 0;
1785 return;
1786
1787 case MESA_FORMAT_RGBA_FLOAT32:
1788 *datatype = GL_FLOAT;
1789 *comps = 4;
1790 return;
1791 case MESA_FORMAT_RGBA_FLOAT16:
1792 *datatype = GL_HALF_FLOAT_ARB;
1793 *comps = 4;
1794 return;
1795 case MESA_FORMAT_RGB_FLOAT32:
1796 *datatype = GL_FLOAT;
1797 *comps = 3;
1798 return;
1799 case MESA_FORMAT_RGB_FLOAT16:
1800 *datatype = GL_HALF_FLOAT_ARB;
1801 *comps = 3;
1802 return;
1803 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
1804 case MESA_FORMAT_RG_FLOAT32:
1805 *datatype = GL_FLOAT;
1806 *comps = 2;
1807 return;
1808 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
1809 case MESA_FORMAT_RG_FLOAT16:
1810 *datatype = GL_HALF_FLOAT_ARB;
1811 *comps = 2;
1812 return;
1813 case MESA_FORMAT_ALPHA_FLOAT32:
1814 case MESA_FORMAT_LUMINANCE_FLOAT32:
1815 case MESA_FORMAT_INTENSITY_FLOAT32:
1816 case MESA_FORMAT_R_FLOAT32:
1817 *datatype = GL_FLOAT;
1818 *comps = 1;
1819 return;
1820 case MESA_FORMAT_ALPHA_FLOAT16:
1821 case MESA_FORMAT_LUMINANCE_FLOAT16:
1822 case MESA_FORMAT_INTENSITY_FLOAT16:
1823 case MESA_FORMAT_R_FLOAT16:
1824 *datatype = GL_HALF_FLOAT_ARB;
1825 *comps = 1;
1826 return;
1827
1828 case MESA_FORMAT_RGBA_INT8:
1829 *datatype = GL_BYTE;
1830 *comps = 4;
1831 return;
1832 case MESA_FORMAT_RGBA_INT16:
1833 *datatype = GL_SHORT;
1834 *comps = 4;
1835 return;
1836 case MESA_FORMAT_RGBA_INT32:
1837 *datatype = GL_INT;
1838 *comps = 4;
1839 return;
1840
1841 /**
1842 * \name Non-normalized unsigned integer formats.
1843 */
1844 case MESA_FORMAT_RGBA_UINT8:
1845 *datatype = GL_UNSIGNED_BYTE;
1846 *comps = 4;
1847 return;
1848 case MESA_FORMAT_RGBA_UINT16:
1849 *datatype = GL_UNSIGNED_SHORT;
1850 *comps = 4;
1851 return;
1852 case MESA_FORMAT_RGBA_UINT32:
1853 *datatype = GL_UNSIGNED_INT;
1854 *comps = 4;
1855 return;
1856
1857 case MESA_FORMAT_RGB9_E5_FLOAT:
1858 *datatype = GL_UNSIGNED_INT_5_9_9_9_REV;
1859 *comps = 3;
1860 return;
1861
1862 case MESA_FORMAT_R11_G11_B10_FLOAT:
1863 *datatype = GL_UNSIGNED_INT_10F_11F_11F_REV;
1864 *comps = 3;
1865 return;
1866
1867 case MESA_FORMAT_COUNT:
1868 assert(0);
1869 return;
1870
1871 case MESA_FORMAT_NONE:
1872 /* For debug builds, warn if any formats are not handled */
1873 #ifdef DEBUG
1874 default:
1875 #endif
1876 _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps",
1877 _mesa_get_format_name(format));
1878 *datatype = 0;
1879 *comps = 1;
1880 }
1881 }