mesa: Identify packed depth/stencil buffers using the Format field.
[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
30
31 /**
32 * Information about texture formats.
33 */
34 struct gl_format_info
35 {
36 gl_format Name;
37
38 /** text name for debugging */
39 const char *StrName;
40
41 /**
42 * Base format is one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE,
43 * GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX,
44 * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
45 */
46 GLenum BaseFormat;
47
48 /**
49 * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALED,
50 * GL_UNSIGNED_INT, GL_INT, GL_FLOAT.
51 */
52 GLenum DataType;
53
54 GLubyte RedBits;
55 GLubyte GreenBits;
56 GLubyte BlueBits;
57 GLubyte AlphaBits;
58 GLubyte LuminanceBits;
59 GLubyte IntensityBits;
60 GLubyte IndexBits;
61 GLubyte DepthBits;
62 GLubyte StencilBits;
63
64 /**
65 * To describe compressed formats. If not compressed, Width=Height=1.
66 */
67 GLubyte BlockWidth, BlockHeight;
68 GLubyte BytesPerBlock;
69 };
70
71
72 /**
73 * Info about each format.
74 * These must be in the same order as the MESA_FORMAT_* enums so that
75 * we can do lookups without searching.
76 */
77 static struct gl_format_info format_info[MESA_FORMAT_COUNT] =
78 {
79 {
80 MESA_FORMAT_NONE, /* Name */
81 "MESA_FORMAT_NONE", /* StrName */
82 GL_NONE, /* BaseFormat */
83 GL_NONE, /* DataType */
84 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
85 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
86 0, 0, 0 /* BlockWidth/Height,Bytes */
87 },
88 {
89 MESA_FORMAT_RGBA8888, /* Name */
90 "MESA_FORMAT_RGBA8888", /* StrName */
91 GL_RGBA, /* BaseFormat */
92 GL_UNSIGNED_NORMALIZED, /* DataType */
93 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
94 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
95 1, 1, 4 /* BlockWidth/Height,Bytes */
96 },
97 {
98 MESA_FORMAT_RGBA8888_REV, /* Name */
99 "MESA_FORMAT_RGBA8888_REV", /* StrName */
100 GL_RGBA, /* BaseFormat */
101 GL_UNSIGNED_NORMALIZED, /* DataType */
102 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
103 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
104 1, 1, 4 /* BlockWidth/Height,Bytes */
105 },
106 {
107 MESA_FORMAT_ARGB8888, /* Name */
108 "MESA_FORMAT_ARGB8888", /* StrName */
109 GL_RGBA, /* BaseFormat */
110 GL_UNSIGNED_NORMALIZED, /* DataType */
111 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
112 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
113 1, 1, 4 /* BlockWidth/Height,Bytes */
114 },
115 {
116 MESA_FORMAT_ARGB8888_REV, /* Name */
117 "MESA_FORMAT_ARGB8888_REV", /* StrName */
118 GL_RGBA, /* BaseFormat */
119 GL_UNSIGNED_NORMALIZED, /* DataType */
120 8, 8, 8, 8, /* Red/Green/Blue/AlphaBits */
121 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
122 1, 1, 4 /* BlockWidth/Height,Bytes */
123 },
124 {
125 MESA_FORMAT_XRGB8888, /* Name */
126 "MESA_FORMAT_XRGB8888", /* StrName */
127 GL_RGB, /* BaseFormat */
128 GL_UNSIGNED_NORMALIZED, /* DataType */
129 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
130 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
131 1, 1, 4 /* BlockWidth/Height,Bytes */
132 },
133 {
134 MESA_FORMAT_XRGB8888_REV, /* Name */
135 "MESA_FORMAT_XRGB8888_REV", /* StrName */
136 GL_RGB, /* BaseFormat */
137 GL_UNSIGNED_NORMALIZED, /* DataType */
138 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
139 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
140 1, 1, 4 /* BlockWidth/Height,Bytes */
141 },
142 {
143 MESA_FORMAT_RGB888, /* Name */
144 "MESA_FORMAT_RGB888", /* StrName */
145 GL_RGB, /* BaseFormat */
146 GL_UNSIGNED_NORMALIZED, /* DataType */
147 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
148 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
149 1, 1, 3 /* BlockWidth/Height,Bytes */
150 },
151 {
152 MESA_FORMAT_BGR888, /* Name */
153 "MESA_FORMAT_BGR888", /* StrName */
154 GL_RGB, /* BaseFormat */
155 GL_UNSIGNED_NORMALIZED, /* DataType */
156 8, 8, 8, 0, /* Red/Green/Blue/AlphaBits */
157 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
158 1, 1, 3 /* BlockWidth/Height,Bytes */
159 },
160 {
161 MESA_FORMAT_RGB565, /* Name */
162 "MESA_FORMAT_RGB565", /* StrName */
163 GL_RGB, /* BaseFormat */
164 GL_UNSIGNED_NORMALIZED, /* DataType */
165 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
166 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
167 1, 1, 2 /* BlockWidth/Height,Bytes */
168 },
169 {
170 MESA_FORMAT_RGB565_REV, /* Name */
171 "MESA_FORMAT_RGB565_REV", /* StrName */
172 GL_RGB, /* BaseFormat */
173 GL_UNSIGNED_NORMALIZED, /* DataType */
174 5, 6, 5, 0, /* Red/Green/Blue/AlphaBits */
175 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
176 1, 1, 2 /* BlockWidth/Height,Bytes */
177 },
178 {
179 MESA_FORMAT_ARGB4444, /* Name */
180 "MESA_FORMAT_ARGB4444", /* StrName */
181 GL_RGBA, /* BaseFormat */
182 GL_UNSIGNED_NORMALIZED, /* DataType */
183 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
184 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
185 1, 1, 2 /* BlockWidth/Height,Bytes */
186 },
187 {
188 MESA_FORMAT_ARGB4444_REV, /* Name */
189 "MESA_FORMAT_ARGB4444_REV", /* StrName */
190 GL_RGBA, /* BaseFormat */
191 GL_UNSIGNED_NORMALIZED, /* DataType */
192 4, 4, 4, 4, /* Red/Green/Blue/AlphaBits */
193 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
194 1, 1, 2 /* BlockWidth/Height,Bytes */
195 },
196 {
197 MESA_FORMAT_RGBA5551, /* Name */
198 "MESA_FORMAT_RGBA5551", /* StrName */
199 GL_RGBA, /* BaseFormat */
200 GL_UNSIGNED_NORMALIZED, /* DataType */
201 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
202 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
203 1, 1, 2 /* BlockWidth/Height,Bytes */
204 },
205 {
206 MESA_FORMAT_ARGB1555, /* Name */
207 "MESA_FORMAT_ARGB1555", /* StrName */
208 GL_RGBA, /* BaseFormat */
209 GL_UNSIGNED_NORMALIZED, /* DataType */
210 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
211 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
212 1, 1, 2 /* BlockWidth/Height,Bytes */
213 },
214 {
215 MESA_FORMAT_ARGB1555_REV, /* Name */
216 "MESA_FORMAT_ARGB1555_REV", /* StrName */
217 GL_RGBA, /* BaseFormat */
218 GL_UNSIGNED_NORMALIZED, /* DataType */
219 5, 5, 5, 1, /* Red/Green/Blue/AlphaBits */
220 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
221 1, 1, 2 /* BlockWidth/Height,Bytes */
222 },
223 {
224 MESA_FORMAT_AL88, /* Name */
225 "MESA_FORMAT_AL88", /* StrName */
226 GL_LUMINANCE_ALPHA, /* BaseFormat */
227 GL_UNSIGNED_NORMALIZED, /* DataType */
228 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
229 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
230 1, 1, 2 /* BlockWidth/Height,Bytes */
231 },
232 {
233 MESA_FORMAT_AL88_REV, /* Name */
234 "MESA_FORMAT_AL88_REV", /* StrName */
235 GL_LUMINANCE_ALPHA, /* BaseFormat */
236 GL_UNSIGNED_NORMALIZED, /* DataType */
237 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
238 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
239 1, 1, 2 /* BlockWidth/Height,Bytes */
240 },
241 {
242 MESA_FORMAT_AL1616, /* Name */
243 "MESA_FORMAT_AL1616", /* StrName */
244 GL_LUMINANCE_ALPHA, /* BaseFormat */
245 GL_UNSIGNED_NORMALIZED, /* DataType */
246 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
247 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
248 1, 1, 4 /* BlockWidth/Height,Bytes */
249 },
250 {
251 MESA_FORMAT_AL1616_REV, /* Name */
252 "MESA_FORMAT_AL1616_REV", /* StrName */
253 GL_LUMINANCE_ALPHA, /* BaseFormat */
254 GL_UNSIGNED_NORMALIZED, /* DataType */
255 0, 0, 0, 16, /* Red/Green/Blue/AlphaBits */
256 16, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
257 1, 1, 4 /* BlockWidth/Height,Bytes */
258 },
259 {
260 MESA_FORMAT_RGB332, /* Name */
261 "MESA_FORMAT_RGB332", /* StrName */
262 GL_RGB, /* BaseFormat */
263 GL_UNSIGNED_NORMALIZED, /* DataType */
264 3, 3, 2, 0, /* Red/Green/Blue/AlphaBits */
265 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
266 1, 1, 1 /* BlockWidth/Height,Bytes */
267 },
268 {
269 MESA_FORMAT_A8, /* Name */
270 "MESA_FORMAT_A8", /* StrName */
271 GL_ALPHA, /* BaseFormat */
272 GL_UNSIGNED_NORMALIZED, /* DataType */
273 0, 0, 0, 8, /* Red/Green/Blue/AlphaBits */
274 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
275 1, 1, 1 /* BlockWidth/Height,Bytes */
276 },
277 {
278 MESA_FORMAT_L8, /* Name */
279 "MESA_FORMAT_L8", /* StrName */
280 GL_LUMINANCE, /* BaseFormat */
281 GL_UNSIGNED_NORMALIZED, /* DataType */
282 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
283 8, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
284 1, 1, 1 /* BlockWidth/Height,Bytes */
285 },
286 {
287 MESA_FORMAT_I8, /* Name */
288 "MESA_FORMAT_I8", /* StrName */
289 GL_INTENSITY, /* BaseFormat */
290 GL_UNSIGNED_NORMALIZED, /* DataType */
291 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
292 0, 8, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
293 1, 1, 1 /* BlockWidth/Height,Bytes */
294 },
295 {
296 MESA_FORMAT_CI8, /* Name */
297 "MESA_FORMAT_CI8", /* StrName */
298 GL_COLOR_INDEX, /* BaseFormat */
299 GL_UNSIGNED_INT, /* DataType */
300 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
301 0, 0, 8, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
302 1, 1, 1 /* BlockWidth/Height,Bytes */
303 },
304 {
305 MESA_FORMAT_YCBCR, /* Name */
306 "MESA_FORMAT_YCBCR", /* StrName */
307 GL_YCBCR_MESA, /* BaseFormat */
308 GL_UNSIGNED_NORMALIZED, /* DataType */
309 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
310 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
311 1, 1, 2 /* BlockWidth/Height,Bytes */
312 },
313 {
314 MESA_FORMAT_YCBCR_REV, /* Name */
315 "MESA_FORMAT_YCBCR_REV", /* StrName */
316 GL_YCBCR_MESA, /* BaseFormat */
317 GL_UNSIGNED_NORMALIZED, /* DataType */
318 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
319 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
320 1, 1, 2 /* BlockWidth/Height,Bytes */
321 },
322 {
323 MESA_FORMAT_Z24_S8, /* Name */
324 "MESA_FORMAT_Z24_S8", /* StrName */
325 GL_DEPTH_STENCIL, /* BaseFormat */
326 GL_UNSIGNED_INT, /* DataType */
327 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
328 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
329 1, 1, 4 /* BlockWidth/Height,Bytes */
330 },
331 {
332 MESA_FORMAT_S8_Z24, /* Name */
333 "MESA_FORMAT_S8_Z24", /* StrName */
334 GL_DEPTH_STENCIL, /* BaseFormat */
335 GL_UNSIGNED_INT, /* DataType */
336 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
337 0, 0, 0, 24, 8, /* Lum/Int/Index/Depth/StencilBits */
338 1, 1, 4 /* BlockWidth/Height,Bytes */
339 },
340 {
341 MESA_FORMAT_Z16, /* Name */
342 "MESA_FORMAT_Z16", /* StrName */
343 GL_DEPTH_COMPONENT, /* BaseFormat */
344 GL_UNSIGNED_INT, /* DataType */
345 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
346 0, 0, 0, 16, 0, /* Lum/Int/Index/Depth/StencilBits */
347 1, 1, 2 /* BlockWidth/Height,Bytes */
348 },
349 {
350 MESA_FORMAT_X8_Z24, /* Name */
351 "MESA_FORMAT_X8_Z24", /* StrName */
352 GL_DEPTH_COMPONENT, /* BaseFormat */
353 GL_UNSIGNED_INT, /* DataType */
354 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
355 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
356 1, 1, 4 /* BlockWidth/Height,Bytes */
357 },
358 {
359 MESA_FORMAT_Z24_X8, /* Name */
360 "MESA_FORMAT_Z24_X8", /* StrName */
361 GL_DEPTH_COMPONENT, /* BaseFormat */
362 GL_UNSIGNED_INT, /* DataType */
363 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
364 0, 0, 0, 24, 0, /* Lum/Int/Index/Depth/StencilBits */
365 1, 1, 4 /* BlockWidth/Height,Bytes */
366 },
367 {
368 MESA_FORMAT_Z32, /* Name */
369 "MESA_FORMAT_Z32", /* StrName */
370 GL_DEPTH_COMPONENT, /* BaseFormat */
371 GL_UNSIGNED_INT, /* DataType */
372 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
373 0, 0, 0, 32, 0, /* Lum/Int/Index/Depth/StencilBits */
374 1, 1, 4 /* BlockWidth/Height,Bytes */
375 },
376 {
377 MESA_FORMAT_S8, /* Name */
378 "MESA_FORMAT_S8", /* StrName */
379 GL_STENCIL_INDEX, /* BaseFormat */
380 GL_UNSIGNED_INT, /* DataType */
381 0, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
382 0, 0, 0, 0, 8, /* Lum/Int/Index/Depth/StencilBits */
383 1, 1, 1 /* BlockWidth/Height,Bytes */
384 },
385 {
386 MESA_FORMAT_SRGB8,
387 "MESA_FORMAT_SRGB8",
388 GL_RGB,
389 GL_UNSIGNED_NORMALIZED,
390 8, 8, 8, 0,
391 0, 0, 0, 0, 0,
392 1, 1, 3
393 },
394 {
395 MESA_FORMAT_SRGBA8,
396 "MESA_FORMAT_SRGBA8",
397 GL_RGBA,
398 GL_UNSIGNED_NORMALIZED,
399 8, 8, 8, 8,
400 0, 0, 0, 0, 0,
401 1, 1, 4
402 },
403 {
404 MESA_FORMAT_SARGB8,
405 "MESA_FORMAT_SARGB8",
406 GL_RGBA,
407 GL_UNSIGNED_NORMALIZED,
408 8, 8, 8, 8,
409 0, 0, 0, 0, 0,
410 1, 1, 4
411 },
412 {
413 MESA_FORMAT_SL8,
414 "MESA_FORMAT_SL8",
415 GL_LUMINANCE,
416 GL_UNSIGNED_NORMALIZED,
417 0, 0, 0, 0,
418 8, 0, 0, 0, 0,
419 1, 1, 1
420 },
421 {
422 MESA_FORMAT_SLA8,
423 "MESA_FORMAT_SLA8",
424 GL_LUMINANCE_ALPHA,
425 GL_UNSIGNED_NORMALIZED,
426 0, 0, 0, 8,
427 8, 0, 0, 0, 0,
428 1, 1, 2
429 },
430 {
431 MESA_FORMAT_SRGB_DXT1, /* Name */
432 "MESA_FORMAT_SRGB_DXT1", /* StrName */
433 GL_RGB, /* BaseFormat */
434 GL_UNSIGNED_NORMALIZED, /* DataType */
435 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
436 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
437 4, 4, 8 /* 8 bytes per 4x4 block */
438 },
439 {
440 MESA_FORMAT_SRGBA_DXT1,
441 "MESA_FORMAT_SRGBA_DXT1",
442 GL_RGBA,
443 GL_UNSIGNED_NORMALIZED,
444 4, 4, 4, 4,
445 0, 0, 0, 0, 0,
446 4, 4, 8 /* 8 bytes per 4x4 block */
447 },
448 {
449 MESA_FORMAT_SRGBA_DXT3,
450 "MESA_FORMAT_SRGBA_DXT3",
451 GL_RGBA,
452 GL_UNSIGNED_NORMALIZED,
453 4, 4, 4, 4,
454 0, 0, 0, 0, 0,
455 4, 4, 16 /* 16 bytes per 4x4 block */
456 },
457 {
458 MESA_FORMAT_SRGBA_DXT5,
459 "MESA_FORMAT_SRGBA_DXT5",
460 GL_RGBA,
461 GL_UNSIGNED_NORMALIZED,
462 4, 4, 4, 4,
463 0, 0, 0, 0, 0,
464 4, 4, 16 /* 16 bytes per 4x4 block */
465 },
466
467 {
468 MESA_FORMAT_RGB_FXT1,
469 "MESA_FORMAT_RGB_FXT1",
470 GL_RGB,
471 GL_UNSIGNED_NORMALIZED,
472 4, 4, 4, 0, /* approx Red/Green/BlueBits */
473 0, 0, 0, 0, 0,
474 8, 4, 16 /* 16 bytes per 8x4 block */
475 },
476 {
477 MESA_FORMAT_RGBA_FXT1,
478 "MESA_FORMAT_RGBA_FXT1",
479 GL_RGBA,
480 GL_UNSIGNED_NORMALIZED,
481 4, 4, 4, 1, /* approx Red/Green/Blue/AlphaBits */
482 0, 0, 0, 0, 0,
483 8, 4, 16 /* 16 bytes per 8x4 block */
484 },
485
486 {
487 MESA_FORMAT_RGB_DXT1, /* Name */
488 "MESA_FORMAT_RGB_DXT1", /* StrName */
489 GL_RGB, /* BaseFormat */
490 GL_UNSIGNED_NORMALIZED, /* DataType */
491 4, 4, 4, 0, /* approx Red/Green/Blue/AlphaBits */
492 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
493 4, 4, 8 /* 8 bytes per 4x4 block */
494 },
495 {
496 MESA_FORMAT_RGBA_DXT1,
497 "MESA_FORMAT_RGBA_DXT1",
498 GL_RGBA,
499 GL_UNSIGNED_NORMALIZED,
500 4, 4, 4, 4,
501 0, 0, 0, 0, 0,
502 4, 4, 8 /* 8 bytes per 4x4 block */
503 },
504 {
505 MESA_FORMAT_RGBA_DXT3,
506 "MESA_FORMAT_RGBA_DXT3",
507 GL_RGBA,
508 GL_UNSIGNED_NORMALIZED,
509 4, 4, 4, 4,
510 0, 0, 0, 0, 0,
511 4, 4, 16 /* 16 bytes per 4x4 block */
512 },
513 {
514 MESA_FORMAT_RGBA_DXT5,
515 "MESA_FORMAT_RGBA_DXT5",
516 GL_RGBA,
517 GL_UNSIGNED_NORMALIZED,
518 4, 4, 4, 4,
519 0, 0, 0, 0, 0,
520 4, 4, 16 /* 16 bytes per 4x4 block */
521 },
522 {
523 MESA_FORMAT_RGBA_FLOAT32,
524 "MESA_FORMAT_RGBA_FLOAT32",
525 GL_RGBA,
526 GL_FLOAT,
527 32, 32, 32, 32,
528 0, 0, 0, 0, 0,
529 1, 1, 16
530 },
531 {
532 MESA_FORMAT_RGBA_FLOAT16,
533 "MESA_FORMAT_RGBA_FLOAT16",
534 GL_RGBA,
535 GL_FLOAT,
536 16, 16, 16, 16,
537 0, 0, 0, 0, 0,
538 1, 1, 8
539 },
540 {
541 MESA_FORMAT_RGB_FLOAT32,
542 "MESA_FORMAT_RGB_FLOAT32",
543 GL_RGB,
544 GL_FLOAT,
545 32, 32, 32, 0,
546 0, 0, 0, 0, 0,
547 1, 1, 12
548 },
549 {
550 MESA_FORMAT_RGB_FLOAT16,
551 "MESA_FORMAT_RGB_FLOAT16",
552 GL_RGB,
553 GL_FLOAT,
554 16, 16, 16, 0,
555 0, 0, 0, 0, 0,
556 1, 1, 6
557 },
558 {
559 MESA_FORMAT_ALPHA_FLOAT32,
560 "MESA_FORMAT_ALPHA_FLOAT32",
561 GL_ALPHA,
562 GL_FLOAT,
563 0, 0, 0, 32,
564 0, 0, 0, 0, 0,
565 1, 1, 4
566 },
567 {
568 MESA_FORMAT_ALPHA_FLOAT16,
569 "MESA_FORMAT_ALPHA_FLOAT16",
570 GL_ALPHA,
571 GL_FLOAT,
572 0, 0, 0, 16,
573 0, 0, 0, 0, 0,
574 1, 1, 2
575 },
576 {
577 MESA_FORMAT_LUMINANCE_FLOAT32,
578 "MESA_FORMAT_LUMINANCE_FLOAT32",
579 GL_ALPHA,
580 GL_FLOAT,
581 0, 0, 0, 0,
582 32, 0, 0, 0, 0,
583 1, 1, 4
584 },
585 {
586 MESA_FORMAT_LUMINANCE_FLOAT16,
587 "MESA_FORMAT_LUMINANCE_FLOAT16",
588 GL_ALPHA,
589 GL_FLOAT,
590 0, 0, 0, 0,
591 16, 0, 0, 0, 0,
592 1, 1, 2
593 },
594 {
595 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32,
596 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32",
597 GL_LUMINANCE_ALPHA,
598 GL_FLOAT,
599 0, 0, 0, 32,
600 32, 0, 0, 0, 0,
601 1, 1, 8
602 },
603 {
604 MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16,
605 "MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16",
606 GL_LUMINANCE_ALPHA,
607 GL_FLOAT,
608 0, 0, 0, 16,
609 16, 0, 0, 0, 0,
610 1, 1, 4
611 },
612 {
613 MESA_FORMAT_INTENSITY_FLOAT32,
614 "MESA_FORMAT_INTENSITY_FLOAT32",
615 GL_INTENSITY,
616 GL_FLOAT,
617 0, 0, 0, 0,
618 0, 32, 0, 0, 0,
619 1, 1, 4
620 },
621 {
622 MESA_FORMAT_INTENSITY_FLOAT16,
623 "MESA_FORMAT_INTENSITY_FLOAT16",
624 GL_INTENSITY,
625 GL_FLOAT,
626 0, 0, 0, 0,
627 0, 16, 0, 0, 0,
628 1, 1, 2
629 },
630
631 /* unnormalized signed int formats */
632 {
633 MESA_FORMAT_RGBA_INT8,
634 "MESA_FORMAT_RGBA_INT8",
635 GL_RGBA,
636 GL_INT,
637 8, 8, 8, 8,
638 0, 0, 0, 0, 0,
639 1, 1, 4
640 },
641 {
642 MESA_FORMAT_RGBA_INT16,
643 "MESA_FORMAT_RGBA_INT16",
644 GL_RGBA,
645 GL_INT,
646 16, 16, 16, 16,
647 0, 0, 0, 0, 0,
648 1, 1, 8
649 },
650 {
651 MESA_FORMAT_RGBA_INT32,
652 "MESA_FORMAT_RGBA_INT32",
653 GL_RGBA,
654 GL_INT,
655 32, 32, 32, 32,
656 0, 0, 0, 0, 0,
657 1, 1, 16
658 },
659
660 /* unnormalized unsigned int formats */
661 {
662 MESA_FORMAT_RGBA_UINT8,
663 "MESA_FORMAT_RGBA_UINT8",
664 GL_RGBA,
665 GL_UNSIGNED_INT,
666 8, 8, 8, 8,
667 0, 0, 0, 0, 0,
668 1, 1, 4
669 },
670 {
671 MESA_FORMAT_RGBA_UINT16,
672 "MESA_FORMAT_RGBA_UINT16",
673 GL_RGBA,
674 GL_UNSIGNED_INT,
675 16, 16, 16, 16,
676 0, 0, 0, 0, 0,
677 1, 1, 8
678 },
679 {
680 MESA_FORMAT_RGBA_UINT32,
681 "MESA_FORMAT_RGBA_UINT32",
682 GL_RGBA,
683 GL_UNSIGNED_INT,
684 32, 32, 32, 32,
685 0, 0, 0, 0, 0,
686 1, 1, 16
687 },
688
689
690 {
691 MESA_FORMAT_DUDV8,
692 "MESA_FORMAT_DUDV8",
693 GL_DUDV_ATI,
694 GL_SIGNED_NORMALIZED,
695 0, 0, 0, 0,
696 0, 0, 0, 0, 0,
697 1, 1, 2
698 },
699
700 /* Signed 8 bits / channel */
701 {
702 MESA_FORMAT_SIGNED_R8, /* Name */
703 "MESA_FORMAT_SIGNED_R8", /* StrName */
704 GL_RGBA, /* BaseFormat */
705 GL_SIGNED_NORMALIZED, /* DataType */
706 8, 0, 0, 0, /* Red/Green/Blue/AlphaBits */
707 0, 0, 0, 0, 0, /* Lum/Int/Index/Depth/StencilBits */
708 1, 1, 1 /* BlockWidth/Height,Bytes */
709 },
710 {
711 MESA_FORMAT_SIGNED_RG88,
712 "MESA_FORMAT_SIGNED_RG88",
713 GL_RGBA,
714 GL_SIGNED_NORMALIZED,
715 8, 8, 0, 0,
716 0, 0, 0, 0, 0,
717 1, 1, 2
718 },
719 {
720 MESA_FORMAT_SIGNED_RGBX8888,
721 "MESA_FORMAT_SIGNED_RGBX8888",
722 GL_RGBA,
723 GL_SIGNED_NORMALIZED,
724 8, 8, 8, 0,
725 0, 0, 0, 0, 0,
726 1, 1, 4 /* 4 bpp, but no alpha */
727 },
728 {
729 MESA_FORMAT_SIGNED_RGBA8888,
730 "MESA_FORMAT_SIGNED_RGBA8888",
731 GL_RGBA,
732 GL_SIGNED_NORMALIZED,
733 8, 8, 8, 8,
734 0, 0, 0, 0, 0,
735 1, 1, 4
736 },
737 {
738 MESA_FORMAT_SIGNED_RGBA8888_REV,
739 "MESA_FORMAT_SIGNED_RGBA8888_REV",
740 GL_RGBA,
741 GL_SIGNED_NORMALIZED,
742 8, 8, 8, 8,
743 0, 0, 0, 0, 0,
744 1, 1, 4
745 },
746
747 /* Signed 16 bits / channel */
748 {
749 MESA_FORMAT_SIGNED_R_16,
750 "MESA_FORMAT_SIGNED_R_16",
751 GL_RGBA,
752 GL_SIGNED_NORMALIZED,
753 16, 0, 0, 0,
754 0, 0, 0, 0, 0,
755 1, 1, 2
756 },
757 {
758 MESA_FORMAT_SIGNED_RG_16,
759 "MESA_FORMAT_SIGNED_RG_16",
760 GL_RGBA,
761 GL_SIGNED_NORMALIZED,
762 16, 16, 0, 0,
763 0, 0, 0, 0, 0,
764 1, 1, 4
765 },
766 {
767 MESA_FORMAT_SIGNED_RGB_16,
768 "MESA_FORMAT_SIGNED_RGB_16",
769 GL_RGBA,
770 GL_SIGNED_NORMALIZED,
771 16, 16, 16, 0,
772 0, 0, 0, 0, 0,
773 1, 1, 6
774 },
775 {
776 MESA_FORMAT_SIGNED_RGBA_16,
777 "MESA_FORMAT_SIGNED_RGBA_16",
778 GL_RGBA,
779 GL_SIGNED_NORMALIZED,
780 16, 16, 16, 16,
781 0, 0, 0, 0, 0,
782 1, 1, 8
783 },
784 {
785 MESA_FORMAT_RGBA_16,
786 "MESA_FORMAT_RGBA_16",
787 GL_RGBA,
788 GL_UNSIGNED_NORMALIZED,
789 16, 16, 16, 16,
790 0, 0, 0, 0, 0,
791 1, 1, 8
792 }
793 };
794
795
796
797 static const struct gl_format_info *
798 _mesa_get_format_info(gl_format format)
799 {
800 const struct gl_format_info *info = &format_info[format];
801 assert(info->Name == format);
802 return info;
803 }
804
805
806 /** Return string name of format (for debugging) */
807 const char *
808 _mesa_get_format_name(gl_format format)
809 {
810 const struct gl_format_info *info = _mesa_get_format_info(format);
811 ASSERT(info->BytesPerBlock);
812 return info->StrName;
813 }
814
815
816
817 /**
818 * Return bytes needed to store a block of pixels in the given format.
819 * Normally, a block is 1x1 (a single pixel). But for compressed formats
820 * a block may be 4x4 or 8x4, etc.
821 */
822 GLuint
823 _mesa_get_format_bytes(gl_format format)
824 {
825 const struct gl_format_info *info = _mesa_get_format_info(format);
826 ASSERT(info->BytesPerBlock);
827 return info->BytesPerBlock;
828 }
829
830
831 /**
832 * Return bits per component for the given format.
833 * \param format one of MESA_FORMAT_x
834 * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc.
835 */
836 GLint
837 _mesa_get_format_bits(gl_format format, GLenum pname)
838 {
839 const struct gl_format_info *info = _mesa_get_format_info(format);
840
841 switch (pname) {
842 case GL_RED_BITS:
843 case GL_TEXTURE_RED_SIZE:
844 case GL_RENDERBUFFER_RED_SIZE_EXT:
845 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE:
846 return info->RedBits;
847 case GL_GREEN_BITS:
848 case GL_TEXTURE_GREEN_SIZE:
849 case GL_RENDERBUFFER_GREEN_SIZE_EXT:
850 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE:
851 return info->GreenBits;
852 case GL_BLUE_BITS:
853 case GL_TEXTURE_BLUE_SIZE:
854 case GL_RENDERBUFFER_BLUE_SIZE_EXT:
855 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE:
856 return info->BlueBits;
857 case GL_ALPHA_BITS:
858 case GL_TEXTURE_ALPHA_SIZE:
859 case GL_RENDERBUFFER_ALPHA_SIZE_EXT:
860 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE:
861 return info->AlphaBits;
862 case GL_TEXTURE_INTENSITY_SIZE:
863 return info->IntensityBits;
864 case GL_TEXTURE_LUMINANCE_SIZE:
865 return info->LuminanceBits;
866 case GL_INDEX_BITS:
867 case GL_TEXTURE_INDEX_SIZE_EXT:
868 return info->IndexBits;
869 case GL_DEPTH_BITS:
870 case GL_TEXTURE_DEPTH_SIZE_ARB:
871 case GL_RENDERBUFFER_DEPTH_SIZE_EXT:
872 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE:
873 return info->DepthBits;
874 case GL_STENCIL_BITS:
875 case GL_TEXTURE_STENCIL_SIZE_EXT:
876 case GL_RENDERBUFFER_STENCIL_SIZE_EXT:
877 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE:
878 return info->StencilBits;
879 default:
880 _mesa_problem(NULL, "bad pname in _mesa_get_format_bits()");
881 return 0;
882 }
883 }
884
885
886 /**
887 * Return the data type (or more specifically, the data representation)
888 * for the given format.
889 * The return value will be one of:
890 * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1]
891 * GL_SIGNED_NORMALIZED = signed int representing [-1, 1]
892 * GL_UNSIGNED_INT = an ordinary unsigned integer
893 * GL_FLOAT = an ordinary float
894 */
895 GLenum
896 _mesa_get_format_datatype(gl_format format)
897 {
898 const struct gl_format_info *info = _mesa_get_format_info(format);
899 return info->DataType;
900 }
901
902
903 /**
904 * Return the basic format for the given type. The result will be
905 * one of GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA,
906 * GL_INTENSITY, GL_YCBCR_MESA, GL_COLOR_INDEX, GL_DEPTH_COMPONENT,
907 * GL_STENCIL_INDEX, GL_DEPTH_STENCIL.
908 */
909 GLenum
910 _mesa_get_format_base_format(gl_format format)
911 {
912 const struct gl_format_info *info = _mesa_get_format_info(format);
913 return info->BaseFormat;
914 }
915
916
917 /**
918 * Return the block size (in pixels) for the given format. Normally
919 * the block size is 1x1. But compressed formats will have block sizes
920 * of 4x4 or 8x4 pixels, etc.
921 * \param bw returns block width in pixels
922 * \param bh returns block height in pixels
923 */
924 void
925 _mesa_get_format_block_size(gl_format format, GLuint *bw, GLuint *bh)
926 {
927 const struct gl_format_info *info = _mesa_get_format_info(format);
928 *bw = info->BlockWidth;
929 *bh = info->BlockHeight;
930 }
931
932
933 /** Is the given format a compressed format? */
934 GLboolean
935 _mesa_is_format_compressed(gl_format format)
936 {
937 const struct gl_format_info *info = _mesa_get_format_info(format);
938 return info->BlockWidth > 1 || info->BlockHeight > 1;
939 }
940
941
942 /**
943 * Determine if the given format represents a packed depth/stencil buffer.
944 */
945 GLboolean
946 _mesa_is_format_packed_depth_stencil(gl_format format)
947 {
948 if (format == MESA_FORMAT_Z24_S8
949 || format == MESA_FORMAT_Z24_X8
950 || format == MESA_FORMAT_S8_Z24
951 || format == MESA_FORMAT_X8_Z24)
952 return GL_TRUE;
953
954 return GL_FALSE;
955 }
956
957
958 /**
959 * Return color encoding for given format.
960 * \return GL_LINEAR or GL_SRGB
961 */
962 GLenum
963 _mesa_get_format_color_encoding(gl_format format)
964 {
965 /* XXX this info should be encoded in gl_format_info */
966 switch (format) {
967 case MESA_FORMAT_SRGB8:
968 case MESA_FORMAT_SRGBA8:
969 case MESA_FORMAT_SARGB8:
970 case MESA_FORMAT_SL8:
971 case MESA_FORMAT_SLA8:
972 case MESA_FORMAT_SRGB_DXT1:
973 case MESA_FORMAT_SRGBA_DXT1:
974 case MESA_FORMAT_SRGBA_DXT3:
975 case MESA_FORMAT_SRGBA_DXT5:
976 return GL_SRGB;
977 default:
978 return GL_LINEAR;
979 }
980 }
981
982
983 /**
984 * Return number of bytes needed to store an image of the given size
985 * in the given format.
986 */
987 GLuint
988 _mesa_format_image_size(gl_format format, GLsizei width,
989 GLsizei height, GLsizei depth)
990 {
991 const struct gl_format_info *info = _mesa_get_format_info(format);
992 /* Strictly speaking, a conditional isn't needed here */
993 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
994 /* compressed format */
995 const GLuint bw = info->BlockWidth, bh = info->BlockHeight;
996 const GLuint wblocks = (width + bw - 1) / bw;
997 const GLuint hblocks = (height + bh - 1) / bh;
998 const GLuint sz = wblocks * hblocks * info->BytesPerBlock;
999 return sz;
1000 }
1001 else {
1002 /* non-compressed */
1003 const GLuint sz = width * height * depth * info->BytesPerBlock;
1004 return sz;
1005 }
1006 }
1007
1008
1009
1010 GLint
1011 _mesa_format_row_stride(gl_format format, GLsizei width)
1012 {
1013 const struct gl_format_info *info = _mesa_get_format_info(format);
1014 /* Strictly speaking, a conditional isn't needed here */
1015 if (info->BlockWidth > 1 || info->BlockHeight > 1) {
1016 /* compressed format */
1017 const GLuint bw = info->BlockWidth;
1018 const GLuint wblocks = (width + bw - 1) / bw;
1019 const GLint stride = wblocks * info->BytesPerBlock;
1020 return stride;
1021 }
1022 else {
1023 const GLint stride = width * info->BytesPerBlock;
1024 return stride;
1025 }
1026 }
1027
1028
1029
1030 /**
1031 * Do sanity checking of the format info table.
1032 */
1033 void
1034 _mesa_test_formats(void)
1035 {
1036 GLuint i;
1037
1038 assert(Elements(format_info) == MESA_FORMAT_COUNT);
1039
1040 for (i = 0; i < MESA_FORMAT_COUNT; i++) {
1041 const struct gl_format_info *info = _mesa_get_format_info(i);
1042 assert(info);
1043
1044 assert(info->Name == i);
1045
1046 if (info->Name == MESA_FORMAT_NONE)
1047 continue;
1048
1049 if (info->BlockWidth == 1 && info->BlockHeight == 1) {
1050 if (info->RedBits > 0) {
1051 GLuint t = info->RedBits + info->GreenBits
1052 + info->BlueBits + info->AlphaBits;
1053 assert(t / 8 == info->BytesPerBlock);
1054 (void) t;
1055 }
1056 }
1057
1058 assert(info->DataType == GL_UNSIGNED_NORMALIZED ||
1059 info->DataType == GL_SIGNED_NORMALIZED ||
1060 info->DataType == GL_UNSIGNED_INT ||
1061 info->DataType == GL_FLOAT);
1062
1063 if (info->BaseFormat == GL_RGB) {
1064 assert(info->RedBits > 0);
1065 assert(info->GreenBits > 0);
1066 assert(info->BlueBits > 0);
1067 assert(info->AlphaBits == 0);
1068 assert(info->LuminanceBits == 0);
1069 assert(info->IntensityBits == 0);
1070 }
1071 else if (info->BaseFormat == GL_RGBA) {
1072 assert(info->RedBits > 0);
1073 assert(info->GreenBits > 0);
1074 assert(info->BlueBits > 0);
1075 assert(info->AlphaBits > 0);
1076 assert(info->LuminanceBits == 0);
1077 assert(info->IntensityBits == 0);
1078 }
1079 else if (info->BaseFormat == GL_LUMINANCE) {
1080 assert(info->RedBits == 0);
1081 assert(info->GreenBits == 0);
1082 assert(info->BlueBits == 0);
1083 assert(info->AlphaBits == 0);
1084 assert(info->LuminanceBits > 0);
1085 assert(info->IntensityBits == 0);
1086 }
1087 else if (info->BaseFormat == GL_INTENSITY) {
1088 assert(info->RedBits == 0);
1089 assert(info->GreenBits == 0);
1090 assert(info->BlueBits == 0);
1091 assert(info->AlphaBits == 0);
1092 assert(info->LuminanceBits == 0);
1093 assert(info->IntensityBits > 0);
1094 }
1095
1096 }
1097 }
1098
1099
1100
1101 /**
1102 * Return datatype and number of components per texel for the given gl_format.
1103 * Only used for mipmap generation code.
1104 */
1105 void
1106 _mesa_format_to_type_and_comps(gl_format format,
1107 GLenum *datatype, GLuint *comps)
1108 {
1109 switch (format) {
1110 case MESA_FORMAT_RGBA8888:
1111 case MESA_FORMAT_RGBA8888_REV:
1112 case MESA_FORMAT_ARGB8888:
1113 case MESA_FORMAT_ARGB8888_REV:
1114 case MESA_FORMAT_XRGB8888:
1115 *datatype = GL_UNSIGNED_BYTE;
1116 *comps = 4;
1117 return;
1118 case MESA_FORMAT_RGB888:
1119 case MESA_FORMAT_BGR888:
1120 *datatype = GL_UNSIGNED_BYTE;
1121 *comps = 3;
1122 return;
1123 case MESA_FORMAT_RGB565:
1124 case MESA_FORMAT_RGB565_REV:
1125 *datatype = GL_UNSIGNED_SHORT_5_6_5;
1126 *comps = 3;
1127 return;
1128
1129 case MESA_FORMAT_ARGB4444:
1130 case MESA_FORMAT_ARGB4444_REV:
1131 *datatype = GL_UNSIGNED_SHORT_4_4_4_4;
1132 *comps = 4;
1133 return;
1134
1135 case MESA_FORMAT_ARGB1555:
1136 case MESA_FORMAT_ARGB1555_REV:
1137 *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV;
1138 *comps = 4;
1139 return;
1140
1141 case MESA_FORMAT_AL88:
1142 case MESA_FORMAT_AL88_REV:
1143 *datatype = GL_UNSIGNED_BYTE;
1144 *comps = 2;
1145 return;
1146
1147 case MESA_FORMAT_AL1616:
1148 case MESA_FORMAT_AL1616_REV:
1149 *datatype = GL_UNSIGNED_SHORT;
1150 *comps = 2;
1151 return;
1152
1153 case MESA_FORMAT_RGB332:
1154 *datatype = GL_UNSIGNED_BYTE_3_3_2;
1155 *comps = 3;
1156 return;
1157
1158 case MESA_FORMAT_A8:
1159 case MESA_FORMAT_L8:
1160 case MESA_FORMAT_I8:
1161 case MESA_FORMAT_CI8:
1162 *datatype = GL_UNSIGNED_BYTE;
1163 *comps = 1;
1164 return;
1165
1166 case MESA_FORMAT_YCBCR:
1167 case MESA_FORMAT_YCBCR_REV:
1168 *datatype = GL_UNSIGNED_SHORT;
1169 *comps = 2;
1170 return;
1171
1172 case MESA_FORMAT_Z24_S8:
1173 *datatype = GL_UNSIGNED_INT;
1174 *comps = 1; /* XXX OK? */
1175 return;
1176
1177 case MESA_FORMAT_S8_Z24:
1178 *datatype = GL_UNSIGNED_INT;
1179 *comps = 1; /* XXX OK? */
1180 return;
1181
1182 case MESA_FORMAT_Z16:
1183 *datatype = GL_UNSIGNED_SHORT;
1184 *comps = 1;
1185 return;
1186
1187 case MESA_FORMAT_X8_Z24:
1188 *datatype = GL_UNSIGNED_INT;
1189 *comps = 1;
1190 return;
1191
1192 case MESA_FORMAT_Z24_X8:
1193 *datatype = GL_UNSIGNED_INT;
1194 *comps = 1;
1195 return;
1196
1197 case MESA_FORMAT_Z32:
1198 *datatype = GL_UNSIGNED_INT;
1199 *comps = 1;
1200 return;
1201
1202 case MESA_FORMAT_DUDV8:
1203 *datatype = GL_BYTE;
1204 *comps = 2;
1205 return;
1206
1207 case MESA_FORMAT_SIGNED_RGBA8888:
1208 case MESA_FORMAT_SIGNED_RGBA8888_REV:
1209 *datatype = GL_BYTE;
1210 *comps = 4;
1211 return;
1212
1213 case MESA_FORMAT_SIGNED_R_16:
1214 *datatype = GL_SHORT;
1215 *comps = 1;
1216 return;
1217 case MESA_FORMAT_SIGNED_RG_16:
1218 *datatype = GL_SHORT;
1219 *comps = 2;
1220 return;
1221 case MESA_FORMAT_SIGNED_RGB_16:
1222 *datatype = GL_SHORT;
1223 *comps = 3;
1224 return;
1225 case MESA_FORMAT_SIGNED_RGBA_16:
1226 *datatype = GL_SHORT;
1227 *comps = 4;
1228 return;
1229
1230 #if FEATURE_EXT_texture_sRGB
1231 case MESA_FORMAT_SRGB8:
1232 *datatype = GL_UNSIGNED_BYTE;
1233 *comps = 3;
1234 return;
1235 case MESA_FORMAT_SRGBA8:
1236 case MESA_FORMAT_SARGB8:
1237 *datatype = GL_UNSIGNED_BYTE;
1238 *comps = 4;
1239 return;
1240 case MESA_FORMAT_SL8:
1241 *datatype = GL_UNSIGNED_BYTE;
1242 *comps = 1;
1243 return;
1244 case MESA_FORMAT_SLA8:
1245 *datatype = GL_UNSIGNED_BYTE;
1246 *comps = 2;
1247 return;
1248 #endif
1249
1250 #if FEATURE_texture_fxt1
1251 case MESA_FORMAT_RGB_FXT1:
1252 case MESA_FORMAT_RGBA_FXT1:
1253 #endif
1254 #if FEATURE_texture_s3tc
1255 case MESA_FORMAT_RGB_DXT1:
1256 case MESA_FORMAT_RGBA_DXT1:
1257 case MESA_FORMAT_RGBA_DXT3:
1258 case MESA_FORMAT_RGBA_DXT5:
1259 #if FEATURE_EXT_texture_sRGB
1260 case MESA_FORMAT_SRGB_DXT1:
1261 case MESA_FORMAT_SRGBA_DXT1:
1262 case MESA_FORMAT_SRGBA_DXT3:
1263 case MESA_FORMAT_SRGBA_DXT5:
1264 #endif
1265 /* XXX generate error instead? */
1266 *datatype = GL_UNSIGNED_BYTE;
1267 *comps = 0;
1268 return;
1269 #endif
1270
1271 case MESA_FORMAT_RGBA_FLOAT32:
1272 *datatype = GL_FLOAT;
1273 *comps = 4;
1274 return;
1275 case MESA_FORMAT_RGBA_FLOAT16:
1276 *datatype = GL_HALF_FLOAT_ARB;
1277 *comps = 4;
1278 return;
1279 case MESA_FORMAT_RGB_FLOAT32:
1280 *datatype = GL_FLOAT;
1281 *comps = 3;
1282 return;
1283 case MESA_FORMAT_RGB_FLOAT16:
1284 *datatype = GL_HALF_FLOAT_ARB;
1285 *comps = 3;
1286 return;
1287 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
1288 *datatype = GL_FLOAT;
1289 *comps = 2;
1290 return;
1291 case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
1292 *datatype = GL_HALF_FLOAT_ARB;
1293 *comps = 2;
1294 return;
1295 case MESA_FORMAT_ALPHA_FLOAT32:
1296 case MESA_FORMAT_LUMINANCE_FLOAT32:
1297 case MESA_FORMAT_INTENSITY_FLOAT32:
1298 *datatype = GL_FLOAT;
1299 *comps = 1;
1300 return;
1301 case MESA_FORMAT_ALPHA_FLOAT16:
1302 case MESA_FORMAT_LUMINANCE_FLOAT16:
1303 case MESA_FORMAT_INTENSITY_FLOAT16:
1304 *datatype = GL_HALF_FLOAT_ARB;
1305 *comps = 1;
1306 return;
1307
1308 case MESA_FORMAT_RGBA_INT8:
1309 *datatype = GL_BYTE;
1310 *comps = 4;
1311 return;
1312 case MESA_FORMAT_RGBA_INT16:
1313 *datatype = GL_SHORT;
1314 *comps = 4;
1315 return;
1316 case MESA_FORMAT_RGBA_INT32:
1317 *datatype = GL_INT;
1318 *comps = 4;
1319 return;
1320
1321 /**
1322 * \name Non-normalized unsigned integer formats.
1323 */
1324 case MESA_FORMAT_RGBA_UINT8:
1325 *datatype = GL_UNSIGNED_BYTE;
1326 *comps = 4;
1327 return;
1328 case MESA_FORMAT_RGBA_UINT16:
1329 *datatype = GL_UNSIGNED_SHORT;
1330 *comps = 4;
1331 return;
1332 case MESA_FORMAT_RGBA_UINT32:
1333 *datatype = GL_UNSIGNED_INT;
1334 *comps = 4;
1335 return;
1336
1337
1338 default:
1339 _mesa_problem(NULL, "bad format in _mesa_format_to_type_and_comps");
1340 *datatype = 0;
1341 *comps = 1;
1342 }
1343 }