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.
43 * Normally, BYTE_TO_FLOAT(0) returns 0.00392 That causes problems when
44 * we later convert the float to a packed integer value (such as for
45 * GL_RGB5_A1) because we'll wind up with a non-zero value.
47 * We redefine the macros here so zero is handled correctly.
50 #define BYTE_TO_FLOAT(B) ((B) == 0 ? 0.0F : ((2.0F * (B) + 1.0F) * (1.0F/255.0F)))
53 #define SHORT_TO_FLOAT(S) ((S) == 0 ? 0.0F : ((2.0F * (S) + 1.0F) * (1.0F/65535.0F)))
57 /** Compute ceiling of integer quotient of A divided by B. */
58 #define CEILING( A, B ) ( (A) % (B) == 0 ? (A)/(B) : (A)/(B)+1 )
62 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
65 _mesa_type_is_packed(GLenum type
)
68 case GL_UNSIGNED_BYTE_3_3_2
:
69 case GL_UNSIGNED_BYTE_2_3_3_REV
:
70 case GL_UNSIGNED_SHORT_5_6_5
:
71 case GL_UNSIGNED_SHORT_5_6_5_REV
:
72 case GL_UNSIGNED_SHORT_4_4_4_4
:
73 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
74 case GL_UNSIGNED_SHORT_5_5_5_1
:
75 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
76 case GL_UNSIGNED_INT_8_8_8_8
:
77 case GL_UNSIGNED_INT_8_8_8_8_REV
:
78 case GL_UNSIGNED_INT_10_10_10_2
:
79 case GL_UNSIGNED_INT_2_10_10_10_REV
:
80 case GL_UNSIGNED_SHORT_8_8_MESA
:
81 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
82 case GL_UNSIGNED_INT_24_8_EXT
:
92 * Flip the order of the 2 bytes in each word in the given array.
95 * \param n number of words.
98 _mesa_swap2( GLushort
*p
, GLuint n
)
101 for (i
= 0; i
< n
; i
++) {
102 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
109 * Flip the order of the 4 bytes in each word in the given array.
112 _mesa_swap4( GLuint
*p
, GLuint n
)
115 for (i
= 0; i
< n
; i
++) {
118 | ((b
>> 8) & 0xff00)
119 | ((b
<< 8) & 0xff0000)
120 | ((b
<< 24) & 0xff000000);
127 * Get the size of a GL data type.
129 * \param type GL data type.
131 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
132 * if an invalid type enum.
135 _mesa_sizeof_type( GLenum type
)
140 case GL_UNSIGNED_BYTE
:
141 return sizeof(GLubyte
);
143 return sizeof(GLbyte
);
144 case GL_UNSIGNED_SHORT
:
145 return sizeof(GLushort
);
147 return sizeof(GLshort
);
148 case GL_UNSIGNED_INT
:
149 return sizeof(GLuint
);
151 return sizeof(GLint
);
153 return sizeof(GLfloat
);
155 return sizeof(GLdouble
);
156 case GL_HALF_FLOAT_ARB
:
157 return sizeof(GLhalfARB
);
165 * Same as _mesa_sizeof_type() but also accepting the packed pixel
169 _mesa_sizeof_packed_type( GLenum type
)
174 case GL_UNSIGNED_BYTE
:
175 return sizeof(GLubyte
);
177 return sizeof(GLbyte
);
178 case GL_UNSIGNED_SHORT
:
179 return sizeof(GLushort
);
181 return sizeof(GLshort
);
182 case GL_UNSIGNED_INT
:
183 return sizeof(GLuint
);
185 return sizeof(GLint
);
186 case GL_HALF_FLOAT_ARB
:
187 return sizeof(GLhalfARB
);
189 return sizeof(GLfloat
);
190 case GL_UNSIGNED_BYTE_3_3_2
:
191 return sizeof(GLubyte
);
192 case GL_UNSIGNED_BYTE_2_3_3_REV
:
193 return sizeof(GLubyte
);
194 case GL_UNSIGNED_SHORT_5_6_5
:
195 return sizeof(GLushort
);
196 case GL_UNSIGNED_SHORT_5_6_5_REV
:
197 return sizeof(GLushort
);
198 case GL_UNSIGNED_SHORT_4_4_4_4
:
199 return sizeof(GLushort
);
200 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
201 return sizeof(GLushort
);
202 case GL_UNSIGNED_SHORT_5_5_5_1
:
203 return sizeof(GLushort
);
204 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
205 return sizeof(GLushort
);
206 case GL_UNSIGNED_INT_8_8_8_8
:
207 return sizeof(GLuint
);
208 case GL_UNSIGNED_INT_8_8_8_8_REV
:
209 return sizeof(GLuint
);
210 case GL_UNSIGNED_INT_10_10_10_2
:
211 return sizeof(GLuint
);
212 case GL_UNSIGNED_INT_2_10_10_10_REV
:
213 return sizeof(GLuint
);
214 case GL_UNSIGNED_SHORT_8_8_MESA
:
215 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
216 return sizeof(GLushort
);
217 case GL_UNSIGNED_INT_24_8_EXT
:
218 return sizeof(GLuint
);
226 * Get the number of components in a pixel format.
228 * \param format pixel format.
230 * \return the number of components in the given format, or -1 if a bad format.
233 _mesa_components_in_format( GLenum format
)
237 case GL_COLOR_INDEX1_EXT
:
238 case GL_COLOR_INDEX2_EXT
:
239 case GL_COLOR_INDEX4_EXT
:
240 case GL_COLOR_INDEX8_EXT
:
241 case GL_COLOR_INDEX12_EXT
:
242 case GL_COLOR_INDEX16_EXT
:
243 case GL_STENCIL_INDEX
:
244 case GL_DEPTH_COMPONENT
:
246 case GL_RED_INTEGER_EXT
:
248 case GL_GREEN_INTEGER_EXT
:
250 case GL_BLUE_INTEGER_EXT
:
252 case GL_ALPHA_INTEGER_EXT
:
254 case GL_LUMINANCE_INTEGER_EXT
:
257 case GL_LUMINANCE_ALPHA
:
258 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
262 case GL_RGB_INTEGER_EXT
:
265 case GL_RGBA_INTEGER_EXT
:
275 case GL_DEPTH_STENCIL_EXT
:
287 * Get the bytes per pixel of pixel format type pair.
289 * \param format pixel format.
290 * \param type pixel type.
292 * \return bytes per pixel, or -1 if a bad format or type was given.
295 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
297 GLint comps
= _mesa_components_in_format( format
);
303 return 0; /* special case */
305 case GL_UNSIGNED_BYTE
:
306 return comps
* sizeof(GLubyte
);
308 case GL_UNSIGNED_SHORT
:
309 return comps
* sizeof(GLshort
);
311 case GL_UNSIGNED_INT
:
312 return comps
* sizeof(GLint
);
314 return comps
* sizeof(GLfloat
);
315 case GL_HALF_FLOAT_ARB
:
316 return comps
* sizeof(GLhalfARB
);
317 case GL_UNSIGNED_BYTE_3_3_2
:
318 case GL_UNSIGNED_BYTE_2_3_3_REV
:
319 if (format
== GL_RGB
|| format
== GL_BGR
)
320 return sizeof(GLubyte
);
322 return -1; /* error */
323 case GL_UNSIGNED_SHORT_5_6_5
:
324 case GL_UNSIGNED_SHORT_5_6_5_REV
:
325 if (format
== GL_RGB
|| format
== GL_BGR
)
326 return sizeof(GLushort
);
328 return -1; /* error */
329 case GL_UNSIGNED_SHORT_4_4_4_4
:
330 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
331 case GL_UNSIGNED_SHORT_5_5_5_1
:
332 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
333 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
334 return sizeof(GLushort
);
337 case GL_UNSIGNED_INT_8_8_8_8
:
338 case GL_UNSIGNED_INT_8_8_8_8_REV
:
339 case GL_UNSIGNED_INT_10_10_10_2
:
340 case GL_UNSIGNED_INT_2_10_10_10_REV
:
341 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
342 return sizeof(GLuint
);
345 case GL_UNSIGNED_SHORT_8_8_MESA
:
346 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
347 if (format
== GL_YCBCR_MESA
)
348 return sizeof(GLushort
);
351 case GL_UNSIGNED_INT_24_8_EXT
:
352 if (format
== GL_DEPTH_STENCIL_EXT
)
353 return sizeof(GLuint
);
363 * Test for a legal pixel format and type.
365 * \param format pixel format.
366 * \param type pixel type.
368 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
372 _mesa_is_legal_format_and_type( struct gl_context
*ctx
, GLenum format
, GLenum type
)
376 case GL_STENCIL_INDEX
:
380 case GL_UNSIGNED_BYTE
:
382 case GL_UNSIGNED_SHORT
:
384 case GL_UNSIGNED_INT
:
387 case GL_HALF_FLOAT_ARB
:
388 return ctx
->Extensions
.ARB_half_float_pixel
;
396 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
400 case GL_LUMINANCE_ALPHA
:
401 case GL_DEPTH_COMPONENT
:
404 case GL_UNSIGNED_BYTE
:
406 case GL_UNSIGNED_SHORT
:
408 case GL_UNSIGNED_INT
:
411 case GL_HALF_FLOAT_ARB
:
412 return ctx
->Extensions
.ARB_half_float_pixel
;
417 if (!ctx
->Extensions
.ARB_texture_rg
)
422 case GL_UNSIGNED_BYTE
:
424 case GL_UNSIGNED_SHORT
:
426 case GL_UNSIGNED_INT
:
429 case GL_HALF_FLOAT_ARB
:
430 return ctx
->Extensions
.ARB_half_float_pixel
;
437 case GL_UNSIGNED_BYTE
:
439 case GL_UNSIGNED_SHORT
:
441 case GL_UNSIGNED_INT
:
443 case GL_UNSIGNED_BYTE_3_3_2
:
444 case GL_UNSIGNED_BYTE_2_3_3_REV
:
445 case GL_UNSIGNED_SHORT_5_6_5
:
446 case GL_UNSIGNED_SHORT_5_6_5_REV
:
448 case GL_HALF_FLOAT_ARB
:
449 return ctx
->Extensions
.ARB_half_float_pixel
;
455 /* NOTE: no packed types are supported with BGR. That's
456 * intentional, according to the GL spec.
459 case GL_UNSIGNED_BYTE
:
461 case GL_UNSIGNED_SHORT
:
463 case GL_UNSIGNED_INT
:
466 case GL_HALF_FLOAT_ARB
:
467 return ctx
->Extensions
.ARB_half_float_pixel
;
476 case GL_UNSIGNED_BYTE
:
478 case GL_UNSIGNED_SHORT
:
480 case GL_UNSIGNED_INT
:
482 case GL_UNSIGNED_SHORT_4_4_4_4
:
483 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
484 case GL_UNSIGNED_SHORT_5_5_5_1
:
485 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
486 case GL_UNSIGNED_INT_8_8_8_8
:
487 case GL_UNSIGNED_INT_8_8_8_8_REV
:
488 case GL_UNSIGNED_INT_10_10_10_2
:
489 case GL_UNSIGNED_INT_2_10_10_10_REV
:
491 case GL_HALF_FLOAT_ARB
:
492 return ctx
->Extensions
.ARB_half_float_pixel
;
497 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
498 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
502 case GL_DEPTH_STENCIL_EXT
:
503 if (ctx
->Extensions
.EXT_packed_depth_stencil
504 && type
== GL_UNSIGNED_INT_24_8_EXT
)
512 case GL_UNSIGNED_BYTE
:
514 case GL_UNSIGNED_SHORT
:
516 case GL_UNSIGNED_INT
:
522 case GL_RED_INTEGER_EXT
:
523 case GL_GREEN_INTEGER_EXT
:
524 case GL_BLUE_INTEGER_EXT
:
525 case GL_ALPHA_INTEGER_EXT
:
526 case GL_RGB_INTEGER_EXT
:
527 case GL_RGBA_INTEGER_EXT
:
528 case GL_BGR_INTEGER_EXT
:
529 case GL_BGRA_INTEGER_EXT
:
530 case GL_LUMINANCE_INTEGER_EXT
:
531 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
534 case GL_UNSIGNED_BYTE
:
536 case GL_UNSIGNED_SHORT
:
538 case GL_UNSIGNED_INT
:
539 return ctx
->Extensions
.EXT_texture_integer
;
552 * Test if the given image format is a color/RGBA format (i.e., not color
553 * index, depth, stencil, etc).
554 * \param format the image format value (may by an internal texture format)
555 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
558 _mesa_is_color_format(GLenum format
)
576 case GL_LUMINANCE_ALPHA
:
577 case GL_LUMINANCE4_ALPHA4
:
578 case GL_LUMINANCE6_ALPHA2
:
579 case GL_LUMINANCE8_ALPHA8
:
580 case GL_LUMINANCE12_ALPHA4
:
581 case GL_LUMINANCE12_ALPHA12
:
582 case GL_LUMINANCE16_ALPHA16
:
614 /* float texture formats */
615 case GL_ALPHA16F_ARB
:
616 case GL_ALPHA32F_ARB
:
617 case GL_LUMINANCE16F_ARB
:
618 case GL_LUMINANCE32F_ARB
:
619 case GL_LUMINANCE_ALPHA16F_ARB
:
620 case GL_LUMINANCE_ALPHA32F_ARB
:
621 case GL_INTENSITY16F_ARB
:
622 case GL_INTENSITY32F_ARB
:
631 /* compressed formats */
632 case GL_COMPRESSED_ALPHA
:
633 case GL_COMPRESSED_LUMINANCE
:
634 case GL_COMPRESSED_LUMINANCE_ALPHA
:
635 case GL_COMPRESSED_INTENSITY
:
636 case GL_COMPRESSED_RED
:
637 case GL_COMPRESSED_RG
:
638 case GL_COMPRESSED_RGB
:
639 case GL_COMPRESSED_RGBA
:
644 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
645 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
646 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
647 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
648 case GL_COMPRESSED_RGB_FXT1_3DFX
:
649 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
650 #if FEATURE_EXT_texture_sRGB
653 case GL_SRGB_ALPHA_EXT
:
654 case GL_SRGB8_ALPHA8_EXT
:
655 case GL_SLUMINANCE_ALPHA_EXT
:
656 case GL_SLUMINANCE8_ALPHA8_EXT
:
657 case GL_SLUMINANCE_EXT
:
658 case GL_SLUMINANCE8_EXT
:
659 case GL_COMPRESSED_SRGB_EXT
:
660 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
661 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
662 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
663 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
664 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
665 case GL_COMPRESSED_SLUMINANCE_EXT
:
666 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
667 #endif /* FEATURE_EXT_texture_sRGB */
668 case GL_COMPRESSED_RED_RGTC1
:
669 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
670 case GL_COMPRESSED_RG_RGTC2
:
671 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
672 /* signed, normalized texture formats */
675 /* generic integer formats */
676 case GL_RED_INTEGER_EXT
:
677 case GL_GREEN_INTEGER_EXT
:
678 case GL_BLUE_INTEGER_EXT
:
679 case GL_ALPHA_INTEGER_EXT
:
680 case GL_RGB_INTEGER_EXT
:
681 case GL_RGBA_INTEGER_EXT
:
682 case GL_BGR_INTEGER_EXT
:
683 case GL_BGRA_INTEGER_EXT
:
684 case GL_LUMINANCE_INTEGER_EXT
:
685 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
686 /* sized integer formats */
687 case GL_RGBA32UI_EXT
:
689 case GL_ALPHA32UI_EXT
:
690 case GL_INTENSITY32UI_EXT
:
691 case GL_LUMINANCE32UI_EXT
:
692 case GL_LUMINANCE_ALPHA32UI_EXT
:
693 case GL_RGBA16UI_EXT
:
695 case GL_ALPHA16UI_EXT
:
696 case GL_INTENSITY16UI_EXT
:
697 case GL_LUMINANCE16UI_EXT
:
698 case GL_LUMINANCE_ALPHA16UI_EXT
:
701 case GL_ALPHA8UI_EXT
:
702 case GL_INTENSITY8UI_EXT
:
703 case GL_LUMINANCE8UI_EXT
:
704 case GL_LUMINANCE_ALPHA8UI_EXT
:
707 case GL_ALPHA32I_EXT
:
708 case GL_INTENSITY32I_EXT
:
709 case GL_LUMINANCE32I_EXT
:
710 case GL_LUMINANCE_ALPHA32I_EXT
:
713 case GL_ALPHA16I_EXT
:
714 case GL_INTENSITY16I_EXT
:
715 case GL_LUMINANCE16I_EXT
:
716 case GL_LUMINANCE_ALPHA16I_EXT
:
720 case GL_INTENSITY8I_EXT
:
721 case GL_LUMINANCE8I_EXT
:
722 case GL_LUMINANCE_ALPHA8I_EXT
:
724 case GL_YCBCR_MESA
: /* not considered to be RGB */
733 * Test if the given image format is a color index format.
736 _mesa_is_index_format(GLenum format
)
740 case GL_COLOR_INDEX1_EXT
:
741 case GL_COLOR_INDEX2_EXT
:
742 case GL_COLOR_INDEX4_EXT
:
743 case GL_COLOR_INDEX8_EXT
:
744 case GL_COLOR_INDEX12_EXT
:
745 case GL_COLOR_INDEX16_EXT
:
754 * Test if the given image format is a depth component format.
757 _mesa_is_depth_format(GLenum format
)
760 case GL_DEPTH_COMPONENT
:
761 case GL_DEPTH_COMPONENT16
:
762 case GL_DEPTH_COMPONENT24
:
763 case GL_DEPTH_COMPONENT32
:
772 * Test if the given image format is a stencil format.
775 _mesa_is_stencil_format(GLenum format
)
778 case GL_STENCIL_INDEX
:
779 case GL_DEPTH_STENCIL
:
788 * Test if the given image format is a YCbCr format.
791 _mesa_is_ycbcr_format(GLenum format
)
803 * Test if the given image format is a depth+stencil format.
806 _mesa_is_depthstencil_format(GLenum format
)
809 case GL_DEPTH24_STENCIL8_EXT
:
810 case GL_DEPTH_STENCIL_EXT
:
819 * Test if the given image format is a depth or stencil format.
822 _mesa_is_depth_or_stencil_format(GLenum format
)
825 case GL_DEPTH_COMPONENT
:
826 case GL_DEPTH_COMPONENT16
:
827 case GL_DEPTH_COMPONENT24
:
828 case GL_DEPTH_COMPONENT32
:
829 case GL_STENCIL_INDEX
:
830 case GL_STENCIL_INDEX1_EXT
:
831 case GL_STENCIL_INDEX4_EXT
:
832 case GL_STENCIL_INDEX8_EXT
:
833 case GL_STENCIL_INDEX16_EXT
:
834 case GL_DEPTH_STENCIL_EXT
:
835 case GL_DEPTH24_STENCIL8_EXT
:
844 * Test if the given image format is a dudv format.
847 _mesa_is_dudv_format(GLenum format
)
860 * Test if the given format is an integer (non-normalized) format.
863 _mesa_is_integer_format(GLenum format
)
866 /* generic integer formats */
867 case GL_RED_INTEGER_EXT
:
868 case GL_GREEN_INTEGER_EXT
:
869 case GL_BLUE_INTEGER_EXT
:
870 case GL_ALPHA_INTEGER_EXT
:
871 case GL_RGB_INTEGER_EXT
:
872 case GL_RGBA_INTEGER_EXT
:
873 case GL_BGR_INTEGER_EXT
:
874 case GL_BGRA_INTEGER_EXT
:
875 case GL_LUMINANCE_INTEGER_EXT
:
876 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
877 /* specific integer formats */
878 case GL_RGBA32UI_EXT
:
880 case GL_ALPHA32UI_EXT
:
881 case GL_INTENSITY32UI_EXT
:
882 case GL_LUMINANCE32UI_EXT
:
883 case GL_LUMINANCE_ALPHA32UI_EXT
:
884 case GL_RGBA16UI_EXT
:
886 case GL_ALPHA16UI_EXT
:
887 case GL_INTENSITY16UI_EXT
:
888 case GL_LUMINANCE16UI_EXT
:
889 case GL_LUMINANCE_ALPHA16UI_EXT
:
892 case GL_ALPHA8UI_EXT
:
893 case GL_INTENSITY8UI_EXT
:
894 case GL_LUMINANCE8UI_EXT
:
895 case GL_LUMINANCE_ALPHA8UI_EXT
:
898 case GL_ALPHA32I_EXT
:
899 case GL_INTENSITY32I_EXT
:
900 case GL_LUMINANCE32I_EXT
:
901 case GL_LUMINANCE_ALPHA32I_EXT
:
904 case GL_ALPHA16I_EXT
:
905 case GL_INTENSITY16I_EXT
:
906 case GL_LUMINANCE16I_EXT
:
907 case GL_LUMINANCE_ALPHA16I_EXT
:
911 case GL_INTENSITY8I_EXT
:
912 case GL_LUMINANCE8I_EXT
:
913 case GL_LUMINANCE_ALPHA8I_EXT
:
922 * Test if an image format is a supported compressed format.
923 * \param format the internal format token provided by the user.
924 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
927 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
930 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
931 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
932 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
933 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
934 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
939 return ctx
->Extensions
.S3_s3tc
;
940 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
941 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
942 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
943 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
944 return ctx
->Extensions
.EXT_texture_sRGB
945 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
946 case GL_COMPRESSED_RGB_FXT1_3DFX
:
947 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
948 return ctx
->Extensions
.TDFX_texture_compression_FXT1
;
949 case GL_COMPRESSED_RED_RGTC1
:
950 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
951 case GL_COMPRESSED_RG_RGTC2
:
952 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
953 return ctx
->Extensions
.ARB_texture_compression_rgtc
;
961 * Return the address of a specific pixel in an image (1D, 2D or 3D).
963 * Pixel unpacking/packing parameters are observed according to \p packing.
965 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
966 * \param image starting address of image data
967 * \param width the image width
968 * \param height theimage height
969 * \param format the pixel format
970 * \param type the pixel data type
971 * \param packing the pixelstore attributes
972 * \param img which image in the volume (0 for 1D or 2D images)
973 * \param row row of pixel in the image (0 for 1D images)
974 * \param column column of pixel in the image
976 * \return address of pixel on success, or NULL on error.
978 * \sa gl_pixelstore_attrib.
981 _mesa_image_address( GLuint dimensions
,
982 const struct gl_pixelstore_attrib
*packing
,
984 GLsizei width
, GLsizei height
,
985 GLenum format
, GLenum type
,
986 GLint img
, GLint row
, GLint column
)
988 GLint alignment
; /* 1, 2 or 4 */
989 GLint pixels_per_row
;
990 GLint rows_per_image
;
993 GLint skipimages
; /* for 3-D volume images */
996 ASSERT(dimensions
>= 1 && dimensions
<= 3);
998 alignment
= packing
->Alignment
;
999 if (packing
->RowLength
> 0) {
1000 pixels_per_row
= packing
->RowLength
;
1003 pixels_per_row
= width
;
1005 if (packing
->ImageHeight
> 0) {
1006 rows_per_image
= packing
->ImageHeight
;
1009 rows_per_image
= height
;
1012 skippixels
= packing
->SkipPixels
;
1013 /* Note: SKIP_ROWS _is_ used for 1D images */
1014 skiprows
= packing
->SkipRows
;
1015 /* Note: SKIP_IMAGES is only used for 3D images */
1016 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
1018 if (type
== GL_BITMAP
) {
1020 GLint comp_per_pixel
; /* components per pixel */
1021 GLint bytes_per_comp
; /* bytes per component */
1022 GLint bytes_per_row
;
1023 GLint bytes_per_image
;
1025 /* Compute bytes per component */
1026 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
1027 if (bytes_per_comp
< 0) {
1031 /* Compute number of components per pixel */
1032 comp_per_pixel
= _mesa_components_in_format( format
);
1033 if (comp_per_pixel
< 0) {
1037 bytes_per_row
= alignment
1038 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
1040 bytes_per_image
= bytes_per_row
* rows_per_image
;
1042 pixel_addr
= (GLubyte
*) image
1043 + (skipimages
+ img
) * bytes_per_image
1044 + (skiprows
+ row
) * bytes_per_row
1045 + (skippixels
+ column
) / 8;
1048 /* Non-BITMAP data */
1049 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
1052 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
1054 /* The pixel type and format should have been error checked earlier */
1055 assert(bytes_per_pixel
> 0);
1057 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
1058 remainder
= bytes_per_row
% alignment
;
1060 bytes_per_row
+= (alignment
- remainder
);
1062 ASSERT(bytes_per_row
% alignment
== 0);
1064 bytes_per_image
= bytes_per_row
* rows_per_image
;
1066 if (packing
->Invert
) {
1067 /* set pixel_addr to the last row */
1068 topOfImage
= bytes_per_row
* (height
- 1);
1069 bytes_per_row
= -bytes_per_row
;
1075 /* compute final pixel address */
1076 pixel_addr
= (GLubyte
*) image
1077 + (skipimages
+ img
) * bytes_per_image
1079 + (skiprows
+ row
) * bytes_per_row
1080 + (skippixels
+ column
) * bytes_per_pixel
;
1083 return (GLvoid
*) pixel_addr
;
1088 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
1089 const GLvoid
*image
,
1091 GLenum format
, GLenum type
,
1094 return _mesa_image_address(1, packing
, image
, width
, 1,
1095 format
, type
, 0, 0, column
);
1100 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
1101 const GLvoid
*image
,
1102 GLsizei width
, GLsizei height
,
1103 GLenum format
, GLenum type
,
1104 GLint row
, GLint column
)
1106 return _mesa_image_address(2, packing
, image
, width
, height
,
1107 format
, type
, 0, row
, column
);
1112 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
1113 const GLvoid
*image
,
1114 GLsizei width
, GLsizei height
,
1115 GLenum format
, GLenum type
,
1116 GLint img
, GLint row
, GLint column
)
1118 return _mesa_image_address(3, packing
, image
, width
, height
,
1119 format
, type
, img
, row
, column
);
1125 * Compute the stride (in bytes) between image rows.
1127 * \param packing the pixelstore attributes
1128 * \param width image width.
1129 * \param format pixel format.
1130 * \param type pixel data type.
1132 * \return the stride in bytes for the given parameters, or -1 if error
1135 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
1136 GLint width
, GLenum format
, GLenum type
)
1138 GLint bytesPerRow
, remainder
;
1142 if (type
== GL_BITMAP
) {
1143 if (packing
->RowLength
== 0) {
1144 bytesPerRow
= (width
+ 7) / 8;
1147 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1151 /* Non-BITMAP data */
1152 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1153 if (bytesPerPixel
<= 0)
1154 return -1; /* error */
1155 if (packing
->RowLength
== 0) {
1156 bytesPerRow
= bytesPerPixel
* width
;
1159 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1163 remainder
= bytesPerRow
% packing
->Alignment
;
1164 if (remainder
> 0) {
1165 bytesPerRow
+= (packing
->Alignment
- remainder
);
1168 if (packing
->Invert
) {
1169 /* negate the bytes per row (negative row stride) */
1170 bytesPerRow
= -bytesPerRow
;
1178 * Compute the stride between images in a 3D texture (in bytes) for the given
1179 * pixel packing parameters and image width, format and type.
1182 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1183 GLint width
, GLint height
,
1184 GLenum format
, GLenum type
)
1186 GLint bytesPerRow
, bytesPerImage
, remainder
;
1190 if (type
== GL_BITMAP
) {
1191 if (packing
->RowLength
== 0) {
1192 bytesPerRow
= (width
+ 7) / 8;
1195 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1199 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1201 if (bytesPerPixel
<= 0)
1202 return -1; /* error */
1203 if (packing
->RowLength
== 0) {
1204 bytesPerRow
= bytesPerPixel
* width
;
1207 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1211 remainder
= bytesPerRow
% packing
->Alignment
;
1213 bytesPerRow
+= (packing
->Alignment
- remainder
);
1215 if (packing
->ImageHeight
== 0)
1216 bytesPerImage
= bytesPerRow
* height
;
1218 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1220 return bytesPerImage
;
1226 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1227 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1228 * "On" bits will set texels to \p onValue.
1229 * "Off" bits will not modify texels.
1230 * \param width src bitmap width in pixels
1231 * \param height src bitmap height in pixels
1232 * \param unpack bitmap unpacking state
1233 * \param bitmap the src bitmap data
1234 * \param destBuffer start of dest buffer
1235 * \param destStride row stride in dest buffer
1236 * \param onValue if bit is 1, set destBuffer pixel to this value
1239 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1240 const struct gl_pixelstore_attrib
*unpack
,
1241 const GLubyte
*bitmap
,
1242 GLubyte
*destBuffer
, GLint destStride
,
1245 const GLubyte
*srcRow
= (const GLubyte
*)
1246 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1247 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1248 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1249 GL_COLOR_INDEX
, GL_BITMAP
);
1252 #define SET_PIXEL(COL, ROW) \
1253 destBuffer[(ROW) * destStride + (COL)] = onValue;
1255 for (row
= 0; row
< height
; row
++) {
1256 const GLubyte
*src
= srcRow
;
1258 if (unpack
->LsbFirst
) {
1260 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1261 for (col
= 0; col
< width
; col
++) {
1264 SET_PIXEL(col
, row
);
1276 /* get ready for next row */
1282 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1283 for (col
= 0; col
< width
; col
++) {
1286 SET_PIXEL(col
, row
);
1298 /* get ready for next row */
1303 srcRow
+= srcStride
;
1313 * Convert an array of RGBA colors from one datatype to another.
1314 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1317 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
1318 GLenum dstType
, GLvoid
*dst
,
1319 GLuint count
, const GLubyte mask
[])
1321 GLuint tempBuffer
[MAX_WIDTH
][4];
1322 const GLboolean useTemp
= (src
== dst
);
1324 ASSERT(srcType
!= dstType
);
1327 case GL_UNSIGNED_BYTE
:
1328 if (dstType
== GL_UNSIGNED_SHORT
) {
1329 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1330 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1332 for (i
= 0; i
< count
; i
++) {
1333 if (!mask
|| mask
[i
]) {
1334 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
1335 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
1336 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
1337 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
1341 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1344 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1345 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1347 ASSERT(dstType
== GL_FLOAT
);
1348 for (i
= 0; i
< count
; i
++) {
1349 if (!mask
|| mask
[i
]) {
1350 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
1351 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
1352 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
1353 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
1357 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1360 case GL_UNSIGNED_SHORT
:
1361 if (dstType
== GL_UNSIGNED_BYTE
) {
1362 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1363 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1365 for (i
= 0; i
< count
; i
++) {
1366 if (!mask
|| mask
[i
]) {
1367 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
1368 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
1369 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
1370 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
1374 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1377 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1378 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1380 ASSERT(dstType
== GL_FLOAT
);
1381 for (i
= 0; i
< count
; i
++) {
1382 if (!mask
|| mask
[i
]) {
1383 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
1384 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
1385 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
1386 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
1390 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1394 if (dstType
== GL_UNSIGNED_BYTE
) {
1395 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1396 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1398 for (i
= 0; i
< count
; i
++) {
1399 if (!mask
|| mask
[i
]) {
1400 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
1401 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
1402 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
1403 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
1407 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1410 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1411 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1413 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
1414 for (i
= 0; i
< count
; i
++) {
1415 if (!mask
|| mask
[i
]) {
1416 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
1417 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
1418 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
1419 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
1423 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1427 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
1435 * Perform basic clipping for glDrawPixels. The image's position and size
1436 * and the unpack SkipPixels and SkipRows are adjusted so that the image
1437 * region is entirely within the window and scissor bounds.
1438 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
1439 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
1440 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
1442 * \return GL_TRUE if image is ready for drawing or
1443 * GL_FALSE if image was completely clipped away (draw nothing)
1446 _mesa_clip_drawpixels(const struct gl_context
*ctx
,
1447 GLint
*destX
, GLint
*destY
,
1448 GLsizei
*width
, GLsizei
*height
,
1449 struct gl_pixelstore_attrib
*unpack
)
1451 const struct gl_framebuffer
*buffer
= ctx
->DrawBuffer
;
1453 if (unpack
->RowLength
== 0) {
1454 unpack
->RowLength
= *width
;
1457 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
1458 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
1461 if (*destX
< buffer
->_Xmin
) {
1462 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
1463 *width
-= (buffer
->_Xmin
- *destX
);
1464 *destX
= buffer
->_Xmin
;
1466 /* right clipping */
1467 if (*destX
+ *width
> buffer
->_Xmax
)
1468 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
1473 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
1474 /* bottom clipping */
1475 if (*destY
< buffer
->_Ymin
) {
1476 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
1477 *height
-= (buffer
->_Ymin
- *destY
);
1478 *destY
= buffer
->_Ymin
;
1481 if (*destY
+ *height
> buffer
->_Ymax
)
1482 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
1484 else { /* upside down */
1486 if (*destY
> buffer
->_Ymax
) {
1487 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
1488 *height
-= (*destY
- buffer
->_Ymax
);
1489 *destY
= buffer
->_Ymax
;
1491 /* bottom clipping */
1492 if (*destY
- *height
< buffer
->_Ymin
)
1493 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
1494 /* adjust destY so it's the first row to write to */
1506 * Perform clipping for glReadPixels. The image's window position
1507 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
1508 * so that the image region is entirely within the window bounds.
1509 * Note: this is different from _mesa_clip_drawpixels() in that the
1510 * scissor box is ignored, and we use the bounds of the current readbuffer
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_readpixels(const struct gl_context
*ctx
,
1518 GLint
*srcX
, GLint
*srcY
,
1519 GLsizei
*width
, GLsizei
*height
,
1520 struct gl_pixelstore_attrib
*pack
)
1522 const struct gl_framebuffer
*buffer
= ctx
->ReadBuffer
;
1524 if (pack
->RowLength
== 0) {
1525 pack
->RowLength
= *width
;
1530 pack
->SkipPixels
+= (0 - *srcX
);
1531 *width
-= (0 - *srcX
);
1534 /* right clipping */
1535 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
1536 *width
-= (*srcX
+ *width
- buffer
->Width
);
1541 /* bottom clipping */
1543 pack
->SkipRows
+= (0 - *srcY
);
1544 *height
-= (0 - *srcY
);
1548 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
1549 *height
-= (*srcY
+ *height
- buffer
->Height
);
1559 * Do clipping for a glCopyTexSubImage call.
1560 * The framebuffer source region might extend outside the framebuffer
1561 * bounds. Clip the source region against the framebuffer bounds and
1562 * adjust the texture/dest position and size accordingly.
1564 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
1567 _mesa_clip_copytexsubimage(const struct gl_context
*ctx
,
1568 GLint
*destX
, GLint
*destY
,
1569 GLint
*srcX
, GLint
*srcY
,
1570 GLsizei
*width
, GLsizei
*height
)
1572 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
1573 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
1575 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
1576 srcX
, srcY
, width
, height
)) {
1577 *destX
= *destX
+ *srcX
- srcX0
;
1578 *destY
= *destY
+ *srcY
- srcY0
;
1590 * Clip the rectangle defined by (x, y, width, height) against the bounds
1591 * specified by [xmin, xmax) and [ymin, ymax).
1592 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
1595 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
1596 GLint xmax
, GLint ymax
,
1598 GLsizei
*width
, GLsizei
*height
)
1602 *width
-= (xmin
- *x
);
1606 /* right clipping */
1607 if (*x
+ *width
> xmax
)
1608 *width
-= (*x
+ *width
- xmax
);
1613 /* bottom (or top) clipping */
1615 *height
-= (ymin
- *y
);
1619 /* top (or bottom) clipping */
1620 if (*y
+ *height
> ymax
)
1621 *height
-= (*y
+ *height
- ymax
);
1631 * Clip dst coords against Xmax (or Ymax).
1634 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
1635 GLint
*dstX0
, GLint
*dstX1
,
1640 if (*dstX1
> maxValue
) {
1641 /* X1 outside right edge */
1642 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
1643 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1644 /* chop off [t, 1] part */
1645 ASSERT(t
>= 0.0 && t
<= 1.0);
1647 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1648 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1650 else if (*dstX0
> maxValue
) {
1651 /* X0 outside right edge */
1652 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
1653 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1654 /* chop off [t, 1] part */
1655 ASSERT(t
>= 0.0 && t
<= 1.0);
1657 bias
= (*srcX0
< *srcX1
) ? -0.5F
: 0.5F
;
1658 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1664 * Clip dst coords against Xmin (or Ymin).
1667 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
1668 GLint
*dstX0
, GLint
*dstX1
,
1673 if (*dstX0
< minValue
) {
1674 /* X0 outside left edge */
1675 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
1676 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1677 /* chop off [0, t] part */
1678 ASSERT(t
>= 0.0 && t
<= 1.0);
1680 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
; /* flipped??? */
1681 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1683 else if (*dstX1
< minValue
) {
1684 /* X1 outside left edge */
1685 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
1686 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1687 /* chop off [0, t] part */
1688 ASSERT(t
>= 0.0 && t
<= 1.0);
1690 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1691 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1697 * Do clipping of blit src/dest rectangles.
1698 * The dest rect is clipped against both the buffer bounds and scissor bounds.
1699 * The src rect is just clipped against the buffer bounds.
1701 * When either the src or dest rect is clipped, the other is also clipped
1704 * Note that X0 need not be less than X1 (same for Y) for either the source
1705 * and dest rects. That makes the clipping a little trickier.
1707 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
1710 _mesa_clip_blit(struct gl_context
*ctx
,
1711 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
1712 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
1714 const GLint srcXmin
= 0;
1715 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
1716 const GLint srcYmin
= 0;
1717 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
1719 /* these include scissor bounds */
1720 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
1721 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
1722 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
1723 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
1726 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
1727 *srcX0, *srcX1, *dstX0, *dstX1);
1728 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
1729 *srcY0, *srcY1, *dstY0, *dstY1);
1732 /* trivial rejection tests */
1733 if (*dstX0
== *dstX1
)
1734 return GL_FALSE
; /* no width */
1735 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
1736 return GL_FALSE
; /* totally out (left) of bounds */
1737 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
1738 return GL_FALSE
; /* totally out (right) of bounds */
1740 if (*dstY0
== *dstY1
)
1742 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
1744 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
1747 if (*srcX0
== *srcX1
)
1749 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
1751 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
1754 if (*srcY0
== *srcY1
)
1756 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
1758 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
1764 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
1765 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
1766 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
1767 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
1770 * src clip (just swap src/dst values from above)
1772 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
1773 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
1774 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
1775 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
1778 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
1779 *srcX0, *srcX1, *dstX0, *dstX1);
1780 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
1781 *srcY0, *srcY1, *dstY0, *dstY1);
1784 ASSERT(*dstX0
>= dstXmin
);
1785 ASSERT(*dstX0
<= dstXmax
);
1786 ASSERT(*dstX1
>= dstXmin
);
1787 ASSERT(*dstX1
<= dstXmax
);
1789 ASSERT(*dstY0
>= dstYmin
);
1790 ASSERT(*dstY0
<= dstYmax
);
1791 ASSERT(*dstY1
>= dstYmin
);
1792 ASSERT(*dstY1
<= dstYmax
);
1794 ASSERT(*srcX0
>= srcXmin
);
1795 ASSERT(*srcX0
<= srcXmax
);
1796 ASSERT(*srcX1
>= srcXmin
);
1797 ASSERT(*srcX1
<= srcXmax
);
1799 ASSERT(*srcY0
>= srcYmin
);
1800 ASSERT(*srcY0
<= srcYmax
);
1801 ASSERT(*srcY1
>= srcYmin
);
1802 ASSERT(*srcY1
<= srcYmax
);