189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/* 289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Mesa 3-D graphics library 3008ed1df83735c72c2731c509a3665938d3c7209Brian Paul * Version: 6.5.1 489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 5008ed1df83735c72c2731c509a3665938d3c7209Brian Paul * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. 65bd093bd7b3711f88e1fd0fc9cdb37a18d7d24b9Roland Scheidegger * Copyright (c) 2008 VMware, Inc. 789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Permission is hereby granted, free of charge, to any person obtaining a 989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * copy of this software and associated documentation files (the "Software"), 1089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * to deal in the Software without restriction, including without limitation 1189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * the rights to use, copy, modify, merge, publish, distribute, sublicense, 1289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * and/or sell copies of the Software, and to permit persons to whom the 1389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * Software is furnished to do so, subject to the following conditions: 1489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 1589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * The above copyright notice and this permission notice shall be included 1689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * in all copies or substantial portions of the Software. 1789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * 1889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 2189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 2289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 2389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 2589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 2689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 278f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul/** 288f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul * \file texcompress.c 298f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul * Helper functions for texture compression. 308f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul */ 318f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul 328f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul 3389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "glheader.h" 343c63452e64df7e10aa073c6c3b9492b1d7dabbb8Brian Paul#include "imports.h" 358f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul#include "colormac.h" 36354d66e2f58bb19efcd9a0f8b2398d3f1dc4248dBrian Paul#include "formats.h" 37db61b9ce39bccc43140357652ceb78baaf2aea44Vinson Lee#include "mfeatures.h" 380117da40cd7edd3d165bb28569c289b37eca12b9Vinson Lee#include "mtypes.h" 3989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul#include "texcompress.h" 403370ba802ff93fde399c9b07303a71ab0827e217Brian Paul#include "texcompress_fxt1.h" 413370ba802ff93fde399c9b07303a71ab0827e217Brian Paul#include "texcompress_rgtc.h" 423370ba802ff93fde399c9b07303a71ab0827e217Brian Paul#include "texcompress_s3tc.h" 43d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu#include "texcompress_etc.h" 44a1661dc8957a35899d653e9fffd97f166c56be56Brian Paul#include "swrast/s_context.h" 4589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 46008ed1df83735c72c2731c509a3665938d3c7209Brian Paul 4789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 4809916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * Get the GL base format of a specified GL compressed texture format 4909916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * 5009916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * From page 232 of the OpenGL 3.3 (Compatiblity Profile) spec: 5109916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * 5209916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * "Compressed Internal Format Base Internal Format Type 5309916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * --------------------------- -------------------- --------- 5409916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_ALPHA ALPHA Generic 5509916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_LUMINANCE LUMINANCE Generic 5609916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_LUMINANCE_ALPHA LUMINANCE_ALPHA Generic 5709916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_INTENSITY INTENSITY Generic 5809916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_RED RED Generic 5909916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_RG RG Generic 6009916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_RGB RGB Generic 6109916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_RGBA RGBA Generic 6209916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_SRGB RGB Generic 6309916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_SRGB_ALPHA RGBA Generic 6409916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_SLUMINANCE LUMINANCE Generic 6509916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_SLUMINANCE_ALPHA LUMINANCE_ALPHA Generic 6609916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_RED_RGTC1 RED Specific 6709916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_SIGNED_RED_RGTC1 RED Specific 6809916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_RG_RGTC2 RG Specific 6909916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * COMPRESSED_SIGNED_RG_RGTC2 RG Specific" 7009916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * 7109916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * \return 7209916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * The base format of \c format if \c format is a compressed format (either 7309916e877fc14723d7950f892e181df9f7d7f36fIan Romanick * generic or specific. Otherwise 0 is returned. 7409916e877fc14723d7950f892e181df9f7d7f36fIan Romanick */ 7509916e877fc14723d7950f892e181df9f7d7f36fIan RomanickGLenum 7609916e877fc14723d7950f892e181df9f7d7f36fIan Romanick_mesa_gl_compressed_format_base_format(GLenum format) 7709916e877fc14723d7950f892e181df9f7d7f36fIan Romanick{ 7809916e877fc14723d7950f892e181df9f7d7f36fIan Romanick switch (format) { 7909916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RED: 8009916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RED_RGTC1: 8109916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SIGNED_RED_RGTC1: 8209916e877fc14723d7950f892e181df9f7d7f36fIan Romanick return GL_RED; 8309916e877fc14723d7950f892e181df9f7d7f36fIan Romanick 8409916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RG: 8509916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RG_RGTC2: 8609916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SIGNED_RG_RGTC2: 8709916e877fc14723d7950f892e181df9f7d7f36fIan Romanick return GL_RG; 8809916e877fc14723d7950f892e181df9f7d7f36fIan Romanick 8909916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGB: 9009916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SRGB: 9109916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 9209916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGB_FXT1_3DFX: 9309916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 94d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu case GL_ETC1_RGB8_OES: 9509916e877fc14723d7950f892e181df9f7d7f36fIan Romanick return GL_RGB; 9609916e877fc14723d7950f892e181df9f7d7f36fIan Romanick 9709916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGBA: 9809916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SRGB_ALPHA: 9909916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGBA_BPTC_UNORM_ARB: 10009916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB: 10109916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB: 10209916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB: 10309916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 10409916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 10509916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 10609916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_RGBA_FXT1_3DFX: 10709916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 10809916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 10909916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 11009916e877fc14723d7950f892e181df9f7d7f36fIan Romanick return GL_RGBA; 11109916e877fc14723d7950f892e181df9f7d7f36fIan Romanick 11209916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_ALPHA: 11309916e877fc14723d7950f892e181df9f7d7f36fIan Romanick return GL_ALPHA; 11409916e877fc14723d7950f892e181df9f7d7f36fIan Romanick 11509916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_LUMINANCE: 11609916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SLUMINANCE: 11709916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_LUMINANCE_LATC1_EXT: 11809916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: 11909916e877fc14723d7950f892e181df9f7d7f36fIan Romanick return GL_LUMINANCE; 12009916e877fc14723d7950f892e181df9f7d7f36fIan Romanick 12109916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_LUMINANCE_ALPHA: 12209916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SLUMINANCE_ALPHA: 12309916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: 12409916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: 12509916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: 12609916e877fc14723d7950f892e181df9f7d7f36fIan Romanick return GL_LUMINANCE_ALPHA; 12709916e877fc14723d7950f892e181df9f7d7f36fIan Romanick 12809916e877fc14723d7950f892e181df9f7d7f36fIan Romanick case GL_COMPRESSED_INTENSITY: 12909916e877fc14723d7950f892e181df9f7d7f36fIan Romanick return GL_INTENSITY; 13009916e877fc14723d7950f892e181df9f7d7f36fIan Romanick 13109916e877fc14723d7950f892e181df9f7d7f36fIan Romanick default: 13209916e877fc14723d7950f892e181df9f7d7f36fIan Romanick return 0; 13309916e877fc14723d7950f892e181df9f7d7f36fIan Romanick } 13409916e877fc14723d7950f892e181df9f7d7f36fIan Romanick} 13509916e877fc14723d7950f892e181df9f7d7f36fIan Romanick 13609916e877fc14723d7950f892e181df9f7d7f36fIan Romanick/** 137008ed1df83735c72c2731c509a3665938d3c7209Brian Paul * Return list of (and count of) all specific texture compression 138008ed1df83735c72c2731c509a3665938d3c7209Brian Paul * formats that are supported. 1398f04c12e0ad876baa7eb9ed379e2b00150b376e0Brian Paul * 140b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * Some formats are \b not returned by this function. The 141b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * \c GL_COMPRESSED_TEXTURE_FORMATS query only returns formats that are 142b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * "suitable for general-purpose usage." All texture compression extensions 143b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * have taken this to mean either linear RGB or linear RGBA. 144b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 145b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * The GL_ARB_texture_compress_rgtc spec says: 146b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 147b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * "19) Should the GL_NUM_COMPRESSED_TEXTURE_FORMATS and 148b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * GL_COMPRESSED_TEXTURE_FORMATS queries return the RGTC formats? 149b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 150b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * RESOLVED: No. 151b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 152b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * The OpenGL 2.1 specification says "The only values returned 153b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * by this query [GL_COMPRESSED_TEXTURE_FORMATS"] are those 154b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * corresponding to formats suitable for general-purpose usage. 155b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * The renderer will not enumerate formats with restrictions that 156b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * need to be specifically understood prior to use." 157b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 158b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * Compressed textures with just red or red-green components are 159b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * not general-purpose so should not be returned by these queries 160b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * because they have restrictions. 161b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 162b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * Applications that seek to use the RGTC formats should do so 163b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * by looking for this extension's name in the string returned by 164b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * glGetString(GL_EXTENSIONS) rather than 165b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * what GL_NUM_COMPRESSED_TEXTURE_FORMATS and 166b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * GL_COMPRESSED_TEXTURE_FORMATS return." 167b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 168b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * There is nearly identical wording in the GL_EXT_texture_compression_rgtc 169b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * spec. 170b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 171b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * The GL_EXT_texture_rRGB spec says: 172b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 173b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * "22) Should the new COMPRESSED_SRGB_* formats be listed in an 174b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * implementation's GL_COMPRESSED_TEXTURE_FORMATS list? 175b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 176b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * RESOLVED: No. Section 3.8.1 says formats listed by 177b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * GL_COMPRESSED_TEXTURE_FORMATS are "suitable for general-purpose 178b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * usage." The non-linear distribution of red, green, and 179b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * blue for these sRGB compressed formats makes them not really 180b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * general-purpose." 181b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 182b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * The GL_EXT_texture_compression_latc spec says: 183b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 184b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * "16) Should the GL_NUM_COMPRESSED_TEXTURE_FORMATS and 185b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * GL_COMPRESSED_TEXTURE_FORMATS queries return the LATC formats? 186b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 187b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * RESOLVED: No. 188b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 189b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * The OpenGL 2.1 specification says "The only values returned 190b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * by this query [GL_COMPRESSED_TEXTURE_FORMATS"] are those 191b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * corresponding to formats suitable for general-purpose usage. 192b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * The renderer will not enumerate formats with restrictions that 193b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * need to be specifically understood prior to use." 194b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 195b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * Historically, OpenGL implementation have advertised the RGB and 196b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * RGBA versions of the S3TC extensions compressed format tokens 197b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * through this mechanism. 198b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 199b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * The specification is not sufficiently clear about what "suitable 200b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * for general-purpose usage" means. Historically that seems to mean 201b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * unsigned RGB or unsigned RGBA. The DXT1 format supporting alpha 202b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * (GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) is not exposed in the list (at 203b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * least for NVIDIA drivers) because the alpha is always 1.0 expect 204b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * when it is 0.0 when RGB is required to be black. NVIDIA's even 205b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * limits itself to true linear RGB or RGBA formats, specifically 206b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * not including EXT_texture_sRGB's sRGB S3TC compressed formats. 207b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 208b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * Adding luminance and luminance-alpha texture formats (and 209b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * certainly signed versions of luminance and luminance-alpha 210b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * formats!) invites potential comptaibility problems with old 211b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * applications using this mechanism since old applications are 212b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * unlikely to expect non-RGB or non-RGBA formats to be advertised 213b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * through this mechanism. However no specific misinteractions 214b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * with old applications is known. 215b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 216b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * Applications that seek to use the LATC formats should do so 217b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * by looking for this extension's name in the string returned by 218b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * glGetString(GL_EXTENSIONS) rather than 219b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * what GL_NUM_COMPRESSED_TEXTURE_FORMATS and 220b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * GL_COMPRESSED_TEXTURE_FORMATS return." 221b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 222b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * There is no formal spec for GL_ATI_texture_compression_3dc. Since the 223b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * formats added by this extension are luminance-alpha formats, it is 224b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * reasonable to expect them to follow the same rules as 225b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * GL_EXT_texture_compression_latc. At the very least, Catalyst 11.6 does not 226b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * expose the 3dc formats through this mechanism. 227b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick * 228008ed1df83735c72c2731c509a3665938d3c7209Brian Paul * \param ctx the GL context 229008ed1df83735c72c2731c509a3665938d3c7209Brian Paul * \param formats the resulting format list (may be NULL). 2306dc85575000127630489b407c50a4b3ea87c9acbKeith Whitwell * 23189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul * \return number of formats. 23289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 23389fb06fcc11cbe3f23521312155d6c55d869f526Brian PaulGLuint 234b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick_mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats) 23589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 23689fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul GLuint n = 0; 23733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick if (ctx->Extensions.TDFX_texture_compression_FXT1) { 23833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick if (formats) { 23933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick formats[n++] = GL_COMPRESSED_RGB_FXT1_3DFX; 24033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick formats[n++] = GL_COMPRESSED_RGBA_FXT1_3DFX; 24189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 24233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick else { 24333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick n += 2; 24478233887446a8f5fe66d674caf1b7ee838647ac1Brian Paul } 24533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick } 246b189d1635d89cd7d900e8f9a5eed88d7dc0b46cbIan Romanick 24733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick if (ctx->Extensions.EXT_texture_compression_s3tc) { 24833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick if (formats) { 24933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick formats[n++] = GL_COMPRESSED_RGB_S3TC_DXT1_EXT; 25033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; 25133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; 25233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick } 25333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick else { 25433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick n += 3; 25533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick } 25633fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick } 25733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick if (ctx->Extensions.S3_s3tc) { 25833fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick if (formats) { 25933fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick formats[n++] = GL_RGB_S3TC; 26033fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick formats[n++] = GL_RGB4_S3TC; 26133fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick formats[n++] = GL_RGBA_S3TC; 26233fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick formats[n++] = GL_RGBA4_S3TC; 26333fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick } 26433fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick else { 26533fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick n += 4; 266663a9e1b7ef7b8384abe2f81e1a8749b942f6d3aDaniel Borca } 26733fa5e4bfad8005f09ad3c9fc92c40fa863935d1Ian Romanick } 268199b0894b501607bf8d599ef5efc08cd6c08c79dKristian Høgsberg 269d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu if (ctx->Extensions.OES_compressed_ETC1_RGB8_texture) { 270d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu if (formats) { 271d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu formats[n++] = GL_ETC1_RGB8_OES; 272d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 273d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu else { 274d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu n += 1; 275d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 276d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu } 277d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu 278011e946cb09993a9b298358188736394241bbb03Ian Romanick#if FEATURE_ES1 279011e946cb09993a9b298358188736394241bbb03Ian Romanick if (ctx->API == API_OPENGLES) { 280011e946cb09993a9b298358188736394241bbb03Ian Romanick if (formats) { 281011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE4_RGB8_OES; 282011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE4_RGBA8_OES; 283011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE4_R5_G6_B5_OES; 284011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE4_RGBA4_OES; 285011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE4_RGB5_A1_OES; 286011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE8_RGB8_OES; 287011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE8_RGBA8_OES; 288011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE8_R5_G6_B5_OES; 289011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE8_RGBA4_OES; 290011e946cb09993a9b298358188736394241bbb03Ian Romanick formats[n++] = GL_PALETTE8_RGB5_A1_OES; 291011e946cb09993a9b298358188736394241bbb03Ian Romanick } 292011e946cb09993a9b298358188736394241bbb03Ian Romanick else { 293011e946cb09993a9b298358188736394241bbb03Ian Romanick n += 10; 294011e946cb09993a9b298358188736394241bbb03Ian Romanick } 295199b0894b501607bf8d599ef5efc08cd6c08c79dKristian Høgsberg } 296199b0894b501607bf8d599ef5efc08cd6c08c79dKristian Høgsberg#endif 297faf5d6584b9d75a10987c4460b376af7d1e4d496Adam Jackson 298faf5d6584b9d75a10987c4460b376af7d1e4d496Adam Jackson return n; 29989fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 30089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 30289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul/** 30354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul * Convert a compressed MESA_FORMAT_x to a GLenum. 30489fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul */ 30554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paulgl_format 30654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul_mesa_glenum_to_compressed_format(GLenum format) 30789fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul{ 30854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul switch (format) { 309c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_COMPRESSED_RGB_FXT1_3DFX: 31054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_RGB_FXT1; 311c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_COMPRESSED_RGBA_FXT1_3DFX: 31254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_RGBA_FXT1; 31354bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 314c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_COMPRESSED_RGB_S3TC_DXT1_EXT: 315c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_RGB_S3TC: 31654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_RGB_DXT1; 317c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT: 318c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_RGB4_S3TC: 31954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_RGBA_DXT1; 320c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT: 321c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_RGBA_S3TC: 32254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_RGBA_DXT3; 323c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT: 324c3c19be8e0d0b13916cc128cf3c8e839935c912aBrian Paul case GL_RGBA4_S3TC: 32554bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_RGBA_DXT5; 32654bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul 3275bd093bd7b3711f88e1fd0fc9cdb37a18d7d24b9Roland Scheidegger case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT: 32854bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_SRGB_DXT1; 3295bd093bd7b3711f88e1fd0fc9cdb37a18d7d24b9Roland Scheidegger case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT: 33054bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_SRGBA_DXT1; 3315bd093bd7b3711f88e1fd0fc9cdb37a18d7d24b9Roland Scheidegger case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT: 33254bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_SRGBA_DXT3; 3335bd093bd7b3711f88e1fd0fc9cdb37a18d7d24b9Roland Scheidegger case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT: 33454bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_SRGBA_DXT5; 33589fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3368d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie case GL_COMPRESSED_RED_RGTC1: 3378d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie return MESA_FORMAT_RED_RGTC1; 3388d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie case GL_COMPRESSED_SIGNED_RED_RGTC1: 3398d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie return MESA_FORMAT_SIGNED_RED_RGTC1; 3408d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie case GL_COMPRESSED_RG_RGTC2: 3418d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie return MESA_FORMAT_RG_RGTC2; 3428d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie case GL_COMPRESSED_SIGNED_RG_RGTC2: 3438d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie return MESA_FORMAT_SIGNED_RG_RGTC2; 3448d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie 3457d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_LATC1_EXT: 3467d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return MESA_FORMAT_L_LATC1; 3477d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT: 3487d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return MESA_FORMAT_SIGNED_L_LATC1; 3497d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT: 35069f16accd0aa3b8d414092a5e52ccc99649da01aMarek Olšák case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI: 3517d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return MESA_FORMAT_LA_LATC2; 3527d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT: 3537d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return MESA_FORMAT_SIGNED_LA_LATC2; 3547d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák 355d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu case GL_ETC1_RGB8_OES: 356d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return MESA_FORMAT_ETC1_RGB8; 357d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu 35889fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul default: 35954bb414e00a4daedbe530b9933bc11bac4ae7149Brian Paul return MESA_FORMAT_NONE; 36089fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul } 36189fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul} 36289fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 36389fb06fcc11cbe3f23521312155d6c55d869f526Brian Paul 3649528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul/** 3659528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul * Given a compressed MESA_FORMAT_x value, return the corresponding 3669528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul * GLenum for that format. 3679528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul * This is needed for glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT) 3689528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul * which must return the specific texture format used when the user might 3699528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul * have originally specified a generic compressed format in their 3709528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul * glTexImage2D() call. 3719528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul * For non-compressed textures, we always return the user-specified 3729528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul * internal format unchanged. 3739528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul */ 3749528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian PaulGLenum 375aab06dc0f0bf295abe213021b79ff65d70a4f4c0Brian Paul_mesa_compressed_format_to_glenum(struct gl_context *ctx, gl_format mesaFormat) 3769528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul{ 3779528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul switch (mesaFormat) { 3789528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul#if FEATURE_texture_fxt1 3799528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_RGB_FXT1: 3809528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_RGB_FXT1_3DFX; 3819528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_RGBA_FXT1: 3829528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_RGBA_FXT1_3DFX; 3839528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul#endif 3849528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul#if FEATURE_texture_s3tc 3859528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_RGB_DXT1: 3869528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_RGB_S3TC_DXT1_EXT; 3879528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_RGBA_DXT1: 3889528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT; 3899528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_RGBA_DXT3: 3909528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT; 3919528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_RGBA_DXT5: 3929528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT; 3939528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul#if FEATURE_EXT_texture_sRGB 3949528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_SRGB_DXT1: 3959528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT; 3969528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_SRGBA_DXT1: 3979528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT; 3989528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_SRGBA_DXT3: 3999528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT; 4009528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul case MESA_FORMAT_SRGBA_DXT5: 4019528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT; 4029528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul#endif 4039528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul#endif 4048d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie 4058d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie case MESA_FORMAT_RED_RGTC1: 4068d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie return GL_COMPRESSED_RED_RGTC1; 4078d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie case MESA_FORMAT_SIGNED_RED_RGTC1: 4088d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie return GL_COMPRESSED_SIGNED_RED_RGTC1; 4098d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie case MESA_FORMAT_RG_RGTC2: 4108d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie return GL_COMPRESSED_RG_RGTC2; 4118d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie case MESA_FORMAT_SIGNED_RG_RGTC2: 4128d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie return GL_COMPRESSED_SIGNED_RG_RGTC2; 4138d47c919859e9cd90cfc04eb220ac8a5aa87048eDave Airlie 4147d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case MESA_FORMAT_L_LATC1: 4157d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_COMPRESSED_LUMINANCE_LATC1_EXT; 4167d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case MESA_FORMAT_SIGNED_L_LATC1: 4177d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT; 4187d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case MESA_FORMAT_LA_LATC2: 4197d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT; 4207d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák case MESA_FORMAT_SIGNED_LA_LATC2: 4217d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák return GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT; 4227d16e2c0cd70dc5a23b746dbc8e44c58366b5353Marek Olšák 423d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu case MESA_FORMAT_ETC1_RGB8: 424d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu return GL_ETC1_RGB8_OES; 425d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu 4269528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul default: 4279528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul _mesa_problem(ctx, "Unexpected mesa texture format in" 4289528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul " _mesa_compressed_format_to_glenum()"); 4299528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul return 0; 4309528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul } 4319528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul} 4329528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul 4339528dc6ed8d09eba0dc3be17dc5e9ef4add8083cBrian Paul 434bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul/* 435bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul * Return the address of the pixel at (col, row, img) in a 436bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul * compressed texture image. 437bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul * \param col, row, img - image position (3D), should be a multiple of the 438bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul * format's block size. 439bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul * \param format - compressed image format 440bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul * \param width - image width (stride) in pixels 441bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul * \param image - the image address 442bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul * \return address of pixel at (row, col, img) 443bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul */ 444bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian PaulGLubyte * 445bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul_mesa_compressed_image_address(GLint col, GLint row, GLint img, 446bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul gl_format mesaFormat, 447bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul GLsizei width, const GLubyte *image) 448bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul{ 449bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul /* XXX only 2D images implemented, not 3D */ 450bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul const GLuint blockSize = _mesa_get_format_bytes(mesaFormat); 451bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul GLuint bw, bh; 452bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul GLint offset; 453bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul 454bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul _mesa_get_format_block_size(mesaFormat, &bw, &bh); 455bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul 456bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul ASSERT(col % bw == 0); 457bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul ASSERT(row % bh == 0); 458bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul 459bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul offset = ((width + bw - 1) / bw) * (row / bh) + col / bw; 460bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul offset *= blockSize; 461bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul 462bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul return (GLubyte *) image + offset; 463bc143b1a9ffc16af27b2e7183ca3ec59ad5a7c89Brian Paul} 4643370ba802ff93fde399c9b07303a71ab0827e217Brian Paul 4653370ba802ff93fde399c9b07303a71ab0827e217Brian Paul 4663370ba802ff93fde399c9b07303a71ab0827e217Brian Paul/** 4673370ba802ff93fde399c9b07303a71ab0827e217Brian Paul * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image. 46807459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul * \param srcRowStride stride in bytes between rows of blocks in the 46907459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul * compressed source image. 4703370ba802ff93fde399c9b07303a71ab0827e217Brian Paul */ 4713370ba802ff93fde399c9b07303a71ab0827e217Brian Paulvoid 4723370ba802ff93fde399c9b07303a71ab0827e217Brian Paul_mesa_decompress_image(gl_format format, GLuint width, GLuint height, 4733370ba802ff93fde399c9b07303a71ab0827e217Brian Paul const GLubyte *src, GLint srcRowStride, 4743370ba802ff93fde399c9b07303a71ab0827e217Brian Paul GLfloat *dest) 4753370ba802ff93fde399c9b07303a71ab0827e217Brian Paul{ 476a1661dc8957a35899d653e9fffd97f166c56be56Brian Paul void (*fetch)(const struct swrast_texture_image *texImage, 4773370ba802ff93fde399c9b07303a71ab0827e217Brian Paul GLint i, GLint j, GLint k, GLfloat *texel); 478a1661dc8957a35899d653e9fffd97f166c56be56Brian Paul struct swrast_texture_image texImage; /* dummy teximage */ 4793370ba802ff93fde399c9b07303a71ab0827e217Brian Paul GLuint i, j; 48007459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul GLuint bytes, bw, bh; 48107459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul 48207459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul bytes = _mesa_get_format_bytes(format); 48307459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul _mesa_get_format_block_size(format, &bw, &bh); 4843370ba802ff93fde399c9b07303a71ab0827e217Brian Paul 4853370ba802ff93fde399c9b07303a71ab0827e217Brian Paul /* setup dummy texture image info */ 4863370ba802ff93fde399c9b07303a71ab0827e217Brian Paul memset(&texImage, 0, sizeof(texImage)); 487bd3c10c0f0c60ab3421c2da2eab814edc2296cb0Brian Paul texImage.Map = (void *) src; 48807459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul 48907459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul /* XXX This line is a bit of a hack to adapt to the row stride 49007459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul * convention used by the texture decompression functions. 49107459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul */ 49207459ba50979a99e12720bd9e41a1aa3b8d24e41Brian Paul texImage.RowStride = srcRowStride * bh / bytes; 4933370ba802ff93fde399c9b07303a71ab0827e217Brian Paul 4943370ba802ff93fde399c9b07303a71ab0827e217Brian Paul switch (format) { 4953370ba802ff93fde399c9b07303a71ab0827e217Brian Paul /* DXT formats */ 4963370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_RGB_DXT1: 4974fec5e9154582439bc185eb143e89f220b169c32Brian Paul fetch = _mesa_fetch_texel_rgb_dxt1; 4983370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 4993370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_RGBA_DXT1: 5004fec5e9154582439bc185eb143e89f220b169c32Brian Paul fetch = _mesa_fetch_texel_rgba_dxt1; 5013370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5023370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_RGBA_DXT3: 5034fec5e9154582439bc185eb143e89f220b169c32Brian Paul fetch = _mesa_fetch_texel_rgba_dxt3; 5043370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5053370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_RGBA_DXT5: 5064fec5e9154582439bc185eb143e89f220b169c32Brian Paul fetch = _mesa_fetch_texel_rgba_dxt5; 5073370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5083370ba802ff93fde399c9b07303a71ab0827e217Brian Paul 5093370ba802ff93fde399c9b07303a71ab0827e217Brian Paul /* FXT1 formats */ 5103370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_RGB_FXT1: 5113370ba802ff93fde399c9b07303a71ab0827e217Brian Paul fetch = _mesa_fetch_texel_2d_f_rgb_fxt1; 5123370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5133370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_RGBA_FXT1: 5143370ba802ff93fde399c9b07303a71ab0827e217Brian Paul fetch = _mesa_fetch_texel_2d_f_rgba_fxt1; 5153370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5163370ba802ff93fde399c9b07303a71ab0827e217Brian Paul 5173370ba802ff93fde399c9b07303a71ab0827e217Brian Paul /* Red/RG formats */ 5183370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_RED_RGTC1: 519d78b44c2651b45c337dda71b17351beb41eb9c14Brian Paul fetch = _mesa_fetch_texel_red_rgtc1; 5203370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5213370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_SIGNED_RED_RGTC1: 522d78b44c2651b45c337dda71b17351beb41eb9c14Brian Paul fetch = _mesa_fetch_texel_signed_red_rgtc1; 5233370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5243370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_RG_RGTC2: 525d78b44c2651b45c337dda71b17351beb41eb9c14Brian Paul fetch = _mesa_fetch_texel_rg_rgtc2; 5263370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5273370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_SIGNED_RG_RGTC2: 528d78b44c2651b45c337dda71b17351beb41eb9c14Brian Paul fetch = _mesa_fetch_texel_signed_rg_rgtc2; 5293370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5303370ba802ff93fde399c9b07303a71ab0827e217Brian Paul 5313370ba802ff93fde399c9b07303a71ab0827e217Brian Paul /* L/LA formats */ 5323370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_L_LATC1: 533d78b44c2651b45c337dda71b17351beb41eb9c14Brian Paul fetch = _mesa_fetch_texel_l_latc1; 5343370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5353370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_SIGNED_L_LATC1: 536d78b44c2651b45c337dda71b17351beb41eb9c14Brian Paul fetch = _mesa_fetch_texel_signed_l_latc1; 5373370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5383370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_LA_LATC2: 539d78b44c2651b45c337dda71b17351beb41eb9c14Brian Paul fetch = _mesa_fetch_texel_la_latc2; 5403370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5413370ba802ff93fde399c9b07303a71ab0827e217Brian Paul case MESA_FORMAT_SIGNED_LA_LATC2: 542d78b44c2651b45c337dda71b17351beb41eb9c14Brian Paul fetch = _mesa_fetch_texel_signed_la_latc2; 5433370ba802ff93fde399c9b07303a71ab0827e217Brian Paul break; 5443370ba802ff93fde399c9b07303a71ab0827e217Brian Paul 545d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu /* ETC1 formats */ 546d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu case MESA_FORMAT_ETC1_RGB8: 547d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu fetch = _mesa_fetch_texel_2d_f_etc1_rgb8; 548d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu break; 549d4a38e86d4b4d66cca20ee63222f940cb73fa709Chia-I Wu 5503370ba802ff93fde399c9b07303a71ab0827e217Brian Paul default: 5513370ba802ff93fde399c9b07303a71ab0827e217Brian Paul _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()"); 5523370ba802ff93fde399c9b07303a71ab0827e217Brian Paul return; 5533370ba802ff93fde399c9b07303a71ab0827e217Brian Paul } 5543370ba802ff93fde399c9b07303a71ab0827e217Brian Paul 5553370ba802ff93fde399c9b07303a71ab0827e217Brian Paul for (j = 0; j < height; j++) { 5563370ba802ff93fde399c9b07303a71ab0827e217Brian Paul for (i = 0; i < width; i++) { 5573370ba802ff93fde399c9b07303a71ab0827e217Brian Paul fetch(&texImage, i, j, 0, dest); 5583370ba802ff93fde399c9b07303a71ab0827e217Brian Paul dest += 4; 5593370ba802ff93fde399c9b07303a71ab0827e217Brian Paul } 5603370ba802ff93fde399c9b07303a71ab0827e217Brian Paul } 5613370ba802ff93fde399c9b07303a71ab0827e217Brian Paul} 562