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 GL_UNSIGNED_SHORT_5_6_5
:
72 case GL_UNSIGNED_SHORT_5_6_5_REV
:
73 case GL_UNSIGNED_SHORT_4_4_4_4
:
74 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
75 case GL_UNSIGNED_SHORT_5_5_5_1
:
76 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
77 case GL_UNSIGNED_INT_8_8_8_8
:
78 case GL_UNSIGNED_INT_8_8_8_8_REV
:
79 case GL_UNSIGNED_INT_10_10_10_2
:
80 case GL_UNSIGNED_INT_2_10_10_10_REV
:
81 case GL_UNSIGNED_SHORT_8_8_MESA
:
82 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
83 case GL_UNSIGNED_INT_24_8_EXT
:
93 * Flip the order of the 2 bytes in each word in the given array.
96 * \param n number of words.
99 _mesa_swap2( GLushort
*p
, GLuint n
)
102 for (i
= 0; i
< n
; i
++) {
103 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
110 * Flip the order of the 4 bytes in each word in the given array.
113 _mesa_swap4( GLuint
*p
, GLuint n
)
116 for (i
= 0; i
< n
; i
++) {
119 | ((b
>> 8) & 0xff00)
120 | ((b
<< 8) & 0xff0000)
121 | ((b
<< 24) & 0xff000000);
128 * Get the size of a GL data type.
130 * \param type GL data type.
132 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
133 * if an invalid type enum.
136 _mesa_sizeof_type( GLenum type
)
141 case GL_UNSIGNED_BYTE
:
142 return sizeof(GLubyte
);
144 return sizeof(GLbyte
);
145 case GL_UNSIGNED_SHORT
:
146 return sizeof(GLushort
);
148 return sizeof(GLshort
);
149 case GL_UNSIGNED_INT
:
150 return sizeof(GLuint
);
152 return sizeof(GLint
);
154 return sizeof(GLfloat
);
156 return sizeof(GLdouble
);
157 case GL_HALF_FLOAT_ARB
:
158 return sizeof(GLhalfARB
);
160 return sizeof(GLfixed
);
168 * Same as _mesa_sizeof_type() but also accepting the packed pixel
172 _mesa_sizeof_packed_type( GLenum type
)
177 case GL_UNSIGNED_BYTE
:
178 return sizeof(GLubyte
);
180 return sizeof(GLbyte
);
181 case GL_UNSIGNED_SHORT
:
182 return sizeof(GLushort
);
184 return sizeof(GLshort
);
185 case GL_UNSIGNED_INT
:
186 return sizeof(GLuint
);
188 return sizeof(GLint
);
189 case GL_HALF_FLOAT_ARB
:
190 return sizeof(GLhalfARB
);
192 return sizeof(GLfloat
);
193 case GL_UNSIGNED_BYTE_3_3_2
:
194 return sizeof(GLubyte
);
195 case GL_UNSIGNED_BYTE_2_3_3_REV
:
196 return sizeof(GLubyte
);
197 case GL_UNSIGNED_SHORT_5_6_5
:
198 return sizeof(GLushort
);
199 case GL_UNSIGNED_SHORT_5_6_5_REV
:
200 return sizeof(GLushort
);
201 case GL_UNSIGNED_SHORT_4_4_4_4
:
202 return sizeof(GLushort
);
203 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
204 return sizeof(GLushort
);
205 case GL_UNSIGNED_SHORT_5_5_5_1
:
206 return sizeof(GLushort
);
207 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
208 return sizeof(GLushort
);
209 case GL_UNSIGNED_INT_8_8_8_8
:
210 return sizeof(GLuint
);
211 case GL_UNSIGNED_INT_8_8_8_8_REV
:
212 return sizeof(GLuint
);
213 case GL_UNSIGNED_INT_10_10_10_2
:
214 return sizeof(GLuint
);
215 case GL_UNSIGNED_INT_2_10_10_10_REV
:
216 return sizeof(GLuint
);
217 case GL_UNSIGNED_SHORT_8_8_MESA
:
218 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
219 return sizeof(GLushort
);
220 case GL_UNSIGNED_INT_24_8_EXT
:
221 return sizeof(GLuint
);
229 * Get the number of components in a pixel format.
231 * \param format pixel format.
233 * \return the number of components in the given format, or -1 if a bad format.
236 _mesa_components_in_format( GLenum format
)
240 case GL_COLOR_INDEX1_EXT
:
241 case GL_COLOR_INDEX2_EXT
:
242 case GL_COLOR_INDEX4_EXT
:
243 case GL_COLOR_INDEX8_EXT
:
244 case GL_COLOR_INDEX12_EXT
:
245 case GL_COLOR_INDEX16_EXT
:
246 case GL_STENCIL_INDEX
:
247 case GL_DEPTH_COMPONENT
:
249 case GL_RED_INTEGER_EXT
:
251 case GL_GREEN_INTEGER_EXT
:
253 case GL_BLUE_INTEGER_EXT
:
255 case GL_ALPHA_INTEGER_EXT
:
257 case GL_LUMINANCE_INTEGER_EXT
:
260 case GL_LUMINANCE_ALPHA
:
261 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
265 case GL_RGB_INTEGER_EXT
:
268 case GL_RGBA_INTEGER_EXT
:
278 case GL_DEPTH_STENCIL_EXT
:
290 * Get the bytes per pixel of pixel format type pair.
292 * \param format pixel format.
293 * \param type pixel type.
295 * \return bytes per pixel, or -1 if a bad format or type was given.
298 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
300 GLint comps
= _mesa_components_in_format( format
);
306 return 0; /* special case */
308 case GL_UNSIGNED_BYTE
:
309 return comps
* sizeof(GLubyte
);
311 case GL_UNSIGNED_SHORT
:
312 return comps
* sizeof(GLshort
);
314 case GL_UNSIGNED_INT
:
315 return comps
* sizeof(GLint
);
317 return comps
* sizeof(GLfloat
);
318 case GL_HALF_FLOAT_ARB
:
319 return comps
* sizeof(GLhalfARB
);
320 case GL_UNSIGNED_BYTE_3_3_2
:
321 case GL_UNSIGNED_BYTE_2_3_3_REV
:
322 if (format
== GL_RGB
|| format
== GL_BGR
||
323 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
324 return sizeof(GLubyte
);
326 return -1; /* error */
327 case GL_UNSIGNED_SHORT_5_6_5
:
328 case GL_UNSIGNED_SHORT_5_6_5_REV
:
329 if (format
== GL_RGB
|| format
== GL_BGR
||
330 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
331 return sizeof(GLushort
);
333 return -1; /* error */
334 case GL_UNSIGNED_SHORT_4_4_4_4
:
335 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
336 case GL_UNSIGNED_SHORT_5_5_5_1
:
337 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
338 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
339 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
340 return sizeof(GLushort
);
343 case GL_UNSIGNED_INT_8_8_8_8
:
344 case GL_UNSIGNED_INT_8_8_8_8_REV
:
345 case GL_UNSIGNED_INT_10_10_10_2
:
346 case GL_UNSIGNED_INT_2_10_10_10_REV
:
347 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
348 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
349 return sizeof(GLuint
);
352 case GL_UNSIGNED_SHORT_8_8_MESA
:
353 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
354 if (format
== GL_YCBCR_MESA
)
355 return sizeof(GLushort
);
358 case GL_UNSIGNED_INT_24_8_EXT
:
359 if (format
== GL_DEPTH_STENCIL_EXT
)
360 return sizeof(GLuint
);
370 * Test for a legal pixel format and type.
372 * \param format pixel format.
373 * \param type pixel type.
375 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
379 _mesa_is_legal_format_and_type(const struct gl_context
*ctx
,
380 GLenum format
, GLenum type
)
384 case GL_STENCIL_INDEX
:
388 case GL_UNSIGNED_BYTE
:
390 case GL_UNSIGNED_SHORT
:
392 case GL_UNSIGNED_INT
:
395 case GL_HALF_FLOAT_ARB
:
396 return ctx
->Extensions
.ARB_half_float_pixel
;
404 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
408 case GL_LUMINANCE_ALPHA
:
409 case GL_DEPTH_COMPONENT
:
412 case GL_UNSIGNED_BYTE
:
414 case GL_UNSIGNED_SHORT
:
416 case GL_UNSIGNED_INT
:
419 case GL_HALF_FLOAT_ARB
:
420 return ctx
->Extensions
.ARB_half_float_pixel
;
425 if (!ctx
->Extensions
.ARB_texture_rg
)
430 case GL_UNSIGNED_BYTE
:
432 case GL_UNSIGNED_SHORT
:
434 case GL_UNSIGNED_INT
:
437 case GL_HALF_FLOAT_ARB
:
438 return ctx
->Extensions
.ARB_half_float_pixel
;
445 case GL_UNSIGNED_BYTE
:
447 case GL_UNSIGNED_SHORT
:
449 case GL_UNSIGNED_INT
:
451 case GL_UNSIGNED_BYTE_3_3_2
:
452 case GL_UNSIGNED_BYTE_2_3_3_REV
:
453 case GL_UNSIGNED_SHORT_5_6_5
:
454 case GL_UNSIGNED_SHORT_5_6_5_REV
:
456 case GL_HALF_FLOAT_ARB
:
457 return ctx
->Extensions
.ARB_half_float_pixel
;
463 /* NOTE: no packed types are supported with BGR. That's
464 * intentional, according to the GL spec.
467 case GL_UNSIGNED_BYTE
:
469 case GL_UNSIGNED_SHORT
:
471 case GL_UNSIGNED_INT
:
474 case GL_HALF_FLOAT_ARB
:
475 return ctx
->Extensions
.ARB_half_float_pixel
;
484 case GL_UNSIGNED_BYTE
:
486 case GL_UNSIGNED_SHORT
:
488 case GL_UNSIGNED_INT
:
490 case GL_UNSIGNED_SHORT_4_4_4_4
:
491 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
492 case GL_UNSIGNED_SHORT_5_5_5_1
:
493 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
494 case GL_UNSIGNED_INT_8_8_8_8
:
495 case GL_UNSIGNED_INT_8_8_8_8_REV
:
496 case GL_UNSIGNED_INT_10_10_10_2
:
497 case GL_UNSIGNED_INT_2_10_10_10_REV
:
499 case GL_HALF_FLOAT_ARB
:
500 return ctx
->Extensions
.ARB_half_float_pixel
;
505 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
506 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
510 case GL_DEPTH_STENCIL_EXT
:
511 if (ctx
->Extensions
.EXT_packed_depth_stencil
512 && type
== GL_UNSIGNED_INT_24_8_EXT
)
520 case GL_UNSIGNED_BYTE
:
522 case GL_UNSIGNED_SHORT
:
524 case GL_UNSIGNED_INT
:
531 /* integer-valued formats */
532 case GL_RED_INTEGER_EXT
:
533 case GL_GREEN_INTEGER_EXT
:
534 case GL_BLUE_INTEGER_EXT
:
535 case GL_ALPHA_INTEGER_EXT
:
538 case GL_UNSIGNED_BYTE
:
540 case GL_UNSIGNED_SHORT
:
542 case GL_UNSIGNED_INT
:
543 return ctx
->Extensions
.EXT_texture_integer
;
548 case GL_RGB_INTEGER_EXT
:
551 case GL_UNSIGNED_BYTE
:
553 case GL_UNSIGNED_SHORT
:
555 case GL_UNSIGNED_INT
:
556 case GL_UNSIGNED_BYTE_3_3_2
:
557 case GL_UNSIGNED_BYTE_2_3_3_REV
:
558 case GL_UNSIGNED_SHORT_5_6_5
:
559 case GL_UNSIGNED_SHORT_5_6_5_REV
:
560 return ctx
->Extensions
.EXT_texture_integer
;
565 case GL_BGR_INTEGER_EXT
:
568 case GL_UNSIGNED_BYTE
:
570 case GL_UNSIGNED_SHORT
:
572 case GL_UNSIGNED_INT
:
573 /* NOTE: no packed formats w/ BGR format */
574 return ctx
->Extensions
.EXT_texture_integer
;
579 case GL_RGBA_INTEGER_EXT
:
580 case GL_BGRA_INTEGER_EXT
:
583 case GL_UNSIGNED_BYTE
:
585 case GL_UNSIGNED_SHORT
:
587 case GL_UNSIGNED_INT
:
588 case GL_UNSIGNED_SHORT_4_4_4_4
:
589 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
590 case GL_UNSIGNED_SHORT_5_5_5_1
:
591 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
592 case GL_UNSIGNED_INT_8_8_8_8
:
593 case GL_UNSIGNED_INT_8_8_8_8_REV
:
594 case GL_UNSIGNED_INT_10_10_10_2
:
595 case GL_UNSIGNED_INT_2_10_10_10_REV
:
596 return ctx
->Extensions
.EXT_texture_integer
;
601 case GL_LUMINANCE_INTEGER_EXT
:
602 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
605 case GL_UNSIGNED_BYTE
:
607 case GL_UNSIGNED_SHORT
:
609 case GL_UNSIGNED_INT
:
610 return ctx
->Extensions
.EXT_texture_integer
;
623 * Test if the given image format is a color/RGBA format (i.e., not color
624 * index, depth, stencil, etc).
625 * \param format the image format value (may by an internal texture format)
626 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
629 _mesa_is_color_format(GLenum format
)
647 case GL_LUMINANCE_ALPHA
:
648 case GL_LUMINANCE4_ALPHA4
:
649 case GL_LUMINANCE6_ALPHA2
:
650 case GL_LUMINANCE8_ALPHA8
:
651 case GL_LUMINANCE12_ALPHA4
:
652 case GL_LUMINANCE12_ALPHA12
:
653 case GL_LUMINANCE16_ALPHA16
:
685 /* float texture formats */
686 case GL_ALPHA16F_ARB
:
687 case GL_ALPHA32F_ARB
:
688 case GL_LUMINANCE16F_ARB
:
689 case GL_LUMINANCE32F_ARB
:
690 case GL_LUMINANCE_ALPHA16F_ARB
:
691 case GL_LUMINANCE_ALPHA32F_ARB
:
692 case GL_INTENSITY16F_ARB
:
693 case GL_INTENSITY32F_ARB
:
702 /* compressed formats */
703 case GL_COMPRESSED_ALPHA
:
704 case GL_COMPRESSED_LUMINANCE
:
705 case GL_COMPRESSED_LUMINANCE_ALPHA
:
706 case GL_COMPRESSED_INTENSITY
:
707 case GL_COMPRESSED_RED
:
708 case GL_COMPRESSED_RG
:
709 case GL_COMPRESSED_RGB
:
710 case GL_COMPRESSED_RGBA
:
715 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
716 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
717 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
718 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
719 case GL_COMPRESSED_RGB_FXT1_3DFX
:
720 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
721 #if FEATURE_EXT_texture_sRGB
724 case GL_SRGB_ALPHA_EXT
:
725 case GL_SRGB8_ALPHA8_EXT
:
726 case GL_SLUMINANCE_ALPHA_EXT
:
727 case GL_SLUMINANCE8_ALPHA8_EXT
:
728 case GL_SLUMINANCE_EXT
:
729 case GL_SLUMINANCE8_EXT
:
730 case GL_COMPRESSED_SRGB_EXT
:
731 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
732 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
733 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
734 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
735 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
736 case GL_COMPRESSED_SLUMINANCE_EXT
:
737 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
738 #endif /* FEATURE_EXT_texture_sRGB */
739 case GL_COMPRESSED_RED_RGTC1
:
740 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
741 case GL_COMPRESSED_RG_RGTC2
:
742 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
743 /* signed, normalized texture formats */
746 /* generic integer formats */
747 case GL_RED_INTEGER_EXT
:
748 case GL_GREEN_INTEGER_EXT
:
749 case GL_BLUE_INTEGER_EXT
:
750 case GL_ALPHA_INTEGER_EXT
:
751 case GL_RGB_INTEGER_EXT
:
752 case GL_RGBA_INTEGER_EXT
:
753 case GL_BGR_INTEGER_EXT
:
754 case GL_BGRA_INTEGER_EXT
:
755 case GL_LUMINANCE_INTEGER_EXT
:
756 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
757 /* sized integer formats */
758 case GL_RGBA32UI_EXT
:
760 case GL_ALPHA32UI_EXT
:
761 case GL_INTENSITY32UI_EXT
:
762 case GL_LUMINANCE32UI_EXT
:
763 case GL_LUMINANCE_ALPHA32UI_EXT
:
764 case GL_RGBA16UI_EXT
:
766 case GL_ALPHA16UI_EXT
:
767 case GL_INTENSITY16UI_EXT
:
768 case GL_LUMINANCE16UI_EXT
:
769 case GL_LUMINANCE_ALPHA16UI_EXT
:
772 case GL_ALPHA8UI_EXT
:
773 case GL_INTENSITY8UI_EXT
:
774 case GL_LUMINANCE8UI_EXT
:
775 case GL_LUMINANCE_ALPHA8UI_EXT
:
778 case GL_ALPHA32I_EXT
:
779 case GL_INTENSITY32I_EXT
:
780 case GL_LUMINANCE32I_EXT
:
781 case GL_LUMINANCE_ALPHA32I_EXT
:
784 case GL_ALPHA16I_EXT
:
785 case GL_INTENSITY16I_EXT
:
786 case GL_LUMINANCE16I_EXT
:
787 case GL_LUMINANCE_ALPHA16I_EXT
:
791 case GL_INTENSITY8I_EXT
:
792 case GL_LUMINANCE8I_EXT
:
793 case GL_LUMINANCE_ALPHA8I_EXT
:
795 case GL_YCBCR_MESA
: /* not considered to be RGB */
804 * Test if the given image format is a color index format.
807 _mesa_is_index_format(GLenum format
)
811 case GL_COLOR_INDEX1_EXT
:
812 case GL_COLOR_INDEX2_EXT
:
813 case GL_COLOR_INDEX4_EXT
:
814 case GL_COLOR_INDEX8_EXT
:
815 case GL_COLOR_INDEX12_EXT
:
816 case GL_COLOR_INDEX16_EXT
:
825 * Test if the given image format is a depth component format.
828 _mesa_is_depth_format(GLenum format
)
831 case GL_DEPTH_COMPONENT
:
832 case GL_DEPTH_COMPONENT16
:
833 case GL_DEPTH_COMPONENT24
:
834 case GL_DEPTH_COMPONENT32
:
843 * Test if the given image format is a stencil format.
846 _mesa_is_stencil_format(GLenum format
)
849 case GL_STENCIL_INDEX
:
850 case GL_DEPTH_STENCIL
:
859 * Test if the given image format is a YCbCr format.
862 _mesa_is_ycbcr_format(GLenum format
)
874 * Test if the given image format is a depth+stencil format.
877 _mesa_is_depthstencil_format(GLenum format
)
880 case GL_DEPTH24_STENCIL8_EXT
:
881 case GL_DEPTH_STENCIL_EXT
:
890 * Test if the given image format is a depth or stencil format.
893 _mesa_is_depth_or_stencil_format(GLenum format
)
896 case GL_DEPTH_COMPONENT
:
897 case GL_DEPTH_COMPONENT16
:
898 case GL_DEPTH_COMPONENT24
:
899 case GL_DEPTH_COMPONENT32
:
900 case GL_STENCIL_INDEX
:
901 case GL_STENCIL_INDEX1_EXT
:
902 case GL_STENCIL_INDEX4_EXT
:
903 case GL_STENCIL_INDEX8_EXT
:
904 case GL_STENCIL_INDEX16_EXT
:
905 case GL_DEPTH_STENCIL_EXT
:
906 case GL_DEPTH24_STENCIL8_EXT
:
915 * Test if the given image format is a dudv format.
918 _mesa_is_dudv_format(GLenum format
)
931 * Test if the given format is an integer (non-normalized) format.
934 _mesa_is_integer_format(GLenum format
)
937 /* generic integer formats */
938 case GL_RED_INTEGER_EXT
:
939 case GL_GREEN_INTEGER_EXT
:
940 case GL_BLUE_INTEGER_EXT
:
941 case GL_ALPHA_INTEGER_EXT
:
942 case GL_RGB_INTEGER_EXT
:
943 case GL_RGBA_INTEGER_EXT
:
944 case GL_BGR_INTEGER_EXT
:
945 case GL_BGRA_INTEGER_EXT
:
946 case GL_LUMINANCE_INTEGER_EXT
:
947 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
948 /* specific integer formats */
949 case GL_RGBA32UI_EXT
:
951 case GL_ALPHA32UI_EXT
:
952 case GL_INTENSITY32UI_EXT
:
953 case GL_LUMINANCE32UI_EXT
:
954 case GL_LUMINANCE_ALPHA32UI_EXT
:
955 case GL_RGBA16UI_EXT
:
957 case GL_ALPHA16UI_EXT
:
958 case GL_INTENSITY16UI_EXT
:
959 case GL_LUMINANCE16UI_EXT
:
960 case GL_LUMINANCE_ALPHA16UI_EXT
:
963 case GL_ALPHA8UI_EXT
:
964 case GL_INTENSITY8UI_EXT
:
965 case GL_LUMINANCE8UI_EXT
:
966 case GL_LUMINANCE_ALPHA8UI_EXT
:
969 case GL_ALPHA32I_EXT
:
970 case GL_INTENSITY32I_EXT
:
971 case GL_LUMINANCE32I_EXT
:
972 case GL_LUMINANCE_ALPHA32I_EXT
:
975 case GL_ALPHA16I_EXT
:
976 case GL_INTENSITY16I_EXT
:
977 case GL_LUMINANCE16I_EXT
:
978 case GL_LUMINANCE_ALPHA16I_EXT
:
982 case GL_INTENSITY8I_EXT
:
983 case GL_LUMINANCE8I_EXT
:
984 case GL_LUMINANCE_ALPHA8I_EXT
:
993 * Test if an image format is a supported compressed format.
994 * \param format the internal format token provided by the user.
995 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
998 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
1001 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1002 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1003 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1004 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1005 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
1010 return ctx
->Extensions
.S3_s3tc
;
1011 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1012 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1013 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1014 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1015 return ctx
->Extensions
.EXT_texture_sRGB
1016 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1017 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1018 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1019 return ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1020 case GL_COMPRESSED_RED_RGTC1
:
1021 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1022 case GL_COMPRESSED_RG_RGTC2
:
1023 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1024 return ctx
->Extensions
.ARB_texture_compression_rgtc
;
1032 * Return the address of a specific pixel in an image (1D, 2D or 3D).
1034 * Pixel unpacking/packing parameters are observed according to \p packing.
1036 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
1037 * \param image starting address of image data
1038 * \param width the image width
1039 * \param height theimage height
1040 * \param format the pixel format
1041 * \param type the pixel data type
1042 * \param packing the pixelstore attributes
1043 * \param img which image in the volume (0 for 1D or 2D images)
1044 * \param row row of pixel in the image (0 for 1D images)
1045 * \param column column of pixel in the image
1047 * \return address of pixel on success, or NULL on error.
1049 * \sa gl_pixelstore_attrib.
1052 _mesa_image_address( GLuint dimensions
,
1053 const struct gl_pixelstore_attrib
*packing
,
1054 const GLvoid
*image
,
1055 GLsizei width
, GLsizei height
,
1056 GLenum format
, GLenum type
,
1057 GLint img
, GLint row
, GLint column
)
1059 GLint alignment
; /* 1, 2 or 4 */
1060 GLint pixels_per_row
;
1061 GLint rows_per_image
;
1064 GLint skipimages
; /* for 3-D volume images */
1065 GLubyte
*pixel_addr
;
1067 ASSERT(dimensions
>= 1 && dimensions
<= 3);
1069 alignment
= packing
->Alignment
;
1070 if (packing
->RowLength
> 0) {
1071 pixels_per_row
= packing
->RowLength
;
1074 pixels_per_row
= width
;
1076 if (packing
->ImageHeight
> 0) {
1077 rows_per_image
= packing
->ImageHeight
;
1080 rows_per_image
= height
;
1083 skippixels
= packing
->SkipPixels
;
1084 /* Note: SKIP_ROWS _is_ used for 1D images */
1085 skiprows
= packing
->SkipRows
;
1086 /* Note: SKIP_IMAGES is only used for 3D images */
1087 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
1089 if (type
== GL_BITMAP
) {
1091 GLint comp_per_pixel
; /* components per pixel */
1092 GLint bytes_per_comp
; /* bytes per component */
1093 GLint bytes_per_row
;
1094 GLint bytes_per_image
;
1096 /* Compute bytes per component */
1097 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
1098 if (bytes_per_comp
< 0) {
1102 /* Compute number of components per pixel */
1103 comp_per_pixel
= _mesa_components_in_format( format
);
1104 if (comp_per_pixel
< 0) {
1108 bytes_per_row
= alignment
1109 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
1111 bytes_per_image
= bytes_per_row
* rows_per_image
;
1113 pixel_addr
= (GLubyte
*) image
1114 + (skipimages
+ img
) * bytes_per_image
1115 + (skiprows
+ row
) * bytes_per_row
1116 + (skippixels
+ column
) / 8;
1119 /* Non-BITMAP data */
1120 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
1123 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
1125 /* The pixel type and format should have been error checked earlier */
1126 assert(bytes_per_pixel
> 0);
1128 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
1129 remainder
= bytes_per_row
% alignment
;
1131 bytes_per_row
+= (alignment
- remainder
);
1133 ASSERT(bytes_per_row
% alignment
== 0);
1135 bytes_per_image
= bytes_per_row
* rows_per_image
;
1137 if (packing
->Invert
) {
1138 /* set pixel_addr to the last row */
1139 topOfImage
= bytes_per_row
* (height
- 1);
1140 bytes_per_row
= -bytes_per_row
;
1146 /* compute final pixel address */
1147 pixel_addr
= (GLubyte
*) image
1148 + (skipimages
+ img
) * bytes_per_image
1150 + (skiprows
+ row
) * bytes_per_row
1151 + (skippixels
+ column
) * bytes_per_pixel
;
1154 return (GLvoid
*) pixel_addr
;
1159 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
1160 const GLvoid
*image
,
1162 GLenum format
, GLenum type
,
1165 return _mesa_image_address(1, packing
, image
, width
, 1,
1166 format
, type
, 0, 0, column
);
1171 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
1172 const GLvoid
*image
,
1173 GLsizei width
, GLsizei height
,
1174 GLenum format
, GLenum type
,
1175 GLint row
, GLint column
)
1177 return _mesa_image_address(2, packing
, image
, width
, height
,
1178 format
, type
, 0, row
, column
);
1183 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
1184 const GLvoid
*image
,
1185 GLsizei width
, GLsizei height
,
1186 GLenum format
, GLenum type
,
1187 GLint img
, GLint row
, GLint column
)
1189 return _mesa_image_address(3, packing
, image
, width
, height
,
1190 format
, type
, img
, row
, column
);
1196 * Compute the stride (in bytes) between image rows.
1198 * \param packing the pixelstore attributes
1199 * \param width image width.
1200 * \param format pixel format.
1201 * \param type pixel data type.
1203 * \return the stride in bytes for the given parameters, or -1 if error
1206 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
1207 GLint width
, GLenum format
, GLenum type
)
1209 GLint bytesPerRow
, remainder
;
1213 if (type
== GL_BITMAP
) {
1214 if (packing
->RowLength
== 0) {
1215 bytesPerRow
= (width
+ 7) / 8;
1218 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1222 /* Non-BITMAP data */
1223 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1224 if (bytesPerPixel
<= 0)
1225 return -1; /* error */
1226 if (packing
->RowLength
== 0) {
1227 bytesPerRow
= bytesPerPixel
* width
;
1230 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1234 remainder
= bytesPerRow
% packing
->Alignment
;
1235 if (remainder
> 0) {
1236 bytesPerRow
+= (packing
->Alignment
- remainder
);
1239 if (packing
->Invert
) {
1240 /* negate the bytes per row (negative row stride) */
1241 bytesPerRow
= -bytesPerRow
;
1249 * Compute the stride between images in a 3D texture (in bytes) for the given
1250 * pixel packing parameters and image width, format and type.
1253 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1254 GLint width
, GLint height
,
1255 GLenum format
, GLenum type
)
1257 GLint bytesPerRow
, bytesPerImage
, remainder
;
1261 if (type
== GL_BITMAP
) {
1262 if (packing
->RowLength
== 0) {
1263 bytesPerRow
= (width
+ 7) / 8;
1266 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1270 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1272 if (bytesPerPixel
<= 0)
1273 return -1; /* error */
1274 if (packing
->RowLength
== 0) {
1275 bytesPerRow
= bytesPerPixel
* width
;
1278 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1282 remainder
= bytesPerRow
% packing
->Alignment
;
1284 bytesPerRow
+= (packing
->Alignment
- remainder
);
1286 if (packing
->ImageHeight
== 0)
1287 bytesPerImage
= bytesPerRow
* height
;
1289 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1291 return bytesPerImage
;
1297 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1298 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1299 * "On" bits will set texels to \p onValue.
1300 * "Off" bits will not modify texels.
1301 * \param width src bitmap width in pixels
1302 * \param height src bitmap height in pixels
1303 * \param unpack bitmap unpacking state
1304 * \param bitmap the src bitmap data
1305 * \param destBuffer start of dest buffer
1306 * \param destStride row stride in dest buffer
1307 * \param onValue if bit is 1, set destBuffer pixel to this value
1310 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1311 const struct gl_pixelstore_attrib
*unpack
,
1312 const GLubyte
*bitmap
,
1313 GLubyte
*destBuffer
, GLint destStride
,
1316 const GLubyte
*srcRow
= (const GLubyte
*)
1317 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1318 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1319 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1320 GL_COLOR_INDEX
, GL_BITMAP
);
1323 #define SET_PIXEL(COL, ROW) \
1324 destBuffer[(ROW) * destStride + (COL)] = onValue;
1326 for (row
= 0; row
< height
; row
++) {
1327 const GLubyte
*src
= srcRow
;
1329 if (unpack
->LsbFirst
) {
1331 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1332 for (col
= 0; col
< width
; col
++) {
1335 SET_PIXEL(col
, row
);
1347 /* get ready for next row */
1353 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1354 for (col
= 0; col
< width
; col
++) {
1357 SET_PIXEL(col
, row
);
1369 /* get ready for next row */
1374 srcRow
+= srcStride
;
1384 * Convert an array of RGBA colors from one datatype to another.
1385 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1388 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
1389 GLenum dstType
, GLvoid
*dst
,
1390 GLuint count
, const GLubyte mask
[])
1392 GLuint tempBuffer
[MAX_WIDTH
][4];
1393 const GLboolean useTemp
= (src
== dst
);
1395 ASSERT(srcType
!= dstType
);
1398 case GL_UNSIGNED_BYTE
:
1399 if (dstType
== GL_UNSIGNED_SHORT
) {
1400 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1401 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1403 for (i
= 0; i
< count
; i
++) {
1404 if (!mask
|| mask
[i
]) {
1405 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
1406 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
1407 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
1408 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
1412 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1415 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1416 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1418 ASSERT(dstType
== GL_FLOAT
);
1419 for (i
= 0; i
< count
; i
++) {
1420 if (!mask
|| mask
[i
]) {
1421 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
1422 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
1423 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
1424 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
1428 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1431 case GL_UNSIGNED_SHORT
:
1432 if (dstType
== GL_UNSIGNED_BYTE
) {
1433 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1434 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1436 for (i
= 0; i
< count
; i
++) {
1437 if (!mask
|| mask
[i
]) {
1438 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
1439 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
1440 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
1441 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
1445 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1448 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1449 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1451 ASSERT(dstType
== GL_FLOAT
);
1452 for (i
= 0; i
< count
; i
++) {
1453 if (!mask
|| mask
[i
]) {
1454 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
1455 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
1456 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
1457 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
1461 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1465 if (dstType
== GL_UNSIGNED_BYTE
) {
1466 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1467 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1469 for (i
= 0; i
< count
; i
++) {
1470 if (!mask
|| mask
[i
]) {
1471 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
1472 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
1473 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
1474 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
1478 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1481 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1482 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1484 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
1485 for (i
= 0; i
< count
; i
++) {
1486 if (!mask
|| mask
[i
]) {
1487 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
1488 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
1489 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
1490 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
1494 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1498 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
1506 * Perform basic clipping for glDrawPixels. The image's position and size
1507 * and the unpack SkipPixels and SkipRows are adjusted so that the image
1508 * region is entirely within the window and scissor bounds.
1509 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
1510 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
1511 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
1513 * \return GL_TRUE if image is ready for drawing or
1514 * GL_FALSE if image was completely clipped away (draw nothing)
1517 _mesa_clip_drawpixels(const struct gl_context
*ctx
,
1518 GLint
*destX
, GLint
*destY
,
1519 GLsizei
*width
, GLsizei
*height
,
1520 struct gl_pixelstore_attrib
*unpack
)
1522 const struct gl_framebuffer
*buffer
= ctx
->DrawBuffer
;
1524 if (unpack
->RowLength
== 0) {
1525 unpack
->RowLength
= *width
;
1528 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
1529 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
1532 if (*destX
< buffer
->_Xmin
) {
1533 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
1534 *width
-= (buffer
->_Xmin
- *destX
);
1535 *destX
= buffer
->_Xmin
;
1537 /* right clipping */
1538 if (*destX
+ *width
> buffer
->_Xmax
)
1539 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
1544 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
1545 /* bottom clipping */
1546 if (*destY
< buffer
->_Ymin
) {
1547 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
1548 *height
-= (buffer
->_Ymin
- *destY
);
1549 *destY
= buffer
->_Ymin
;
1552 if (*destY
+ *height
> buffer
->_Ymax
)
1553 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
1555 else { /* upside down */
1557 if (*destY
> buffer
->_Ymax
) {
1558 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
1559 *height
-= (*destY
- buffer
->_Ymax
);
1560 *destY
= buffer
->_Ymax
;
1562 /* bottom clipping */
1563 if (*destY
- *height
< buffer
->_Ymin
)
1564 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
1565 /* adjust destY so it's the first row to write to */
1577 * Perform clipping for glReadPixels. The image's window position
1578 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
1579 * so that the image region is entirely within the window bounds.
1580 * Note: this is different from _mesa_clip_drawpixels() in that the
1581 * scissor box is ignored, and we use the bounds of the current readbuffer
1584 * \return GL_TRUE if image is ready for drawing or
1585 * GL_FALSE if image was completely clipped away (draw nothing)
1588 _mesa_clip_readpixels(const struct gl_context
*ctx
,
1589 GLint
*srcX
, GLint
*srcY
,
1590 GLsizei
*width
, GLsizei
*height
,
1591 struct gl_pixelstore_attrib
*pack
)
1593 const struct gl_framebuffer
*buffer
= ctx
->ReadBuffer
;
1595 if (pack
->RowLength
== 0) {
1596 pack
->RowLength
= *width
;
1601 pack
->SkipPixels
+= (0 - *srcX
);
1602 *width
-= (0 - *srcX
);
1605 /* right clipping */
1606 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
1607 *width
-= (*srcX
+ *width
- buffer
->Width
);
1612 /* bottom clipping */
1614 pack
->SkipRows
+= (0 - *srcY
);
1615 *height
-= (0 - *srcY
);
1619 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
1620 *height
-= (*srcY
+ *height
- buffer
->Height
);
1630 * Do clipping for a glCopyTexSubImage call.
1631 * The framebuffer source region might extend outside the framebuffer
1632 * bounds. Clip the source region against the framebuffer bounds and
1633 * adjust the texture/dest position and size accordingly.
1635 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
1638 _mesa_clip_copytexsubimage(const struct gl_context
*ctx
,
1639 GLint
*destX
, GLint
*destY
,
1640 GLint
*srcX
, GLint
*srcY
,
1641 GLsizei
*width
, GLsizei
*height
)
1643 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
1644 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
1646 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
1647 srcX
, srcY
, width
, height
)) {
1648 *destX
= *destX
+ *srcX
- srcX0
;
1649 *destY
= *destY
+ *srcY
- srcY0
;
1661 * Clip the rectangle defined by (x, y, width, height) against the bounds
1662 * specified by [xmin, xmax) and [ymin, ymax).
1663 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
1666 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
1667 GLint xmax
, GLint ymax
,
1669 GLsizei
*width
, GLsizei
*height
)
1673 *width
-= (xmin
- *x
);
1677 /* right clipping */
1678 if (*x
+ *width
> xmax
)
1679 *width
-= (*x
+ *width
- xmax
);
1684 /* bottom (or top) clipping */
1686 *height
-= (ymin
- *y
);
1690 /* top (or bottom) clipping */
1691 if (*y
+ *height
> ymax
)
1692 *height
-= (*y
+ *height
- ymax
);
1702 * Clip dst coords against Xmax (or Ymax).
1705 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
1706 GLint
*dstX0
, GLint
*dstX1
,
1711 if (*dstX1
> maxValue
) {
1712 /* X1 outside right edge */
1713 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
1714 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1715 /* chop off [t, 1] part */
1716 ASSERT(t
>= 0.0 && t
<= 1.0);
1718 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1719 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1721 else if (*dstX0
> maxValue
) {
1722 /* X0 outside right edge */
1723 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
1724 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1725 /* chop off [t, 1] part */
1726 ASSERT(t
>= 0.0 && t
<= 1.0);
1728 bias
= (*srcX0
< *srcX1
) ? -0.5F
: 0.5F
;
1729 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1735 * Clip dst coords against Xmin (or Ymin).
1738 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
1739 GLint
*dstX0
, GLint
*dstX1
,
1744 if (*dstX0
< minValue
) {
1745 /* X0 outside left edge */
1746 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
1747 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1748 /* chop off [0, t] part */
1749 ASSERT(t
>= 0.0 && t
<= 1.0);
1751 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
; /* flipped??? */
1752 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1754 else if (*dstX1
< minValue
) {
1755 /* X1 outside left edge */
1756 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
1757 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1758 /* chop off [0, t] part */
1759 ASSERT(t
>= 0.0 && t
<= 1.0);
1761 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1762 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1768 * Do clipping of blit src/dest rectangles.
1769 * The dest rect is clipped against both the buffer bounds and scissor bounds.
1770 * The src rect is just clipped against the buffer bounds.
1772 * When either the src or dest rect is clipped, the other is also clipped
1775 * Note that X0 need not be less than X1 (same for Y) for either the source
1776 * and dest rects. That makes the clipping a little trickier.
1778 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
1781 _mesa_clip_blit(struct gl_context
*ctx
,
1782 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
1783 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
1785 const GLint srcXmin
= 0;
1786 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
1787 const GLint srcYmin
= 0;
1788 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
1790 /* these include scissor bounds */
1791 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
1792 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
1793 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
1794 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
1797 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
1798 *srcX0, *srcX1, *dstX0, *dstX1);
1799 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
1800 *srcY0, *srcY1, *dstY0, *dstY1);
1803 /* trivial rejection tests */
1804 if (*dstX0
== *dstX1
)
1805 return GL_FALSE
; /* no width */
1806 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
1807 return GL_FALSE
; /* totally out (left) of bounds */
1808 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
1809 return GL_FALSE
; /* totally out (right) of bounds */
1811 if (*dstY0
== *dstY1
)
1813 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
1815 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
1818 if (*srcX0
== *srcX1
)
1820 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
1822 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
1825 if (*srcY0
== *srcY1
)
1827 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
1829 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
1835 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
1836 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
1837 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
1838 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
1841 * src clip (just swap src/dst values from above)
1843 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
1844 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
1845 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
1846 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
1849 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
1850 *srcX0, *srcX1, *dstX0, *dstX1);
1851 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
1852 *srcY0, *srcY1, *dstY0, *dstY1);
1855 ASSERT(*dstX0
>= dstXmin
);
1856 ASSERT(*dstX0
<= dstXmax
);
1857 ASSERT(*dstX1
>= dstXmin
);
1858 ASSERT(*dstX1
<= dstXmax
);
1860 ASSERT(*dstY0
>= dstYmin
);
1861 ASSERT(*dstY0
<= dstYmax
);
1862 ASSERT(*dstY1
>= dstYmin
);
1863 ASSERT(*dstY1
<= dstYmax
);
1865 ASSERT(*srcX0
>= srcXmin
);
1866 ASSERT(*srcX0
<= srcXmax
);
1867 ASSERT(*srcX1
>= srcXmin
);
1868 ASSERT(*srcX1
<= srcXmax
);
1870 ASSERT(*srcY0
>= srcYmin
);
1871 ASSERT(*srcY0
<= srcYmax
);
1872 ASSERT(*srcY1
>= srcYmin
);
1873 ASSERT(*srcY1
<= srcYmax
);