summaryrefslogtreecommitdiffstats
path: root/src/mesa/main/debug.c
Commit message (Collapse)AuthorAgeFilesLines
* mesa: add support for GL_OES_EGL_image_externalChia-I Wu2011-11-031-1/+2
| | | | | | | | | This is an OpenGL ES specific extension. External textures are textures that may be sampled from, but not be updated (no glTexSubImage* and etc.). The image data are taken from an EGLImage. Reviewed-by: Brian Paul <[email protected]> Acked-by: Jakob Bornecrantz <[email protected]>
* mesa: simplify parameters to GetTexImage() driver hookBrian Paul2011-09-301-3/+1
| | | | | | | The target, level and texObj can be obtained through the texImage parameter. We could make similar changes for the TexImage() hooks too. Reviewed-by: Eric Anholt <[email protected]>
* mesa: remove CHAN_TYPE cruft from debug.cBrian Paul2011-09-201-4/+0
|
* mesa: Remove all mention of MESA_FORMAT_CI8Ian Romanick2011-08-291-1/+0
| | | | | | | | | | | Nothing in Mesa supports color-index textures, and most of the other infrastructure that could allow such support has already been removed. This puts the final nail in the coffin. Also clean out some GL_COLOR_INDEX comments in formats.c. Reviewed-by: Brian Paul <[email protected]> Reviewed-by: Kenneth Graunke <[email protected]>
* mesa: Convert texture debug dump function to using MapTextureImage().Brian Paul2011-08-291-43/+51
| | | | Reviewed-by: Brian Paul <[email protected]>
* mesa: Remove use of fpu_control.hChad Versace2011-08-161-11/+0
| | | | | | | | | | | Remove the inclusion of fpu_control.h from compiler.h. Since Bionic lacks fpu_control.h, this fixes the Android build. Also remove the sole use of the fpu_control bits, which was in debug.c. Those were brianp's debug bits, and he approved of their removal. Reviewed-by: Eric Anholt <[email protected]> Signed-off-by: Chad Versace <[email protected]>
* mesa: Recognize MESA_VERBOSE=all as shortcut for all debug options.José Fonseca2011-04-061-1/+1
|
* mesa: added _mesa_dump_image() for debuggingBrian Paul2011-03-241-0/+24
|
* mesa: remove the MESA_NO_DITHER env varBrian Paul2011-02-171-10/+0
| | | | This was sometimes useful back when 16-bit framebuffers were prominent.
* mesa: make _mesa_write_renderbuffer_image() non-staticBrian Paul2011-02-161-3/+11
|
* mesa: get rid of _NEW_ACCUM, clean-up _NEW_* #definesBrian Paul2011-01-231-2/+1
| | | | | | The _NEW_ACCUM flag was only set when changing the accumulation buffer clear color and never used anywhere. Reclaim that dirty bit. Clean up the definitions of the other dirty bit flags.
* mesa: clean-up _mesa_lookup_prim_by_nr()Brian Paul2011-01-201-20/+0
| | | | Remove the redundant public _mesa_prim_name[] array.
* mesa: Fix printf format warnings.Vinson Lee2010-11-101-1/+1
|
* mesa: remove unneeded DD_POINT_SIZE and DD_LINE_WIDTH tricapsRoland Scheidegger2010-11-101-2/+0
| | | | | | | | DD_POINT_SIZE was broken for quite some time, and the only driver (r200) relying on this no longer needs it. Both DD_POINT_SIZE and DD_LINE_WIDTH have no users left outside of debugging output, hence instead of fixing DD_POINT_SIZE setting just drop both of them - there was a plan to remove tricaps flags entirely at some point.
* Drop GLcontext typedef and use struct gl_context insteadKristian Høgsberg2010-10-131-2/+2
|
* mesa: Remove SGI_color_matrix.Eric Anholt2010-09-231-2/+1
| | | | Another optional ARB_imaging subset extension.
* Revert "glapi: Implement optional dispatch logging"Kristian Høgsberg2010-09-091-5/+1
| | | | | | This reverts commit b9abc6139a310677a37754ea7172d976dbf56979 and the follow on fixes (7aae704 and 6fe1b47). It's changing the glapi/driver ABI and causes a number of problems for debug/non-debug builds.
* glapi: Implement optional dispatch loggingKristian Høgsberg2010-09-091-1/+5
| | | | | | | There's a useful feature buried in glapi to log all API calls to stderr. Unfortunately it requires editing the code and then it's enabled unconditionally for that build. This patch builds in API logging for debug builds and makes it run-time switchable by setting MESA_DEBUG=dispatch.
* mesa: s/sprintf/_mesa_snprintf/Vinson Lee2010-05-021-2/+2
|
* mesa: Also print _NEW_STENCIL in _mesa_print_state()Kristian Høgsberg2010-03-231-1/+2
|
* mesa: casts to silence new warnings from printf()Brian Paul2010-02-191-2/+2
|
* Replace the _mesa_*printf() wrappers with the plain libc versionsKristian Høgsberg2010-02-191-28/+28
|
* Replace _mesa_malloc, _mesa_calloc and _mesa_free with plain libc versionsKristian Høgsberg2010-02-191-14/+14
|
* Remove _mesa_strstr in favor of plain strstr.Kenneth Graunke2010-02-191-3/+3
|
* mesa: Fix typo of 'unknown' in debug.c.Vinson Lee2010-01-181-1/+1
|
* mesa: Remove unnecessary headers from debug.c.Vinson Lee2010-01-181-2/+0
|
* mesa: move, clean-up _mesa_print_texture()Brian Paul2009-10-291-0/+61
|
* Merge branch 'texformat-rework'Brian Paul2009-10-281-3/+4
|\ | | | | | | | | | | | | | | | | | | | | | | Conflicts: src/mesa/drivers/dri/radeon/radeon_fbo.c src/mesa/drivers/dri/s3v/s3v_tex.c src/mesa/drivers/dri/s3v/s3v_xmesa.c src/mesa/drivers/dri/trident/trident_context.c src/mesa/main/debug.c src/mesa/main/mipmap.c src/mesa/main/texformat.c src/mesa/main/texgetimage.c
| * mesa: don't include texformat.hBrian Paul2009-10-051-1/+0
| |
| * mesa: replace gl_texture_format with gl_formatBrian Paul2009-09-301-1/+1
| | | | | | | | | | | | Now gl_texture_image::TexFormat is a simple MESA_FORMAT_x enum. ctx->Driver.ChooseTexture format also returns a MESA_FORMAT_x. gl_texture_format will go away next.
* | mesa: more texture debug code changes, improvementsBrian Paul2009-10-271-27/+66
| |
* | mesa: added _mesa_dump_texture()Brian Paul2009-10-221-3/+25
| |
* | mesa: added _mesa_dump_renderbuffers() debug codeBrian Paul2009-10-211-2/+74
| |
* | mesa: added VERBOSE_SWAPBUFFERSBrian Paul2009-10-141-1/+2
| |
* | mesa: added MESA_VERBOSE option 'draw' to debug glDrawArrays/Elements, etc.Brian Paul2009-10-141-1/+2
| |
* | mesa: rename VERBOSE_IMMEDIATE->VERBOSE_MATERIAL to reflect what it doesBrian Paul2009-10-141-1/+1
|/
* mesa: better texture dump/debug codeBrian Paul2009-08-041-52/+45
|
* Merge branch 'mesa_7_5_branch'Jakob Bornecrantz2009-06-091-1/+1
|\ | | | | | | | | | | | | | | | | Conflicts: Makefile src/mesa/main/version.h src/mesa/shader/slang/slang_preprocess.c src/mesa/state_tracker/st_cb_bufferobjects.c
| * mesa: Use matching signedness for the counter as upper bound.José Fonseca2009-06-081-1/+1
| |
* | mesa: call _mesa_ funcs, not gl funcs for debuggingBrian Paul2009-06-041-15/+18
| |
* | mesa: added debug functions for dumping color/depth/stencil buffersBrian Paul2009-05-211-0/+101
|/
* mesa: fix _mesa_dump_textures(), add null ptr checkBrian Paul2009-04-221-2/+3
| | | | Calling _mesa_dump_textures() deleted the textures... oops!!!
* mesa: more tex image debug/dumping codeBrian Paul2009-03-021-0/+22
|
* mesa: Move statements after declarations.José Fonseca2009-02-111-1/+1
|
* mesa: debug code for printing info about textures, writing teximages to diskBrian Paul2009-02-071-0/+99
|
* glsl: new MESA_GLSL env var for GLSL debugging featuresBrian Paul2009-02-061-3/+1
| | | | | | Replaces the VERBOSE_GLSL, VERBOSE_GLSL_DUMP flags which only worked in debug builds. MESA_GLSL will work both in debug and non-debug builds. Also add facility to dump glUniform() calls to stdout.
* Revert "mesa: meaningless whitespace change to see if git's working (ignore)"Brian Paul2009-02-061-1/+3
| | | | | | This reverts commit b2e779988eeb595187933fe2122d86f8ccfe059c. I didn't mean to push this stuff yet. I'm having a bad git day...
* mesa: meaningless whitespace change to see if git's working (ignore)Brian Paul2009-02-061-3/+1
|
* mesa: additional debug flags for glsl debug/disassemblyBrian Paul2008-11-011-29/+25
|
* Move code to enable FP exceptions into debug.c (set MESA_DEBUG=fpexceptions).Brian Paul2005-11-101-1/+13
| | | | Get rid of MESA_DEBUG preprocessor symbol, just use DEBUG instead.
9' href='#n1099'>1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356
/*
 * Mesa 3-D graphics library
 *
 * Copyright (c) 2011 VMware, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included
 * in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */


#include "colormac.h"
#include "format_unpack.h"
#include "macros.h"
#include "../../gallium/auxiliary/util/u_format_rgb9e5.h"
#include "../../gallium/auxiliary/util/u_format_r11g11b10f.h"


/** Helper struct for MESA_FORMAT_Z32_FLOAT_S8X24_UINT */
struct z32f_x24s8
{
   float z;
   uint32_t x24s8;
};


/* Expand 1, 2, 3, 4, 5, 6-bit values to fill 8 bits */

#define EXPAND_1_8(X)  ( (X) ? 0xff : 0x0 )

#define EXPAND_2_8(X)  ( ((X) << 6) | ((X) << 4) | ((X) << 2) | (X) )

#define EXPAND_3_8(X)  ( ((X) << 5) | ((X) << 2) | ((X) >> 1) )

#define EXPAND_4_8(X)  ( ((X) << 4) | (X) )

#define EXPAND_5_8(X)  ( ((X) << 3) | ((X) >> 2) )

#define EXPAND_6_8(X)  ( ((X) << 2) | ((X) >> 4) )


/**
 * Convert an 8-bit sRGB value from non-linear space to a
 * linear RGB value in [0, 1].
 * Implemented with a 256-entry lookup table.
 */
GLfloat
_mesa_nonlinear_to_linear(GLubyte cs8)
{
   static GLfloat table[256];
   static GLboolean tableReady = GL_FALSE;
   if (!tableReady) {
      /* compute lookup table now */
      GLuint i;
      for (i = 0; i < 256; i++) {
         const GLfloat cs = UBYTE_TO_FLOAT(i);
         if (cs <= 0.04045) {
            table[i] = cs / 12.92f;
         }
         else {
            table[i] = (GLfloat) pow((cs + 0.055) / 1.055, 2.4);
         }
      }
      tableReady = GL_TRUE;
   }
   return table[cs8];
}


/**********************************************************************/
/*  Unpack, returning GLfloat colors                                  */
/**********************************************************************/

typedef void (*unpack_rgba_func)(const void *src, GLfloat dst[][4], GLuint n);


static void
unpack_A8B8G8R8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
   }
}

static void
unpack_R8G8B8A8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
   }
}

static void
unpack_B8G8R8A8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
   }
}

static void
unpack_A8R8G8B8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
   }
}

static void
unpack_RGBX8888(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
      dst[i][ACOMP] = 1.0f;
   }
}

static void
unpack_RGBX8888_REV(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
      dst[i][ACOMP] = 1.0f;
   }
}

