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
:
673 /* signed texture formats */
677 case GL_YCBCR_MESA
: /* not considered to be RGB */
686 * Test if the given image format is a color index format.
689 _mesa_is_index_format(GLenum format
)
693 case GL_COLOR_INDEX1_EXT
:
694 case GL_COLOR_INDEX2_EXT
:
695 case GL_COLOR_INDEX4_EXT
:
696 case GL_COLOR_INDEX8_EXT
:
697 case GL_COLOR_INDEX12_EXT
:
698 case GL_COLOR_INDEX16_EXT
:
707 * Test if the given image format is a depth component format.
710 _mesa_is_depth_format(GLenum format
)
713 case GL_DEPTH_COMPONENT
:
714 case GL_DEPTH_COMPONENT16
:
715 case GL_DEPTH_COMPONENT24
:
716 case GL_DEPTH_COMPONENT32
:
725 * Test if the given image format is a stencil format.
728 _mesa_is_stencil_format(GLenum format
)
731 case GL_STENCIL_INDEX
:
732 case GL_DEPTH_STENCIL
:
741 * Test if the given image format is a YCbCr format.
744 _mesa_is_ycbcr_format(GLenum format
)
756 * Test if the given image format is a depth+stencil format.
759 _mesa_is_depthstencil_format(GLenum format
)
762 case GL_DEPTH24_STENCIL8_EXT
:
763 case GL_DEPTH_STENCIL_EXT
:
772 * Test if the given image format is a depth or stencil format.
775 _mesa_is_depth_or_stencil_format(GLenum format
)
778 case GL_DEPTH_COMPONENT
:
779 case GL_DEPTH_COMPONENT16
:
780 case GL_DEPTH_COMPONENT24
:
781 case GL_DEPTH_COMPONENT32
:
782 case GL_STENCIL_INDEX
:
783 case GL_STENCIL_INDEX1_EXT
:
784 case GL_STENCIL_INDEX4_EXT
:
785 case GL_STENCIL_INDEX8_EXT
:
786 case GL_STENCIL_INDEX16_EXT
:
787 case GL_DEPTH_STENCIL_EXT
:
788 case GL_DEPTH24_STENCIL8_EXT
:
797 * Test if the given image format is a dudv format.
800 _mesa_is_dudv_format(GLenum format
)
813 * Test if the given format is an integer (non-normalized) format.
816 _mesa_is_integer_format(GLenum format
)
819 case GL_RED_INTEGER_EXT
:
820 case GL_GREEN_INTEGER_EXT
:
821 case GL_BLUE_INTEGER_EXT
:
822 case GL_ALPHA_INTEGER_EXT
:
823 case GL_RGB_INTEGER_EXT
:
824 case GL_RGBA_INTEGER_EXT
:
825 case GL_BGR_INTEGER_EXT
:
826 case GL_BGRA_INTEGER_EXT
:
827 case GL_LUMINANCE_INTEGER_EXT
:
828 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
837 * Test if an image format is a supported compressed format.
838 * \param format the internal format token provided by the user.
839 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
842 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
845 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
846 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
847 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
848 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
849 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
854 return ctx
->Extensions
.S3_s3tc
;
855 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
856 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
857 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
858 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
859 return ctx
->Extensions
.EXT_texture_sRGB
860 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
861 case GL_COMPRESSED_RGB_FXT1_3DFX
:
862 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
863 return ctx
->Extensions
.TDFX_texture_compression_FXT1
;
864 case GL_COMPRESSED_RED_RGTC1
:
865 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
866 case GL_COMPRESSED_RG_RGTC2
:
867 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
868 return ctx
->Extensions
.ARB_texture_compression_rgtc
;
876 * Return the address of a specific pixel in an image (1D, 2D or 3D).
878 * Pixel unpacking/packing parameters are observed according to \p packing.
880 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
881 * \param image starting address of image data
882 * \param width the image width
883 * \param height theimage height
884 * \param format the pixel format
885 * \param type the pixel data type
886 * \param packing the pixelstore attributes
887 * \param img which image in the volume (0 for 1D or 2D images)
888 * \param row row of pixel in the image (0 for 1D images)
889 * \param column column of pixel in the image
891 * \return address of pixel on success, or NULL on error.
893 * \sa gl_pixelstore_attrib.
896 _mesa_image_address( GLuint dimensions
,
897 const struct gl_pixelstore_attrib
*packing
,
899 GLsizei width
, GLsizei height
,
900 GLenum format
, GLenum type
,
901 GLint img
, GLint row
, GLint column
)
903 GLint alignment
; /* 1, 2 or 4 */
904 GLint pixels_per_row
;
905 GLint rows_per_image
;
908 GLint skipimages
; /* for 3-D volume images */
911 ASSERT(dimensions
>= 1 && dimensions
<= 3);
913 alignment
= packing
->Alignment
;
914 if (packing
->RowLength
> 0) {
915 pixels_per_row
= packing
->RowLength
;
918 pixels_per_row
= width
;
920 if (packing
->ImageHeight
> 0) {
921 rows_per_image
= packing
->ImageHeight
;
924 rows_per_image
= height
;
927 skippixels
= packing
->SkipPixels
;
928 /* Note: SKIP_ROWS _is_ used for 1D images */
929 skiprows
= packing
->SkipRows
;
930 /* Note: SKIP_IMAGES is only used for 3D images */
931 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
933 if (type
== GL_BITMAP
) {
935 GLint comp_per_pixel
; /* components per pixel */
936 GLint bytes_per_comp
; /* bytes per component */
938 GLint bytes_per_image
;
940 /* Compute bytes per component */
941 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
942 if (bytes_per_comp
< 0) {
946 /* Compute number of components per pixel */
947 comp_per_pixel
= _mesa_components_in_format( format
);
948 if (comp_per_pixel
< 0) {
952 bytes_per_row
= alignment
953 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
955 bytes_per_image
= bytes_per_row
* rows_per_image
;
957 pixel_addr
= (GLubyte
*) image
958 + (skipimages
+ img
) * bytes_per_image
959 + (skiprows
+ row
) * bytes_per_row
960 + (skippixels
+ column
) / 8;
963 /* Non-BITMAP data */
964 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
967 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
969 /* The pixel type and format should have been error checked earlier */
970 assert(bytes_per_pixel
> 0);
972 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
973 remainder
= bytes_per_row
% alignment
;
975 bytes_per_row
+= (alignment
- remainder
);
977 ASSERT(bytes_per_row
% alignment
== 0);
979 bytes_per_image
= bytes_per_row
* rows_per_image
;
981 if (packing
->Invert
) {
982 /* set pixel_addr to the last row */
983 topOfImage
= bytes_per_row
* (height
- 1);
984 bytes_per_row
= -bytes_per_row
;
990 /* compute final pixel address */
991 pixel_addr
= (GLubyte
*) image
992 + (skipimages
+ img
) * bytes_per_image
994 + (skiprows
+ row
) * bytes_per_row
995 + (skippixels
+ column
) * bytes_per_pixel
;
998 return (GLvoid
*) pixel_addr
;
1003 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
1004 const GLvoid
*image
,
1006 GLenum format
, GLenum type
,
1009 return _mesa_image_address(1, packing
, image
, width
, 1,
1010 format
, type
, 0, 0, column
);
1015 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
1016 const GLvoid
*image
,
1017 GLsizei width
, GLsizei height
,
1018 GLenum format
, GLenum type
,
1019 GLint row
, GLint column
)
1021 return _mesa_image_address(2, packing
, image
, width
, height
,
1022 format
, type
, 0, row
, column
);
1027 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
1028 const GLvoid
*image
,
1029 GLsizei width
, GLsizei height
,
1030 GLenum format
, GLenum type
,
1031 GLint img
, GLint row
, GLint column
)
1033 return _mesa_image_address(3, packing
, image
, width
, height
,
1034 format
, type
, img
, row
, column
);
1040 * Compute the stride (in bytes) between image rows.
1042 * \param packing the pixelstore attributes
1043 * \param width image width.
1044 * \param format pixel format.
1045 * \param type pixel data type.
1047 * \return the stride in bytes for the given parameters, or -1 if error
1050 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
1051 GLint width
, GLenum format
, GLenum type
)
1053 GLint bytesPerRow
, remainder
;
1057 if (type
== GL_BITMAP
) {
1058 if (packing
->RowLength
== 0) {
1059 bytesPerRow
= (width
+ 7) / 8;
1062 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1066 /* Non-BITMAP data */
1067 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1068 if (bytesPerPixel
<= 0)
1069 return -1; /* error */
1070 if (packing
->RowLength
== 0) {
1071 bytesPerRow
= bytesPerPixel
* width
;
1074 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1078 remainder
= bytesPerRow
% packing
->Alignment
;
1079 if (remainder
> 0) {
1080 bytesPerRow
+= (packing
->Alignment
- remainder
);
1083 if (packing
->Invert
) {
1084 /* negate the bytes per row (negative row stride) */
1085 bytesPerRow
= -bytesPerRow
;
1093 * Compute the stride between images in a 3D texture (in bytes) for the given
1094 * pixel packing parameters and image width, format and type.
1097 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1098 GLint width
, GLint height
,
1099 GLenum format
, GLenum type
)
1101 GLint bytesPerRow
, bytesPerImage
, remainder
;
1105 if (type
== GL_BITMAP
) {
1106 if (packing
->RowLength
== 0) {
1107 bytesPerRow
= (width
+ 7) / 8;
1110 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1114 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1116 if (bytesPerPixel
<= 0)
1117 return -1; /* error */
1118 if (packing
->RowLength
== 0) {
1119 bytesPerRow
= bytesPerPixel
* width
;
1122 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1126 remainder
= bytesPerRow
% packing
->Alignment
;
1128 bytesPerRow
+= (packing
->Alignment
- remainder
);
1130 if (packing
->ImageHeight
== 0)
1131 bytesPerImage
= bytesPerRow
* height
;
1133 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1135 return bytesPerImage
;
1141 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1142 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1143 * "On" bits will set texels to \p onValue.
1144 * "Off" bits will not modify texels.
1145 * \param width src bitmap width in pixels
1146 * \param height src bitmap height in pixels
1147 * \param unpack bitmap unpacking state
1148 * \param bitmap the src bitmap data
1149 * \param destBuffer start of dest buffer
1150 * \param destStride row stride in dest buffer
1151 * \param onValue if bit is 1, set destBuffer pixel to this value
1154 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1155 const struct gl_pixelstore_attrib
*unpack
,
1156 const GLubyte
*bitmap
,
1157 GLubyte
*destBuffer
, GLint destStride
,
1160 const GLubyte
*srcRow
= (const GLubyte
*)
1161 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1162 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1163 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1164 GL_COLOR_INDEX
, GL_BITMAP
);
1167 #define SET_PIXEL(COL, ROW) \
1168 destBuffer[(ROW) * destStride + (COL)] = onValue;
1170 for (row
= 0; row
< height
; row
++) {
1171 const GLubyte
*src
= srcRow
;
1173 if (unpack
->LsbFirst
) {
1175 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1176 for (col
= 0; col
< width
; col
++) {
1179 SET_PIXEL(col
, row
);
1191 /* get ready for next row */
1197 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1198 for (col
= 0; col
< width
; col
++) {
1201 SET_PIXEL(col
, row
);
1213 /* get ready for next row */
1218 srcRow
+= srcStride
;
1228 * Convert an array of RGBA colors from one datatype to another.
1229 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1232 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
1233 GLenum dstType
, GLvoid
*dst
,
1234 GLuint count
, const GLubyte mask
[])
1236 GLuint tempBuffer
[MAX_WIDTH
][4];
1237 const GLboolean useTemp
= (src
== dst
);
1239 ASSERT(srcType
!= dstType
);
1242 case GL_UNSIGNED_BYTE
:
1243 if (dstType
== GL_UNSIGNED_SHORT
) {
1244 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1245 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1247 for (i
= 0; i
< count
; i
++) {
1248 if (!mask
|| mask
[i
]) {
1249 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
1250 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
1251 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
1252 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
1256 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1259 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1260 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1262 ASSERT(dstType
== GL_FLOAT
);
1263 for (i
= 0; i
< count
; i
++) {
1264 if (!mask
|| mask
[i
]) {
1265 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
1266 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
1267 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
1268 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
1272 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1275 case GL_UNSIGNED_SHORT
:
1276 if (dstType
== GL_UNSIGNED_BYTE
) {
1277 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1278 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1280 for (i
= 0; i
< count
; i
++) {
1281 if (!mask
|| mask
[i
]) {
1282 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
1283 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
1284 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
1285 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
1289 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1292 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1293 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1295 ASSERT(dstType
== GL_FLOAT
);
1296 for (i
= 0; i
< count
; i
++) {
1297 if (!mask
|| mask
[i
]) {
1298 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
1299 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
1300 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
1301 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
1305 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1309 if (dstType
== GL_UNSIGNED_BYTE
) {
1310 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1311 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1313 for (i
= 0; i
< count
; i
++) {
1314 if (!mask
|| mask
[i
]) {
1315 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
1316 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
1317 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
1318 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
1322 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1325 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1326 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1328 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
1329 for (i
= 0; i
< count
; i
++) {
1330 if (!mask
|| mask
[i
]) {
1331 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
1332 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
1333 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
1334 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
1338 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1342 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
1350 * Perform basic clipping for glDrawPixels. The image's position and size
1351 * and the unpack SkipPixels and SkipRows are adjusted so that the image
1352 * region is entirely within the window and scissor bounds.
1353 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
1354 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
1355 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
1357 * \return GL_TRUE if image is ready for drawing or
1358 * GL_FALSE if image was completely clipped away (draw nothing)
1361 _mesa_clip_drawpixels(const struct gl_context
*ctx
,
1362 GLint
*destX
, GLint
*destY
,
1363 GLsizei
*width
, GLsizei
*height
,
1364 struct gl_pixelstore_attrib
*unpack
)
1366 const struct gl_framebuffer
*buffer
= ctx
->DrawBuffer
;
1368 if (unpack
->RowLength
== 0) {
1369 unpack
->RowLength
= *width
;
1372 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
1373 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
1376 if (*destX
< buffer
->_Xmin
) {
1377 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
1378 *width
-= (buffer
->_Xmin
- *destX
);
1379 *destX
= buffer
->_Xmin
;
1381 /* right clipping */
1382 if (*destX
+ *width
> buffer
->_Xmax
)
1383 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
1388 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
1389 /* bottom clipping */
1390 if (*destY
< buffer
->_Ymin
) {
1391 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
1392 *height
-= (buffer
->_Ymin
- *destY
);
1393 *destY
= buffer
->_Ymin
;
1396 if (*destY
+ *height
> buffer
->_Ymax
)
1397 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
1399 else { /* upside down */
1401 if (*destY
> buffer
->_Ymax
) {
1402 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
1403 *height
-= (*destY
- buffer
->_Ymax
);
1404 *destY
= buffer
->_Ymax
;
1406 /* bottom clipping */
1407 if (*destY
- *height
< buffer
->_Ymin
)
1408 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
1409 /* adjust destY so it's the first row to write to */
1421 * Perform clipping for glReadPixels. The image's window position
1422 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
1423 * so that the image region is entirely within the window bounds.
1424 * Note: this is different from _mesa_clip_drawpixels() in that the
1425 * scissor box is ignored, and we use the bounds of the current readbuffer
1428 * \return GL_TRUE if image is ready for drawing or
1429 * GL_FALSE if image was completely clipped away (draw nothing)
1432 _mesa_clip_readpixels(const struct gl_context
*ctx
,
1433 GLint
*srcX
, GLint
*srcY
,
1434 GLsizei
*width
, GLsizei
*height
,
1435 struct gl_pixelstore_attrib
*pack
)
1437 const struct gl_framebuffer
*buffer
= ctx
->ReadBuffer
;
1439 if (pack
->RowLength
== 0) {
1440 pack
->RowLength
= *width
;
1445 pack
->SkipPixels
+= (0 - *srcX
);
1446 *width
-= (0 - *srcX
);
1449 /* right clipping */
1450 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
1451 *width
-= (*srcX
+ *width
- buffer
->Width
);
1456 /* bottom clipping */
1458 pack
->SkipRows
+= (0 - *srcY
);
1459 *height
-= (0 - *srcY
);
1463 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
1464 *height
-= (*srcY
+ *height
- buffer
->Height
);
1474 * Do clipping for a glCopyTexSubImage call.
1475 * The framebuffer source region might extend outside the framebuffer
1476 * bounds. Clip the source region against the framebuffer bounds and
1477 * adjust the texture/dest position and size accordingly.
1479 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
1482 _mesa_clip_copytexsubimage(const struct gl_context
*ctx
,
1483 GLint
*destX
, GLint
*destY
,
1484 GLint
*srcX
, GLint
*srcY
,
1485 GLsizei
*width
, GLsizei
*height
)
1487 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
1488 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
1490 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
1491 srcX
, srcY
, width
, height
)) {
1492 *destX
= *destX
+ *srcX
- srcX0
;
1493 *destY
= *destY
+ *srcY
- srcY0
;
1505 * Clip the rectangle defined by (x, y, width, height) against the bounds
1506 * specified by [xmin, xmax) and [ymin, ymax).
1507 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
1510 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
1511 GLint xmax
, GLint ymax
,
1513 GLsizei
*width
, GLsizei
*height
)
1517 *width
-= (xmin
- *x
);
1521 /* right clipping */
1522 if (*x
+ *width
> xmax
)
1523 *width
-= (*x
+ *width
- xmax
);
1528 /* bottom (or top) clipping */
1530 *height
-= (ymin
- *y
);
1534 /* top (or bottom) clipping */
1535 if (*y
+ *height
> ymax
)
1536 *height
-= (*y
+ *height
- ymax
);
1546 * Clip dst coords against Xmax (or Ymax).
1549 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
1550 GLint
*dstX0
, GLint
*dstX1
,
1555 if (*dstX1
> maxValue
) {
1556 /* X1 outside right edge */
1557 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
1558 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1559 /* chop off [t, 1] part */
1560 ASSERT(t
>= 0.0 && t
<= 1.0);
1562 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1563 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1565 else if (*dstX0
> maxValue
) {
1566 /* X0 outside right edge */
1567 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
1568 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1569 /* chop off [t, 1] part */
1570 ASSERT(t
>= 0.0 && t
<= 1.0);
1572 bias
= (*srcX0
< *srcX1
) ? -0.5F
: 0.5F
;
1573 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1579 * Clip dst coords against Xmin (or Ymin).
1582 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
1583 GLint
*dstX0
, GLint
*dstX1
,
1588 if (*dstX0
< minValue
) {
1589 /* X0 outside left edge */
1590 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
1591 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1592 /* chop off [0, t] part */
1593 ASSERT(t
>= 0.0 && t
<= 1.0);
1595 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
; /* flipped??? */
1596 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1598 else if (*dstX1
< minValue
) {
1599 /* X1 outside left edge */
1600 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
1601 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1602 /* chop off [0, t] part */
1603 ASSERT(t
>= 0.0 && t
<= 1.0);
1605 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1606 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1612 * Do clipping of blit src/dest rectangles.
1613 * The dest rect is clipped against both the buffer bounds and scissor bounds.
1614 * The src rect is just clipped against the buffer bounds.
1616 * When either the src or dest rect is clipped, the other is also clipped
1619 * Note that X0 need not be less than X1 (same for Y) for either the source
1620 * and dest rects. That makes the clipping a little trickier.
1622 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
1625 _mesa_clip_blit(struct gl_context
*ctx
,
1626 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
1627 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
1629 const GLint srcXmin
= 0;
1630 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
1631 const GLint srcYmin
= 0;
1632 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
1634 /* these include scissor bounds */
1635 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
1636 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
1637 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
1638 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
1641 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
1642 *srcX0, *srcX1, *dstX0, *dstX1);
1643 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
1644 *srcY0, *srcY1, *dstY0, *dstY1);
1647 /* trivial rejection tests */
1648 if (*dstX0
== *dstX1
)
1649 return GL_FALSE
; /* no width */
1650 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
1651 return GL_FALSE
; /* totally out (left) of bounds */
1652 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
1653 return GL_FALSE
; /* totally out (right) of bounds */
1655 if (*dstY0
== *dstY1
)
1657 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
1659 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
1662 if (*srcX0
== *srcX1
)
1664 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
1666 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
1669 if (*srcY0
== *srcY1
)
1671 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
1673 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
1679 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
1680 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
1681 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
1682 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
1685 * src clip (just swap src/dst values from above)
1687 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
1688 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
1689 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
1690 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
1693 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
1694 *srcX0, *srcX1, *dstX0, *dstX1);
1695 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
1696 *srcY0, *srcY1, *dstY0, *dstY1);
1699 ASSERT(*dstX0
>= dstXmin
);
1700 ASSERT(*dstX0
<= dstXmax
);
1701 ASSERT(*dstX1
>= dstXmin
);
1702 ASSERT(*dstX1
<= dstXmax
);
1704 ASSERT(*dstY0
>= dstYmin
);
1705 ASSERT(*dstY0
<= dstYmax
);
1706 ASSERT(*dstY1
>= dstYmin
);
1707 ASSERT(*dstY1
<= dstYmax
);
1709 ASSERT(*srcX0
>= srcXmin
);
1710 ASSERT(*srcX0
<= srcXmax
);
1711 ASSERT(*srcX1
>= srcXmin
);
1712 ASSERT(*srcX1
<= srcXmax
);
1714 ASSERT(*srcY0
>= srcYmin
);
1715 ASSERT(*srcY0
<= srcYmax
);
1716 ASSERT(*srcY1
>= srcYmin
);
1717 ASSERT(*srcY1
<= srcYmax
);