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