static void
unpack_B8G8R8X8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i]      ) & 0xff );
      dst[i][ACOMP] = 1.0f;
   }
}

static void
unpack_X8R8G8B8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( (s[i] >>  8) & 0xff );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( (s[i] >> 16) & 0xff );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( (s[i] >> 24)        );
      dst[i][ACOMP] = 1.0f;
   }
}

static void
unpack_BGR_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_RGB_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i*3+0] );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i*3+1] );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i*3+2] );
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_B5G6R5_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
      dst[i][GCOMP] = ((s[i] >> 5 ) & 0x3f) * (1.0F / 63.0F);
      dst[i][BCOMP] = ((s[i]      ) & 0x1f) * (1.0F / 31.0F);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_R5G6B5_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   /* Warning: this function does not match the current Mesa definition
    * of MESA_FORMAT_R5G6B5_UNORM.
    */
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
      dst[i][RCOMP] = UBYTE_TO_FLOAT( ((t >> 8) & 0xf8) | ((t >> 13) & 0x7) );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( ((t >> 3) & 0xfc) | ((t >>  9) & 0x3) );
      dst[i][BCOMP] = UBYTE_TO_FLOAT( ((t << 3) & 0xf8) | ((t >>  2) & 0x7) );
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_B4G4R4A4_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
      dst[i][GCOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
      dst[i][BCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
      dst[i][ACOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
   }
}

static void
unpack_A4R4G4B4_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
      dst[i][GCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
      dst[i][BCOMP] = ((s[i] >> 12) & 0xf) * (1.0F / 15.0F);
      dst[i][ACOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
   }
}

static void
unpack_A1B5G5R5_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >> 11) & 0x1f) * (1.0F / 31.0F);
      dst[i][GCOMP] = ((s[i] >>  6) & 0x1f) * (1.0F / 31.0F);
      dst[i][BCOMP] = ((s[i] >>  1) & 0x1f) * (1.0F / 31.0F);
      dst[i][ACOMP] = ((s[i]      ) & 0x01) * 1.0F;
   }
}

static void
unpack_B5G5R5A1_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
      dst[i][GCOMP] = ((s[i] >>  5) & 0x1f) * (1.0F / 31.0F);
      dst[i][BCOMP] = ((s[i] >>  0) & 0x1f) * (1.0F / 31.0F);
      dst[i][ACOMP] = ((s[i] >> 15) & 0x01) * 1.0F;
   }
}

static void
unpack_A1R5G5B5_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   /* Warning: this function does not match the current Mesa definition
    * of MESA_FORMAT_A1R5G5B5_UNORM.
    */
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
      dst[i][RCOMP] = ((tmp >> 10) & 0x1f) * (1.0F / 31.0F);
      dst[i][GCOMP] = ((tmp >>  5) & 0x1f) * (1.0F / 31.0F);
      dst[i][BCOMP] = ((tmp >>  0) & 0x1f) * (1.0F / 31.0F);
      dst[i][ACOMP] = ((tmp >> 15) & 0x01) * 1.0F;
   }
}

static void
unpack_L4A4_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = (s[i] & 0xf) * (1.0F / 15.0F);
      dst[i][ACOMP] = ((s[i] >> 4) & 0xf) * (1.0F / 15.0F);
   }
}

static void
unpack_L8A8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = 
      dst[i][GCOMP] = 
      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
   }
}

static void
unpack_A8L8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = 
      dst[i][GCOMP] = 
      dst[i][BCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
   }
}

static void
unpack_L16A16_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
      dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
   }
}

static void
unpack_A16L16_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
      dst[i][ACOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
   }
}

static void
unpack_B2G3R3_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >> 5) & 0x7) * (1.0F / 7.0F);
      dst[i][GCOMP] = ((s[i] >> 2) & 0x7) * (1.0F / 7.0F);
      dst[i][BCOMP] = ((s[i]     ) & 0x3) * (1.0F / 3.0F);
      dst[i][ACOMP] = 1.0F;
   }
}


static void
unpack_A_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
   }
}

static void
unpack_A_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
   }
}

static void
unpack_L_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = UBYTE_TO_FLOAT(s[i]);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_L_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = USHORT_TO_FLOAT(s[i]);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_I_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i]);
   }
}

static void
unpack_I_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = USHORT_TO_FLOAT(s[i]);
   }
}

static void
unpack_YCBCR(const void *src, GLfloat dst[][4], GLuint n)
{
   GLuint i;
   for (i = 0; i < n; i++) {
      const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
      const GLushort *src1 = src0 + 1;         /* odd */
      const GLubyte y0 = (*src0 >> 8) & 0xff;  /* luminance */
      const GLubyte cb = *src0 & 0xff;         /* chroma U */
      const GLubyte y1 = (*src1 >> 8) & 0xff;  /* luminance */
      const GLubyte cr = *src1 & 0xff;         /* chroma V */
      const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
      GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
      GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
      GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
      r *= (1.0F / 255.0F);
      g *= (1.0F / 255.0F);
      b *= (1.0F / 255.0F);
      dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
      dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
      dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_YCBCR_REV(const void *src, GLfloat dst[][4], GLuint n)
{
   GLuint i;
   for (i = 0; i < n; i++) {
      const GLushort *src0 = ((const GLushort *) src) + i * 2; /* even */
      const GLushort *src1 = src0 + 1;         /* odd */
      const GLubyte y0 = *src0 & 0xff;         /* luminance */
      const GLubyte cr = (*src0 >> 8) & 0xff;  /* chroma V */
      const GLubyte y1 = *src1 & 0xff;         /* luminance */
      const GLubyte cb = (*src1 >> 8) & 0xff;  /* chroma U */
      const GLubyte y = (i & 1) ? y1 : y0;     /* choose even/odd luminance */
      GLfloat r = 1.164F * (y - 16) + 1.596F * (cr - 128);
      GLfloat g = 1.164F * (y - 16) - 0.813F * (cr - 128) - 0.391F * (cb - 128);
      GLfloat b = 1.164F * (y - 16) + 2.018F * (cb - 128);
      r *= (1.0F / 255.0F);
      g *= (1.0F / 255.0F);
      b *= (1.0F / 255.0F);
      dst[i][RCOMP] = CLAMP(r, 0.0F, 1.0F);
      dst[i][GCOMP] = CLAMP(g, 0.0F, 1.0F);
      dst[i][BCOMP] = CLAMP(b, 0.0F, 1.0F);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_R_UNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][0] = UBYTE_TO_FLOAT(s[i]);
      dst[i][1] =
      dst[i][2] = 0.0F;
      dst[i][3] = 1.0F;
   }
}

static void
unpack_R8G8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_G8R8_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = UBYTE_TO_FLOAT( s[i] >> 8 );
      dst[i][GCOMP] = UBYTE_TO_FLOAT( s[i] & 0xff );
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_R_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = USHORT_TO_FLOAT(s[i]);
      dst[i][GCOMP] = 0.0;
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_R16G16_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_G16R16_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i] >> 16 );
      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i] & 0xffff );
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_B10G10R10A2_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
      dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
      dst[i][BCOMP] = ((s[i] >>  0) & 0x3ff) * (1.0F / 1023.0F);
      dst[i][ACOMP] = ((s[i] >> 30) &  0x03) * (1.0F / 3.0F);
   }
}


static void
unpack_B10G10R10A2_UINT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
      dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
      dst[i][BCOMP] = (GLfloat)((s[i] >>  0) & 0x3ff);
      dst[i][ACOMP] = (GLfloat)((s[i] >> 30) &  0x03);
   }
}


static void
unpack_R10G10B10A2_UINT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat)((s[i] >>  0) & 0x3ff);
      dst[i][GCOMP] = (GLfloat)((s[i] >> 10) & 0x3ff);
      dst[i][BCOMP] = (GLfloat)((s[i] >> 20) & 0x3ff);
      dst[i][ACOMP] = (GLfloat)((s[i] >> 30) &  0x03);
   }
}


static void
unpack_S8_UINT_Z24_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   /* only return Z, not stencil data */
   const GLuint *s = ((const GLuint *) src);
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][0] =
      dst[i][1] =
      dst[i][2] = (GLfloat) ((s[i] >> 8) * scale);
      dst[i][3] = 1.0F;
      ASSERT(dst[i][0] >= 0.0F);
      ASSERT(dst[i][0] <= 1.0F);
   }
}

static void
unpack_Z24_UNORM_S8_UINT(const void *src, GLfloat dst[][4], GLuint n)
{
   /* only return Z, not stencil data */
   const GLuint *s = ((const GLuint *) src);
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][0] =
      dst[i][1] =
      dst[i][2] = (float) ((s[i] & 0x00ffffff) * scale);
      dst[i][3] = 1.0F;
      ASSERT(dst[i][0] >= 0.0F);
      ASSERT(dst[i][0] <= 1.0F);
   }
}

static void
unpack_Z_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][0] =
      dst[i][1] =
      dst[i][2] = s[i] * (1.0F / 65535.0F);
      dst[i][3] = 1.0F;
   }
}

static void
unpack_Z24_UNORM_X8_UINT(const void *src, GLfloat dst[][4], GLuint n)
{
   unpack_Z24_UNORM_S8_UINT(src, dst, n);
}

static void
unpack_X8_UINT_Z24_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   unpack_S8_UINT_Z24_UNORM(src, dst, n);
}

static void
unpack_Z_UNORM32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][0] =
      dst[i][1] =
      dst[i][2] = s[i] * (1.0F / 0xffffffff);
      dst[i][3] = 1.0F;
   }
}

static void
unpack_Z32_FLOAT_S8X24_UINT(const void *src, GLfloat dst[][4], GLuint n)
{
   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][0] =
      dst[i][1] =
      dst[i][2] = s[i].z;
      dst[i][3] = 1.0F;
   }
}

static void
unpack_Z_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = ((const GLfloat *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][0] =
      dst[i][1] =
      dst[i][2] = s[i];
      dst[i][3] = 1.0F;
   }
}


static void
unpack_S8(const void *src, GLfloat dst[][4], GLuint n)
{
   /* should never be used */
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][0] =
      dst[i][1] =
      dst[i][2] = 0.0F;
      dst[i][3] = 1.0F;
   }
}


static void
unpack_BGR_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_nonlinear_to_linear(s[i*3+2]);
      dst[i][GCOMP] = _mesa_nonlinear_to_linear(s[i*3+1]);
      dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i*3+0]);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_A8B8G8R8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 24) );
      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] & 0xff ); /* linear! */
   }
}

static void
unpack_B8G8R8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
   }
}

static void
unpack_R8G8B8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
   }
}

static void
unpack_L_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = 
      dst[i][GCOMP] = 
      dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i]);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_L8A8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = _mesa_nonlinear_to_linear(s[i] & 0xff);
      dst[i][ACOMP] = UBYTE_TO_FLOAT(s[i] >> 8); /* linear! */
   }
}

static void
unpack_SRGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}

static void
unpack_SRGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}

static void
unpack_SRGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
{
}

static void
unpack_SRGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
{
}

static void
unpack_RGB_FXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}

static void
unpack_RGBA_FXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}

static void
unpack_RGB_DXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}

static void
unpack_RGBA_DXT1(const void *src, GLfloat dst[][4], GLuint n)
{
}

static void
unpack_RGBA_DXT3(const void *src, GLfloat dst[][4], GLuint n)
{
}

static void
unpack_RGBA_DXT5(const void *src, GLfloat dst[][4], GLuint n)
{
}


static void
unpack_RGBA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = (const GLfloat *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i*4+0];
      dst[i][GCOMP] = s[i*4+1];
      dst[i][BCOMP] = s[i*4+2];
      dst[i][ACOMP] = s[i*4+3];
   }
}

static void
unpack_RGBA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLhalfARB *s = (const GLhalfARB *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
      dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
      dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
      dst[i][ACOMP] = _mesa_half_to_float(s[i*4+3]);
   }
}

