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.
42 * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
43 * we later convert the float to a packed integer value (such as for
44 * GL_RGB5_A1) because we'll wind up with a non-zero value.
46 * We redefine the macros here so zero is handled correctly.
49 #define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
52 #define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
56 /** Compute ceiling of integer quotient of A divided by B. */
57 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
61 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
64 _mesa_type_is_packed(GLenum type
)
67 case GL_UNSIGNED_BYTE_3_3_2
:
68 case GL_UNSIGNED_BYTE_2_3_3_REV
:
69 case GL_UNSIGNED_SHORT_5_6_5
:
70 case GL_UNSIGNED_SHORT_5_6_5_REV
:
71 case GL_UNSIGNED_SHORT_4_4_4_4
:
72 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
73 case GL_UNSIGNED_SHORT_5_5_5_1
:
74 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
75 case GL_UNSIGNED_INT_8_8_8_8
:
76 case GL_UNSIGNED_INT_8_8_8_8_REV
:
77 case GL_UNSIGNED_INT_10_10_10_2
:
78 case GL_UNSIGNED_INT_2_10_10_10_REV
:
79 case GL_UNSIGNED_SHORT_8_8_MESA
:
80 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
81 case GL_UNSIGNED_INT_24_8_EXT
:
91 * Flip the order of the 2 bytes in each word in the given array.
94 * \param n number of words.
97 _mesa_swap2( GLushort
*p
, GLuint n
)
100 for (i
= 0; i
< n
; i
++) {
101 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
108 * Flip the order of the 4 bytes in each word in the given array.
111 _mesa_swap4( GLuint
*p
, GLuint n
)
114 for (i
= 0; i
< n
; i
++) {
117 | ((b
>> 8) & 0xff00)
118 | ((b
<< 8) & 0xff0000)
119 | ((b
<< 24) & 0xff000000);
126 * Get the size of a GL data type.
128 * \param type GL data type.
130 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
131 * if an invalid type enum.
134 _mesa_sizeof_type( GLenum type
)
139 case GL_UNSIGNED_BYTE
:
140 return sizeof(GLubyte
);
142 return sizeof(GLbyte
);
143 case GL_UNSIGNED_SHORT
:
144 return sizeof(GLushort
);
146 return sizeof(GLshort
);
147 case GL_UNSIGNED_INT
:
148 return sizeof(GLuint
);
150 return sizeof(GLint
);
152 return sizeof(GLfloat
);
154 return sizeof(GLdouble
);
155 case GL_HALF_FLOAT_ARB
:
156 return sizeof(GLhalfARB
);
158 return sizeof(GLfixed
);
166 * Same as _mesa_sizeof_type() but also accepting the packed pixel
170 _mesa_sizeof_packed_type( GLenum type
)
175 case GL_UNSIGNED_BYTE
:
176 return sizeof(GLubyte
);
178 return sizeof(GLbyte
);
179 case GL_UNSIGNED_SHORT
:
180 return sizeof(GLushort
);
182 return sizeof(GLshort
);
183 case GL_UNSIGNED_INT
:
184 return sizeof(GLuint
);
186 return sizeof(GLint
);
187 case GL_HALF_FLOAT_ARB
:
188 return sizeof(GLhalfARB
);
190 return sizeof(GLfloat
);
191 case GL_UNSIGNED_BYTE_3_3_2
:
192 return sizeof(GLubyte
);
193 case GL_UNSIGNED_BYTE_2_3_3_REV
:
194 return sizeof(GLubyte
);
195 case GL_UNSIGNED_SHORT_5_6_5
:
196 return sizeof(GLushort
);
197 case GL_UNSIGNED_SHORT_5_6_5_REV
:
198 return sizeof(GLushort
);
199 case GL_UNSIGNED_SHORT_4_4_4_4
:
200 return sizeof(GLushort
);
201 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
202 return sizeof(GLushort
);
203 case GL_UNSIGNED_SHORT_5_5_5_1
:
204 return sizeof(GLushort
);
205 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
206 return sizeof(GLushort
);
207 case GL_UNSIGNED_INT_8_8_8_8
:
208 return sizeof(GLuint
);
209 case GL_UNSIGNED_INT_8_8_8_8_REV
:
210 return sizeof(GLuint
);
211 case GL_UNSIGNED_INT_10_10_10_2
:
212 return sizeof(GLuint
);
213 case GL_UNSIGNED_INT_2_10_10_10_REV
:
214 return sizeof(GLuint
);
215 case GL_UNSIGNED_SHORT_8_8_MESA
:
216 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
217 return sizeof(GLushort
);
218 case GL_UNSIGNED_INT_24_8_EXT
:
219 return sizeof(GLuint
);
227 * Get the number of components in a pixel format.
229 * \param format pixel format.
231 * \return the number of components in the given format, or -1 if a bad format.
234 _mesa_components_in_format( GLenum format
)
238 case GL_COLOR_INDEX1_EXT
:
239 case GL_COLOR_INDEX2_EXT
:
240 case GL_COLOR_INDEX4_EXT
:
241 case GL_COLOR_INDEX8_EXT
:
242 case GL_COLOR_INDEX12_EXT
:
243 case GL_COLOR_INDEX16_EXT
:
244 case GL_STENCIL_INDEX
:
245 case GL_DEPTH_COMPONENT
:
247 case GL_RED_INTEGER_EXT
:
249 case GL_GREEN_INTEGER_EXT
:
251 case GL_BLUE_INTEGER_EXT
:
253 case GL_ALPHA_INTEGER_EXT
:
255 case GL_LUMINANCE_INTEGER_EXT
:
258 case GL_LUMINANCE_ALPHA
:
259 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
263 case GL_RGB_INTEGER_EXT
:
266 case GL_RGBA_INTEGER_EXT
:
276 case GL_DEPTH_STENCIL_EXT
:
288 * Get the bytes per pixel of pixel format type pair.
290 * \param format pixel format.
291 * \param type pixel type.
293 * \return bytes per pixel, or -1 if a bad format or type was given.
296 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
298 GLint comps
= _mesa_components_in_format( format
);
304 return 0; /* special case */
306 case GL_UNSIGNED_BYTE
:
307 return comps
* sizeof(GLubyte
);
309 case GL_UNSIGNED_SHORT
:
310 return comps
* sizeof(GLshort
);
312 case GL_UNSIGNED_INT
:
313 return comps
* sizeof(GLint
);
315 return comps
* sizeof(GLfloat
);
316 case GL_HALF_FLOAT_ARB
:
317 return comps
* sizeof(GLhalfARB
);
318 case GL_UNSIGNED_BYTE_3_3_2
:
319 case GL_UNSIGNED_BYTE_2_3_3_REV
:
320 if (format
== GL_RGB
|| format
== GL_BGR
||
321 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
322 return sizeof(GLubyte
);
324 return -1; /* error */
325 case GL_UNSIGNED_SHORT_5_6_5
:
326 case GL_UNSIGNED_SHORT_5_6_5_REV
:
327 if (format
== GL_RGB
|| format
== GL_BGR
||
328 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
329 return sizeof(GLushort
);
331 return -1; /* error */
332 case GL_UNSIGNED_SHORT_4_4_4_4
:
333 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
334 case GL_UNSIGNED_SHORT_5_5_5_1
:
335 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
336 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
337 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
338 return sizeof(GLushort
);
341 case GL_UNSIGNED_INT_8_8_8_8
:
342 case GL_UNSIGNED_INT_8_8_8_8_REV
:
343 case GL_UNSIGNED_INT_10_10_10_2
:
344 case GL_UNSIGNED_INT_2_10_10_10_REV
:
345 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
346 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
347 return sizeof(GLuint
);
350 case GL_UNSIGNED_SHORT_8_8_MESA
:
351 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
352 if (format
== GL_YCBCR_MESA
)
353 return sizeof(GLushort
);
356 case GL_UNSIGNED_INT_24_8_EXT
:
357 if (format
== GL_DEPTH_STENCIL_EXT
)
358 return sizeof(GLuint
);
368 * Test for a legal pixel format and type.
370 * \param format pixel format.
371 * \param type pixel type.
373 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
377 _mesa_is_legal_format_and_type(const struct gl_context
*ctx
,
378 GLenum format
, GLenum type
)
382 case GL_STENCIL_INDEX
:
386 case GL_UNSIGNED_BYTE
:
388 case GL_UNSIGNED_SHORT
:
390 case GL_UNSIGNED_INT
:
393 case GL_HALF_FLOAT_ARB
:
394 return ctx
->Extensions
.ARB_half_float_pixel
;
402 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
406 case GL_LUMINANCE_ALPHA
:
407 case GL_DEPTH_COMPONENT
:
410 case GL_UNSIGNED_BYTE
:
412 case GL_UNSIGNED_SHORT
:
414 case GL_UNSIGNED_INT
:
417 case GL_HALF_FLOAT_ARB
:
418 return ctx
->Extensions
.ARB_half_float_pixel
;
423 if (!ctx
->Extensions
.ARB_texture_rg
)
428 case GL_UNSIGNED_BYTE
:
430 case GL_UNSIGNED_SHORT
:
432 case GL_UNSIGNED_INT
:
435 case GL_HALF_FLOAT_ARB
:
436 return ctx
->Extensions
.ARB_half_float_pixel
;
443 case GL_UNSIGNED_BYTE
:
445 case GL_UNSIGNED_SHORT
:
447 case GL_UNSIGNED_INT
:
449 case GL_UNSIGNED_BYTE_3_3_2
:
450 case GL_UNSIGNED_BYTE_2_3_3_REV
:
451 case GL_UNSIGNED_SHORT_5_6_5
:
452 case GL_UNSIGNED_SHORT_5_6_5_REV
:
454 case GL_HALF_FLOAT_ARB
:
455 return ctx
->Extensions
.ARB_half_float_pixel
;
461 /* NOTE: no packed types are supported with BGR. That's
462 * intentional, according to the GL spec.
465 case GL_UNSIGNED_BYTE
:
467 case GL_UNSIGNED_SHORT
:
469 case GL_UNSIGNED_INT
:
472 case GL_HALF_FLOAT_ARB
:
473 return ctx
->Extensions
.ARB_half_float_pixel
;
482 case GL_UNSIGNED_BYTE
:
484 case GL_UNSIGNED_SHORT
:
486 case GL_UNSIGNED_INT
:
488 case GL_UNSIGNED_SHORT_4_4_4_4
:
489 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
490 case GL_UNSIGNED_SHORT_5_5_5_1
:
491 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
492 case GL_UNSIGNED_INT_8_8_8_8
:
493 case GL_UNSIGNED_INT_8_8_8_8_REV
:
494 case GL_UNSIGNED_INT_10_10_10_2
:
495 case GL_UNSIGNED_INT_2_10_10_10_REV
:
497 case GL_HALF_FLOAT_ARB
:
498 return ctx
->Extensions
.ARB_half_float_pixel
;
503 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
504 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
508 case GL_DEPTH_STENCIL_EXT
:
509 if (ctx
->Extensions
.EXT_packed_depth_stencil
510 && type
== GL_UNSIGNED_INT_24_8_EXT
)
518 case GL_UNSIGNED_BYTE
:
520 case GL_UNSIGNED_SHORT
:
522 case GL_UNSIGNED_INT
:
529 /* integer-valued formats */
530 case GL_RED_INTEGER_EXT
:
531 case GL_GREEN_INTEGER_EXT
:
532 case GL_BLUE_INTEGER_EXT
:
533 case GL_ALPHA_INTEGER_EXT
:
536 case GL_UNSIGNED_BYTE
:
538 case GL_UNSIGNED_SHORT
:
540 case GL_UNSIGNED_INT
:
541 return ctx
->Extensions
.EXT_texture_integer
;
546 case GL_RGB_INTEGER_EXT
:
549 case GL_UNSIGNED_BYTE
:
551 case GL_UNSIGNED_SHORT
:
553 case GL_UNSIGNED_INT
:
554 case GL_UNSIGNED_BYTE_3_3_2
:
555 case GL_UNSIGNED_BYTE_2_3_3_REV
:
556 case GL_UNSIGNED_SHORT_5_6_5
:
557 case GL_UNSIGNED_SHORT_5_6_5_REV
:
558 return ctx
->Extensions
.EXT_texture_integer
;
563 case GL_BGR_INTEGER_EXT
:
566 case GL_UNSIGNED_BYTE
:
568 case GL_UNSIGNED_SHORT
:
570 case GL_UNSIGNED_INT
:
571 /* NOTE: no packed formats w/ BGR format */
572 return ctx
->Extensions
.EXT_texture_integer
;
577 case GL_RGBA_INTEGER_EXT
:
578 case GL_BGRA_INTEGER_EXT
:
581 case GL_UNSIGNED_BYTE
:
583 case GL_UNSIGNED_SHORT
:
585 case GL_UNSIGNED_INT
:
586 case GL_UNSIGNED_SHORT_4_4_4_4
:
587 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
588 case GL_UNSIGNED_SHORT_5_5_5_1
:
589 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
590 case GL_UNSIGNED_INT_8_8_8_8
:
591 case GL_UNSIGNED_INT_8_8_8_8_REV
:
592 case GL_UNSIGNED_INT_10_10_10_2
:
593 case GL_UNSIGNED_INT_2_10_10_10_REV
:
594 return ctx
->Extensions
.EXT_texture_integer
;
599 case GL_LUMINANCE_INTEGER_EXT
:
600 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
603 case GL_UNSIGNED_BYTE
:
605 case GL_UNSIGNED_SHORT
:
607 case GL_UNSIGNED_INT
:
608 return ctx
->Extensions
.EXT_texture_integer
;
621 * Test if the given image format is a color/RGBA format (i.e., not color
622 * index, depth, stencil, etc).
623 * \param format the image format value (may by an internal texture format)
624 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
627 _mesa_is_color_format(GLenum format
)
645 case GL_LUMINANCE_ALPHA
:
646 case GL_LUMINANCE4_ALPHA4
:
647 case GL_LUMINANCE6_ALPHA2
:
648 case GL_LUMINANCE8_ALPHA8
:
649 case GL_LUMINANCE12_ALPHA4
:
650 case GL_LUMINANCE12_ALPHA12
:
651 case GL_LUMINANCE16_ALPHA16
:
683 /* float texture formats */
684 case GL_ALPHA16F_ARB
:
685 case GL_ALPHA32F_ARB
:
686 case GL_LUMINANCE16F_ARB
:
687 case GL_LUMINANCE32F_ARB
:
688 case GL_LUMINANCE_ALPHA16F_ARB
:
689 case GL_LUMINANCE_ALPHA32F_ARB
:
690 case GL_INTENSITY16F_ARB
:
691 case GL_INTENSITY32F_ARB
:
700 /* compressed formats */
701 case GL_COMPRESSED_ALPHA
:
702 case GL_COMPRESSED_LUMINANCE
:
703 case GL_COMPRESSED_LUMINANCE_ALPHA
:
704 case GL_COMPRESSED_INTENSITY
:
705 case GL_COMPRESSED_RED
:
706 case GL_COMPRESSED_RG
:
707 case GL_COMPRESSED_RGB
:
708 case GL_COMPRESSED_RGBA
:
713 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
714 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
715 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
716 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
717 case GL_COMPRESSED_RGB_FXT1_3DFX
:
718 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
719 #if FEATURE_EXT_texture_sRGB
722 case GL_SRGB_ALPHA_EXT
:
723 case GL_SRGB8_ALPHA8_EXT
:
724 case GL_SLUMINANCE_ALPHA_EXT
:
725 case GL_SLUMINANCE8_ALPHA8_EXT
:
726 case GL_SLUMINANCE_EXT
:
727 case GL_SLUMINANCE8_EXT
:
728 case GL_COMPRESSED_SRGB_EXT
:
729 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
730 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
731 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
732 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
733 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
734 case GL_COMPRESSED_SLUMINANCE_EXT
:
735 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
736 #endif /* FEATURE_EXT_texture_sRGB */
737 case GL_COMPRESSED_RED_RGTC1
:
738 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
739 case GL_COMPRESSED_RG_RGTC2
:
740 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
741 /* signed, normalized texture formats */
744 /* generic integer formats */
745 case GL_RED_INTEGER_EXT
:
746 case GL_GREEN_INTEGER_EXT
:
747 case GL_BLUE_INTEGER_EXT
:
748 case GL_ALPHA_INTEGER_EXT
:
749 case GL_RGB_INTEGER_EXT
:
750 case GL_RGBA_INTEGER_EXT
:
751 case GL_BGR_INTEGER_EXT
:
752 case GL_BGRA_INTEGER_EXT
:
753 case GL_LUMINANCE_INTEGER_EXT
:
754 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
755 /* sized integer formats */
756 case GL_RGBA32UI_EXT
:
758 case GL_ALPHA32UI_EXT
:
759 case GL_INTENSITY32UI_EXT
:
760 case GL_LUMINANCE32UI_EXT
:
761 case GL_LUMINANCE_ALPHA32UI_EXT
:
762 case GL_RGBA16UI_EXT
:
764 case GL_ALPHA16UI_EXT
:
765 case GL_INTENSITY16UI_EXT
:
766 case GL_LUMINANCE16UI_EXT
:
767 case GL_LUMINANCE_ALPHA16UI_EXT
:
770 case GL_ALPHA8UI_EXT
:
771 case GL_INTENSITY8UI_EXT
:
772 case GL_LUMINANCE8UI_EXT
:
773 case GL_LUMINANCE_ALPHA8UI_EXT
:
776 case GL_ALPHA32I_EXT
:
777 case GL_INTENSITY32I_EXT
:
778 case GL_LUMINANCE32I_EXT
:
779 case GL_LUMINANCE_ALPHA32I_EXT
:
782 case GL_ALPHA16I_EXT
:
783 case GL_INTENSITY16I_EXT
:
784 case GL_LUMINANCE16I_EXT
:
785 case GL_LUMINANCE_ALPHA16I_EXT
:
789 case GL_INTENSITY8I_EXT
:
790 case GL_LUMINANCE8I_EXT
:
791 case GL_LUMINANCE_ALPHA8I_EXT
:
793 case GL_YCBCR_MESA
: /* not considered to be RGB */
802 * Test if the given image format is a color index format.
805 _mesa_is_index_format(GLenum format
)
809 case GL_COLOR_INDEX1_EXT
:
810 case GL_COLOR_INDEX2_EXT
:
811 case GL_COLOR_INDEX4_EXT
:
812 case GL_COLOR_INDEX8_EXT
:
813 case GL_COLOR_INDEX12_EXT
:
814 case GL_COLOR_INDEX16_EXT
:
823 * Test if the given image format is a depth component format.
826 _mesa_is_depth_format(GLenum format
)
829 case GL_DEPTH_COMPONENT
:
830 case GL_DEPTH_COMPONENT16
:
831 case GL_DEPTH_COMPONENT24
:
832 case GL_DEPTH_COMPONENT32
:
841 * Test if the given image format is a stencil format.
844 _mesa_is_stencil_format(GLenum format
)
847 case GL_STENCIL_INDEX
:
848 case GL_DEPTH_STENCIL
:
857 * Test if the given image format is a YCbCr format.
860 _mesa_is_ycbcr_format(GLenum format
)
872 * Test if the given image format is a depth+stencil format.
875 _mesa_is_depthstencil_format(GLenum format
)
878 case GL_DEPTH24_STENCIL8_EXT
:
879 case GL_DEPTH_STENCIL_EXT
:
888 * Test if the given image format is a depth or stencil format.
891 _mesa_is_depth_or_stencil_format(GLenum format
)
894 case GL_DEPTH_COMPONENT
:
895 case GL_DEPTH_COMPONENT16
:
896 case GL_DEPTH_COMPONENT24
:
897 case GL_DEPTH_COMPONENT32
:
898 case GL_STENCIL_INDEX
:
899 case GL_STENCIL_INDEX1_EXT
:
900 case GL_STENCIL_INDEX4_EXT
:
901 case GL_STENCIL_INDEX8_EXT
:
902 case GL_STENCIL_INDEX16_EXT
:
903 case GL_DEPTH_STENCIL_EXT
:
904 case GL_DEPTH24_STENCIL8_EXT
:
913 * Test if the given image format is a dudv format.
916 _mesa_is_dudv_format(GLenum format
)
929 * Test if the given format is an integer (non-normalized) format.
932 _mesa_is_integer_format(GLenum format
)
935 /* generic integer formats */
936 case GL_RED_INTEGER_EXT
:
937 case GL_GREEN_INTEGER_EXT
:
938 case GL_BLUE_INTEGER_EXT
:
939 case GL_ALPHA_INTEGER_EXT
:
940 case GL_RGB_INTEGER_EXT
:
941 case GL_RGBA_INTEGER_EXT
:
942 case GL_BGR_INTEGER_EXT
:
943 case GL_BGRA_INTEGER_EXT
:
944 case GL_LUMINANCE_INTEGER_EXT
:
945 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
946 /* specific integer formats */
947 case GL_RGBA32UI_EXT
:
949 case GL_ALPHA32UI_EXT
:
950 case GL_INTENSITY32UI_EXT
:
951 case GL_LUMINANCE32UI_EXT
:
952 case GL_LUMINANCE_ALPHA32UI_EXT
:
953 case GL_RGBA16UI_EXT
:
955 case GL_ALPHA16UI_EXT
:
956 case GL_INTENSITY16UI_EXT
:
957 case GL_LUMINANCE16UI_EXT
:
958 case GL_LUMINANCE_ALPHA16UI_EXT
:
961 case GL_ALPHA8UI_EXT
:
962 case GL_INTENSITY8UI_EXT
:
963 case GL_LUMINANCE8UI_EXT
:
964 case GL_LUMINANCE_ALPHA8UI_EXT
:
967 case GL_ALPHA32I_EXT
:
968 case GL_INTENSITY32I_EXT
:
969 case GL_LUMINANCE32I_EXT
:
970 case GL_LUMINANCE_ALPHA32I_EXT
:
973 case GL_ALPHA16I_EXT
:
974 case GL_INTENSITY16I_EXT
:
975 case GL_LUMINANCE16I_EXT
:
976 case GL_LUMINANCE_ALPHA16I_EXT
:
980 case GL_INTENSITY8I_EXT
:
981 case GL_LUMINANCE8I_EXT
:
982 case GL_LUMINANCE_ALPHA8I_EXT
:
991 * Test if an image format is a supported compressed format.
992 * \param format the internal format token provided by the user.
993 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
996 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
999 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1000 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1001 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1002 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1003 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
1008 return ctx
->Extensions
.S3_s3tc
;
1009 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1010 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1011 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1012 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1013 return ctx
->Extensions
.EXT_texture_sRGB
1014 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1015 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1016 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1017 return ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1018 case GL_COMPRESSED_RED_RGTC1
:
1019 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1020 case GL_COMPRESSED_RG_RGTC2
:
1021 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1022 return ctx
->Extensions
.ARB_texture_compression_rgtc
;
1030 * Return the address of a specific pixel in an image (1D, 2D or 3D).
1032 * Pixel unpacking/packing parameters are observed according to \p packing.
1034 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
1035 * \param image starting address of image data
1036 * \param width the image width
1037 * \param height theimage height
1038 * \param format the pixel format
1039 * \param type the pixel data type
1040 * \param packing the pixelstore attributes
1041 * \param img which image in the volume (0 for 1D or 2D images)
1042 * \param row row of pixel in the image (0 for 1D images)
1043 * \param column column of pixel in the image
1045 * \return address of pixel on success, or NULL on error.
1047 * \sa gl_pixelstore_attrib.
1050 _mesa_image_address( GLuint dimensions
,
1051 const struct gl_pixelstore_attrib
*packing
,
1052 const GLvoid
*image
,
1053 GLsizei width
, GLsizei height
,
1054 GLenum format
, GLenum type
,
1055 GLint img
, GLint row
, GLint column
)
1057 GLint alignment
; /* 1, 2 or 4 */
1058 GLint pixels_per_row
;
1059 GLint rows_per_image
;
1062 GLint skipimages
; /* for 3-D volume images */
1063 GLubyte
*pixel_addr
;
1065 ASSERT(dimensions
>= 1 && dimensions
<= 3);
1067 alignment
= packing
->Alignment
;
1068 if (packing
->RowLength
> 0) {
1069 pixels_per_row
= packing
->RowLength
;
1072 pixels_per_row
= width
;
1074 if (packing
->ImageHeight
> 0) {
1075 rows_per_image
= packing
->ImageHeight
;
1078 rows_per_image
= height
;
1081 skippixels
= packing
->SkipPixels
;
1082 /* Note: SKIP_ROWS _is_ used for 1D images */
1083 skiprows
= packing
->SkipRows
;
1084 /* Note: SKIP_IMAGES is only used for 3D images */
1085 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
1087 if (type
== GL_BITMAP
) {
1089 GLint comp_per_pixel
; /* components per pixel */
1090 GLint bytes_per_comp
; /* bytes per component */
1091 GLint bytes_per_row
;
1092 GLint bytes_per_image
;
1094 /* Compute bytes per component */
1095 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
1096 if (bytes_per_comp
< 0) {
1100 /* Compute number of components per pixel */
1101 comp_per_pixel
= _mesa_components_in_format( format
);
1102 if (comp_per_pixel
< 0) {
1106 bytes_per_row
= alignment
1107 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
1109 bytes_per_image
= bytes_per_row
* rows_per_image
;
1111 pixel_addr
= (GLubyte
*) image
1112 + (skipimages
+ img
) * bytes_per_image
1113 + (skiprows
+ row
) * bytes_per_row
1114 + (skippixels
+ column
) / 8;
1117 /* Non-BITMAP data */
1118 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
1121 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
1123 /* The pixel type and format should have been error checked earlier */
1124 assert(bytes_per_pixel
> 0);
1126 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
1127 remainder
= bytes_per_row
% alignment
;
1129 bytes_per_row
+= (alignment
- remainder
);
1131 ASSERT(bytes_per_row
% alignment
== 0);
1133 bytes_per_image
= bytes_per_row
* rows_per_image
;
1135 if (packing
->Invert
) {
1136 /* set pixel_addr to the last row */
1137 topOfImage
= bytes_per_row
* (height
- 1);
1138 bytes_per_row
= -bytes_per_row
;
1144 /* compute final pixel address */
1145 pixel_addr
= (GLubyte
*) image
1146 + (skipimages
+ img
) * bytes_per_image
1148 + (skiprows
+ row
) * bytes_per_row
1149 + (skippixels
+ column
) * bytes_per_pixel
;
1152 return (GLvoid
*) pixel_addr
;
1157 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
1158 const GLvoid
*image
,
1160 GLenum format
, GLenum type
,
1163 return _mesa_image_address(1, packing
, image
, width
, 1,
1164 format
, type
, 0, 0, column
);
1169 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
1170 const GLvoid
*image
,
1171 GLsizei width
, GLsizei height
,
1172 GLenum format
, GLenum type
,
1173 GLint row
, GLint column
)
1175 return _mesa_image_address(2, packing
, image
, width
, height
,
1176 format
, type
, 0, row
, column
);
1181 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
1182 const GLvoid
*image
,
1183 GLsizei width
, GLsizei height
,
1184 GLenum format
, GLenum type
,
1185 GLint img
, GLint row
, GLint column
)
1187 return _mesa_image_address(3, packing
, image
, width
, height
,
1188 format
, type
, img
, row
, column
);
1194 * Compute the stride (in bytes) between image rows.
1196 * \param packing the pixelstore attributes
1197 * \param width image width.
1198 * \param format pixel format.
1199 * \param type pixel data type.
1201 * \return the stride in bytes for the given parameters, or -1 if error
1204 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
1205 GLint width
, GLenum format
, GLenum type
)
1207 GLint bytesPerRow
, remainder
;
1211 if (type
== GL_BITMAP
) {
1212 if (packing
->RowLength
== 0) {
1213 bytesPerRow
= (width
+ 7) / 8;
1216 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1220 /* Non-BITMAP data */
1221 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1222 if (bytesPerPixel
<= 0)
1223 return -1; /* error */
1224 if (packing
->RowLength
== 0) {
1225 bytesPerRow
= bytesPerPixel
* width
;
1228 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1232 remainder
= bytesPerRow
% packing
->Alignment
;
1233 if (remainder
> 0) {
1234 bytesPerRow
+= (packing
->Alignment
- remainder
);
1237 if (packing
->Invert
) {
1238 /* negate the bytes per row (negative row stride) */
1239 bytesPerRow
= -bytesPerRow
;
1247 * Compute the stride between images in a 3D texture (in bytes) for the given
1248 * pixel packing parameters and image width, format and type.
1251 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1252 GLint width
, GLint height
,
1253 GLenum format
, GLenum type
)
1255 GLint bytesPerRow
, bytesPerImage
, remainder
;
1259 if (type
== GL_BITMAP
) {
1260 if (packing
->RowLength
== 0) {
1261 bytesPerRow
= (width
+ 7) / 8;
1264 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1268 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1270 if (bytesPerPixel
<= 0)
1271 return -1; /* error */
1272 if (packing
->RowLength
== 0) {
1273 bytesPerRow
= bytesPerPixel
* width
;
1276 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1280 remainder
= bytesPerRow
% packing
->Alignment
;
1282 bytesPerRow
+= (packing
->Alignment
- remainder
);
1284 if (packing
->ImageHeight
== 0)
1285 bytesPerImage
= bytesPerRow
* height
;
1287 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1289 return bytesPerImage
;
1295 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1296 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1297 * "On" bits will set texels to \p onValue.
1298 * "Off" bits will not modify texels.
1299 * \param width src bitmap width in pixels
1300 * \param height src bitmap height in pixels
1301 * \param unpack bitmap unpacking state
1302 * \param bitmap the src bitmap data
1303 * \param destBuffer start of dest buffer
1304 * \param destStride row stride in dest buffer
1305 * \param onValue if bit is 1, set destBuffer pixel to this value
1308 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1309 const struct gl_pixelstore_attrib
*unpack
,
1310 const GLubyte
*bitmap
,
1311 GLubyte
*destBuffer
, GLint destStride
,
1314 const GLubyte
*srcRow
= (const GLubyte
*)
1315 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1316 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1317 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1318 GL_COLOR_INDEX
, GL_BITMAP
);
1321 #define SET_PIXEL(COL, ROW) \
1322 destBuffer[(ROW) * destStride + (COL)] = onValue;
1324 for (row
= 0; row
< height
; row
++) {
1325 const GLubyte
*src
= srcRow
;
1327 if (unpack
->LsbFirst
) {
1329 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1330 for (col
= 0; col
< width
; col
++) {
1333 SET_PIXEL(col
, row
);
1345 /* get ready for next row */
1351 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1352 for (col
= 0; col
< width
; col
++) {
1355 SET_PIXEL(col
, row
);
1367 /* get ready for next row */
1372 srcRow
+= srcStride
;
1382 * Convert an array of RGBA colors from one datatype to another.
1383 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1386 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
1387 GLenum dstType
, GLvoid
*dst
,
1388 GLuint count
, const GLubyte mask
[])
1390 GLuint tempBuffer
[MAX_WIDTH
][4];
1391 const GLboolean useTemp
= (src
== dst
);
1393 ASSERT(srcType
!= dstType
);
1396 case GL_UNSIGNED_BYTE
:
1397 if (dstType
== GL_UNSIGNED_SHORT
) {
1398 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1399 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1401 for (i
= 0; i
< count
; i
++) {
1402 if (!mask
|| mask
[i
]) {
1403 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
1404 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
1405 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
1406 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
1410 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1413 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1414 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1416 ASSERT(dstType
== GL_FLOAT
);
1417 for (i
= 0; i
< count
; i
++) {
1418 if (!mask
|| mask
[i
]) {
1419 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
1420 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
1421 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
1422 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
1426 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1429 case GL_UNSIGNED_SHORT
:
1430 if (dstType
== GL_UNSIGNED_BYTE
) {
1431 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1432 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1434 for (i
= 0; i
< count
; i
++) {
1435 if (!mask
|| mask
[i
]) {
1436 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
1437 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
1438 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
1439 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
1443 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1446 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1447 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1449 ASSERT(dstType
== GL_FLOAT
);
1450 for (i
= 0; i
< count
; i
++) {
1451 if (!mask
|| mask
[i
]) {
1452 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
1453 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
1454 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
1455 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
1459 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1463 if (dstType
== GL_UNSIGNED_BYTE
) {
1464 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1465 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1467 for (i
= 0; i
< count
; i
++) {
1468 if (!mask
|| mask
[i
]) {
1469 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
1470 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
1471 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
1472 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
1476 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1479 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1480 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1482 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
1483 for (i
= 0; i
< count
; i
++) {
1484 if (!mask
|| mask
[i
]) {
1485 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
1486 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
1487 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
1488 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
1492 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1496 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
1504 * Perform basic clipping for glDrawPixels. The image's position and size
1505 * and the unpack SkipPixels and SkipRows are adjusted so that the image
1506 * region is entirely within the window and scissor bounds.
1507 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
1508 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
1509 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
1511 * \return GL_TRUE if image is ready for drawing or
1512 * GL_FALSE if image was completely clipped away (draw nothing)
1515 _mesa_clip_drawpixels(const struct gl_context
*ctx
,
1516 GLint
*destX
, GLint
*destY
,
1517 GLsizei
*width
, GLsizei
*height
,
1518 struct gl_pixelstore_attrib
*unpack
)
1520 const struct gl_framebuffer
*buffer
= ctx
->DrawBuffer
;
1522 if (unpack
->RowLength
== 0) {
1523 unpack
->RowLength
= *width
;
1526 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
1527 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
1530 if (*destX
< buffer
->_Xmin
) {
1531 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
1532 *width
-= (buffer
->_Xmin
- *destX
);
1533 *destX
= buffer
->_Xmin
;
1535 /* right clipping */
1536 if (*destX
+ *width
> buffer
->_Xmax
)
1537 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
1542 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
1543 /* bottom clipping */
1544 if (*destY
< buffer
->_Ymin
) {
1545 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
1546 *height
-= (buffer
->_Ymin
- *destY
);
1547 *destY
= buffer
->_Ymin
;
1550 if (*destY
+ *height
> buffer
->_Ymax
)
1551 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
1553 else { /* upside down */
1555 if (*destY
> buffer
->_Ymax
) {
1556 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
1557 *height
-= (*destY
- buffer
->_Ymax
);
1558 *destY
= buffer
->_Ymax
;
1560 /* bottom clipping */
1561 if (*destY
- *height
< buffer
->_Ymin
)
1562 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
1563 /* adjust destY so it's the first row to write to */
1575 * Perform clipping for glReadPixels. The image's window position
1576 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
1577 * so that the image region is entirely within the window bounds.
1578 * Note: this is different from _mesa_clip_drawpixels() in that the
1579 * scissor box is ignored, and we use the bounds of the current readbuffer
1582 * \return GL_TRUE if image is ready for drawing or
1583 * GL_FALSE if image was completely clipped away (draw nothing)
1586 _mesa_clip_readpixels(const struct gl_context
*ctx
,
1587 GLint
*srcX
, GLint
*srcY
,
1588 GLsizei
*width
, GLsizei
*height
,
1589 struct gl_pixelstore_attrib
*pack
)
1591 const struct gl_framebuffer
*buffer
= ctx
->ReadBuffer
;
1593 if (pack
->RowLength
== 0) {
1594 pack
->RowLength
= *width
;
1599 pack
->SkipPixels
+= (0 - *srcX
);
1600 *width
-= (0 - *srcX
);
1603 /* right clipping */
1604 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
1605 *width
-= (*srcX
+ *width
- buffer
->Width
);
1610 /* bottom clipping */
1612 pack
->SkipRows
+= (0 - *srcY
);
1613 *height
-= (0 - *srcY
);
1617 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
1618 *height
-= (*srcY
+ *height
- buffer
->Height
);
1628 * Do clipping for a glCopyTexSubImage call.
1629 * The framebuffer source region might extend outside the framebuffer
1630 * bounds. Clip the source region against the framebuffer bounds and
1631 * adjust the texture/dest position and size accordingly.
1633 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
1636 _mesa_clip_copytexsubimage(const struct gl_context
*ctx
,
1637 GLint
*destX
, GLint
*destY
,
1638 GLint
*srcX
, GLint
*srcY
,
1639 GLsizei
*width
, GLsizei
*height
)
1641 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
1642 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
1644 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
1645 srcX
, srcY
, width
, height
)) {
1646 *destX
= *destX
+ *srcX
- srcX0
;
1647 *destY
= *destY
+ *srcY
- srcY0
;
1659 * Clip the rectangle defined by (x, y, width, height) against the bounds
1660 * specified by [xmin, xmax) and [ymin, ymax).
1661 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
1664 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
1665 GLint xmax
, GLint ymax
,
1667 GLsizei
*width
, GLsizei
*height
)
1671 *width
-= (xmin
- *x
);
1675 /* right clipping */
1676 if (*x
+ *width
> xmax
)
1677 *width
-= (*x
+ *width
- xmax
);
1682 /* bottom (or top) clipping */
1684 *height
-= (ymin
- *y
);
1688 /* top (or bottom) clipping */
1689 if (*y
+ *height
> ymax
)
1690 *height
-= (*y
+ *height
- ymax
);
1700 * Clip dst coords against Xmax (or Ymax).
1703 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
1704 GLint
*dstX0
, GLint
*dstX1
,
1709 if (*dstX1
> maxValue
) {
1710 /* X1 outside right edge */
1711 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
1712 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1713 /* chop off [t, 1] part */
1714 ASSERT(t
>= 0.0 && t
<= 1.0);
1716 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1717 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1719 else if (*dstX0
> maxValue
) {
1720 /* X0 outside right edge */
1721 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
1722 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1723 /* chop off [t, 1] part */
1724 ASSERT(t
>= 0.0 && t
<= 1.0);
1726 bias
= (*srcX0
< *srcX1
) ? -0.5F
: 0.5F
;
1727 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1733 * Clip dst coords against Xmin (or Ymin).
1736 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
1737 GLint
*dstX0
, GLint
*dstX1
,
1742 if (*dstX0
< minValue
) {
1743 /* X0 outside left edge */
1744 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
1745 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1746 /* chop off [0, t] part */
1747 ASSERT(t
>= 0.0 && t
<= 1.0);
1749 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
; /* flipped??? */
1750 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1752 else if (*dstX1
< minValue
) {
1753 /* X1 outside left edge */
1754 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
1755 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1756 /* chop off [0, t] part */
1757 ASSERT(t
>= 0.0 && t
<= 1.0);
1759 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1760 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1766 * Do clipping of blit src/dest rectangles.
1767 * The dest rect is clipped against both the buffer bounds and scissor bounds.
1768 * The src rect is just clipped against the buffer bounds.
1770 * When either the src or dest rect is clipped, the other is also clipped
1773 * Note that X0 need not be less than X1 (same for Y) for either the source
1774 * and dest rects. That makes the clipping a little trickier.
1776 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
1779 _mesa_clip_blit(struct gl_context
*ctx
,
1780 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
1781 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
1783 const GLint srcXmin
= 0;
1784 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
1785 const GLint srcYmin
= 0;
1786 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
1788 /* these include scissor bounds */
1789 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
1790 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
1791 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
1792 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
1795 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
1796 *srcX0, *srcX1, *dstX0, *dstX1);
1797 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
1798 *srcY0, *srcY1, *dstY0, *dstY1);
1801 /* trivial rejection tests */
1802 if (*dstX0
== *dstX1
)
1803 return GL_FALSE
; /* no width */
1804 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
1805 return GL_FALSE
; /* totally out (left) of bounds */
1806 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
1807 return GL_FALSE
; /* totally out (right) of bounds */
1809 if (*dstY0
== *dstY1
)
1811 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
1813 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
1816 if (*srcX0
== *srcX1
)
1818 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
1820 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
1823 if (*srcY0
== *srcY1
)
1825 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
1827 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
1833 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
1834 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
1835 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
1836 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
1839 * src clip (just swap src/dst values from above)
1841 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
1842 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
1843 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
1844 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
1847 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
1848 *srcX0, *srcX1, *dstX0, *dstX1);
1849 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
1850 *srcY0, *srcY1, *dstY0, *dstY1);
1853 ASSERT(*dstX0
>= dstXmin
);
1854 ASSERT(*dstX0
<= dstXmax
);
1855 ASSERT(*dstX1
>= dstXmin
);
1856 ASSERT(*dstX1
<= dstXmax
);
1858 ASSERT(*dstY0
>= dstYmin
);
1859 ASSERT(*dstY0
<= dstYmax
);
1860 ASSERT(*dstY1
>= dstYmin
);
1861 ASSERT(*dstY1
<= dstYmax
);
1863 ASSERT(*srcX0
>= srcXmin
);
1864 ASSERT(*srcX0
<= srcXmax
);
1865 ASSERT(*srcX1
>= srcXmin
);
1866 ASSERT(*srcX1
<= srcXmax
);
1868 ASSERT(*srcY0
>= srcYmin
);
1869 ASSERT(*srcY0
<= srcYmax
);
1870 ASSERT(*srcY1
>= srcYmin
);
1871 ASSERT(*srcY1
<= srcYmax
);