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