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