1848b8605Smrg/*
2848b8605Smrg * Mesa 3-D graphics library
3848b8605Smrg *
4848b8605Smrg * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5848b8605Smrg * Copyright (c) 2008-2009 VMware, Inc.
6848b8605Smrg *
7848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
8848b8605Smrg * copy of this software and associated documentation files (the "Software"),
9848b8605Smrg * to deal in the Software without restriction, including without limitation
10848b8605Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11848b8605Smrg * and/or sell copies of the Software, and to permit persons to whom the
12848b8605Smrg * Software is furnished to do so, subject to the following conditions:
13848b8605Smrg *
14848b8605Smrg * The above copyright notice and this permission notice shall be included
15848b8605Smrg * in all copies or substantial portions of the Software.
16848b8605Smrg *
17848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19848b8605Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20848b8605Smrg * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21848b8605Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22848b8605Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23848b8605Smrg * OTHER DEALINGS IN THE SOFTWARE.
24848b8605Smrg */
25848b8605Smrg
26848b8605Smrg
27848b8605Smrg/**
28848b8605Smrg * \file texformat.c
29848b8605Smrg * Texture formats.
30848b8605Smrg *
31848b8605Smrg * \author Gareth Hughes
32848b8605Smrg * \author Brian Paul
33848b8605Smrg */
34848b8605Smrg
35848b8605Smrg
36848b8605Smrg#include "context.h"
37848b8605Smrg#include "enums.h"
38848b8605Smrg#include "mtypes.h"
39848b8605Smrg#include "texcompress.h"
40848b8605Smrg#include "texformat.h"
41b8e80941Smrg#include "glformats.h"
42848b8605Smrg
43848b8605Smrg#define RETURN_IF_SUPPORTED(f) do {		\
44848b8605Smrg   if (ctx->TextureFormatSupported[f])		\
45848b8605Smrg      return f;					\
46848b8605Smrg} while (0)
47848b8605Smrg
48848b8605Smrg/**
49848b8605Smrg * Choose an appropriate texture format given the format, type and
50848b8605Smrg * internalFormat parameters passed to glTexImage().
51848b8605Smrg *
52848b8605Smrg * \param ctx  the GL context.
53848b8605Smrg * \param target  a texture target (GL_TEXTURE_x)
54848b8605Smrg * \param internalFormat  user's prefered internal texture format.
55848b8605Smrg * \param format  incoming image pixel format.
56848b8605Smrg * \param type  incoming image data type.
57848b8605Smrg *
58848b8605Smrg * \return the closest mesa_format for the given format/type arguments
59848b8605Smrg *
60848b8605Smrg * This is called via dd_function_table::ChooseTextureFormat.  Hardware
61848b8605Smrg * drivers may override this function with a specialized version.
62848b8605Smrg */
63848b8605Smrgmesa_format
64848b8605Smrg_mesa_choose_tex_format(struct gl_context *ctx, GLenum target,
65848b8605Smrg                        GLint internalFormat, GLenum format, GLenum type)
66848b8605Smrg{
67848b8605Smrg   (void) format;
68848b8605Smrg
69848b8605Smrg   switch (internalFormat) {
70848b8605Smrg   /* shallow RGBA formats */
71848b8605Smrg   case 4:
72848b8605Smrg   case GL_RGBA:
73848b8605Smrg      if (type == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
74848b8605Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_B4G4R4A4_UNORM);
75848b8605Smrg      } else if (type == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
76848b8605Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_B5G5R5A1_UNORM);
77b8e80941Smrg      } else if (type == GL_UNSIGNED_SHORT_5_5_5_1) {
78b8e80941Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_B5G5R5A1_UNORM);
79848b8605Smrg      } else if (type == GL_UNSIGNED_INT_2_10_10_10_REV) {
80848b8605Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UNORM);
81848b8605Smrg      }
82848b8605Smrg      /* fallthrough */
83848b8605Smrg
84848b8605Smrg   case GL_RGBA8:
85848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_UNORM);
86848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_UNORM);
87848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
88848b8605Smrg      break;
89848b8605Smrg   case GL_RGB5_A1:
90848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B5G5R5A1_UNORM);
91b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A1B5G5R5_UNORM);
92848b8605Smrg      break;
93848b8605Smrg   case GL_RGBA2:
94848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A4R4G4B4_UNORM); /* just to test another format*/
95848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B4G4R4A4_UNORM);
96848b8605Smrg      break;
97848b8605Smrg   case GL_RGBA4:
98848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B4G4R4A4_UNORM);
99848b8605Smrg      break;
100848b8605Smrg
101848b8605Smrg   /* deep RGBA formats */
102848b8605Smrg   case GL_RGB10_A2:
103848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R10G10B10A2_UNORM);
104848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UNORM);
105848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
106848b8605Smrg      break;
107848b8605Smrg   case GL_RGBA12:
108848b8605Smrg   case GL_RGBA16:
109848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UNORM16);
110848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UNORM16);
111848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_UNORM);
112848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
113848b8605Smrg      break;
114848b8605Smrg
115848b8605Smrg   /* shallow RGB formats */
116848b8605Smrg   case 3:
117848b8605Smrg   case GL_RGB:
118848b8605Smrg      if (type == GL_UNSIGNED_INT_2_10_10_10_REV) {
119848b8605Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UNORM);
120848b8605Smrg      }
121b8e80941Smrg      if (type == GL_UNSIGNED_SHORT_5_6_5) {
122b8e80941Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM);
123b8e80941Smrg      }
124848b8605Smrg      /* fallthrough */
125848b8605Smrg   case GL_RGB8:
126848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UNORM8);
127848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8X8_UNORM);
128848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_UNORM);
129848b8605Smrg
130848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_UNORM8);
131848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM);
132848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
133848b8605Smrg      break;
134848b8605Smrg   case GL_R3_G3_B2:
135848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B2G3R3_UNORM);
136848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM);
137848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R5G6B5_UNORM);
138848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_UNORM8);
139848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM);
140848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
141848b8605Smrg      break;
142848b8605Smrg   case GL_RGB4:
143848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R5G6B5_UNORM); /* just to test another format */
144848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM);
145848b8605Smrg      break;
146848b8605Smrg   case GL_RGB5:
147848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM);
148848b8605Smrg      break;
149848b8605Smrg
150848b8605Smrg   /* deep RGB formats */
151848b8605Smrg   case GL_RGB10:
152848b8605Smrg   case GL_RGB12:
153848b8605Smrg   case GL_RGB16:
154848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_UNORM16);
155848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UNORM16);
156848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM);
157848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
158848b8605Smrg      break;
159848b8605Smrg
160848b8605Smrg   /* Alpha formats */
161848b8605Smrg   case GL_ALPHA:
162848b8605Smrg   case GL_ALPHA4:
163848b8605Smrg   case GL_ALPHA8:
164848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_UNORM8);
165b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_UNORM);
166848b8605Smrg      break;
167848b8605Smrg
168848b8605Smrg   case GL_ALPHA12:
169848b8605Smrg   case GL_ALPHA16:
170848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_UNORM16);
171848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_UNORM8);
172b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_UNORM);
173848b8605Smrg      break;
174848b8605Smrg
175848b8605Smrg   /* Luminance formats */
176848b8605Smrg   case 1:
177848b8605Smrg   case GL_LUMINANCE:
178848b8605Smrg   case GL_LUMINANCE4:
179848b8605Smrg   case GL_LUMINANCE8:
180848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_UNORM8);
181848b8605Smrg      break;
182848b8605Smrg
183848b8605Smrg   case GL_LUMINANCE12:
184848b8605Smrg   case GL_LUMINANCE16:
185848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_UNORM16);
186848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_UNORM8);
187848b8605Smrg      break;
188848b8605Smrg
189848b8605Smrg      /* Luminance/Alpha formats */
190848b8605Smrg   case GL_LUMINANCE4_ALPHA4:
191848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L4A4_UNORM);
192848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_UNORM);
193848b8605Smrg      break;
194848b8605Smrg
195848b8605Smrg   case 2:
196848b8605Smrg   case GL_LUMINANCE_ALPHA:
197848b8605Smrg   case GL_LUMINANCE6_ALPHA2:
198848b8605Smrg   case GL_LUMINANCE8_ALPHA8:
199848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_UNORM);
200848b8605Smrg      break;
201848b8605Smrg
202848b8605Smrg   case GL_LUMINANCE12_ALPHA4:
203848b8605Smrg   case GL_LUMINANCE12_ALPHA12:
204848b8605Smrg   case GL_LUMINANCE16_ALPHA16:
205848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L16A16_UNORM);
206848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_UNORM);
207848b8605Smrg      break;
208848b8605Smrg
209848b8605Smrg   case GL_INTENSITY:
210848b8605Smrg   case GL_INTENSITY4:
211848b8605Smrg   case GL_INTENSITY8:
212848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_UNORM8);
213848b8605Smrg      break;
214848b8605Smrg
215848b8605Smrg   case GL_INTENSITY12:
216848b8605Smrg   case GL_INTENSITY16:
217848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_UNORM16);
218848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_UNORM8);
219848b8605Smrg      break;
220848b8605Smrg
221848b8605Smrg   case GL_DEPTH_COMPONENT:
222848b8605Smrg   case GL_DEPTH_COMPONENT24:
223848b8605Smrg   case GL_DEPTH_COMPONENT32:
224848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_Z_UNORM32);
225848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_X8_UINT);
226848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_S8_UINT);
227848b8605Smrg      break;
228848b8605Smrg   case GL_DEPTH_COMPONENT16:
229848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_Z_UNORM16);
230848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_X8_UINT);
231848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_S8_UINT);
232848b8605Smrg      break;
233848b8605Smrg
234848b8605Smrg   case GL_COMPRESSED_ALPHA_ARB:
235848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_UNORM8);
236b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_UNORM);
237848b8605Smrg      break;
238848b8605Smrg   case GL_COMPRESSED_LUMINANCE_ARB:
239848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_UNORM8);
240848b8605Smrg      break;
241848b8605Smrg   case GL_COMPRESSED_LUMINANCE_ALPHA_ARB:
242848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_UNORM);
243848b8605Smrg      break;
244848b8605Smrg   case GL_COMPRESSED_INTENSITY_ARB:
245848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_UNORM8);
246848b8605Smrg      break;
247848b8605Smrg   case GL_COMPRESSED_RGB_ARB:
248848b8605Smrg      /* We don't use texture compression for 1D and 1D array textures.
249848b8605Smrg       * For 1D textures, compressions doesn't buy us much.
250848b8605Smrg       * For 1D ARRAY textures, there's complicated issues with updating
251848b8605Smrg       * sub-regions on non-block boundaries with glCopyTexSubImage, among
252848b8605Smrg       * other issues.  FWIW, the GL_EXT_texture_array extension prohibits
253848b8605Smrg       * 1D ARRAY textures in S3TC format.
254848b8605Smrg       */
255848b8605Smrg      if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) {
256b8e80941Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_DXT1);
257848b8605Smrg      }
258848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_UNORM8);
259848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8X8_UNORM);
260848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
261848b8605Smrg      break;
262848b8605Smrg   case GL_COMPRESSED_RGBA_ARB:
263848b8605Smrg      /* We don't use texture compression for 1D and 1D array textures. */
264848b8605Smrg      if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY) {
265b8e80941Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_DXT3); /* Not rgba_dxt1, see spec */
266848b8605Smrg      }
267848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_UNORM);
268848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
269848b8605Smrg      break;
270848b8605Smrg
271848b8605Smrg   case GL_RGB565:
272848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B5G6R5_UNORM);
273848b8605Smrg      break;
274848b8605Smrg
275848b8605Smrg   case GL_YCBCR_MESA:
276848b8605Smrg      if (type == GL_UNSIGNED_SHORT_8_8_MESA)
277848b8605Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR);
278848b8605Smrg      else
279848b8605Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_YCBCR_REV);
280848b8605Smrg      break;
281848b8605Smrg
282848b8605Smrg   case GL_ALPHA16F_ARB:
283848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_FLOAT16);
284848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_FLOAT32);
285848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
286848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
287848b8605Smrg      break;
288848b8605Smrg   case GL_ALPHA32F_ARB:
289848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_FLOAT32);
290848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
291848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_FLOAT16);
292848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
293848b8605Smrg      break;
294848b8605Smrg   case GL_LUMINANCE16F_ARB:
295848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_FLOAT16);
296848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_FLOAT32);
297848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
298848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
299848b8605Smrg      break;
300848b8605Smrg   case GL_LUMINANCE32F_ARB:
301848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_FLOAT32);
302848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
303848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_FLOAT16);
304848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
305848b8605Smrg      break;
306848b8605Smrg   case GL_LUMINANCE_ALPHA16F_ARB:
307848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_FLOAT16);
308848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_FLOAT32);
309848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
310848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
311848b8605Smrg      break;
312848b8605Smrg   case GL_LUMINANCE_ALPHA32F_ARB:
313848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_FLOAT32);
314848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
315848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_FLOAT16);
316848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
317848b8605Smrg      break;
318848b8605Smrg   case GL_INTENSITY16F_ARB:
319848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_FLOAT16);
320848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_FLOAT32);
321848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
322848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
323848b8605Smrg      break;
324848b8605Smrg   case GL_INTENSITY32F_ARB:
325848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_FLOAT32);
326848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
327848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_FLOAT16);
328848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
329848b8605Smrg      break;
330848b8605Smrg   case GL_RGB16F_ARB:
331848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
332848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_FLOAT16);
333848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
334848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
335848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
336848b8605Smrg      break;
337848b8605Smrg   case GL_RGB32F_ARB:
338848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT32);
339848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_FLOAT32);
340848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
341848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_FLOAT16);
342848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
343848b8605Smrg      break;
344848b8605Smrg   case GL_RGBA16F_ARB:
345848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
346848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
347848b8605Smrg      break;
348848b8605Smrg   case GL_RGBA32F_ARB:
349848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
350848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
351848b8605Smrg      break;
352848b8605Smrg
353848b8605Smrg   case GL_RGB9_E5:
354848b8605Smrg      /* GL_EXT_texture_shared_exponent -- just one format to support */
355b8e80941Smrg      assert(ctx->TextureFormatSupported[MESA_FORMAT_R9G9B9E5_FLOAT]);
356848b8605Smrg      return MESA_FORMAT_R9G9B9E5_FLOAT;
357848b8605Smrg
358848b8605Smrg   case GL_R11F_G11F_B10F:
359848b8605Smrg      /* GL_EXT_texture_packed_float -- just one format to support */
360b8e80941Smrg      assert(ctx->TextureFormatSupported[MESA_FORMAT_R11G11B10_FLOAT]);
361848b8605Smrg      return MESA_FORMAT_R11G11B10_FLOAT;
362848b8605Smrg
363848b8605Smrg   case GL_DEPTH_STENCIL_EXT:
364848b8605Smrg   case GL_DEPTH24_STENCIL8_EXT:
365848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_S8_UINT_Z24_UNORM);
366848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_Z24_UNORM_S8_UINT);
367848b8605Smrg      break;
368848b8605Smrg
369848b8605Smrg   case GL_DEPTH_COMPONENT32F:
370b8e80941Smrg      assert(ctx->TextureFormatSupported[MESA_FORMAT_Z_FLOAT32]);
371848b8605Smrg      return MESA_FORMAT_Z_FLOAT32;
372848b8605Smrg   case GL_DEPTH32F_STENCIL8:
373b8e80941Smrg      assert(ctx->TextureFormatSupported[MESA_FORMAT_Z32_FLOAT_S8X24_UINT]);
374848b8605Smrg      return MESA_FORMAT_Z32_FLOAT_S8X24_UINT;
375848b8605Smrg
376848b8605Smrg   case GL_RED_SNORM:
377848b8605Smrg   case GL_R8_SNORM:
378848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_SNORM8);
379848b8605Smrg      break;
380848b8605Smrg   case GL_RG_SNORM:
381848b8605Smrg   case GL_RG8_SNORM:
382848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8_SNORM);
383848b8605Smrg      break;
384848b8605Smrg   case GL_RGB_SNORM:
385848b8605Smrg   case GL_RGB8_SNORM:
386848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8X8_SNORM);
387848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
388848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_X8B8G8R8_SNORM);
389848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
390848b8605Smrg      break;
391848b8605Smrg   case GL_RGBA_SNORM:
392848b8605Smrg   case GL_RGBA8_SNORM:
393848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
394848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
395848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
396848b8605Smrg      break;
397848b8605Smrg   case GL_ALPHA_SNORM:
398848b8605Smrg   case GL_ALPHA8_SNORM:
399848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_SNORM8);
400848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
401848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
402848b8605Smrg      break;
403848b8605Smrg   case GL_LUMINANCE_SNORM:
404848b8605Smrg   case GL_LUMINANCE8_SNORM:
405848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_SNORM8);
406848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_X8B8G8R8_SNORM);
407848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
408848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
409848b8605Smrg      break;
410848b8605Smrg   case GL_LUMINANCE_ALPHA_SNORM:
411848b8605Smrg   case GL_LUMINANCE8_ALPHA8_SNORM:
412848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_SNORM);
413b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8L8_SNORM);
414848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
415848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
416848b8605Smrg      break;
417848b8605Smrg   case GL_INTENSITY_SNORM:
418848b8605Smrg   case GL_INTENSITY8_SNORM:
419848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_SNORM8);
420848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
421848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
422848b8605Smrg      break;
423848b8605Smrg   case GL_R16_SNORM:
424848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_SNORM16);
425848b8605Smrg      break;
426848b8605Smrg   case GL_RG16_SNORM:
427848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R16G16_SNORM);
428848b8605Smrg      break;
429848b8605Smrg   case GL_RGB16_SNORM:
430848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_SNORM16);
431848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_SNORM16);
432848b8605Smrg      /* FALLTHROUGH */
433848b8605Smrg   case GL_RGBA16_SNORM:
434848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SNORM16);
435848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
436848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
437848b8605Smrg      break;
438848b8605Smrg   case GL_ALPHA16_SNORM:
439848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_SNORM16);
440848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SNORM16);
441848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
442848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
443848b8605Smrg      break;
444848b8605Smrg   case GL_LUMINANCE16_SNORM:
445848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_SNORM16);
446848b8605Smrg      /* FALLTHROUGH */
447848b8605Smrg   case GL_LUMINANCE16_ALPHA16_SNORM:
448848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SNORM16);
449848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SNORM16);
450848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
451848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
452848b8605Smrg      break;
453848b8605Smrg   case GL_INTENSITY16_SNORM:
454848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_SNORM16);
455848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SNORM16);
456848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SNORM);
457848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SNORM);
458848b8605Smrg      break;
459848b8605Smrg
460848b8605Smrg   case GL_SRGB_EXT:
461848b8605Smrg   case GL_SRGB8_EXT:
462848b8605Smrg      /* there is no MESA_FORMAT_RGB_SRGB8 */
463848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8X8_SRGB);
464848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SRGB);
465848b8605Smrg
466848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_SRGB8);
467848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
468b8e80941Smrg
469b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_X8B8G8R8_SRGB);
470b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
471848b8605Smrg      break;
472848b8605Smrg   case GL_SRGB_ALPHA_EXT:
473848b8605Smrg   case GL_SRGB8_ALPHA8_EXT:
474848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8B8A8_SRGB);
475848b8605Smrg
476848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SRGB);
477848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
478b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
479b8e80941Smrg      break;
480b8e80941Smrg   case GL_SR8_EXT:
481b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_SRGB8);
482848b8605Smrg      break;
483848b8605Smrg   case GL_SLUMINANCE_EXT:
484848b8605Smrg   case GL_SLUMINANCE8_EXT:
485848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_SRGB8);
486848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
487b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
488848b8605Smrg      break;
489848b8605Smrg   case GL_SLUMINANCE_ALPHA_EXT:
490848b8605Smrg   case GL_SLUMINANCE8_ALPHA8_EXT:
491848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_SRGB);
492b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8L8_SRGB);
493848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
494b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
495848b8605Smrg      break;
496848b8605Smrg   case GL_COMPRESSED_SLUMINANCE_EXT:
497848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_SRGB8);
498848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
499b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
500848b8605Smrg      break;
501848b8605Smrg   case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT:
502848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L8A8_SRGB);
503b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8L8_SRGB);
504848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
505b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
506848b8605Smrg      break;
507848b8605Smrg   case GL_COMPRESSED_SRGB_EXT:
508b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_SRGB_DXT1);
509848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_BGR_SRGB8);
510848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
511b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
512848b8605Smrg      break;
513848b8605Smrg   case GL_COMPRESSED_SRGB_ALPHA_EXT:
514b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_SRGBA_DXT3); /* Not srgba_dxt1, see spec */
515848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8B8G8R8_SRGB);
516848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_SRGB);
517b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A8R8G8B8_SRGB);
518848b8605Smrg      break;
519848b8605Smrg
520848b8605Smrg   case GL_ALPHA8UI_EXT:
521848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_UINT8);
522848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
523848b8605Smrg      break;
524848b8605Smrg   case GL_ALPHA16UI_EXT:
525848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_UINT16);
526848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
527848b8605Smrg      break;
528848b8605Smrg   case GL_ALPHA32UI_EXT:
529848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_UINT32);
530848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
531848b8605Smrg      break;
532848b8605Smrg   case GL_ALPHA8I_EXT:
533848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_SINT8);
534848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8);
535848b8605Smrg      break;
536848b8605Smrg   case GL_ALPHA16I_EXT:
537848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_SINT16);
538848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16);
539848b8605Smrg      break;
540848b8605Smrg   case GL_ALPHA32I_EXT:
541848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_A_SINT32);
542848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32);
543848b8605Smrg      break;
544848b8605Smrg   case GL_LUMINANCE8UI_EXT:
545848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_UINT8);
546848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
547848b8605Smrg      break;
548848b8605Smrg   case GL_LUMINANCE16UI_EXT:
549848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_UINT16);
550848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
551848b8605Smrg      break;
552848b8605Smrg   case GL_LUMINANCE32UI_EXT:
553848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_UINT32);
554848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
555848b8605Smrg      break;
556848b8605Smrg   case GL_LUMINANCE8I_EXT:
557848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_SINT8);
558848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8);
559848b8605Smrg      break;
560848b8605Smrg   case GL_LUMINANCE16I_EXT:
561848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_SINT16);
562848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16);
563848b8605Smrg      break;
564848b8605Smrg   case GL_LUMINANCE32I_EXT:
565848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_L_SINT32);
566848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32);
567848b8605Smrg      break;
568848b8605Smrg   case GL_LUMINANCE_ALPHA8UI_EXT:
569848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UINT8);
570848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
571848b8605Smrg      break;
572848b8605Smrg   case GL_LUMINANCE_ALPHA16UI_EXT:
573848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UINT16);
574848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
575848b8605Smrg      break;
576848b8605Smrg   case GL_LUMINANCE_ALPHA32UI_EXT:
577848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_UINT32);
578848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
579848b8605Smrg      break;
580848b8605Smrg   case GL_LUMINANCE_ALPHA8I_EXT:
581848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SINT8);
582848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8);
583848b8605Smrg      break;
584848b8605Smrg   case GL_LUMINANCE_ALPHA16I_EXT:
585848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SINT16);
586848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16);
587848b8605Smrg      break;
588848b8605Smrg   case GL_LUMINANCE_ALPHA32I_EXT:
589848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_LA_SINT32);
590848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32);
591848b8605Smrg      break;
592848b8605Smrg   case GL_INTENSITY8UI_EXT:
593848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_UINT8);
594848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
595848b8605Smrg      break;
596848b8605Smrg   case GL_INTENSITY16UI_EXT:
597848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_UINT16);
598848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
599848b8605Smrg      break;
600848b8605Smrg   case GL_INTENSITY32UI_EXT:
601848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_UINT32);
602848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
603848b8605Smrg      break;
604848b8605Smrg   case GL_INTENSITY8I_EXT:
605848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_SINT8);
606848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8);
607848b8605Smrg      break;
608848b8605Smrg   case GL_INTENSITY16I_EXT:
609848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_SINT16);
610848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16);
611848b8605Smrg      break;
612848b8605Smrg   case GL_INTENSITY32I_EXT:
613848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_I_SINT32);
614848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32);
615848b8605Smrg      break;
616848b8605Smrg
617848b8605Smrg   case GL_RGB8UI_EXT:
618848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT8);
619848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_UINT8);
620848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
621848b8605Smrg      break;
622848b8605Smrg   case GL_RGB16UI_EXT:
623848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT16);
624848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_UINT16);
625848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
626848b8605Smrg      break;
627848b8605Smrg   case GL_RGB32UI_EXT:
628848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_UINT32);
629848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_UINT32);
630848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
631848b8605Smrg      break;
632848b8605Smrg   case GL_RGB8I_EXT:
633848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_SINT8);
634848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_SINT8);
635848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8);
636848b8605Smrg      break;
637848b8605Smrg   case GL_RGB16I_EXT:
638848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_SINT16);
639848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_SINT16);
640848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16);
641848b8605Smrg      break;
642848b8605Smrg   case GL_RGB32I_EXT:
643848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGB_SINT32);
644848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBX_SINT32);
645848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32);
646848b8605Smrg      break;
647848b8605Smrg   case GL_RGBA8UI_EXT:
648848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT8);
649848b8605Smrg      break;
650848b8605Smrg   case GL_RGBA16UI_EXT:
651848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT16);
652848b8605Smrg      break;
653848b8605Smrg   case GL_RGBA32UI_EXT:
654848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_UINT32);
655848b8605Smrg      break;
656848b8605Smrg   case GL_RGBA8I_EXT:
657848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT8);
658848b8605Smrg      break;
659848b8605Smrg   case GL_RGBA16I_EXT:
660848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT16);
661848b8605Smrg      break;
662848b8605Smrg   case GL_RGBA32I_EXT:
663848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_SINT32);
664848b8605Smrg      break;
665848b8605Smrg
666848b8605Smrg   case GL_R8:
667848b8605Smrg   case GL_RED:
668848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_UNORM8);
669848b8605Smrg      break;
670848b8605Smrg
671848b8605Smrg   case GL_COMPRESSED_RED:
672848b8605Smrg      if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY)
673848b8605Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_R_RGTC1_UNORM);
674848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_UNORM8);
675848b8605Smrg      break;
676848b8605Smrg
677848b8605Smrg   case GL_R16:
678848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_UNORM16);
679848b8605Smrg      break;
680848b8605Smrg
681848b8605Smrg   case GL_RG:
682848b8605Smrg   case GL_RG8:
683848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8_UNORM);
684848b8605Smrg      break;
685848b8605Smrg
686848b8605Smrg   case GL_COMPRESSED_RG:
687848b8605Smrg      if (target != GL_TEXTURE_1D && target != GL_TEXTURE_1D_ARRAY)
688848b8605Smrg         RETURN_IF_SUPPORTED(MESA_FORMAT_RG_RGTC2_UNORM);
689848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R8G8_UNORM);
690848b8605Smrg      break;
691848b8605Smrg
692848b8605Smrg   case GL_RG16:
693848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R16G16_UNORM);
694848b8605Smrg      break;
695848b8605Smrg
696848b8605Smrg   case GL_R16F:
697848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
698848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
699848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
700848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
701848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
702848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
703848b8605Smrg      break;
704848b8605Smrg   case GL_R32F:
705848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT32);
706848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
707848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
708848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_FLOAT16);
709848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
710848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
711848b8605Smrg      break;
712848b8605Smrg   case GL_RG16F:
713848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
714848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
715848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
716848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
717848b8605Smrg      break;
718848b8605Smrg   case GL_RG32F:
719848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT32);
720848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT32);
721848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_FLOAT16);
722848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RGBA_FLOAT16);
723848b8605Smrg      break;
724848b8605Smrg
725848b8605Smrg   case GL_R8UI:
726848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT8);
727848b8605Smrg      break;
728848b8605Smrg   case GL_RG8UI:
729848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT8);
730848b8605Smrg      break;
731848b8605Smrg   case GL_R16UI:
732848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT16);
733848b8605Smrg      break;
734848b8605Smrg   case GL_RG16UI:
735848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT16);
736848b8605Smrg      break;
737848b8605Smrg   case GL_R32UI:
738848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_UINT32);
739848b8605Smrg      break;
740848b8605Smrg   case GL_RG32UI:
741848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_UINT32);
742848b8605Smrg      break;
743848b8605Smrg   case GL_R8I:
744848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_SINT8);
745848b8605Smrg      break;
746848b8605Smrg   case GL_RG8I:
747848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SINT8);
748848b8605Smrg      break;
749848b8605Smrg   case GL_R16I:
750848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_SINT16);
751848b8605Smrg      break;
752848b8605Smrg   case GL_RG16I:
753848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SINT16);
754848b8605Smrg      break;
755848b8605Smrg   case GL_R32I:
756848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R_SINT32);
757848b8605Smrg      break;
758848b8605Smrg   case GL_RG32I:
759848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_RG_SINT32);
760848b8605Smrg      break;
761848b8605Smrg
762848b8605Smrg   case GL_RGB10_A2UI:
763848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B10G10R10A2_UINT);
764848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_R10G10B10A2_UINT);
765848b8605Smrg      break;
766848b8605Smrg
767848b8605Smrg   case GL_BGRA:
768848b8605Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_B8G8R8A8_UNORM);
769848b8605Smrg      break;
770848b8605Smrg
771b8e80941Smrg   case GL_STENCIL_INDEX:
772b8e80941Smrg   case GL_STENCIL_INDEX8:
773b8e80941Smrg      RETURN_IF_SUPPORTED(MESA_FORMAT_S_UINT8);
774b8e80941Smrg      break;
775848b8605Smrg
776848b8605Smrg   default:
777b8e80941Smrg      /* For non-generic compressed format we assert two things:
778b8e80941Smrg       *
779b8e80941Smrg       * 1. The format has already been validated against the set of available
780b8e80941Smrg       *    extensions.
781b8e80941Smrg       *
782b8e80941Smrg       * 2. The driver only enables the extension if it supports all of the
783b8e80941Smrg       *    formats that are part of that extension.
784b8e80941Smrg       */
785b8e80941Smrg      if (_mesa_is_compressed_format(ctx, internalFormat))
786b8e80941Smrg         return _mesa_glenum_to_compressed_format(internalFormat);
787848b8605Smrg   }
788b8e80941Smrg
789b8e80941Smrg   _mesa_problem(ctx, "unexpected format %s in _mesa_choose_tex_format()",
790b8e80941Smrg                 _mesa_enum_to_string(internalFormat));
791b8e80941Smrg   return MESA_FORMAT_NONE;
792848b8605Smrg}
793