17117f1b4Smrg/*
27117f1b4Smrg * Mesa 3-D graphics library
37117f1b4Smrg *
47117f1b4Smrg * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
54a49301eSmrg * Copyright (c) 2008 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 texcompress.c
297117f1b4Smrg * Helper functions for texture compression.
307117f1b4Smrg */
317117f1b4Smrg
327117f1b4Smrg
337117f1b4Smrg#include "glheader.h"
347ec681f3Smrg
35af69d88dSmrg#include "context.h"
364a49301eSmrg#include "formats.h"
373464ebd5Sriastradh#include "mtypes.h"
38af69d88dSmrg#include "context.h"
397117f1b4Smrg#include "texcompress.h"
40af69d88dSmrg#include "texcompress_fxt1.h"
41af69d88dSmrg#include "texcompress_rgtc.h"
42af69d88dSmrg#include "texcompress_s3tc.h"
43af69d88dSmrg#include "texcompress_etc.h"
44af69d88dSmrg#include "texcompress_bptc.h"
457117f1b4Smrg
467117f1b4Smrg
473464ebd5Sriastradh/**
483464ebd5Sriastradh * Get the GL base format of a specified GL compressed texture format
493464ebd5Sriastradh *
503464ebd5Sriastradh * From page 232 of the OpenGL 3.3 (Compatiblity Profile) spec:
513464ebd5Sriastradh *
523464ebd5Sriastradh *     "Compressed Internal Format      Base Internal Format    Type
533464ebd5Sriastradh *     ---------------------------     --------------------    ---------
543464ebd5Sriastradh *     COMPRESSED_ALPHA                ALPHA                   Generic
553464ebd5Sriastradh *     COMPRESSED_LUMINANCE            LUMINANCE               Generic
563464ebd5Sriastradh *     COMPRESSED_LUMINANCE_ALPHA      LUMINANCE_ALPHA         Generic
573464ebd5Sriastradh *     COMPRESSED_INTENSITY            INTENSITY               Generic
583464ebd5Sriastradh *     COMPRESSED_RED                  RED                     Generic
593464ebd5Sriastradh *     COMPRESSED_RG                   RG                      Generic
603464ebd5Sriastradh *     COMPRESSED_RGB                  RGB                     Generic
613464ebd5Sriastradh *     COMPRESSED_RGBA                 RGBA                    Generic
623464ebd5Sriastradh *     COMPRESSED_SRGB                 RGB                     Generic
633464ebd5Sriastradh *     COMPRESSED_SRGB_ALPHA           RGBA                    Generic
643464ebd5Sriastradh *     COMPRESSED_SLUMINANCE           LUMINANCE               Generic
653464ebd5Sriastradh *     COMPRESSED_SLUMINANCE_ALPHA     LUMINANCE_ALPHA         Generic
663464ebd5Sriastradh *     COMPRESSED_RED_RGTC1            RED                     Specific
673464ebd5Sriastradh *     COMPRESSED_SIGNED_RED_RGTC1     RED                     Specific
683464ebd5Sriastradh *     COMPRESSED_RG_RGTC2             RG                      Specific
693464ebd5Sriastradh *     COMPRESSED_SIGNED_RG_RGTC2      RG                      Specific"
703464ebd5Sriastradh *
713464ebd5Sriastradh * \return
723464ebd5Sriastradh * The base format of \c format if \c format is a compressed format (either
733464ebd5Sriastradh * generic or specific.  Otherwise 0 is returned.
743464ebd5Sriastradh */
753464ebd5SriastradhGLenum
763464ebd5Sriastradh_mesa_gl_compressed_format_base_format(GLenum format)
773464ebd5Sriastradh{
783464ebd5Sriastradh   switch (format) {
793464ebd5Sriastradh   case GL_COMPRESSED_RED:
80af69d88dSmrg   case GL_COMPRESSED_R11_EAC:
813464ebd5Sriastradh   case GL_COMPRESSED_RED_RGTC1:
82af69d88dSmrg   case GL_COMPRESSED_SIGNED_R11_EAC:
833464ebd5Sriastradh   case GL_COMPRESSED_SIGNED_RED_RGTC1:
843464ebd5Sriastradh      return GL_RED;
853464ebd5Sriastradh
863464ebd5Sriastradh   case GL_COMPRESSED_RG:
87af69d88dSmrg   case GL_COMPRESSED_RG11_EAC:
883464ebd5Sriastradh   case GL_COMPRESSED_RG_RGTC2:
89af69d88dSmrg   case GL_COMPRESSED_SIGNED_RG11_EAC:
903464ebd5Sriastradh   case GL_COMPRESSED_SIGNED_RG_RGTC2:
913464ebd5Sriastradh      return GL_RG;
923464ebd5Sriastradh
933464ebd5Sriastradh   case GL_COMPRESSED_RGB:
943464ebd5Sriastradh   case GL_COMPRESSED_SRGB:
95af69d88dSmrg   case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB:
96af69d88dSmrg   case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB:
973464ebd5Sriastradh   case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
983464ebd5Sriastradh   case GL_COMPRESSED_RGB_FXT1_3DFX:
993464ebd5Sriastradh   case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
100af69d88dSmrg   case GL_ETC1_RGB8_OES:
101af69d88dSmrg   case GL_COMPRESSED_RGB8_ETC2:
102af69d88dSmrg   case GL_COMPRESSED_SRGB8_ETC2:
10301e04c3fSmrg   case GL_RGB_S3TC:
10401e04c3fSmrg   case GL_RGB4_S3TC:
10501e04c3fSmrg   case GL_PALETTE4_RGB8_OES:
10601e04c3fSmrg   case GL_PALETTE4_R5_G6_B5_OES:
10701e04c3fSmrg   case GL_PALETTE8_RGB8_OES:
10801e04c3fSmrg   case GL_PALETTE8_R5_G6_B5_OES:
109b9abf16eSmaya   case GL_ATC_RGB_AMD:
1103464ebd5Sriastradh      return GL_RGB;
1113464ebd5Sriastradh
1123464ebd5Sriastradh   case GL_COMPRESSED_RGBA:
1133464ebd5Sriastradh   case GL_COMPRESSED_SRGB_ALPHA:
1143464ebd5Sriastradh   case GL_COMPRESSED_RGBA_BPTC_UNORM_ARB:
1153464ebd5Sriastradh   case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB:
1163464ebd5Sriastradh   case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
1173464ebd5Sriastradh   case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
1183464ebd5Sriastradh   case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
1193464ebd5Sriastradh   case GL_COMPRESSED_RGBA_FXT1_3DFX:
1203464ebd5Sriastradh   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
1213464ebd5Sriastradh   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
1223464ebd5Sriastradh   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
123af69d88dSmrg   case GL_COMPRESSED_RGBA8_ETC2_EAC:
124af69d88dSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
125af69d88dSmrg   case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
126af69d88dSmrg   case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
12701e04c3fSmrg   case GL_RGBA_S3TC:
12801e04c3fSmrg   case GL_RGBA4_S3TC:
12901e04c3fSmrg   case GL_PALETTE4_RGBA8_OES:
13001e04c3fSmrg   case GL_PALETTE8_RGB5_A1_OES:
13101e04c3fSmrg   case GL_PALETTE4_RGBA4_OES:
13201e04c3fSmrg   case GL_PALETTE4_RGB5_A1_OES:
13301e04c3fSmrg   case GL_PALETTE8_RGBA8_OES:
13401e04c3fSmrg   case GL_PALETTE8_RGBA4_OES:
135b9abf16eSmaya   case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
136b9abf16eSmaya   case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
1373464ebd5Sriastradh      return GL_RGBA;
1383464ebd5Sriastradh
1393464ebd5Sriastradh   case GL_COMPRESSED_ALPHA:
1403464ebd5Sriastradh      return GL_ALPHA;
1413464ebd5Sriastradh
1423464ebd5Sriastradh   case GL_COMPRESSED_LUMINANCE:
1433464ebd5Sriastradh   case GL_COMPRESSED_SLUMINANCE:
1443464ebd5Sriastradh   case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
1453464ebd5Sriastradh   case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
1463464ebd5Sriastradh      return GL_LUMINANCE;
1473464ebd5Sriastradh
1483464ebd5Sriastradh   case GL_COMPRESSED_LUMINANCE_ALPHA:
1493464ebd5Sriastradh   case GL_COMPRESSED_SLUMINANCE_ALPHA:
1503464ebd5Sriastradh   case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
1513464ebd5Sriastradh   case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
1523464ebd5Sriastradh   case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
1533464ebd5Sriastradh      return GL_LUMINANCE_ALPHA;
1543464ebd5Sriastradh
1553464ebd5Sriastradh   case GL_COMPRESSED_INTENSITY:
1563464ebd5Sriastradh      return GL_INTENSITY;
1573464ebd5Sriastradh
1583464ebd5Sriastradh   default:
1593464ebd5Sriastradh      return 0;
1603464ebd5Sriastradh   }
1613464ebd5Sriastradh}
1623464ebd5Sriastradh
1637117f1b4Smrg/**
1647117f1b4Smrg * Return list of (and count of) all specific texture compression
1657117f1b4Smrg * formats that are supported.
1667117f1b4Smrg *
1673464ebd5Sriastradh * Some formats are \b not returned by this function.  The
1683464ebd5Sriastradh * \c GL_COMPRESSED_TEXTURE_FORMATS query only returns formats that are
1693464ebd5Sriastradh * "suitable for general-purpose usage."  All texture compression extensions
1703464ebd5Sriastradh * have taken this to mean either linear RGB or linear RGBA.
1713464ebd5Sriastradh *
1723464ebd5Sriastradh * The GL_ARB_texture_compress_rgtc spec says:
1733464ebd5Sriastradh *
1743464ebd5Sriastradh *    "19) Should the GL_NUM_COMPRESSED_TEXTURE_FORMATS and
1753464ebd5Sriastradh *        GL_COMPRESSED_TEXTURE_FORMATS queries return the RGTC formats?
1763464ebd5Sriastradh *
1773464ebd5Sriastradh *        RESOLVED:  No.
1783464ebd5Sriastradh *
1793464ebd5Sriastradh *        The OpenGL 2.1 specification says "The only values returned
1803464ebd5Sriastradh *        by this query [GL_COMPRESSED_TEXTURE_FORMATS"] are those
1813464ebd5Sriastradh *        corresponding to formats suitable for general-purpose usage.
1823464ebd5Sriastradh *        The renderer will not enumerate formats with restrictions that
1833464ebd5Sriastradh *        need to be specifically understood prior to use."
1843464ebd5Sriastradh *
1853464ebd5Sriastradh *        Compressed textures with just red or red-green components are
1863464ebd5Sriastradh *        not general-purpose so should not be returned by these queries
1873464ebd5Sriastradh *        because they have restrictions.
1883464ebd5Sriastradh *
1893464ebd5Sriastradh *        Applications that seek to use the RGTC formats should do so
1903464ebd5Sriastradh *        by looking for this extension's name in the string returned by
1913464ebd5Sriastradh *        glGetString(GL_EXTENSIONS) rather than
1923464ebd5Sriastradh *        what GL_NUM_COMPRESSED_TEXTURE_FORMATS and
1933464ebd5Sriastradh *        GL_COMPRESSED_TEXTURE_FORMATS return."
1943464ebd5Sriastradh *
1953464ebd5Sriastradh * There is nearly identical wording in the GL_EXT_texture_compression_rgtc
1963464ebd5Sriastradh * spec.
1973464ebd5Sriastradh *
1983464ebd5Sriastradh * The GL_EXT_texture_rRGB spec says:
1993464ebd5Sriastradh *
2003464ebd5Sriastradh *    "22) Should the new COMPRESSED_SRGB_* formats be listed in an
2013464ebd5Sriastradh *        implementation's GL_COMPRESSED_TEXTURE_FORMATS list?
2023464ebd5Sriastradh *
2033464ebd5Sriastradh *        RESOLVED:  No.  Section 3.8.1 says formats listed by
2043464ebd5Sriastradh *        GL_COMPRESSED_TEXTURE_FORMATS are "suitable for general-purpose
2053464ebd5Sriastradh *        usage."  The non-linear distribution of red, green, and
2063464ebd5Sriastradh *        blue for these sRGB compressed formats makes them not really
2073464ebd5Sriastradh *        general-purpose."
2083464ebd5Sriastradh *
2093464ebd5Sriastradh * The GL_EXT_texture_compression_latc spec says:
2103464ebd5Sriastradh *
2113464ebd5Sriastradh *    "16) Should the GL_NUM_COMPRESSED_TEXTURE_FORMATS and
2123464ebd5Sriastradh *        GL_COMPRESSED_TEXTURE_FORMATS queries return the LATC formats?
2133464ebd5Sriastradh *
2143464ebd5Sriastradh *        RESOLVED:  No.
2153464ebd5Sriastradh *
2163464ebd5Sriastradh *        The OpenGL 2.1 specification says "The only values returned
2173464ebd5Sriastradh *        by this query [GL_COMPRESSED_TEXTURE_FORMATS"] are those
2183464ebd5Sriastradh *        corresponding to formats suitable for general-purpose usage.
2193464ebd5Sriastradh *        The renderer will not enumerate formats with restrictions that
2203464ebd5Sriastradh *        need to be specifically understood prior to use."
2213464ebd5Sriastradh *
2223464ebd5Sriastradh *        Historically, OpenGL implementation have advertised the RGB and
2233464ebd5Sriastradh *        RGBA versions of the S3TC extensions compressed format tokens
2243464ebd5Sriastradh *        through this mechanism.
2253464ebd5Sriastradh *
2263464ebd5Sriastradh *        The specification is not sufficiently clear about what "suitable
2273464ebd5Sriastradh *        for general-purpose usage" means.  Historically that seems to mean
2283464ebd5Sriastradh *        unsigned RGB or unsigned RGBA.  The DXT1 format supporting alpha
2293464ebd5Sriastradh *        (GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) is not exposed in the list (at
2303464ebd5Sriastradh *        least for NVIDIA drivers) because the alpha is always 1.0 expect
2313464ebd5Sriastradh *        when it is 0.0 when RGB is required to be black.  NVIDIA's even
2323464ebd5Sriastradh *        limits itself to true linear RGB or RGBA formats, specifically
2333464ebd5Sriastradh *        not including EXT_texture_sRGB's sRGB S3TC compressed formats.
2343464ebd5Sriastradh *
2353464ebd5Sriastradh *        Adding luminance and luminance-alpha texture formats (and
2363464ebd5Sriastradh *        certainly signed versions of luminance and luminance-alpha
2373464ebd5Sriastradh *        formats!) invites potential comptaibility problems with old
2383464ebd5Sriastradh *        applications using this mechanism since old applications are
2393464ebd5Sriastradh *        unlikely to expect non-RGB or non-RGBA formats to be advertised
2403464ebd5Sriastradh *        through this mechanism.  However no specific misinteractions
2413464ebd5Sriastradh *        with old applications is known.
2423464ebd5Sriastradh *
2433464ebd5Sriastradh *        Applications that seek to use the LATC formats should do so
2443464ebd5Sriastradh *        by looking for this extension's name in the string returned by
2453464ebd5Sriastradh *        glGetString(GL_EXTENSIONS) rather than
2463464ebd5Sriastradh *        what GL_NUM_COMPRESSED_TEXTURE_FORMATS and
2473464ebd5Sriastradh *        GL_COMPRESSED_TEXTURE_FORMATS return."
2483464ebd5Sriastradh *
2493464ebd5Sriastradh * There is no formal spec for GL_ATI_texture_compression_3dc.  Since the
2503464ebd5Sriastradh * formats added by this extension are luminance-alpha formats, it is
2513464ebd5Sriastradh * reasonable to expect them to follow the same rules as
2523464ebd5Sriastradh * GL_EXT_texture_compression_latc.  At the very least, Catalyst 11.6 does not
2533464ebd5Sriastradh * expose the 3dc formats through this mechanism.
2543464ebd5Sriastradh *
255af69d88dSmrg * The spec for GL_ARB_texture_compression_bptc doesn't mention whether it
256af69d88dSmrg * should be included in GL_COMPRESSED_TEXTURE_FORMATS. However as it takes a
257af69d88dSmrg * very long time to compress the textures in this format it's probably not
258af69d88dSmrg * very useful as a general format where the GL will have to compress it on
259af69d88dSmrg * the fly.
260af69d88dSmrg *
2617117f1b4Smrg * \param ctx  the GL context
2627117f1b4Smrg * \param formats  the resulting format list (may be NULL).
2637117f1b4Smrg *
2647117f1b4Smrg * \return number of formats.
2657117f1b4Smrg */
2667117f1b4SmrgGLuint
2673464ebd5Sriastradh_mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
2687117f1b4Smrg{
26901e04c3fSmrg   GLint discard_formats[100];
2707117f1b4Smrg   GLuint n = 0;
27101e04c3fSmrg
27201e04c3fSmrg   if (!formats) {
27301e04c3fSmrg      formats = discard_formats;
27401e04c3fSmrg   }
27501e04c3fSmrg
27601e04c3fSmrg   if (_mesa_is_desktop_gl(ctx) &&
27701e04c3fSmrg       ctx->Extensions.TDFX_texture_compression_FXT1) {
27801e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGB_FXT1_3DFX;
27901e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_FXT1_3DFX;
2804a49301eSmrg   }
2813464ebd5Sriastradh
2824a49301eSmrg   if (ctx->Extensions.EXT_texture_compression_s3tc) {
28301e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
28401e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
28501e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
286af69d88dSmrg
287af69d88dSmrg      /* The ES and desktop GL specs diverge here.
288af69d88dSmrg       *
289af69d88dSmrg       * In desktop OpenGL, the driver can perform online compression of
290af69d88dSmrg       * uncompressed texture data.  GL_NUM_COMPRESSED_TEXTURE_FORMATS and
291af69d88dSmrg       * GL_COMPRESSED_TEXTURE_FORMATS give the application a list of
292af69d88dSmrg       * formats that it could ask the driver to compress with some
293af69d88dSmrg       * expectation of quality.  The GL_ARB_texture_compression spec
294af69d88dSmrg       * calls this "suitable for general-purpose usage."  As noted
295af69d88dSmrg       * above, this means GL_COMPRESSED_RGBA_S3TC_DXT1_EXT is not
296af69d88dSmrg       * included in the list.
297af69d88dSmrg       *
298af69d88dSmrg       * In OpenGL ES, the driver never performs compression.
299af69d88dSmrg       * GL_NUM_COMPRESSED_TEXTURE_FORMATS and
300af69d88dSmrg       * GL_COMPRESSED_TEXTURE_FORMATS give the application a list of
301af69d88dSmrg       * formats that the driver can receive from the application.  It
302af69d88dSmrg       * is the *complete* list of formats.  The
303af69d88dSmrg       * GL_EXT_texture_compression_s3tc spec says:
304af69d88dSmrg       *
305af69d88dSmrg       *     "New State for OpenGL ES 2.0.25 and 3.0.2 Specifications
306af69d88dSmrg       *
307af69d88dSmrg       *         The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
308af69d88dSmrg       *         COMPRESSED_TEXTURE_FORMATS include
309af69d88dSmrg       *         COMPRESSED_RGB_S3TC_DXT1_EXT,
310af69d88dSmrg       *         COMPRESSED_RGBA_S3TC_DXT1_EXT,
311af69d88dSmrg       *         COMPRESSED_RGBA_S3TC_DXT3_EXT, and
312af69d88dSmrg       *         COMPRESSED_RGBA_S3TC_DXT5_EXT."
313af69d88dSmrg       *
314af69d88dSmrg       * Note that the addition is only to the OpenGL ES specification!
315af69d88dSmrg       */
316af69d88dSmrg      if (_mesa_is_gles(ctx)) {
31701e04c3fSmrg         formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
318af69d88dSmrg      }
3194a49301eSmrg   }
320af69d88dSmrg
321af69d88dSmrg   /* The GL_OES_compressed_ETC1_RGB8_texture spec says:
322af69d88dSmrg    *
323af69d88dSmrg    *     "New State
324af69d88dSmrg    *
325af69d88dSmrg    *         The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
326af69d88dSmrg    *         COMPRESSED_TEXTURE_FORMATS include ETC1_RGB8_OES."
327af69d88dSmrg    */
328af69d88dSmrg   if (_mesa_is_gles(ctx)
329af69d88dSmrg       && ctx->Extensions.OES_compressed_ETC1_RGB8_texture) {
33001e04c3fSmrg      formats[n++] = GL_ETC1_RGB8_OES;
3314a49301eSmrg   }
3323464ebd5Sriastradh
333b9abf16eSmaya   /* Required by EXT_texture_compression_bptc in GLES. */
334b9abf16eSmaya   if (_mesa_has_EXT_texture_compression_bptc(ctx)) {
335b9abf16eSmaya      formats[n++] = GL_COMPRESSED_RGBA_BPTC_UNORM;
336b9abf16eSmaya      formats[n++] = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
337b9abf16eSmaya      formats[n++] = GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT;
338b9abf16eSmaya      formats[n++] = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
339b9abf16eSmaya   }
340b9abf16eSmaya
341b9abf16eSmaya   /* Required by EXT_texture_compression_rgtc in GLES. */
342b9abf16eSmaya   if (_mesa_is_gles3(ctx) &&
343b9abf16eSmaya       _mesa_has_EXT_texture_compression_rgtc(ctx)) {
344b9abf16eSmaya      formats[n++] = GL_COMPRESSED_RED_RGTC1_EXT;
345b9abf16eSmaya      formats[n++] = GL_COMPRESSED_SIGNED_RED_RGTC1_EXT;
346b9abf16eSmaya      formats[n++] = GL_COMPRESSED_RED_GREEN_RGTC2_EXT;
347b9abf16eSmaya      formats[n++] = GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT;
348b9abf16eSmaya   }
349b9abf16eSmaya
350af69d88dSmrg   if (ctx->API == API_OPENGLES) {
35101e04c3fSmrg      formats[n++] = GL_PALETTE4_RGB8_OES;
35201e04c3fSmrg      formats[n++] = GL_PALETTE4_RGBA8_OES;
35301e04c3fSmrg      formats[n++] = GL_PALETTE4_R5_G6_B5_OES;
35401e04c3fSmrg      formats[n++] = GL_PALETTE4_RGBA4_OES;
35501e04c3fSmrg      formats[n++] = GL_PALETTE4_RGB5_A1_OES;
35601e04c3fSmrg      formats[n++] = GL_PALETTE8_RGB8_OES;
35701e04c3fSmrg      formats[n++] = GL_PALETTE8_RGBA8_OES;
35801e04c3fSmrg      formats[n++] = GL_PALETTE8_R5_G6_B5_OES;
35901e04c3fSmrg      formats[n++] = GL_PALETTE8_RGBA4_OES;
36001e04c3fSmrg      formats[n++] = GL_PALETTE8_RGB5_A1_OES;
36101e04c3fSmrg   }
36201e04c3fSmrg
36301e04c3fSmrg   if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility) {
36401e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGB8_ETC2;
36501e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA8_ETC2_EAC;
36601e04c3fSmrg      formats[n++] = GL_COMPRESSED_R11_EAC;
36701e04c3fSmrg      formats[n++] = GL_COMPRESSED_RG11_EAC;
36801e04c3fSmrg      formats[n++] = GL_COMPRESSED_SIGNED_R11_EAC;
36901e04c3fSmrg      formats[n++] = GL_COMPRESSED_SIGNED_RG11_EAC;
37001e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
3713464ebd5Sriastradh   }
372af69d88dSmrg
373af69d88dSmrg   if (_mesa_is_gles3(ctx)) {
37401e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ETC2;
37501e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
37601e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
3773464ebd5Sriastradh   }
37801e04c3fSmrg
37901e04c3fSmrg   /* The KHR_texture_compression_astc_hdr spec says:
38001e04c3fSmrg    *
38101e04c3fSmrg    *    "Interactions with OpenGL 4.2
38201e04c3fSmrg    *
38301e04c3fSmrg    *        OpenGL 4.2 supports the feature that compressed textures can be
38401e04c3fSmrg    *        compressed online, by passing the compressed texture format enum
38501e04c3fSmrg    *        as the internal format when uploading a texture using TexImage1D,
38601e04c3fSmrg    *        TexImage2D or TexImage3D (see Section 3.9.3, Texture Image
38701e04c3fSmrg    *        Specification, subsection Encoding of Special Internal Formats).
38801e04c3fSmrg    *
38901e04c3fSmrg    *        Due to the complexity of the ASTC compression algorithm, it is
39001e04c3fSmrg    *        not usually suitable for online use, and therefore ASTC support
39101e04c3fSmrg    *        will be limited to pre-compressed textures only. Where on-device
39201e04c3fSmrg    *        compression is required, a domain-specific limited compressor
39301e04c3fSmrg    *        will typically be used, and this is therefore not suitable for
39401e04c3fSmrg    *        implementation in the driver.
39501e04c3fSmrg    *
39601e04c3fSmrg    *        In particular, the ASTC format specifiers will not be added to
39701e04c3fSmrg    *        Table 3.14, and thus will not be accepted by the TexImage*D
39801e04c3fSmrg    *        functions, and will not be returned by the (already deprecated)
39901e04c3fSmrg    *        COMPRESSED_TEXTURE_FORMATS query."
40001e04c3fSmrg    *
40101e04c3fSmrg    * The ES and the desktop specs diverge here. In OpenGL ES, the
40201e04c3fSmrg    * COMPRESSED_TEXTURE_FORMATS query returns the set of supported specific
40301e04c3fSmrg    * compressed formats.
40401e04c3fSmrg    */
40501e04c3fSmrg   if (ctx->API == API_OPENGLES2 &&
40601e04c3fSmrg       ctx->Extensions.KHR_texture_compression_astc_ldr) {
40701e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
40801e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
40901e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
41001e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
41101e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
41201e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
41301e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
41401e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
41501e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
41601e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
41701e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
41801e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
41901e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
42001e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
42101e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
42201e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
42301e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
42401e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
42501e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
42601e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
42701e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
42801e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
42901e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
43001e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
43101e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
43201e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
43301e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
43401e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
43501e04c3fSmrg   }
43601e04c3fSmrg
43701e04c3fSmrg   if (_mesa_is_gles3(ctx) &&
43801e04c3fSmrg       ctx->Extensions.OES_texture_compression_astc) {
43901e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_3x3x3_OES;
44001e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x3x3_OES;
44101e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4x3_OES;
44201e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4x4_OES;
44301e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x4x4_OES;
44401e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5x4_OES;
44501e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5x5_OES;
44601e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x5x5_OES;
44701e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6x5_OES;
44801e04c3fSmrg      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6x6_OES;
44901e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES;
45001e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES;
45101e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES;
45201e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES;
45301e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES;
45401e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES;
45501e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES;
45601e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES;
45701e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES;
45801e04c3fSmrg      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES;
45901e04c3fSmrg   }
46001e04c3fSmrg
461b9abf16eSmaya   /* The GL_AMD_compressed_ATC_texture spec says:
462b9abf16eSmaya    *
463b9abf16eSmaya    *     "New State
464b9abf16eSmaya    *
465b9abf16eSmaya    *         The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
466b9abf16eSmaya    *         COMPRESSED_TEXTURE_FORMATS include ATC_RGB_AMD,
467b9abf16eSmaya    *         ATC_RGBA_EXPLICIT_ALPHA_AMD, and ATC_RGBA_INTERPOLATED_ALPHA_AMD."
468b9abf16eSmaya    */
469b9abf16eSmaya   if (_mesa_has_AMD_compressed_ATC_texture(ctx)) {
470b9abf16eSmaya      formats[n++] = GL_ATC_RGB_AMD;
471b9abf16eSmaya      formats[n++] = GL_ATC_RGBA_EXPLICIT_ALPHA_AMD;
472b9abf16eSmaya      formats[n++] = GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
473b9abf16eSmaya   }
474b9abf16eSmaya
47501e04c3fSmrg   assert(n <= ARRAY_SIZE(discard_formats));
47601e04c3fSmrg
477af69d88dSmrg   return n;
4787117f1b4Smrg}
4797117f1b4Smrg
4807117f1b4Smrg
4817117f1b4Smrg/**
48201e04c3fSmrg * Convert GLenum to a compressed MESA_FORMAT_x.
4837117f1b4Smrg */
484af69d88dSmrgmesa_format
4854a49301eSmrg_mesa_glenum_to_compressed_format(GLenum format)
4867117f1b4Smrg{
4874a49301eSmrg   switch (format) {
4887117f1b4Smrg   case GL_COMPRESSED_RGB_FXT1_3DFX:
4894a49301eSmrg      return MESA_FORMAT_RGB_FXT1;
4907117f1b4Smrg   case GL_COMPRESSED_RGBA_FXT1_3DFX:
4914a49301eSmrg      return MESA_FORMAT_RGBA_FXT1;
4924a49301eSmrg
4937117f1b4Smrg   case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
4947117f1b4Smrg   case GL_RGB_S3TC:
49501e04c3fSmrg   case GL_RGB4_S3TC:
4964a49301eSmrg      return MESA_FORMAT_RGB_DXT1;
4977117f1b4Smrg   case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
4984a49301eSmrg      return MESA_FORMAT_RGBA_DXT1;
4997117f1b4Smrg   case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
5007117f1b4Smrg   case GL_RGBA_S3TC:
50101e04c3fSmrg   case GL_RGBA4_S3TC:
5024a49301eSmrg      return MESA_FORMAT_RGBA_DXT3;
5037117f1b4Smrg   case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
5044a49301eSmrg      return MESA_FORMAT_RGBA_DXT5;
5054a49301eSmrg
5064a49301eSmrg   case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
5074a49301eSmrg      return MESA_FORMAT_SRGB_DXT1;
5084a49301eSmrg   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
5094a49301eSmrg      return MESA_FORMAT_SRGBA_DXT1;
5104a49301eSmrg   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
5114a49301eSmrg      return MESA_FORMAT_SRGBA_DXT3;
5124a49301eSmrg   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
5134a49301eSmrg      return MESA_FORMAT_SRGBA_DXT5;
5144a49301eSmrg
5153464ebd5Sriastradh   case GL_COMPRESSED_RED_RGTC1:
516af69d88dSmrg      return MESA_FORMAT_R_RGTC1_UNORM;
5173464ebd5Sriastradh   case GL_COMPRESSED_SIGNED_RED_RGTC1:
518af69d88dSmrg      return MESA_FORMAT_R_RGTC1_SNORM;
5193464ebd5Sriastradh   case GL_COMPRESSED_RG_RGTC2:
520af69d88dSmrg      return MESA_FORMAT_RG_RGTC2_UNORM;
5213464ebd5Sriastradh   case GL_COMPRESSED_SIGNED_RG_RGTC2:
522af69d88dSmrg      return MESA_FORMAT_RG_RGTC2_SNORM;
5233464ebd5Sriastradh
5243464ebd5Sriastradh   case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
525af69d88dSmrg      return MESA_FORMAT_L_LATC1_UNORM;
5263464ebd5Sriastradh   case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
527af69d88dSmrg      return MESA_FORMAT_L_LATC1_SNORM;
5283464ebd5Sriastradh   case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
5293464ebd5Sriastradh   case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
530af69d88dSmrg      return MESA_FORMAT_LA_LATC2_UNORM;
5313464ebd5Sriastradh   case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
532af69d88dSmrg      return MESA_FORMAT_LA_LATC2_SNORM;
533af69d88dSmrg
534af69d88dSmrg   case GL_ETC1_RGB8_OES:
535af69d88dSmrg      return MESA_FORMAT_ETC1_RGB8;
536af69d88dSmrg   case GL_COMPRESSED_RGB8_ETC2:
537af69d88dSmrg      return MESA_FORMAT_ETC2_RGB8;
538af69d88dSmrg   case GL_COMPRESSED_SRGB8_ETC2:
539af69d88dSmrg      return MESA_FORMAT_ETC2_SRGB8;
540af69d88dSmrg   case GL_COMPRESSED_RGBA8_ETC2_EAC:
541af69d88dSmrg      return MESA_FORMAT_ETC2_RGBA8_EAC;
542af69d88dSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
543af69d88dSmrg      return MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC;
544af69d88dSmrg   case GL_COMPRESSED_R11_EAC:
545af69d88dSmrg      return MESA_FORMAT_ETC2_R11_EAC;
546af69d88dSmrg   case GL_COMPRESSED_RG11_EAC:
547af69d88dSmrg      return MESA_FORMAT_ETC2_RG11_EAC;
548af69d88dSmrg   case GL_COMPRESSED_SIGNED_R11_EAC:
549af69d88dSmrg      return MESA_FORMAT_ETC2_SIGNED_R11_EAC;
550af69d88dSmrg   case GL_COMPRESSED_SIGNED_RG11_EAC:
551af69d88dSmrg      return MESA_FORMAT_ETC2_SIGNED_RG11_EAC;
552af69d88dSmrg   case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
553af69d88dSmrg      return MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
554af69d88dSmrg   case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
555af69d88dSmrg      return MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
556af69d88dSmrg
557af69d88dSmrg   case GL_COMPRESSED_RGBA_BPTC_UNORM:
558af69d88dSmrg      return MESA_FORMAT_BPTC_RGBA_UNORM;
559af69d88dSmrg   case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
560af69d88dSmrg      return MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM;
561af69d88dSmrg   case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
562af69d88dSmrg      return MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT;
563af69d88dSmrg   case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
564af69d88dSmrg      return MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT;
5653464ebd5Sriastradh
56601e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
56701e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_4x4;
56801e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
56901e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_5x4;
57001e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
57101e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_5x5;
57201e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
57301e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_6x5;
57401e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
57501e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_6x6;
57601e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
57701e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_8x5;
57801e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
57901e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_8x6;
58001e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
58101e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_8x8;
58201e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
58301e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_10x5;
58401e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
58501e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_10x6;
58601e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
58701e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_10x8;
58801e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
58901e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_10x10;
59001e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
59101e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_12x10;
59201e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
59301e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_12x12;
59401e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
59501e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4;
59601e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
59701e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4;
59801e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
59901e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5;
60001e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
60101e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5;
60201e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
60301e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6;
60401e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
60501e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5;
60601e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
60701e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6;
60801e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
60901e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8;
61001e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
61101e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5;
61201e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
61301e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6;
61401e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
61501e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8;
61601e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
61701e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10;
61801e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
61901e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10;
62001e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
62101e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12;
62201e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_3x3x3_OES:
62301e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_3x3x3;
62401e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_4x3x3_OES:
62501e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_4x3x3;
62601e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_4x4x3_OES:
62701e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_4x4x3;
62801e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_4x4x4_OES:
62901e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_4x4x4;
63001e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_5x4x4_OES:
63101e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_5x4x4;
63201e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_5x5x4_OES:
63301e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_5x5x4;
63401e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_5x5x5_OES:
63501e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_5x5x5;
63601e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_6x5x5_OES:
63701e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_6x5x5;
63801e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_6x6x5_OES:
63901e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_6x6x5;
64001e04c3fSmrg   case GL_COMPRESSED_RGBA_ASTC_6x6x6_OES:
64101e04c3fSmrg      return MESA_FORMAT_RGBA_ASTC_6x6x6;
64201e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES:
64301e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3;
64401e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES:
64501e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3;
64601e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES:
64701e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3;
64801e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES:
64901e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4;
65001e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES:
65101e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4;
65201e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES:
65301e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4;
65401e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES:
65501e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5;
65601e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES:
65701e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5;
65801e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES:
65901e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5;
66001e04c3fSmrg   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES:
66101e04c3fSmrg      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6;
66201e04c3fSmrg
663b9abf16eSmaya   case GL_ATC_RGB_AMD:
664b9abf16eSmaya      return MESA_FORMAT_ATC_RGB;
665b9abf16eSmaya   case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
666b9abf16eSmaya      return MESA_FORMAT_ATC_RGBA_EXPLICIT;
667b9abf16eSmaya   case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
668b9abf16eSmaya      return MESA_FORMAT_ATC_RGBA_INTERPOLATED;
669b9abf16eSmaya
6707117f1b4Smrg   default:
6714a49301eSmrg      return MESA_FORMAT_NONE;
6727117f1b4Smrg   }
6737117f1b4Smrg}
6747117f1b4Smrg
6757117f1b4Smrg
6764a49301eSmrg/**
6774a49301eSmrg * Given a compressed MESA_FORMAT_x value, return the corresponding
6784a49301eSmrg * GLenum for that format.
6794a49301eSmrg * This is needed for glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT)
6804a49301eSmrg * which must return the specific texture format used when the user might
6814a49301eSmrg * have originally specified a generic compressed format in their
6824a49301eSmrg * glTexImage2D() call.
6834a49301eSmrg * For non-compressed textures, we always return the user-specified
6844a49301eSmrg * internal format unchanged.
6857117f1b4Smrg */
6864a49301eSmrgGLenum
68701e04c3fSmrg_mesa_compressed_format_to_glenum(struct gl_context *ctx,
68801e04c3fSmrg                                  mesa_format mesaFormat)
6897117f1b4Smrg{
6907117f1b4Smrg   switch (mesaFormat) {
6917117f1b4Smrg   case MESA_FORMAT_RGB_FXT1:
6924a49301eSmrg      return GL_COMPRESSED_RGB_FXT1_3DFX;
6937117f1b4Smrg   case MESA_FORMAT_RGBA_FXT1:
6944a49301eSmrg      return GL_COMPRESSED_RGBA_FXT1_3DFX;
6957117f1b4Smrg   case MESA_FORMAT_RGB_DXT1:
6964a49301eSmrg      return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
6977117f1b4Smrg   case MESA_FORMAT_RGBA_DXT1:
6984a49301eSmrg      return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
6997117f1b4Smrg   case MESA_FORMAT_RGBA_DXT3:
7004a49301eSmrg      return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
7017117f1b4Smrg   case MESA_FORMAT_RGBA_DXT5:
7024a49301eSmrg      return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
7034a49301eSmrg   case MESA_FORMAT_SRGB_DXT1:
7044a49301eSmrg      return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
7054a49301eSmrg   case MESA_FORMAT_SRGBA_DXT1:
7064a49301eSmrg      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
7074a49301eSmrg   case MESA_FORMAT_SRGBA_DXT3:
7084a49301eSmrg      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
7094a49301eSmrg   case MESA_FORMAT_SRGBA_DXT5:
7104a49301eSmrg      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
711af69d88dSmrg   case MESA_FORMAT_R_RGTC1_UNORM:
7123464ebd5Sriastradh      return GL_COMPRESSED_RED_RGTC1;
713af69d88dSmrg   case MESA_FORMAT_R_RGTC1_SNORM:
7143464ebd5Sriastradh      return GL_COMPRESSED_SIGNED_RED_RGTC1;
715af69d88dSmrg   case MESA_FORMAT_RG_RGTC2_UNORM:
7163464ebd5Sriastradh      return GL_COMPRESSED_RG_RGTC2;
717af69d88dSmrg   case MESA_FORMAT_RG_RGTC2_SNORM:
7183464ebd5Sriastradh      return GL_COMPRESSED_SIGNED_RG_RGTC2;
7193464ebd5Sriastradh
720af69d88dSmrg   case MESA_FORMAT_L_LATC1_UNORM:
7213464ebd5Sriastradh      return GL_COMPRESSED_LUMINANCE_LATC1_EXT;
722af69d88dSmrg   case MESA_FORMAT_L_LATC1_SNORM:
7233464ebd5Sriastradh      return GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT;
724af69d88dSmrg   case MESA_FORMAT_LA_LATC2_UNORM:
7253464ebd5Sriastradh      return GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT;
726af69d88dSmrg   case MESA_FORMAT_LA_LATC2_SNORM:
7273464ebd5Sriastradh      return GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT;
7283464ebd5Sriastradh
729af69d88dSmrg   case MESA_FORMAT_ETC1_RGB8:
730af69d88dSmrg      return GL_ETC1_RGB8_OES;
731af69d88dSmrg   case MESA_FORMAT_ETC2_RGB8:
732af69d88dSmrg      return GL_COMPRESSED_RGB8_ETC2;
733af69d88dSmrg   case MESA_FORMAT_ETC2_SRGB8:
734af69d88dSmrg      return GL_COMPRESSED_SRGB8_ETC2;
735af69d88dSmrg   case MESA_FORMAT_ETC2_RGBA8_EAC:
736af69d88dSmrg      return GL_COMPRESSED_RGBA8_ETC2_EAC;
737af69d88dSmrg   case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
738af69d88dSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
739af69d88dSmrg   case MESA_FORMAT_ETC2_R11_EAC:
740af69d88dSmrg      return GL_COMPRESSED_R11_EAC;
741af69d88dSmrg   case MESA_FORMAT_ETC2_RG11_EAC:
742af69d88dSmrg      return GL_COMPRESSED_RG11_EAC;
743af69d88dSmrg   case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
744af69d88dSmrg      return GL_COMPRESSED_SIGNED_R11_EAC;
745af69d88dSmrg   case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
746af69d88dSmrg      return GL_COMPRESSED_SIGNED_RG11_EAC;
747af69d88dSmrg   case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
748af69d88dSmrg      return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
749af69d88dSmrg   case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
750af69d88dSmrg      return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
751af69d88dSmrg
752af69d88dSmrg   case MESA_FORMAT_BPTC_RGBA_UNORM:
753af69d88dSmrg      return GL_COMPRESSED_RGBA_BPTC_UNORM;
754af69d88dSmrg   case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
755af69d88dSmrg      return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
756af69d88dSmrg   case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:
757af69d88dSmrg      return GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT;
758af69d88dSmrg   case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:
759af69d88dSmrg      return GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
760af69d88dSmrg
76101e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_4x4:
76201e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
76301e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_5x4:
76401e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
76501e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_5x5:
76601e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
76701e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_6x5:
76801e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
76901e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_6x6:
77001e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
77101e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_8x5:
77201e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
77301e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_8x6:
77401e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
77501e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_8x8:
77601e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
77701e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_10x5:
77801e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
77901e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_10x6:
78001e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
78101e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_10x8:
78201e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
78301e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_10x10:
78401e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
78501e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_12x10:
78601e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
78701e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_12x12:
78801e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
78901e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4:
79001e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
79101e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4:
79201e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
79301e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5:
79401e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
79501e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5:
79601e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
79701e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6:
79801e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
79901e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5:
80001e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
80101e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6:
80201e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
80301e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8:
80401e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
80501e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5:
80601e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
80701e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6:
80801e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
80901e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8:
81001e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
81101e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10:
81201e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
81301e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10:
81401e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
81501e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12:
81601e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
81701e04c3fSmrg
81801e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_3x3x3:
81901e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_3x3x3_OES;
82001e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_4x3x3:
82101e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_4x3x3_OES;
82201e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_4x4x3:
82301e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_4x4x3_OES;
82401e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_4x4x4:
82501e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_4x4x4_OES;
82601e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_5x4x4:
82701e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_5x4x4_OES;
82801e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_5x5x4:
82901e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_5x5x4_OES;
83001e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_5x5x5:
83101e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_5x5x5_OES;
83201e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_6x5x5:
83301e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_6x5x5_OES;
83401e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_6x6x5:
83501e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_6x6x5_OES;
83601e04c3fSmrg   case MESA_FORMAT_RGBA_ASTC_6x6x6:
83701e04c3fSmrg      return GL_COMPRESSED_RGBA_ASTC_6x6x6_OES;
83801e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3:
83901e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES;
84001e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3:
84101e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES;
84201e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3:
84301e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES;
84401e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4:
84501e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES;
84601e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4:
84701e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES;
84801e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4:
84901e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES;
85001e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5:
85101e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES;
85201e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5:
85301e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES;
85401e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5:
85501e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES;
85601e04c3fSmrg   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6:
85701e04c3fSmrg      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES;
858b9abf16eSmaya
859b9abf16eSmaya   case MESA_FORMAT_ATC_RGB:
860b9abf16eSmaya      return GL_ATC_RGB_AMD;
861b9abf16eSmaya   case MESA_FORMAT_ATC_RGBA_EXPLICIT:
862b9abf16eSmaya      return GL_ATC_RGBA_EXPLICIT_ALPHA_AMD;
863b9abf16eSmaya   case MESA_FORMAT_ATC_RGBA_INTERPOLATED:
864b9abf16eSmaya      return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
865b9abf16eSmaya
8667117f1b4Smrg   default:
8674a49301eSmrg      _mesa_problem(ctx, "Unexpected mesa texture format in"
8684a49301eSmrg                    " _mesa_compressed_format_to_glenum()");
8697117f1b4Smrg      return 0;
8707117f1b4Smrg   }
8717117f1b4Smrg}
8727117f1b4Smrg
8737117f1b4Smrg
8747117f1b4Smrg/*
8757117f1b4Smrg * Return the address of the pixel at (col, row, img) in a
8767117f1b4Smrg * compressed texture image.
8774a49301eSmrg * \param col, row, img - image position (3D), should be a multiple of the
8784a49301eSmrg *                        format's block size.
8797117f1b4Smrg * \param format - compressed image format
8804a49301eSmrg * \param width - image width (stride) in pixels
8817117f1b4Smrg * \param image - the image address
8824a49301eSmrg * \return address of pixel at (row, col, img)
8837117f1b4Smrg */
8847117f1b4SmrgGLubyte *
8857117f1b4Smrg_mesa_compressed_image_address(GLint col, GLint row, GLint img,
886af69d88dSmrg                               mesa_format mesaFormat,
8877117f1b4Smrg                               GLsizei width, const GLubyte *image)
8887117f1b4Smrg{
8894a49301eSmrg   /* XXX only 2D images implemented, not 3D */
8904a49301eSmrg   const GLuint blockSize = _mesa_get_format_bytes(mesaFormat);
8914a49301eSmrg   GLuint bw, bh;
8924a49301eSmrg   GLint offset;
8937117f1b4Smrg
8944a49301eSmrg   _mesa_get_format_block_size(mesaFormat, &bw, &bh);
8957117f1b4Smrg
89601e04c3fSmrg   assert(col % bw == 0);
89701e04c3fSmrg   assert(row % bh == 0);
8987117f1b4Smrg
8994a49301eSmrg   offset = ((width + bw - 1) / bw) * (row / bh) + col / bw;
9004a49301eSmrg   offset *= blockSize;
9017117f1b4Smrg
9024a49301eSmrg   return (GLubyte *) image + offset;
9037117f1b4Smrg}
904af69d88dSmrg
905af69d88dSmrg
906af69d88dSmrg/**
907af69d88dSmrg * Return a texel-fetch function for the given format, or NULL if
908af69d88dSmrg * invalid format.
909af69d88dSmrg */
910af69d88dSmrgcompressed_fetch_func
911af69d88dSmrg_mesa_get_compressed_fetch_func(mesa_format format)
912af69d88dSmrg{
91301e04c3fSmrg   switch (_mesa_get_format_layout(format)) {
91401e04c3fSmrg   case MESA_FORMAT_LAYOUT_S3TC:
915af69d88dSmrg      return _mesa_get_dxt_fetch_func(format);
91601e04c3fSmrg   case MESA_FORMAT_LAYOUT_FXT1:
917af69d88dSmrg      return _mesa_get_fxt_fetch_func(format);
91801e04c3fSmrg   case MESA_FORMAT_LAYOUT_RGTC:
91901e04c3fSmrg   case MESA_FORMAT_LAYOUT_LATC:
920af69d88dSmrg      return _mesa_get_compressed_rgtc_func(format);
92101e04c3fSmrg   case MESA_FORMAT_LAYOUT_ETC1:
922af69d88dSmrg      return _mesa_get_etc_fetch_func(format);
92301e04c3fSmrg   case MESA_FORMAT_LAYOUT_BPTC:
924af69d88dSmrg      return _mesa_get_bptc_fetch_func(format);
925af69d88dSmrg   default:
926af69d88dSmrg      return NULL;
927af69d88dSmrg   }
928af69d88dSmrg}
929af69d88dSmrg
930af69d88dSmrg
931af69d88dSmrg/**
932af69d88dSmrg * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image.
933af69d88dSmrg * \param srcRowStride  stride in bytes between rows of blocks in the
934af69d88dSmrg *                      compressed source image.
935af69d88dSmrg */
936af69d88dSmrgvoid
937af69d88dSmrg_mesa_decompress_image(mesa_format format, GLuint width, GLuint height,
938af69d88dSmrg                       const GLubyte *src, GLint srcRowStride,
939af69d88dSmrg                       GLfloat *dest)
940af69d88dSmrg{
941af69d88dSmrg   compressed_fetch_func fetch;
942af69d88dSmrg   GLuint i, j;
943af69d88dSmrg   GLuint bytes, bw, bh;
944af69d88dSmrg   GLint stride;
945af69d88dSmrg
946af69d88dSmrg   bytes = _mesa_get_format_bytes(format);
947af69d88dSmrg   _mesa_get_format_block_size(format, &bw, &bh);
948af69d88dSmrg
949af69d88dSmrg   fetch = _mesa_get_compressed_fetch_func(format);
950af69d88dSmrg   if (!fetch) {
951af69d88dSmrg      _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
952af69d88dSmrg      return;
953af69d88dSmrg   }
95401e04c3fSmrg
955af69d88dSmrg   stride = srcRowStride * bh / bytes;
956af69d88dSmrg
957af69d88dSmrg   for (j = 0; j < height; j++) {
958af69d88dSmrg      for (i = 0; i < width; i++) {
959af69d88dSmrg         fetch(src, stride, i, j, dest);
960af69d88dSmrg         dest += 4;
961af69d88dSmrg      }
962af69d88dSmrg   }
963af69d88dSmrg}
964