1bf215546Sopenharmony_ci/*
2bf215546Sopenharmony_ci * Mesa 3-D graphics library
3bf215546Sopenharmony_ci *
4bf215546Sopenharmony_ci * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
5bf215546Sopenharmony_ci * Copyright (c) 2008 VMware, Inc.
6bf215546Sopenharmony_ci *
7bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
8bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
9bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation
10bf215546Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11bf215546Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
12bf215546Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
13bf215546Sopenharmony_ci *
14bf215546Sopenharmony_ci * The above copyright notice and this permission notice shall be included
15bf215546Sopenharmony_ci * in all copies or substantial portions of the Software.
16bf215546Sopenharmony_ci *
17bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18bf215546Sopenharmony_ci * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20bf215546Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21bf215546Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22bf215546Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23bf215546Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
24bf215546Sopenharmony_ci */
25bf215546Sopenharmony_ci
26bf215546Sopenharmony_ci
27bf215546Sopenharmony_ci/**
28bf215546Sopenharmony_ci * \file texcompress.c
29bf215546Sopenharmony_ci * Helper functions for texture compression.
30bf215546Sopenharmony_ci */
31bf215546Sopenharmony_ci
32bf215546Sopenharmony_ci
33bf215546Sopenharmony_ci#include "glheader.h"
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci#include "context.h"
36bf215546Sopenharmony_ci#include "formats.h"
37bf215546Sopenharmony_ci#include "mtypes.h"
38bf215546Sopenharmony_ci#include "context.h"
39bf215546Sopenharmony_ci#include "texcompress.h"
40bf215546Sopenharmony_ci#include "texcompress_fxt1.h"
41bf215546Sopenharmony_ci#include "texcompress_rgtc.h"
42bf215546Sopenharmony_ci#include "texcompress_s3tc.h"
43bf215546Sopenharmony_ci#include "texcompress_etc.h"
44bf215546Sopenharmony_ci#include "texcompress_bptc.h"
45bf215546Sopenharmony_ci
46bf215546Sopenharmony_ci
47bf215546Sopenharmony_ci/**
48bf215546Sopenharmony_ci * Get the GL base format of a specified GL compressed texture format
49bf215546Sopenharmony_ci *
50bf215546Sopenharmony_ci * From page 232 of the OpenGL 3.3 (Compatiblity Profile) spec:
51bf215546Sopenharmony_ci *
52bf215546Sopenharmony_ci *     "Compressed Internal Format      Base Internal Format    Type
53bf215546Sopenharmony_ci *     ---------------------------     --------------------    ---------
54bf215546Sopenharmony_ci *     COMPRESSED_ALPHA                ALPHA                   Generic
55bf215546Sopenharmony_ci *     COMPRESSED_LUMINANCE            LUMINANCE               Generic
56bf215546Sopenharmony_ci *     COMPRESSED_LUMINANCE_ALPHA      LUMINANCE_ALPHA         Generic
57bf215546Sopenharmony_ci *     COMPRESSED_INTENSITY            INTENSITY               Generic
58bf215546Sopenharmony_ci *     COMPRESSED_RED                  RED                     Generic
59bf215546Sopenharmony_ci *     COMPRESSED_RG                   RG                      Generic
60bf215546Sopenharmony_ci *     COMPRESSED_RGB                  RGB                     Generic
61bf215546Sopenharmony_ci *     COMPRESSED_RGBA                 RGBA                    Generic
62bf215546Sopenharmony_ci *     COMPRESSED_SRGB                 RGB                     Generic
63bf215546Sopenharmony_ci *     COMPRESSED_SRGB_ALPHA           RGBA                    Generic
64bf215546Sopenharmony_ci *     COMPRESSED_SLUMINANCE           LUMINANCE               Generic
65bf215546Sopenharmony_ci *     COMPRESSED_SLUMINANCE_ALPHA     LUMINANCE_ALPHA         Generic
66bf215546Sopenharmony_ci *     COMPRESSED_RED_RGTC1            RED                     Specific
67bf215546Sopenharmony_ci *     COMPRESSED_SIGNED_RED_RGTC1     RED                     Specific
68bf215546Sopenharmony_ci *     COMPRESSED_RG_RGTC2             RG                      Specific
69bf215546Sopenharmony_ci *     COMPRESSED_SIGNED_RG_RGTC2      RG                      Specific"
70bf215546Sopenharmony_ci *
71bf215546Sopenharmony_ci * \return
72bf215546Sopenharmony_ci * The base format of \c format if \c format is a compressed format (either
73bf215546Sopenharmony_ci * generic or specific.  Otherwise 0 is returned.
74bf215546Sopenharmony_ci */
75bf215546Sopenharmony_ciGLenum
76bf215546Sopenharmony_ci_mesa_gl_compressed_format_base_format(GLenum format)
77bf215546Sopenharmony_ci{
78bf215546Sopenharmony_ci   switch (format) {
79bf215546Sopenharmony_ci   case GL_COMPRESSED_RED:
80bf215546Sopenharmony_ci   case GL_COMPRESSED_R11_EAC:
81bf215546Sopenharmony_ci   case GL_COMPRESSED_RED_RGTC1:
82bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_R11_EAC:
83bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_RED_RGTC1:
84bf215546Sopenharmony_ci      return GL_RED;
85bf215546Sopenharmony_ci
86bf215546Sopenharmony_ci   case GL_COMPRESSED_RG:
87bf215546Sopenharmony_ci   case GL_COMPRESSED_RG11_EAC:
88bf215546Sopenharmony_ci   case GL_COMPRESSED_RG_RGTC2:
89bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_RG11_EAC:
90bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_RG_RGTC2:
91bf215546Sopenharmony_ci      return GL_RG;
92bf215546Sopenharmony_ci
93bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB:
94bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB:
95bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT_ARB:
96bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_ARB:
97bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
98bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB_FXT1_3DFX:
99bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
100bf215546Sopenharmony_ci   case GL_ETC1_RGB8_OES:
101bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB8_ETC2:
102bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ETC2:
103bf215546Sopenharmony_ci   case GL_RGB_S3TC:
104bf215546Sopenharmony_ci   case GL_RGB4_S3TC:
105bf215546Sopenharmony_ci   case GL_PALETTE4_RGB8_OES:
106bf215546Sopenharmony_ci   case GL_PALETTE4_R5_G6_B5_OES:
107bf215546Sopenharmony_ci   case GL_PALETTE8_RGB8_OES:
108bf215546Sopenharmony_ci   case GL_PALETTE8_R5_G6_B5_OES:
109bf215546Sopenharmony_ci   case GL_ATC_RGB_AMD:
110bf215546Sopenharmony_ci      return GL_RGB;
111bf215546Sopenharmony_ci
112bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA:
113bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_ALPHA:
114bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_BPTC_UNORM_ARB:
115bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM_ARB:
116bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
117bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
118bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
119bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_FXT1_3DFX:
120bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
121bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
122bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
123bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA8_ETC2_EAC:
124bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
125bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
126bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
127bf215546Sopenharmony_ci   case GL_RGBA_S3TC:
128bf215546Sopenharmony_ci   case GL_RGBA4_S3TC:
129bf215546Sopenharmony_ci   case GL_PALETTE4_RGBA8_OES:
130bf215546Sopenharmony_ci   case GL_PALETTE8_RGB5_A1_OES:
131bf215546Sopenharmony_ci   case GL_PALETTE4_RGBA4_OES:
132bf215546Sopenharmony_ci   case GL_PALETTE4_RGB5_A1_OES:
133bf215546Sopenharmony_ci   case GL_PALETTE8_RGBA8_OES:
134bf215546Sopenharmony_ci   case GL_PALETTE8_RGBA4_OES:
135bf215546Sopenharmony_ci   case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
136bf215546Sopenharmony_ci   case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
137bf215546Sopenharmony_ci      return GL_RGBA;
138bf215546Sopenharmony_ci
139bf215546Sopenharmony_ci   case GL_COMPRESSED_ALPHA:
140bf215546Sopenharmony_ci      return GL_ALPHA;
141bf215546Sopenharmony_ci
142bf215546Sopenharmony_ci   case GL_COMPRESSED_LUMINANCE:
143bf215546Sopenharmony_ci   case GL_COMPRESSED_SLUMINANCE:
144bf215546Sopenharmony_ci   case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
145bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
146bf215546Sopenharmony_ci      return GL_LUMINANCE;
147bf215546Sopenharmony_ci
148bf215546Sopenharmony_ci   case GL_COMPRESSED_LUMINANCE_ALPHA:
149bf215546Sopenharmony_ci   case GL_COMPRESSED_SLUMINANCE_ALPHA:
150bf215546Sopenharmony_ci   case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
151bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
152bf215546Sopenharmony_ci   case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
153bf215546Sopenharmony_ci      return GL_LUMINANCE_ALPHA;
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci   case GL_COMPRESSED_INTENSITY:
156bf215546Sopenharmony_ci      return GL_INTENSITY;
157bf215546Sopenharmony_ci
158bf215546Sopenharmony_ci   default:
159bf215546Sopenharmony_ci      return 0;
160bf215546Sopenharmony_ci   }
161bf215546Sopenharmony_ci}
162bf215546Sopenharmony_ci
163bf215546Sopenharmony_ci/**
164bf215546Sopenharmony_ci * Return list of (and count of) all specific texture compression
165bf215546Sopenharmony_ci * formats that are supported.
166bf215546Sopenharmony_ci *
167bf215546Sopenharmony_ci * Some formats are \b not returned by this function.  The
168bf215546Sopenharmony_ci * \c GL_COMPRESSED_TEXTURE_FORMATS query only returns formats that are
169bf215546Sopenharmony_ci * "suitable for general-purpose usage."  All texture compression extensions
170bf215546Sopenharmony_ci * have taken this to mean either linear RGB or linear RGBA.
171bf215546Sopenharmony_ci *
172bf215546Sopenharmony_ci * The GL_ARB_texture_compress_rgtc spec says:
173bf215546Sopenharmony_ci *
174bf215546Sopenharmony_ci *    "19) Should the GL_NUM_COMPRESSED_TEXTURE_FORMATS and
175bf215546Sopenharmony_ci *        GL_COMPRESSED_TEXTURE_FORMATS queries return the RGTC formats?
176bf215546Sopenharmony_ci *
177bf215546Sopenharmony_ci *        RESOLVED:  No.
178bf215546Sopenharmony_ci *
179bf215546Sopenharmony_ci *        The OpenGL 2.1 specification says "The only values returned
180bf215546Sopenharmony_ci *        by this query [GL_COMPRESSED_TEXTURE_FORMATS"] are those
181bf215546Sopenharmony_ci *        corresponding to formats suitable for general-purpose usage.
182bf215546Sopenharmony_ci *        The renderer will not enumerate formats with restrictions that
183bf215546Sopenharmony_ci *        need to be specifically understood prior to use."
184bf215546Sopenharmony_ci *
185bf215546Sopenharmony_ci *        Compressed textures with just red or red-green components are
186bf215546Sopenharmony_ci *        not general-purpose so should not be returned by these queries
187bf215546Sopenharmony_ci *        because they have restrictions.
188bf215546Sopenharmony_ci *
189bf215546Sopenharmony_ci *        Applications that seek to use the RGTC formats should do so
190bf215546Sopenharmony_ci *        by looking for this extension's name in the string returned by
191bf215546Sopenharmony_ci *        glGetString(GL_EXTENSIONS) rather than
192bf215546Sopenharmony_ci *        what GL_NUM_COMPRESSED_TEXTURE_FORMATS and
193bf215546Sopenharmony_ci *        GL_COMPRESSED_TEXTURE_FORMATS return."
194bf215546Sopenharmony_ci *
195bf215546Sopenharmony_ci * There is nearly identical wording in the GL_EXT_texture_compression_rgtc
196bf215546Sopenharmony_ci * spec.
197bf215546Sopenharmony_ci *
198bf215546Sopenharmony_ci * The GL_EXT_texture_rRGB spec says:
199bf215546Sopenharmony_ci *
200bf215546Sopenharmony_ci *    "22) Should the new COMPRESSED_SRGB_* formats be listed in an
201bf215546Sopenharmony_ci *        implementation's GL_COMPRESSED_TEXTURE_FORMATS list?
202bf215546Sopenharmony_ci *
203bf215546Sopenharmony_ci *        RESOLVED:  No.  Section 3.8.1 says formats listed by
204bf215546Sopenharmony_ci *        GL_COMPRESSED_TEXTURE_FORMATS are "suitable for general-purpose
205bf215546Sopenharmony_ci *        usage."  The non-linear distribution of red, green, and
206bf215546Sopenharmony_ci *        blue for these sRGB compressed formats makes them not really
207bf215546Sopenharmony_ci *        general-purpose."
208bf215546Sopenharmony_ci *
209bf215546Sopenharmony_ci * The GL_EXT_texture_compression_latc spec says:
210bf215546Sopenharmony_ci *
211bf215546Sopenharmony_ci *    "16) Should the GL_NUM_COMPRESSED_TEXTURE_FORMATS and
212bf215546Sopenharmony_ci *        GL_COMPRESSED_TEXTURE_FORMATS queries return the LATC formats?
213bf215546Sopenharmony_ci *
214bf215546Sopenharmony_ci *        RESOLVED:  No.
215bf215546Sopenharmony_ci *
216bf215546Sopenharmony_ci *        The OpenGL 2.1 specification says "The only values returned
217bf215546Sopenharmony_ci *        by this query [GL_COMPRESSED_TEXTURE_FORMATS"] are those
218bf215546Sopenharmony_ci *        corresponding to formats suitable for general-purpose usage.
219bf215546Sopenharmony_ci *        The renderer will not enumerate formats with restrictions that
220bf215546Sopenharmony_ci *        need to be specifically understood prior to use."
221bf215546Sopenharmony_ci *
222bf215546Sopenharmony_ci *        Historically, OpenGL implementation have advertised the RGB and
223bf215546Sopenharmony_ci *        RGBA versions of the S3TC extensions compressed format tokens
224bf215546Sopenharmony_ci *        through this mechanism.
225bf215546Sopenharmony_ci *
226bf215546Sopenharmony_ci *        The specification is not sufficiently clear about what "suitable
227bf215546Sopenharmony_ci *        for general-purpose usage" means.  Historically that seems to mean
228bf215546Sopenharmony_ci *        unsigned RGB or unsigned RGBA.  The DXT1 format supporting alpha
229bf215546Sopenharmony_ci *        (GL_COMPRESSED_RGBA_S3TC_DXT1_EXT) is not exposed in the list (at
230bf215546Sopenharmony_ci *        least for NVIDIA drivers) because the alpha is always 1.0 expect
231bf215546Sopenharmony_ci *        when it is 0.0 when RGB is required to be black.  NVIDIA's even
232bf215546Sopenharmony_ci *        limits itself to true linear RGB or RGBA formats, specifically
233bf215546Sopenharmony_ci *        not including EXT_texture_sRGB's sRGB S3TC compressed formats.
234bf215546Sopenharmony_ci *
235bf215546Sopenharmony_ci *        Adding luminance and luminance-alpha texture formats (and
236bf215546Sopenharmony_ci *        certainly signed versions of luminance and luminance-alpha
237bf215546Sopenharmony_ci *        formats!) invites potential comptaibility problems with old
238bf215546Sopenharmony_ci *        applications using this mechanism since old applications are
239bf215546Sopenharmony_ci *        unlikely to expect non-RGB or non-RGBA formats to be advertised
240bf215546Sopenharmony_ci *        through this mechanism.  However no specific misinteractions
241bf215546Sopenharmony_ci *        with old applications is known.
242bf215546Sopenharmony_ci *
243bf215546Sopenharmony_ci *        Applications that seek to use the LATC formats should do so
244bf215546Sopenharmony_ci *        by looking for this extension's name in the string returned by
245bf215546Sopenharmony_ci *        glGetString(GL_EXTENSIONS) rather than
246bf215546Sopenharmony_ci *        what GL_NUM_COMPRESSED_TEXTURE_FORMATS and
247bf215546Sopenharmony_ci *        GL_COMPRESSED_TEXTURE_FORMATS return."
248bf215546Sopenharmony_ci *
249bf215546Sopenharmony_ci * There is no formal spec for GL_ATI_texture_compression_3dc.  Since the
250bf215546Sopenharmony_ci * formats added by this extension are luminance-alpha formats, it is
251bf215546Sopenharmony_ci * reasonable to expect them to follow the same rules as
252bf215546Sopenharmony_ci * GL_EXT_texture_compression_latc.  At the very least, Catalyst 11.6 does not
253bf215546Sopenharmony_ci * expose the 3dc formats through this mechanism.
254bf215546Sopenharmony_ci *
255bf215546Sopenharmony_ci * The spec for GL_ARB_texture_compression_bptc doesn't mention whether it
256bf215546Sopenharmony_ci * should be included in GL_COMPRESSED_TEXTURE_FORMATS. However as it takes a
257bf215546Sopenharmony_ci * very long time to compress the textures in this format it's probably not
258bf215546Sopenharmony_ci * very useful as a general format where the GL will have to compress it on
259bf215546Sopenharmony_ci * the fly.
260bf215546Sopenharmony_ci *
261bf215546Sopenharmony_ci * \param ctx  the GL context
262bf215546Sopenharmony_ci * \param formats  the resulting format list (may be NULL).
263bf215546Sopenharmony_ci *
264bf215546Sopenharmony_ci * \return number of formats.
265bf215546Sopenharmony_ci */
266bf215546Sopenharmony_ciGLuint
267bf215546Sopenharmony_ci_mesa_get_compressed_formats(struct gl_context *ctx, GLint *formats)
268bf215546Sopenharmony_ci{
269bf215546Sopenharmony_ci   GLint discard_formats[100];
270bf215546Sopenharmony_ci   GLuint n = 0;
271bf215546Sopenharmony_ci
272bf215546Sopenharmony_ci   if (!formats) {
273bf215546Sopenharmony_ci      formats = discard_formats;
274bf215546Sopenharmony_ci   }
275bf215546Sopenharmony_ci
276bf215546Sopenharmony_ci   if (_mesa_is_desktop_gl(ctx) &&
277bf215546Sopenharmony_ci       ctx->Extensions.TDFX_texture_compression_FXT1) {
278bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGB_FXT1_3DFX;
279bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_FXT1_3DFX;
280bf215546Sopenharmony_ci   }
281bf215546Sopenharmony_ci
282bf215546Sopenharmony_ci   if (ctx->Extensions.EXT_texture_compression_s3tc) {
283bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
284bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
285bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
286bf215546Sopenharmony_ci
287bf215546Sopenharmony_ci      /* The ES and desktop GL specs diverge here.
288bf215546Sopenharmony_ci       *
289bf215546Sopenharmony_ci       * In desktop OpenGL, the driver can perform online compression of
290bf215546Sopenharmony_ci       * uncompressed texture data.  GL_NUM_COMPRESSED_TEXTURE_FORMATS and
291bf215546Sopenharmony_ci       * GL_COMPRESSED_TEXTURE_FORMATS give the application a list of
292bf215546Sopenharmony_ci       * formats that it could ask the driver to compress with some
293bf215546Sopenharmony_ci       * expectation of quality.  The GL_ARB_texture_compression spec
294bf215546Sopenharmony_ci       * calls this "suitable for general-purpose usage."  As noted
295bf215546Sopenharmony_ci       * above, this means GL_COMPRESSED_RGBA_S3TC_DXT1_EXT is not
296bf215546Sopenharmony_ci       * included in the list.
297bf215546Sopenharmony_ci       *
298bf215546Sopenharmony_ci       * In OpenGL ES, the driver never performs compression.
299bf215546Sopenharmony_ci       * GL_NUM_COMPRESSED_TEXTURE_FORMATS and
300bf215546Sopenharmony_ci       * GL_COMPRESSED_TEXTURE_FORMATS give the application a list of
301bf215546Sopenharmony_ci       * formats that the driver can receive from the application.  It
302bf215546Sopenharmony_ci       * is the *complete* list of formats.  The
303bf215546Sopenharmony_ci       * GL_EXT_texture_compression_s3tc spec says:
304bf215546Sopenharmony_ci       *
305bf215546Sopenharmony_ci       *     "New State for OpenGL ES 2.0.25 and 3.0.2 Specifications
306bf215546Sopenharmony_ci       *
307bf215546Sopenharmony_ci       *         The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
308bf215546Sopenharmony_ci       *         COMPRESSED_TEXTURE_FORMATS include
309bf215546Sopenharmony_ci       *         COMPRESSED_RGB_S3TC_DXT1_EXT,
310bf215546Sopenharmony_ci       *         COMPRESSED_RGBA_S3TC_DXT1_EXT,
311bf215546Sopenharmony_ci       *         COMPRESSED_RGBA_S3TC_DXT3_EXT, and
312bf215546Sopenharmony_ci       *         COMPRESSED_RGBA_S3TC_DXT5_EXT."
313bf215546Sopenharmony_ci       *
314bf215546Sopenharmony_ci       * Note that the addition is only to the OpenGL ES specification!
315bf215546Sopenharmony_ci       */
316bf215546Sopenharmony_ci      if (_mesa_is_gles(ctx)) {
317bf215546Sopenharmony_ci         formats[n++] = GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
318bf215546Sopenharmony_ci      }
319bf215546Sopenharmony_ci   }
320bf215546Sopenharmony_ci
321bf215546Sopenharmony_ci   /* The GL_OES_compressed_ETC1_RGB8_texture spec says:
322bf215546Sopenharmony_ci    *
323bf215546Sopenharmony_ci    *     "New State
324bf215546Sopenharmony_ci    *
325bf215546Sopenharmony_ci    *         The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
326bf215546Sopenharmony_ci    *         COMPRESSED_TEXTURE_FORMATS include ETC1_RGB8_OES."
327bf215546Sopenharmony_ci    */
328bf215546Sopenharmony_ci   if (_mesa_is_gles(ctx)
329bf215546Sopenharmony_ci       && ctx->Extensions.OES_compressed_ETC1_RGB8_texture) {
330bf215546Sopenharmony_ci      formats[n++] = GL_ETC1_RGB8_OES;
331bf215546Sopenharmony_ci   }
332bf215546Sopenharmony_ci
333bf215546Sopenharmony_ci   /* Required by EXT_texture_compression_bptc in GLES. */
334bf215546Sopenharmony_ci   if (_mesa_has_EXT_texture_compression_bptc(ctx)) {
335bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_BPTC_UNORM;
336bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
337bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT;
338bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
339bf215546Sopenharmony_ci   }
340bf215546Sopenharmony_ci
341bf215546Sopenharmony_ci   /* Required by EXT_texture_compression_rgtc in GLES. */
342bf215546Sopenharmony_ci   if (_mesa_is_gles3(ctx) &&
343bf215546Sopenharmony_ci       _mesa_has_EXT_texture_compression_rgtc(ctx)) {
344bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RED_RGTC1_EXT;
345bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SIGNED_RED_RGTC1_EXT;
346bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RED_GREEN_RGTC2_EXT;
347bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SIGNED_RED_GREEN_RGTC2_EXT;
348bf215546Sopenharmony_ci   }
349bf215546Sopenharmony_ci
350bf215546Sopenharmony_ci   if (ctx->API == API_OPENGLES) {
351bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE4_RGB8_OES;
352bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE4_RGBA8_OES;
353bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE4_R5_G6_B5_OES;
354bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE4_RGBA4_OES;
355bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE4_RGB5_A1_OES;
356bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE8_RGB8_OES;
357bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE8_RGBA8_OES;
358bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE8_R5_G6_B5_OES;
359bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE8_RGBA4_OES;
360bf215546Sopenharmony_ci      formats[n++] = GL_PALETTE8_RGB5_A1_OES;
361bf215546Sopenharmony_ci   }
362bf215546Sopenharmony_ci
363bf215546Sopenharmony_ci   if (_mesa_is_gles3(ctx) || ctx->Extensions.ARB_ES3_compatibility) {
364bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGB8_ETC2;
365bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA8_ETC2_EAC;
366bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_R11_EAC;
367bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RG11_EAC;
368bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SIGNED_R11_EAC;
369bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SIGNED_RG11_EAC;
370bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
371bf215546Sopenharmony_ci   }
372bf215546Sopenharmony_ci
373bf215546Sopenharmony_ci   if (_mesa_is_gles3(ctx)) {
374bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ETC2;
375bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
376bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
377bf215546Sopenharmony_ci   }
378bf215546Sopenharmony_ci
379bf215546Sopenharmony_ci   /* The KHR_texture_compression_astc_hdr spec says:
380bf215546Sopenharmony_ci    *
381bf215546Sopenharmony_ci    *    "Interactions with OpenGL 4.2
382bf215546Sopenharmony_ci    *
383bf215546Sopenharmony_ci    *        OpenGL 4.2 supports the feature that compressed textures can be
384bf215546Sopenharmony_ci    *        compressed online, by passing the compressed texture format enum
385bf215546Sopenharmony_ci    *        as the internal format when uploading a texture using TexImage1D,
386bf215546Sopenharmony_ci    *        TexImage2D or TexImage3D (see Section 3.9.3, Texture Image
387bf215546Sopenharmony_ci    *        Specification, subsection Encoding of Special Internal Formats).
388bf215546Sopenharmony_ci    *
389bf215546Sopenharmony_ci    *        Due to the complexity of the ASTC compression algorithm, it is
390bf215546Sopenharmony_ci    *        not usually suitable for online use, and therefore ASTC support
391bf215546Sopenharmony_ci    *        will be limited to pre-compressed textures only. Where on-device
392bf215546Sopenharmony_ci    *        compression is required, a domain-specific limited compressor
393bf215546Sopenharmony_ci    *        will typically be used, and this is therefore not suitable for
394bf215546Sopenharmony_ci    *        implementation in the driver.
395bf215546Sopenharmony_ci    *
396bf215546Sopenharmony_ci    *        In particular, the ASTC format specifiers will not be added to
397bf215546Sopenharmony_ci    *        Table 3.14, and thus will not be accepted by the TexImage*D
398bf215546Sopenharmony_ci    *        functions, and will not be returned by the (already deprecated)
399bf215546Sopenharmony_ci    *        COMPRESSED_TEXTURE_FORMATS query."
400bf215546Sopenharmony_ci    *
401bf215546Sopenharmony_ci    * The ES and the desktop specs diverge here. In OpenGL ES, the
402bf215546Sopenharmony_ci    * COMPRESSED_TEXTURE_FORMATS query returns the set of supported specific
403bf215546Sopenharmony_ci    * compressed formats.
404bf215546Sopenharmony_ci    */
405bf215546Sopenharmony_ci   if (ctx->API == API_OPENGLES2 &&
406bf215546Sopenharmony_ci       ctx->Extensions.KHR_texture_compression_astc_ldr) {
407bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
408bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
409bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
410bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
411bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
412bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
413bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
414bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
415bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
416bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
417bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
418bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
419bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
420bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
421bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
422bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
423bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
424bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
425bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
426bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
427bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
428bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
429bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
430bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
431bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
432bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
433bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
434bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
435bf215546Sopenharmony_ci   }
436bf215546Sopenharmony_ci
437bf215546Sopenharmony_ci   if (_mesa_is_gles3(ctx) &&
438bf215546Sopenharmony_ci       ctx->Extensions.OES_texture_compression_astc) {
439bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_3x3x3_OES;
440bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x3x3_OES;
441bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4x3_OES;
442bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_4x4x4_OES;
443bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x4x4_OES;
444bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5x4_OES;
445bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_5x5x5_OES;
446bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x5x5_OES;
447bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6x5_OES;
448bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_RGBA_ASTC_6x6x6_OES;
449bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES;
450bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES;
451bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES;
452bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES;
453bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES;
454bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES;
455bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES;
456bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES;
457bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES;
458bf215546Sopenharmony_ci      formats[n++] = GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES;
459bf215546Sopenharmony_ci   }
460bf215546Sopenharmony_ci
461bf215546Sopenharmony_ci   /* The GL_AMD_compressed_ATC_texture spec says:
462bf215546Sopenharmony_ci    *
463bf215546Sopenharmony_ci    *     "New State
464bf215546Sopenharmony_ci    *
465bf215546Sopenharmony_ci    *         The queries for NUM_COMPRESSED_TEXTURE_FORMATS and
466bf215546Sopenharmony_ci    *         COMPRESSED_TEXTURE_FORMATS include ATC_RGB_AMD,
467bf215546Sopenharmony_ci    *         ATC_RGBA_EXPLICIT_ALPHA_AMD, and ATC_RGBA_INTERPOLATED_ALPHA_AMD."
468bf215546Sopenharmony_ci    */
469bf215546Sopenharmony_ci   if (_mesa_has_AMD_compressed_ATC_texture(ctx)) {
470bf215546Sopenharmony_ci      formats[n++] = GL_ATC_RGB_AMD;
471bf215546Sopenharmony_ci      formats[n++] = GL_ATC_RGBA_EXPLICIT_ALPHA_AMD;
472bf215546Sopenharmony_ci      formats[n++] = GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
473bf215546Sopenharmony_ci   }
474bf215546Sopenharmony_ci
475bf215546Sopenharmony_ci   assert(n <= ARRAY_SIZE(discard_formats));
476bf215546Sopenharmony_ci
477bf215546Sopenharmony_ci   return n;
478bf215546Sopenharmony_ci}
479bf215546Sopenharmony_ci
480bf215546Sopenharmony_ci
481bf215546Sopenharmony_ci/**
482bf215546Sopenharmony_ci * Convert GLenum to a compressed MESA_FORMAT_x.
483bf215546Sopenharmony_ci */
484bf215546Sopenharmony_cimesa_format
485bf215546Sopenharmony_ci_mesa_glenum_to_compressed_format(GLenum format)
486bf215546Sopenharmony_ci{
487bf215546Sopenharmony_ci   switch (format) {
488bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB_FXT1_3DFX:
489bf215546Sopenharmony_ci      return MESA_FORMAT_RGB_FXT1;
490bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_FXT1_3DFX:
491bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_FXT1;
492bf215546Sopenharmony_ci
493bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB_S3TC_DXT1_EXT:
494bf215546Sopenharmony_ci   case GL_RGB_S3TC:
495bf215546Sopenharmony_ci   case GL_RGB4_S3TC:
496bf215546Sopenharmony_ci      return MESA_FORMAT_RGB_DXT1;
497bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT:
498bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_DXT1;
499bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT:
500bf215546Sopenharmony_ci   case GL_RGBA_S3TC:
501bf215546Sopenharmony_ci   case GL_RGBA4_S3TC:
502bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_DXT3;
503bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT:
504bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_DXT5;
505bf215546Sopenharmony_ci
506bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT:
507bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB_DXT1;
508bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT:
509bf215546Sopenharmony_ci      return MESA_FORMAT_SRGBA_DXT1;
510bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT:
511bf215546Sopenharmony_ci      return MESA_FORMAT_SRGBA_DXT3;
512bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT:
513bf215546Sopenharmony_ci      return MESA_FORMAT_SRGBA_DXT5;
514bf215546Sopenharmony_ci
515bf215546Sopenharmony_ci   case GL_COMPRESSED_RED_RGTC1:
516bf215546Sopenharmony_ci      return MESA_FORMAT_R_RGTC1_UNORM;
517bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_RED_RGTC1:
518bf215546Sopenharmony_ci      return MESA_FORMAT_R_RGTC1_SNORM;
519bf215546Sopenharmony_ci   case GL_COMPRESSED_RG_RGTC2:
520bf215546Sopenharmony_ci      return MESA_FORMAT_RG_RGTC2_UNORM;
521bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_RG_RGTC2:
522bf215546Sopenharmony_ci      return MESA_FORMAT_RG_RGTC2_SNORM;
523bf215546Sopenharmony_ci
524bf215546Sopenharmony_ci   case GL_COMPRESSED_LUMINANCE_LATC1_EXT:
525bf215546Sopenharmony_ci      return MESA_FORMAT_L_LATC1_UNORM;
526bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT:
527bf215546Sopenharmony_ci      return MESA_FORMAT_L_LATC1_SNORM;
528bf215546Sopenharmony_ci   case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT:
529bf215546Sopenharmony_ci   case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI:
530bf215546Sopenharmony_ci      return MESA_FORMAT_LA_LATC2_UNORM;
531bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT:
532bf215546Sopenharmony_ci      return MESA_FORMAT_LA_LATC2_SNORM;
533bf215546Sopenharmony_ci
534bf215546Sopenharmony_ci   case GL_ETC1_RGB8_OES:
535bf215546Sopenharmony_ci      return MESA_FORMAT_ETC1_RGB8;
536bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB8_ETC2:
537bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_RGB8;
538bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ETC2:
539bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_SRGB8;
540bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA8_ETC2_EAC:
541bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_RGBA8_EAC;
542bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC:
543bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC;
544bf215546Sopenharmony_ci   case GL_COMPRESSED_R11_EAC:
545bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_R11_EAC;
546bf215546Sopenharmony_ci   case GL_COMPRESSED_RG11_EAC:
547bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_RG11_EAC;
548bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_R11_EAC:
549bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_SIGNED_R11_EAC;
550bf215546Sopenharmony_ci   case GL_COMPRESSED_SIGNED_RG11_EAC:
551bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_SIGNED_RG11_EAC;
552bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2:
553bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1;
554bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2:
555bf215546Sopenharmony_ci      return MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1;
556bf215546Sopenharmony_ci
557bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_BPTC_UNORM:
558bf215546Sopenharmony_ci      return MESA_FORMAT_BPTC_RGBA_UNORM;
559bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM:
560bf215546Sopenharmony_ci      return MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM;
561bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT:
562bf215546Sopenharmony_ci      return MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT;
563bf215546Sopenharmony_ci   case GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT:
564bf215546Sopenharmony_ci      return MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT;
565bf215546Sopenharmony_ci
566bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_4x4_KHR:
567bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_4x4;
568bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_5x4_KHR:
569bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_5x4;
570bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_5x5_KHR:
571bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_5x5;
572bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_6x5_KHR:
573bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_6x5;
574bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_6x6_KHR:
575bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_6x6;
576bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_8x5_KHR:
577bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_8x5;
578bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_8x6_KHR:
579bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_8x6;
580bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_8x8_KHR:
581bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_8x8;
582bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_10x5_KHR:
583bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_10x5;
584bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_10x6_KHR:
585bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_10x6;
586bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_10x8_KHR:
587bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_10x8;
588bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_10x10_KHR:
589bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_10x10;
590bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_12x10_KHR:
591bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_12x10;
592bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_12x12_KHR:
593bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_12x12;
594bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR:
595bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4;
596bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR:
597bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4;
598bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR:
599bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5;
600bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR:
601bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5;
602bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR:
603bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6;
604bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR:
605bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5;
606bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR:
607bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6;
608bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR:
609bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8;
610bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR:
611bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5;
612bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR:
613bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6;
614bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR:
615bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8;
616bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR:
617bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10;
618bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR:
619bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10;
620bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR:
621bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12;
622bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_3x3x3_OES:
623bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_3x3x3;
624bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_4x3x3_OES:
625bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_4x3x3;
626bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_4x4x3_OES:
627bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_4x4x3;
628bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_4x4x4_OES:
629bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_4x4x4;
630bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_5x4x4_OES:
631bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_5x4x4;
632bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_5x5x4_OES:
633bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_5x5x4;
634bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_5x5x5_OES:
635bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_5x5x5;
636bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_6x5x5_OES:
637bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_6x5x5;
638bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_6x6x5_OES:
639bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_6x6x5;
640bf215546Sopenharmony_ci   case GL_COMPRESSED_RGBA_ASTC_6x6x6_OES:
641bf215546Sopenharmony_ci      return MESA_FORMAT_RGBA_ASTC_6x6x6;
642bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES:
643bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3;
644bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES:
645bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3;
646bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES:
647bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3;
648bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES:
649bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4;
650bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES:
651bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4;
652bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES:
653bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4;
654bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES:
655bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5;
656bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES:
657bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5;
658bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES:
659bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5;
660bf215546Sopenharmony_ci   case GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES:
661bf215546Sopenharmony_ci      return MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6;
662bf215546Sopenharmony_ci
663bf215546Sopenharmony_ci   case GL_ATC_RGB_AMD:
664bf215546Sopenharmony_ci      return MESA_FORMAT_ATC_RGB;
665bf215546Sopenharmony_ci   case GL_ATC_RGBA_EXPLICIT_ALPHA_AMD:
666bf215546Sopenharmony_ci      return MESA_FORMAT_ATC_RGBA_EXPLICIT;
667bf215546Sopenharmony_ci   case GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD:
668bf215546Sopenharmony_ci      return MESA_FORMAT_ATC_RGBA_INTERPOLATED;
669bf215546Sopenharmony_ci
670bf215546Sopenharmony_ci   default:
671bf215546Sopenharmony_ci      return MESA_FORMAT_NONE;
672bf215546Sopenharmony_ci   }
673bf215546Sopenharmony_ci}
674bf215546Sopenharmony_ci
675bf215546Sopenharmony_ci
676bf215546Sopenharmony_ci/**
677bf215546Sopenharmony_ci * Given a compressed MESA_FORMAT_x value, return the corresponding
678bf215546Sopenharmony_ci * GLenum for that format.
679bf215546Sopenharmony_ci * This is needed for glGetTexLevelParameter(GL_TEXTURE_INTERNAL_FORMAT)
680bf215546Sopenharmony_ci * which must return the specific texture format used when the user might
681bf215546Sopenharmony_ci * have originally specified a generic compressed format in their
682bf215546Sopenharmony_ci * glTexImage2D() call.
683bf215546Sopenharmony_ci * For non-compressed textures, we always return the user-specified
684bf215546Sopenharmony_ci * internal format unchanged.
685bf215546Sopenharmony_ci */
686bf215546Sopenharmony_ciGLenum
687bf215546Sopenharmony_ci_mesa_compressed_format_to_glenum(struct gl_context *ctx,
688bf215546Sopenharmony_ci                                  mesa_format mesaFormat)
689bf215546Sopenharmony_ci{
690bf215546Sopenharmony_ci   switch (mesaFormat) {
691bf215546Sopenharmony_ci   case MESA_FORMAT_RGB_FXT1:
692bf215546Sopenharmony_ci      return GL_COMPRESSED_RGB_FXT1_3DFX;
693bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_FXT1:
694bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_FXT1_3DFX;
695bf215546Sopenharmony_ci   case MESA_FORMAT_RGB_DXT1:
696bf215546Sopenharmony_ci      return GL_COMPRESSED_RGB_S3TC_DXT1_EXT;
697bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_DXT1:
698bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_S3TC_DXT1_EXT;
699bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_DXT3:
700bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_S3TC_DXT3_EXT;
701bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_DXT5:
702bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_S3TC_DXT5_EXT;
703bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB_DXT1:
704bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB_S3TC_DXT1_EXT;
705bf215546Sopenharmony_ci   case MESA_FORMAT_SRGBA_DXT1:
706bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT;
707bf215546Sopenharmony_ci   case MESA_FORMAT_SRGBA_DXT3:
708bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT;
709bf215546Sopenharmony_ci   case MESA_FORMAT_SRGBA_DXT5:
710bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT;
711bf215546Sopenharmony_ci   case MESA_FORMAT_R_RGTC1_UNORM:
712bf215546Sopenharmony_ci      return GL_COMPRESSED_RED_RGTC1;
713bf215546Sopenharmony_ci   case MESA_FORMAT_R_RGTC1_SNORM:
714bf215546Sopenharmony_ci      return GL_COMPRESSED_SIGNED_RED_RGTC1;
715bf215546Sopenharmony_ci   case MESA_FORMAT_RG_RGTC2_UNORM:
716bf215546Sopenharmony_ci      return GL_COMPRESSED_RG_RGTC2;
717bf215546Sopenharmony_ci   case MESA_FORMAT_RG_RGTC2_SNORM:
718bf215546Sopenharmony_ci      return GL_COMPRESSED_SIGNED_RG_RGTC2;
719bf215546Sopenharmony_ci
720bf215546Sopenharmony_ci   case MESA_FORMAT_L_LATC1_UNORM:
721bf215546Sopenharmony_ci      return GL_COMPRESSED_LUMINANCE_LATC1_EXT;
722bf215546Sopenharmony_ci   case MESA_FORMAT_L_LATC1_SNORM:
723bf215546Sopenharmony_ci      return GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT;
724bf215546Sopenharmony_ci   case MESA_FORMAT_LA_LATC2_UNORM:
725bf215546Sopenharmony_ci      return GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT;
726bf215546Sopenharmony_ci   case MESA_FORMAT_LA_LATC2_SNORM:
727bf215546Sopenharmony_ci      return GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT;
728bf215546Sopenharmony_ci
729bf215546Sopenharmony_ci   case MESA_FORMAT_ETC1_RGB8:
730bf215546Sopenharmony_ci      return GL_ETC1_RGB8_OES;
731bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_RGB8:
732bf215546Sopenharmony_ci      return GL_COMPRESSED_RGB8_ETC2;
733bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_SRGB8:
734bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ETC2;
735bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_RGBA8_EAC:
736bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA8_ETC2_EAC;
737bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
738bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC;
739bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_R11_EAC:
740bf215546Sopenharmony_ci      return GL_COMPRESSED_R11_EAC;
741bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_RG11_EAC:
742bf215546Sopenharmony_ci      return GL_COMPRESSED_RG11_EAC;
743bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
744bf215546Sopenharmony_ci      return GL_COMPRESSED_SIGNED_R11_EAC;
745bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
746bf215546Sopenharmony_ci      return GL_COMPRESSED_SIGNED_RG11_EAC;
747bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
748bf215546Sopenharmony_ci      return GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2;
749bf215546Sopenharmony_ci   case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
750bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2;
751bf215546Sopenharmony_ci
752bf215546Sopenharmony_ci   case MESA_FORMAT_BPTC_RGBA_UNORM:
753bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_BPTC_UNORM;
754bf215546Sopenharmony_ci   case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:
755bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM;
756bf215546Sopenharmony_ci   case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:
757bf215546Sopenharmony_ci      return GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT;
758bf215546Sopenharmony_ci   case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:
759bf215546Sopenharmony_ci      return GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT;
760bf215546Sopenharmony_ci
761bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_4x4:
762bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_4x4_KHR;
763bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_5x4:
764bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_5x4_KHR;
765bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_5x5:
766bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_5x5_KHR;
767bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_6x5:
768bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_6x5_KHR;
769bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_6x6:
770bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_6x6_KHR;
771bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_8x5:
772bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_8x5_KHR;
773bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_8x6:
774bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_8x6_KHR;
775bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_8x8:
776bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_8x8_KHR;
777bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_10x5:
778bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_10x5_KHR;
779bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_10x6:
780bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_10x6_KHR;
781bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_10x8:
782bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_10x8_KHR;
783bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_10x10:
784bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_10x10_KHR;
785bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_12x10:
786bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_12x10_KHR;
787bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_12x12:
788bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_12x12_KHR;
789bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4:
790bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR;
791bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4:
792bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR;
793bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5:
794bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR;
795bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5:
796bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR;
797bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6:
798bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR;
799bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x5:
800bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR;
801bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x6:
802bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR;
803bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_8x8:
804bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR;
805bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x5:
806bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR;
807bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x6:
808bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR;
809bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x8:
810bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR;
811bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_10x10:
812bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR;
813bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x10:
814bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR;
815bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_12x12:
816bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR;
817bf215546Sopenharmony_ci
818bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_3x3x3:
819bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_3x3x3_OES;
820bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_4x3x3:
821bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_4x3x3_OES;
822bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_4x4x3:
823bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_4x4x3_OES;
824bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_4x4x4:
825bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_4x4x4_OES;
826bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_5x4x4:
827bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_5x4x4_OES;
828bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_5x5x4:
829bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_5x5x4_OES;
830bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_5x5x5:
831bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_5x5x5_OES;
832bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_6x5x5:
833bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_6x5x5_OES;
834bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_6x6x5:
835bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_6x6x5_OES;
836bf215546Sopenharmony_ci   case MESA_FORMAT_RGBA_ASTC_6x6x6:
837bf215546Sopenharmony_ci      return GL_COMPRESSED_RGBA_ASTC_6x6x6_OES;
838bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_3x3x3:
839bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_3x3x3_OES;
840bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x3x3:
841bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x3x3_OES;
842bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x3:
843bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x3_OES;
844bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_4x4x4:
845bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4x4_OES;
846bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x4x4:
847bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4x4_OES;
848bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x4:
849bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x4_OES;
850bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_5x5x5:
851bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5x5_OES;
852bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x5x5:
853bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5x5_OES;
854bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x5:
855bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x5_OES;
856bf215546Sopenharmony_ci   case MESA_FORMAT_SRGB8_ALPHA8_ASTC_6x6x6:
857bf215546Sopenharmony_ci      return GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6x6_OES;
858bf215546Sopenharmony_ci
859bf215546Sopenharmony_ci   case MESA_FORMAT_ATC_RGB:
860bf215546Sopenharmony_ci      return GL_ATC_RGB_AMD;
861bf215546Sopenharmony_ci   case MESA_FORMAT_ATC_RGBA_EXPLICIT:
862bf215546Sopenharmony_ci      return GL_ATC_RGBA_EXPLICIT_ALPHA_AMD;
863bf215546Sopenharmony_ci   case MESA_FORMAT_ATC_RGBA_INTERPOLATED:
864bf215546Sopenharmony_ci      return GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD;
865bf215546Sopenharmony_ci
866bf215546Sopenharmony_ci   default:
867bf215546Sopenharmony_ci      _mesa_problem(ctx, "Unexpected mesa texture format in"
868bf215546Sopenharmony_ci                    " _mesa_compressed_format_to_glenum()");
869bf215546Sopenharmony_ci      return 0;
870bf215546Sopenharmony_ci   }
871bf215546Sopenharmony_ci}
872bf215546Sopenharmony_ci
873bf215546Sopenharmony_ci
874bf215546Sopenharmony_ci/**
875bf215546Sopenharmony_ci * Return a texel-fetch function for the given format, or NULL if
876bf215546Sopenharmony_ci * invalid format.
877bf215546Sopenharmony_ci */
878bf215546Sopenharmony_cicompressed_fetch_func
879bf215546Sopenharmony_ci_mesa_get_compressed_fetch_func(mesa_format format)
880bf215546Sopenharmony_ci{
881bf215546Sopenharmony_ci   switch (_mesa_get_format_layout(format)) {
882bf215546Sopenharmony_ci   case MESA_FORMAT_LAYOUT_S3TC:
883bf215546Sopenharmony_ci      return _mesa_get_dxt_fetch_func(format);
884bf215546Sopenharmony_ci   case MESA_FORMAT_LAYOUT_FXT1:
885bf215546Sopenharmony_ci      return _mesa_get_fxt_fetch_func(format);
886bf215546Sopenharmony_ci   case MESA_FORMAT_LAYOUT_RGTC:
887bf215546Sopenharmony_ci   case MESA_FORMAT_LAYOUT_LATC:
888bf215546Sopenharmony_ci      return _mesa_get_compressed_rgtc_func(format);
889bf215546Sopenharmony_ci   case MESA_FORMAT_LAYOUT_ETC1:
890bf215546Sopenharmony_ci      return _mesa_get_etc_fetch_func(format);
891bf215546Sopenharmony_ci   case MESA_FORMAT_LAYOUT_BPTC:
892bf215546Sopenharmony_ci      return _mesa_get_bptc_fetch_func(format);
893bf215546Sopenharmony_ci   default:
894bf215546Sopenharmony_ci      return NULL;
895bf215546Sopenharmony_ci   }
896bf215546Sopenharmony_ci}
897bf215546Sopenharmony_ci
898bf215546Sopenharmony_ci
899bf215546Sopenharmony_ci/**
900bf215546Sopenharmony_ci * Decompress a compressed texture image, returning a GL_RGBA/GL_FLOAT image.
901bf215546Sopenharmony_ci * \param srcRowStride  stride in bytes between rows of blocks in the
902bf215546Sopenharmony_ci *                      compressed source image.
903bf215546Sopenharmony_ci */
904bf215546Sopenharmony_civoid
905bf215546Sopenharmony_ci_mesa_decompress_image(mesa_format format, GLuint width, GLuint height,
906bf215546Sopenharmony_ci                       const GLubyte *src, GLint srcRowStride,
907bf215546Sopenharmony_ci                       GLfloat *dest)
908bf215546Sopenharmony_ci{
909bf215546Sopenharmony_ci   compressed_fetch_func fetch;
910bf215546Sopenharmony_ci   GLuint i, j;
911bf215546Sopenharmony_ci   GLuint bytes, bw, bh;
912bf215546Sopenharmony_ci   GLint stride;
913bf215546Sopenharmony_ci
914bf215546Sopenharmony_ci   bytes = _mesa_get_format_bytes(format);
915bf215546Sopenharmony_ci   _mesa_get_format_block_size(format, &bw, &bh);
916bf215546Sopenharmony_ci
917bf215546Sopenharmony_ci   fetch = _mesa_get_compressed_fetch_func(format);
918bf215546Sopenharmony_ci   if (!fetch) {
919bf215546Sopenharmony_ci      _mesa_problem(NULL, "Unexpected format in _mesa_decompress_image()");
920bf215546Sopenharmony_ci      return;
921bf215546Sopenharmony_ci   }
922bf215546Sopenharmony_ci
923bf215546Sopenharmony_ci   stride = srcRowStride * bh / bytes;
924bf215546Sopenharmony_ci
925bf215546Sopenharmony_ci   for (j = 0; j < height; j++) {
926bf215546Sopenharmony_ci      for (i = 0; i < width; i++) {
927bf215546Sopenharmony_ci         fetch(src, stride, i, j, dest);
928bf215546Sopenharmony_ci         dest += 4;
929bf215546Sopenharmony_ci      }
930bf215546Sopenharmony_ci   }
931bf215546Sopenharmony_ci}
932