1 /**************************************************************************
2 *
3 * Copyright 2007 VMware, Inc.
4 * Copyright (c) 2008-2010 VMware, Inc.
5 * All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
27 **************************************************************************/
28
29
30 /**
31 * Mesa / Gallium format conversion and format selection code.
32 * \author Brian Paul
33 */
34
35
36 #include "main/context.h"
37 #include "main/enums.h"
38 #include "main/formats.h"
39 #include "main/glformats.h"
40 #include "main/texcompress.h"
41 #include "main/texgetimage.h"
42 #include "main/teximage.h"
43 #include "main/texstore.h"
44 #include "main/image.h"
45 #include "main/macros.h"
46 #include "main/formatquery.h"
47
48 #include "pipe/p_context.h"
49 #include "pipe/p_defines.h"
50 #include "pipe/p_screen.h"
51 #include "util/format/u_format.h"
52 #include "st_cb_texture.h"
53 #include "st_context.h"
54 #include "st_format.h"
55 #include "st_texture.h"
56
57
58 /**
59 * Translate Mesa format to Gallium format.
60 */
61 enum pipe_format
st_mesa_format_to_pipe_format(const struct st_context * st,mesa_format mesaFormat)62 st_mesa_format_to_pipe_format(const struct st_context *st,
63 mesa_format mesaFormat)
64 {
65 struct pipe_screen *screen = st->screen;
66
67 /* The destination RGBA format mustn't be changed, because it's also
68 * a destination format of the unpack/decompression function.
69 */
70 if (mesaFormat == MESA_FORMAT_ETC1_RGB8 && !st->has_etc1)
71 return st->transcode_etc ? PIPE_FORMAT_DXT1_RGB : PIPE_FORMAT_R8G8B8A8_UNORM;
72
73 /* ETC2 formats are emulated as uncompressed ones.
74 * The destination formats mustn't be changed, because they are also
75 * destination formats of the unpack/decompression function.
76 */
77 if (_mesa_is_format_etc2(mesaFormat) && !st->has_etc2) {
78 bool has_bgra_srgb = screen->is_format_supported(screen,
79 PIPE_FORMAT_B8G8R8A8_SRGB,
80 PIPE_TEXTURE_2D, 0, 0,
81 PIPE_BIND_SAMPLER_VIEW);
82
83 switch (mesaFormat) {
84 case MESA_FORMAT_ETC2_RGB8:
85 return st->transcode_etc ? PIPE_FORMAT_DXT1_RGB : PIPE_FORMAT_R8G8B8A8_UNORM;
86 case MESA_FORMAT_ETC2_SRGB8:
87 return st->transcode_etc ? PIPE_FORMAT_DXT1_SRGB :
88 has_bgra_srgb ? PIPE_FORMAT_B8G8R8A8_SRGB : PIPE_FORMAT_R8G8B8A8_SRGB;
89 case MESA_FORMAT_ETC2_RGBA8_EAC:
90 return st->transcode_etc ? PIPE_FORMAT_DXT5_RGBA : PIPE_FORMAT_R8G8B8A8_UNORM;
91 case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:
92 return st->transcode_etc ? PIPE_FORMAT_DXT5_SRGBA :
93 has_bgra_srgb ? PIPE_FORMAT_B8G8R8A8_SRGB : PIPE_FORMAT_R8G8B8A8_SRGB;
94 case MESA_FORMAT_ETC2_R11_EAC:
95 return PIPE_FORMAT_R16_UNORM;
96 case MESA_FORMAT_ETC2_RG11_EAC:
97 return PIPE_FORMAT_R16G16_UNORM;
98 case MESA_FORMAT_ETC2_SIGNED_R11_EAC:
99 return PIPE_FORMAT_R16_SNORM;
100 case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:
101 return PIPE_FORMAT_R16G16_SNORM;
102 case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:
103 return st->transcode_etc ? PIPE_FORMAT_DXT1_RGBA : PIPE_FORMAT_R8G8B8A8_UNORM;
104 case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:
105 return st->transcode_etc ? PIPE_FORMAT_DXT1_SRGBA :
106 has_bgra_srgb ? PIPE_FORMAT_B8G8R8A8_SRGB : PIPE_FORMAT_R8G8B8A8_SRGB;
107 default:
108 unreachable("Unknown ETC2 format");
109 }
110 }
111
112 if (st_astc_format_fallback(st, mesaFormat)) {
113 const struct util_format_description *desc =
114 util_format_description(mesaFormat);
115
116 if (_mesa_is_format_srgb(mesaFormat)) {
117 if (!st->transcode_astc)
118 return PIPE_FORMAT_R8G8B8A8_SRGB;
119 else if (desc->block.width * desc->block.height < 32)
120 return PIPE_FORMAT_DXT5_SRGBA;
121 else
122 return PIPE_FORMAT_DXT1_SRGBA;
123 } else {
124 if (!st->transcode_astc)
125 return PIPE_FORMAT_R8G8B8A8_UNORM;
126 else if (desc->block.width * desc->block.height < 32)
127 return PIPE_FORMAT_DXT5_RGBA;
128 else
129 return PIPE_FORMAT_DXT1_RGBA;
130 }
131 }
132
133 return mesaFormat;
134 }
135
136
137 /**
138 * Translate Gallium format to Mesa format.
139 */
140 mesa_format
st_pipe_format_to_mesa_format(enum pipe_format format)141 st_pipe_format_to_mesa_format(enum pipe_format format)
142 {
143 mesa_format mf = format;
144 if (!_mesa_get_format_name(mf))
145 return MESA_FORMAT_NONE;
146 return mf;
147 }
148
149 /**
150 * Map GL texture formats to Gallium pipe formats.
151 */
152 struct format_mapping
153 {
154 GLenum glFormats[18]; /**< list of GLenum formats, 0-terminated */
155 enum pipe_format pipeFormats[14]; /**< list of pipe formats, 0-terminated */
156 };
157
158
159 #define DEFAULT_RGBA_FORMATS \
160 PIPE_FORMAT_R8G8B8A8_UNORM, \
161 PIPE_FORMAT_B8G8R8A8_UNORM, \
162 PIPE_FORMAT_A8R8G8B8_UNORM, \
163 PIPE_FORMAT_A8B8G8R8_UNORM, \
164 0
165
166 #define DEFAULT_RGB_FORMATS \
167 PIPE_FORMAT_R8G8B8X8_UNORM, \
168 PIPE_FORMAT_B8G8R8X8_UNORM, \
169 PIPE_FORMAT_X8R8G8B8_UNORM, \
170 PIPE_FORMAT_X8B8G8R8_UNORM, \
171 PIPE_FORMAT_B5G6R5_UNORM, \
172 DEFAULT_RGBA_FORMATS
173
174 #define DEFAULT_SRGBA_FORMATS \
175 PIPE_FORMAT_R8G8B8A8_SRGB, \
176 PIPE_FORMAT_B8G8R8A8_SRGB, \
177 PIPE_FORMAT_A8R8G8B8_SRGB, \
178 PIPE_FORMAT_A8B8G8R8_SRGB, \
179 0
180
181 #define DEFAULT_DEPTH_FORMATS \
182 PIPE_FORMAT_Z24X8_UNORM, \
183 PIPE_FORMAT_X8Z24_UNORM, \
184 PIPE_FORMAT_Z16_UNORM, \
185 PIPE_FORMAT_Z24_UNORM_S8_UINT, \
186 PIPE_FORMAT_S8_UINT_Z24_UNORM, \
187 0
188
189 #define DEFAULT_SNORM8_RGBA_FORMATS \
190 PIPE_FORMAT_R8G8B8A8_SNORM, \
191 0
192
193 #define DEFAULT_UNORM16_RGBA_FORMATS \
194 PIPE_FORMAT_R16G16B16A16_UNORM, \
195 DEFAULT_RGBA_FORMATS
196
197
198 /**
199 * This table maps OpenGL texture format enums to Gallium pipe_format enums.
200 * Multiple GL enums might map to multiple pipe_formats.
201 * The first pipe format in the list that's supported is the one that's chosen.
202 */
203 static const struct format_mapping format_map[] = {
204 /* Basic RGB, RGBA formats */
205 {
206 { GL_RGB10, 0 },
207 { PIPE_FORMAT_R10G10B10X2_UNORM, PIPE_FORMAT_B10G10R10X2_UNORM,
208 PIPE_FORMAT_R10G10B10A2_UNORM, PIPE_FORMAT_B10G10R10A2_UNORM,
209 DEFAULT_RGB_FORMATS }
210 },
211 {
212 { GL_RGB10_A2, 0 },
213 { PIPE_FORMAT_R10G10B10A2_UNORM, PIPE_FORMAT_B10G10R10A2_UNORM,
214 DEFAULT_RGBA_FORMATS }
215 },
216 {
217 { 4, GL_RGBA, GL_RGBA8, 0 },
218 { PIPE_FORMAT_R8G8B8A8_UNORM, DEFAULT_RGBA_FORMATS }
219 },
220 {
221 { GL_BGRA, 0 },
222 { DEFAULT_RGBA_FORMATS }
223 },
224 {
225 { 3, GL_RGB, GL_RGB8, 0 },
226 { PIPE_FORMAT_R8G8B8X8_UNORM, DEFAULT_RGB_FORMATS }
227 },
228 {
229 { GL_RGB12, GL_RGB16, 0 },
230 { PIPE_FORMAT_R16G16B16X16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
231 DEFAULT_RGB_FORMATS }
232 },
233 {
234 { GL_RGBA12, GL_RGBA16, 0 },
235 { PIPE_FORMAT_R16G16B16A16_UNORM, DEFAULT_RGBA_FORMATS }
236 },
237 {
238 { GL_RGBA4, GL_RGBA2, 0 },
239 { PIPE_FORMAT_B4G4R4A4_UNORM, PIPE_FORMAT_A4B4G4R4_UNORM,
240 DEFAULT_RGBA_FORMATS }
241 },
242 {
243 { GL_RGB5_A1, 0 },
244 { PIPE_FORMAT_B5G5R5A1_UNORM, PIPE_FORMAT_A1B5G5R5_UNORM,
245 DEFAULT_RGBA_FORMATS }
246 },
247 {
248 { GL_R3_G3_B2, 0 },
249 { PIPE_FORMAT_B2G3R3_UNORM, PIPE_FORMAT_R3G3B2_UNORM,
250 PIPE_FORMAT_B5G6R5_UNORM, PIPE_FORMAT_B5G5R5A1_UNORM,
251 DEFAULT_RGB_FORMATS }
252 },
253 {
254 { GL_RGB4, 0 },
255 { PIPE_FORMAT_B4G4R4X4_UNORM, PIPE_FORMAT_B4G4R4A4_UNORM,
256 PIPE_FORMAT_A4B4G4R4_UNORM,
257 DEFAULT_RGB_FORMATS }
258 },
259 {
260 { GL_RGB5, 0 },
261 { PIPE_FORMAT_B5G5R5X1_UNORM, PIPE_FORMAT_X1B5G5R5_UNORM,
262 PIPE_FORMAT_B5G5R5A1_UNORM, PIPE_FORMAT_A1B5G5R5_UNORM,
263 DEFAULT_RGB_FORMATS }
264 },
265 {
266 { GL_RGB565, 0 },
267 { PIPE_FORMAT_B5G6R5_UNORM, DEFAULT_RGB_FORMATS }
268 },
269
270 /* basic Alpha formats */
271 {
272 { GL_ALPHA12, GL_ALPHA16, 0 },
273 { PIPE_FORMAT_A16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
274 PIPE_FORMAT_A8_UNORM, DEFAULT_RGBA_FORMATS }
275 },
276 {
277 { GL_ALPHA, GL_ALPHA4, GL_ALPHA8, GL_COMPRESSED_ALPHA, 0 },
278 { PIPE_FORMAT_A8_UNORM, DEFAULT_RGBA_FORMATS }
279 },
280
281 /* basic Luminance formats */
282 {
283 { GL_LUMINANCE12, GL_LUMINANCE16, 0 },
284 { PIPE_FORMAT_L16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
285 PIPE_FORMAT_L8_UNORM, DEFAULT_RGB_FORMATS }
286 },
287 {
288 { 1, GL_LUMINANCE, GL_LUMINANCE4, GL_LUMINANCE8, 0 },
289 { PIPE_FORMAT_L8_UNORM, PIPE_FORMAT_L8A8_UNORM, DEFAULT_RGB_FORMATS }
290 },
291
292 /* basic Luminance/Alpha formats */
293 {
294 { GL_LUMINANCE12_ALPHA4, GL_LUMINANCE12_ALPHA12,
295 GL_LUMINANCE16_ALPHA16, 0},
296 { PIPE_FORMAT_L16A16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
297 PIPE_FORMAT_L8A8_UNORM, DEFAULT_RGBA_FORMATS }
298 },
299 {
300 { 2, GL_LUMINANCE_ALPHA, GL_LUMINANCE6_ALPHA2, GL_LUMINANCE8_ALPHA8, 0 },
301 { PIPE_FORMAT_L8A8_UNORM, DEFAULT_RGBA_FORMATS }
302 },
303 {
304 { GL_LUMINANCE4_ALPHA4, 0 },
305 { PIPE_FORMAT_L4A4_UNORM, PIPE_FORMAT_L8A8_UNORM,
306 DEFAULT_RGBA_FORMATS }
307 },
308
309 /* basic Intensity formats */
310 {
311 { GL_INTENSITY12, GL_INTENSITY16, 0 },
312 { PIPE_FORMAT_I16_UNORM, PIPE_FORMAT_R16G16B16A16_UNORM,
313 PIPE_FORMAT_I8_UNORM, DEFAULT_RGBA_FORMATS }
314 },
315 {
316 { GL_INTENSITY, GL_INTENSITY4, GL_INTENSITY8,
317 GL_COMPRESSED_INTENSITY, 0 },
318 { PIPE_FORMAT_I8_UNORM, DEFAULT_RGBA_FORMATS }
319 },
320
321 /* YCbCr */
322 {
323 { GL_YCBCR_MESA, 0 },
324 { PIPE_FORMAT_UYVY, PIPE_FORMAT_YUYV, 0 }
325 },
326
327 /* compressed formats */ /* XXX PIPE_BIND_SAMPLER_VIEW only */
328 {
329 { GL_COMPRESSED_RGB, 0 },
330 { PIPE_FORMAT_DXT1_RGB, DEFAULT_RGB_FORMATS }
331 },
332 {
333 { GL_COMPRESSED_RGBA, 0 },
334 { PIPE_FORMAT_DXT5_RGBA, DEFAULT_RGBA_FORMATS }
335 },
336 {
337 { GL_RGB_S3TC, GL_RGB4_S3TC, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 0 },
338 { PIPE_FORMAT_DXT1_RGB, 0 }
339 },
340 {
341 { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 0 },
342 { PIPE_FORMAT_DXT1_RGBA, 0 }
343 },
344 {
345 { GL_RGBA_S3TC, GL_RGBA4_S3TC, GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 0 },
346 { PIPE_FORMAT_DXT3_RGBA, 0 }
347 },
348 {
349 { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 0 },
350 { PIPE_FORMAT_DXT5_RGBA, 0 }
351 },
352
353 {
354 { GL_COMPRESSED_RGB_FXT1_3DFX, 0 },
355 { PIPE_FORMAT_FXT1_RGB, 0 }
356 },
357 {
358 { GL_COMPRESSED_RGBA_FXT1_3DFX, 0 },
359 { PIPE_FORMAT_FXT1_RGBA, 0 }
360 },
361
362 /* Depth formats */
363 {
364 { GL_DEPTH_COMPONENT16, 0 },
365 { PIPE_FORMAT_Z16_UNORM, DEFAULT_DEPTH_FORMATS }
366 },
367 {
368 { GL_DEPTH_COMPONENT24, 0 },
369 { PIPE_FORMAT_Z24X8_UNORM, PIPE_FORMAT_X8Z24_UNORM,
370 DEFAULT_DEPTH_FORMATS }
371 },
372 {
373 { GL_DEPTH_COMPONENT32, 0 },
374 { PIPE_FORMAT_Z32_UNORM, DEFAULT_DEPTH_FORMATS }
375 },
376 {
377 { GL_DEPTH_COMPONENT, 0 },
378 { DEFAULT_DEPTH_FORMATS }
379 },
380 {
381 { GL_DEPTH_COMPONENT32F, 0 },
382 { PIPE_FORMAT_Z32_FLOAT, 0 }
383 },
384
385 /* stencil formats */
386 {
387 { GL_STENCIL_INDEX, GL_STENCIL_INDEX1_EXT, GL_STENCIL_INDEX4_EXT,
388 GL_STENCIL_INDEX8_EXT, GL_STENCIL_INDEX16_EXT, 0 },
389 {
390 PIPE_FORMAT_S8_UINT, PIPE_FORMAT_Z24_UNORM_S8_UINT,
391 PIPE_FORMAT_S8_UINT_Z24_UNORM, 0
392 }
393 },
394
395 /* Depth / Stencil formats */
396 {
397 { GL_DEPTH_STENCIL_EXT, GL_DEPTH24_STENCIL8_EXT, 0 },
398 { PIPE_FORMAT_Z24_UNORM_S8_UINT, PIPE_FORMAT_S8_UINT_Z24_UNORM, 0 }
399 },
400 {
401 { GL_DEPTH32F_STENCIL8, 0 },
402 { PIPE_FORMAT_Z32_FLOAT_S8X24_UINT, 0 }
403 },
404
405 /* sRGB formats */
406 {
407 { GL_SRGB_EXT, GL_SRGB8_EXT, 0 },
408 { PIPE_FORMAT_R8G8B8X8_SRGB, PIPE_FORMAT_B8G8R8X8_SRGB,
409 DEFAULT_SRGBA_FORMATS }
410 },
411 {
412 { GL_SRGB_ALPHA_EXT, GL_SRGB8_ALPHA8_EXT, 0 },
413 { PIPE_FORMAT_R8G8B8A8_SRGB, DEFAULT_SRGBA_FORMATS }
414 },
415 {
416 { GL_COMPRESSED_SRGB_EXT, GL_COMPRESSED_SRGB_S3TC_DXT1_EXT, 0 },
417 { PIPE_FORMAT_DXT1_SRGB, PIPE_FORMAT_R8G8B8X8_SRGB,
418 PIPE_FORMAT_B8G8R8X8_SRGB, DEFAULT_SRGBA_FORMATS }
419 },
420 {
421 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT, 0 },
422 { PIPE_FORMAT_DXT1_SRGBA, 0 }
423 },
424 {
425 { GL_COMPRESSED_SRGB_ALPHA_EXT,
426 GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT, 0 },
427 { PIPE_FORMAT_DXT3_SRGBA, DEFAULT_SRGBA_FORMATS }
428 },
429 {
430 { GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT, 0 },
431 { PIPE_FORMAT_DXT5_SRGBA, 0 }
432 },
433 {
434 { GL_SLUMINANCE_ALPHA_EXT, GL_SLUMINANCE8_ALPHA8_EXT,
435 GL_COMPRESSED_SLUMINANCE_ALPHA_EXT, 0 },
436 { PIPE_FORMAT_L8A8_SRGB, DEFAULT_SRGBA_FORMATS }
437 },
438 {
439 { GL_SLUMINANCE_EXT, GL_SLUMINANCE8_EXT, GL_COMPRESSED_SLUMINANCE_EXT,
440 0 },
441 { PIPE_FORMAT_L8_SRGB, DEFAULT_SRGBA_FORMATS }
442 },
443 {
444 { GL_SR8_EXT, 0 },
445 { PIPE_FORMAT_R8_SRGB, 0 }
446 },
447 {
448 { GL_SRG8_EXT, 0 },
449 { PIPE_FORMAT_R8G8_SRGB, 0 }
450 },
451
452 /* 16-bit float formats */
453 {
454 { GL_RGBA16F_ARB, 0 },
455 { PIPE_FORMAT_R16G16B16A16_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
456 },
457 {
458 { GL_RGB16F_ARB, 0 },
459 { PIPE_FORMAT_R16G16B16_FLOAT, PIPE_FORMAT_R16G16B16X16_FLOAT,
460 PIPE_FORMAT_R16G16B16A16_FLOAT,
461 PIPE_FORMAT_R32G32B32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
462 },
463 {
464 { GL_LUMINANCE_ALPHA16F_ARB, 0 },
465 { PIPE_FORMAT_L16A16_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
466 PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
467 },
468 {
469 { GL_ALPHA16F_ARB, 0 },
470 { PIPE_FORMAT_A16_FLOAT, PIPE_FORMAT_L16A16_FLOAT,
471 PIPE_FORMAT_A32_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
472 PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
473 },
474 {
475 { GL_INTENSITY16F_ARB, 0 },
476 { PIPE_FORMAT_I16_FLOAT, PIPE_FORMAT_L16A16_FLOAT,
477 PIPE_FORMAT_I32_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
478 PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
479 },
480 {
481 { GL_LUMINANCE16F_ARB, 0 },
482 { PIPE_FORMAT_L16_FLOAT, PIPE_FORMAT_L16A16_FLOAT,
483 PIPE_FORMAT_L32_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
484 PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
485 },
486 {
487 { GL_R16F, 0 },
488 { PIPE_FORMAT_R16_FLOAT, PIPE_FORMAT_R16G16_FLOAT,
489 PIPE_FORMAT_R32_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
490 PIPE_FORMAT_R32G32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
491 },
492 {
493 { GL_RG16F, 0 },
494 { PIPE_FORMAT_R16G16_FLOAT, PIPE_FORMAT_R16G16B16A16_FLOAT,
495 PIPE_FORMAT_R32G32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
496 },
497
498 /* 32-bit float formats */
499 {
500 { GL_RGBA32F_ARB, 0 },
501 { PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
502 },
503 {
504 { GL_RGB32F_ARB, 0 },
505 { PIPE_FORMAT_R32G32B32_FLOAT, PIPE_FORMAT_R32G32B32X32_FLOAT,
506 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
507 },
508 {
509 { GL_LUMINANCE_ALPHA32F_ARB, 0 },
510 { PIPE_FORMAT_L32A32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
511 },
512 {
513 { GL_ALPHA32F_ARB, 0 },
514 { PIPE_FORMAT_A32_FLOAT, PIPE_FORMAT_L32A32_FLOAT,
515 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
516 },
517 {
518 { GL_INTENSITY32F_ARB, 0 },
519 { PIPE_FORMAT_I32_FLOAT, PIPE_FORMAT_L32A32_FLOAT,
520 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
521 },
522 {
523 { GL_LUMINANCE32F_ARB, 0 },
524 { PIPE_FORMAT_L32_FLOAT, PIPE_FORMAT_L32A32_FLOAT,
525 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
526 },
527 {
528 { GL_R32F, 0 },
529 { PIPE_FORMAT_R32_FLOAT, PIPE_FORMAT_R32G32_FLOAT,
530 PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
531 },
532 {
533 { GL_RG32F, 0 },
534 { PIPE_FORMAT_R32G32_FLOAT, PIPE_FORMAT_R32G32B32A32_FLOAT, 0 }
535 },
536
537 /* R, RG formats */
538 {
539 { GL_RED, GL_R8, 0 },
540 { PIPE_FORMAT_R8_UNORM, PIPE_FORMAT_R8G8_UNORM, DEFAULT_RGBA_FORMATS }
541 },
542 {
543 { GL_RG, GL_RG8, 0 },
544 { PIPE_FORMAT_R8G8_UNORM, DEFAULT_RGBA_FORMATS }
545 },
546 {
547 { GL_R16, 0 },
548 { PIPE_FORMAT_R16_UNORM, PIPE_FORMAT_R16G16_UNORM,
549 DEFAULT_UNORM16_RGBA_FORMATS }
550 },
551 {
552 { GL_RG16, 0 },
553 { PIPE_FORMAT_R16G16_UNORM, DEFAULT_UNORM16_RGBA_FORMATS }
554 },
555
556 /* compressed R, RG formats */
557 {
558 { GL_COMPRESSED_RED, GL_COMPRESSED_RED_RGTC1, 0 },
559 { PIPE_FORMAT_RGTC1_UNORM, PIPE_FORMAT_R8_UNORM, DEFAULT_RGBA_FORMATS }
560 },
561 {
562 { GL_COMPRESSED_SIGNED_RED_RGTC1, 0 },
563 { PIPE_FORMAT_RGTC1_SNORM, DEFAULT_SNORM8_RGBA_FORMATS }
564 },
565 {
566 { GL_COMPRESSED_RG, GL_COMPRESSED_RG_RGTC2, 0 },
567 { PIPE_FORMAT_RGTC2_UNORM, PIPE_FORMAT_R8G8_UNORM, DEFAULT_RGBA_FORMATS }
568 },
569 {
570 { GL_COMPRESSED_SIGNED_RG_RGTC2, 0 },
571 { PIPE_FORMAT_RGTC2_SNORM, DEFAULT_SNORM8_RGBA_FORMATS }
572 },
573 {
574 { GL_COMPRESSED_LUMINANCE, GL_COMPRESSED_LUMINANCE_LATC1_EXT, 0 },
575 { PIPE_FORMAT_LATC1_UNORM, PIPE_FORMAT_L8_UNORM, DEFAULT_RGBA_FORMATS }
576 },
577 {
578 { GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT, 0 },
579 { PIPE_FORMAT_LATC1_SNORM, DEFAULT_SNORM8_RGBA_FORMATS }
580 },
581 {
582 { GL_COMPRESSED_LUMINANCE_ALPHA, GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT,
583 GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI, 0 },
584 { PIPE_FORMAT_LATC2_UNORM, PIPE_FORMAT_L8A8_UNORM, DEFAULT_RGBA_FORMATS }
585 },
586 {
587 { GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT, 0 },
588 { PIPE_FORMAT_LATC2_SNORM, DEFAULT_SNORM8_RGBA_FORMATS }
589 },
590
591 /* ETC1 */
592 {
593 { GL_ETC1_RGB8_OES, 0 },
594 { PIPE_FORMAT_ETC1_RGB8, 0 }
595 },
596
597 /* ETC2 */
598 {
599 { GL_COMPRESSED_RGB8_ETC2, 0 },
600 { PIPE_FORMAT_ETC2_RGB8, 0 }
601 },
602 {
603 { GL_COMPRESSED_SRGB8_ETC2, 0 },
604 { PIPE_FORMAT_ETC2_SRGB8, 0 }
605 },
606 {
607 { GL_COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2, 0 },
608 { PIPE_FORMAT_ETC2_RGB8A1, 0 }
609 },
610 {
611 { GL_COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2, 0 },
612 { PIPE_FORMAT_ETC2_SRGB8A1, 0 }
613 },
614 {
615 { GL_COMPRESSED_RGBA8_ETC2_EAC, 0 },
616 { PIPE_FORMAT_ETC2_RGBA8, 0 }
617 },
618 {
619 { GL_COMPRESSED_SRGB8_ALPHA8_ETC2_EAC, 0 },
620 { PIPE_FORMAT_ETC2_SRGBA8, 0 }
621 },
622 {
623 { GL_COMPRESSED_R11_EAC, 0 },
624 { PIPE_FORMAT_ETC2_R11_UNORM, 0 }
625 },
626 {
627 { GL_COMPRESSED_SIGNED_R11_EAC, 0 },
628 { PIPE_FORMAT_ETC2_R11_SNORM, 0 }
629 },
630 {
631 { GL_COMPRESSED_RG11_EAC, 0 },
632 { PIPE_FORMAT_ETC2_RG11_UNORM, 0 }
633 },
634 {
635 { GL_COMPRESSED_SIGNED_RG11_EAC, 0 },
636 { PIPE_FORMAT_ETC2_RG11_SNORM, 0 }
637 },
638
639 /* BPTC */
640 {
641 { GL_COMPRESSED_RGBA_BPTC_UNORM, 0 },
642 { PIPE_FORMAT_BPTC_RGBA_UNORM, 0 },
643 },
644 {
645 { GL_COMPRESSED_SRGB_ALPHA_BPTC_UNORM, 0 },
646 { PIPE_FORMAT_BPTC_SRGBA, 0 },
647 },
648 {
649 { GL_COMPRESSED_RGB_BPTC_SIGNED_FLOAT, 0 },
650 { PIPE_FORMAT_BPTC_RGB_FLOAT, 0 },
651 },
652 {
653 { GL_COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT, 0 },
654 { PIPE_FORMAT_BPTC_RGB_UFLOAT, 0 },
655 },
656
657 /* ASTC */
658 {
659 { GL_COMPRESSED_RGBA_ASTC_4x4_KHR, 0 },
660 { PIPE_FORMAT_ASTC_4x4, 0},
661 },
662 {
663 { GL_COMPRESSED_RGBA_ASTC_5x4_KHR, 0 },
664 { PIPE_FORMAT_ASTC_5x4, 0},
665 },
666 {
667 { GL_COMPRESSED_RGBA_ASTC_5x5_KHR, 0 },
668 { PIPE_FORMAT_ASTC_5x5, 0},
669 },
670 {
671 { GL_COMPRESSED_RGBA_ASTC_6x5_KHR, 0 },
672 { PIPE_FORMAT_ASTC_6x5, 0},
673 },
674 {
675 { GL_COMPRESSED_RGBA_ASTC_6x6_KHR, 0 },
676 { PIPE_FORMAT_ASTC_6x6, 0},
677 },
678 {
679 { GL_COMPRESSED_RGBA_ASTC_8x5_KHR, 0 },
680 { PIPE_FORMAT_ASTC_8x5, 0},
681 },
682 {
683 { GL_COMPRESSED_RGBA_ASTC_8x6_KHR, 0 },
684 { PIPE_FORMAT_ASTC_8x6, 0},
685 },
686 {
687 { GL_COMPRESSED_RGBA_ASTC_8x8_KHR, 0 },
688 { PIPE_FORMAT_ASTC_8x8, 0},
689 },
690 {
691 { GL_COMPRESSED_RGBA_ASTC_10x5_KHR, 0 },
692 { PIPE_FORMAT_ASTC_10x5, 0},
693 },
694 {
695 { GL_COMPRESSED_RGBA_ASTC_10x6_KHR, 0 },
696 { PIPE_FORMAT_ASTC_10x6, 0},
697 },
698 {
699 { GL_COMPRESSED_RGBA_ASTC_10x8_KHR, 0 },
700 { PIPE_FORMAT_ASTC_10x8, 0},
701 },
702 {
703 { GL_COMPRESSED_RGBA_ASTC_10x10_KHR, 0 },
704 { PIPE_FORMAT_ASTC_10x10, 0},
705 },
706 {
707 { GL_COMPRESSED_RGBA_ASTC_12x10_KHR, 0 },
708 { PIPE_FORMAT_ASTC_12x10, 0},
709 },
710 {
711 { GL_COMPRESSED_RGBA_ASTC_12x12_KHR, 0 },
712 { PIPE_FORMAT_ASTC_12x12, 0},
713 },
714
715 {
716 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR, 0 },
717 { PIPE_FORMAT_ASTC_4x4_SRGB, 0},
718 },
719 {
720 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR, 0 },
721 { PIPE_FORMAT_ASTC_5x4_SRGB, 0},
722 },
723 {
724 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR, 0 },
725 { PIPE_FORMAT_ASTC_5x5_SRGB, 0},
726 },
727 {
728 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR, 0 },
729 { PIPE_FORMAT_ASTC_6x5_SRGB, 0},
730 },
731 {
732 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR, 0 },
733 { PIPE_FORMAT_ASTC_6x6_SRGB, 0},
734 },
735 {
736 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR, 0 },
737 { PIPE_FORMAT_ASTC_8x5_SRGB, 0},
738 },
739 {
740 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR, 0 },
741 { PIPE_FORMAT_ASTC_8x6_SRGB, 0},
742 },
743 {
744 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR, 0 },
745 { PIPE_FORMAT_ASTC_8x8_SRGB, 0},
746 },
747 {
748 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR, 0 },
749 { PIPE_FORMAT_ASTC_10x5_SRGB, 0},
750 },
751 {
752 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR, 0 },
753 { PIPE_FORMAT_ASTC_10x6_SRGB, 0},
754 },
755 {
756 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR, 0 },
757 { PIPE_FORMAT_ASTC_10x8_SRGB, 0},
758 },
759 {
760 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 0 },
761 { PIPE_FORMAT_ASTC_10x10_SRGB, 0},
762 },
763 {
764 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 0 },
765 { PIPE_FORMAT_ASTC_12x10_SRGB, 0},
766 },
767 {
768 { GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 0 },
769 { PIPE_FORMAT_ASTC_12x12_SRGB, 0},
770 },
771
772 /* signed/unsigned integer formats.
773 */
774 {
775 { GL_RGBA_INTEGER_EXT,
776 GL_BGRA_INTEGER_EXT,
777 GL_RGBA8I_EXT, 0 },
778 { PIPE_FORMAT_R8G8B8A8_SINT, 0 }
779 },
780 {
781 { GL_RGB_INTEGER_EXT,
782 GL_BGR_INTEGER_EXT,
783 GL_RGB8I_EXT,
784 GL_BLUE_INTEGER_EXT, 0 },
785 { PIPE_FORMAT_R8G8B8_SINT, PIPE_FORMAT_R8G8B8X8_SINT,
786 PIPE_FORMAT_R8G8B8A8_SINT, 0 }
787 },
788 {
789 { GL_ALPHA_INTEGER_EXT,
790 GL_ALPHA8I_EXT, 0 },
791 { PIPE_FORMAT_A8_SINT, PIPE_FORMAT_R8G8B8A8_SINT, 0 }
792 },
793 {
794 { GL_ALPHA16I_EXT, 0 },
795 { PIPE_FORMAT_A16_SINT, PIPE_FORMAT_R16G16B16A16_SINT, 0 }
796 },
797 {
798 { GL_ALPHA32I_EXT, 0 },
799 { PIPE_FORMAT_A32_SINT, PIPE_FORMAT_R32G32B32A32_SINT, 0 }
800 },
801 {
802 { GL_ALPHA8UI_EXT, 0 },
803 { PIPE_FORMAT_A8_UINT, PIPE_FORMAT_R8G8B8A8_UINT, 0 }
804 },
805 {
806 { GL_ALPHA16UI_EXT, 0 },
807 { PIPE_FORMAT_A16_UINT, PIPE_FORMAT_R16G16B16A16_UINT, 0 }
808 },
809 {
810 { GL_ALPHA32UI_EXT, 0 },
811 { PIPE_FORMAT_A32_UINT, PIPE_FORMAT_R32G32B32A32_UINT, 0 }
812 },
813 {
814 { GL_INTENSITY8I_EXT, 0 },
815 { PIPE_FORMAT_I8_SINT, PIPE_FORMAT_R8G8B8A8_SINT, 0 }
816 },
817 {
818 { GL_INTENSITY16I_EXT, 0 },
819 { PIPE_FORMAT_I16_SINT, PIPE_FORMAT_R16G16B16A16_SINT, 0 }
820 },
821 {
822 { GL_INTENSITY32I_EXT, 0 },
823 { PIPE_FORMAT_I32_SINT, PIPE_FORMAT_R32G32B32A32_SINT, 0 }
824 },
825 {
826 { GL_INTENSITY8UI_EXT, 0 },
827 { PIPE_FORMAT_I8_UINT, PIPE_FORMAT_R8G8B8A8_UINT, 0 }
828 },
829 {
830 { GL_INTENSITY16UI_EXT, 0 },
831 { PIPE_FORMAT_I16_UINT, PIPE_FORMAT_R16G16B16A16_UINT, 0 }
832 },
833 {
834 { GL_INTENSITY32UI_EXT, 0 },
835 { PIPE_FORMAT_I32_UINT, PIPE_FORMAT_R32G32B32A32_UINT, 0 }
836 },
837 {
838 { GL_LUMINANCE8I_EXT, 0 },
839 { PIPE_FORMAT_L8_SINT, PIPE_FORMAT_R8G8B8A8_SINT, 0 }
840 },
841 {
842 { GL_LUMINANCE16I_EXT, 0 },
843 { PIPE_FORMAT_L16_SINT, PIPE_FORMAT_R16G16B16A16_SINT, 0 }
844 },
845 {
846 { GL_LUMINANCE32I_EXT, 0 },
847 { PIPE_FORMAT_L32_SINT, PIPE_FORMAT_R32G32B32A32_SINT, 0 }
848 },
849 {
850 { GL_LUMINANCE_INTEGER_EXT,
851 GL_LUMINANCE8UI_EXT, 0 },
852 { PIPE_FORMAT_L8_UINT, PIPE_FORMAT_R8G8B8A8_UINT, 0 }
853 },
854 {
855 { GL_LUMINANCE16UI_EXT, 0 },
856 { PIPE_FORMAT_L16_UINT, PIPE_FORMAT_R16G16B16A16_UINT, 0 }
857 },
858 {
859 { GL_LUMINANCE32UI_EXT, 0 },
860 { PIPE_FORMAT_L32_UINT, PIPE_FORMAT_R32G32B32A32_UINT, 0 }
861 },
862 {
863 { GL_LUMINANCE_ALPHA_INTEGER_EXT,
864 GL_LUMINANCE_ALPHA8I_EXT, 0 },
865 { PIPE_FORMAT_L8A8_SINT, PIPE_FORMAT_R8G8B8A8_SINT, 0 }
866 },
867 {
868 { GL_LUMINANCE_ALPHA16I_EXT, 0 },
869 { PIPE_FORMAT_L16A16_SINT, PIPE_FORMAT_R16G16B16A16_SINT, 0 }
870 },
871 {
872 { GL_LUMINANCE_ALPHA32I_EXT, 0 },
873 { PIPE_FORMAT_L32A32_SINT, PIPE_FORMAT_R32G32B32A32_SINT, 0 }
874 },
875 {
876 { GL_LUMINANCE_ALPHA8UI_EXT, 0 },
877 { PIPE_FORMAT_L8A8_UINT, PIPE_FORMAT_R8G8B8A8_UINT, 0 }
878 },
879 {
880 { GL_LUMINANCE_ALPHA16UI_EXT, 0 },
881 { PIPE_FORMAT_L16A16_UINT, PIPE_FORMAT_R16G16B16A16_UINT, 0 }
882 },
883 {
884 { GL_LUMINANCE_ALPHA32UI_EXT, 0 },
885 { PIPE_FORMAT_L32A32_UINT, PIPE_FORMAT_R32G32B32A32_UINT, 0 }
886 },
887 {
888 { GL_RGB16I_EXT, 0 },
889 { PIPE_FORMAT_R16G16B16_SINT, PIPE_FORMAT_R16G16B16X16_SINT,
890 PIPE_FORMAT_R16G16B16A16_SINT, 0 },
891 },
892 {
893 { GL_RGBA16I_EXT, 0 },
894 { PIPE_FORMAT_R16G16B16A16_SINT, 0 },
895 },
896 {
897 { GL_RGB32I_EXT, 0 },
898 { PIPE_FORMAT_R32G32B32_SINT, PIPE_FORMAT_R32G32B32X32_SINT,
899 PIPE_FORMAT_R32G32B32A32_SINT, 0 },
900 },
901 {
902 { GL_RGBA32I_EXT, 0 },
903 { PIPE_FORMAT_R32G32B32A32_SINT, 0 }
904 },
905 {
906 { GL_RGBA8UI_EXT, 0 },
907 { PIPE_FORMAT_R8G8B8A8_UINT, 0 }
908 },
909 {
910 { GL_RGB8UI_EXT, 0 },
911 { PIPE_FORMAT_R8G8B8_UINT, PIPE_FORMAT_R8G8B8X8_UINT,
912 PIPE_FORMAT_R8G8B8A8_UINT, 0 }
913 },
914 {
915 { GL_RGB16UI_EXT, 0 },
916 { PIPE_FORMAT_R16G16B16_UINT, PIPE_FORMAT_R16G16B16X16_UINT,
917 PIPE_FORMAT_R16G16B16A16_UINT, 0 }
918 },
919 {
920 { GL_RGBA16UI_EXT, 0 },
921 { PIPE_FORMAT_R16G16B16A16_UINT, 0 }
922 },
923 {
924 { GL_RGB32UI_EXT, 0},
925 { PIPE_FORMAT_R32G32B32_UINT, PIPE_FORMAT_R32G32B32X32_UINT,
926 PIPE_FORMAT_R32G32B32A32_UINT, 0 }
927 },
928 {
929 { GL_RGBA32UI_EXT, 0},
930 { PIPE_FORMAT_R32G32B32A32_UINT, 0 }
931 },
932 {
933 { GL_R8I, GL_RED_INTEGER_EXT, 0},
934 { PIPE_FORMAT_R8_SINT, PIPE_FORMAT_R8G8_SINT, 0},
935 },
936 {
937 { GL_R16I, 0},
938 { PIPE_FORMAT_R16_SINT, 0},
939 },
940 {
941 { GL_R32I, 0},
942 { PIPE_FORMAT_R32_SINT, 0},
943 },
944 {
945 { GL_R8UI, 0},
946 { PIPE_FORMAT_R8_UINT, PIPE_FORMAT_R8G8_UINT, 0},
947 },
948 {
949 { GL_R16UI, 0},
950 { PIPE_FORMAT_R16_UINT, 0},
951 },
952 {
953 { GL_R32UI, 0},
954 { PIPE_FORMAT_R32_UINT, 0},
955 },
956 {
957 { GL_RG8I, GL_GREEN_INTEGER_EXT, 0},
958 { PIPE_FORMAT_R8G8_SINT, 0},
959 },
960 {
961 { GL_RG16I, 0},
962 { PIPE_FORMAT_R16G16_SINT, 0},
963 },
964 {
965 { GL_RG32I, 0},
966 { PIPE_FORMAT_R32G32_SINT, 0},
967 },
968 {
969 { GL_RG8UI, 0},
970 { PIPE_FORMAT_R8G8_UINT, 0},
971 },
972 {
973 { GL_RG16UI, 0},
974 { PIPE_FORMAT_R16G16_UINT, 0},
975 },
976 {
977 { GL_RG32UI, 0},
978 { PIPE_FORMAT_R32G32_UINT, 0},
979 },
980 /* signed normalized formats */
981 {
982 { GL_RED_SNORM, GL_R8_SNORM, 0 },
983 { PIPE_FORMAT_R8_SNORM, PIPE_FORMAT_R8G8_SNORM,
984 PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
985 },
986 {
987 { GL_R16_SNORM, 0 },
988 { PIPE_FORMAT_R16_SNORM,
989 PIPE_FORMAT_R16G16_SNORM,
990 PIPE_FORMAT_R16G16B16A16_SNORM,
991 PIPE_FORMAT_R8_SNORM,
992 PIPE_FORMAT_R8G8_SNORM,
993 PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
994 },
995 {
996 { GL_RG_SNORM, GL_RG8_SNORM, 0 },
997 { PIPE_FORMAT_R8G8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
998 },
999 {
1000 { GL_RG16_SNORM, 0 },
1001 { PIPE_FORMAT_R16G16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1002 PIPE_FORMAT_R8G8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1003 },
1004 {
1005 { GL_RGB_SNORM, GL_RGB8_SNORM, 0 },
1006 { PIPE_FORMAT_R8G8B8X8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1007 },
1008 {
1009 { GL_RGBA_SNORM, GL_RGBA8_SNORM, 0 },
1010 { PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1011 },
1012 {
1013 { GL_RGB16_SNORM, 0 },
1014 { PIPE_FORMAT_R16G16B16X16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1015 PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1016 },
1017 {
1018 { GL_RGBA16_SNORM, 0 },
1019 { PIPE_FORMAT_R16G16B16A16_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1020 },
1021 {
1022 { GL_ALPHA_SNORM, GL_ALPHA8_SNORM, 0 },
1023 { PIPE_FORMAT_A8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1024 },
1025 {
1026 { GL_ALPHA16_SNORM, 0 },
1027 { PIPE_FORMAT_A16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1028 PIPE_FORMAT_A8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1029 },
1030 {
1031 { GL_LUMINANCE_SNORM, GL_LUMINANCE8_SNORM, 0 },
1032 { PIPE_FORMAT_L8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1033 },
1034 {
1035 { GL_LUMINANCE16_SNORM, 0 },
1036 { PIPE_FORMAT_L16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1037 PIPE_FORMAT_L8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1038 },
1039 {
1040 { GL_LUMINANCE_ALPHA_SNORM, GL_LUMINANCE8_ALPHA8_SNORM, 0 },
1041 { PIPE_FORMAT_L8A8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1042 },
1043 {
1044 { GL_LUMINANCE16_ALPHA16_SNORM, 0 },
1045 { PIPE_FORMAT_L16A16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1046 PIPE_FORMAT_L8A8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1047 },
1048 {
1049 { GL_INTENSITY_SNORM, GL_INTENSITY8_SNORM, 0 },
1050 { PIPE_FORMAT_I8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1051 },
1052 {
1053 { GL_INTENSITY16_SNORM, 0 },
1054 { PIPE_FORMAT_I16_SNORM, PIPE_FORMAT_R16G16B16A16_SNORM,
1055 PIPE_FORMAT_I8_SNORM, PIPE_FORMAT_R8G8B8A8_SNORM, 0 }
1056 },
1057 {
1058 { GL_RGB9_E5, 0 },
1059 { PIPE_FORMAT_R9G9B9E5_FLOAT, 0 }
1060 },
1061 {
1062 { GL_R11F_G11F_B10F, 0 },
1063 { PIPE_FORMAT_R11G11B10_FLOAT, 0 }
1064 },
1065 {
1066 { GL_RGB10_A2UI, 0 },
1067 { PIPE_FORMAT_R10G10B10A2_UINT, PIPE_FORMAT_B10G10R10A2_UINT, 0 }
1068 },
1069 };
1070
1071
1072 /**
1073 * Return first supported format from the given list.
1074 * \param allow_dxt indicates whether it's OK to return a DXT format.
1075 */
1076 static enum pipe_format
find_supported_format(struct pipe_screen * screen,const enum pipe_format formats[],enum pipe_texture_target target,unsigned sample_count,unsigned storage_sample_count,unsigned bindings,boolean allow_dxt)1077 find_supported_format(struct pipe_screen *screen,
1078 const enum pipe_format formats[],
1079 enum pipe_texture_target target,
1080 unsigned sample_count,
1081 unsigned storage_sample_count,
1082 unsigned bindings,
1083 boolean allow_dxt)
1084 {
1085 uint i;
1086 for (i = 0; formats[i]; i++) {
1087 if (!bindings || screen->is_format_supported(screen, formats[i], target,
1088 sample_count, storage_sample_count,
1089 bindings)) {
1090 if (!allow_dxt && util_format_is_s3tc(formats[i])) {
1091 /* we can't return a dxt format, continue searching */
1092 continue;
1093 }
1094
1095 return formats[i];
1096 }
1097 }
1098 return PIPE_FORMAT_NONE;
1099 }
1100
1101 /**
1102 * Given an OpenGL internalFormat value for a texture or surface, return
1103 * the best matching PIPE_FORMAT_x, or PIPE_FORMAT_NONE if there's no match.
1104 * This is called during glTexImage2D, for example.
1105 *
1106 * The bindings parameter typically has PIPE_BIND_SAMPLER_VIEW set, plus
1107 * either PIPE_BINDING_RENDER_TARGET or PIPE_BINDING_DEPTH_STENCIL if
1108 * we want render-to-texture ability.
1109 * If bindings is zero, the driver doesn't need to support the returned format.
1110 *
1111 * \param internalFormat the user value passed to glTexImage2D
1112 * \param target one of PIPE_TEXTURE_x
1113 * \param bindings bitmask of PIPE_BIND_x flags.
1114 * \param allow_dxt indicates whether it's OK to return a DXT format. This
1115 * only matters when internalFormat names a generic or
1116 * specific compressed format. And that should only happen
1117 * when we're getting called from gl[Copy]TexImage().
1118 */
1119 enum pipe_format
st_choose_format(struct st_context * st,GLenum internalFormat,GLenum format,GLenum type,enum pipe_texture_target target,unsigned sample_count,unsigned storage_sample_count,unsigned bindings,bool swap_bytes,bool allow_dxt)1120 st_choose_format(struct st_context *st, GLenum internalFormat,
1121 GLenum format, GLenum type,
1122 enum pipe_texture_target target, unsigned sample_count,
1123 unsigned storage_sample_count,
1124 unsigned bindings, bool swap_bytes, bool allow_dxt)
1125 {
1126 struct pipe_screen *screen = st->screen;
1127 unsigned i;
1128 int j;
1129 enum pipe_format pf;
1130
1131 /* can't render to compressed formats at this time */
1132 if (_mesa_is_compressed_format(st->ctx, internalFormat)
1133 && (bindings & ~PIPE_BIND_SAMPLER_VIEW)) {
1134 return PIPE_FORMAT_NONE;
1135 }
1136
1137 /* If we have an unsized internalFormat, and the driver supports a format
1138 * that exactly matches format/type such that we can just memcpy, pick that
1139 * (unless the format wouldn't still be unorm, which is the expectation for
1140 * unsized formats).
1141 */
1142 if (_mesa_is_enum_format_unsized(internalFormat) && format != 0 &&
1143 _mesa_is_type_unsigned(type)) {
1144 pf = st_choose_matching_format(st, bindings, format, type,
1145 swap_bytes);
1146
1147 if (pf != PIPE_FORMAT_NONE &&
1148 (!bindings || screen->is_format_supported(screen, pf, target, sample_count,
1149 storage_sample_count, bindings)) &&
1150 _mesa_get_format_base_format(st_pipe_format_to_mesa_format(pf)) ==
1151 internalFormat) {
1152 goto success;
1153 }
1154 }
1155
1156 /* For an unsized GL_RGB but a 2_10_10_10 type, try to pick one of the
1157 * 2_10_10_10 formats. This is important for
1158 * GL_EXT_texture_type_2_10_10_10_EXT support, which says that these
1159 * formats are not color-renderable. Mesa's check for making those
1160 * non-color-renderable is based on our chosen format being 2101010.
1161 */
1162 if (type == GL_UNSIGNED_INT_2_10_10_10_REV) {
1163 if (internalFormat == GL_RGB)
1164 internalFormat = GL_RGB10;
1165 else if (internalFormat == GL_RGBA)
1166 internalFormat = GL_RGB10_A2;
1167 }
1168
1169 if (type == GL_UNSIGNED_SHORT_5_5_5_1) {
1170 if (internalFormat == GL_RGB)
1171 internalFormat = GL_RGB5;
1172 else if (internalFormat == GL_RGBA)
1173 internalFormat = GL_RGB5_A1;
1174 }
1175
1176 /* search table for internalFormat */
1177 for (i = 0; i < ARRAY_SIZE(format_map); i++) {
1178 const struct format_mapping *mapping = &format_map[i];
1179 for (j = 0; mapping->glFormats[j]; j++) {
1180 if (mapping->glFormats[j] == internalFormat) {
1181 /* Found the desired internal format. Find first pipe format
1182 * which is supported by the driver.
1183 */
1184 pf = find_supported_format(screen, mapping->pipeFormats,
1185 target, sample_count,
1186 storage_sample_count, bindings,
1187 allow_dxt);
1188 goto success;
1189 }
1190 }
1191 }
1192
1193 _mesa_problem(NULL, "unhandled format!\n");
1194 return PIPE_FORMAT_NONE;
1195
1196 success:
1197 if (0) {
1198 debug_printf("%s(fmt=%s, type=%s, intFmt=%s) = %s\n",
1199 __FUNCTION__,
1200 _mesa_enum_to_string(format),
1201 _mesa_enum_to_string(type),
1202 _mesa_enum_to_string(internalFormat),
1203 util_format_name(pf));
1204 }
1205 return pf;
1206 }
1207
1208
1209 /**
1210 * Called by FBO code to choose a PIPE_FORMAT_ for drawing surfaces.
1211 */
1212 enum pipe_format
st_choose_renderbuffer_format(struct st_context * st,GLenum internalFormat,unsigned sample_count,unsigned storage_sample_count)1213 st_choose_renderbuffer_format(struct st_context *st,
1214 GLenum internalFormat, unsigned sample_count,
1215 unsigned storage_sample_count)
1216 {
1217 unsigned bindings;
1218 if (_mesa_is_depth_or_stencil_format(internalFormat))
1219 bindings = PIPE_BIND_DEPTH_STENCIL;
1220 else
1221 bindings = PIPE_BIND_RENDER_TARGET;
1222 return st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
1223 PIPE_TEXTURE_2D, sample_count,
1224 storage_sample_count, bindings,
1225 false, false);
1226 }
1227
1228
1229 /**
1230 * Given an OpenGL user-requested format and type, and swapBytes state,
1231 * return the format which exactly matches those parameters, so that
1232 * a memcpy-based transfer can be done.
1233 *
1234 * If no match format exists, return PIPE_FORMAT_NONE.
1235 */
1236 enum pipe_format
st_choose_matching_format_noverify(struct st_context * st,GLenum format,GLenum type,GLboolean swapBytes)1237 st_choose_matching_format_noverify(struct st_context *st,
1238 GLenum format, GLenum type, GLboolean swapBytes)
1239 {
1240 if (swapBytes && !_mesa_swap_bytes_in_type_enum(&type))
1241 return PIPE_FORMAT_NONE;
1242
1243 mesa_format mesa_format = _mesa_format_from_format_and_type(format, type);
1244 if (_mesa_format_is_mesa_array_format(mesa_format))
1245 mesa_format = _mesa_format_from_array_format(mesa_format);
1246 if (mesa_format != MESA_FORMAT_NONE)
1247 return st_mesa_format_to_pipe_format(st, mesa_format);
1248
1249 return PIPE_FORMAT_NONE;
1250 }
1251
1252
1253 /**
1254 * Given an OpenGL user-requested format and type, and swapBytes state,
1255 * return the format which exactly matches those parameters, so that
1256 * a memcpy-based transfer can be done.
1257 *
1258 * If no format is supported, return PIPE_FORMAT_NONE.
1259 */
1260 enum pipe_format
st_choose_matching_format(struct st_context * st,unsigned bind,GLenum format,GLenum type,GLboolean swapBytes)1261 st_choose_matching_format(struct st_context *st, unsigned bind,
1262 GLenum format, GLenum type, GLboolean swapBytes)
1263 {
1264 struct pipe_screen *screen = st->screen;
1265 enum pipe_format pformat = st_choose_matching_format_noverify(st, format, type, swapBytes);
1266 if (pformat != PIPE_FORMAT_NONE &&
1267 (!bind || screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D, 0, 0, bind)))
1268 return pformat;
1269
1270 return PIPE_FORMAT_NONE;
1271 }
1272
1273
1274 /**
1275 * Called via ctx->Driver.ChooseTextureFormat().
1276 */
1277 mesa_format
st_ChooseTextureFormat(struct gl_context * ctx,GLenum target,GLint internalFormat,GLenum format,GLenum type)1278 st_ChooseTextureFormat(struct gl_context *ctx, GLenum target,
1279 GLint internalFormat,
1280 GLenum format, GLenum type)
1281 {
1282 struct st_context *st = st_context(ctx);
1283 enum pipe_format pFormat;
1284 mesa_format mFormat;
1285 unsigned bindings;
1286 bool is_renderbuffer = false;
1287 enum pipe_texture_target pTarget;
1288
1289 if (target == GL_RENDERBUFFER) {
1290 pTarget = PIPE_TEXTURE_2D;
1291 is_renderbuffer = true;
1292 } else {
1293 pTarget = gl_target_to_pipe(target);
1294 }
1295
1296 if (target == GL_TEXTURE_1D || target == GL_TEXTURE_1D_ARRAY) {
1297 /* We don't do compression for these texture targets because of
1298 * difficulty with sub-texture updates on non-block boundaries, etc.
1299 * So change the internal format request to an uncompressed format.
1300 */
1301 internalFormat =
1302 _mesa_generic_compressed_format_to_uncompressed_format(internalFormat);
1303 }
1304
1305 /* GL textures may wind up being render targets, but we don't know
1306 * that in advance. Specify potential render target flags now for formats
1307 * that we know should always be renderable.
1308 */
1309 bindings = PIPE_BIND_SAMPLER_VIEW;
1310 if (_mesa_is_depth_or_stencil_format(internalFormat))
1311 bindings |= PIPE_BIND_DEPTH_STENCIL;
1312 else if (is_renderbuffer || internalFormat == 3 || internalFormat == 4 ||
1313 internalFormat == GL_RGB || internalFormat == GL_RGBA ||
1314 internalFormat == GL_RGBA2 ||
1315 internalFormat == GL_RGB4 || internalFormat == GL_RGBA4 ||
1316 internalFormat == GL_RGB8 || internalFormat == GL_RGBA8 ||
1317 internalFormat == GL_BGRA ||
1318 internalFormat == GL_RGB16F ||
1319 internalFormat == GL_RGBA16F ||
1320 internalFormat == GL_RGB32F ||
1321 internalFormat == GL_RGBA32F ||
1322 internalFormat == GL_RED ||
1323 internalFormat == GL_RED_SNORM ||
1324 internalFormat == GL_R8I ||
1325 internalFormat == GL_R8UI)
1326 bindings |= PIPE_BIND_RENDER_TARGET;
1327
1328 /* GLES allows the driver to choose any format which matches
1329 * the format+type combo, because GLES only supports unsized internal
1330 * formats and expects the driver to choose whatever suits it.
1331 */
1332 if (_mesa_is_gles(ctx)) {
1333 GLenum baseFormat = _mesa_base_tex_format(ctx, internalFormat);
1334 GLenum basePackFormat = _mesa_base_pack_format(format);
1335 GLenum iformat = internalFormat;
1336
1337 /* Treat GL_BGRA as GL_RGBA. */
1338 if (iformat == GL_BGRA)
1339 iformat = GL_RGBA;
1340
1341 /* Check if the internalformat is unsized and compatible
1342 * with the "format".
1343 */
1344 if (iformat == baseFormat && iformat == basePackFormat) {
1345 pFormat = st_choose_matching_format(st, bindings, format, type,
1346 ctx->Unpack.SwapBytes);
1347
1348 if (pFormat != PIPE_FORMAT_NONE)
1349 return st_pipe_format_to_mesa_format(pFormat);
1350
1351 if (!is_renderbuffer) {
1352 /* try choosing format again, this time without render
1353 * target bindings.
1354 */
1355 pFormat = st_choose_matching_format(st, PIPE_BIND_SAMPLER_VIEW,
1356 format, type,
1357 ctx->Unpack.SwapBytes);
1358 if (pFormat != PIPE_FORMAT_NONE)
1359 return st_pipe_format_to_mesa_format(pFormat);
1360 }
1361 }
1362 }
1363
1364 pFormat = st_choose_format(st, internalFormat, format, type,
1365 pTarget, 0, 0, bindings,
1366 ctx->Unpack.SwapBytes, true);
1367
1368 if (pFormat == PIPE_FORMAT_NONE && !is_renderbuffer) {
1369 /* try choosing format again, this time without render target bindings */
1370 pFormat = st_choose_format(st, internalFormat, format, type,
1371 pTarget, 0, 0, PIPE_BIND_SAMPLER_VIEW,
1372 ctx->Unpack.SwapBytes, true);
1373 }
1374
1375 if (pFormat == PIPE_FORMAT_NONE) {
1376 mFormat = _mesa_glenum_to_compressed_format(internalFormat);
1377 if (st_compressed_format_fallback(st, mFormat))
1378 return mFormat;
1379
1380 /* no luck at all */
1381 return MESA_FORMAT_NONE;
1382 }
1383
1384 mFormat = st_pipe_format_to_mesa_format(pFormat);
1385
1386 /* Debugging aid */
1387 if (0) {
1388 debug_printf("%s(intFormat=%s, format=%s, type=%s) -> %s, %s\n",
1389 __func__,
1390 _mesa_enum_to_string(internalFormat),
1391 _mesa_enum_to_string(format),
1392 _mesa_enum_to_string(type),
1393 util_format_name(pFormat),
1394 _mesa_get_format_name(mFormat));
1395 }
1396
1397 return mFormat;
1398 }
1399
1400
1401 /**
1402 * Called via ctx->Driver.QueryInternalFormat().
1403 */
1404 static size_t
st_QuerySamplesForFormat(struct gl_context * ctx,GLenum target,GLenum internalFormat,int samples[16])1405 st_QuerySamplesForFormat(struct gl_context *ctx, GLenum target,
1406 GLenum internalFormat, int samples[16])
1407 {
1408 struct st_context *st = st_context(ctx);
1409 enum pipe_format format;
1410 unsigned i, bind, num_sample_counts = 0;
1411 unsigned min_max_samples;
1412
1413 (void) target;
1414
1415 if (_mesa_is_depth_or_stencil_format(internalFormat))
1416 bind = PIPE_BIND_DEPTH_STENCIL;
1417 else
1418 bind = PIPE_BIND_RENDER_TARGET;
1419
1420 if (_mesa_is_enum_format_integer(internalFormat))
1421 min_max_samples = ctx->Const.MaxIntegerSamples;
1422 else if (_mesa_is_depth_or_stencil_format(internalFormat))
1423 min_max_samples = ctx->Const.MaxDepthTextureSamples;
1424 else
1425 min_max_samples = ctx->Const.MaxColorTextureSamples;
1426
1427 /* If an sRGB framebuffer is unsupported, sRGB formats behave like linear
1428 * formats.
1429 */
1430 if (!ctx->Extensions.EXT_sRGB) {
1431 internalFormat = _mesa_get_linear_internalformat(internalFormat);
1432 }
1433
1434 /* Set sample counts in descending order. */
1435 for (i = 16; i > 1; i--) {
1436 format = st_choose_format(st, internalFormat, GL_NONE, GL_NONE,
1437 PIPE_TEXTURE_2D, i, i, bind,
1438 false, false);
1439
1440 if (format != PIPE_FORMAT_NONE || i == min_max_samples) {
1441 samples[num_sample_counts++] = i;
1442 }
1443 }
1444
1445 if (!num_sample_counts) {
1446 samples[num_sample_counts++] = 1;
1447 }
1448
1449 return num_sample_counts;
1450 }
1451
1452
1453 /**
1454 * ARB_internalformat_query2 driver hook.
1455 */
1456 void
st_QueryInternalFormat(struct gl_context * ctx,GLenum target,GLenum internalFormat,GLenum pname,GLint * params)1457 st_QueryInternalFormat(struct gl_context *ctx, GLenum target,
1458 GLenum internalFormat, GLenum pname, GLint *params)
1459 {
1460 struct st_context *st = st_context(ctx);
1461 /* The API entry-point gives us a temporary params buffer that is non-NULL
1462 * and guaranteed to have at least 16 elements.
1463 */
1464 assert(params != NULL);
1465
1466 switch (pname) {
1467 case GL_SAMPLES:
1468 st_QuerySamplesForFormat(ctx, target, internalFormat, params);
1469 break;
1470
1471 case GL_NUM_SAMPLE_COUNTS: {
1472 int samples[16];
1473 size_t num_samples;
1474 num_samples = st_QuerySamplesForFormat(ctx, target, internalFormat,
1475 samples);
1476 params[0] = (GLint) num_samples;
1477 break;
1478 }
1479 case GL_INTERNALFORMAT_PREFERRED: {
1480 params[0] = GL_NONE;
1481
1482 /* We need to resolve an internal format that is compatible with
1483 * the passed internal format, and optimal to the driver. By now,
1484 * we just validate that the passed internal format is supported by
1485 * the driver, and if so return the same internal format, otherwise
1486 * return GL_NONE.
1487 */
1488 unsigned bindings;
1489 if (_mesa_is_depth_or_stencil_format(internalFormat))
1490 bindings = PIPE_BIND_DEPTH_STENCIL;
1491 else
1492 bindings = PIPE_BIND_RENDER_TARGET;
1493 enum pipe_format pformat = st_choose_format(st,
1494 internalFormat,
1495 GL_NONE,
1496 GL_NONE,
1497 PIPE_TEXTURE_2D, 0, 0,
1498 bindings,
1499 false, false);
1500 if (pformat)
1501 params[0] = internalFormat;
1502 break;
1503 }
1504 case GL_TEXTURE_REDUCTION_MODE_ARB: {
1505 mesa_format format = st_ChooseTextureFormat(ctx, target, internalFormat, GL_NONE, GL_NONE);
1506 enum pipe_format pformat = st_mesa_format_to_pipe_format(st, format);
1507 struct pipe_screen *screen = st->screen;
1508 params[0] = pformat != PIPE_FORMAT_NONE &&
1509 screen->is_format_supported(screen, pformat, PIPE_TEXTURE_2D,
1510 0, 0, PIPE_BIND_SAMPLER_REDUCTION_MINMAX);
1511 break;
1512 }
1513 default:
1514 /* For the rest of the pnames, we call back the Mesa's default
1515 * function for drivers that don't implement ARB_internalformat_query2.
1516 */
1517 _mesa_query_internal_format_default(ctx, target, internalFormat, pname,
1518 params);
1519 }
1520 }
1521
1522
1523 /**
1524 * This is used for translating texture border color and the clear
1525 * color. For example, the clear color is interpreted according to
1526 * the renderbuffer's base format. For example, if clearing a
1527 * GL_LUMINANCE buffer, we'll return colorOut[0] = colorOut[1] =
1528 * colorOut[2] = colorIn[0].
1529 * Similarly for texture border colors.
1530 */
1531 void
st_translate_color(union pipe_color_union * color,GLenum baseFormat,GLboolean is_integer)1532 st_translate_color(union pipe_color_union *color,
1533 GLenum baseFormat, GLboolean is_integer)
1534 {
1535 if (is_integer) {
1536 int *ci = color->i;
1537
1538 switch (baseFormat) {
1539 case GL_RED:
1540 ci[1] = 0;
1541 ci[2] = 0;
1542 ci[3] = 1;
1543 break;
1544 case GL_RG:
1545 ci[2] = 0;
1546 ci[3] = 1;
1547 break;
1548 case GL_RGB:
1549 ci[3] = 1;
1550 break;
1551 case GL_ALPHA:
1552 ci[0] = ci[1] = ci[2] = 0;
1553 break;
1554 case GL_LUMINANCE:
1555 ci[1] = ci[2] = ci[0];
1556 ci[3] = 1;
1557 break;
1558 case GL_LUMINANCE_ALPHA:
1559 ci[1] = ci[2] = ci[0];
1560 break;
1561 case GL_INTENSITY:
1562 ci[1] = ci[2] = ci[3] = ci[0];
1563 break;
1564 }
1565 }
1566 else {
1567 float *cf = color->f;
1568
1569 switch (baseFormat) {
1570 case GL_RED:
1571 cf[1] = 0.0F;
1572 cf[2] = 0.0F;
1573 cf[3] = 1.0F;
1574 break;
1575 case GL_RG:
1576 cf[2] = 0.0F;
1577 cf[3] = 1.0F;
1578 break;
1579 case GL_RGB:
1580 cf[3] = 1.0F;
1581 break;
1582 case GL_ALPHA:
1583 cf[0] = cf[1] = cf[2] = 0.0F;
1584 break;
1585 case GL_LUMINANCE:
1586 cf[1] = cf[2] = cf[0];
1587 cf[3] = 1.0F;
1588 break;
1589 case GL_LUMINANCE_ALPHA:
1590 cf[1] = cf[2] = cf[0];
1591 break;
1592 /* Stencil border is tricky on some hw. Help drivers a little here. */
1593 case GL_STENCIL_INDEX:
1594 case GL_INTENSITY:
1595 cf[1] = cf[2] = cf[3] = cf[0];
1596 break;
1597 }
1598 }
1599 }
1600