Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5564 | serge | 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 | #include "imports.h" |
||
28 | #include "formats.h" |
||
29 | #include "macros.h" |
||
30 | #include "glformats.h" |
||
31 | #include "c11/threads.h" |
||
32 | #include "util/hash_table.h" |
||
33 | |||
34 | /** |
||
35 | * Information about texture formats. |
||
36 | */ |
||
37 | struct gl_format_info |
||
38 | { |
||
39 | mesa_format Name; |
||
40 | |||
41 | /** text name for debugging */ |
||
42 | const char *StrName; |
||
43 | |||
44 | enum mesa_format_layout Layout; |
||
45 | |||
46 | /** |
||
47 | * Base format is one of GL_RED, GL_RG, GL_RGB, GL_RGBA, GL_ALPHA, |
||
48 | * GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, GL_YCBCR_MESA, |
||
49 | * GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL. |
||
50 | */ |
||
51 | GLenum BaseFormat; |
||
52 | |||
53 | /** |
||
54 | * Logical data type: one of GL_UNSIGNED_NORMALIZED, GL_SIGNED_NORMALIZED, |
||
55 | * GL_UNSIGNED_INT, GL_INT, GL_FLOAT. |
||
56 | */ |
||
57 | GLenum DataType; |
||
58 | |||
59 | GLubyte RedBits; |
||
60 | GLubyte GreenBits; |
||
61 | GLubyte BlueBits; |
||
62 | GLubyte AlphaBits; |
||
63 | GLubyte LuminanceBits; |
||
64 | GLubyte IntensityBits; |
||
65 | GLubyte DepthBits; |
||
66 | GLubyte StencilBits; |
||
67 | |||
68 | /** |
||
69 | * To describe compressed formats. If not compressed, Width=Height=1. |
||
70 | */ |
||
71 | GLubyte BlockWidth, BlockHeight; |
||
72 | GLubyte BytesPerBlock; |
||
73 | |||
74 | uint8_t Swizzle[4]; |
||
75 | mesa_array_format ArrayFormat; |
||
76 | }; |
||
77 | |||
78 | #include "format_info.h" |
||
79 | |||
80 | static const struct gl_format_info * |
||
81 | _mesa_get_format_info(mesa_format format) |
||
82 | { |
||
83 | const struct gl_format_info *info = &format_info[format]; |
||
84 | assert(info->Name == format); |
||
85 | return info; |
||
86 | } |
||
87 | |||
88 | |||
89 | /** Return string name of format (for debugging) */ |
||
90 | const char * |
||
91 | _mesa_get_format_name(mesa_format format) |
||
92 | { |
||
93 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
94 | return info->StrName; |
||
95 | } |
||
96 | |||
97 | |||
98 | |||
99 | /** |
||
100 | * Return bytes needed to store a block of pixels in the given format. |
||
101 | * Normally, a block is 1x1 (a single pixel). But for compressed formats |
||
102 | * a block may be 4x4 or 8x4, etc. |
||
103 | * |
||
104 | * Note: not GLuint, so as not to coerce math to unsigned. cf. fdo #37351 |
||
105 | */ |
||
106 | GLint |
||
107 | _mesa_get_format_bytes(mesa_format format) |
||
108 | { |
||
109 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
110 | assert(info->BytesPerBlock); |
||
111 | assert(info->BytesPerBlock <= MAX_PIXEL_BYTES || |
||
112 | _mesa_is_format_compressed(format)); |
||
113 | return info->BytesPerBlock; |
||
114 | } |
||
115 | |||
116 | |||
117 | /** |
||
118 | * Return bits per component for the given format. |
||
119 | * \param format one of MESA_FORMAT_x |
||
120 | * \param pname the component, such as GL_RED_BITS, GL_TEXTURE_BLUE_BITS, etc. |
||
121 | */ |
||
122 | GLint |
||
123 | _mesa_get_format_bits(mesa_format format, GLenum pname) |
||
124 | { |
||
125 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
126 | |||
127 | switch (pname) { |
||
128 | case GL_RED_BITS: |
||
129 | case GL_TEXTURE_RED_SIZE: |
||
130 | case GL_RENDERBUFFER_RED_SIZE_EXT: |
||
131 | case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE: |
||
132 | return info->RedBits; |
||
133 | case GL_GREEN_BITS: |
||
134 | case GL_TEXTURE_GREEN_SIZE: |
||
135 | case GL_RENDERBUFFER_GREEN_SIZE_EXT: |
||
136 | case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE: |
||
137 | return info->GreenBits; |
||
138 | case GL_BLUE_BITS: |
||
139 | case GL_TEXTURE_BLUE_SIZE: |
||
140 | case GL_RENDERBUFFER_BLUE_SIZE_EXT: |
||
141 | case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE: |
||
142 | return info->BlueBits; |
||
143 | case GL_ALPHA_BITS: |
||
144 | case GL_TEXTURE_ALPHA_SIZE: |
||
145 | case GL_RENDERBUFFER_ALPHA_SIZE_EXT: |
||
146 | case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE: |
||
147 | return info->AlphaBits; |
||
148 | case GL_TEXTURE_INTENSITY_SIZE: |
||
149 | return info->IntensityBits; |
||
150 | case GL_TEXTURE_LUMINANCE_SIZE: |
||
151 | return info->LuminanceBits; |
||
152 | case GL_INDEX_BITS: |
||
153 | return 0; |
||
154 | case GL_DEPTH_BITS: |
||
155 | case GL_TEXTURE_DEPTH_SIZE_ARB: |
||
156 | case GL_RENDERBUFFER_DEPTH_SIZE_EXT: |
||
157 | case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE: |
||
158 | return info->DepthBits; |
||
159 | case GL_STENCIL_BITS: |
||
160 | case GL_TEXTURE_STENCIL_SIZE_EXT: |
||
161 | case GL_RENDERBUFFER_STENCIL_SIZE_EXT: |
||
162 | case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE: |
||
163 | return info->StencilBits; |
||
164 | default: |
||
165 | _mesa_problem(NULL, "bad pname in _mesa_get_format_bits()"); |
||
166 | return 0; |
||
167 | } |
||
168 | } |
||
169 | |||
170 | |||
171 | GLuint |
||
172 | _mesa_get_format_max_bits(mesa_format format) |
||
173 | { |
||
174 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
175 | GLuint max = MAX2(info->RedBits, info->GreenBits); |
||
176 | max = MAX2(max, info->BlueBits); |
||
177 | max = MAX2(max, info->AlphaBits); |
||
178 | max = MAX2(max, info->LuminanceBits); |
||
179 | max = MAX2(max, info->IntensityBits); |
||
180 | max = MAX2(max, info->DepthBits); |
||
181 | max = MAX2(max, info->StencilBits); |
||
182 | return max; |
||
183 | } |
||
184 | |||
185 | |||
186 | /** |
||
187 | * Return the layout type of the given format. |
||
188 | * The return value will be one of: |
||
189 | * MESA_FORMAT_LAYOUT_ARRAY |
||
190 | * MESA_FORMAT_LAYOUT_PACKED |
||
191 | * MESA_FORMAT_LAYOUT_OTHER |
||
192 | */ |
||
193 | extern enum mesa_format_layout |
||
194 | _mesa_get_format_layout(mesa_format format) |
||
195 | { |
||
196 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
197 | return info->Layout; |
||
198 | } |
||
199 | |||
200 | |||
201 | /** |
||
202 | * Return the data type (or more specifically, the data representation) |
||
203 | * for the given format. |
||
204 | * The return value will be one of: |
||
205 | * GL_UNSIGNED_NORMALIZED = unsigned int representing [0,1] |
||
206 | * GL_SIGNED_NORMALIZED = signed int representing [-1, 1] |
||
207 | * GL_UNSIGNED_INT = an ordinary unsigned integer |
||
208 | * GL_INT = an ordinary signed integer |
||
209 | * GL_FLOAT = an ordinary float |
||
210 | */ |
||
211 | GLenum |
||
212 | _mesa_get_format_datatype(mesa_format format) |
||
213 | { |
||
214 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
215 | return info->DataType; |
||
216 | } |
||
217 | |||
218 | static GLenum |
||
219 | get_base_format_for_array_format(mesa_array_format format) |
||
220 | { |
||
221 | uint8_t swizzle[4]; |
||
222 | int num_channels; |
||
223 | |||
224 | _mesa_array_format_get_swizzle(format, swizzle); |
||
225 | num_channels = _mesa_array_format_get_num_channels(format); |
||
226 | |||
227 | switch (num_channels) { |
||
228 | case 4: |
||
229 | /* FIXME: RGBX formats have 4 channels, but their base format is GL_RGB. |
||
230 | * This is not really a problem for now because we only create array |
||
231 | * formats from GL format/type combinations, and these cannot specify |
||
232 | * RGBX formats. |
||
233 | */ |
||
234 | return GL_RGBA; |
||
235 | case 3: |
||
236 | return GL_RGB; |
||
237 | case 2: |
||
238 | if (swizzle[0] == 0 && |
||
239 | swizzle[1] == 0 && |
||
240 | swizzle[2] == 0 && |
||
241 | swizzle[3] == 1) |
||
242 | return GL_LUMINANCE_ALPHA; |
||
243 | if (swizzle[0] == 1 && |
||
244 | swizzle[1] == 1 && |
||
245 | swizzle[2] == 1 && |
||
246 | swizzle[3] == 0) |
||
247 | return GL_LUMINANCE_ALPHA; |
||
248 | if (swizzle[0] == 0 && |
||
249 | swizzle[1] == 1 && |
||
250 | swizzle[2] == 4 && |
||
251 | swizzle[3] == 5) |
||
252 | return GL_RG; |
||
253 | if (swizzle[0] == 1 && |
||
254 | swizzle[1] == 0 && |
||
255 | swizzle[2] == 4 && |
||
256 | swizzle[3] == 5) |
||
257 | return GL_RG; |
||
258 | break; |
||
259 | case 1: |
||
260 | if (swizzle[0] == 0 && |
||
261 | swizzle[1] == 0 && |
||
262 | swizzle[2] == 0 && |
||
263 | swizzle[3] == 5) |
||
264 | return GL_LUMINANCE; |
||
265 | if (swizzle[0] == 0 && |
||
266 | swizzle[1] == 0 && |
||
267 | swizzle[2] == 0 && |
||
268 | swizzle[3] == 0) |
||
269 | return GL_INTENSITY; |
||
270 | if (swizzle[0] <= MESA_FORMAT_SWIZZLE_W) |
||
271 | return GL_RED; |
||
272 | if (swizzle[1] <= MESA_FORMAT_SWIZZLE_W) |
||
273 | return GL_GREEN; |
||
274 | if (swizzle[2] <= MESA_FORMAT_SWIZZLE_W) |
||
275 | return GL_BLUE; |
||
276 | if (swizzle[3] <= MESA_FORMAT_SWIZZLE_W) |
||
277 | return GL_ALPHA; |
||
278 | break; |
||
279 | } |
||
280 | |||
281 | unreachable("Unsupported format"); |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * Return the basic format for the given type. The result will be one of |
||
286 | * GL_RGB, GL_RGBA, GL_ALPHA, GL_LUMINANCE, GL_LUMINANCE_ALPHA, GL_INTENSITY, |
||
287 | * GL_YCBCR_MESA, GL_DEPTH_COMPONENT, GL_STENCIL_INDEX, GL_DEPTH_STENCIL. |
||
288 | * This functions accepts a mesa_format or a mesa_array_format. |
||
289 | */ |
||
290 | GLenum |
||
291 | _mesa_get_format_base_format(uint32_t format) |
||
292 | { |
||
293 | if (!_mesa_format_is_mesa_array_format(format)) { |
||
294 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
295 | return info->BaseFormat; |
||
296 | } else { |
||
297 | return get_base_format_for_array_format(format); |
||
298 | } |
||
299 | } |
||
300 | |||
301 | |||
302 | /** |
||
303 | * Return the block size (in pixels) for the given format. Normally |
||
304 | * the block size is 1x1. But compressed formats will have block sizes |
||
305 | * of 4x4 or 8x4 pixels, etc. |
||
306 | * \param bw returns block width in pixels |
||
307 | * \param bh returns block height in pixels |
||
308 | */ |
||
309 | void |
||
310 | _mesa_get_format_block_size(mesa_format format, GLuint *bw, GLuint *bh) |
||
311 | { |
||
312 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
313 | *bw = info->BlockWidth; |
||
314 | *bh = info->BlockHeight; |
||
315 | } |
||
316 | |||
317 | |||
318 | /** |
||
319 | * Returns the an array of four numbers representing the transformation |
||
320 | * from the RGBA or SZ colorspace to the given format. For array formats, |
||
321 | * the i'th RGBA component is given by: |
||
322 | * |
||
323 | * if (swizzle[i] <= MESA_FORMAT_SWIZZLE_W) |
||
324 | * comp = data[swizzle[i]]; |
||
325 | * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ZERO) |
||
326 | * comp = 0; |
||
327 | * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_ONE) |
||
328 | * comp = 1; |
||
329 | * else if (swizzle[i] == MESA_FORMAT_SWIZZLE_NONE) |
||
330 | * // data does not contain a channel of this format |
||
331 | * |
||
332 | * For packed formats, the swizzle gives the number of components left of |
||
333 | * the least significant bit. |
||
334 | * |
||
335 | * Compressed formats have no swizzle. |
||
336 | */ |
||
337 | void |
||
338 | _mesa_get_format_swizzle(mesa_format format, uint8_t swizzle_out[4]) |
||
339 | { |
||
340 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
341 | memcpy(swizzle_out, info->Swizzle, sizeof(info->Swizzle)); |
||
342 | } |
||
343 | |||
344 | mesa_array_format |
||
345 | _mesa_array_format_flip_channels(mesa_array_format format) |
||
346 | { |
||
347 | int num_channels; |
||
348 | uint8_t swizzle[4]; |
||
349 | |||
350 | num_channels = _mesa_array_format_get_num_channels(format); |
||
351 | _mesa_array_format_get_swizzle(format, swizzle); |
||
352 | |||
353 | if (num_channels == 1) |
||
354 | return format; |
||
355 | |||
356 | if (num_channels == 2) { |
||
357 | _mesa_array_format_set_swizzle(&format, swizzle[1], swizzle[0], |
||
358 | swizzle[2], swizzle[3]); |
||
359 | return format; |
||
360 | } |
||
361 | |||
362 | if (num_channels == 4) { |
||
363 | _mesa_array_format_set_swizzle(&format, swizzle[3], swizzle[2], |
||
364 | swizzle[1], swizzle[0]); |
||
365 | return format; |
||
366 | } |
||
367 | |||
368 | unreachable("Invalid array format"); |
||
369 | } |
||
370 | |||
371 | uint32_t |
||
372 | _mesa_format_to_array_format(mesa_format format) |
||
373 | { |
||
374 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
375 | if (_mesa_little_endian()) |
||
376 | return info->ArrayFormat; |
||
377 | else |
||
378 | return _mesa_array_format_flip_channels(info->ArrayFormat); |
||
379 | } |
||
380 | |||
381 | static struct hash_table *format_array_format_table; |
||
382 | static once_flag format_array_format_table_exists = ONCE_FLAG_INIT; |
||
383 | |||
384 | static bool |
||
385 | array_formats_equal(const void *a, const void *b) |
||
386 | { |
||
387 | return (intptr_t)a == (intptr_t)b; |
||
388 | } |
||
389 | |||
390 | static void |
||
391 | format_array_format_table_init(void) |
||
392 | { |
||
393 | const struct gl_format_info *info; |
||
394 | mesa_array_format array_format; |
||
395 | unsigned f; |
||
396 | |||
397 | format_array_format_table = _mesa_hash_table_create(NULL, NULL, |
||
398 | array_formats_equal); |
||
399 | |||
400 | for (f = 1; f < MESA_FORMAT_COUNT; ++f) { |
||
401 | info = _mesa_get_format_info(f); |
||
402 | if (!info->ArrayFormat) |
||
403 | continue; |
||
404 | |||
405 | if (_mesa_little_endian()) { |
||
406 | array_format = info->ArrayFormat; |
||
407 | } else { |
||
408 | array_format = _mesa_array_format_flip_channels(info->ArrayFormat); |
||
409 | } |
||
410 | |||
411 | /* This can happen and does for some of the BGR formats. Let's take |
||
412 | * the first one in the list. |
||
413 | */ |
||
414 | if (_mesa_hash_table_search_pre_hashed(format_array_format_table, |
||
415 | array_format, |
||
416 | (void *)(intptr_t)array_format)) |
||
417 | continue; |
||
418 | |||
419 | _mesa_hash_table_insert_pre_hashed(format_array_format_table, |
||
420 | array_format, |
||
421 | (void *)(intptr_t)array_format, |
||
422 | (void *)(intptr_t)f); |
||
423 | } |
||
424 | } |
||
425 | |||
426 | mesa_format |
||
427 | _mesa_format_from_array_format(uint32_t array_format) |
||
428 | { |
||
429 | struct hash_entry *entry; |
||
430 | |||
431 | assert(_mesa_format_is_mesa_array_format(array_format)); |
||
432 | |||
433 | call_once(&format_array_format_table_exists, format_array_format_table_init); |
||
434 | |||
435 | entry = _mesa_hash_table_search_pre_hashed(format_array_format_table, |
||
436 | array_format, |
||
437 | (void *)(intptr_t)array_format); |
||
438 | if (entry) |
||
439 | return (intptr_t)entry->data; |
||
440 | else |
||
441 | return MESA_FORMAT_NONE; |
||
442 | } |
||
443 | |||
444 | /** Is the given format a compressed format? */ |
||
445 | GLboolean |
||
446 | _mesa_is_format_compressed(mesa_format format) |
||
447 | { |
||
448 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
449 | return info->BlockWidth > 1 || info->BlockHeight > 1; |
||
450 | } |
||
451 | |||
452 | |||
453 | /** |
||
454 | * Determine if the given format represents a packed depth/stencil buffer. |
||
455 | */ |
||
456 | GLboolean |
||
457 | _mesa_is_format_packed_depth_stencil(mesa_format format) |
||
458 | { |
||
459 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
460 | |||
461 | return info->BaseFormat == GL_DEPTH_STENCIL; |
||
462 | } |
||
463 | |||
464 | |||
465 | /** |
||
466 | * Is the given format a signed/unsigned integer color format? |
||
467 | */ |
||
468 | GLboolean |
||
469 | _mesa_is_format_integer_color(mesa_format format) |
||
470 | { |
||
471 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
472 | return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT) && |
||
473 | info->BaseFormat != GL_DEPTH_COMPONENT && |
||
474 | info->BaseFormat != GL_DEPTH_STENCIL && |
||
475 | info->BaseFormat != GL_STENCIL_INDEX; |
||
476 | } |
||
477 | |||
478 | |||
479 | /** |
||
480 | * Is the given format an unsigned integer format? |
||
481 | */ |
||
482 | GLboolean |
||
483 | _mesa_is_format_unsigned(mesa_format format) |
||
484 | { |
||
485 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
486 | return _mesa_is_type_unsigned(info->DataType); |
||
487 | } |
||
488 | |||
489 | |||
490 | /** |
||
491 | * Does the given format store signed values? |
||
492 | */ |
||
493 | GLboolean |
||
494 | _mesa_is_format_signed(mesa_format format) |
||
495 | { |
||
496 | if (format == MESA_FORMAT_R11G11B10_FLOAT || |
||
497 | format == MESA_FORMAT_R9G9B9E5_FLOAT) { |
||
498 | /* these packed float formats only store unsigned values */ |
||
499 | return GL_FALSE; |
||
500 | } |
||
501 | else { |
||
502 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
503 | return (info->DataType == GL_SIGNED_NORMALIZED || |
||
504 | info->DataType == GL_INT || |
||
505 | info->DataType == GL_FLOAT); |
||
506 | } |
||
507 | } |
||
508 | |||
509 | /** |
||
510 | * Is the given format an integer format? |
||
511 | */ |
||
512 | GLboolean |
||
513 | _mesa_is_format_integer(mesa_format format) |
||
514 | { |
||
515 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
516 | return (info->DataType == GL_INT || info->DataType == GL_UNSIGNED_INT); |
||
517 | } |
||
518 | |||
519 | |||
520 | /** |
||
521 | * Return true if the given format is a color format. |
||
522 | */ |
||
523 | GLenum |
||
524 | _mesa_is_format_color_format(mesa_format format) |
||
525 | { |
||
526 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
527 | switch (info->BaseFormat) { |
||
528 | case GL_DEPTH_COMPONENT: |
||
529 | case GL_STENCIL_INDEX: |
||
530 | case GL_DEPTH_STENCIL: |
||
531 | return false; |
||
532 | default: |
||
533 | return true; |
||
534 | } |
||
535 | } |
||
536 | |||
537 | |||
538 | /** |
||
539 | * Return color encoding for given format. |
||
540 | * \return GL_LINEAR or GL_SRGB |
||
541 | */ |
||
542 | GLenum |
||
543 | _mesa_get_format_color_encoding(mesa_format format) |
||
544 | { |
||
545 | /* XXX this info should be encoded in gl_format_info */ |
||
546 | switch (format) { |
||
547 | case MESA_FORMAT_BGR_SRGB8: |
||
548 | case MESA_FORMAT_A8B8G8R8_SRGB: |
||
549 | case MESA_FORMAT_B8G8R8A8_SRGB: |
||
550 | case MESA_FORMAT_A8R8G8B8_SRGB: |
||
551 | case MESA_FORMAT_R8G8B8A8_SRGB: |
||
552 | case MESA_FORMAT_L_SRGB8: |
||
553 | case MESA_FORMAT_L8A8_SRGB: |
||
554 | case MESA_FORMAT_A8L8_SRGB: |
||
555 | case MESA_FORMAT_SRGB_DXT1: |
||
556 | case MESA_FORMAT_SRGBA_DXT1: |
||
557 | case MESA_FORMAT_SRGBA_DXT3: |
||
558 | case MESA_FORMAT_SRGBA_DXT5: |
||
559 | case MESA_FORMAT_R8G8B8X8_SRGB: |
||
560 | case MESA_FORMAT_ETC2_SRGB8: |
||
561 | case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: |
||
562 | case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: |
||
563 | case MESA_FORMAT_B8G8R8X8_SRGB: |
||
564 | case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM: |
||
565 | return GL_SRGB; |
||
566 | default: |
||
567 | return GL_LINEAR; |
||
568 | } |
||
569 | } |
||
570 | |||
571 | |||
572 | /** |
||
573 | * Return TRUE if format is an ETC2 compressed format specified |
||
574 | * by GL_ARB_ES3_compatibility. |
||
575 | */ |
||
576 | bool |
||
577 | _mesa_is_format_etc2(mesa_format format) |
||
578 | { |
||
579 | switch (format) { |
||
580 | case MESA_FORMAT_ETC2_RGB8: |
||
581 | case MESA_FORMAT_ETC2_SRGB8: |
||
582 | case MESA_FORMAT_ETC2_RGBA8_EAC: |
||
583 | case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: |
||
584 | case MESA_FORMAT_ETC2_R11_EAC: |
||
585 | case MESA_FORMAT_ETC2_RG11_EAC: |
||
586 | case MESA_FORMAT_ETC2_SIGNED_R11_EAC: |
||
587 | case MESA_FORMAT_ETC2_SIGNED_RG11_EAC: |
||
588 | case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: |
||
589 | case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: |
||
590 | return GL_TRUE; |
||
591 | default: |
||
592 | return GL_FALSE; |
||
593 | } |
||
594 | } |
||
595 | |||
596 | |||
597 | /** |
||
598 | * For an sRGB format, return the corresponding linear color space format. |
||
599 | * For non-sRGB formats, return the format as-is. |
||
600 | */ |
||
601 | mesa_format |
||
602 | _mesa_get_srgb_format_linear(mesa_format format) |
||
603 | { |
||
604 | switch (format) { |
||
605 | case MESA_FORMAT_BGR_SRGB8: |
||
606 | format = MESA_FORMAT_BGR_UNORM8; |
||
607 | break; |
||
608 | case MESA_FORMAT_A8B8G8R8_SRGB: |
||
609 | format = MESA_FORMAT_A8B8G8R8_UNORM; |
||
610 | break; |
||
611 | case MESA_FORMAT_B8G8R8A8_SRGB: |
||
612 | format = MESA_FORMAT_B8G8R8A8_UNORM; |
||
613 | break; |
||
614 | case MESA_FORMAT_A8R8G8B8_SRGB: |
||
615 | format = MESA_FORMAT_A8R8G8B8_UNORM; |
||
616 | break; |
||
617 | case MESA_FORMAT_R8G8B8A8_SRGB: |
||
618 | format = MESA_FORMAT_R8G8B8A8_UNORM; |
||
619 | break; |
||
620 | case MESA_FORMAT_L_SRGB8: |
||
621 | format = MESA_FORMAT_L_UNORM8; |
||
622 | break; |
||
623 | case MESA_FORMAT_L8A8_SRGB: |
||
624 | format = MESA_FORMAT_L8A8_UNORM; |
||
625 | break; |
||
626 | case MESA_FORMAT_A8L8_SRGB: |
||
627 | format = MESA_FORMAT_A8L8_UNORM; |
||
628 | break; |
||
629 | case MESA_FORMAT_SRGB_DXT1: |
||
630 | format = MESA_FORMAT_RGB_DXT1; |
||
631 | break; |
||
632 | case MESA_FORMAT_SRGBA_DXT1: |
||
633 | format = MESA_FORMAT_RGBA_DXT1; |
||
634 | break; |
||
635 | case MESA_FORMAT_SRGBA_DXT3: |
||
636 | format = MESA_FORMAT_RGBA_DXT3; |
||
637 | break; |
||
638 | case MESA_FORMAT_SRGBA_DXT5: |
||
639 | format = MESA_FORMAT_RGBA_DXT5; |
||
640 | break; |
||
641 | case MESA_FORMAT_R8G8B8X8_SRGB: |
||
642 | format = MESA_FORMAT_R8G8B8X8_UNORM; |
||
643 | break; |
||
644 | case MESA_FORMAT_X8B8G8R8_SRGB: |
||
645 | format = MESA_FORMAT_X8B8G8R8_UNORM; |
||
646 | break; |
||
647 | case MESA_FORMAT_ETC2_SRGB8: |
||
648 | format = MESA_FORMAT_ETC2_RGB8; |
||
649 | break; |
||
650 | case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: |
||
651 | format = MESA_FORMAT_ETC2_RGBA8_EAC; |
||
652 | break; |
||
653 | case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: |
||
654 | format = MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1; |
||
655 | break; |
||
656 | case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM: |
||
657 | format = MESA_FORMAT_BPTC_RGBA_UNORM; |
||
658 | break; |
||
659 | case MESA_FORMAT_B8G8R8X8_SRGB: |
||
660 | format = MESA_FORMAT_B8G8R8X8_UNORM; |
||
661 | break; |
||
662 | case MESA_FORMAT_X8R8G8B8_SRGB: |
||
663 | format = MESA_FORMAT_X8R8G8B8_UNORM; |
||
664 | break; |
||
665 | default: |
||
666 | break; |
||
667 | } |
||
668 | return format; |
||
669 | } |
||
670 | |||
671 | |||
672 | /** |
||
673 | * If the given format is a compressed format, return a corresponding |
||
674 | * uncompressed format. |
||
675 | */ |
||
676 | mesa_format |
||
677 | _mesa_get_uncompressed_format(mesa_format format) |
||
678 | { |
||
679 | switch (format) { |
||
680 | case MESA_FORMAT_RGB_FXT1: |
||
681 | return MESA_FORMAT_BGR_UNORM8; |
||
682 | case MESA_FORMAT_RGBA_FXT1: |
||
683 | return MESA_FORMAT_A8B8G8R8_UNORM; |
||
684 | case MESA_FORMAT_RGB_DXT1: |
||
685 | case MESA_FORMAT_SRGB_DXT1: |
||
686 | return MESA_FORMAT_BGR_UNORM8; |
||
687 | case MESA_FORMAT_RGBA_DXT1: |
||
688 | case MESA_FORMAT_SRGBA_DXT1: |
||
689 | return MESA_FORMAT_A8B8G8R8_UNORM; |
||
690 | case MESA_FORMAT_RGBA_DXT3: |
||
691 | case MESA_FORMAT_SRGBA_DXT3: |
||
692 | return MESA_FORMAT_A8B8G8R8_UNORM; |
||
693 | case MESA_FORMAT_RGBA_DXT5: |
||
694 | case MESA_FORMAT_SRGBA_DXT5: |
||
695 | return MESA_FORMAT_A8B8G8R8_UNORM; |
||
696 | case MESA_FORMAT_R_RGTC1_UNORM: |
||
697 | return MESA_FORMAT_R_UNORM8; |
||
698 | case MESA_FORMAT_R_RGTC1_SNORM: |
||
699 | return MESA_FORMAT_R_SNORM8; |
||
700 | case MESA_FORMAT_RG_RGTC2_UNORM: |
||
701 | return MESA_FORMAT_R8G8_UNORM; |
||
702 | case MESA_FORMAT_RG_RGTC2_SNORM: |
||
703 | return MESA_FORMAT_R8G8_SNORM; |
||
704 | case MESA_FORMAT_L_LATC1_UNORM: |
||
705 | return MESA_FORMAT_L_UNORM8; |
||
706 | case MESA_FORMAT_L_LATC1_SNORM: |
||
707 | return MESA_FORMAT_L_SNORM8; |
||
708 | case MESA_FORMAT_LA_LATC2_UNORM: |
||
709 | return MESA_FORMAT_L8A8_UNORM; |
||
710 | case MESA_FORMAT_LA_LATC2_SNORM: |
||
711 | return MESA_FORMAT_L8A8_SNORM; |
||
712 | case MESA_FORMAT_ETC1_RGB8: |
||
713 | case MESA_FORMAT_ETC2_RGB8: |
||
714 | case MESA_FORMAT_ETC2_SRGB8: |
||
715 | return MESA_FORMAT_BGR_UNORM8; |
||
716 | case MESA_FORMAT_ETC2_RGBA8_EAC: |
||
717 | case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: |
||
718 | case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: |
||
719 | case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: |
||
720 | return MESA_FORMAT_A8B8G8R8_UNORM; |
||
721 | case MESA_FORMAT_ETC2_R11_EAC: |
||
722 | case MESA_FORMAT_ETC2_SIGNED_R11_EAC: |
||
723 | return MESA_FORMAT_R_UNORM16; |
||
724 | case MESA_FORMAT_ETC2_RG11_EAC: |
||
725 | case MESA_FORMAT_ETC2_SIGNED_RG11_EAC: |
||
726 | return MESA_FORMAT_R16G16_UNORM; |
||
727 | case MESA_FORMAT_BPTC_RGBA_UNORM: |
||
728 | case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM: |
||
729 | return MESA_FORMAT_A8B8G8R8_UNORM; |
||
730 | case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT: |
||
731 | case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT: |
||
732 | return MESA_FORMAT_RGB_FLOAT32; |
||
733 | default: |
||
734 | #ifdef DEBUG |
||
735 | assert(!_mesa_is_format_compressed(format)); |
||
736 | #endif |
||
737 | return format; |
||
738 | } |
||
739 | } |
||
740 | |||
741 | |||
742 | GLuint |
||
743 | _mesa_format_num_components(mesa_format format) |
||
744 | { |
||
745 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
746 | return ((info->RedBits > 0) + |
||
747 | (info->GreenBits > 0) + |
||
748 | (info->BlueBits > 0) + |
||
749 | (info->AlphaBits > 0) + |
||
750 | (info->LuminanceBits > 0) + |
||
751 | (info->IntensityBits > 0) + |
||
752 | (info->DepthBits > 0) + |
||
753 | (info->StencilBits > 0)); |
||
754 | } |
||
755 | |||
756 | |||
757 | /** |
||
758 | * Returns true if a color format has data stored in the R/G/B/A channels, |
||
759 | * given an index from 0 to 3. |
||
760 | */ |
||
761 | bool |
||
762 | _mesa_format_has_color_component(mesa_format format, int component) |
||
763 | { |
||
764 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
765 | |||
766 | assert(info->BaseFormat != GL_DEPTH_COMPONENT && |
||
767 | info->BaseFormat != GL_DEPTH_STENCIL && |
||
768 | info->BaseFormat != GL_STENCIL_INDEX); |
||
769 | |||
770 | switch (component) { |
||
771 | case 0: |
||
772 | return (info->RedBits + info->IntensityBits + info->LuminanceBits) > 0; |
||
773 | case 1: |
||
774 | return (info->GreenBits + info->IntensityBits + info->LuminanceBits) > 0; |
||
775 | case 2: |
||
776 | return (info->BlueBits + info->IntensityBits + info->LuminanceBits) > 0; |
||
777 | case 3: |
||
778 | return (info->AlphaBits + info->IntensityBits) > 0; |
||
779 | default: |
||
780 | assert(!"Invalid color component: must be 0..3"); |
||
781 | return false; |
||
782 | } |
||
783 | } |
||
784 | |||
785 | |||
786 | /** |
||
787 | * Return number of bytes needed to store an image of the given size |
||
788 | * in the given format. |
||
789 | */ |
||
790 | GLuint |
||
791 | _mesa_format_image_size(mesa_format format, GLsizei width, |
||
792 | GLsizei height, GLsizei depth) |
||
793 | { |
||
794 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
795 | /* Strictly speaking, a conditional isn't needed here */ |
||
796 | if (info->BlockWidth > 1 || info->BlockHeight > 1) { |
||
797 | /* compressed format (2D only for now) */ |
||
798 | const GLuint bw = info->BlockWidth, bh = info->BlockHeight; |
||
799 | const GLuint wblocks = (width + bw - 1) / bw; |
||
800 | const GLuint hblocks = (height + bh - 1) / bh; |
||
801 | const GLuint sz = wblocks * hblocks * info->BytesPerBlock; |
||
802 | return sz * depth; |
||
803 | } |
||
804 | else { |
||
805 | /* non-compressed */ |
||
806 | const GLuint sz = width * height * depth * info->BytesPerBlock; |
||
807 | return sz; |
||
808 | } |
||
809 | } |
||
810 | |||
811 | |||
812 | /** |
||
813 | * Same as _mesa_format_image_size() but returns a 64-bit value to |
||
814 | * accommodate very large textures. |
||
815 | */ |
||
816 | uint64_t |
||
817 | _mesa_format_image_size64(mesa_format format, GLsizei width, |
||
818 | GLsizei height, GLsizei depth) |
||
819 | { |
||
820 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
821 | /* Strictly speaking, a conditional isn't needed here */ |
||
822 | if (info->BlockWidth > 1 || info->BlockHeight > 1) { |
||
823 | /* compressed format (2D only for now) */ |
||
824 | const uint64_t bw = info->BlockWidth, bh = info->BlockHeight; |
||
825 | const uint64_t wblocks = (width + bw - 1) / bw; |
||
826 | const uint64_t hblocks = (height + bh - 1) / bh; |
||
827 | const uint64_t sz = wblocks * hblocks * info->BytesPerBlock; |
||
828 | return sz * depth; |
||
829 | } |
||
830 | else { |
||
831 | /* non-compressed */ |
||
832 | const uint64_t sz = ((uint64_t) width * |
||
833 | (uint64_t) height * |
||
834 | (uint64_t) depth * |
||
835 | info->BytesPerBlock); |
||
836 | return sz; |
||
837 | } |
||
838 | } |
||
839 | |||
840 | |||
841 | |||
842 | GLint |
||
843 | _mesa_format_row_stride(mesa_format format, GLsizei width) |
||
844 | { |
||
845 | const struct gl_format_info *info = _mesa_get_format_info(format); |
||
846 | /* Strictly speaking, a conditional isn't needed here */ |
||
847 | if (info->BlockWidth > 1 || info->BlockHeight > 1) { |
||
848 | /* compressed format */ |
||
849 | const GLuint bw = info->BlockWidth; |
||
850 | const GLuint wblocks = (width + bw - 1) / bw; |
||
851 | const GLint stride = wblocks * info->BytesPerBlock; |
||
852 | return stride; |
||
853 | } |
||
854 | else { |
||
855 | const GLint stride = width * info->BytesPerBlock; |
||
856 | return stride; |
||
857 | } |
||
858 | } |
||
859 | |||
860 | |||
861 | /** |
||
862 | * Debug/test: check that all formats are handled in the |
||
863 | * _mesa_format_to_type_and_comps() function. When new pixel formats |
||
864 | * are added to Mesa, that function needs to be updated. |
||
865 | * This is a no-op after the first call. |
||
866 | */ |
||
867 | static void |
||
868 | check_format_to_type_and_comps(void) |
||
869 | { |
||
870 | mesa_format f; |
||
871 | |||
872 | for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) { |
||
873 | GLenum datatype = 0; |
||
874 | GLuint comps = 0; |
||
875 | /* This function will emit a problem/warning if the format is |
||
876 | * not handled. |
||
877 | */ |
||
878 | _mesa_format_to_type_and_comps(f, &datatype, &comps); |
||
879 | } |
||
880 | } |
||
881 | |||
882 | /** |
||
883 | * Do sanity checking of the format info table. |
||
884 | */ |
||
885 | void |
||
886 | _mesa_test_formats(void) |
||
887 | { |
||
888 | GLuint i; |
||
889 | |||
890 | STATIC_ASSERT(ARRAY_SIZE(format_info) == MESA_FORMAT_COUNT); |
||
891 | |||
892 | for (i = 0; i < MESA_FORMAT_COUNT; i++) { |
||
893 | const struct gl_format_info *info = _mesa_get_format_info(i); |
||
894 | assert(info); |
||
895 | |||
896 | assert(info->Name == i); |
||
897 | |||
898 | if (info->Name == MESA_FORMAT_NONE) |
||
899 | continue; |
||
900 | |||
901 | if (info->BlockWidth == 1 && info->BlockHeight == 1) { |
||
902 | if (info->RedBits > 0) { |
||
903 | GLuint t = info->RedBits + info->GreenBits |
||
904 | + info->BlueBits + info->AlphaBits; |
||
905 | assert(t / 8 <= info->BytesPerBlock); |
||
906 | (void) t; |
||
907 | } |
||
908 | } |
||
909 | |||
910 | assert(info->DataType == GL_UNSIGNED_NORMALIZED || |
||
911 | info->DataType == GL_SIGNED_NORMALIZED || |
||
912 | info->DataType == GL_UNSIGNED_INT || |
||
913 | info->DataType == GL_INT || |
||
914 | info->DataType == GL_FLOAT || |
||
915 | /* Z32_FLOAT_X24S8 has DataType of GL_NONE */ |
||
916 | info->DataType == GL_NONE); |
||
917 | |||
918 | if (info->BaseFormat == GL_RGB) { |
||
919 | assert(info->RedBits > 0); |
||
920 | assert(info->GreenBits > 0); |
||
921 | assert(info->BlueBits > 0); |
||
922 | assert(info->AlphaBits == 0); |
||
923 | assert(info->LuminanceBits == 0); |
||
924 | assert(info->IntensityBits == 0); |
||
925 | } |
||
926 | else if (info->BaseFormat == GL_RGBA) { |
||
927 | assert(info->RedBits > 0); |
||
928 | assert(info->GreenBits > 0); |
||
929 | assert(info->BlueBits > 0); |
||
930 | assert(info->AlphaBits > 0); |
||
931 | assert(info->LuminanceBits == 0); |
||
932 | assert(info->IntensityBits == 0); |
||
933 | } |
||
934 | else if (info->BaseFormat == GL_RG) { |
||
935 | assert(info->RedBits > 0); |
||
936 | assert(info->GreenBits > 0); |
||
937 | assert(info->BlueBits == 0); |
||
938 | assert(info->AlphaBits == 0); |
||
939 | assert(info->LuminanceBits == 0); |
||
940 | assert(info->IntensityBits == 0); |
||
941 | } |
||
942 | else if (info->BaseFormat == GL_RED) { |
||
943 | assert(info->RedBits > 0); |
||
944 | assert(info->GreenBits == 0); |
||
945 | assert(info->BlueBits == 0); |
||
946 | assert(info->AlphaBits == 0); |
||
947 | assert(info->LuminanceBits == 0); |
||
948 | assert(info->IntensityBits == 0); |
||
949 | } |
||
950 | else if (info->BaseFormat == GL_LUMINANCE) { |
||
951 | assert(info->RedBits == 0); |
||
952 | assert(info->GreenBits == 0); |
||
953 | assert(info->BlueBits == 0); |
||
954 | assert(info->AlphaBits == 0); |
||
955 | assert(info->LuminanceBits > 0); |
||
956 | assert(info->IntensityBits == 0); |
||
957 | } |
||
958 | else if (info->BaseFormat == GL_INTENSITY) { |
||
959 | assert(info->RedBits == 0); |
||
960 | assert(info->GreenBits == 0); |
||
961 | assert(info->BlueBits == 0); |
||
962 | assert(info->AlphaBits == 0); |
||
963 | assert(info->LuminanceBits == 0); |
||
964 | assert(info->IntensityBits > 0); |
||
965 | } |
||
966 | } |
||
967 | |||
968 | check_format_to_type_and_comps(); |
||
969 | } |
||
970 | |||
971 | |||
972 | |||
973 | /** |
||
974 | * Return datatype and number of components per texel for the given mesa_format. |
||
975 | * Only used for mipmap generation code. |
||
976 | */ |
||
977 | void |
||
978 | _mesa_format_to_type_and_comps(mesa_format format, |
||
979 | GLenum *datatype, GLuint *comps) |
||
980 | { |
||
981 | switch (format) { |
||
982 | case MESA_FORMAT_A8B8G8R8_UNORM: |
||
983 | case MESA_FORMAT_R8G8B8A8_UNORM: |
||
984 | case MESA_FORMAT_B8G8R8A8_UNORM: |
||
985 | case MESA_FORMAT_A8R8G8B8_UNORM: |
||
986 | case MESA_FORMAT_X8B8G8R8_UNORM: |
||
987 | case MESA_FORMAT_R8G8B8X8_UNORM: |
||
988 | case MESA_FORMAT_B8G8R8X8_UNORM: |
||
989 | case MESA_FORMAT_X8R8G8B8_UNORM: |
||
990 | *datatype = GL_UNSIGNED_BYTE; |
||
991 | *comps = 4; |
||
992 | return; |
||
993 | case MESA_FORMAT_BGR_UNORM8: |
||
994 | case MESA_FORMAT_RGB_UNORM8: |
||
995 | *datatype = GL_UNSIGNED_BYTE; |
||
996 | *comps = 3; |
||
997 | return; |
||
998 | case MESA_FORMAT_B5G6R5_UNORM: |
||
999 | case MESA_FORMAT_R5G6B5_UNORM: |
||
1000 | *datatype = GL_UNSIGNED_SHORT_5_6_5; |
||
1001 | *comps = 3; |
||
1002 | return; |
||
1003 | |||
1004 | case MESA_FORMAT_B4G4R4A4_UNORM: |
||
1005 | case MESA_FORMAT_A4R4G4B4_UNORM: |
||
1006 | case MESA_FORMAT_B4G4R4X4_UNORM: |
||
1007 | *datatype = GL_UNSIGNED_SHORT_4_4_4_4; |
||
1008 | *comps = 4; |
||
1009 | return; |
||
1010 | |||
1011 | case MESA_FORMAT_B5G5R5A1_UNORM: |
||
1012 | case MESA_FORMAT_A1R5G5B5_UNORM: |
||
1013 | case MESA_FORMAT_B5G5R5X1_UNORM: |
||
1014 | *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV; |
||
1015 | *comps = 4; |
||
1016 | return; |
||
1017 | |||
1018 | case MESA_FORMAT_B10G10R10A2_UNORM: |
||
1019 | *datatype = GL_UNSIGNED_INT_2_10_10_10_REV; |
||
1020 | *comps = 4; |
||
1021 | return; |
||
1022 | |||
1023 | case MESA_FORMAT_A1B5G5R5_UNORM: |
||
1024 | *datatype = GL_UNSIGNED_SHORT_5_5_5_1; |
||
1025 | *comps = 4; |
||
1026 | return; |
||
1027 | |||
1028 | case MESA_FORMAT_L4A4_UNORM: |
||
1029 | *datatype = MESA_UNSIGNED_BYTE_4_4; |
||
1030 | *comps = 2; |
||
1031 | return; |
||
1032 | |||
1033 | case MESA_FORMAT_L8A8_UNORM: |
||
1034 | case MESA_FORMAT_A8L8_UNORM: |
||
1035 | case MESA_FORMAT_R8G8_UNORM: |
||
1036 | case MESA_FORMAT_G8R8_UNORM: |
||
1037 | *datatype = GL_UNSIGNED_BYTE; |
||
1038 | *comps = 2; |
||
1039 | return; |
||
1040 | |||
1041 | case MESA_FORMAT_L16A16_UNORM: |
||
1042 | case MESA_FORMAT_A16L16_UNORM: |
||
1043 | case MESA_FORMAT_R16G16_UNORM: |
||
1044 | case MESA_FORMAT_G16R16_UNORM: |
||
1045 | *datatype = GL_UNSIGNED_SHORT; |
||
1046 | *comps = 2; |
||
1047 | return; |
||
1048 | |||
1049 | case MESA_FORMAT_R_UNORM16: |
||
1050 | case MESA_FORMAT_A_UNORM16: |
||
1051 | case MESA_FORMAT_L_UNORM16: |
||
1052 | case MESA_FORMAT_I_UNORM16: |
||
1053 | *datatype = GL_UNSIGNED_SHORT; |
||
1054 | *comps = 1; |
||
1055 | return; |
||
1056 | |||
1057 | case MESA_FORMAT_R3G3B2_UNORM: |
||
1058 | *datatype = GL_UNSIGNED_BYTE_2_3_3_REV; |
||
1059 | *comps = 3; |
||
1060 | return; |
||
1061 | case MESA_FORMAT_A4B4G4R4_UNORM: |
||
1062 | *datatype = GL_UNSIGNED_SHORT_4_4_4_4; |
||
1063 | *comps = 4; |
||
1064 | return; |
||
1065 | |||
1066 | case MESA_FORMAT_R4G4B4A4_UNORM: |
||
1067 | *datatype = GL_UNSIGNED_SHORT_4_4_4_4; |
||
1068 | *comps = 4; |
||
1069 | return; |
||
1070 | case MESA_FORMAT_R5G5B5A1_UNORM: |
||
1071 | *datatype = GL_UNSIGNED_SHORT_1_5_5_5_REV; |
||
1072 | *comps = 4; |
||
1073 | return; |
||
1074 | case MESA_FORMAT_A2B10G10R10_UNORM: |
||
1075 | case MESA_FORMAT_A2B10G10R10_UINT: |
||
1076 | *datatype = GL_UNSIGNED_INT_10_10_10_2; |
||
1077 | *comps = 4; |
||
1078 | return; |
||
1079 | case MESA_FORMAT_A2R10G10B10_UNORM: |
||
1080 | case MESA_FORMAT_A2R10G10B10_UINT: |
||
1081 | *datatype = GL_UNSIGNED_INT_10_10_10_2; |
||
1082 | *comps = 4; |
||
1083 | return; |
||
1084 | |||
1085 | case MESA_FORMAT_B2G3R3_UNORM: |
||
1086 | *datatype = GL_UNSIGNED_BYTE_3_3_2; |
||
1087 | *comps = 3; |
||
1088 | return; |
||
1089 | |||
1090 | case MESA_FORMAT_A_UNORM8: |
||
1091 | case MESA_FORMAT_L_UNORM8: |
||
1092 | case MESA_FORMAT_I_UNORM8: |
||
1093 | case MESA_FORMAT_R_UNORM8: |
||
1094 | case MESA_FORMAT_S_UINT8: |
||
1095 | *datatype = GL_UNSIGNED_BYTE; |
||
1096 | *comps = 1; |
||
1097 | return; |
||
1098 | |||
1099 | case MESA_FORMAT_YCBCR: |
||
1100 | case MESA_FORMAT_YCBCR_REV: |
||
1101 | *datatype = GL_UNSIGNED_SHORT; |
||
1102 | *comps = 2; |
||
1103 | return; |
||
1104 | |||
1105 | case MESA_FORMAT_S8_UINT_Z24_UNORM: |
||
1106 | *datatype = GL_UNSIGNED_INT_24_8_MESA; |
||
1107 | *comps = 2; |
||
1108 | return; |
||
1109 | |||
1110 | case MESA_FORMAT_Z24_UNORM_S8_UINT: |
||
1111 | *datatype = GL_UNSIGNED_INT_8_24_REV_MESA; |
||
1112 | *comps = 2; |
||
1113 | return; |
||
1114 | |||
1115 | case MESA_FORMAT_Z_UNORM16: |
||
1116 | *datatype = GL_UNSIGNED_SHORT; |
||
1117 | *comps = 1; |
||
1118 | return; |
||
1119 | |||
1120 | case MESA_FORMAT_Z24_UNORM_X8_UINT: |
||
1121 | *datatype = GL_UNSIGNED_INT; |
||
1122 | *comps = 1; |
||
1123 | return; |
||
1124 | |||
1125 | case MESA_FORMAT_X8_UINT_Z24_UNORM: |
||
1126 | *datatype = GL_UNSIGNED_INT; |
||
1127 | *comps = 1; |
||
1128 | return; |
||
1129 | |||
1130 | case MESA_FORMAT_Z_UNORM32: |
||
1131 | *datatype = GL_UNSIGNED_INT; |
||
1132 | *comps = 1; |
||
1133 | return; |
||
1134 | |||
1135 | case MESA_FORMAT_Z_FLOAT32: |
||
1136 | *datatype = GL_FLOAT; |
||
1137 | *comps = 1; |
||
1138 | return; |
||
1139 | |||
1140 | case MESA_FORMAT_Z32_FLOAT_S8X24_UINT: |
||
1141 | *datatype = GL_FLOAT_32_UNSIGNED_INT_24_8_REV; |
||
1142 | *comps = 1; |
||
1143 | return; |
||
1144 | |||
1145 | case MESA_FORMAT_R_SNORM8: |
||
1146 | case MESA_FORMAT_A_SNORM8: |
||
1147 | case MESA_FORMAT_L_SNORM8: |
||
1148 | case MESA_FORMAT_I_SNORM8: |
||
1149 | *datatype = GL_BYTE; |
||
1150 | *comps = 1; |
||
1151 | return; |
||
1152 | case MESA_FORMAT_R8G8_SNORM: |
||
1153 | case MESA_FORMAT_L8A8_SNORM: |
||
1154 | case MESA_FORMAT_A8L8_SNORM: |
||
1155 | *datatype = GL_BYTE; |
||
1156 | *comps = 2; |
||
1157 | return; |
||
1158 | case MESA_FORMAT_A8B8G8R8_SNORM: |
||
1159 | case MESA_FORMAT_R8G8B8A8_SNORM: |
||
1160 | case MESA_FORMAT_X8B8G8R8_SNORM: |
||
1161 | *datatype = GL_BYTE; |
||
1162 | *comps = 4; |
||
1163 | return; |
||
1164 | |||
1165 | case MESA_FORMAT_RGBA_UNORM16: |
||
1166 | *datatype = GL_UNSIGNED_SHORT; |
||
1167 | *comps = 4; |
||
1168 | return; |
||
1169 | |||
1170 | case MESA_FORMAT_R_SNORM16: |
||
1171 | case MESA_FORMAT_A_SNORM16: |
||
1172 | case MESA_FORMAT_L_SNORM16: |
||
1173 | case MESA_FORMAT_I_SNORM16: |
||
1174 | *datatype = GL_SHORT; |
||
1175 | *comps = 1; |
||
1176 | return; |
||
1177 | case MESA_FORMAT_R16G16_SNORM: |
||
1178 | case MESA_FORMAT_LA_SNORM16: |
||
1179 | *datatype = GL_SHORT; |
||
1180 | *comps = 2; |
||
1181 | return; |
||
1182 | case MESA_FORMAT_RGB_SNORM16: |
||
1183 | *datatype = GL_SHORT; |
||
1184 | *comps = 3; |
||
1185 | return; |
||
1186 | case MESA_FORMAT_RGBA_SNORM16: |
||
1187 | *datatype = GL_SHORT; |
||
1188 | *comps = 4; |
||
1189 | return; |
||
1190 | |||
1191 | case MESA_FORMAT_BGR_SRGB8: |
||
1192 | *datatype = GL_UNSIGNED_BYTE; |
||
1193 | *comps = 3; |
||
1194 | return; |
||
1195 | case MESA_FORMAT_A8B8G8R8_SRGB: |
||
1196 | case MESA_FORMAT_B8G8R8A8_SRGB: |
||
1197 | case MESA_FORMAT_A8R8G8B8_SRGB: |
||
1198 | case MESA_FORMAT_R8G8B8A8_SRGB: |
||
1199 | *datatype = GL_UNSIGNED_BYTE; |
||
1200 | *comps = 4; |
||
1201 | return; |
||
1202 | case MESA_FORMAT_L_SRGB8: |
||
1203 | *datatype = GL_UNSIGNED_BYTE; |
||
1204 | *comps = 1; |
||
1205 | return; |
||
1206 | case MESA_FORMAT_L8A8_SRGB: |
||
1207 | case MESA_FORMAT_A8L8_SRGB: |
||
1208 | *datatype = GL_UNSIGNED_BYTE; |
||
1209 | *comps = 2; |
||
1210 | return; |
||
1211 | |||
1212 | case MESA_FORMAT_RGB_FXT1: |
||
1213 | case MESA_FORMAT_RGBA_FXT1: |
||
1214 | case MESA_FORMAT_RGB_DXT1: |
||
1215 | case MESA_FORMAT_RGBA_DXT1: |
||
1216 | case MESA_FORMAT_RGBA_DXT3: |
||
1217 | case MESA_FORMAT_RGBA_DXT5: |
||
1218 | case MESA_FORMAT_SRGB_DXT1: |
||
1219 | case MESA_FORMAT_SRGBA_DXT1: |
||
1220 | case MESA_FORMAT_SRGBA_DXT3: |
||
1221 | case MESA_FORMAT_SRGBA_DXT5: |
||
1222 | case MESA_FORMAT_R_RGTC1_UNORM: |
||
1223 | case MESA_FORMAT_R_RGTC1_SNORM: |
||
1224 | case MESA_FORMAT_RG_RGTC2_UNORM: |
||
1225 | case MESA_FORMAT_RG_RGTC2_SNORM: |
||
1226 | case MESA_FORMAT_L_LATC1_UNORM: |
||
1227 | case MESA_FORMAT_L_LATC1_SNORM: |
||
1228 | case MESA_FORMAT_LA_LATC2_UNORM: |
||
1229 | case MESA_FORMAT_LA_LATC2_SNORM: |
||
1230 | case MESA_FORMAT_ETC1_RGB8: |
||
1231 | case MESA_FORMAT_ETC2_RGB8: |
||
1232 | case MESA_FORMAT_ETC2_SRGB8: |
||
1233 | case MESA_FORMAT_ETC2_RGBA8_EAC: |
||
1234 | case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: |
||
1235 | case MESA_FORMAT_ETC2_R11_EAC: |
||
1236 | case MESA_FORMAT_ETC2_RG11_EAC: |
||
1237 | case MESA_FORMAT_ETC2_SIGNED_R11_EAC: |
||
1238 | case MESA_FORMAT_ETC2_SIGNED_RG11_EAC: |
||
1239 | case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: |
||
1240 | case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: |
||
1241 | case MESA_FORMAT_BPTC_RGBA_UNORM: |
||
1242 | case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM: |
||
1243 | case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT: |
||
1244 | case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT: |
||
1245 | /* XXX generate error instead? */ |
||
1246 | *datatype = GL_UNSIGNED_BYTE; |
||
1247 | *comps = 0; |
||
1248 | return; |
||
1249 | |||
1250 | case MESA_FORMAT_RGBA_FLOAT32: |
||
1251 | *datatype = GL_FLOAT; |
||
1252 | *comps = 4; |
||
1253 | return; |
||
1254 | case MESA_FORMAT_RGBA_FLOAT16: |
||
1255 | *datatype = GL_HALF_FLOAT_ARB; |
||
1256 | *comps = 4; |
||
1257 | return; |
||
1258 | case MESA_FORMAT_RGB_FLOAT32: |
||
1259 | *datatype = GL_FLOAT; |
||
1260 | *comps = 3; |
||
1261 | return; |
||
1262 | case MESA_FORMAT_RGB_FLOAT16: |
||
1263 | *datatype = GL_HALF_FLOAT_ARB; |
||
1264 | *comps = 3; |
||
1265 | return; |
||
1266 | case MESA_FORMAT_LA_FLOAT32: |
||
1267 | case MESA_FORMAT_RG_FLOAT32: |
||
1268 | *datatype = GL_FLOAT; |
||
1269 | *comps = 2; |
||
1270 | return; |
||
1271 | case MESA_FORMAT_LA_FLOAT16: |
||
1272 | case MESA_FORMAT_RG_FLOAT16: |
||
1273 | *datatype = GL_HALF_FLOAT_ARB; |
||
1274 | *comps = 2; |
||
1275 | return; |
||
1276 | case MESA_FORMAT_A_FLOAT32: |
||
1277 | case MESA_FORMAT_L_FLOAT32: |
||
1278 | case MESA_FORMAT_I_FLOAT32: |
||
1279 | case MESA_FORMAT_R_FLOAT32: |
||
1280 | *datatype = GL_FLOAT; |
||
1281 | *comps = 1; |
||
1282 | return; |
||
1283 | case MESA_FORMAT_A_FLOAT16: |
||
1284 | case MESA_FORMAT_L_FLOAT16: |
||
1285 | case MESA_FORMAT_I_FLOAT16: |
||
1286 | case MESA_FORMAT_R_FLOAT16: |
||
1287 | *datatype = GL_HALF_FLOAT_ARB; |
||
1288 | *comps = 1; |
||
1289 | return; |
||
1290 | |||
1291 | case MESA_FORMAT_A_UINT8: |
||
1292 | case MESA_FORMAT_L_UINT8: |
||
1293 | case MESA_FORMAT_I_UINT8: |
||
1294 | *datatype = GL_UNSIGNED_BYTE; |
||
1295 | *comps = 1; |
||
1296 | return; |
||
1297 | case MESA_FORMAT_LA_UINT8: |
||
1298 | *datatype = GL_UNSIGNED_BYTE; |
||
1299 | *comps = 2; |
||
1300 | return; |
||
1301 | |||
1302 | case MESA_FORMAT_A_UINT16: |
||
1303 | case MESA_FORMAT_L_UINT16: |
||
1304 | case MESA_FORMAT_I_UINT16: |
||
1305 | *datatype = GL_UNSIGNED_SHORT; |
||
1306 | *comps = 1; |
||
1307 | return; |
||
1308 | case MESA_FORMAT_LA_UINT16: |
||
1309 | *datatype = GL_UNSIGNED_SHORT; |
||
1310 | *comps = 2; |
||
1311 | return; |
||
1312 | case MESA_FORMAT_A_UINT32: |
||
1313 | case MESA_FORMAT_L_UINT32: |
||
1314 | case MESA_FORMAT_I_UINT32: |
||
1315 | *datatype = GL_UNSIGNED_INT; |
||
1316 | *comps = 1; |
||
1317 | return; |
||
1318 | case MESA_FORMAT_LA_UINT32: |
||
1319 | *datatype = GL_UNSIGNED_INT; |
||
1320 | *comps = 2; |
||
1321 | return; |
||
1322 | case MESA_FORMAT_A_SINT8: |
||
1323 | case MESA_FORMAT_L_SINT8: |
||
1324 | case MESA_FORMAT_I_SINT8: |
||
1325 | *datatype = GL_BYTE; |
||
1326 | *comps = 1; |
||
1327 | return; |
||
1328 | case MESA_FORMAT_LA_SINT8: |
||
1329 | *datatype = GL_BYTE; |
||
1330 | *comps = 2; |
||
1331 | return; |
||
1332 | |||
1333 | case MESA_FORMAT_A_SINT16: |
||
1334 | case MESA_FORMAT_L_SINT16: |
||
1335 | case MESA_FORMAT_I_SINT16: |
||
1336 | *datatype = GL_SHORT; |
||
1337 | *comps = 1; |
||
1338 | return; |
||
1339 | case MESA_FORMAT_LA_SINT16: |
||
1340 | *datatype = GL_SHORT; |
||
1341 | *comps = 2; |
||
1342 | return; |
||
1343 | |||
1344 | case MESA_FORMAT_A_SINT32: |
||
1345 | case MESA_FORMAT_L_SINT32: |
||
1346 | case MESA_FORMAT_I_SINT32: |
||
1347 | *datatype = GL_INT; |
||
1348 | *comps = 1; |
||
1349 | return; |
||
1350 | case MESA_FORMAT_LA_SINT32: |
||
1351 | *datatype = GL_INT; |
||
1352 | *comps = 2; |
||
1353 | return; |
||
1354 | |||
1355 | case MESA_FORMAT_R_SINT8: |
||
1356 | *datatype = GL_BYTE; |
||
1357 | *comps = 1; |
||
1358 | return; |
||
1359 | case MESA_FORMAT_RG_SINT8: |
||
1360 | *datatype = GL_BYTE; |
||
1361 | *comps = 2; |
||
1362 | return; |
||
1363 | case MESA_FORMAT_RGB_SINT8: |
||
1364 | *datatype = GL_BYTE; |
||
1365 | *comps = 3; |
||
1366 | return; |
||
1367 | case MESA_FORMAT_RGBA_SINT8: |
||
1368 | *datatype = GL_BYTE; |
||
1369 | *comps = 4; |
||
1370 | return; |
||
1371 | case MESA_FORMAT_R_SINT16: |
||
1372 | *datatype = GL_SHORT; |
||
1373 | *comps = 1; |
||
1374 | return; |
||
1375 | case MESA_FORMAT_RG_SINT16: |
||
1376 | *datatype = GL_SHORT; |
||
1377 | *comps = 2; |
||
1378 | return; |
||
1379 | case MESA_FORMAT_RGB_SINT16: |
||
1380 | *datatype = GL_SHORT; |
||
1381 | *comps = 3; |
||
1382 | return; |
||
1383 | case MESA_FORMAT_RGBA_SINT16: |
||
1384 | *datatype = GL_SHORT; |
||
1385 | *comps = 4; |
||
1386 | return; |
||
1387 | case MESA_FORMAT_R_SINT32: |
||
1388 | *datatype = GL_INT; |
||
1389 | *comps = 1; |
||
1390 | return; |
||
1391 | case MESA_FORMAT_RG_SINT32: |
||
1392 | *datatype = GL_INT; |
||
1393 | *comps = 2; |
||
1394 | return; |
||
1395 | case MESA_FORMAT_RGB_SINT32: |
||
1396 | *datatype = GL_INT; |
||
1397 | *comps = 3; |
||
1398 | return; |
||
1399 | case MESA_FORMAT_RGBA_SINT32: |
||
1400 | *datatype = GL_INT; |
||
1401 | *comps = 4; |
||
1402 | return; |
||
1403 | |||
1404 | /** |
||
1405 | * \name Non-normalized unsigned integer formats. |
||
1406 | */ |
||
1407 | case MESA_FORMAT_R_UINT8: |
||
1408 | *datatype = GL_UNSIGNED_BYTE; |
||
1409 | *comps = 1; |
||
1410 | return; |
||
1411 | case MESA_FORMAT_RG_UINT8: |
||
1412 | *datatype = GL_UNSIGNED_BYTE; |
||
1413 | *comps = 2; |
||
1414 | return; |
||
1415 | case MESA_FORMAT_RGB_UINT8: |
||
1416 | *datatype = GL_UNSIGNED_BYTE; |
||
1417 | *comps = 3; |
||
1418 | return; |
||
1419 | case MESA_FORMAT_RGBA_UINT8: |
||
1420 | *datatype = GL_UNSIGNED_BYTE; |
||
1421 | *comps = 4; |
||
1422 | return; |
||
1423 | case MESA_FORMAT_R_UINT16: |
||
1424 | *datatype = GL_UNSIGNED_SHORT; |
||
1425 | *comps = 1; |
||
1426 | return; |
||
1427 | case MESA_FORMAT_RG_UINT16: |
||
1428 | *datatype = GL_UNSIGNED_SHORT; |
||
1429 | *comps = 2; |
||
1430 | return; |
||
1431 | case MESA_FORMAT_RGB_UINT16: |
||
1432 | *datatype = GL_UNSIGNED_SHORT; |
||
1433 | *comps = 3; |
||
1434 | return; |
||
1435 | case MESA_FORMAT_RGBA_UINT16: |
||
1436 | *datatype = GL_UNSIGNED_SHORT; |
||
1437 | *comps = 4; |
||
1438 | return; |
||
1439 | case MESA_FORMAT_R_UINT32: |
||
1440 | *datatype = GL_UNSIGNED_INT; |
||
1441 | *comps = 1; |
||
1442 | return; |
||
1443 | case MESA_FORMAT_RG_UINT32: |
||
1444 | *datatype = GL_UNSIGNED_INT; |
||
1445 | *comps = 2; |
||
1446 | return; |
||
1447 | case MESA_FORMAT_RGB_UINT32: |
||
1448 | *datatype = GL_UNSIGNED_INT; |
||
1449 | *comps = 3; |
||
1450 | return; |
||
1451 | case MESA_FORMAT_RGBA_UINT32: |
||
1452 | *datatype = GL_UNSIGNED_INT; |
||
1453 | *comps = 4; |
||
1454 | return; |
||
1455 | |||
1456 | case MESA_FORMAT_R9G9B9E5_FLOAT: |
||
1457 | *datatype = GL_UNSIGNED_INT_5_9_9_9_REV; |
||
1458 | *comps = 3; |
||
1459 | return; |
||
1460 | |||
1461 | case MESA_FORMAT_R11G11B10_FLOAT: |
||
1462 | *datatype = GL_UNSIGNED_INT_10F_11F_11F_REV; |
||
1463 | *comps = 3; |
||
1464 | return; |
||
1465 | |||
1466 | case MESA_FORMAT_B10G10R10A2_UINT: |
||
1467 | case MESA_FORMAT_R10G10B10A2_UINT: |
||
1468 | *datatype = GL_UNSIGNED_INT_2_10_10_10_REV; |
||
1469 | *comps = 4; |
||
1470 | return; |
||
1471 | |||
1472 | case MESA_FORMAT_R8G8B8X8_SRGB: |
||
1473 | case MESA_FORMAT_X8B8G8R8_SRGB: |
||
1474 | case MESA_FORMAT_RGBX_UINT8: |
||
1475 | *datatype = GL_UNSIGNED_BYTE; |
||
1476 | *comps = 4; |
||
1477 | return; |
||
1478 | |||
1479 | case MESA_FORMAT_R8G8B8X8_SNORM: |
||
1480 | case MESA_FORMAT_RGBX_SINT8: |
||
1481 | *datatype = GL_BYTE; |
||
1482 | *comps = 4; |
||
1483 | return; |
||
1484 | |||
1485 | case MESA_FORMAT_B10G10R10X2_UNORM: |
||
1486 | case MESA_FORMAT_R10G10B10X2_UNORM: |
||
1487 | *datatype = GL_UNSIGNED_INT_2_10_10_10_REV; |
||
1488 | *comps = 4; |
||
1489 | return; |
||
1490 | |||
1491 | case MESA_FORMAT_RGBX_UNORM16: |
||
1492 | case MESA_FORMAT_RGBX_UINT16: |
||
1493 | *datatype = GL_UNSIGNED_SHORT; |
||
1494 | *comps = 4; |
||
1495 | return; |
||
1496 | |||
1497 | case MESA_FORMAT_RGBX_SNORM16: |
||
1498 | case MESA_FORMAT_RGBX_SINT16: |
||
1499 | *datatype = GL_SHORT; |
||
1500 | *comps = 4; |
||
1501 | return; |
||
1502 | |||
1503 | case MESA_FORMAT_RGBX_FLOAT16: |
||
1504 | *datatype = GL_HALF_FLOAT; |
||
1505 | *comps = 4; |
||
1506 | return; |
||
1507 | |||
1508 | case MESA_FORMAT_RGBX_FLOAT32: |
||
1509 | *datatype = GL_FLOAT; |
||
1510 | *comps = 4; |
||
1511 | return; |
||
1512 | |||
1513 | case MESA_FORMAT_RGBX_UINT32: |
||
1514 | *datatype = GL_UNSIGNED_INT; |
||
1515 | *comps = 4; |
||
1516 | return; |
||
1517 | |||
1518 | case MESA_FORMAT_RGBX_SINT32: |
||
1519 | *datatype = GL_INT; |
||
1520 | *comps = 4; |
||
1521 | return; |
||
1522 | |||
1523 | case MESA_FORMAT_R10G10B10A2_UNORM: |
||
1524 | *datatype = GL_UNSIGNED_INT_2_10_10_10_REV; |
||
1525 | *comps = 4; |
||
1526 | return; |
||
1527 | |||
1528 | case MESA_FORMAT_G8R8_SNORM: |
||
1529 | *datatype = GL_BYTE; |
||
1530 | *comps = 2; |
||
1531 | return; |
||
1532 | |||
1533 | case MESA_FORMAT_G16R16_SNORM: |
||
1534 | *datatype = GL_SHORT; |
||
1535 | *comps = 2; |
||
1536 | return; |
||
1537 | |||
1538 | case MESA_FORMAT_B8G8R8X8_SRGB: |
||
1539 | case MESA_FORMAT_X8R8G8B8_SRGB: |
||
1540 | *datatype = GL_UNSIGNED_BYTE; |
||
1541 | *comps = 4; |
||
1542 | return; |
||
1543 | |||
1544 | case MESA_FORMAT_COUNT: |
||
1545 | assert(0); |
||
1546 | return; |
||
1547 | |||
1548 | case MESA_FORMAT_NONE: |
||
1549 | /* For debug builds, warn if any formats are not handled */ |
||
1550 | #ifdef DEBUG |
||
1551 | default: |
||
1552 | #endif |
||
1553 | _mesa_problem(NULL, "bad format %s in _mesa_format_to_type_and_comps", |
||
1554 | _mesa_get_format_name(format)); |
||
1555 | *datatype = 0; |
||
1556 | *comps = 1; |
||
1557 | } |
||
1558 | } |
||
1559 | |||
1560 | /** |
||
1561 | * Check if a mesa_format exactly matches a GL format/type combination |
||
1562 | * such that we can use memcpy() from one to the other. |
||
1563 | * \param mesa_format a MESA_FORMAT_x value |
||
1564 | * \param format the user-specified image format |
||
1565 | * \param type the user-specified image datatype |
||
1566 | * \param swapBytes typically the current pixel pack/unpack byteswap state |
||
1567 | * \return GL_TRUE if the formats match, GL_FALSE otherwise. |
||
1568 | */ |
||
1569 | GLboolean |
||
1570 | _mesa_format_matches_format_and_type(mesa_format mesa_format, |
||
1571 | GLenum format, GLenum type, |
||
1572 | GLboolean swapBytes) |
||
1573 | { |
||
1574 | const GLboolean littleEndian = _mesa_little_endian(); |
||
1575 | |||
1576 | /* Note: When reading a GL format/type combination, the format lists channel |
||
1577 | * assignments from most significant channel in the type to least |
||
1578 | * significant. A type with _REV indicates that the assignments are |
||
1579 | * swapped, so they are listed from least significant to most significant. |
||
1580 | * |
||
1581 | * For sanity, please keep this switch statement ordered the same as the |
||
1582 | * enums in formats.h. |
||
1583 | */ |
||
1584 | |||
1585 | switch (mesa_format) { |
||
1586 | |||
1587 | case MESA_FORMAT_NONE: |
||
1588 | case MESA_FORMAT_COUNT: |
||
1589 | return GL_FALSE; |
||
1590 | |||
1591 | case MESA_FORMAT_A8B8G8R8_UNORM: |
||
1592 | case MESA_FORMAT_A8B8G8R8_SRGB: |
||
1593 | if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8 && !swapBytes) |
||
1594 | return GL_TRUE; |
||
1595 | |||
1596 | if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV && swapBytes) |
||
1597 | return GL_TRUE; |
||
1598 | |||
1599 | if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && !littleEndian) |
||
1600 | return GL_TRUE; |
||
1601 | |||
1602 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8_REV |
||
1603 | && !swapBytes) |
||
1604 | return GL_TRUE; |
||
1605 | |||
1606 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8 |
||
1607 | && swapBytes) |
||
1608 | return GL_TRUE; |
||
1609 | |||
1610 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && littleEndian) |
||
1611 | return GL_TRUE; |
||
1612 | |||
1613 | return GL_FALSE; |
||
1614 | |||
1615 | case MESA_FORMAT_R8G8B8A8_UNORM: |
||
1616 | case MESA_FORMAT_R8G8B8A8_SRGB: |
||
1617 | if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8_REV && |
||
1618 | !swapBytes) |
||
1619 | return GL_TRUE; |
||
1620 | |||
1621 | if (format == GL_RGBA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes) |
||
1622 | return GL_TRUE; |
||
1623 | |||
1624 | if (format == GL_RGBA && type == GL_UNSIGNED_BYTE && littleEndian) |
||
1625 | return GL_TRUE; |
||
1626 | |||
1627 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8 && |
||
1628 | !swapBytes) |
||
1629 | return GL_TRUE; |
||
1630 | |||
1631 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_INT_8_8_8_8_REV && |
||
1632 | swapBytes) |
||
1633 | return GL_TRUE; |
||
1634 | |||
1635 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_BYTE && !littleEndian) |
||
1636 | return GL_TRUE; |
||
1637 | |||
1638 | return GL_FALSE; |
||
1639 | |||
1640 | case MESA_FORMAT_B8G8R8A8_UNORM: |
||
1641 | case MESA_FORMAT_B8G8R8A8_SRGB: |
||
1642 | if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV && |
||
1643 | !swapBytes) |
||
1644 | return GL_TRUE; |
||
1645 | |||
1646 | if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8 && swapBytes) |
||
1647 | return GL_TRUE; |
||
1648 | |||
1649 | if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && littleEndian) |
||
1650 | return GL_TRUE; |
||
1651 | |||
1652 | return GL_FALSE; |
||
1653 | |||
1654 | case MESA_FORMAT_A8R8G8B8_UNORM: |
||
1655 | case MESA_FORMAT_A8R8G8B8_SRGB: |
||
1656 | if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8 && !swapBytes) |
||
1657 | return GL_TRUE; |
||
1658 | |||
1659 | if (format == GL_BGRA && type == GL_UNSIGNED_INT_8_8_8_8_REV && |
||
1660 | swapBytes) |
||
1661 | return GL_TRUE; |
||
1662 | |||
1663 | if (format == GL_BGRA && type == GL_UNSIGNED_BYTE && !littleEndian) |
||
1664 | return GL_TRUE; |
||
1665 | |||
1666 | return GL_FALSE; |
||
1667 | |||
1668 | case MESA_FORMAT_X8B8G8R8_UNORM: |
||
1669 | case MESA_FORMAT_R8G8B8X8_UNORM: |
||
1670 | return GL_FALSE; |
||
1671 | |||
1672 | case MESA_FORMAT_B8G8R8X8_UNORM: |
||
1673 | case MESA_FORMAT_X8R8G8B8_UNORM: |
||
1674 | return GL_FALSE; |
||
1675 | |||
1676 | case MESA_FORMAT_BGR_UNORM8: |
||
1677 | case MESA_FORMAT_BGR_SRGB8: |
||
1678 | return format == GL_BGR && type == GL_UNSIGNED_BYTE && littleEndian; |
||
1679 | |||
1680 | case MESA_FORMAT_RGB_UNORM8: |
||
1681 | return format == GL_RGB && type == GL_UNSIGNED_BYTE && littleEndian; |
||
1682 | |||
1683 | case MESA_FORMAT_B5G6R5_UNORM: |
||
1684 | return ((format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5) || |
||
1685 | (format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5_REV)) && |
||
1686 | !swapBytes; |
||
1687 | |||
1688 | case MESA_FORMAT_R5G6B5_UNORM: |
||
1689 | return ((format == GL_BGR && type == GL_UNSIGNED_SHORT_5_6_5) || |
||
1690 | (format == GL_RGB && type == GL_UNSIGNED_SHORT_5_6_5_REV)) && |
||
1691 | !swapBytes; |
||
1692 | |||
1693 | case MESA_FORMAT_B4G4R4A4_UNORM: |
||
1694 | return format == GL_BGRA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && |
||
1695 | !swapBytes; |
||
1696 | |||
1697 | case MESA_FORMAT_A4R4G4B4_UNORM: |
||
1698 | return GL_FALSE; |
||
1699 | |||
1700 | case MESA_FORMAT_A1B5G5R5_UNORM: |
||
1701 | return format == GL_RGBA && type == GL_UNSIGNED_SHORT_5_5_5_1 && |
||
1702 | !swapBytes; |
||
1703 | |||
1704 | case MESA_FORMAT_B5G5R5A1_UNORM: |
||
1705 | return format == GL_BGRA && type == GL_UNSIGNED_SHORT_1_5_5_5_REV && |
||
1706 | !swapBytes; |
||
1707 | |||
1708 | case MESA_FORMAT_A1R5G5B5_UNORM: |
||
1709 | return format == GL_BGRA && type == GL_UNSIGNED_SHORT_5_5_5_1 && |
||
1710 | !swapBytes; |
||
1711 | |||
1712 | case MESA_FORMAT_L4A4_UNORM: |
||
1713 | return GL_FALSE; |
||
1714 | case MESA_FORMAT_L8A8_UNORM: |
||
1715 | case MESA_FORMAT_L8A8_SRGB: |
||
1716 | return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE && littleEndian; |
||
1717 | case MESA_FORMAT_A8L8_UNORM: |
||
1718 | case MESA_FORMAT_A8L8_SRGB: |
||
1719 | return GL_FALSE; |
||
1720 | |||
1721 | case MESA_FORMAT_L16A16_UNORM: |
||
1722 | return format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_SHORT && littleEndian && !swapBytes; |
||
1723 | case MESA_FORMAT_A16L16_UNORM: |
||
1724 | return GL_FALSE; |
||
1725 | |||
1726 | case MESA_FORMAT_B2G3R3_UNORM: |
||
1727 | return format == GL_RGB && type == GL_UNSIGNED_BYTE_3_3_2; |
||
1728 | |||
1729 | case MESA_FORMAT_R3G3B2_UNORM: |
||
1730 | return format == GL_RGB && type == GL_UNSIGNED_BYTE_2_3_3_REV; |
||
1731 | |||
1732 | case MESA_FORMAT_A4B4G4R4_UNORM: |
||
1733 | if (format == GL_RGBA && type == GL_UNSIGNED_SHORT_4_4_4_4 && !swapBytes) |
||
1734 | return GL_TRUE; |
||
1735 | |||
1736 | if (format == GL_RGBA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && swapBytes) |
||
1737 | return GL_TRUE; |
||
1738 | |||
1739 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && !swapBytes) |
||
1740 | return GL_TRUE; |
||
1741 | |||
1742 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_SHORT_4_4_4_4 && swapBytes) |
||
1743 | return GL_TRUE; |
||
1744 | |||
1745 | return GL_FALSE; |
||
1746 | |||
1747 | case MESA_FORMAT_R4G4B4A4_UNORM: |
||
1748 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_SHORT_4_4_4_4 && !swapBytes) |
||
1749 | return GL_TRUE; |
||
1750 | |||
1751 | if (format == GL_ABGR_EXT && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && swapBytes) |
||
1752 | return GL_TRUE; |
||
1753 | |||
1754 | if (format == GL_RGBA && type == GL_UNSIGNED_SHORT_4_4_4_4_REV && !swapBytes) |
||
1755 | return GL_TRUE; |
||
1756 | |||
1757 | if (format == GL_RGBA && type == GL_UNSIGNED_SHORT_4_4_4_4 && swapBytes) |
||
1758 | return GL_TRUE; |
||
1759 | |||
1760 | return GL_FALSE; |
||
1761 | |||
1762 | case MESA_FORMAT_R5G5B5A1_UNORM: |
||
1763 | return format == GL_RGBA && type == GL_UNSIGNED_SHORT_1_5_5_5_REV; |
||
1764 | |||
1765 | case MESA_FORMAT_A2B10G10R10_UNORM: |
||
1766 | return format == GL_RGBA && type == GL_UNSIGNED_INT_10_10_10_2; |
||
1767 | |||
1768 | case MESA_FORMAT_A2B10G10R10_UINT: |
||
1769 | return format == GL_RGBA_INTEGER_EXT && type == GL_UNSIGNED_INT_10_10_10_2; |
||
1770 | |||
1771 | case MESA_FORMAT_A2R10G10B10_UNORM: |
||
1772 | return format == GL_BGRA && type == GL_UNSIGNED_INT_10_10_10_2; |
||
1773 | |||
1774 | case MESA_FORMAT_A2R10G10B10_UINT: |
||
1775 | return format == GL_BGRA_INTEGER_EXT && type == GL_UNSIGNED_INT_10_10_10_2; |
||
1776 | |||
1777 | case MESA_FORMAT_A_UNORM8: |
||
1778 | return format == GL_ALPHA && type == GL_UNSIGNED_BYTE; |
||
1779 | case MESA_FORMAT_A_UNORM16: |
||
1780 | return format == GL_ALPHA && type == GL_UNSIGNED_SHORT && !swapBytes; |
||
1781 | case MESA_FORMAT_L_UNORM8: |
||
1782 | case MESA_FORMAT_L_SRGB8: |
||
1783 | return format == GL_LUMINANCE && type == GL_UNSIGNED_BYTE; |
||
1784 | case MESA_FORMAT_L_UNORM16: |
||
1785 | return format == GL_LUMINANCE && type == GL_UNSIGNED_SHORT && !swapBytes; |
||
1786 | case MESA_FORMAT_I_UNORM8: |
||
1787 | return format == GL_RED && type == GL_UNSIGNED_BYTE; |
||
1788 | case MESA_FORMAT_I_UNORM16: |
||
1789 | return format == GL_RED && type == GL_UNSIGNED_SHORT && !swapBytes; |
||
1790 | |||
1791 | case MESA_FORMAT_YCBCR: |
||
1792 | return format == GL_YCBCR_MESA && |
||
1793 | ((type == GL_UNSIGNED_SHORT_8_8_MESA && littleEndian != swapBytes) || |
||
1794 | (type == GL_UNSIGNED_SHORT_8_8_REV_MESA && littleEndian == swapBytes)); |
||
1795 | case MESA_FORMAT_YCBCR_REV: |
||
1796 | return format == GL_YCBCR_MESA && |
||
1797 | ((type == GL_UNSIGNED_SHORT_8_8_MESA && littleEndian == swapBytes) || |
||
1798 | (type == GL_UNSIGNED_SHORT_8_8_REV_MESA && littleEndian != swapBytes)); |
||
1799 | |||
1800 | case MESA_FORMAT_R_UNORM8: |
||
1801 | return format == GL_RED && type == GL_UNSIGNED_BYTE; |
||
1802 | case MESA_FORMAT_R8G8_UNORM: |
||
1803 | return format == GL_RG && type == GL_UNSIGNED_BYTE && littleEndian; |
||
1804 | case MESA_FORMAT_G8R8_UNORM: |
||
1805 | return GL_FALSE; |
||
1806 | |||
1807 | case MESA_FORMAT_R_UNORM16: |
||
1808 | return format == GL_RED && type == GL_UNSIGNED_SHORT && |
||
1809 | !swapBytes; |
||
1810 | case MESA_FORMAT_R16G16_UNORM: |
||
1811 | return format == GL_RG && type == GL_UNSIGNED_SHORT && littleEndian && |
||
1812 | !swapBytes; |
||
1813 | case MESA_FORMAT_G16R16_UNORM: |
||
1814 | return GL_FALSE; |
||
1815 | |||
1816 | case MESA_FORMAT_B10G10R10A2_UNORM: |
||
1817 | return format == GL_BGRA && type == GL_UNSIGNED_INT_2_10_10_10_REV && |
||
1818 | !swapBytes; |
||
1819 | |||
1820 | case MESA_FORMAT_S8_UINT_Z24_UNORM: |
||
1821 | return format == GL_DEPTH_STENCIL && type == GL_UNSIGNED_INT_24_8 && |
||
1822 | !swapBytes; |
||
1823 | case MESA_FORMAT_X8_UINT_Z24_UNORM: |
||
1824 | case MESA_FORMAT_Z24_UNORM_S8_UINT: |
||
1825 | return GL_FALSE; |
||
1826 | |||
1827 | case MESA_FORMAT_Z_UNORM16: |
||
1828 | return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_SHORT && |
||
1829 | !swapBytes; |
||
1830 | |||
1831 | case MESA_FORMAT_Z24_UNORM_X8_UINT: |
||
1832 | return GL_FALSE; |
||
1833 | |||
1834 | case MESA_FORMAT_Z_UNORM32: |
||
1835 | return format == GL_DEPTH_COMPONENT && type == GL_UNSIGNED_INT && |
||
1836 | !swapBytes; |
||
1837 | |||
1838 | case MESA_FORMAT_S_UINT8: |
||
1839 | return format == GL_STENCIL_INDEX && type == GL_UNSIGNED_BYTE; |
||
1840 | |||
1841 | case MESA_FORMAT_SRGB_DXT1: |
||
1842 | case MESA_FORMAT_SRGBA_DXT1: |
||
1843 | case MESA_FORMAT_SRGBA_DXT3: |
||
1844 | case MESA_FORMAT_SRGBA_DXT5: |
||
1845 | return GL_FALSE; |
||
1846 | |||
1847 | case MESA_FORMAT_RGB_FXT1: |
||
1848 | case MESA_FORMAT_RGBA_FXT1: |
||
1849 | case MESA_FORMAT_RGB_DXT1: |
||
1850 | case MESA_FORMAT_RGBA_DXT1: |
||
1851 | case MESA_FORMAT_RGBA_DXT3: |
||
1852 | case MESA_FORMAT_RGBA_DXT5: |
||
1853 | return GL_FALSE; |
||
1854 | |||
1855 | case MESA_FORMAT_BPTC_RGBA_UNORM: |
||
1856 | case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM: |
||
1857 | case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT: |
||
1858 | case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT: |
||
1859 | return GL_FALSE; |
||
1860 | |||
1861 | case MESA_FORMAT_RGBA_FLOAT32: |
||
1862 | return format == GL_RGBA && type == GL_FLOAT && !swapBytes; |
||
1863 | case MESA_FORMAT_RGBA_FLOAT16: |
||
1864 | return format == GL_RGBA && type == GL_HALF_FLOAT && !swapBytes; |
||
1865 | |||
1866 | case MESA_FORMAT_RGB_FLOAT32: |
||
1867 | return format == GL_RGB && type == GL_FLOAT && !swapBytes; |
||
1868 | case MESA_FORMAT_RGB_FLOAT16: |
||
1869 | return format == GL_RGB && type == GL_HALF_FLOAT && !swapBytes; |
||
1870 | |||
1871 | case MESA_FORMAT_A_FLOAT32: |
||
1872 | return format == GL_ALPHA && type == GL_FLOAT && !swapBytes; |
||
1873 | case MESA_FORMAT_A_FLOAT16: |
||
1874 | return format == GL_ALPHA && type == GL_HALF_FLOAT && !swapBytes; |
||
1875 | |||
1876 | case MESA_FORMAT_L_FLOAT32: |
||
1877 | return format == GL_LUMINANCE && type == GL_FLOAT && !swapBytes; |
||
1878 | case MESA_FORMAT_L_FLOAT16: |
||
1879 | return format == GL_LUMINANCE && type == GL_HALF_FLOAT && !swapBytes; |
||
1880 | |||
1881 | case MESA_FORMAT_LA_FLOAT32: |
||
1882 | return format == GL_LUMINANCE_ALPHA && type == GL_FLOAT && !swapBytes; |
||
1883 | case MESA_FORMAT_LA_FLOAT16: |
||
1884 | return format == GL_LUMINANCE_ALPHA && type == GL_HALF_FLOAT && !swapBytes; |
||
1885 | |||
1886 | case MESA_FORMAT_I_FLOAT32: |
||
1887 | return format == GL_RED && type == GL_FLOAT && !swapBytes; |
||
1888 | case MESA_FORMAT_I_FLOAT16: |
||
1889 | return format == GL_RED && type == GL_HALF_FLOAT && !swapBytes; |
||
1890 | |||
1891 | case MESA_FORMAT_R_FLOAT32: |
||
1892 | return format == GL_RED && type == GL_FLOAT && !swapBytes; |
||
1893 | case MESA_FORMAT_R_FLOAT16: |
||
1894 | return format == GL_RED && type == GL_HALF_FLOAT && !swapBytes; |
||
1895 | |||
1896 | case MESA_FORMAT_RG_FLOAT32: |
||
1897 | return format == GL_RG && type == GL_FLOAT && !swapBytes; |
||
1898 | case MESA_FORMAT_RG_FLOAT16: |
||
1899 | return format == GL_RG && type == GL_HALF_FLOAT && !swapBytes; |
||
1900 | |||
1901 | case MESA_FORMAT_A_UINT8: |
||
1902 | return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_BYTE; |
||
1903 | case MESA_FORMAT_A_UINT16: |
||
1904 | return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_SHORT && |
||
1905 | !swapBytes; |
||
1906 | case MESA_FORMAT_A_UINT32: |
||
1907 | return format == GL_ALPHA_INTEGER && type == GL_UNSIGNED_INT && |
||
1908 | !swapBytes; |
||
1909 | case MESA_FORMAT_A_SINT8: |
||
1910 | return format == GL_ALPHA_INTEGER && type == GL_BYTE; |
||
1911 | case MESA_FORMAT_A_SINT16: |
||
1912 | return format == GL_ALPHA_INTEGER && type == GL_SHORT && !swapBytes; |
||
1913 | case MESA_FORMAT_A_SINT32: |
||
1914 | return format == GL_ALPHA_INTEGER && type == GL_INT && !swapBytes; |
||
1915 | |||
1916 | case MESA_FORMAT_I_UINT8: |
||
1917 | return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE; |
||
1918 | case MESA_FORMAT_I_UINT16: |
||
1919 | return format == GL_RED_INTEGER && type == GL_UNSIGNED_SHORT && !swapBytes; |
||
1920 | case MESA_FORMAT_I_UINT32: |
||
1921 | return format == GL_RED_INTEGER && type == GL_UNSIGNED_INT && !swapBytes; |
||
1922 | case MESA_FORMAT_I_SINT8: |
||
1923 | return format == GL_RED_INTEGER && type == GL_BYTE; |
||
1924 | case MESA_FORMAT_I_SINT16: |
||
1925 | return format == GL_RED_INTEGER && type == GL_SHORT && !swapBytes; |
||
1926 | case MESA_FORMAT_I_SINT32: |
||
1927 | return format == GL_RED_INTEGER && type == GL_INT && !swapBytes; |
||
1928 | |||
1929 | case MESA_FORMAT_L_UINT8: |
||
1930 | return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_BYTE; |
||
1931 | case MESA_FORMAT_L_UINT16: |
||
1932 | return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_SHORT && |
||
1933 | !swapBytes; |
||
1934 | case MESA_FORMAT_L_UINT32: |
||
1935 | return format == GL_LUMINANCE_INTEGER_EXT && type == GL_UNSIGNED_INT && |
||
1936 | !swapBytes; |
||
1937 | case MESA_FORMAT_L_SINT8: |
||
1938 | return format == GL_LUMINANCE_INTEGER_EXT && type == GL_BYTE; |
||
1939 | case MESA_FORMAT_L_SINT16: |
||
1940 | return format == GL_LUMINANCE_INTEGER_EXT && type == GL_SHORT && |
||
1941 | !swapBytes; |
||
1942 | case MESA_FORMAT_L_SINT32: |
||
1943 | return format == GL_LUMINANCE_INTEGER_EXT && type == GL_INT && !swapBytes; |
||
1944 | |||
1945 | case MESA_FORMAT_LA_UINT8: |
||
1946 | return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && |
||
1947 | type == GL_UNSIGNED_BYTE && !swapBytes; |
||
1948 | case MESA_FORMAT_LA_UINT16: |
||
1949 | return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && |
||
1950 | type == GL_UNSIGNED_SHORT && !swapBytes; |
||
1951 | case MESA_FORMAT_LA_UINT32: |
||
1952 | return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && |
||
1953 | type == GL_UNSIGNED_INT && !swapBytes; |
||
1954 | case MESA_FORMAT_LA_SINT8: |
||
1955 | return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && type == GL_BYTE && |
||
1956 | !swapBytes; |
||
1957 | case MESA_FORMAT_LA_SINT16: |
||
1958 | return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && type == GL_SHORT && |
||
1959 | !swapBytes; |
||
1960 | case MESA_FORMAT_LA_SINT32: |
||
1961 | return format == GL_LUMINANCE_ALPHA_INTEGER_EXT && type == GL_INT && |
||
1962 | !swapBytes; |
||
1963 | |||
1964 | case MESA_FORMAT_R_SINT8: |
||
1965 | return format == GL_RED_INTEGER && type == GL_BYTE; |
||
1966 | case MESA_FORMAT_RG_SINT8: |
||
1967 | return format == GL_RG_INTEGER && type == GL_BYTE && !swapBytes; |
||
1968 | case MESA_FORMAT_RGB_SINT8: |
||
1969 | return format == GL_RGB_INTEGER && type == GL_BYTE && !swapBytes; |
||
1970 | case MESA_FORMAT_RGBA_SINT8: |
||
1971 | return format == GL_RGBA_INTEGER && type == GL_BYTE && !swapBytes; |
||
1972 | case MESA_FORMAT_R_SINT16: |
||
1973 | return format == GL_RED_INTEGER && type == GL_SHORT && !swapBytes; |
||
1974 | case MESA_FORMAT_RG_SINT16: |
||
1975 | return format == GL_RG_INTEGER && type == GL_SHORT && !swapBytes; |
||
1976 | case MESA_FORMAT_RGB_SINT16: |
||
1977 | return format == GL_RGB_INTEGER && type == GL_SHORT && !swapBytes; |
||
1978 | case MESA_FORMAT_RGBA_SINT16: |
||
1979 | return format == GL_RGBA_INTEGER && type == GL_SHORT && !swapBytes; |
||
1980 | case MESA_FORMAT_R_SINT32: |
||
1981 | return format == GL_RED_INTEGER && type == GL_INT && !swapBytes; |
||
1982 | case MESA_FORMAT_RG_SINT32: |
||
1983 | return format == GL_RG_INTEGER && type == GL_INT && !swapBytes; |
||
1984 | case MESA_FORMAT_RGB_SINT32: |
||
1985 | return format == GL_RGB_INTEGER && type == GL_INT && !swapBytes; |
||
1986 | case MESA_FORMAT_RGBA_SINT32: |
||
1987 | return format == GL_RGBA_INTEGER && type == GL_INT && !swapBytes; |
||
1988 | |||
1989 | case MESA_FORMAT_R_UINT8: |
||
1990 | return format == GL_RED_INTEGER && type == GL_UNSIGNED_BYTE; |
||
1991 | case MESA_FORMAT_RG_UINT8: |
||
1992 | return format == GL_RG_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes; |
||
1993 | case MESA_FORMAT_RGB_UINT8: |
||
1994 | return format == GL_RGB_INTEGER && type == GL_UNSIGNED_BYTE && !swapBytes; |
||
1995 | case MESA_FORMAT_RGBA_UINT8: |
||
1996 | return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_BYTE && |
||
1997 | !swapBytes; |
||
1998 | case MESA_FORMAT_R_UINT16: |
||
1999 | return format == GL_RED_INTEGER && type == GL_UNSIGNED_SHORT && |
||
2000 | !swapBytes; |
||
2001 | case MESA_FORMAT_RG_UINT16: |
||
2002 | return format == GL_RG_INTEGER && type == GL_UNSIGNED_SHORT && !swapBytes; |
||
2003 | case MESA_FORMAT_RGB_UINT16: |
||
2004 | return format == GL_RGB_INTEGER && type == GL_UNSIGNED_SHORT && |
||
2005 | !swapBytes; |
||
2006 | case MESA_FORMAT_RGBA_UINT16: |
||
2007 | return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_SHORT && |
||
2008 | !swapBytes; |
||
2009 | case MESA_FORMAT_R_UINT32: |
||
2010 | return format == GL_RED_INTEGER && type == GL_UNSIGNED_INT && !swapBytes; |
||
2011 | case MESA_FORMAT_RG_UINT32: |
||
2012 | return format == GL_RG_INTEGER && type == GL_UNSIGNED_INT && !swapBytes; |
||
2013 | case MESA_FORMAT_RGB_UINT32: |
||
2014 | return format == GL_RGB_INTEGER && type == GL_UNSIGNED_INT && !swapBytes; |
||
2015 | case MESA_FORMAT_RGBA_UINT32: |
||
2016 | return format == GL_RGBA_INTEGER && type == GL_UNSIGNED_INT && !swapBytes; |
||
2017 | |||
2018 | case MESA_FORMAT_R_SNORM8: |
||
2019 | return format == GL_RED && type == GL_BYTE; |
||
2020 | case MESA_FORMAT_R8G8_SNORM: |
||
2021 | return format == GL_RG && type == GL_BYTE && littleEndian && |
||
2022 | !swapBytes; |
||
2023 | case MESA_FORMAT_X8B8G8R8_SNORM: |
||
2024 | return GL_FALSE; |
||
2025 | |||
2026 | case MESA_FORMAT_A8B8G8R8_SNORM: |
||
2027 | if (format == GL_RGBA && type == GL_BYTE && !littleEndian) |
||
2028 | return GL_TRUE; |
||
2029 | |||
2030 | if (format == GL_ABGR_EXT && type == GL_BYTE && littleEndian) |
||
2031 | return GL_TRUE; |
||
2032 | |||
2033 | return GL_FALSE; |
||
2034 | |||
2035 | case MESA_FORMAT_R8G8B8A8_SNORM: |
||
2036 | if (format == GL_RGBA && type == GL_BYTE && littleEndian) |
||
2037 | return GL_TRUE; |
||
2038 | |||
2039 | if (format == GL_ABGR_EXT && type == GL_BYTE && !littleEndian) |
||
2040 | return GL_TRUE; |
||
2041 | |||
2042 | return GL_FALSE; |
||
2043 | |||
2044 | case MESA_FORMAT_R_SNORM16: |
||
2045 | return format == GL_RED && type == GL_SHORT && |
||
2046 | !swapBytes; |
||
2047 | case MESA_FORMAT_R16G16_SNORM: |
||
2048 | return format == GL_RG && type == GL_SHORT && littleEndian && !swapBytes; |
||
2049 | case MESA_FORMAT_RGB_SNORM16: |
||
2050 | return format == GL_RGB && type == GL_SHORT && !swapBytes; |
||
2051 | case MESA_FORMAT_RGBA_SNORM16: |
||
2052 | return format == GL_RGBA && type == GL_SHORT && !swapBytes; |
||
2053 | case MESA_FORMAT_RGBA_UNORM16: |
||
2054 | return format == GL_RGBA && type == GL_UNSIGNED_SHORT && |
||
2055 | !swapBytes; |
||
2056 | |||
2057 | case MESA_FORMAT_R_RGTC1_UNORM: |
||
2058 | case MESA_FORMAT_R_RGTC1_SNORM: |
||
2059 | case MESA_FORMAT_RG_RGTC2_UNORM: |
||
2060 | case MESA_FORMAT_RG_RGTC2_SNORM: |
||
2061 | return GL_FALSE; |
||
2062 | |||
2063 | case MESA_FORMAT_L_LATC1_UNORM: |
||
2064 | case MESA_FORMAT_L_LATC1_SNORM: |
||
2065 | case MESA_FORMAT_LA_LATC2_UNORM: |
||
2066 | case MESA_FORMAT_LA_LATC2_SNORM: |
||
2067 | return GL_FALSE; |
||
2068 | |||
2069 | case MESA_FORMAT_ETC1_RGB8: |
||
2070 | case MESA_FORMAT_ETC2_RGB8: |
||
2071 | case MESA_FORMAT_ETC2_SRGB8: |
||
2072 | case MESA_FORMAT_ETC2_RGBA8_EAC: |
||
2073 | case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC: |
||
2074 | case MESA_FORMAT_ETC2_R11_EAC: |
||
2075 | case MESA_FORMAT_ETC2_RG11_EAC: |
||
2076 | case MESA_FORMAT_ETC2_SIGNED_R11_EAC: |
||
2077 | case MESA_FORMAT_ETC2_SIGNED_RG11_EAC: |
||
2078 | case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1: |
||
2079 | case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1: |
||
2080 | return GL_FALSE; |
||
2081 | |||
2082 | case MESA_FORMAT_A_SNORM8: |
||
2083 | return format == GL_ALPHA && type == GL_BYTE; |
||
2084 | case MESA_FORMAT_L_SNORM8: |
||
2085 | return format == GL_LUMINANCE && type == GL_BYTE; |
||
2086 | case MESA_FORMAT_L8A8_SNORM: |
||
2087 | return format == GL_LUMINANCE_ALPHA && type == GL_BYTE && |
||
2088 | littleEndian && !swapBytes; |
||
2089 | case MESA_FORMAT_A8L8_SNORM: |
||
2090 | return format == GL_LUMINANCE_ALPHA && type == GL_BYTE && |
||
2091 | !littleEndian && !swapBytes; |
||
2092 | case MESA_FORMAT_I_SNORM8: |
||
2093 | return format == GL_RED && type == GL_BYTE; |
||
2094 | case MESA_FORMAT_A_SNORM16: |
||
2095 | return format == GL_ALPHA && type == GL_SHORT && !swapBytes; |
||
2096 | case MESA_FORMAT_L_SNORM16: |
||
2097 | return format == GL_LUMINANCE && type == GL_SHORT && !swapBytes; |
||
2098 | case MESA_FORMAT_LA_SNORM16: |
||
2099 | return format == GL_LUMINANCE_ALPHA && type == GL_SHORT && |
||
2100 | littleEndian && !swapBytes; |
||
2101 | case MESA_FORMAT_I_SNORM16: |
||
2102 | return format == GL_RED && type == GL_SHORT && littleEndian && |
||
2103 | !swapBytes; |
||
2104 | |||
2105 | case MESA_FORMAT_B10G10R10A2_UINT: |
||
2106 | return (format == GL_BGRA_INTEGER_EXT && |
||
2107 | type == GL_UNSIGNED_INT_2_10_10_10_REV && |
||
2108 | !swapBytes); |
||
2109 | |||
2110 | case MESA_FORMAT_R10G10B10A2_UINT: |
||
2111 | return (format == GL_RGBA_INTEGER_EXT && |
||
2112 | type == GL_UNSIGNED_INT_2_10_10_10_REV && |
||
2113 | !swapBytes); |
||
2114 | |||
2115 | case MESA_FORMAT_R9G9B9E5_FLOAT: |
||
2116 | return format == GL_RGB && type == GL_UNSIGNED_INT_5_9_9_9_REV && |
||
2117 | !swapBytes; |
||
2118 | |||
2119 | case MESA_FORMAT_R11G11B10_FLOAT: |
||
2120 | return format == GL_RGB && type == GL_UNSIGNED_INT_10F_11F_11F_REV && |
||
2121 | !swapBytes; |
||
2122 | |||
2123 | case MESA_FORMAT_Z_FLOAT32: |
||
2124 | return format == GL_DEPTH_COMPONENT && type == GL_FLOAT && !swapBytes; |
||
2125 | |||
2126 | case MESA_FORMAT_Z32_FLOAT_S8X24_UINT: |
||
2127 | return format == GL_DEPTH_STENCIL && |
||
2128 | type == GL_FLOAT_32_UNSIGNED_INT_24_8_REV && !swapBytes; |
||
2129 | |||
2130 | case MESA_FORMAT_B4G4R4X4_UNORM: |
||
2131 | case MESA_FORMAT_B5G5R5X1_UNORM: |
||
2132 | case MESA_FORMAT_R8G8B8X8_SNORM: |
||
2133 | case MESA_FORMAT_R8G8B8X8_SRGB: |
||
2134 | case MESA_FORMAT_X8B8G8R8_SRGB: |
||
2135 | case MESA_FORMAT_RGBX_UINT8: |
||
2136 | case MESA_FORMAT_RGBX_SINT8: |
||
2137 | case MESA_FORMAT_B10G10R10X2_UNORM: |
||
2138 | case MESA_FORMAT_R10G10B10X2_UNORM: |
||
2139 | case MESA_FORMAT_RGBX_UNORM16: |
||
2140 | case MESA_FORMAT_RGBX_SNORM16: |
||
2141 | case MESA_FORMAT_RGBX_FLOAT16: |
||
2142 | case MESA_FORMAT_RGBX_UINT16: |
||
2143 | case MESA_FORMAT_RGBX_SINT16: |
||
2144 | case MESA_FORMAT_RGBX_FLOAT32: |
||
2145 | case MESA_FORMAT_RGBX_UINT32: |
||
2146 | case MESA_FORMAT_RGBX_SINT32: |
||
2147 | return GL_FALSE; |
||
2148 | |||
2149 | case MESA_FORMAT_R10G10B10A2_UNORM: |
||
2150 | return format == GL_RGBA && type == GL_UNSIGNED_INT_2_10_10_10_REV && |
||
2151 | !swapBytes; |
||
2152 | |||
2153 | case MESA_FORMAT_G8R8_SNORM: |
||
2154 | return format == GL_RG && type == GL_BYTE && !littleEndian && |
||
2155 | !swapBytes; |
||
2156 | |||
2157 | case MESA_FORMAT_G16R16_SNORM: |
||
2158 | return format == GL_RG && type == GL_SHORT && !littleEndian && |
||
2159 | !swapBytes; |
||
2160 | |||
2161 | case MESA_FORMAT_B8G8R8X8_SRGB: |
||
2162 | case MESA_FORMAT_X8R8G8B8_SRGB: |
||
2163 | return GL_FALSE; |
||
2164 | } |
||
2165 | |||
2166 | return GL_FALSE; |
||
2167 | }=>>>>=>=>=>=>=>=> |
||
2168 |