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