static void
unpack_RGB_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = (const GLfloat *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i*3+0];
      dst[i][GCOMP] = s[i*3+1];
      dst[i][BCOMP] = s[i*3+2];
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_RGB_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLhalfARB *s = (const GLhalfARB *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_half_to_float(s[i*3+0]);
      dst[i][GCOMP] = _mesa_half_to_float(s[i*3+1]);
      dst[i][BCOMP] = _mesa_half_to_float(s[i*3+2]);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_A_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = (const GLfloat *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = s[i];
   }
}

static void
unpack_A_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLhalfARB *s = (const GLhalfARB *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = _mesa_half_to_float(s[i]);
   }
}

static void
unpack_L_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = (const GLfloat *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = s[i];
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_L_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLhalfARB *s = (const GLhalfARB *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = _mesa_half_to_float(s[i]);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_LA_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = (const GLfloat *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = s[i*2+0];
      dst[i][ACOMP] = s[i*2+1];
   }
}

static void
unpack_LA_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLhalfARB *s = (const GLhalfARB *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = _mesa_half_to_float(s[i*2+0]);
      dst[i][ACOMP] = _mesa_half_to_float(s[i*2+1]);
   }
}

static void
unpack_I_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = (const GLfloat *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = s[i];
   }
}

static void
unpack_I_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLhalfARB *s = (const GLhalfARB *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = _mesa_half_to_float(s[i]);
   }
}

static void
unpack_R_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = (const GLfloat *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i];
      dst[i][GCOMP] = 0.0F;
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_R_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLhalfARB *s = (const GLhalfARB *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_half_to_float(s[i]);
      dst[i][GCOMP] = 0.0F;
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_RG_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = (const GLfloat *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i*2+0];
      dst[i][GCOMP] = s[i*2+1];
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_RG_FLOAT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLhalfARB *s = (const GLhalfARB *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_half_to_float(s[i*2+0]);
      dst[i][GCOMP] = _mesa_half_to_float(s[i*2+1]);
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_ALPHA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_ALPHA_INT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_ALPHA_INT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLint *s = (const GLint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_INTENSITY_UINT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_INTENSITY_UINT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_INTENSITY_UINT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_INTENSITY_INT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_INTENSITY_INT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_INTENSITY_INT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLint *s = (const GLint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = (GLfloat) s[i];
   }
}

static void
unpack_LUMINANCE_UINT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_LUMINANCE_UINT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_LUMINANCE_UINT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_LUMINANCE_INT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_LUMINANCE_INT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_LUMINANCE_INT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLint *s = (const GLint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = dst[i][GCOMP] = dst[i][BCOMP] = (GLfloat) s[i];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_LUMINANCE_ALPHA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = (GLfloat) s[2*i+0];
      dst[i][ACOMP] = (GLfloat) s[2*i+1];
   }
}

static void
unpack_LUMINANCE_ALPHA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = (GLfloat) s[2*i+0];
      dst[i][ACOMP] = (GLfloat) s[2*i+1];
   }
}

static void
unpack_LUMINANCE_ALPHA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = (GLfloat) s[2*i+0];
      dst[i][ACOMP] = (GLfloat) s[2*i+1];
   }
}

static void
unpack_LUMINANCE_ALPHA_INT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = (GLfloat) s[2*i+0];
      dst[i][ACOMP] = (GLfloat) s[2*i+1];
   }
}

static void
unpack_LUMINANCE_ALPHA_INT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = (GLfloat) s[2*i+0];
      dst[i][ACOMP] = (GLfloat) s[2*i+1];
   }
}

static void
unpack_LUMINANCE_ALPHA_INT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLint *s = (const GLint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = (GLfloat) s[2*i+0];
      dst[i][ACOMP] = (GLfloat) s[2*i+1];
   }
}

static void
unpack_R_INT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i];
      dst[i][GCOMP] = 0.0;
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RG_INT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*2+0];
      dst[i][GCOMP] = (GLfloat) s[i*2+1];
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGB_INT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*3+0];
      dst[i][GCOMP] = (GLfloat) s[i*3+1];
      dst[i][BCOMP] = (GLfloat) s[i*3+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGBA_INT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
   }
}

static void
unpack_R_INT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i];
      dst[i][GCOMP] = 0.0;
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RG_INT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*2+0];
      dst[i][GCOMP] = (GLfloat) s[i*2+1];
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGB_INT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*3+0];
      dst[i][GCOMP] = (GLfloat) s[i*3+1];
      dst[i][BCOMP] = (GLfloat) s[i*3+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGBA_INT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
   }
}

static void
unpack_R_INT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLint *s = (const GLint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i];
      dst[i][GCOMP] = 0.0;
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RG_INT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLint *s = (const GLint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*2+0];
      dst[i][GCOMP] = (GLfloat) s[i*2+1];
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGB_INT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLint *s = (const GLint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*3+0];
      dst[i][GCOMP] = (GLfloat) s[i*3+1];
      dst[i][BCOMP] = (GLfloat) s[i*3+2];
      dst[i][ACOMP] = 1.0;
   }
}


static void
unpack_RGBA_INT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLint *s = (const GLint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
   }
}

static void
unpack_R_UINT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i];
      dst[i][GCOMP] = 0.0;
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RG_UINT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*2+0];
      dst[i][GCOMP] = (GLfloat) s[i*2+1];
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGB_UINT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*3+0];
      dst[i][GCOMP] = (GLfloat) s[i*3+1];
      dst[i][BCOMP] = (GLfloat) s[i*3+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGBA_UINT8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
   }
}

static void
unpack_R_UINT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i];
      dst[i][GCOMP] = 0.0;
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RG_UINT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*2+0];
      dst[i][GCOMP] = (GLfloat) s[i*2+1];
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGB_UINT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*3+0];
      dst[i][GCOMP] = (GLfloat) s[i*3+1];
      dst[i][BCOMP] = (GLfloat) s[i*3+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGBA_UINT16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
   }
}

static void
unpack_R_UINT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i];
      dst[i][GCOMP] = 0.0;
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RG_UINT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*2+0];
      dst[i][GCOMP] = (GLfloat) s[i*2+1];
      dst[i][BCOMP] = 0.0;
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGB_UINT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*3+0];
      dst[i][GCOMP] = (GLfloat) s[i*3+1];
      dst[i][BCOMP] = (GLfloat) s[i*3+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGBA_UINT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = (GLfloat) s[i*4+3];
   }
}

static void
unpack_R_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = ((const GLbyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
      dst[i][GCOMP] = 0.0F;
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_R8G8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_X8B8G8R8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
      dst[i][ACOMP] = 1.0f;
   }
}

static void
unpack_A8B8G8R8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
   }
}

static void
unpack_R8G8B8A8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 24) );
   }
}

static void
unpack_R_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = ((const GLshort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
      dst[i][GCOMP] = 0.0F;
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_R16G16_SNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_RGB_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+0] );
      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+1] );
      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*3+2] );
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_RGBA_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*4+3] );
   }
}

static void
unpack_RGBA_16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
      dst[i][ACOMP] = USHORT_TO_FLOAT( s[i*4+3] );
   }
}

static void
unpack_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_SIGNED_RED_RGTC1(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_SIGNED_RG_RGTC2(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_SIGNED_L_LATC1(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_SIGNED_LA_LATC2(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC1_RGB8(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_RGB8(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_SRGB8(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_RGBA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_SRGB8_ALPHA8_EAC(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_SIGNED_R11_EAC(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_SIGNED_RG11_EAC(const void *src, GLfloat dst[][4], GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
                                      GLuint n)
{
   /* XXX to do */
}

static void
unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1(const void *src, GLfloat dst[][4],
                                      GLuint n)
{
   /* XXX to do */
}

static void
unpack_A_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = ((const GLbyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = 0.0F;
      dst[i][GCOMP] = 0.0F;
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
   }
}

static void
unpack_L_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = ((const GLbyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( s[i] );
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_L8A8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = ((const GLshort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
   }
}

static void
unpack_I_SNORM8(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = ((const GLbyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = BYTE_TO_FLOAT_TEX( s[i] );
   }
}

static void
unpack_A_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = ((const GLshort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = 0.0F;
      dst[i][GCOMP] = 0.0F;
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
   }
}

static void
unpack_L_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = ((const GLshort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i] );
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_LA_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*2+0] );
      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i*2+1] );
   }
}

static void
unpack_I_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = ((const GLshort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = SHORT_TO_FLOAT_TEX( s[i] );
   }
}

static void
unpack_R9G9B9E5_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      rgb9e5_to_float3(s[i], dst[i]);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_R11G11B10_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      r11g11b10f_to_float3(s[i], dst[i]);
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_XRGB4444_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >>  8) & 0xf) * (1.0F / 15.0F);
      dst[i][GCOMP] = ((s[i] >>  4) & 0xf) * (1.0F / 15.0F);
      dst[i][BCOMP] = ((s[i]      ) & 0xf) * (1.0F / 15.0F);
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_XRGB1555_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >> 10) & 0x1f) * (1.0F / 31.0F);
      dst[i][GCOMP] = ((s[i] >>  5) & 0x1f) * (1.0F / 31.0F);
      dst[i][BCOMP] = ((s[i] >>  0) & 0x1f) * (1.0F / 31.0F);
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_XBGR8888_SNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i]      ) );
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >>  8) );
      dst[i][BCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 16) );
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_R8G8B8X8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
      dst[i][ACOMP] = UBYTE_TO_FLOAT( s[i] >> 24 ); /* linear! */
   }
}

static void
unpack_XBGR8888_UINT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i*4+0];
      dst[i][GCOMP] = s[i*4+1];
      dst[i][BCOMP] = s[i*4+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_XBGR8888_SINT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLbyte *s = (const GLbyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i*4+0];
      dst[i][GCOMP] = s[i*4+1];
      dst[i][BCOMP] = s[i*4+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_B10G10R10X2_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
      dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
      dst[i][BCOMP] = ((s[i] >>  0) & 0x3ff) * (1.0F / 1023.0F);
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGBX_UNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = USHORT_TO_FLOAT( s[i*4+0] );
      dst[i][GCOMP] = USHORT_TO_FLOAT( s[i*4+1] );
      dst[i][BCOMP] = USHORT_TO_FLOAT( s[i*4+2] );
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGBX_SNORM16(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+0] );
      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+1] );
      dst[i][BCOMP] = SHORT_TO_FLOAT_TEX( s[i*4+2] );
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_XBGR16161616_FLOAT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_half_to_float(s[i*4+0]);
      dst[i][GCOMP] = _mesa_half_to_float(s[i*4+1]);
      dst[i][BCOMP] = _mesa_half_to_float(s[i*4+2]);
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_XBGR16161616_UINT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = (const GLushort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_XBGR16161616_SINT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLshort *s = (const GLshort *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_RGBX_FLOAT32(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLfloat *s = (const GLfloat *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i*4+0];
      dst[i][GCOMP] = s[i*4+1];
      dst[i][BCOMP] = s[i*4+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_XBGR32323232_UINT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = (const GLuint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_XBGR32323232_SINT(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLint *s = (const GLint *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLfloat) s[i*4+0];
      dst[i][GCOMP] = (GLfloat) s[i*4+1];
      dst[i][BCOMP] = (GLfloat) s[i*4+2];
      dst[i][ACOMP] = 1.0;
   }
}

static void
unpack_R10G10B10A2_UNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = ((s[i] >> 0) & 0x3ff) * (1.0F / 1023.0F);
      dst[i][GCOMP] = ((s[i] >> 10) & 0x3ff) * (1.0F / 1023.0F);
      dst[i][BCOMP] = ((s[i] >> 20) & 0x3ff) * (1.0F / 1023.0F);
      dst[i][ACOMP] = ((s[i] >> 30) &  0x03) * (1.0F / 3.0F);
   }
}

static void
unpack_G8R8_SNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] >> 8) );
      dst[i][GCOMP] = BYTE_TO_FLOAT_TEX( (GLbyte) (s[i] & 0xff) );
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_G16R16_SNORM(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] >> 16) );
      dst[i][GCOMP] = SHORT_TO_FLOAT_TEX( (GLshort) (s[i] & 0xffff) );
      dst[i][BCOMP] = 0.0F;
      dst[i][ACOMP] = 1.0F;
   }
}

