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