2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 #include "mfeatures.h"
44 * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
45 * we later convert the float to a packed integer value (such as for
46 * GL_RGB5_A1) because we'll wind up with a non-zero value.
48 * We redefine the macros here so zero is handled correctly.
51 #define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
54 #define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
58 /** Compute ceiling of integer quotient of A divided by B. */
59 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
63 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
66 _mesa_type_is_packed(GLenum type
)
69 case GL_UNSIGNED_BYTE_3_3_2
:
70 case GL_UNSIGNED_BYTE_2_3_3_REV
:
71 case MESA_UNSIGNED_BYTE_4_4
:
72 case GL_UNSIGNED_SHORT_5_6_5
:
73 case GL_UNSIGNED_SHORT_5_6_5_REV
:
74 case GL_UNSIGNED_SHORT_4_4_4_4
:
75 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
76 case GL_UNSIGNED_SHORT_5_5_5_1
:
77 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
78 case GL_UNSIGNED_INT_8_8_8_8
:
79 case GL_UNSIGNED_INT_8_8_8_8_REV
:
80 case GL_UNSIGNED_INT_10_10_10_2
:
81 case GL_UNSIGNED_INT_2_10_10_10_REV
:
82 case GL_UNSIGNED_SHORT_8_8_MESA
:
83 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
84 case GL_UNSIGNED_INT_24_8_EXT
:
85 case GL_UNSIGNED_INT_5_9_9_9_REV
:
86 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
87 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
97 * Flip the order of the 2 bytes in each word in the given array.
100 * \param n number of words.
103 _mesa_swap2( GLushort
*p
, GLuint n
)
106 for (i
= 0; i
< n
; i
++) {
107 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
114 * Flip the order of the 4 bytes in each word in the given array.
117 _mesa_swap4( GLuint
*p
, GLuint n
)
120 for (i
= 0; i
< n
; i
++) {
123 | ((b
>> 8) & 0xff00)
124 | ((b
<< 8) & 0xff0000)
125 | ((b
<< 24) & 0xff000000);
132 * Get the size of a GL data type.
134 * \param type GL data type.
136 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
137 * if an invalid type enum.
140 _mesa_sizeof_type( GLenum type
)
145 case GL_UNSIGNED_BYTE
:
146 return sizeof(GLubyte
);
148 return sizeof(GLbyte
);
149 case GL_UNSIGNED_SHORT
:
150 return sizeof(GLushort
);
152 return sizeof(GLshort
);
153 case GL_UNSIGNED_INT
:
154 return sizeof(GLuint
);
156 return sizeof(GLint
);
158 return sizeof(GLfloat
);
160 return sizeof(GLdouble
);
161 case GL_HALF_FLOAT_ARB
:
162 return sizeof(GLhalfARB
);
164 return sizeof(GLfixed
);
172 * Same as _mesa_sizeof_type() but also accepting the packed pixel
176 _mesa_sizeof_packed_type( GLenum type
)
181 case GL_UNSIGNED_BYTE
:
182 return sizeof(GLubyte
);
184 return sizeof(GLbyte
);
185 case GL_UNSIGNED_SHORT
:
186 return sizeof(GLushort
);
188 return sizeof(GLshort
);
189 case GL_UNSIGNED_INT
:
190 return sizeof(GLuint
);
192 return sizeof(GLint
);
193 case GL_HALF_FLOAT_ARB
:
194 return sizeof(GLhalfARB
);
196 return sizeof(GLfloat
);
197 case GL_UNSIGNED_BYTE_3_3_2
:
198 return sizeof(GLubyte
);
199 case GL_UNSIGNED_BYTE_2_3_3_REV
:
200 return sizeof(GLubyte
);
201 case MESA_UNSIGNED_BYTE_4_4
:
202 return sizeof(GLubyte
);
203 case GL_UNSIGNED_SHORT_5_6_5
:
204 return sizeof(GLushort
);
205 case GL_UNSIGNED_SHORT_5_6_5_REV
:
206 return sizeof(GLushort
);
207 case GL_UNSIGNED_SHORT_4_4_4_4
:
208 return sizeof(GLushort
);
209 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
210 return sizeof(GLushort
);
211 case GL_UNSIGNED_SHORT_5_5_5_1
:
212 return sizeof(GLushort
);
213 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
214 return sizeof(GLushort
);
215 case GL_UNSIGNED_INT_8_8_8_8
:
216 return sizeof(GLuint
);
217 case GL_UNSIGNED_INT_8_8_8_8_REV
:
218 return sizeof(GLuint
);
219 case GL_UNSIGNED_INT_10_10_10_2
:
220 return sizeof(GLuint
);
221 case GL_UNSIGNED_INT_2_10_10_10_REV
:
222 return sizeof(GLuint
);
223 case GL_UNSIGNED_SHORT_8_8_MESA
:
224 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
225 return sizeof(GLushort
);
226 case GL_UNSIGNED_INT_24_8_EXT
:
227 return sizeof(GLuint
);
228 case GL_UNSIGNED_INT_5_9_9_9_REV
:
229 return sizeof(GLuint
);
230 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
231 return sizeof(GLuint
);
232 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
241 * Get the number of components in a pixel format.
243 * \param format pixel format.
245 * \return the number of components in the given format, or -1 if a bad format.
248 _mesa_components_in_format( GLenum format
)
252 case GL_COLOR_INDEX1_EXT
:
253 case GL_COLOR_INDEX2_EXT
:
254 case GL_COLOR_INDEX4_EXT
:
255 case GL_COLOR_INDEX8_EXT
:
256 case GL_COLOR_INDEX12_EXT
:
257 case GL_COLOR_INDEX16_EXT
:
258 case GL_STENCIL_INDEX
:
259 case GL_DEPTH_COMPONENT
:
261 case GL_RED_INTEGER_EXT
:
263 case GL_GREEN_INTEGER_EXT
:
265 case GL_BLUE_INTEGER_EXT
:
267 case GL_ALPHA_INTEGER_EXT
:
269 case GL_LUMINANCE_INTEGER_EXT
:
272 case GL_LUMINANCE_ALPHA
:
273 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
277 case GL_RGB_INTEGER_EXT
:
280 case GL_RGBA_INTEGER_EXT
:
290 case GL_DEPTH_STENCIL_EXT
:
302 * Get the bytes per pixel of pixel format type pair.
304 * \param format pixel format.
305 * \param type pixel type.
307 * \return bytes per pixel, or -1 if a bad format or type was given.
310 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
312 GLint comps
= _mesa_components_in_format( format
);
318 return 0; /* special case */
320 case GL_UNSIGNED_BYTE
:
321 return comps
* sizeof(GLubyte
);
323 case GL_UNSIGNED_SHORT
:
324 return comps
* sizeof(GLshort
);
326 case GL_UNSIGNED_INT
:
327 return comps
* sizeof(GLint
);
329 return comps
* sizeof(GLfloat
);
330 case GL_HALF_FLOAT_ARB
:
331 return comps
* sizeof(GLhalfARB
);
332 case GL_UNSIGNED_BYTE_3_3_2
:
333 case GL_UNSIGNED_BYTE_2_3_3_REV
:
334 if (format
== GL_RGB
|| format
== GL_BGR
||
335 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
336 return sizeof(GLubyte
);
338 return -1; /* error */
339 case GL_UNSIGNED_SHORT_5_6_5
:
340 case GL_UNSIGNED_SHORT_5_6_5_REV
:
341 if (format
== GL_RGB
|| format
== GL_BGR
||
342 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
343 return sizeof(GLushort
);
345 return -1; /* error */
346 case GL_UNSIGNED_SHORT_4_4_4_4
:
347 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
348 case GL_UNSIGNED_SHORT_5_5_5_1
:
349 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
350 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
351 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
352 return sizeof(GLushort
);
355 case GL_UNSIGNED_INT_8_8_8_8
:
356 case GL_UNSIGNED_INT_8_8_8_8_REV
:
357 case GL_UNSIGNED_INT_10_10_10_2
:
358 case GL_UNSIGNED_INT_2_10_10_10_REV
:
359 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
360 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
361 return sizeof(GLuint
);
364 case GL_UNSIGNED_SHORT_8_8_MESA
:
365 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
366 if (format
== GL_YCBCR_MESA
)
367 return sizeof(GLushort
);
370 case GL_UNSIGNED_INT_24_8_EXT
:
371 if (format
== GL_DEPTH_STENCIL_EXT
)
372 return sizeof(GLuint
);
375 case GL_UNSIGNED_INT_5_9_9_9_REV
:
376 if (format
== GL_RGB
)
377 return sizeof(GLuint
);
380 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
381 if (format
== GL_RGB
)
382 return sizeof(GLuint
);
385 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
386 if (format
== GL_DEPTH_STENCIL
)
397 * Test for a legal pixel format and type.
399 * \param format pixel format.
400 * \param type pixel type.
402 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
406 _mesa_is_legal_format_and_type(const struct gl_context
*ctx
,
407 GLenum format
, GLenum type
)
411 case GL_STENCIL_INDEX
:
415 case GL_UNSIGNED_BYTE
:
417 case GL_UNSIGNED_SHORT
:
419 case GL_UNSIGNED_INT
:
422 case GL_HALF_FLOAT_ARB
:
423 return ctx
->Extensions
.ARB_half_float_pixel
;
431 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
435 case GL_LUMINANCE_ALPHA
:
436 case GL_DEPTH_COMPONENT
:
439 case GL_UNSIGNED_BYTE
:
441 case GL_UNSIGNED_SHORT
:
443 case GL_UNSIGNED_INT
:
446 case GL_HALF_FLOAT_ARB
:
447 return ctx
->Extensions
.ARB_half_float_pixel
;
452 if (!ctx
->Extensions
.ARB_texture_rg
)
457 case GL_UNSIGNED_BYTE
:
459 case GL_UNSIGNED_SHORT
:
461 case GL_UNSIGNED_INT
:
464 case GL_HALF_FLOAT_ARB
:
465 return ctx
->Extensions
.ARB_half_float_pixel
;
472 case GL_UNSIGNED_BYTE
:
474 case GL_UNSIGNED_SHORT
:
476 case GL_UNSIGNED_INT
:
478 case GL_UNSIGNED_BYTE_3_3_2
:
479 case GL_UNSIGNED_BYTE_2_3_3_REV
:
480 case GL_UNSIGNED_SHORT_5_6_5
:
481 case GL_UNSIGNED_SHORT_5_6_5_REV
:
483 case GL_HALF_FLOAT_ARB
:
484 return ctx
->Extensions
.ARB_half_float_pixel
;
485 case GL_UNSIGNED_INT_5_9_9_9_REV
:
486 return ctx
->Extensions
.EXT_texture_shared_exponent
;
487 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
488 return ctx
->Extensions
.EXT_packed_float
;
494 /* NOTE: no packed types are supported with BGR. That's
495 * intentional, according to the GL spec.
498 case GL_UNSIGNED_BYTE
:
500 case GL_UNSIGNED_SHORT
:
502 case GL_UNSIGNED_INT
:
505 case GL_HALF_FLOAT_ARB
:
506 return ctx
->Extensions
.ARB_half_float_pixel
;
515 case GL_UNSIGNED_BYTE
:
517 case GL_UNSIGNED_SHORT
:
519 case GL_UNSIGNED_INT
:
521 case GL_UNSIGNED_SHORT_4_4_4_4
:
522 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
523 case GL_UNSIGNED_SHORT_5_5_5_1
:
524 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
525 case GL_UNSIGNED_INT_8_8_8_8
:
526 case GL_UNSIGNED_INT_8_8_8_8_REV
:
527 case GL_UNSIGNED_INT_10_10_10_2
:
528 case GL_UNSIGNED_INT_2_10_10_10_REV
:
530 case GL_HALF_FLOAT_ARB
:
531 return ctx
->Extensions
.ARB_half_float_pixel
;
536 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
537 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
541 case GL_DEPTH_STENCIL_EXT
:
542 if ((ctx
->Extensions
.EXT_packed_depth_stencil
&&
543 type
== GL_UNSIGNED_INT_24_8_EXT
) ||
544 (ctx
->Extensions
.ARB_depth_buffer_float
&&
545 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
))
553 case GL_UNSIGNED_BYTE
:
555 case GL_UNSIGNED_SHORT
:
557 case GL_UNSIGNED_INT
:
564 /* integer-valued formats */
565 case GL_RED_INTEGER_EXT
:
566 case GL_GREEN_INTEGER_EXT
:
567 case GL_BLUE_INTEGER_EXT
:
568 case GL_ALPHA_INTEGER_EXT
:
571 case GL_UNSIGNED_BYTE
:
573 case GL_UNSIGNED_SHORT
:
575 case GL_UNSIGNED_INT
:
576 return ctx
->Extensions
.EXT_texture_integer
;
581 case GL_RGB_INTEGER_EXT
:
584 case GL_UNSIGNED_BYTE
:
586 case GL_UNSIGNED_SHORT
:
588 case GL_UNSIGNED_INT
:
589 case GL_UNSIGNED_BYTE_3_3_2
:
590 case GL_UNSIGNED_BYTE_2_3_3_REV
:
591 case GL_UNSIGNED_SHORT_5_6_5
:
592 case GL_UNSIGNED_SHORT_5_6_5_REV
:
593 return ctx
->Extensions
.EXT_texture_integer
;
598 case GL_BGR_INTEGER_EXT
:
601 case GL_UNSIGNED_BYTE
:
603 case GL_UNSIGNED_SHORT
:
605 case GL_UNSIGNED_INT
:
606 /* NOTE: no packed formats w/ BGR format */
607 return ctx
->Extensions
.EXT_texture_integer
;
612 case GL_RGBA_INTEGER_EXT
:
613 case GL_BGRA_INTEGER_EXT
:
616 case GL_UNSIGNED_BYTE
:
618 case GL_UNSIGNED_SHORT
:
620 case GL_UNSIGNED_INT
:
621 case GL_UNSIGNED_SHORT_4_4_4_4
:
622 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
623 case GL_UNSIGNED_SHORT_5_5_5_1
:
624 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
625 case GL_UNSIGNED_INT_8_8_8_8
:
626 case GL_UNSIGNED_INT_8_8_8_8_REV
:
627 case GL_UNSIGNED_INT_10_10_10_2
:
628 case GL_UNSIGNED_INT_2_10_10_10_REV
:
629 return ctx
->Extensions
.EXT_texture_integer
;
634 case GL_LUMINANCE_INTEGER_EXT
:
635 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
638 case GL_UNSIGNED_BYTE
:
640 case GL_UNSIGNED_SHORT
:
642 case GL_UNSIGNED_INT
:
643 return ctx
->Extensions
.EXT_texture_integer
;
656 * Test if the given image format is a color/RGBA format (i.e., not color
657 * index, depth, stencil, etc).
658 * \param format the image format value (may by an internal texture format)
659 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
662 _mesa_is_color_format(GLenum format
)
680 case GL_LUMINANCE_ALPHA
:
681 case GL_LUMINANCE4_ALPHA4
:
682 case GL_LUMINANCE6_ALPHA2
:
683 case GL_LUMINANCE8_ALPHA8
:
684 case GL_LUMINANCE12_ALPHA4
:
685 case GL_LUMINANCE12_ALPHA12
:
686 case GL_LUMINANCE16_ALPHA16
:
718 /* float texture formats */
719 case GL_ALPHA16F_ARB
:
720 case GL_ALPHA32F_ARB
:
721 case GL_LUMINANCE16F_ARB
:
722 case GL_LUMINANCE32F_ARB
:
723 case GL_LUMINANCE_ALPHA16F_ARB
:
724 case GL_LUMINANCE_ALPHA32F_ARB
:
725 case GL_INTENSITY16F_ARB
:
726 case GL_INTENSITY32F_ARB
:
735 /* compressed formats */
736 case GL_COMPRESSED_ALPHA
:
737 case GL_COMPRESSED_LUMINANCE
:
738 case GL_COMPRESSED_LUMINANCE_ALPHA
:
739 case GL_COMPRESSED_INTENSITY
:
740 case GL_COMPRESSED_RED
:
741 case GL_COMPRESSED_RG
:
742 case GL_COMPRESSED_RGB
:
743 case GL_COMPRESSED_RGBA
:
748 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
749 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
750 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
751 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
752 case GL_COMPRESSED_RGB_FXT1_3DFX
:
753 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
754 #if FEATURE_EXT_texture_sRGB
757 case GL_SRGB_ALPHA_EXT
:
758 case GL_SRGB8_ALPHA8_EXT
:
759 case GL_SLUMINANCE_ALPHA_EXT
:
760 case GL_SLUMINANCE8_ALPHA8_EXT
:
761 case GL_SLUMINANCE_EXT
:
762 case GL_SLUMINANCE8_EXT
:
763 case GL_COMPRESSED_SRGB_EXT
:
764 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
765 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
766 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
767 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
768 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
769 case GL_COMPRESSED_SLUMINANCE_EXT
:
770 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
771 #endif /* FEATURE_EXT_texture_sRGB */
772 case GL_COMPRESSED_RED_RGTC1
:
773 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
774 case GL_COMPRESSED_RG_RGTC2
:
775 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
776 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
777 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
778 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
779 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
780 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
781 /* generic integer formats */
782 case GL_RED_INTEGER_EXT
:
783 case GL_GREEN_INTEGER_EXT
:
784 case GL_BLUE_INTEGER_EXT
:
785 case GL_ALPHA_INTEGER_EXT
:
786 case GL_RGB_INTEGER_EXT
:
787 case GL_RGBA_INTEGER_EXT
:
788 case GL_BGR_INTEGER_EXT
:
789 case GL_BGRA_INTEGER_EXT
:
790 case GL_LUMINANCE_INTEGER_EXT
:
791 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
792 /* sized integer formats */
793 case GL_RGBA32UI_EXT
:
795 case GL_ALPHA32UI_EXT
:
796 case GL_INTENSITY32UI_EXT
:
797 case GL_LUMINANCE32UI_EXT
:
798 case GL_LUMINANCE_ALPHA32UI_EXT
:
799 case GL_RGBA16UI_EXT
:
801 case GL_ALPHA16UI_EXT
:
802 case GL_INTENSITY16UI_EXT
:
803 case GL_LUMINANCE16UI_EXT
:
804 case GL_LUMINANCE_ALPHA16UI_EXT
:
807 case GL_ALPHA8UI_EXT
:
808 case GL_INTENSITY8UI_EXT
:
809 case GL_LUMINANCE8UI_EXT
:
810 case GL_LUMINANCE_ALPHA8UI_EXT
:
813 case GL_ALPHA32I_EXT
:
814 case GL_INTENSITY32I_EXT
:
815 case GL_LUMINANCE32I_EXT
:
816 case GL_LUMINANCE_ALPHA32I_EXT
:
819 case GL_ALPHA16I_EXT
:
820 case GL_INTENSITY16I_EXT
:
821 case GL_LUMINANCE16I_EXT
:
822 case GL_LUMINANCE_ALPHA16I_EXT
:
826 case GL_INTENSITY8I_EXT
:
827 case GL_LUMINANCE8I_EXT
:
828 case GL_LUMINANCE_ALPHA8I_EXT
:
829 /* signed, normalized texture formats */
841 case GL_RGBA16_SNORM
:
843 case GL_ALPHA8_SNORM
:
844 case GL_ALPHA16_SNORM
:
845 case GL_LUMINANCE_SNORM
:
846 case GL_LUMINANCE8_SNORM
:
847 case GL_LUMINANCE16_SNORM
:
848 case GL_LUMINANCE_ALPHA_SNORM
:
849 case GL_LUMINANCE8_ALPHA8_SNORM
:
850 case GL_LUMINANCE16_ALPHA16_SNORM
:
851 case GL_INTENSITY_SNORM
:
852 case GL_INTENSITY8_SNORM
:
853 case GL_INTENSITY16_SNORM
:
855 case GL_R11F_G11F_B10F
:
857 case GL_YCBCR_MESA
: /* not considered to be RGB */
866 * Test if the given image format is a color index format.
869 _mesa_is_index_format(GLenum format
)
873 case GL_COLOR_INDEX1_EXT
:
874 case GL_COLOR_INDEX2_EXT
:
875 case GL_COLOR_INDEX4_EXT
:
876 case GL_COLOR_INDEX8_EXT
:
877 case GL_COLOR_INDEX12_EXT
:
878 case GL_COLOR_INDEX16_EXT
:
887 * Test if the given image format is a depth component format.
890 _mesa_is_depth_format(GLenum format
)
893 case GL_DEPTH_COMPONENT
:
894 case GL_DEPTH_COMPONENT16
:
895 case GL_DEPTH_COMPONENT24
:
896 case GL_DEPTH_COMPONENT32
:
897 case GL_DEPTH_COMPONENT32F
:
906 * Test if the given image format is a stencil format.
909 _mesa_is_stencil_format(GLenum format
)
912 case GL_STENCIL_INDEX
:
913 case GL_DEPTH_STENCIL
:
922 * Test if the given image format is a YCbCr format.
925 _mesa_is_ycbcr_format(GLenum format
)
937 * Test if the given image format is a depth+stencil format.
940 _mesa_is_depthstencil_format(GLenum format
)
943 case GL_DEPTH24_STENCIL8_EXT
:
944 case GL_DEPTH_STENCIL_EXT
:
945 case GL_DEPTH32F_STENCIL8
:
954 * Test if the given image format is a depth or stencil format.
957 _mesa_is_depth_or_stencil_format(GLenum format
)
960 case GL_DEPTH_COMPONENT
:
961 case GL_DEPTH_COMPONENT16
:
962 case GL_DEPTH_COMPONENT24
:
963 case GL_DEPTH_COMPONENT32
:
964 case GL_STENCIL_INDEX
:
965 case GL_STENCIL_INDEX1_EXT
:
966 case GL_STENCIL_INDEX4_EXT
:
967 case GL_STENCIL_INDEX8_EXT
:
968 case GL_STENCIL_INDEX16_EXT
:
969 case GL_DEPTH_STENCIL_EXT
:
970 case GL_DEPTH24_STENCIL8_EXT
:
971 case GL_DEPTH_COMPONENT32F
:
972 case GL_DEPTH32F_STENCIL8
:
981 * Test if the given image format is a dudv format.
984 _mesa_is_dudv_format(GLenum format
)
997 * Test if the given format is an integer (non-normalized) format.
1000 _mesa_is_integer_format(GLenum format
)
1003 /* generic integer formats */
1004 case GL_RED_INTEGER_EXT
:
1005 case GL_GREEN_INTEGER_EXT
:
1006 case GL_BLUE_INTEGER_EXT
:
1007 case GL_ALPHA_INTEGER_EXT
:
1008 case GL_RGB_INTEGER_EXT
:
1009 case GL_RGBA_INTEGER_EXT
:
1010 case GL_BGR_INTEGER_EXT
:
1011 case GL_BGRA_INTEGER_EXT
:
1012 case GL_LUMINANCE_INTEGER_EXT
:
1013 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
1014 /* specific integer formats */
1015 case GL_RGBA32UI_EXT
:
1016 case GL_RGB32UI_EXT
:
1017 case GL_ALPHA32UI_EXT
:
1018 case GL_INTENSITY32UI_EXT
:
1019 case GL_LUMINANCE32UI_EXT
:
1020 case GL_LUMINANCE_ALPHA32UI_EXT
:
1021 case GL_RGBA16UI_EXT
:
1022 case GL_RGB16UI_EXT
:
1023 case GL_ALPHA16UI_EXT
:
1024 case GL_INTENSITY16UI_EXT
:
1025 case GL_LUMINANCE16UI_EXT
:
1026 case GL_LUMINANCE_ALPHA16UI_EXT
:
1027 case GL_RGBA8UI_EXT
:
1029 case GL_ALPHA8UI_EXT
:
1030 case GL_INTENSITY8UI_EXT
:
1031 case GL_LUMINANCE8UI_EXT
:
1032 case GL_LUMINANCE_ALPHA8UI_EXT
:
1033 case GL_RGBA32I_EXT
:
1035 case GL_ALPHA32I_EXT
:
1036 case GL_INTENSITY32I_EXT
:
1037 case GL_LUMINANCE32I_EXT
:
1038 case GL_LUMINANCE_ALPHA32I_EXT
:
1039 case GL_RGBA16I_EXT
:
1041 case GL_ALPHA16I_EXT
:
1042 case GL_INTENSITY16I_EXT
:
1043 case GL_LUMINANCE16I_EXT
:
1044 case GL_LUMINANCE_ALPHA16I_EXT
:
1047 case GL_ALPHA8I_EXT
:
1048 case GL_INTENSITY8I_EXT
:
1049 case GL_LUMINANCE8I_EXT
:
1050 case GL_LUMINANCE_ALPHA8I_EXT
:
1059 * Test if an image format is a supported compressed format.
1060 * \param format the internal format token provided by the user.
1061 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1064 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
1067 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1068 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1069 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1070 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1071 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
1076 return ctx
->Extensions
.S3_s3tc
;
1077 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1078 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1079 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1080 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1081 return ctx
->Extensions
.EXT_texture_sRGB
1082 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1083 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1084 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1085 return ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1086 case GL_COMPRESSED_RED_RGTC1
:
1087 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1088 case GL_COMPRESSED_RG_RGTC2
:
1089 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1090 return ctx
->Extensions
.ARB_texture_compression_rgtc
;
1091 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1092 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1093 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1094 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1095 return ctx
->Extensions
.EXT_texture_compression_latc
;
1096 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1097 return ctx
->Extensions
.ATI_texture_compression_3dc
;
1105 * Return the address of a specific pixel in an image (1D, 2D or 3D).
1107 * Pixel unpacking/packing parameters are observed according to \p packing.
1109 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
1110 * \param image starting address of image data
1111 * \param width the image width
1112 * \param height theimage height
1113 * \param format the pixel format
1114 * \param type the pixel data type
1115 * \param packing the pixelstore attributes
1116 * \param img which image in the volume (0 for 1D or 2D images)
1117 * \param row row of pixel in the image (0 for 1D images)
1118 * \param column column of pixel in the image
1120 * \return address of pixel on success, or NULL on error.
1122 * \sa gl_pixelstore_attrib.
1125 _mesa_image_address( GLuint dimensions
,
1126 const struct gl_pixelstore_attrib
*packing
,
1127 const GLvoid
*image
,
1128 GLsizei width
, GLsizei height
,
1129 GLenum format
, GLenum type
,
1130 GLint img
, GLint row
, GLint column
)
1132 GLint alignment
; /* 1, 2 or 4 */
1133 GLint pixels_per_row
;
1134 GLint rows_per_image
;
1137 GLint skipimages
; /* for 3-D volume images */
1138 GLubyte
*pixel_addr
;
1140 ASSERT(dimensions
>= 1 && dimensions
<= 3);
1142 alignment
= packing
->Alignment
;
1143 if (packing
->RowLength
> 0) {
1144 pixels_per_row
= packing
->RowLength
;
1147 pixels_per_row
= width
;
1149 if (packing
->ImageHeight
> 0) {
1150 rows_per_image
= packing
->ImageHeight
;
1153 rows_per_image
= height
;
1156 skippixels
= packing
->SkipPixels
;
1157 /* Note: SKIP_ROWS _is_ used for 1D images */
1158 skiprows
= packing
->SkipRows
;
1159 /* Note: SKIP_IMAGES is only used for 3D images */
1160 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
1162 if (type
== GL_BITMAP
) {
1164 GLint comp_per_pixel
; /* components per pixel */
1165 GLint bytes_per_comp
; /* bytes per component */
1166 GLint bytes_per_row
;
1167 GLint bytes_per_image
;
1169 /* Compute bytes per component */
1170 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
1171 if (bytes_per_comp
< 0) {
1175 /* Compute number of components per pixel */
1176 comp_per_pixel
= _mesa_components_in_format( format
);
1177 if (comp_per_pixel
< 0) {
1181 bytes_per_row
= alignment
1182 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
1184 bytes_per_image
= bytes_per_row
* rows_per_image
;
1186 pixel_addr
= (GLubyte
*) image
1187 + (skipimages
+ img
) * bytes_per_image
1188 + (skiprows
+ row
) * bytes_per_row
1189 + (skippixels
+ column
) / 8;
1192 /* Non-BITMAP data */
1193 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
1196 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
1198 /* The pixel type and format should have been error checked earlier */
1199 assert(bytes_per_pixel
> 0);
1201 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
1202 remainder
= bytes_per_row
% alignment
;
1204 bytes_per_row
+= (alignment
- remainder
);
1206 ASSERT(bytes_per_row
% alignment
== 0);
1208 bytes_per_image
= bytes_per_row
* rows_per_image
;
1210 if (packing
->Invert
) {
1211 /* set pixel_addr to the last row */
1212 topOfImage
= bytes_per_row
* (height
- 1);
1213 bytes_per_row
= -bytes_per_row
;
1219 /* compute final pixel address */
1220 pixel_addr
= (GLubyte
*) image
1221 + (skipimages
+ img
) * bytes_per_image
1223 + (skiprows
+ row
) * bytes_per_row
1224 + (skippixels
+ column
) * bytes_per_pixel
;
1227 return (GLvoid
*) pixel_addr
;
1232 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
1233 const GLvoid
*image
,
1235 GLenum format
, GLenum type
,
1238 return _mesa_image_address(1, packing
, image
, width
, 1,
1239 format
, type
, 0, 0, column
);
1244 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
1245 const GLvoid
*image
,
1246 GLsizei width
, GLsizei height
,
1247 GLenum format
, GLenum type
,
1248 GLint row
, GLint column
)
1250 return _mesa_image_address(2, packing
, image
, width
, height
,
1251 format
, type
, 0, row
, column
);
1256 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
1257 const GLvoid
*image
,
1258 GLsizei width
, GLsizei height
,
1259 GLenum format
, GLenum type
,
1260 GLint img
, GLint row
, GLint column
)
1262 return _mesa_image_address(3, packing
, image
, width
, height
,
1263 format
, type
, img
, row
, column
);
1269 * Compute the stride (in bytes) between image rows.
1271 * \param packing the pixelstore attributes
1272 * \param width image width.
1273 * \param format pixel format.
1274 * \param type pixel data type.
1276 * \return the stride in bytes for the given parameters, or -1 if error
1279 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
1280 GLint width
, GLenum format
, GLenum type
)
1282 GLint bytesPerRow
, remainder
;
1286 if (type
== GL_BITMAP
) {
1287 if (packing
->RowLength
== 0) {
1288 bytesPerRow
= (width
+ 7) / 8;
1291 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1295 /* Non-BITMAP data */
1296 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1297 if (bytesPerPixel
<= 0)
1298 return -1; /* error */
1299 if (packing
->RowLength
== 0) {
1300 bytesPerRow
= bytesPerPixel
* width
;
1303 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1307 remainder
= bytesPerRow
% packing
->Alignment
;
1308 if (remainder
> 0) {
1309 bytesPerRow
+= (packing
->Alignment
- remainder
);
1312 if (packing
->Invert
) {
1313 /* negate the bytes per row (negative row stride) */
1314 bytesPerRow
= -bytesPerRow
;
1322 * Compute the stride between images in a 3D texture (in bytes) for the given
1323 * pixel packing parameters and image width, format and type.
1326 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1327 GLint width
, GLint height
,
1328 GLenum format
, GLenum type
)
1330 GLint bytesPerRow
, bytesPerImage
, remainder
;
1334 if (type
== GL_BITMAP
) {
1335 if (packing
->RowLength
== 0) {
1336 bytesPerRow
= (width
+ 7) / 8;
1339 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1343 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1345 if (bytesPerPixel
<= 0)
1346 return -1; /* error */
1347 if (packing
->RowLength
== 0) {
1348 bytesPerRow
= bytesPerPixel
* width
;
1351 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1355 remainder
= bytesPerRow
% packing
->Alignment
;
1357 bytesPerRow
+= (packing
->Alignment
- remainder
);
1359 if (packing
->ImageHeight
== 0)
1360 bytesPerImage
= bytesPerRow
* height
;
1362 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1364 return bytesPerImage
;
1370 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1371 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1372 * "On" bits will set texels to \p onValue.
1373 * "Off" bits will not modify texels.
1374 * \param width src bitmap width in pixels
1375 * \param height src bitmap height in pixels
1376 * \param unpack bitmap unpacking state
1377 * \param bitmap the src bitmap data
1378 * \param destBuffer start of dest buffer
1379 * \param destStride row stride in dest buffer
1380 * \param onValue if bit is 1, set destBuffer pixel to this value
1383 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1384 const struct gl_pixelstore_attrib
*unpack
,
1385 const GLubyte
*bitmap
,
1386 GLubyte
*destBuffer
, GLint destStride
,
1389 const GLubyte
*srcRow
= (const GLubyte
*)
1390 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1391 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1392 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1393 GL_COLOR_INDEX
, GL_BITMAP
);
1396 #define SET_PIXEL(COL, ROW) \
1397 destBuffer[(ROW) * destStride + (COL)] = onValue;
1399 for (row
= 0; row
< height
; row
++) {
1400 const GLubyte
*src
= srcRow
;
1402 if (unpack
->LsbFirst
) {
1404 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1405 for (col
= 0; col
< width
; col
++) {
1408 SET_PIXEL(col
, row
);
1420 /* get ready for next row */
1426 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1427 for (col
= 0; col
< width
; col
++) {
1430 SET_PIXEL(col
, row
);
1442 /* get ready for next row */
1447 srcRow
+= srcStride
;
1457 * Convert an array of RGBA colors from one datatype to another.
1458 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1461 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
1462 GLenum dstType
, GLvoid
*dst
,
1463 GLuint count
, const GLubyte mask
[])
1465 GLuint tempBuffer
[MAX_WIDTH
][4];
1466 const GLboolean useTemp
= (src
== dst
);
1468 ASSERT(srcType
!= dstType
);
1471 case GL_UNSIGNED_BYTE
:
1472 if (dstType
== GL_UNSIGNED_SHORT
) {
1473 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1474 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1476 for (i
= 0; i
< count
; i
++) {
1477 if (!mask
|| mask
[i
]) {
1478 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
1479 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
1480 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
1481 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
1485 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1488 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1489 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1491 ASSERT(dstType
== GL_FLOAT
);
1492 for (i
= 0; i
< count
; i
++) {
1493 if (!mask
|| mask
[i
]) {
1494 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
1495 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
1496 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
1497 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
1501 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1504 case GL_UNSIGNED_SHORT
:
1505 if (dstType
== GL_UNSIGNED_BYTE
) {
1506 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1507 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1509 for (i
= 0; i
< count
; i
++) {
1510 if (!mask
|| mask
[i
]) {
1511 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
1512 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
1513 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
1514 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
1518 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1521 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1522 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1524 ASSERT(dstType
== GL_FLOAT
);
1525 for (i
= 0; i
< count
; i
++) {
1526 if (!mask
|| mask
[i
]) {
1527 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
1528 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
1529 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
1530 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
1534 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1538 if (dstType
== GL_UNSIGNED_BYTE
) {
1539 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1540 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1542 for (i
= 0; i
< count
; i
++) {
1543 if (!mask
|| mask
[i
]) {
1544 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
1545 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
1546 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
1547 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
1551 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1554 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1555 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1557 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
1558 for (i
= 0; i
< count
; i
++) {
1559 if (!mask
|| mask
[i
]) {
1560 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
1561 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
1562 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
1563 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
1567 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1571 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
1579 * Perform basic clipping for glDrawPixels. The image's position and size
1580 * and the unpack SkipPixels and SkipRows are adjusted so that the image
1581 * region is entirely within the window and scissor bounds.
1582 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
1583 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
1584 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
1586 * \return GL_TRUE if image is ready for drawing or
1587 * GL_FALSE if image was completely clipped away (draw nothing)
1590 _mesa_clip_drawpixels(const struct gl_context
*ctx
,
1591 GLint
*destX
, GLint
*destY
,
1592 GLsizei
*width
, GLsizei
*height
,
1593 struct gl_pixelstore_attrib
*unpack
)
1595 const struct gl_framebuffer
*buffer
= ctx
->DrawBuffer
;
1597 if (unpack
->RowLength
== 0) {
1598 unpack
->RowLength
= *width
;
1601 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
1602 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
1605 if (*destX
< buffer
->_Xmin
) {
1606 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
1607 *width
-= (buffer
->_Xmin
- *destX
);
1608 *destX
= buffer
->_Xmin
;
1610 /* right clipping */
1611 if (*destX
+ *width
> buffer
->_Xmax
)
1612 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
1617 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
1618 /* bottom clipping */
1619 if (*destY
< buffer
->_Ymin
) {
1620 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
1621 *height
-= (buffer
->_Ymin
- *destY
);
1622 *destY
= buffer
->_Ymin
;
1625 if (*destY
+ *height
> buffer
->_Ymax
)
1626 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
1628 else { /* upside down */
1630 if (*destY
> buffer
->_Ymax
) {
1631 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
1632 *height
-= (*destY
- buffer
->_Ymax
);
1633 *destY
= buffer
->_Ymax
;
1635 /* bottom clipping */
1636 if (*destY
- *height
< buffer
->_Ymin
)
1637 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
1638 /* adjust destY so it's the first row to write to */
1650 * Perform clipping for glReadPixels. The image's window position
1651 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
1652 * so that the image region is entirely within the window bounds.
1653 * Note: this is different from _mesa_clip_drawpixels() in that the
1654 * scissor box is ignored, and we use the bounds of the current readbuffer
1657 * \return GL_TRUE if region to read is in bounds
1658 * GL_FALSE if region is completely out of bounds (nothing to read)
1661 _mesa_clip_readpixels(const struct gl_context
*ctx
,
1662 GLint
*srcX
, GLint
*srcY
,
1663 GLsizei
*width
, GLsizei
*height
,
1664 struct gl_pixelstore_attrib
*pack
)
1666 const struct gl_framebuffer
*buffer
= ctx
->ReadBuffer
;
1668 if (pack
->RowLength
== 0) {
1669 pack
->RowLength
= *width
;
1674 pack
->SkipPixels
+= (0 - *srcX
);
1675 *width
-= (0 - *srcX
);
1678 /* right clipping */
1679 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
1680 *width
-= (*srcX
+ *width
- buffer
->Width
);
1685 /* bottom clipping */
1687 pack
->SkipRows
+= (0 - *srcY
);
1688 *height
-= (0 - *srcY
);
1692 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
1693 *height
-= (*srcY
+ *height
- buffer
->Height
);
1703 * Do clipping for a glCopyTexSubImage call.
1704 * The framebuffer source region might extend outside the framebuffer
1705 * bounds. Clip the source region against the framebuffer bounds and
1706 * adjust the texture/dest position and size accordingly.
1708 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
1711 _mesa_clip_copytexsubimage(const struct gl_context
*ctx
,
1712 GLint
*destX
, GLint
*destY
,
1713 GLint
*srcX
, GLint
*srcY
,
1714 GLsizei
*width
, GLsizei
*height
)
1716 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
1717 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
1719 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
1720 srcX
, srcY
, width
, height
)) {
1721 *destX
= *destX
+ *srcX
- srcX0
;
1722 *destY
= *destY
+ *srcY
- srcY0
;
1734 * Clip the rectangle defined by (x, y, width, height) against the bounds
1735 * specified by [xmin, xmax) and [ymin, ymax).
1736 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
1739 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
1740 GLint xmax
, GLint ymax
,
1742 GLsizei
*width
, GLsizei
*height
)
1746 *width
-= (xmin
- *x
);
1750 /* right clipping */
1751 if (*x
+ *width
> xmax
)
1752 *width
-= (*x
+ *width
- xmax
);
1757 /* bottom (or top) clipping */
1759 *height
-= (ymin
- *y
);
1763 /* top (or bottom) clipping */
1764 if (*y
+ *height
> ymax
)
1765 *height
-= (*y
+ *height
- ymax
);
1775 * Clip dst coords against Xmax (or Ymax).
1778 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
1779 GLint
*dstX0
, GLint
*dstX1
,
1784 if (*dstX1
> maxValue
) {
1785 /* X1 outside right edge */
1786 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
1787 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1788 /* chop off [t, 1] part */
1789 ASSERT(t
>= 0.0 && t
<= 1.0);
1791 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1792 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1794 else if (*dstX0
> maxValue
) {
1795 /* X0 outside right edge */
1796 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
1797 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1798 /* chop off [t, 1] part */
1799 ASSERT(t
>= 0.0 && t
<= 1.0);
1801 bias
= (*srcX0
< *srcX1
) ? -0.5F
: 0.5F
;
1802 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1808 * Clip dst coords against Xmin (or Ymin).
1811 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
1812 GLint
*dstX0
, GLint
*dstX1
,
1817 if (*dstX0
< minValue
) {
1818 /* X0 outside left edge */
1819 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
1820 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1821 /* chop off [0, t] part */
1822 ASSERT(t
>= 0.0 && t
<= 1.0);
1824 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
; /* flipped??? */
1825 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1827 else if (*dstX1
< minValue
) {
1828 /* X1 outside left edge */
1829 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
1830 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1831 /* chop off [0, t] part */
1832 ASSERT(t
>= 0.0 && t
<= 1.0);
1834 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1835 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1841 * Do clipping of blit src/dest rectangles.
1842 * The dest rect is clipped against both the buffer bounds and scissor bounds.
1843 * The src rect is just clipped against the buffer bounds.
1845 * When either the src or dest rect is clipped, the other is also clipped
1848 * Note that X0 need not be less than X1 (same for Y) for either the source
1849 * and dest rects. That makes the clipping a little trickier.
1851 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
1854 _mesa_clip_blit(struct gl_context
*ctx
,
1855 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
1856 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
1858 const GLint srcXmin
= 0;
1859 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
1860 const GLint srcYmin
= 0;
1861 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
1863 /* these include scissor bounds */
1864 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
1865 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
1866 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
1867 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
1870 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
1871 *srcX0, *srcX1, *dstX0, *dstX1);
1872 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
1873 *srcY0, *srcY1, *dstY0, *dstY1);
1876 /* trivial rejection tests */
1877 if (*dstX0
== *dstX1
)
1878 return GL_FALSE
; /* no width */
1879 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
1880 return GL_FALSE
; /* totally out (left) of bounds */
1881 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
1882 return GL_FALSE
; /* totally out (right) of bounds */
1884 if (*dstY0
== *dstY1
)
1886 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
1888 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
1891 if (*srcX0
== *srcX1
)
1893 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
1895 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
1898 if (*srcY0
== *srcY1
)
1900 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
1902 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
1908 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
1909 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
1910 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
1911 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
1914 * src clip (just swap src/dst values from above)
1916 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
1917 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
1918 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
1919 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
1922 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
1923 *srcX0, *srcX1, *dstX0, *dstX1);
1924 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
1925 *srcY0, *srcY1, *dstY0, *dstY1);
1928 ASSERT(*dstX0
>= dstXmin
);
1929 ASSERT(*dstX0
<= dstXmax
);
1930 ASSERT(*dstX1
>= dstXmin
);
1931 ASSERT(*dstX1
<= dstXmax
);
1933 ASSERT(*dstY0
>= dstYmin
);
1934 ASSERT(*dstY0
<= dstYmax
);
1935 ASSERT(*dstY1
>= dstYmin
);
1936 ASSERT(*dstY1
<= dstYmax
);
1938 ASSERT(*srcX0
>= srcXmin
);
1939 ASSERT(*srcX0
<= srcXmax
);
1940 ASSERT(*srcX1
>= srcXmin
);
1941 ASSERT(*srcX1
<= srcXmax
);
1943 ASSERT(*srcY0
>= srcYmin
);
1944 ASSERT(*srcY0
<= srcYmax
);
1945 ASSERT(*srcY1
>= srcYmin
);
1946 ASSERT(*srcY1
<= srcYmax
);