static void
unpack_B8G8R8X8_SRGB(const void *src, GLfloat dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = _mesa_nonlinear_to_linear( (s[i] >> 16) & 0xff );
      dst[i][GCOMP] = _mesa_nonlinear_to_linear( (s[i] >>  8) & 0xff );
      dst[i][BCOMP] = _mesa_nonlinear_to_linear( (s[i]      ) & 0xff );
      dst[i][ACOMP] = 1.0F;
   }
}

/**
 * Return the unpacker function for the given format.
 */
static unpack_rgba_func
get_unpack_rgba_function(mesa_format format)
{
   static unpack_rgba_func table[MESA_FORMAT_COUNT];
   static GLboolean initialized = GL_FALSE;

   if (!initialized) {
      table[MESA_FORMAT_NONE] = NULL;

      table[MESA_FORMAT_A8B8G8R8_UNORM] = unpack_A8B8G8R8_UNORM;
      table[MESA_FORMAT_R8G8B8A8_UNORM] = unpack_R8G8B8A8_UNORM;
      table[MESA_FORMAT_B8G8R8A8_UNORM] = unpack_B8G8R8A8_UNORM;
      table[MESA_FORMAT_A8R8G8B8_UNORM] = unpack_A8R8G8B8_UNORM;
      table[MESA_FORMAT_X8B8G8R8_UNORM] = unpack_RGBX8888;
      table[MESA_FORMAT_R8G8B8X8_UNORM] = unpack_RGBX8888_REV;
      table[MESA_FORMAT_B8G8R8X8_UNORM] = unpack_B8G8R8X8_UNORM;
      table[MESA_FORMAT_X8R8G8B8_UNORM] = unpack_X8R8G8B8_UNORM;
      table[MESA_FORMAT_BGR_UNORM8] = unpack_BGR_UNORM8;
      table[MESA_FORMAT_RGB_UNORM8] = unpack_RGB_UNORM8;
      table[MESA_FORMAT_B5G6R5_UNORM] = unpack_B5G6R5_UNORM;
      table[MESA_FORMAT_R5G6B5_UNORM] = unpack_R5G6B5_UNORM;
      table[MESA_FORMAT_B4G4R4A4_UNORM] = unpack_B4G4R4A4_UNORM;
      table[MESA_FORMAT_A4R4G4B4_UNORM] = unpack_A4R4G4B4_UNORM;
      table[MESA_FORMAT_A1B5G5R5_UNORM] = unpack_A1B5G5R5_UNORM;
      table[MESA_FORMAT_B5G5R5A1_UNORM] = unpack_B5G5R5A1_UNORM;
      table[MESA_FORMAT_A1R5G5B5_UNORM] = unpack_A1R5G5B5_UNORM;
      table[MESA_FORMAT_L4A4_UNORM] = unpack_L4A4_UNORM;
      table[MESA_FORMAT_L8A8_UNORM] = unpack_L8A8_UNORM;
      table[MESA_FORMAT_A8L8_UNORM] = unpack_A8L8_UNORM;
      table[MESA_FORMAT_L16A16_UNORM] = unpack_L16A16_UNORM;
      table[MESA_FORMAT_A16L16_UNORM] = unpack_A16L16_UNORM;
      table[MESA_FORMAT_B2G3R3_UNORM] = unpack_B2G3R3_UNORM;
      table[MESA_FORMAT_A_UNORM8] = unpack_A_UNORM8;
      table[MESA_FORMAT_A_UNORM16] = unpack_A_UNORM16;
      table[MESA_FORMAT_L_UNORM8] = unpack_L_UNORM8;
      table[MESA_FORMAT_L_UNORM16] = unpack_L_UNORM16;
      table[MESA_FORMAT_I_UNORM8] = unpack_I_UNORM8;
      table[MESA_FORMAT_I_UNORM16] = unpack_I_UNORM16;
      table[MESA_FORMAT_YCBCR] = unpack_YCBCR;
      table[MESA_FORMAT_YCBCR_REV] = unpack_YCBCR_REV;
      table[MESA_FORMAT_R_UNORM8] = unpack_R_UNORM8;
      table[MESA_FORMAT_R8G8_UNORM] = unpack_R8G8_UNORM;
      table[MESA_FORMAT_G8R8_UNORM] = unpack_G8R8_UNORM;
      table[MESA_FORMAT_R_UNORM16] = unpack_R_UNORM16;
      table[MESA_FORMAT_R16G16_UNORM] = unpack_R16G16_UNORM;
      table[MESA_FORMAT_G16R16_UNORM] = unpack_G16R16_UNORM;
      table[MESA_FORMAT_B10G10R10A2_UNORM] = unpack_B10G10R10A2_UNORM;
      table[MESA_FORMAT_B10G10R10A2_UINT] = unpack_B10G10R10A2_UINT;
      table[MESA_FORMAT_R10G10B10A2_UINT] = unpack_R10G10B10A2_UINT;
      table[MESA_FORMAT_S8_UINT_Z24_UNORM] = unpack_S8_UINT_Z24_UNORM;
      table[MESA_FORMAT_Z24_UNORM_S8_UINT] = unpack_Z24_UNORM_S8_UINT;
      table[MESA_FORMAT_Z_UNORM16] = unpack_Z_UNORM16;
      table[MESA_FORMAT_Z24_UNORM_X8_UINT] = unpack_Z24_UNORM_X8_UINT;
      table[MESA_FORMAT_X8_UINT_Z24_UNORM] = unpack_X8_UINT_Z24_UNORM;
      table[MESA_FORMAT_Z_UNORM32] = unpack_Z_UNORM32;
      table[MESA_FORMAT_S_UINT8] = unpack_S8;
      table[MESA_FORMAT_BGR_SRGB8] = unpack_BGR_SRGB8;
      table[MESA_FORMAT_A8B8G8R8_SRGB] = unpack_A8B8G8R8_SRGB;
      table[MESA_FORMAT_B8G8R8A8_SRGB] = unpack_B8G8R8A8_SRGB;
      table[MESA_FORMAT_R8G8B8A8_SRGB] = unpack_R8G8B8A8_SRGB;
      table[MESA_FORMAT_L_SRGB8] = unpack_L_SRGB8;
      table[MESA_FORMAT_L8A8_SRGB] = unpack_L8A8_SRGB;
      table[MESA_FORMAT_SRGB_DXT1] = unpack_SRGB_DXT1;
      table[MESA_FORMAT_SRGBA_DXT1] = unpack_SRGBA_DXT1;
      table[MESA_FORMAT_SRGBA_DXT3] = unpack_SRGBA_DXT3;
      table[MESA_FORMAT_SRGBA_DXT5] = unpack_SRGBA_DXT5;

      table[MESA_FORMAT_RGB_FXT1] = unpack_RGB_FXT1;
      table[MESA_FORMAT_RGBA_FXT1] = unpack_RGBA_FXT1;
      table[MESA_FORMAT_RGB_DXT1] = unpack_RGB_DXT1;
      table[MESA_FORMAT_RGBA_DXT1] = unpack_RGBA_DXT1;
      table[MESA_FORMAT_RGBA_DXT3] = unpack_RGBA_DXT3;
      table[MESA_FORMAT_RGBA_DXT5] = unpack_RGBA_DXT5;

      table[MESA_FORMAT_RGBA_FLOAT32] = unpack_RGBA_FLOAT32;
      table[MESA_FORMAT_RGBA_FLOAT16] = unpack_RGBA_FLOAT16;
      table[MESA_FORMAT_RGB_FLOAT32] = unpack_RGB_FLOAT32;
      table[MESA_FORMAT_RGB_FLOAT16] = unpack_RGB_FLOAT16;
      table[MESA_FORMAT_A_FLOAT32] = unpack_A_FLOAT32;
      table[MESA_FORMAT_A_FLOAT16] = unpack_A_FLOAT16;
      table[MESA_FORMAT_L_FLOAT32] = unpack_L_FLOAT32;
      table[MESA_FORMAT_L_FLOAT16] = unpack_L_FLOAT16;
      table[MESA_FORMAT_LA_FLOAT32] = unpack_LA_FLOAT32;
      table[MESA_FORMAT_LA_FLOAT16] = unpack_LA_FLOAT16;
      table[MESA_FORMAT_I_FLOAT32] = unpack_I_FLOAT32;
      table[MESA_FORMAT_I_FLOAT16] = unpack_I_FLOAT16;
      table[MESA_FORMAT_R_FLOAT32] = unpack_R_FLOAT32;
      table[MESA_FORMAT_R_FLOAT16] = unpack_R_FLOAT16;
      table[MESA_FORMAT_RG_FLOAT32] = unpack_RG_FLOAT32;
      table[MESA_FORMAT_RG_FLOAT16] = unpack_RG_FLOAT16;

      table[MESA_FORMAT_A_UINT8] = unpack_ALPHA_UINT8;
      table[MESA_FORMAT_A_UINT16] = unpack_ALPHA_UINT16;
      table[MESA_FORMAT_A_UINT32] = unpack_ALPHA_UINT32;
      table[MESA_FORMAT_A_SINT8] = unpack_ALPHA_INT8;
      table[MESA_FORMAT_A_SINT16] = unpack_ALPHA_INT16;
      table[MESA_FORMAT_A_SINT32] = unpack_ALPHA_INT32;

      table[MESA_FORMAT_I_UINT8] = unpack_INTENSITY_UINT8;
      table[MESA_FORMAT_I_UINT16] = unpack_INTENSITY_UINT16;
      table[MESA_FORMAT_I_UINT32] = unpack_INTENSITY_UINT32;
      table[MESA_FORMAT_I_SINT8] = unpack_INTENSITY_INT8;
      table[MESA_FORMAT_I_SINT16] = unpack_INTENSITY_INT16;
      table[MESA_FORMAT_I_SINT32] = unpack_INTENSITY_INT32;

      table[MESA_FORMAT_L_UINT8] = unpack_LUMINANCE_UINT8;
      table[MESA_FORMAT_L_UINT16] = unpack_LUMINANCE_UINT16;
      table[MESA_FORMAT_L_UINT32] = unpack_LUMINANCE_UINT32;
      table[MESA_FORMAT_L_SINT8] = unpack_LUMINANCE_INT8;
      table[MESA_FORMAT_L_SINT16] = unpack_LUMINANCE_INT16;
      table[MESA_FORMAT_L_SINT32] = unpack_LUMINANCE_INT32;

      table[MESA_FORMAT_LA_UINT8] = unpack_LUMINANCE_ALPHA_UINT8;
      table[MESA_FORMAT_LA_UINT16] = unpack_LUMINANCE_ALPHA_UINT16;
      table[MESA_FORMAT_LA_UINT32] = unpack_LUMINANCE_ALPHA_UINT32;
      table[MESA_FORMAT_LA_SINT8] = unpack_LUMINANCE_ALPHA_INT8;
      table[MESA_FORMAT_LA_SINT16] = unpack_LUMINANCE_ALPHA_INT16;
      table[MESA_FORMAT_LA_SINT32] = unpack_LUMINANCE_ALPHA_INT32;

      table[MESA_FORMAT_R_SINT8] = unpack_R_INT8;
      table[MESA_FORMAT_RG_SINT8] = unpack_RG_INT8;
      table[MESA_FORMAT_RGB_SINT8] = unpack_RGB_INT8;
      table[MESA_FORMAT_RGBA_SINT8] = unpack_RGBA_INT8;
      table[MESA_FORMAT_R_SINT16] = unpack_R_INT16;
      table[MESA_FORMAT_RG_SINT16] = unpack_RG_INT16;
      table[MESA_FORMAT_RGB_SINT16] = unpack_RGB_INT16;
      table[MESA_FORMAT_RGBA_SINT16] = unpack_RGBA_INT16;
      table[MESA_FORMAT_R_SINT32] = unpack_R_INT32;
      table[MESA_FORMAT_RG_SINT32] = unpack_RG_INT32;
      table[MESA_FORMAT_RGB_SINT32] = unpack_RGB_INT32;
      table[MESA_FORMAT_RGBA_SINT32] = unpack_RGBA_INT32;
      table[MESA_FORMAT_R_UINT8] = unpack_R_UINT8;
      table[MESA_FORMAT_RG_UINT8] = unpack_RG_UINT8;
      table[MESA_FORMAT_RGB_UINT8] = unpack_RGB_UINT8;
      table[MESA_FORMAT_RGBA_UINT8] = unpack_RGBA_UINT8;
      table[MESA_FORMAT_R_UINT16] = unpack_R_UINT16;
      table[MESA_FORMAT_RG_UINT16] = unpack_RG_UINT16;
      table[MESA_FORMAT_RGB_UINT16] = unpack_RGB_UINT16;
      table[MESA_FORMAT_RGBA_UINT16] = unpack_RGBA_UINT16;
      table[MESA_FORMAT_R_UINT32] = unpack_R_UINT32;
      table[MESA_FORMAT_RG_UINT32] = unpack_RG_UINT32;
      table[MESA_FORMAT_RGB_UINT32] = unpack_RGB_UINT32;
      table[MESA_FORMAT_RGBA_UINT32] = unpack_RGBA_UINT32;

      table[MESA_FORMAT_R_SNORM8] = unpack_R_SNORM8;
      table[MESA_FORMAT_R8G8_SNORM] = unpack_R8G8_SNORM;
      table[MESA_FORMAT_X8B8G8R8_SNORM] = unpack_X8B8G8R8_SNORM;
      table[MESA_FORMAT_A8B8G8R8_SNORM] = unpack_A8B8G8R8_SNORM;
      table[MESA_FORMAT_R8G8B8A8_SNORM] = unpack_R8G8B8A8_SNORM;
      table[MESA_FORMAT_R_SNORM16] = unpack_R_SNORM16;
      table[MESA_FORMAT_R16G16_SNORM] = unpack_R16G16_SNORM;
      table[MESA_FORMAT_RGB_SNORM16] = unpack_RGB_SNORM16;
      table[MESA_FORMAT_RGBA_SNORM16] = unpack_RGBA_SNORM16;
      table[MESA_FORMAT_RGBA_UNORM16] = unpack_RGBA_16;

      table[MESA_FORMAT_R_RGTC1_UNORM] = unpack_RED_RGTC1;
      table[MESA_FORMAT_R_RGTC1_SNORM] = unpack_SIGNED_RED_RGTC1;
      table[MESA_FORMAT_RG_RGTC2_UNORM] = unpack_RG_RGTC2;
      table[MESA_FORMAT_RG_RGTC2_SNORM] = unpack_SIGNED_RG_RGTC2;

      table[MESA_FORMAT_L_LATC1_UNORM] = unpack_L_LATC1;
      table[MESA_FORMAT_L_LATC1_SNORM] = unpack_SIGNED_L_LATC1;
      table[MESA_FORMAT_LA_LATC2_UNORM] = unpack_LA_LATC2;
      table[MESA_FORMAT_LA_LATC2_SNORM] = unpack_SIGNED_LA_LATC2;

      table[MESA_FORMAT_ETC1_RGB8] = unpack_ETC1_RGB8;
      table[MESA_FORMAT_ETC2_RGB8] = unpack_ETC2_RGB8;
      table[MESA_FORMAT_ETC2_SRGB8] = unpack_ETC2_SRGB8;
      table[MESA_FORMAT_ETC2_RGBA8_EAC] = unpack_ETC2_RGBA8_EAC;
      table[MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC] = unpack_ETC2_SRGB8_ALPHA8_EAC;
      table[MESA_FORMAT_ETC2_R11_EAC] = unpack_ETC2_R11_EAC;
      table[MESA_FORMAT_ETC2_RG11_EAC] = unpack_ETC2_RG11_EAC;
      table[MESA_FORMAT_ETC2_SIGNED_R11_EAC] = unpack_ETC2_SIGNED_R11_EAC;
      table[MESA_FORMAT_ETC2_SIGNED_RG11_EAC] = unpack_ETC2_SIGNED_RG11_EAC;
      table[MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1] =
         unpack_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
      table[MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1] =
         unpack_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
      table[MESA_FORMAT_A_SNORM8] = unpack_A_SNORM8;
      table[MESA_FORMAT_L_SNORM8] = unpack_L_SNORM8;
      table[MESA_FORMAT_L8A8_SNORM] = unpack_L8A8_SNORM;
      table[MESA_FORMAT_I_SNORM8] = unpack_I_SNORM8;
      table[MESA_FORMAT_A_SNORM16] = unpack_A_SNORM16;
      table[MESA_FORMAT_L_SNORM16] = unpack_L_SNORM16;
      table[MESA_FORMAT_LA_SNORM16] = unpack_LA_SNORM16;
      table[MESA_FORMAT_I_SNORM16] = unpack_I_SNORM16;

      table[MESA_FORMAT_R9G9B9E5_FLOAT] = unpack_R9G9B9E5_FLOAT;
      table[MESA_FORMAT_R11G11B10_FLOAT] = unpack_R11G11B10_FLOAT;

      table[MESA_FORMAT_Z_FLOAT32] = unpack_Z_FLOAT32;
      table[MESA_FORMAT_Z32_FLOAT_S8X24_UINT] = unpack_Z32_FLOAT_S8X24_UINT;

      table[MESA_FORMAT_B4G4R4X4_UNORM] = unpack_XRGB4444_UNORM;
      table[MESA_FORMAT_B5G5R5X1_UNORM] = unpack_XRGB1555_UNORM;
      table[MESA_FORMAT_R8G8B8X8_SNORM] = unpack_XBGR8888_SNORM;
      table[MESA_FORMAT_R8G8B8X8_SRGB] = unpack_R8G8B8X8_SRGB;
      table[MESA_FORMAT_RGBX_UINT8] = unpack_XBGR8888_UINT;
      table[MESA_FORMAT_RGBX_SINT8] = unpack_XBGR8888_SINT;
      table[MESA_FORMAT_B10G10R10X2_UNORM] = unpack_B10G10R10X2_UNORM;
      table[MESA_FORMAT_RGBX_UNORM16] = unpack_RGBX_UNORM16;
      table[MESA_FORMAT_RGBX_SNORM16] = unpack_RGBX_SNORM16;
      table[MESA_FORMAT_RGBX_FLOAT16] = unpack_XBGR16161616_FLOAT;
      table[MESA_FORMAT_RGBX_UINT16] = unpack_XBGR16161616_UINT;
      table[MESA_FORMAT_RGBX_SINT16] = unpack_XBGR16161616_SINT;
      table[MESA_FORMAT_RGBX_FLOAT32] = unpack_RGBX_FLOAT32;
      table[MESA_FORMAT_RGBX_UINT32] = unpack_XBGR32323232_UINT;
      table[MESA_FORMAT_RGBX_SINT32] = unpack_XBGR32323232_SINT;

      table[MESA_FORMAT_R10G10B10A2_UNORM] = unpack_R10G10B10A2_UNORM;

      table[MESA_FORMAT_G8R8_SNORM] = unpack_G8R8_SNORM;
      table[MESA_FORMAT_G16R16_SNORM] = unpack_G16R16_SNORM;

      table[MESA_FORMAT_B8G8R8X8_SRGB] = unpack_B8G8R8X8_SRGB;

      initialized = GL_TRUE;
   }

   if (table[format] == NULL) {
      _mesa_problem(NULL, "unsupported unpack for format %s",
                    _mesa_get_format_name(format));
   }

   return table[format];
}


