17117f1b4Smrg/* 27117f1b4Smrg * Mesa 3-D graphics library 37117f1b4Smrg * 44a49301eSmrg * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. 54a49301eSmrg * Copyright (c) 2008-2009 VMware, Inc. 67117f1b4Smrg * 77117f1b4Smrg * Permission is hereby granted, free of charge, to any person obtaining a 87117f1b4Smrg * copy of this software and associated documentation files (the "Software"), 97117f1b4Smrg * to deal in the Software without restriction, including without limitation 107117f1b4Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 117117f1b4Smrg * and/or sell copies of the Software, and to permit persons to whom the 127117f1b4Smrg * Software is furnished to do so, subject to the following conditions: 137117f1b4Smrg * 147117f1b4Smrg * The above copyright notice and this permission notice shall be included 157117f1b4Smrg * in all copies or substantial portions of the Software. 167117f1b4Smrg * 177117f1b4Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 187117f1b4Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 197117f1b4Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20af69d88dSmrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 21af69d88dSmrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22af69d88dSmrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23af69d88dSmrg * OTHER DEALINGS IN THE SOFTWARE. 247117f1b4Smrg */ 257117f1b4Smrg 267117f1b4Smrg 277117f1b4Smrg/** 287117f1b4Smrg * \file texformat.c 297117f1b4Smrg * Texture formats. 307117f1b4Smrg * 317117f1b4Smrg * \author Gareth Hughes 324a49301eSmrg * \author Brian Paul 337117f1b4Smrg */ 347117f1b4Smrg 357117f1b4Smrg 367117f1b4Smrg#include "context.h" 37af69d88dSmrg#include "enums.h" 383464ebd5Sriastradh#include "mtypes.h" 394a49301eSmrg#include "texcompress.h" 407117f1b4Smrg#include "texformat.h" 4101e04c3fSmrg#include "glformats.h" 427117f1b4Smrg 433464ebd5Sriastradh#define RETURN_IF_SUPPORTED(f) do { \ 443464ebd5Sriastradh if (ctx->TextureFormatSupported[f]) \ 453464ebd5Sriastradh return f; \ 463464ebd5Sriastradh} while (0) 477117f1b4Smrg 487117f1b4Smrg/** 497117f1b4Smrg * Choose an appropriate texture format given the format, type and 507117f1b4Smrg * internalFormat parameters passed to glTexImage(). 517117f1b4Smrg * 527117f1b4Smrg * \param ctx the GL context. 53af69d88dSmrg * \param target a texture target (GL_TEXTURE_x) 547117f1b4Smrg * \param internalFormat user's prefered internal texture format. 557117f1b4Smrg * \param format incoming image pixel format. 567117f1b4Smrg * \param type incoming image data type. 577117f1b4Smrg * 58af69d88dSmrg * \return the closest mesa_format for the given format/type arguments 59af69d88dSmrg * 60af69d88dSmrg * This is called via dd_function_table::ChooseTextureFormat. Hardware 61af69d88dSmrg * drivers may override this function with a specialized version. 627117f1b4Smrg */ 63af69d88dSmrgmesa_format 64af69d88dSmrg_mesa_choose_tex_format(struct gl_context *ctx, GLenum target, 65af69d88dSmrg GLint internalFormat, GLenum format, GLenum type) 667117f1b4Smrg{ 677117f1b4Smrg (void) format; 687117f1b4Smrg 697117f1b4Smrg switch (internalFormat) { 70af69d88dSmrg /* shallow RGBA formats */ 71af69d88dSmrg case 4: 72af69d88dSmrg case GL_RGBA: 73af69d88dSmrg if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) { 74af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B4G4R4A4_UNORM); 75af69d88dSmrg } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) { 76af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B5G5R5A1_UNORM); 7701e04c3fSmrg } else if (type == GL_UNSIGNED_SHORT_5_5_5_1) { 7801e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B5G5R5A1_UNORM); 79af69d88dSmrg } else if (type == GL_UNSIGNED_INT_2_10_10_10_REV) { 80af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UNORM); 814a49301eSmrg } 827ec681f3Smrg FALLTHROUGH; 83af69d88dSmrg 84af69d88dSmrg case GL_RGBA8: 85af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_UNORM); 86af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_UNORM); 87af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM); 88af69d88dSmrg break; 89af69d88dSmrg case GL_RGB5_A1: 90af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B5G5R5A1_UNORM); 9101e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A1B5G5R5_UNORM); 92af69d88dSmrg break; 93af69d88dSmrg case GL_RGBA2: 94af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A4R4G4B4_UNORM); /* just to test another format*/ 95af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B4G4R4A4_UNORM); 96af69d88dSmrg break; 97af69d88dSmrg case GL_RGBA4: 98af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B4G4R4A4_UNORM); 99af69d88dSmrg break; 100af69d88dSmrg 101af69d88dSmrg /* deep RGBA formats */ 102af69d88dSmrg case GL_RGB10_A2: 103af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R10G10B10A2_UNORM); 104af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UNORM); 105af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM); 106af69d88dSmrg break; 107af69d88dSmrg case GL_RGBA12: 108af69d88dSmrg case GL_RGBA16: 109af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UNORM16); 110af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UNORM16); 111af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_UNORM); 112af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM); 113af69d88dSmrg break; 114af69d88dSmrg 115af69d88dSmrg /* shallow RGB formats */ 116af69d88dSmrg case 3: 117af69d88dSmrg case GL_RGB: 118af69d88dSmrg if (type == GL_UNSIGNED_INT_2_10_10_10_REV) { 119af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UNORM); 1203464ebd5Sriastradh } 12101e04c3fSmrg if (type == GL_UNSIGNED_SHORT_5_6_5) { 12201e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM); 12301e04c3fSmrg } 1247ec681f3Smrg FALLTHROUGH; 125af69d88dSmrg case GL_RGB8: 126af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UNORM8); 127af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8X8_UNORM); 128af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_UNORM); 129af69d88dSmrg 130af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_UNORM8); 131af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM); 132af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM); 133af69d88dSmrg break; 134af69d88dSmrg case GL_R3_G3_B2: 135af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B2G3R3_UNORM); 136af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM); 137af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R5G6B5_UNORM); 138af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_UNORM8); 139af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM); 140af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM); 141af69d88dSmrg break; 142af69d88dSmrg case GL_RGB4: 143af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R5G6B5_UNORM); /* just to test another format */ 144af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM); 145af69d88dSmrg break; 146af69d88dSmrg case GL_RGB5: 147af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM); 148af69d88dSmrg break; 149af69d88dSmrg 150af69d88dSmrg /* deep RGB formats */ 151af69d88dSmrg case GL_RGB10: 152af69d88dSmrg case GL_RGB12: 153af69d88dSmrg case GL_RGB16: 154af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_UNORM16); 155af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UNORM16); 156af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM); 157af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM); 158af69d88dSmrg break; 159af69d88dSmrg 160af69d88dSmrg /* Alpha formats */ 161af69d88dSmrg case GL_ALPHA: 162af69d88dSmrg case GL_ALPHA4: 163af69d88dSmrg case GL_ALPHA8: 164af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_UNORM8); 1657ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UNORM8); 166af69d88dSmrg break; 167af69d88dSmrg 168af69d88dSmrg case GL_ALPHA12: 169af69d88dSmrg case GL_ALPHA16: 170af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_UNORM16); 171af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_UNORM8); 1727ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UNORM8); 173af69d88dSmrg break; 174af69d88dSmrg 175af69d88dSmrg /* Luminance formats */ 176af69d88dSmrg case 1: 177af69d88dSmrg case GL_LUMINANCE: 178af69d88dSmrg case GL_LUMINANCE4: 179af69d88dSmrg case GL_LUMINANCE8: 180af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_UNORM8); 181af69d88dSmrg break; 182af69d88dSmrg 183af69d88dSmrg case GL_LUMINANCE12: 184af69d88dSmrg case GL_LUMINANCE16: 185af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_UNORM16); 186af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_UNORM8); 187af69d88dSmrg break; 1883464ebd5Sriastradh 189af69d88dSmrg /* Luminance/Alpha formats */ 190af69d88dSmrg case GL_LUMINANCE4_ALPHA4: 191af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L4A4_UNORM); 1927ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UNORM8); 193af69d88dSmrg break; 194af69d88dSmrg 195af69d88dSmrg case 2: 196af69d88dSmrg case GL_LUMINANCE_ALPHA: 197af69d88dSmrg case GL_LUMINANCE6_ALPHA2: 198af69d88dSmrg case GL_LUMINANCE8_ALPHA8: 1997ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UNORM8); 200af69d88dSmrg break; 201af69d88dSmrg 202af69d88dSmrg case GL_LUMINANCE12_ALPHA4: 203af69d88dSmrg case GL_LUMINANCE12_ALPHA12: 204af69d88dSmrg case GL_LUMINANCE16_ALPHA16: 2057ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UNORM16); 2067ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UNORM8); 207af69d88dSmrg break; 208af69d88dSmrg 209af69d88dSmrg case GL_INTENSITY: 210af69d88dSmrg case GL_INTENSITY4: 211af69d88dSmrg case GL_INTENSITY8: 212af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_UNORM8); 213af69d88dSmrg break; 214af69d88dSmrg 215af69d88dSmrg case GL_INTENSITY12: 216af69d88dSmrg case GL_INTENSITY16: 217af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_UNORM16); 218af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_UNORM8); 219af69d88dSmrg break; 220af69d88dSmrg 221af69d88dSmrg case GL_DEPTH_COMPONENT: 222af69d88dSmrg case GL_DEPTH_COMPONENT24: 223af69d88dSmrg case GL_DEPTH_COMPONENT32: 224af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_Z_UNORM32); 225af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_X8_UINT); 226af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_S8_UINT); 227af69d88dSmrg break; 228af69d88dSmrg case GL_DEPTH_COMPONENT16: 229af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_Z_UNORM16); 230af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_X8_UINT); 231af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_S8_UINT); 232af69d88dSmrg break; 233af69d88dSmrg 234af69d88dSmrg case GL_COMPRESSED_ALPHA_ARB: 235af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_UNORM8); 2367ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UNORM8); 237af69d88dSmrg break; 238af69d88dSmrg case GL_COMPRESSED_LUMINANCE_ARB: 239af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_UNORM8); 240af69d88dSmrg break; 241af69d88dSmrg case GL_COMPRESSED_LUMINANCE_ALPHA_ARB: 2427ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UNORM8); 243af69d88dSmrg break; 244af69d88dSmrg case GL_COMPRESSED_INTENSITY_ARB: 245af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_UNORM8); 246af69d88dSmrg break; 247af69d88dSmrg case GL_COMPRESSED_RGB_ARB: 248af69d88dSmrg /* We don't use texture compression for 1D and 1D array textures. 249af69d88dSmrg * For 1D textures, compressions doesn't buy us much. 250af69d88dSmrg * For 1D ARRAY textures, there's complicated issues with updating 251af69d88dSmrg * sub-regions on non-block boundaries with glCopyTexSubImage, among 252af69d88dSmrg * other issues. FWIW, the GL_EXT_texture_array extension prohibits 253af69d88dSmrg * 1D ARRAY textures in S3TC format. 254af69d88dSmrg */ 255af69d88dSmrg if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) { 25601e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1); 2573464ebd5Sriastradh } 258af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_UNORM8); 259af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM); 260af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM); 261af69d88dSmrg break; 262af69d88dSmrg case GL_COMPRESSED_RGBA_ARB: 263af69d88dSmrg /* We don't use texture compression for 1D and 1D array textures. */ 264af69d88dSmrg if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) { 26501e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */ 2663464ebd5Sriastradh } 267af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_UNORM); 268af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM); 269af69d88dSmrg break; 270af69d88dSmrg 271af69d88dSmrg case GL_RGB565: 272af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM); 273af69d88dSmrg break; 274af69d88dSmrg 275af69d88dSmrg case GL_YCBCR_MESA: 276af69d88dSmrg if (type == GL_UNSIGNED_SHORT_8_8_MESA) 277af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR); 278af69d88dSmrg else 279af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR_REV); 280af69d88dSmrg break; 281af69d88dSmrg 282af69d88dSmrg case GL_ALPHA16F_ARB: 283af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_FLOAT16); 284af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_FLOAT32); 285af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 286af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 287af69d88dSmrg break; 288af69d88dSmrg case GL_ALPHA32F_ARB: 289af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_FLOAT32); 290af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 291af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_FLOAT16); 292af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 293af69d88dSmrg break; 294af69d88dSmrg case GL_LUMINANCE16F_ARB: 295af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_FLOAT16); 296af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_FLOAT32); 297af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 298af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 299af69d88dSmrg break; 300af69d88dSmrg case GL_LUMINANCE32F_ARB: 301af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_FLOAT32); 302af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 303af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_FLOAT16); 304af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 305af69d88dSmrg break; 306af69d88dSmrg case GL_LUMINANCE_ALPHA16F_ARB: 307af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_FLOAT16); 308af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_FLOAT32); 309af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 310af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 311af69d88dSmrg break; 312af69d88dSmrg case GL_LUMINANCE_ALPHA32F_ARB: 313af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_FLOAT32); 314af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 315af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_FLOAT16); 316af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 317af69d88dSmrg break; 318af69d88dSmrg case GL_INTENSITY16F_ARB: 319af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_FLOAT16); 320af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_FLOAT32); 321af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 322af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 323af69d88dSmrg break; 324af69d88dSmrg case GL_INTENSITY32F_ARB: 325af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_FLOAT32); 326af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 327af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_FLOAT16); 328af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 329af69d88dSmrg break; 330af69d88dSmrg case GL_RGB16F_ARB: 331af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16); 332af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_FLOAT16); 333af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 334af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32); 335af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 336af69d88dSmrg break; 337af69d88dSmrg case GL_RGB32F_ARB: 338af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32); 339af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_FLOAT32); 340af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 341af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16); 342af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 343af69d88dSmrg break; 344af69d88dSmrg case GL_RGBA16F_ARB: 345af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 346af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 347af69d88dSmrg break; 348af69d88dSmrg case GL_RGBA32F_ARB: 349af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 350af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 351af69d88dSmrg break; 352af69d88dSmrg 353af69d88dSmrg case GL_RGB9_E5: 354af69d88dSmrg /* GL_EXT_texture_shared_exponent -- just one format to support */ 35501e04c3fSmrg assert(ctx->TextureFormatSupported[MESA_FORMAT_R9G9B9E5_FLOAT]); 356af69d88dSmrg return MESA_FORMAT_R9G9B9E5_FLOAT; 357af69d88dSmrg 358af69d88dSmrg case GL_R11F_G11F_B10F: 359af69d88dSmrg /* GL_EXT_texture_packed_float -- just one format to support */ 36001e04c3fSmrg assert(ctx->TextureFormatSupported[MESA_FORMAT_R11G11B10_FLOAT]); 361af69d88dSmrg return MESA_FORMAT_R11G11B10_FLOAT; 362af69d88dSmrg 363af69d88dSmrg case GL_DEPTH_STENCIL_EXT: 364af69d88dSmrg case GL_DEPTH24_STENCIL8_EXT: 365af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_S8_UINT_Z24_UNORM); 366af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_S8_UINT); 367af69d88dSmrg break; 368af69d88dSmrg 369af69d88dSmrg case GL_DEPTH_COMPONENT32F: 37001e04c3fSmrg assert(ctx->TextureFormatSupported[MESA_FORMAT_Z_FLOAT32]); 371af69d88dSmrg return MESA_FORMAT_Z_FLOAT32; 372af69d88dSmrg case GL_DEPTH32F_STENCIL8: 37301e04c3fSmrg assert(ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT_S8X24_UINT]); 374af69d88dSmrg return MESA_FORMAT_Z32_FLOAT_S8X24_UINT; 375af69d88dSmrg 376af69d88dSmrg case GL_RED_SNORM: 377af69d88dSmrg case GL_R8_SNORM: 378af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_SNORM8); 379af69d88dSmrg break; 380af69d88dSmrg case GL_RG_SNORM: 381af69d88dSmrg case GL_RG8_SNORM: 3827ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SNORM8); 383af69d88dSmrg break; 384af69d88dSmrg case GL_RGB_SNORM: 385af69d88dSmrg case GL_RGB8_SNORM: 386af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8X8_SNORM); 387af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 388af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_X8B8G8R8_SNORM); 389af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 390af69d88dSmrg break; 391af69d88dSmrg case GL_RGBA_SNORM: 392af69d88dSmrg case GL_RGBA8_SNORM: 393af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 394af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 395af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 396af69d88dSmrg break; 397af69d88dSmrg case GL_ALPHA_SNORM: 398af69d88dSmrg case GL_ALPHA8_SNORM: 399af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_SNORM8); 400af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 401af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 402af69d88dSmrg break; 403af69d88dSmrg case GL_LUMINANCE_SNORM: 404af69d88dSmrg case GL_LUMINANCE8_SNORM: 405af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_SNORM8); 406af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_X8B8G8R8_SNORM); 407af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 408af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 409af69d88dSmrg break; 410af69d88dSmrg case GL_LUMINANCE_ALPHA_SNORM: 411af69d88dSmrg case GL_LUMINANCE8_ALPHA8_SNORM: 4127ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SNORM8); 413af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 414af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 415af69d88dSmrg break; 416af69d88dSmrg case GL_INTENSITY_SNORM: 417af69d88dSmrg case GL_INTENSITY8_SNORM: 418af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_SNORM8); 419af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 420af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 421af69d88dSmrg break; 422af69d88dSmrg case GL_R16_SNORM: 423af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_SNORM16); 424af69d88dSmrg break; 425af69d88dSmrg case GL_RG16_SNORM: 4267ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SNORM16); 427af69d88dSmrg break; 428af69d88dSmrg case GL_RGB16_SNORM: 429af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_SNORM16); 430af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_SNORM16); 4317ec681f3Smrg FALLTHROUGH; 432af69d88dSmrg case GL_RGBA16_SNORM: 433af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SNORM16); 434af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 435af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 436af69d88dSmrg break; 437af69d88dSmrg case GL_ALPHA16_SNORM: 438af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_SNORM16); 439af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SNORM16); 440af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 441af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 442af69d88dSmrg break; 443af69d88dSmrg case GL_LUMINANCE16_SNORM: 444af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_SNORM16); 4457ec681f3Smrg FALLTHROUGH; 446af69d88dSmrg case GL_LUMINANCE16_ALPHA16_SNORM: 447af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SNORM16); 448af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SNORM16); 449af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 450af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 451af69d88dSmrg break; 452af69d88dSmrg case GL_INTENSITY16_SNORM: 453af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_SNORM16); 454af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SNORM16); 455af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM); 456af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM); 457af69d88dSmrg break; 458af69d88dSmrg 459af69d88dSmrg case GL_SRGB_EXT: 460af69d88dSmrg case GL_SRGB8_EXT: 461af69d88dSmrg /* there is no MESA_FORMAT_RGB_SRGB8 */ 462af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8X8_SRGB); 463af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SRGB); 464af69d88dSmrg 465af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_SRGB8); 466af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB); 46701e04c3fSmrg 46801e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_X8B8G8R8_SRGB); 46901e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB); 470af69d88dSmrg break; 471af69d88dSmrg case GL_SRGB_ALPHA_EXT: 472af69d88dSmrg case GL_SRGB8_ALPHA8_EXT: 473af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SRGB); 474af69d88dSmrg 475af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SRGB); 476af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB); 47701e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB); 478af69d88dSmrg break; 479b9abf16eSmaya case GL_SR8_EXT: 480b9abf16eSmaya RETURN_IF_SUPPORTED(MESA_FORMAT_R_SRGB8); 481b9abf16eSmaya break; 4827ec681f3Smrg case GL_SRG8_EXT: 4837ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SRGB8); 4847ec681f3Smrg break; 485af69d88dSmrg case GL_SLUMINANCE_EXT: 486af69d88dSmrg case GL_SLUMINANCE8_EXT: 487af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_SRGB8); 488af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB); 48901e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB); 490af69d88dSmrg break; 491af69d88dSmrg case GL_SLUMINANCE_ALPHA_EXT: 492af69d88dSmrg case GL_SLUMINANCE8_ALPHA8_EXT: 4937ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SRGB8); 494af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB); 49501e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB); 496af69d88dSmrg break; 497af69d88dSmrg case GL_COMPRESSED_SLUMINANCE_EXT: 498af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_SRGB8); 499af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB); 50001e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB); 501af69d88dSmrg break; 502af69d88dSmrg case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT: 5037ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SRGB8); 504af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB); 50501e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB); 506af69d88dSmrg break; 507af69d88dSmrg case GL_COMPRESSED_SRGB_EXT: 50801e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1); 509af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_SRGB8); 510af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB); 51101e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB); 512af69d88dSmrg break; 513af69d88dSmrg case GL_COMPRESSED_SRGB_ALPHA_EXT: 51401e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */ 515af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SRGB); 516af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB); 51701e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB); 518af69d88dSmrg break; 519af69d88dSmrg 520af69d88dSmrg case GL_ALPHA8UI_EXT: 521af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_UINT8); 522af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8); 523af69d88dSmrg break; 524af69d88dSmrg case GL_ALPHA16UI_EXT: 525af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_UINT16); 526af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16); 527af69d88dSmrg break; 528af69d88dSmrg case GL_ALPHA32UI_EXT: 529af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_UINT32); 530af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32); 531af69d88dSmrg break; 532af69d88dSmrg case GL_ALPHA8I_EXT: 533af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_SINT8); 534af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8); 535af69d88dSmrg break; 536af69d88dSmrg case GL_ALPHA16I_EXT: 537af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_SINT16); 538af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16); 539af69d88dSmrg break; 540af69d88dSmrg case GL_ALPHA32I_EXT: 541af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_A_SINT32); 542af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32); 543af69d88dSmrg break; 544af69d88dSmrg case GL_LUMINANCE8UI_EXT: 545af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_UINT8); 546af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8); 547af69d88dSmrg break; 548af69d88dSmrg case GL_LUMINANCE16UI_EXT: 549af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_UINT16); 550af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16); 551af69d88dSmrg break; 552af69d88dSmrg case GL_LUMINANCE32UI_EXT: 553af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_UINT32); 554af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32); 555af69d88dSmrg break; 556af69d88dSmrg case GL_LUMINANCE8I_EXT: 557af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_SINT8); 558af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8); 559af69d88dSmrg break; 560af69d88dSmrg case GL_LUMINANCE16I_EXT: 561af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_SINT16); 562af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16); 563af69d88dSmrg break; 564af69d88dSmrg case GL_LUMINANCE32I_EXT: 565af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_L_SINT32); 566af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32); 567af69d88dSmrg break; 568af69d88dSmrg case GL_LUMINANCE_ALPHA8UI_EXT: 569af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UINT8); 570af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8); 571af69d88dSmrg break; 572af69d88dSmrg case GL_LUMINANCE_ALPHA16UI_EXT: 573af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UINT16); 574af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16); 575af69d88dSmrg break; 576af69d88dSmrg case GL_LUMINANCE_ALPHA32UI_EXT: 577af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UINT32); 578af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32); 579af69d88dSmrg break; 580af69d88dSmrg case GL_LUMINANCE_ALPHA8I_EXT: 581af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SINT8); 582af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8); 583af69d88dSmrg break; 584af69d88dSmrg case GL_LUMINANCE_ALPHA16I_EXT: 585af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SINT16); 586af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16); 587af69d88dSmrg break; 588af69d88dSmrg case GL_LUMINANCE_ALPHA32I_EXT: 589af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SINT32); 590af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32); 591af69d88dSmrg break; 592af69d88dSmrg case GL_INTENSITY8UI_EXT: 593af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_UINT8); 594af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8); 595af69d88dSmrg break; 596af69d88dSmrg case GL_INTENSITY16UI_EXT: 597af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_UINT16); 598af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16); 599af69d88dSmrg break; 600af69d88dSmrg case GL_INTENSITY32UI_EXT: 601af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_UINT32); 602af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32); 603af69d88dSmrg break; 604af69d88dSmrg case GL_INTENSITY8I_EXT: 605af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_SINT8); 606af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8); 607af69d88dSmrg break; 608af69d88dSmrg case GL_INTENSITY16I_EXT: 609af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_SINT16); 610af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16); 611af69d88dSmrg break; 612af69d88dSmrg case GL_INTENSITY32I_EXT: 613af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_I_SINT32); 614af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32); 615af69d88dSmrg break; 616af69d88dSmrg 617af69d88dSmrg case GL_RGB8UI_EXT: 618af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT8); 619af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_UINT8); 620af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8); 621af69d88dSmrg break; 622af69d88dSmrg case GL_RGB16UI_EXT: 623af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT16); 624af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_UINT16); 625af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16); 626af69d88dSmrg break; 627af69d88dSmrg case GL_RGB32UI_EXT: 628af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT32); 629af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_UINT32); 630af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32); 631af69d88dSmrg break; 632af69d88dSmrg case GL_RGB8I_EXT: 633af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_SINT8); 634af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_SINT8); 635af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8); 636af69d88dSmrg break; 637af69d88dSmrg case GL_RGB16I_EXT: 638af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_SINT16); 639af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_SINT16); 640af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16); 641af69d88dSmrg break; 642af69d88dSmrg case GL_RGB32I_EXT: 643af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_SINT32); 644af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_SINT32); 645af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32); 646af69d88dSmrg break; 647af69d88dSmrg case GL_RGBA8UI_EXT: 648af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8); 649af69d88dSmrg break; 650af69d88dSmrg case GL_RGBA16UI_EXT: 651af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16); 652af69d88dSmrg break; 653af69d88dSmrg case GL_RGBA32UI_EXT: 654af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32); 655af69d88dSmrg break; 656af69d88dSmrg case GL_RGBA8I_EXT: 657af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8); 658af69d88dSmrg break; 659af69d88dSmrg case GL_RGBA16I_EXT: 660af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16); 661af69d88dSmrg break; 662af69d88dSmrg case GL_RGBA32I_EXT: 663af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32); 664af69d88dSmrg break; 665af69d88dSmrg 666af69d88dSmrg case GL_R8: 667af69d88dSmrg case GL_RED: 668af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_UNORM8); 669af69d88dSmrg break; 670af69d88dSmrg 671af69d88dSmrg case GL_COMPRESSED_RED: 672af69d88dSmrg if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) 673af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_RGTC1_UNORM); 674af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_UNORM8); 675af69d88dSmrg break; 676af69d88dSmrg 677af69d88dSmrg case GL_R16: 678af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_UNORM16); 679af69d88dSmrg break; 680af69d88dSmrg 681af69d88dSmrg case GL_RG: 682af69d88dSmrg case GL_RG8: 6837ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UNORM8); 684af69d88dSmrg break; 685af69d88dSmrg 686af69d88dSmrg case GL_COMPRESSED_RG: 687af69d88dSmrg if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) 688af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2_UNORM); 6897ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UNORM8); 690af69d88dSmrg break; 691af69d88dSmrg 692af69d88dSmrg case GL_RG16: 6937ec681f3Smrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UNORM16); 694af69d88dSmrg break; 695af69d88dSmrg 696af69d88dSmrg case GL_R16F: 697af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16); 698af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16); 699af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32); 700af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32); 701af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 702af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 703af69d88dSmrg break; 704af69d88dSmrg case GL_R32F: 705af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32); 706af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32); 707af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 708af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16); 709af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16); 710af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 711af69d88dSmrg break; 712af69d88dSmrg case GL_RG16F: 713af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16); 714af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32); 715af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 716af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 717af69d88dSmrg break; 718af69d88dSmrg case GL_RG32F: 719af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32); 720af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32); 721af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16); 722af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16); 723af69d88dSmrg break; 724af69d88dSmrg 725af69d88dSmrg case GL_R8UI: 726af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT8); 727af69d88dSmrg break; 728af69d88dSmrg case GL_RG8UI: 729af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT8); 730af69d88dSmrg break; 731af69d88dSmrg case GL_R16UI: 732af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT16); 733af69d88dSmrg break; 734af69d88dSmrg case GL_RG16UI: 735af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT16); 736af69d88dSmrg break; 737af69d88dSmrg case GL_R32UI: 738af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT32); 739af69d88dSmrg break; 740af69d88dSmrg case GL_RG32UI: 741af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT32); 742af69d88dSmrg break; 743af69d88dSmrg case GL_R8I: 744af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_SINT8); 745af69d88dSmrg break; 746af69d88dSmrg case GL_RG8I: 747af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SINT8); 748af69d88dSmrg break; 749af69d88dSmrg case GL_R16I: 750af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_SINT16); 751af69d88dSmrg break; 752af69d88dSmrg case GL_RG16I: 753af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SINT16); 754af69d88dSmrg break; 755af69d88dSmrg case GL_R32I: 756af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R_SINT32); 757af69d88dSmrg break; 758af69d88dSmrg case GL_RG32I: 759af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SINT32); 760af69d88dSmrg break; 761af69d88dSmrg 762af69d88dSmrg case GL_RGB10_A2UI: 763af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UINT); 764af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_R10G10B10A2_UINT); 765af69d88dSmrg break; 766af69d88dSmrg 767af69d88dSmrg case GL_BGRA: 768af69d88dSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM); 769af69d88dSmrg break; 7703464ebd5Sriastradh 77101e04c3fSmrg case GL_STENCIL_INDEX: 77201e04c3fSmrg case GL_STENCIL_INDEX8: 77301e04c3fSmrg RETURN_IF_SUPPORTED(MESA_FORMAT_S_UINT8); 77401e04c3fSmrg break; 775c1f859d4Smrg 776af69d88dSmrg default: 77701e04c3fSmrg /* For non-generic compressed format we assert two things: 77801e04c3fSmrg * 77901e04c3fSmrg * 1. The format has already been validated against the set of available 78001e04c3fSmrg * extensions. 78101e04c3fSmrg * 78201e04c3fSmrg * 2. The driver only enables the extension if it supports all of the 78301e04c3fSmrg * formats that are part of that extension. 78401e04c3fSmrg */ 78501e04c3fSmrg if (_mesa_is_compressed_format(ctx, internalFormat)) 78601e04c3fSmrg return _mesa_glenum_to_compressed_format(internalFormat); 787af69d88dSmrg } 78801e04c3fSmrg 78901e04c3fSmrg _mesa_problem(ctx, "unexpected format %s in _mesa_choose_tex_format()", 79001e04c3fSmrg _mesa_enum_to_string(internalFormat)); 79101e04c3fSmrg return MESA_FORMAT_NONE; 792af69d88dSmrg} 793