efbd4a2c25de20dbea532d6da684e4a3d2645f31
[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_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE,
44 * GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX,
45 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
46 */
47 GLenum BaseFormat;
48
49 /**
50 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
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_I8, /* Name */
307 "MESA_FORMAT_I8", /* StrName */
308 GL_INTENSITY, /* BaseFormat */
309 GL_UNSIGNED_NORMALIZED, /* DataType */
310 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
311 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
312 1, 1, 1 /* BlockWidth/Height,Bytes */
313 },
314 {
315 MESA_FORMAT_CI8, /* Name */
316 "MESA_FORMAT_CI8", /* StrName */
317 GL_COLOR_INDEX, /* BaseFormat */
318 GL_UNSIGNED_INT, /* DataType */
319 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
320 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
321 1, 1, 1 /* BlockWidth/Height,Bytes */
322 },
323 {
324 MESA_FORMAT_YCBCR, /* Name */
325 "MESA_FORMAT_YCBCR", /* StrName */
326 GL_YCBCR_MESA, /* BaseFormat */
327 GL_UNSIGNED_NORMALIZED, /* DataType */
328 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
329 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
330 1, 1, 2 /* BlockWidth/Height,Bytes */
331 },
332 {
333 MESA_FORMAT_YCBCR_REV, /* Name */
334 "MESA_FORMAT_YCBCR_REV", /* 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_R8,
343 "MESA_FORMAT_R8",
344 GL_RED,
345 GL_UNSIGNED_NORMALIZED,
346 8, 0, 0, 0,
347 0, 0, 0, 0, 0,
348 1, 1, 1
349 },
350 {
351 MESA_FORMAT_RG88,
352 "MESA_FORMAT_RG88",
353 GL_RG,
354 GL_UNSIGNED_NORMALIZED,
355 8, 8, 0, 0,
356 0, 0, 0, 0, 0,
357 1, 1, 2
358 },
359 {
360 MESA_FORMAT_RG88_REV,
361 "MESA_FORMAT_RG88_REV",
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_R16,
370 "MESA_FORMAT_R16",
371 GL_RED,
372 GL_UNSIGNED_NORMALIZED,
373 16, 0, 0, 0,
374 0, 0, 0, 0, 0,
375 1, 1, 2
376 },
377 {
378 MESA_FORMAT_RG1616,
379 "MESA_FORMAT_RG1616",
380 GL_RG,
381 GL_UNSIGNED_NORMALIZED,
382 16, 16, 0, 0,
383 0, 0, 0, 0, 0,
384 1, 1, 4
385 },
386 {
387 MESA_FORMAT_RG1616_REV,
388 "MESA_FORMAT_RG1616_REV",
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_ARGB2101010,
397 "MESA_FORMAT_ARGB2101010",
398 GL_RGBA,
399 GL_UNSIGNED_NORMALIZED,
400 10, 10, 10, 2,
401 0, 0, 0, 0, 0,
402 1, 1, 4
403 },
404 {
405 MESA_FORMAT_Z24_S8, /* Name */
406 "MESA_FORMAT_Z24_S8", /* StrName */
407 GL_DEPTH_STENCIL, /* BaseFormat */
408 GL_UNSIGNED_INT, /* DataType */
409 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
410 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
411 1, 1, 4 /* BlockWidth/Height,Bytes */
412 },
413 {
414 MESA_FORMAT_S8_Z24, /* Name */
415 "MESA_FORMAT_S8_Z24", /* 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_Z16, /* Name */
424 "MESA_FORMAT_Z16", /* StrName */
425 GL_DEPTH_COMPONENT, /* BaseFormat */
426 GL_UNSIGNED_INT, /* DataType */
427 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
428 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
429 1, 1, 2 /* BlockWidth/Height,Bytes */
430 },
431 {
432 MESA_FORMAT_X8_Z24, /* Name */
433 "MESA_FORMAT_X8_Z24", /* StrName */
434 GL_DEPTH_COMPONENT, /* BaseFormat */
435 GL_UNSIGNED_INT, /* DataType */
436 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
437 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
438 1, 1, 4 /* BlockWidth/Height,Bytes */
439 },
440 {
441 MESA_FORMAT_Z24_X8, /* Name */
442 "MESA_FORMAT_Z24_X8", /* 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_Z32, /* Name */
451 "MESA_FORMAT_Z32", /* StrName */
452 GL_DEPTH_COMPONENT, /* BaseFormat */
453 GL_UNSIGNED_INT, /* DataType */
454 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
455 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
456 1, 1, 4 /* BlockWidth/Height,Bytes */
457 },
458 {
459 MESA_FORMAT_S8, /* Name */
460 "MESA_FORMAT_S8", /* StrName */
461 GL_STENCIL_INDEX, /* BaseFormat */
462 GL_UNSIGNED_INT, /* DataType */
463 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
464 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
465 1, 1, 1 /* BlockWidth/Height,Bytes */
466 },
467 {
468 MESA_FORMAT_SRGB8,
469 "MESA_FORMAT_SRGB8",
470 GL_RGB,
471 GL_UNSIGNED_NORMALIZED,
472 8, 8, 8, 0,
473 0, 0, 0, 0, 0,
474 1, 1, 3
475 },
476 {
477 MESA_FORMAT_SRGBA8,
478 "MESA_FORMAT_SRGBA8",
479 GL_RGBA,
480 GL_UNSIGNED_NORMALIZED,
481 8, 8, 8, 8,
482 0, 0, 0, 0, 0,
483 1, 1, 4
484 },
485 {
486 MESA_FORMAT_SARGB8,
487 "MESA_FORMAT_SARGB8",
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_SL8,
496 "MESA_FORMAT_SL8",
497 GL_LUMINANCE,
498 GL_UNSIGNED_NORMALIZED,
499 0, 0, 0, 0,
500 8, 0, 0, 0, 0,
501 1, 1, 1
502 },
503 {
504 MESA_FORMAT_SLA8,
505 "MESA_FORMAT_SLA8",
506 GL_LUMINANCE_ALPHA,
507 GL_UNSIGNED_NORMALIZED,
508 0, 0, 0, 8,
509 8, 0, 0, 0, 0,
510 1, 1, 2
511 },
512 {
513 MESA_FORMAT_SRGB_DXT1, /* Name */
514 "MESA_FORMAT_SRGB_DXT1", /* StrName */
515 GL_RGB, /* BaseFormat */
516 GL_UNSIGNED_NORMALIZED, /* DataType */
517 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
518 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
519 4, 4, 8 /* 8 bytes per 4x4 block */
520 },
521 {
522 MESA_FORMAT_SRGBA_DXT1,
523 "MESA_FORMAT_SRGBA_DXT1",
524 GL_RGBA,
525 GL_UNSIGNED_NORMALIZED,
526 4, 4, 4, 4,
527 0, 0, 0, 0, 0,
528 4, 4, 8 /* 8 bytes per 4x4 block */
529 },
530 {
531 MESA_FORMAT_SRGBA_DXT3,
532 "MESA_FORMAT_SRGBA_DXT3",
533 GL_RGBA,
534 GL_UNSIGNED_NORMALIZED,
535 4, 4, 4, 4,
536 0, 0, 0, 0, 0,
537 4, 4, 16 /* 16 bytes per 4x4 block */
538 },
539 {
540 MESA_FORMAT_SRGBA_DXT5,
541 "MESA_FORMAT_SRGBA_DXT5",
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 {
550 MESA_FORMAT_RGB_FXT1,
551 "MESA_FORMAT_RGB_FXT1",
552 GL_RGB,
553 GL_UNSIGNED_NORMALIZED,
554 4, 4, 4, 0, /* approx Red/Green/BlueBits */
555 0, 0, 0, 0, 0,
556 8, 4, 16 /* 16 bytes per 8x4 block */
557 },
558 {
559 MESA_FORMAT_RGBA_FXT1,
560 "MESA_FORMAT_RGBA_FXT1",
561 GL_RGBA,
562 GL_UNSIGNED_NORMALIZED,
563 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
564 0, 0, 0, 0, 0,
565 8, 4, 16 /* 16 bytes per 8x4 block */
566 },
567
568 {
569 MESA_FORMAT_RGB_DXT1, /* Name */
570 "MESA_FORMAT_RGB_DXT1", /* StrName */
571 GL_RGB, /* BaseFormat */
572 GL_UNSIGNED_NORMALIZED, /* DataType */
573 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
574 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
575 4, 4, 8 /* 8 bytes per 4x4 block */
576 },
577 {
578 MESA_FORMAT_RGBA_DXT1,
579 "MESA_FORMAT_RGBA_DXT1",
580 GL_RGBA,
581 GL_UNSIGNED_NORMALIZED,
582 4, 4, 4, 4,
583 0, 0, 0, 0, 0,
584 4, 4, 8 /* 8 bytes per 4x4 block */
585 },
586 {
587 MESA_FORMAT_RGBA_DXT3,
588 "MESA_FORMAT_RGBA_DXT3",
589 GL_RGBA,
590 GL_UNSIGNED_NORMALIZED,
591 4, 4, 4, 4,
592 0, 0, 0, 0, 0,
593 4, 4, 16 /* 16 bytes per 4x4 block */
594 },
595 {
596 MESA_FORMAT_RGBA_DXT5,
597 "MESA_FORMAT_RGBA_DXT5",
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_FLOAT32,
606 "MESA_FORMAT_RGBA_FLOAT32",
607 GL_RGBA,
608 GL_FLOAT,
609 32, 32, 32, 32,
610 0, 0, 0, 0, 0,
611 1, 1, 16
612 },
613 {
614 MESA_FORMAT_RGBA_FLOAT16,
615 "MESA_FORMAT_RGBA_FLOAT16",
616 GL_RGBA,
617 GL_FLOAT,
618 16, 16, 16, 16,
619 0, 0, 0, 0, 0,
620 1, 1, 8
621 },
622 {
623 MESA_FORMAT_RGB_FLOAT32,
624 "MESA_FORMAT_RGB_FLOAT32",
625 GL_RGB,
626 GL_FLOAT,
627 32, 32, 32, 0,
628 0, 0, 0, 0, 0,
629 1, 1, 12
630 },
631 {
632 MESA_FORMAT_RGB_FLOAT16,
633 "MESA_FORMAT_RGB_FLOAT16",
634 GL_RGB,
635 GL_FLOAT,
636 16, 16, 16, 0,
637 0, 0, 0, 0, 0,
638 1, 1, 6
639 },
640 {
641 MESA_FORMAT_ALPHA_FLOAT32,
642 "MESA_FORMAT_ALPHA_FLOAT32",
643 GL_ALPHA,
644 GL_FLOAT,
645 0, 0, 0, 32,
646 0, 0, 0, 0, 0,
647 1, 1, 4
648 },
649 {
650 MESA_FORMAT_ALPHA_FLOAT16,
651 "MESA_FORMAT_ALPHA_FLOAT16",
652 GL_ALPHA,
653 GL_FLOAT,
654 0, 0, 0, 16,
655 0, 0, 0, 0, 0,
656 1, 1, 2
657 },
658 {
659 MESA_FORMAT_LUMINANCE_FLOAT32,
660 "MESA_FORMAT_LUMINANCE_FLOAT32",
661 GL_ALPHA,
662 GL_FLOAT,
663 0, 0, 0, 0,
664 32, 0, 0, 0, 0,
665 1, 1, 4
666 },
667 {
668 MESA_FORMAT_LUMINANCE_FLOAT16,
669 "MESA_FORMAT_LUMINANCE_FLOAT16",
670 GL_ALPHA,
671 GL_FLOAT,
672 0, 0, 0, 0,
673 16, 0, 0, 0, 0,
674 1, 1, 2
675 },
676 {
677 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
678 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
679 GL_LUMINANCE_ALPHA,
680 GL_FLOAT,
681 0, 0, 0, 32,
682 32, 0, 0, 0, 0,
683 1, 1, 8
684 },
685 {
686 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
687 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
688 GL_LUMINANCE_ALPHA,
689 GL_FLOAT,
690 0, 0, 0, 16,
691 16, 0, 0, 0, 0,
692 1, 1, 4
693 },
694 {
695 MESA_FORMAT_INTENSITY_FLOAT32,
696 "MESA_FORMAT_INTENSITY_FLOAT32",
697 GL_INTENSITY,
698 GL_FLOAT,
699 0, 0, 0, 0,
700 0, 32, 0, 0, 0,
701 1, 1, 4
702 },
703 {
704 MESA_FORMAT_INTENSITY_FLOAT16,
705 "MESA_FORMAT_INTENSITY_FLOAT16",
706 GL_INTENSITY,
707 GL_FLOAT,
708 0, 0, 0, 0,
709 0, 16, 0, 0, 0,
710 1, 1, 2
711 },
712
713 /* unnormalized signed int formats */
714 {
715 MESA_FORMAT_RGBA_INT8,
716 "MESA_FORMAT_RGBA_INT8",
717 GL_RGBA,
718 GL_INT,
719 8, 8, 8, 8,
720 0, 0, 0, 0, 0,
721 1, 1, 4
722 },
723 {
724 MESA_FORMAT_RGBA_INT16,
725 "MESA_FORMAT_RGBA_INT16",
726 GL_RGBA,
727 GL_INT,
728 16, 16, 16, 16,
729 0, 0, 0, 0, 0,
730 1, 1, 8
731 },
732 {
733 MESA_FORMAT_RGBA_INT32,
734 "MESA_FORMAT_RGBA_INT32",
735 GL_RGBA,
736 GL_INT,
737 32, 32, 32, 32,
738 0, 0, 0, 0, 0,
739 1, 1, 16
740 },
741
742 /* unnormalized unsigned int formats */
743 {
744 MESA_FORMAT_RGBA_UINT8,
745 "MESA_FORMAT_RGBA_UINT8",
746 GL_RGBA,
747 GL_UNSIGNED_INT,
748 8, 8, 8, 8,
749 0, 0, 0, 0, 0,
750 1, 1, 4
751 },
752 {
753 MESA_FORMAT_RGBA_UINT16,
754 "MESA_FORMAT_RGBA_UINT16",
755 GL_RGBA,
756 GL_UNSIGNED_INT,
757 16, 16, 16, 16,
758 0, 0, 0, 0, 0,
759 1, 1, 8
760 },
761 {
762 MESA_FORMAT_RGBA_UINT32,
763 "MESA_FORMAT_RGBA_UINT32",
764 GL_RGBA,
765 GL_UNSIGNED_INT,
766 32, 32, 32, 32,
767 0, 0, 0, 0, 0,
768 1, 1, 16
769 },
770
771
772 {
773 MESA_FORMAT_DUDV8,
774 "MESA_FORMAT_DUDV8",
775 GL_DUDV_ATI,
776 GL_SIGNED_NORMALIZED,
777 0, 0, 0, 0,
778 0, 0, 0, 0, 0,
779 1, 1, 2
780 },
781
782 /* Signed 8 bits / channel */
783 {
784 MESA_FORMAT_SIGNED_R8, /* Name */
785 "MESA_FORMAT_SIGNED_R8", /* StrName */
786 GL_RGBA, /* BaseFormat */
787 GL_SIGNED_NORMALIZED, /* DataType */
788 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
789 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
790 1, 1, 1 /* BlockWidth/Height,Bytes */
791 },
792 {
793 MESA_FORMAT_SIGNED_RG88,
794 "MESA_FORMAT_SIGNED_RG88",
795 GL_RGBA,
796 GL_SIGNED_NORMALIZED,
797 8, 8, 0, 0,
798 0, 0, 0, 0, 0,
799 1, 1, 2
800 },
801 {
802 MESA_FORMAT_SIGNED_RGBX8888,
803 "MESA_FORMAT_SIGNED_RGBX8888",
804 GL_RGBA,
805 GL_SIGNED_NORMALIZED,
806 8, 8, 8, 0,
807 0, 0, 0, 0, 0,
808 1, 1, 4 /* 4 bpp, but no alpha */
809 },
810 {
811 MESA_FORMAT_SIGNED_RGBA8888,
812 "MESA_FORMAT_SIGNED_RGBA8888",
813 GL_RGBA,
814 GL_SIGNED_NORMALIZED,
815 8, 8, 8, 8,
816 0, 0, 0, 0, 0,
817 1, 1, 4
818 },
819 {
820 MESA_FORMAT_SIGNED_RGBA8888_REV,
821 "MESA_FORMAT_SIGNED_RGBA8888_REV",
822 GL_RGBA,
823 GL_SIGNED_NORMALIZED,
824 8, 8, 8, 8,
825 0, 0, 0, 0, 0,
826 1, 1, 4
827 },
828
829 /* Signed 16 bits / channel */
830 {
831 MESA_FORMAT_SIGNED_R_16,
832 "MESA_FORMAT_SIGNED_R_16",
833 GL_RGBA,
834 GL_SIGNED_NORMALIZED,
835 16, 0, 0, 0,
836 0, 0, 0, 0, 0,
837 1, 1, 2
838 },
839 {
840 MESA_FORMAT_SIGNED_RG_16,
841 "MESA_FORMAT_SIGNED_RG_16",
842 GL_RGBA,
843 GL_SIGNED_NORMALIZED,
844 16, 16, 0, 0,
845 0, 0, 0, 0, 0,
846 1, 1, 4
847 },
848 {
849 MESA_FORMAT_SIGNED_RGB_16,
850 "MESA_FORMAT_SIGNED_RGB_16",
851 GL_RGBA,
852 GL_SIGNED_NORMALIZED,
853 16, 16, 16, 0,
854 0, 0, 0, 0, 0,
855 1, 1, 6
856 },
857 {
858 MESA_FORMAT_SIGNED_RGBA_16,
859 "MESA_FORMAT_SIGNED_RGBA_16",
860 GL_RGBA,
861 GL_SIGNED_NORMALIZED,
862 16, 16, 16, 16,
863 0, 0, 0, 0, 0,
864 1, 1, 8
865 },
866 {
867 MESA_FORMAT_RGBA_16,
868 "MESA_FORMAT_RGBA_16",
869 GL_RGBA,
870 GL_UNSIGNED_NORMALIZED,
871 16, 16, 16, 16,
872 0, 0, 0, 0, 0,
873 1, 1, 8
874 }
875 };
876
877
878
879 static const struct gl_format_info *
880 _mesa_get_format_info(gl_format format)
881 {
882 const struct gl_format_info *info = &format_info[format];
883 assert(info->Name == format);
884 return info;
885 }
886
887
888 /** Return string name of format (for debugging) */
889 const char *
890 _mesa_get_format_name(gl_format format)
891 {
892 const struct gl_format_info *info = _mesa_get_format_info(format);
893 return info->StrName;
894 }
895
896
897
898 /**
899 * Return bytes needed to store a block of pixels in the given format.
900 * Normally, a block is 1x1 (a single pixel). But for compressed formats
901 * a block may be 4x4 or 8x4, etc.
902 */
903 GLuint
904 _mesa_get_format_bytes(gl_format format)
905 {
906 const struct gl_format_info *info = _mesa_get_format_info(format);
907 ASSERT(info->BytesPerBlock);
908 return info->BytesPerBlock;
909 }
910
911
912 /**
913 * Return bits per component for the given format.
914 * \param format one of MESA_FORMAT_x
915 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
916 */
917 GLint
918 _mesa_get_format_bits(gl_format format, GLenum pname)
919 {
920 const struct gl_format_info *info = _mesa_get_format_info(format);
921
922 switch (pname) {
923 case GL_RED_BITS:
924 case GL_TEXTURE_RED_SIZE:
925 case GL_RENDERBUFFER_RED_SIZE_EXT:
926 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
927 return info->RedBits;
928 case GL_GREEN_BITS:
929 case GL_TEXTURE_GREEN_SIZE:
930 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
931 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
932 return info->GreenBits;
933 case GL_BLUE_BITS:
934 case GL_TEXTURE_BLUE_SIZE:
935 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
936 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
937 return info->BlueBits;
938 case GL_ALPHA_BITS:
939 case GL_TEXTURE_ALPHA_SIZE:
940 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
941 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
942 return info->AlphaBits;
943 case GL_TEXTURE_INTENSITY_SIZE:
944 return info->IntensityBits;
945 case GL_TEXTURE_LUMINANCE_SIZE:
946 return info->LuminanceBits;
947 case GL_INDEX_BITS:
948 case GL_TEXTURE_INDEX_SIZE_EXT:
949 return info->IndexBits;
950 case GL_DEPTH_BITS:
951 case GL_TEXTURE_DEPTH_SIZE_ARB:
952 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
953 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
954 return info->DepthBits;
955 case GL_STENCIL_BITS:
956 case GL_TEXTURE_STENCIL_SIZE_EXT:
957 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
958 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
959 return info->StencilBits;
960 default:
961 _mesa_problem(NULL, "bad pname in _mesa_get_format_bits()");
962 return 0;
963 }
964 }
965
966
967 /**
968 * Return the data type (or more specifically, the data representation)
969 * for the given format.
970 * The return value will be one of:
971 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
972 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
973 * GL_UNSIGNED_INT = an ordinary unsigned integer
974 * GL_INT = an ordinary signed integer
975 * GL_FLOAT = an ordinary float
976 */
977 GLenum
978 _mesa_get_format_datatype(gl_format format)
979 {
980 const struct gl_format_info *info = _mesa_get_format_info(format);
981 return info->DataType;
982 }
983
984
985 /**
986 * Return the basic format for the given type. The result will be
987 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
988 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
989 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
990 */
991 GLenum
992 _mesa_get_format_base_format(gl_format format)
993 {
994 const struct gl_format_info *info = _mesa_get_format_info(format);
995 return info->BaseFormat;
996 }
997
998
999 /**
1000 * Return the block size (in pixels) for the given format. Normally
1001 * the block size is 1x1. But compressed formats will have block sizes
1002 * of 4x4 or 8x4 pixels, etc.
1003 * \param bw returns block width in pixels
1004 * \param bh returns block height in pixels
1005 */
1006 void
1007 _mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
1008 {
1009 const struct gl_format_info *info = _mesa_get_format_info(format);
1010 *bw = info->BlockWidth;
1011 *bh = info->BlockHeight;
1012 }
1013
1014
1015 /** Is the given format a compressed format? */
1016 GLboolean
1017 _mesa_is_format_compressed(gl_format format)
1018 {
1019 const struct gl_format_info *info = _mesa_get_format_info(format);
1020 return info->BlockWidth > 1 || info->BlockHeight > 1;
1021 }
1022
1023
1024 /**
1025 * Determine if the given format represents a packed depth/stencil buffer.
1026 */
1027 GLboolean
1028 _mesa_is_format_packed_depth_stencil(gl_format format)
1029 {
1030 const struct gl_format_info *info = _mesa_get_format_info(format);
1031
1032 return info->BaseFormat == GL_DEPTH_STENCIL;
1033 }
1034
1035
1036 /**
1037 * Is the given format a signed/unsigned integer color format?
1038 */
1039 GLboolean
1040 _mesa_is_format_integer_color(gl_format format)
1041 {
1042 const struct gl_format_info *info = _mesa_get_format_info(format);
1043 return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) &&
1044 info->BaseFormat != GL_DEPTH_COMPONENT &&
1045 info->BaseFormat != GL_DEPTH_STENCIL &&
1046 info->BaseFormat != GL_STENCIL_INDEX;
1047 }
1048
1049
1050 /**
1051 * Return color encoding for given format.
1052 * \return GL_LINEAR or GL_SRGB
1053 */
1054 GLenum
1055 _mesa_get_format_color_encoding(gl_format format)
1056 {
1057 /* XXX this info should be encoded in gl_format_info */
1058 switch (format) {
1059 case MESA_FORMAT_SRGB8:
1060 case MESA_FORMAT_SRGBA8:
1061 case MESA_FORMAT_SARGB8:
1062 case MESA_FORMAT_SL8:
1063 case MESA_FORMAT_SLA8:
1064 case MESA_FORMAT_SRGB_DXT1:
1065 case MESA_FORMAT_SRGBA_DXT1:
1066 case MESA_FORMAT_SRGBA_DXT3:
1067 case MESA_FORMAT_SRGBA_DXT5:
1068 return GL_SRGB;
1069 default:
1070 return GL_LINEAR;
1071 }
1072 }
1073
1074
1075 /**
1076 * Return number of bytes needed to store an image of the given size
1077 * in the given format.
1078 */
1079 GLuint
1080 _mesa_format_image_size(gl_format format, GLsizei width,
1081 GLsizei height, GLsizei depth)
1082 {
1083 const struct gl_format_info *info = _mesa_get_format_info(format);
1084 /* Strictly speaking, a conditional isn't needed here */
1085 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1086 /* compressed format (2D only for now) */
1087 const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
1088 const GLuint wblocks = (width + bw - 1) / bw;
1089 const GLuint hblocks = (height + bh - 1) / bh;
1090 const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
1091 assert(depth == 1);
1092 return sz;
1093 }
1094 else {
1095 /* non-compressed */
1096 const GLuint sz = width * height * depth * info->BytesPerBlock;
1097 return sz;
1098 }
1099 }
1100
1101
1102 /**
1103 * Same as _mesa_format_image_size() but returns a 64-bit value to
1104 * accomodate very large textures.
1105 */
1106 uint64_t
1107 _mesa_format_image_size64(gl_format format, GLsizei width,
1108 GLsizei height, GLsizei depth)
1109 {
1110 const struct gl_format_info *info = _mesa_get_format_info(format);
1111 /* Strictly speaking, a conditional isn't needed here */
1112 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1113 /* compressed format (2D only for now) */
1114 const uint64_t bw = info->BlockWidth, bh = info->BlockHeight;
1115 const uint64_t wblocks = (width + bw - 1) / bw;
1116 const uint64_t hblocks = (height + bh - 1) / bh;
1117 const uint64_t sz = wblocks * hblocks * info->BytesPerBlock;
1118 assert(depth == 1);
1119 return sz;
1120 }
1121 else {
1122 /* non-compressed */
1123 const uint64_t sz = ((uint64_t) width *
1124 (uint64_t) height *
1125 (uint64_t) depth *
1126 info->BytesPerBlock);
1127 return sz;
1128 }
1129 }
1130
1131
1132
1133 GLint
1134 _mesa_format_row_stride(gl_format format, GLsizei width)
1135 {
1136 const struct gl_format_info *info = _mesa_get_format_info(format);
1137 /* Strictly speaking, a conditional isn't needed here */
1138 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1139 /* compressed format */
1140 const GLuint bw = info->BlockWidth;
1141 const GLuint wblocks = (width + bw - 1) / bw;
1142 const GLint stride = wblocks * info->BytesPerBlock;
1143 return stride;
1144 }
1145 else {
1146 const GLint stride = width * info->BytesPerBlock;
1147 return stride;
1148 }
1149 }
1150
1151
1152
1153 /**
1154 * Do sanity checking of the format info table.
1155 */
1156 void
1157 _mesa_test_formats(void)
1158 {
1159 GLuint i;
1160
1161 assert(Elements(format_info) == MESA_FORMAT_COUNT);
1162
1163 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
1164 const struct gl_format_info *info = _mesa_get_format_info(i);
1165 assert(info);
1166
1167 assert(info->Name == i);
1168
1169 if (info->Name == MESA_FORMAT_NONE)
1170 continue;
1171
1172 if (info->BlockWidth == 1 && info->BlockHeight == 1) {
1173 if (info->RedBits > 0) {
1174 GLuint t = info->RedBits + info->GreenBits
1175 + info->BlueBits + info->AlphaBits;
1176 assert(t / 8 == info->BytesPerBlock);
1177 (void) t;
1178 }
1179 }
1180
1181 assert(info->DataType == GL_UNSIGNED_NORMALIZED ||
1182 info->DataType == GL_SIGNED_NORMALIZED ||
1183 info->DataType == GL_UNSIGNED_INT ||
1184 info->DataType == GL_FLOAT);
1185
1186 if (info->BaseFormat == GL_RGB) {
1187 assert(info->RedBits > 0);
1188 assert(info->GreenBits > 0);
1189 assert(info->BlueBits > 0);
1190 assert(info->AlphaBits == 0);
1191 assert(info->LuminanceBits == 0);
1192 assert(info->IntensityBits == 0);
1193 }
1194 else if (info->BaseFormat == GL_RGBA) {
1195 assert(info->RedBits > 0);
1196 assert(info->GreenBits > 0);
1197 assert(info->BlueBits > 0);
1198 assert(info->AlphaBits > 0);
1199 assert(info->LuminanceBits == 0);
1200 assert(info->IntensityBits == 0);
1201 }
1202 else if (info->BaseFormat == GL_RG) {
1203 assert(info->RedBits > 0);
1204 assert(info->GreenBits > 0);
1205 assert(info->BlueBits == 0);
1206 assert(info->AlphaBits == 0);
1207 assert(info->LuminanceBits == 0);
1208 assert(info->IntensityBits == 0);
1209 }
1210 else if (info->BaseFormat == GL_RED) {
1211 assert(info->RedBits > 0);
1212 assert(info->GreenBits == 0);
1213 assert(info->BlueBits == 0);
1214 assert(info->AlphaBits == 0);
1215 assert(info->LuminanceBits == 0);
1216 assert(info->IntensityBits == 0);
1217 }
1218 else if (info->BaseFormat == GL_LUMINANCE) {
1219 assert(info->RedBits == 0);
1220 assert(info->GreenBits == 0);
1221 assert(info->BlueBits == 0);
1222 assert(info->AlphaBits == 0);
1223 assert(info->LuminanceBits > 0);
1224 assert(info->IntensityBits == 0);
1225 }
1226 else if (info->BaseFormat == GL_INTENSITY) {
1227 assert(info->RedBits == 0);
1228 assert(info->GreenBits == 0);
1229 assert(info->BlueBits == 0);
1230 assert(info->AlphaBits == 0);
1231 assert(info->LuminanceBits == 0);
1232 assert(info->IntensityBits > 0);
1233 }
1234
1235 }
1236 }
1237
1238
1239
1240 /**
1241 * Return datatype and number of components per texel for the given gl_format.
1242 * Only used for mipmap generation code.
1243 */
1244 void
1245 _mesa_format_to_type_and_comps(gl_format format,
1246 GLenum *datatype, GLuint *comps)
1247 {
1248 switch (format) {
1249 case MESA_FORMAT_RGBA8888:
1250 case MESA_FORMAT_RGBA8888_REV:
1251 case MESA_FORMAT_ARGB8888:
1252 case MESA_FORMAT_ARGB8888_REV:
1253 case MESA_FORMAT_XRGB8888:
1254 case MESA_FORMAT_XRGB8888_REV:
1255 *datatype = GL_UNSIGNED_BYTE;
1256 *comps = 4;
1257 return;
1258 case MESA_FORMAT_RGB888:
1259 case MESA_FORMAT_BGR888:
1260 *datatype = GL_UNSIGNED_BYTE;
1261 *comps = 3;
1262 return;
1263 case MESA_FORMAT_RGB565:
1264 case MESA_FORMAT_RGB565_REV:
1265 *datatype = GL_UNSIGNED_SHORT_5_6_5;
1266 *comps = 3;
1267 return;
1268
1269 case MESA_FORMAT_ARGB4444:
1270 case MESA_FORMAT_ARGB4444_REV:
1271 *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
1272 *comps = 4;
1273 return;
1274
1275 case MESA_FORMAT_ARGB1555:
1276 case MESA_FORMAT_ARGB1555_REV:
1277 *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1278 *comps = 4;
1279 return;
1280
1281 case MESA_FORMAT_ARGB2101010:
1282 *datatype = GL_UNSIGNED_INT_2_10_10_10_REV;
1283 *comps = 4;
1284 return;
1285
1286 case MESA_FORMAT_RGBA5551:
1287 *datatype = GL_UNSIGNED_SHORT_5_5_5_1;
1288 *comps = 4;
1289 return;
1290
1291 case MESA_FORMAT_AL44: /* XXX this isn't plain GL_UNSIGNED_BYTE */
1292 case MESA_FORMAT_AL88:
1293 case MESA_FORMAT_AL88_REV:
1294 case MESA_FORMAT_RG88:
1295 case MESA_FORMAT_RG88_REV:
1296 *datatype = GL_UNSIGNED_BYTE;
1297 *comps = 2;
1298 return;
1299
1300 case MESA_FORMAT_AL1616:
1301 case MESA_FORMAT_AL1616_REV:
1302 case MESA_FORMAT_RG1616:
1303 case MESA_FORMAT_RG1616_REV:
1304 *datatype = GL_UNSIGNED_SHORT;
1305 *comps = 2;
1306 return;
1307
1308 case MESA_FORMAT_R16:
1309 case MESA_FORMAT_A16:
1310 *datatype = GL_UNSIGNED_SHORT;
1311 *comps = 1;
1312 return;
1313
1314 case MESA_FORMAT_RGB332:
1315 *datatype = GL_UNSIGNED_BYTE_3_3_2;
1316 *comps = 3;
1317 return;
1318
1319 case MESA_FORMAT_A8:
1320 case MESA_FORMAT_L8:
1321 case MESA_FORMAT_I8:
1322 case MESA_FORMAT_CI8:
1323 case MESA_FORMAT_R8:
1324 case MESA_FORMAT_S8:
1325 *datatype = GL_UNSIGNED_BYTE;
1326 *comps = 1;
1327 return;
1328
1329 case MESA_FORMAT_YCBCR:
1330 case MESA_FORMAT_YCBCR_REV:
1331 *datatype = GL_UNSIGNED_SHORT;
1332 *comps = 2;
1333 return;
1334
1335 case MESA_FORMAT_Z24_S8:
1336 *datatype = GL_UNSIGNED_INT;
1337 *comps = 1; /* XXX OK? */
1338 return;
1339
1340 case MESA_FORMAT_S8_Z24:
1341 *datatype = GL_UNSIGNED_INT;
1342 *comps = 1; /* XXX OK? */
1343 return;
1344
1345 case MESA_FORMAT_Z16:
1346 *datatype = GL_UNSIGNED_SHORT;
1347 *comps = 1;
1348 return;
1349
1350 case MESA_FORMAT_X8_Z24:
1351 *datatype = GL_UNSIGNED_INT;
1352 *comps = 1;
1353 return;
1354
1355 case MESA_FORMAT_Z24_X8:
1356 *datatype = GL_UNSIGNED_INT;
1357 *comps = 1;
1358 return;
1359
1360 case MESA_FORMAT_Z32:
1361 *datatype = GL_UNSIGNED_INT;
1362 *comps = 1;
1363 return;
1364
1365 case MESA_FORMAT_DUDV8:
1366 *datatype = GL_BYTE;
1367 *comps = 2;
1368 return;
1369
1370 case MESA_FORMAT_SIGNED_R8:
1371 *datatype = GL_BYTE;
1372 *comps = 1;
1373 return;
1374 case MESA_FORMAT_SIGNED_RG88:
1375 *datatype = GL_BYTE;
1376 *comps = 2;
1377 return;
1378 case MESA_FORMAT_SIGNED_RGBA8888:
1379 case MESA_FORMAT_SIGNED_RGBA8888_REV:
1380 case MESA_FORMAT_SIGNED_RGBX8888:
1381 *datatype = GL_BYTE;
1382 *comps = 4;
1383 return;
1384
1385 case MESA_FORMAT_RGBA_16:
1386 *datatype = GL_UNSIGNED_SHORT;
1387 *comps = 4;
1388 return;
1389
1390 case MESA_FORMAT_SIGNED_R_16:
1391 *datatype = GL_SHORT;
1392 *comps = 1;
1393 return;
1394 case MESA_FORMAT_SIGNED_RG_16:
1395 *datatype = GL_SHORT;
1396 *comps = 2;
1397 return;
1398 case MESA_FORMAT_SIGNED_RGB_16:
1399 *datatype = GL_SHORT;
1400 *comps = 3;
1401 return;
1402 case MESA_FORMAT_SIGNED_RGBA_16:
1403 *datatype = GL_SHORT;
1404 *comps = 4;
1405 return;
1406
1407 #if FEATURE_EXT_texture_sRGB
1408 case MESA_FORMAT_SRGB8:
1409 *datatype = GL_UNSIGNED_BYTE;
1410 *comps = 3;
1411 return;
1412 case MESA_FORMAT_SRGBA8:
1413 case MESA_FORMAT_SARGB8:
1414 *datatype = GL_UNSIGNED_BYTE;
1415 *comps = 4;
1416 return;
1417 case MESA_FORMAT_SL8:
1418 *datatype = GL_UNSIGNED_BYTE;
1419 *comps = 1;
1420 return;
1421 case MESA_FORMAT_SLA8:
1422 *datatype = GL_UNSIGNED_BYTE;
1423 *comps = 2;
1424 return;
1425 #endif
1426
1427 #if FEATURE_texture_fxt1
1428 case MESA_FORMAT_RGB_FXT1:
1429 case MESA_FORMAT_RGBA_FXT1:
1430 #endif
1431 #if FEATURE_texture_s3tc
1432 case MESA_FORMAT_RGB_DXT1:
1433 case MESA_FORMAT_RGBA_DXT1:
1434 case MESA_FORMAT_RGBA_DXT3:
1435 case MESA_FORMAT_RGBA_DXT5:
1436 #if FEATURE_EXT_texture_sRGB
1437 case MESA_FORMAT_SRGB_DXT1:
1438 case MESA_FORMAT_SRGBA_DXT1:
1439 case MESA_FORMAT_SRGBA_DXT3:
1440 case MESA_FORMAT_SRGBA_DXT5:
1441 #endif
1442 #endif
1443 /* XXX generate error instead? */
1444 *datatype = GL_UNSIGNED_BYTE;
1445 *comps = 0;
1446 return;
1447
1448 case MESA_FORMAT_RGBA_FLOAT32:
1449 *datatype = GL_FLOAT;
1450 *comps = 4;
1451 return;
1452 case MESA_FORMAT_RGBA_FLOAT16:
1453 *datatype = GL_HALF_FLOAT_ARB;
1454 *comps = 4;
1455 return;
1456 case MESA_FORMAT_RGB_FLOAT32:
1457 *datatype = GL_FLOAT;
1458 *comps = 3;
1459 return;
1460 case MESA_FORMAT_RGB_FLOAT16:
1461 *datatype = GL_HALF_FLOAT_ARB;
1462 *comps = 3;
1463 return;
1464 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
1465 *datatype = GL_FLOAT;
1466 *comps = 2;
1467 return;
1468 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
1469 *datatype = GL_HALF_FLOAT_ARB;
1470 *comps = 2;
1471 return;
1472 case MESA_FORMAT_ALPHA_FLOAT32:
1473 case MESA_FORMAT_LUMINANCE_FLOAT32:
1474 case MESA_FORMAT_INTENSITY_FLOAT32:
1475 *datatype = GL_FLOAT;
1476 *comps = 1;
1477 return;
1478 case MESA_FORMAT_ALPHA_FLOAT16:
1479 case MESA_FORMAT_LUMINANCE_FLOAT16:
1480 case MESA_FORMAT_INTENSITY_FLOAT16:
1481 *datatype = GL_HALF_FLOAT_ARB;
1482 *comps = 1;
1483 return;
1484
1485 case MESA_FORMAT_RGBA_INT8:
1486 *datatype = GL_BYTE;
1487 *comps = 4;
1488 return;
1489 case MESA_FORMAT_RGBA_INT16:
1490 *datatype = GL_SHORT;
1491 *comps = 4;
1492 return;
1493 case MESA_FORMAT_RGBA_INT32:
1494 *datatype = GL_INT;
1495 *comps = 4;
1496 return;
1497
1498 /**
1499 * \name Non-normalized unsigned integer formats.
1500 */
1501 case MESA_FORMAT_RGBA_UINT8:
1502 *datatype = GL_UNSIGNED_BYTE;
1503 *comps = 4;
1504 return;
1505 case MESA_FORMAT_RGBA_UINT16:
1506 *datatype = GL_UNSIGNED_SHORT;
1507 *comps = 4;
1508 return;
1509 case MESA_FORMAT_RGBA_UINT32:
1510 *datatype = GL_UNSIGNED_INT;
1511 *comps = 4;
1512 return;
1513
1514 case MESA_FORMAT_NONE:
1515 case MESA_FORMAT_COUNT:
1516 /* For debug builds, warn if any formats are not handled */
1517 #ifndef DEBUG
1518 default:
1519 #endif
1520 _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps",
1521 _mesa_get_format_name(format));
1522 *datatype = 0;
1523 *comps = 1;
1524 }
1525 }