/**
 * Unpack rgba colors, returning as GLfloat values.
 */
void
_mesa_unpack_rgba_row(mesa_format format, GLuint n,
                      const void *src, GLfloat dst[][4])
{
   unpack_rgba_func unpack = get_unpack_rgba_function(format);
   unpack(src, dst, n);
}


/**********************************************************************/
/*  Unpack, returning GLubyte colors                                  */
/**********************************************************************/


static void
unpack_ubyte_A8B8G8R8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (s[i] >> 24);
      dst[i][GCOMP] = (s[i] >> 16) & 0xff;
      dst[i][BCOMP] = (s[i] >>  8) & 0xff;
      dst[i][ACOMP] = (s[i]      ) & 0xff;
   }
}

static void
unpack_ubyte_R8G8B8A8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (s[i]      ) & 0xff;
      dst[i][GCOMP] = (s[i] >>  8) & 0xff;
      dst[i][BCOMP] = (s[i] >> 16) & 0xff;
      dst[i][ACOMP] = (s[i] >> 24);
   }
}

static void
unpack_ubyte_B8G8R8A8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (s[i] >> 16) & 0xff;
      dst[i][GCOMP] = (s[i] >>  8) & 0xff;
      dst[i][BCOMP] = (s[i]      ) & 0xff;
      dst[i][ACOMP] = (s[i] >> 24);
   }
}

static void
unpack_ubyte_A8R8G8B8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (s[i] >>  8) & 0xff;
      dst[i][GCOMP] = (s[i] >> 16) & 0xff;
      dst[i][BCOMP] = (s[i] >> 24);
      dst[i][ACOMP] = (s[i]      ) & 0xff;
   }
}

static void
unpack_ubyte_RGBX8888(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (s[i] >> 24);
      dst[i][GCOMP] = (s[i] >> 16) & 0xff;
      dst[i][BCOMP] = (s[i] >>  8) & 0xff;
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_RGBX8888_REV(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (s[i]      ) & 0xff;
      dst[i][GCOMP] = (s[i] >>  8) & 0xff;
      dst[i][BCOMP] = (s[i] >> 16) & 0xff;
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_B8G8R8X8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (s[i] >> 16) & 0xff;
      dst[i][GCOMP] = (s[i] >>  8) & 0xff;
      dst[i][BCOMP] = (s[i]      ) & 0xff;
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_X8R8G8B8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (s[i] >>  8) & 0xff;
      dst[i][GCOMP] = (s[i] >> 16) & 0xff;
      dst[i][BCOMP] = (s[i] >> 24);
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_BGR_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i*3+2];
      dst[i][GCOMP] = s[i*3+1];
      dst[i][BCOMP] = s[i*3+0];
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_RGB_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLubyte *s = (const GLubyte *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i*3+0];
      dst[i][GCOMP] = s[i*3+1];
      dst[i][BCOMP] = s[i*3+2];
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_B5G6R5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
      dst[i][GCOMP] = EXPAND_6_8((s[i] >> 5 ) & 0x3f);
      dst[i][BCOMP] = EXPAND_5_8( s[i]        & 0x1f);
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_R5G6B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   /* Warning: this function does not match the current Mesa definition
    * of MESA_FORMAT_R5G6B5_UNORM.
    */
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      GLuint t = (s[i] >> 8) | (s[i] << 8); /* byte swap */
      dst[i][RCOMP] = EXPAND_5_8((t >> 11) & 0x1f);
      dst[i][GCOMP] = EXPAND_6_8((t >> 5 ) & 0x3f);
      dst[i][BCOMP] = EXPAND_5_8( t        & 0x1f);
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_B4G4R4A4_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = EXPAND_4_8((s[i] >>  8) & 0xf);
      dst[i][GCOMP] = EXPAND_4_8((s[i] >>  4) & 0xf);
      dst[i][BCOMP] = EXPAND_4_8((s[i]      ) & 0xf);
      dst[i][ACOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
   }
}

static void
unpack_ubyte_A4R4G4B4_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = EXPAND_4_8((s[i] >>  4) & 0xf);
      dst[i][GCOMP] = EXPAND_4_8((s[i] >>  8) & 0xf);
      dst[i][BCOMP] = EXPAND_4_8((s[i] >> 12) & 0xf);
      dst[i][ACOMP] = EXPAND_4_8((s[i]      ) & 0xf);
   }
}

static void
unpack_ubyte_A1B5G5R5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = EXPAND_5_8((s[i] >> 11) & 0x1f);
      dst[i][GCOMP] = EXPAND_5_8((s[i] >>  6) & 0x1f);
      dst[i][BCOMP] = EXPAND_5_8((s[i] >>  1) & 0x1f);
      dst[i][ACOMP] = EXPAND_1_8((s[i]      ) & 0x01);
   }
}

static void
unpack_ubyte_B5G5R5A1_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = EXPAND_5_8((s[i] >> 10) & 0x1f);
      dst[i][GCOMP] = EXPAND_5_8((s[i] >>  5) & 0x1f);
      dst[i][BCOMP] = EXPAND_5_8((s[i] >>  0) & 0x1f);
      dst[i][ACOMP] = EXPAND_1_8((s[i] >> 15) & 0x01);
   }
}

static void
unpack_ubyte_A1R5G5B5_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   /* Warning: this function does not match the current Mesa definition
    * of MESA_FORMAT_A1R5G5B5_UNORM.
    */
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      GLushort tmp = (s[i] << 8) | (s[i] >> 8); /* byteswap */
      dst[i][RCOMP] = EXPAND_5_8((tmp >> 10) & 0x1f);
      dst[i][GCOMP] = EXPAND_5_8((tmp >>  5) & 0x1f);
      dst[i][BCOMP] = EXPAND_5_8((tmp >>  0) & 0x1f);
      dst[i][ACOMP] = EXPAND_1_8((tmp >> 15) & 0x01);
   }
}

static void
unpack_ubyte_L4A4_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xf);
      dst[i][ACOMP] = EXPAND_4_8(s[i] >> 4);
   }
}

static void
unpack_ubyte_L8A8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = 
      dst[i][GCOMP] = 
      dst[i][BCOMP] = EXPAND_4_8(s[i] & 0xff);
      dst[i][ACOMP] = EXPAND_4_8(s[i] >> 8);
   }
}

static void
unpack_ubyte_A8L8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = 
      dst[i][GCOMP] = 
      dst[i][BCOMP] = EXPAND_4_8(s[i] >> 8);
      dst[i][ACOMP] = EXPAND_4_8(s[i] & 0xff);
   }
}

static void
unpack_ubyte_B2G3R3_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = EXPAND_3_8((s[i] >> 5) & 0x7);
      dst[i][GCOMP] = EXPAND_3_8((s[i] >> 2) & 0x7);
      dst[i][BCOMP] = EXPAND_2_8((s[i]     ) & 0x3);
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_A_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = 0;
      dst[i][ACOMP] = s[i];
   }
}

static void
unpack_ubyte_L_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] = s[i];
      dst[i][ACOMP] = 0xff;
   }
}


static void
unpack_ubyte_I_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] =
      dst[i][GCOMP] =
      dst[i][BCOMP] =
      dst[i][ACOMP] = s[i];
   }
}

static void
unpack_ubyte_R_UNORM8(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLubyte *s = ((const GLubyte *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][0] = s[i];
      dst[i][1] =
      dst[i][2] = 0;
      dst[i][3] = 0xff;
   }
}

static void
unpack_ubyte_R8G8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i] & 0xff;
      dst[i][GCOMP] = s[i] >> 8;
      dst[i][BCOMP] = 0;
      dst[i][ACOMP] = 0xff;
   }
}

static void
unpack_ubyte_G8R8_UNORM(const void *src, GLubyte dst[][4], GLuint n)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = s[i] >> 8;
      dst[i][GCOMP] = s[i] & 0xff;
      dst[i][BCOMP] = 0;
      dst[i][ACOMP] = 0xff;
   }
}


/**
 * Unpack rgba colors, returning as GLubyte values.  This should usually
 * only be used for unpacking formats that use 8 bits or less per channel.
 */
void
_mesa_unpack_ubyte_rgba_row(mesa_format format, GLuint n,
                            const void *src, GLubyte dst[][4])
{
   switch (format) {
   case MESA_FORMAT_A8B8G8R8_UNORM:
      unpack_ubyte_A8B8G8R8_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_R8G8B8A8_UNORM:
      unpack_ubyte_R8G8B8A8_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_B8G8R8A8_UNORM:
      unpack_ubyte_B8G8R8A8_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_A8R8G8B8_UNORM:
      unpack_ubyte_A8R8G8B8_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_X8B8G8R8_UNORM:
      unpack_ubyte_RGBX8888(src, dst, n);
      break;
   case MESA_FORMAT_R8G8B8X8_UNORM:
      unpack_ubyte_RGBX8888_REV(src, dst, n);
      break;
   case MESA_FORMAT_B8G8R8X8_UNORM:
      unpack_ubyte_B8G8R8X8_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_X8R8G8B8_UNORM:
      unpack_ubyte_X8R8G8B8_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_BGR_UNORM8:
      unpack_ubyte_BGR_UNORM8(src, dst, n);
      break;
   case MESA_FORMAT_RGB_UNORM8:
      unpack_ubyte_RGB_UNORM8(src, dst, n);
      break;
   case MESA_FORMAT_B5G6R5_UNORM:
      unpack_ubyte_B5G6R5_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_R5G6B5_UNORM:
      unpack_ubyte_R5G6B5_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_B4G4R4A4_UNORM:
      unpack_ubyte_B4G4R4A4_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_A4R4G4B4_UNORM:
      unpack_ubyte_A4R4G4B4_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_A1B5G5R5_UNORM:
      unpack_ubyte_A1B5G5R5_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_B5G5R5A1_UNORM:
      unpack_ubyte_B5G5R5A1_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_A1R5G5B5_UNORM:
      unpack_ubyte_A1R5G5B5_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_L4A4_UNORM:
      unpack_ubyte_L4A4_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_L8A8_UNORM:
      unpack_ubyte_L8A8_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_A8L8_UNORM:
      unpack_ubyte_A8L8_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_B2G3R3_UNORM:
      unpack_ubyte_B2G3R3_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_A_UNORM8:
      unpack_ubyte_A_UNORM8(src, dst, n);
      break;
   case MESA_FORMAT_L_UNORM8:
      unpack_ubyte_L_UNORM8(src, dst, n);
      break;
   case MESA_FORMAT_I_UNORM8:
      unpack_ubyte_I_UNORM8(src, dst, n);
      break;
   case MESA_FORMAT_R_UNORM8:
      unpack_ubyte_R_UNORM8(src, dst, n);
      break;
   case MESA_FORMAT_R8G8_UNORM:
      unpack_ubyte_R8G8_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_G8R8_UNORM:
      unpack_ubyte_G8R8_UNORM(src, dst, n);
      break;
   default:
      /* get float values, convert to ubyte */
      {
         GLfloat *tmp = malloc(n * 4 * sizeof(GLfloat));
         if (tmp) {
            GLuint i;
            _mesa_unpack_rgba_row(format, n, src, (GLfloat (*)[4]) tmp);
            for (i = 0; i < n; i++) {
               UNCLAMPED_FLOAT_TO_UBYTE(dst[i][0], tmp[i*4+0]);
               UNCLAMPED_FLOAT_TO_UBYTE(dst[i][1], tmp[i*4+1]);
               UNCLAMPED_FLOAT_TO_UBYTE(dst[i][2], tmp[i*4+2]);
               UNCLAMPED_FLOAT_TO_UBYTE(dst[i][3], tmp[i*4+3]);
            }
            free(tmp);
         }
      }
      break;
   }
}


/**********************************************************************/
/*  Unpack, returning GLuint colors                                   */
/**********************************************************************/

static void
unpack_int_rgba_RGBA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
{
   memcpy(dst, src, n * 4 * sizeof(GLuint));
}

static void
unpack_int_rgba_RGBA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 4 + 0];
      dst[i][1] = src[i * 4 + 1];
      dst[i][2] = src[i * 4 + 2];
      dst[i][3] = src[i * 4 + 3];
   }
}

static void
unpack_int_rgba_RGBA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 4 + 0];
      dst[i][1] = src[i * 4 + 1];
      dst[i][2] = src[i * 4 + 2];
      dst[i][3] = src[i * 4 + 3];
   }
}

static void
unpack_int_rgba_RGBA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 4 + 0];
      dst[i][1] = src[i * 4 + 1];
      dst[i][2] = src[i * 4 + 2];
      dst[i][3] = src[i * 4 + 3];
   }
}

static void
unpack_int_rgba_RGBA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 4 + 0];
      dst[i][1] = src[i * 4 + 1];
      dst[i][2] = src[i * 4 + 2];
      dst[i][3] = src[i * 4 + 3];
   }
}

static void
unpack_int_rgba_B8G8R8A8_UNORM(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
      dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
      dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
      dst[i][ACOMP] = (GLubyte) src[i * 4 + 3];
   }
}

static void
unpack_int_rgba_B8G8R8X8_UNORM(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][RCOMP] = (GLubyte) src[i * 4 + 2];
      dst[i][GCOMP] = (GLubyte) src[i * 4 + 1];
      dst[i][BCOMP] = (GLubyte) src[i * 4 + 0];
      dst[i][ACOMP] = (GLubyte) 0xff;
   }
}

static void
unpack_int_rgba_RGB_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 3 + 0];
      dst[i][1] = src[i * 3 + 1];
      dst[i][2] = src[i * 3 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_RGB_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 3 + 0];
      dst[i][1] = src[i * 3 + 1];
      dst[i][2] = src[i * 3 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_RGB_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 3 + 0];
      dst[i][1] = src[i * 3 + 1];
      dst[i][2] = src[i * 3 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_RGB_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 3 + 0];
      dst[i][1] = src[i * 3 + 1];
      dst[i][2] = src[i * 3 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_RGB_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 3 + 0];
      dst[i][1] = src[i * 3 + 1];
      dst[i][2] = src[i * 3 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_RG_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 2 + 0];
      dst[i][1] = src[i * 2 + 1];
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_RG_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 2 + 0];
      dst[i][1] = src[i * 2 + 1];
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_RG_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 2 + 0];
      dst[i][1] = src[i * 2 + 1];
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_RG_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 2 + 0];
      dst[i][1] = src[i * 2 + 1];
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_RG_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 2 + 0];
      dst[i][1] = src[i * 2 + 1];
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_R_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i];
      dst[i][1] = 0;
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_R_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i];
      dst[i][1] = 0;
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_R_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i];
      dst[i][1] = 0;
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_R_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i];
      dst[i][1] = 0;
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_R_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i];
      dst[i][1] = 0;
      dst[i][2] = 0;
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = 0;
      dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = 0;
      dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = 0;
      dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = 0;
      dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = 0;
      dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_LUMINANCE_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_LUMINANCE_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_LUMINANCE_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_LUMINANCE_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_LUMINANCE_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i];
      dst[i][3] = 1;
   }
}


static void
unpack_int_rgba_LUMINANCE_ALPHA_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
      dst[i][3] = src[i * 2 + 1];
   }
}

static void
unpack_int_rgba_LUMINANCE_ALPHA_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
      dst[i][3] = src[i * 2 + 1];
   }
}

static void
unpack_int_rgba_LUMINANCE_ALPHA_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
      dst[i][3] = src[i * 2 + 1];
   }
}

static void
unpack_int_rgba_LUMINANCE_ALPHA_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
      dst[i][3] = src[i * 2 + 1];
   }
}

static void
unpack_int_rgba_LUMINANCE_ALPHA_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = src[i * 2 + 0];
      dst[i][3] = src[i * 2 + 1];
   }
}

static void
unpack_int_rgba_INTENSITY_UINT32(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_INTENSITY_UINT16(const GLushort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_INTENSITY_INT16(const GLshort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_INTENSITY_UINT8(const GLubyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_INTENSITY_INT8(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = dst[i][1] = dst[i][2] = dst[i][3] = src[i];
   }
}

static void
unpack_int_rgba_B10G10R10A2_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      GLuint tmp = src[i];
      dst[i][0] = (tmp >> 20) & 0x3ff;
      dst[i][1] = (tmp >> 10) & 0x3ff;
      dst[i][2] = (tmp >> 0) & 0x3ff;
      dst[i][3] = (tmp >> 30) & 0x3;
   }
}

static void
unpack_int_rgba_R10G10B10A2_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      GLuint tmp = src[i];
      dst[i][0] = (tmp >> 0) & 0x3ff;
      dst[i][1] = (tmp >> 10) & 0x3ff;
      dst[i][2] = (tmp >> 20) & 0x3ff;
      dst[i][3] = (tmp >> 30) & 0x3;
   }
}

static void
unpack_int_rgba_B10G10R10A2_UNORM(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      GLuint tmp = src[i];
      dst[i][0] = (tmp >> 20) & 0x3ff;
      dst[i][1] = (tmp >> 10) & 0x3ff;
      dst[i][2] = (tmp >> 0) & 0x3ff;
      dst[i][3] = (tmp >> 30) & 0x3;
   }
}

static void
unpack_int_rgba_XBGR8888_UINT(const GLubyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 4 + 0];
      dst[i][1] = src[i * 4 + 1];
      dst[i][2] = src[i * 4 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_XBGR8888_SINT(const GLbyte *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 4 + 0];
      dst[i][1] = src[i * 4 + 1];
      dst[i][2] = src[i * 4 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_XBGR16161616_UINT(const GLushort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 4 + 0];
      dst[i][1] = src[i * 4 + 1];
      dst[i][2] = src[i * 4 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_XBGR16161616_SINT(const GLshort *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 4 + 0];
      dst[i][1] = src[i * 4 + 1];
      dst[i][2] = src[i * 4 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_XBGR32323232_UINT(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      dst[i][0] = src[i * 4 + 0];
      dst[i][1] = src[i * 4 + 1];
      dst[i][2] = src[i * 4 + 2];
      dst[i][3] = 1;
   }
}

static void
unpack_int_rgba_R10G10B10A2_UNORM(const GLuint *src, GLuint dst[][4], GLuint n)
{
   unsigned int i;

   for (i = 0; i < n; i++) {
      GLuint tmp = src[i];
      dst[i][0] = (tmp >> 0) & 0x3ff;
      dst[i][1] = (tmp >> 10) & 0x3ff;
      dst[i][2] = (tmp >> 20) & 0x3ff;
      dst[i][3] = (tmp >> 30) & 0x3;
   }
}

void
_mesa_unpack_uint_rgba_row(mesa_format format, GLuint n,
                           const void *src, GLuint dst[][4])
{
   switch (format) {
      /* Since there won't be any sign extension happening, there's no need to
       * make separate paths for 32-bit-to-32-bit integer unpack.
       */
   case MESA_FORMAT_RGBA_UINT32:
   case MESA_FORMAT_RGBA_SINT32:
      unpack_int_rgba_RGBA_UINT32(src, dst, n);
      break;

   case MESA_FORMAT_RGBA_UINT16:
      unpack_int_rgba_RGBA_UINT16(src, dst, n);
      break;
   case MESA_FORMAT_RGBA_SINT16:
      unpack_int_rgba_RGBA_INT16(src, dst, n);
      break;

   case MESA_FORMAT_RGBA_UINT8:
      unpack_int_rgba_RGBA_UINT8(src, dst, n);
      break;
   case MESA_FORMAT_RGBA_SINT8:
      unpack_int_rgba_RGBA_INT8(src, dst, n);
      break;

   case MESA_FORMAT_B8G8R8A8_UNORM:
      unpack_int_rgba_B8G8R8A8_UNORM(src, dst, n);
      break;

   case MESA_FORMAT_B8G8R8X8_UNORM:
      unpack_int_rgba_B8G8R8X8_UNORM(src, dst, n);
      break;

   case MESA_FORMAT_RGB_UINT32:
   case MESA_FORMAT_RGB_SINT32:
      unpack_int_rgba_RGB_UINT32(src, dst, n);
      break;

   case MESA_FORMAT_RGB_UINT16:
      unpack_int_rgba_RGB_UINT16(src, dst, n);
      break;
   case MESA_FORMAT_RGB_SINT16:
      unpack_int_rgba_RGB_INT16(src, dst, n);
      break;

   case MESA_FORMAT_RGB_UINT8:
      unpack_int_rgba_RGB_UINT8(src, dst, n);
      break;
   case MESA_FORMAT_RGB_SINT8:
      unpack_int_rgba_RGB_INT8(src, dst, n);
      break;

   case MESA_FORMAT_RG_UINT32:
   case MESA_FORMAT_RG_SINT32:
      unpack_int_rgba_RG_UINT32(src, dst, n);
      break;

   case MESA_FORMAT_RG_UINT16:
      unpack_int_rgba_RG_UINT16(src, dst, n);
      break;
   case MESA_FORMAT_RG_SINT16:
      unpack_int_rgba_RG_INT16(src, dst, n);
      break;

   case MESA_FORMAT_RG_UINT8:
      unpack_int_rgba_RG_UINT8(src, dst, n);
      break;
   case MESA_FORMAT_RG_SINT8:
      unpack_int_rgba_RG_INT8(src, dst, n);
      break;

   case MESA_FORMAT_R_UINT32:
   case MESA_FORMAT_R_SINT32:
      unpack_int_rgba_R_UINT32(src, dst, n);
      break;

   case MESA_FORMAT_R_UINT16:
      unpack_int_rgba_R_UINT16(src, dst, n);
      break;
   case MESA_FORMAT_R_SINT16:
      unpack_int_rgba_R_INT16(src, dst, n);
      break;

   case MESA_FORMAT_R_UINT8:
      unpack_int_rgba_R_UINT8(src, dst, n);
      break;
   case MESA_FORMAT_R_SINT8:
      unpack_int_rgba_R_INT8(src, dst, n);
      break;

   case MESA_FORMAT_A_UINT32:
   case MESA_FORMAT_A_SINT32:
      unpack_int_rgba_ALPHA_UINT32(src, dst, n);
      break;

   case MESA_FORMAT_A_UINT16:
      unpack_int_rgba_ALPHA_UINT16(src, dst, n);
      break;
   case MESA_FORMAT_A_SINT16:
      unpack_int_rgba_ALPHA_INT16(src, dst, n);
      break;

   case MESA_FORMAT_A_UINT8:
      unpack_int_rgba_ALPHA_UINT8(src, dst, n);
      break;
   case MESA_FORMAT_A_SINT8:
      unpack_int_rgba_ALPHA_INT8(src, dst, n);
      break;

   case MESA_FORMAT_L_UINT32:
   case MESA_FORMAT_L_SINT32:
      unpack_int_rgba_LUMINANCE_UINT32(src, dst, n);
      break;
   case MESA_FORMAT_L_UINT16:
      unpack_int_rgba_LUMINANCE_UINT16(src, dst, n);
      break;
   case MESA_FORMAT_L_SINT16:
      unpack_int_rgba_LUMINANCE_INT16(src, dst, n);
      break;

   case MESA_FORMAT_L_UINT8:
      unpack_int_rgba_LUMINANCE_UINT8(src, dst, n);
      break;
   case MESA_FORMAT_L_SINT8:
      unpack_int_rgba_LUMINANCE_INT8(src, dst, n);
      break;

   case MESA_FORMAT_LA_UINT32:
   case MESA_FORMAT_LA_SINT32:
      unpack_int_rgba_LUMINANCE_ALPHA_UINT32(src, dst, n);
      break;

   case MESA_FORMAT_LA_UINT16:
      unpack_int_rgba_LUMINANCE_ALPHA_UINT16(src, dst, n);
      break;
   case MESA_FORMAT_LA_SINT16:
      unpack_int_rgba_LUMINANCE_ALPHA_INT16(src, dst, n);
      break;

   case MESA_FORMAT_LA_UINT8:
      unpack_int_rgba_LUMINANCE_ALPHA_UINT8(src, dst, n);
      break;
   case MESA_FORMAT_LA_SINT8:
      unpack_int_rgba_LUMINANCE_ALPHA_INT8(src, dst, n);
      break;

   case MESA_FORMAT_I_UINT32:
   case MESA_FORMAT_I_SINT32:
      unpack_int_rgba_INTENSITY_UINT32(src, dst, n);
      break;

   case MESA_FORMAT_I_UINT16:
      unpack_int_rgba_INTENSITY_UINT16(src, dst, n);
      break;
   case MESA_FORMAT_I_SINT16:
      unpack_int_rgba_INTENSITY_INT16(src, dst, n);
      break;

   case MESA_FORMAT_I_UINT8:
      unpack_int_rgba_INTENSITY_UINT8(src, dst, n);
      break;
   case MESA_FORMAT_I_SINT8:
      unpack_int_rgba_INTENSITY_INT8(src, dst, n);
      break;

   case MESA_FORMAT_B10G10R10A2_UINT:
      unpack_int_rgba_B10G10R10A2_UINT(src, dst, n);
      break;

   case MESA_FORMAT_R10G10B10A2_UINT:
      unpack_int_rgba_R10G10B10A2_UINT(src, dst, n);
      break;

   case MESA_FORMAT_B10G10R10A2_UNORM:
      unpack_int_rgba_B10G10R10A2_UNORM(src, dst, n);
      break;

   case MESA_FORMAT_RGBX_UINT8:
      unpack_int_rgba_XBGR8888_UINT(src, dst, n);
      break;

   case MESA_FORMAT_RGBX_SINT8:
      unpack_int_rgba_XBGR8888_SINT(src, dst, n);
      break;

   case MESA_FORMAT_RGBX_UINT16:
      unpack_int_rgba_XBGR16161616_UINT(src, dst, n);
      break;

   case MESA_FORMAT_RGBX_SINT16:
      unpack_int_rgba_XBGR16161616_SINT(src, dst, n);
      break;

   case MESA_FORMAT_RGBX_UINT32:
   case MESA_FORMAT_RGBX_SINT32:
      unpack_int_rgba_XBGR32323232_UINT(src, dst, n);
      break;

   case MESA_FORMAT_R10G10B10A2_UNORM:
      unpack_int_rgba_R10G10B10A2_UNORM(src, dst, n);
      break;

   default:
      _mesa_problem(NULL, "%s: bad format %s", __FUNCTION__,
                    _mesa_get_format_name(format));
      return;
   }
}

/**
 * Unpack a 2D rect of pixels returning float RGBA colors.
 * \param format  the source image format
 * \param src  start address of the source image
 * \param srcRowStride  source image row stride in bytes
 * \param dst  start address of the dest image
 * \param dstRowStride  dest image row stride in bytes
 * \param x  source image start X pos
 * \param y  source image start Y pos
 * \param width  width of rect region to convert
 * \param height  height of rect region to convert
 */
void
_mesa_unpack_rgba_block(mesa_format format,
                        const void *src, GLint srcRowStride,
                        GLfloat dst[][4], GLint dstRowStride,
                        GLuint x, GLuint y, GLuint width, GLuint height)
{
   unpack_rgba_func unpack = get_unpack_rgba_function(format);
   const GLuint srcPixStride = _mesa_get_format_bytes(format);
   const GLuint dstPixStride = 4 * sizeof(GLfloat);
   const GLubyte *srcRow;
   GLubyte *dstRow;
   GLuint i;

   /* XXX needs to be fixed for compressed formats */

   srcRow = ((const GLubyte *) src) + srcRowStride * y + srcPixStride * x;
   dstRow = ((GLubyte *) dst) + dstRowStride * y + dstPixStride * x;

   for (i = 0; i < height; i++) {
      unpack(srcRow, (GLfloat (*)[4]) dstRow, width);

      dstRow += dstRowStride;
      srcRow += srcRowStride;
   }
}




typedef void (*unpack_float_z_func)(GLuint n, const void *src, GLfloat *dst);

static void
unpack_float_z_X8_UINT_Z24_UNORM(GLuint n, const void *src, GLfloat *dst)
{
   /* only return Z, not stencil data */
   const GLuint *s = ((const GLuint *) src);
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i] = (GLfloat) ((s[i] >> 8) * scale);
      ASSERT(dst[i] >= 0.0F);
      ASSERT(dst[i] <= 1.0F);
   }
}

static void
unpack_float_z_Z24_UNORM_X8_UINT(GLuint n, const void *src, GLfloat *dst)
{
   /* only return Z, not stencil data */
   const GLuint *s = ((const GLuint *) src);
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i] = (GLfloat) ((s[i] & 0x00ffffff) * scale);
      ASSERT(dst[i] >= 0.0F);
      ASSERT(dst[i] <= 1.0F);
   }
}

static void
unpack_float_Z_UNORM16(GLuint n, const void *src, GLfloat *dst)
{
   const GLushort *s = ((const GLushort *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i] = s[i] * (1.0F / 65535.0F);
   }
}

static void
unpack_float_Z_UNORM32(GLuint n, const void *src, GLfloat *dst)
{
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i] = s[i] * (1.0F / 0xffffffff);
   }
}

static void
unpack_float_Z_FLOAT32(GLuint n, const void *src, GLfloat *dst)
{
   memcpy(dst, src, n * sizeof(float));
}

static void
unpack_float_z_Z32X24S8(GLuint n, const void *src, GLfloat *dst)
{
   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i] = s[i].z;
   }
}



/**
 * Unpack Z values.
 * The returned values will always be in the range [0.0, 1.0].
 */
void
_mesa_unpack_float_z_row(mesa_format format, GLuint n,
                         const void *src, GLfloat *dst)
{
   unpack_float_z_func unpack;

   switch (format) {
   case MESA_FORMAT_S8_UINT_Z24_UNORM:
   case MESA_FORMAT_X8_UINT_Z24_UNORM:
      unpack = unpack_float_z_X8_UINT_Z24_UNORM;
      break;
   case MESA_FORMAT_Z24_UNORM_S8_UINT:
   case MESA_FORMAT_Z24_UNORM_X8_UINT:
      unpack = unpack_float_z_Z24_UNORM_X8_UINT;
      break;
   case MESA_FORMAT_Z_UNORM16:
      unpack = unpack_float_Z_UNORM16;
      break;
   case MESA_FORMAT_Z_UNORM32:
      unpack = unpack_float_Z_UNORM32;
      break;
   case MESA_FORMAT_Z_FLOAT32:
      unpack = unpack_float_Z_FLOAT32;
      break;
   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
      unpack = unpack_float_z_Z32X24S8;
      break;
   default:
      _mesa_problem(NULL, "bad format %s in _mesa_unpack_float_z_row",
                    _mesa_get_format_name(format));
      return;
   }

   unpack(n, src, dst);
}



typedef void (*unpack_uint_z_func)(const void *src, GLuint *dst, GLuint n);

static void
unpack_uint_z_X8_UINT_Z24_UNORM(const void *src, GLuint *dst, GLuint n)
{
   /* only return Z, not stencil data */
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i] = (s[i] & 0xffffff00) | (s[i] >> 24);
   }
}

static void
unpack_uint_z_Z24_UNORM_X8_UINT(const void *src, GLuint *dst, GLuint n)
{
   /* only return Z, not stencil data */
   const GLuint *s = ((const GLuint *) src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i] = (s[i] << 8) | ((s[i] >> 16) & 0xff);
   }
}

static void
unpack_uint_Z_UNORM16(const void *src, GLuint *dst, GLuint n)
{
   const GLushort *s = ((const GLushort *)src);
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i] = (s[i] << 16) | s[i];
   }
}

static void
unpack_uint_Z_UNORM32(const void *src, GLuint *dst, GLuint n)
{
   memcpy(dst, src, n * sizeof(GLuint));
}

static void
unpack_uint_Z_FLOAT32(const void *src, GLuint *dst, GLuint n)
{
   const float *s = (const float *)src;
   GLuint i;
   for (i = 0; i < n; i++) {
      dst[i] = FLOAT_TO_UINT(CLAMP(s[i], 0.0F, 1.0F));
   }
}

static void
unpack_uint_Z_FLOAT32_X24S8(const void *src, GLuint *dst, GLuint n)
{
   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;
   GLuint i;

   for (i = 0; i < n; i++) {
      dst[i] = FLOAT_TO_UINT(CLAMP(s[i].z, 0.0F, 1.0F));
   }
}


/**
 * Unpack Z values.
 * The returned values will always be in the range [0, 0xffffffff].
 */
void
_mesa_unpack_uint_z_row(mesa_format format, GLuint n,
                        const void *src, GLuint *dst)
{
   unpack_uint_z_func unpack;
   const GLubyte *srcPtr = (GLubyte *) src;

   switch (format) {
   case MESA_FORMAT_S8_UINT_Z24_UNORM:
   case MESA_FORMAT_X8_UINT_Z24_UNORM:
      unpack = unpack_uint_z_X8_UINT_Z24_UNORM;
      break;
   case MESA_FORMAT_Z24_UNORM_S8_UINT:
   case MESA_FORMAT_Z24_UNORM_X8_UINT:
      unpack = unpack_uint_z_Z24_UNORM_X8_UINT;
      break;
   case MESA_FORMAT_Z_UNORM16:
      unpack = unpack_uint_Z_UNORM16;
      break;
   case MESA_FORMAT_Z_UNORM32:
      unpack = unpack_uint_Z_UNORM32;
      break;
   case MESA_FORMAT_Z_FLOAT32:
      unpack = unpack_uint_Z_FLOAT32;
      break;
   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
      unpack = unpack_uint_Z_FLOAT32_X24S8;
      break;
   default:
      _mesa_problem(NULL, "bad format %s in _mesa_unpack_uint_z_row",
                    _mesa_get_format_name(format));
      return;
   }

   unpack(srcPtr, dst, n);
}


static void
unpack_ubyte_s_S_UINT8(const void *src, GLubyte *dst, GLuint n)
{
   memcpy(dst, src, n);
}

static void
unpack_ubyte_s_S8_UINT_Z24_UNORM(const void *src, GLubyte *dst, GLuint n)
{
   GLuint i;
   const GLuint *src32 = src;

   for (i = 0; i < n; i++)
      dst[i] = src32[i] & 0xff;
}

static void
unpack_ubyte_s_Z24_UNORM_S8_UINT(const void *src, GLubyte *dst, GLuint n)
{
   GLuint i;
   const GLuint *src32 = src;

   for (i = 0; i < n; i++)
      dst[i] = src32[i] >> 24;
}

static void
unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(const void *src, GLubyte *dst, GLuint n)
{
   GLuint i;
   const struct z32f_x24s8 *s = (const struct z32f_x24s8 *) src;

   for (i = 0; i < n; i++)
      dst[i] = s[i].x24s8 & 0xff;
}

void
_mesa_unpack_ubyte_stencil_row(mesa_format format, GLuint n,
			       const void *src, GLubyte *dst)
{
   switch (format) {
   case MESA_FORMAT_S_UINT8:
      unpack_ubyte_s_S_UINT8(src, dst, n);
      break;
   case MESA_FORMAT_S8_UINT_Z24_UNORM:
      unpack_ubyte_s_S8_UINT_Z24_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_Z24_UNORM_S8_UINT:
      unpack_ubyte_s_Z24_UNORM_S8_UINT(src, dst, n);
      break;
   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
      unpack_ubyte_s_Z32_FLOAT_S8X24_UINT(src, dst, n);
      break;
   default:
      _mesa_problem(NULL, "bad format %s in _mesa_unpack_ubyte_s_row",
                    _mesa_get_format_name(format));
      return;
   }
}

static void
unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(const GLuint *src, GLuint *dst, GLuint n)
{
   GLuint i;

   for (i = 0; i < n; i++) {
      GLuint val = src[i];
      dst[i] = val >> 24 | val << 8;
   }
}

static void
unpack_uint_24_8_depth_stencil_Z32_S8X24(const GLuint *src,
                                         GLuint *dst, GLuint n)
{
   GLuint i;

   for (i = 0; i < n; i++) {
      /* 8 bytes per pixel (float + uint32) */
      GLfloat zf = ((GLfloat *) src)[i * 2 + 0];
      GLuint z24 = (GLuint) (zf * (GLfloat) 0xffffff);
      GLuint s = src[i * 2 + 1] & 0xff;
      dst[i] = (z24 << 8) | s;
   }
}

static void
unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(const GLuint *src, GLuint *dst, GLuint n)
{
   memcpy(dst, src, n * 4);
}

/**
 * Unpack depth/stencil returning as GL_UNSIGNED_INT_24_8.
 * \param format  the source data format
 */
void
_mesa_unpack_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
					 const void *src, GLuint *dst)
{
   switch (format) {
   case MESA_FORMAT_S8_UINT_Z24_UNORM:
      unpack_uint_24_8_depth_stencil_S8_UINT_Z24_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_Z24_UNORM_S8_UINT:
      unpack_uint_24_8_depth_stencil_Z24_UNORM_S8_UINT(src, dst, n);
      break;
   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
      unpack_uint_24_8_depth_stencil_Z32_S8X24(src, dst, n);
      break;
   default:
      _mesa_problem(NULL,
                    "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
                    _mesa_get_format_name(format));
      return;
   }
}

static void
unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(const GLuint *src,
                                            GLuint *dst, GLuint n)
{
   GLuint i;
   struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;

   for (i = 0; i < n; i++) {
      const GLuint z24 = src[i] & 0xffffff;
      d[i].z = z24 * scale;
      d[i].x24s8 = src[i] >> 24;
      assert(d[i].z >= 0.0f);
      assert(d[i].z <= 1.0f);
   }
}

static void
unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(const GLuint *src,
                                               GLuint *dst, GLuint n)
{
   memcpy(dst, src, n * sizeof(struct z32f_x24s8));
}

static void
unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(const GLuint *src,
                                            GLuint *dst, GLuint n)
{
   GLuint i;
   struct z32f_x24s8 *d = (struct z32f_x24s8 *) dst;
   const GLdouble scale = 1.0 / (GLdouble) 0xffffff;

   for (i = 0; i < n; i++) {
      const GLuint z24 = src[i] >> 8;
      d[i].z = z24 * scale;
      d[i].x24s8 = src[i] & 0xff;
      assert(d[i].z >= 0.0f);
      assert(d[i].z <= 1.0f);
   }
}

/**
 * Unpack depth/stencil returning as GL_FLOAT_32_UNSIGNED_INT_24_8_REV.
 * \param format  the source data format
 *
 * In GL_FLOAT_32_UNSIGNED_INT_24_8_REV lower 4 bytes contain float
 * component and higher 4 bytes contain packed 24-bit and 8-bit
 * components.
 *
 *    31 30 29 28 ... 4 3 2 1 0    31 30 29 ... 9 8 7 6 5 ... 2 1 0
 *    +-------------------------+  +--------------------------------+
 *    |    Float Component      |  | Unused         | 8 bit stencil |
 *    +-------------------------+  +--------------------------------+
 *          lower 4 bytes                  higher 4 bytes
 */
void
_mesa_unpack_float_32_uint_24_8_depth_stencil_row(mesa_format format, GLuint n,
			                          const void *src, GLuint *dst)
{
   switch (format) {
   case MESA_FORMAT_S8_UINT_Z24_UNORM:
      unpack_float_32_uint_24_8_S8_UINT_Z24_UNORM(src, dst, n);
      break;
   case MESA_FORMAT_Z24_UNORM_S8_UINT:
      unpack_float_32_uint_24_8_Z24_UNORM_S8_UINT(src, dst, n);
      break;
   case MESA_FORMAT_Z32_FLOAT_S8X24_UINT:
      unpack_float_32_uint_24_8_Z32_FLOAT_S8X24_UINT(src, dst, n);
      break;
   default:
      _mesa_problem(NULL,
                    "bad format %s in _mesa_unpack_uint_24_8_depth_stencil_row",
                    _mesa_get_format_name(format));
      return;
   }
}

/**
 * Unpack depth/stencil
 * \param format  the source data format
 * \param type the destination data type
 */
void
_mesa_unpack_depth_stencil_row(mesa_format format, GLuint n,
	                       const void *src, GLenum type,
                               GLuint *dst)
{
   assert(type == GL_UNSIGNED_INT_24_8 ||
          type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);

   switch (type) {
   case GL_UNSIGNED_INT_24_8:
      _mesa_unpack_uint_24_8_depth_stencil_row(format, n, src, dst);
      break;
   case GL_FLOAT_32_UNSIGNED_INT_24_8_REV:
      _mesa_unpack_float_32_uint_24_8_depth_stencil_row(format, n, src, dst);
      break;
   default:
      _mesa_problem(NULL,
                    "bad type 0x%x in _mesa_unpack_depth_stencil_row",
                    type);
      return;
   }
}