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
);
164 * Same as _mesa_sizeof_type() but also accepting the packed pixel
168 _mesa_sizeof_packed_type( GLenum type
)
173 case GL_UNSIGNED_BYTE
:
174 return sizeof(GLubyte
);
176 return sizeof(GLbyte
);
177 case GL_UNSIGNED_SHORT
:
178 return sizeof(GLushort
);
180 return sizeof(GLshort
);
181 case GL_UNSIGNED_INT
:
182 return sizeof(GLuint
);
184 return sizeof(GLint
);
185 case GL_HALF_FLOAT_ARB
:
186 return sizeof(GLhalfARB
);
188 return sizeof(GLfloat
);
189 case GL_UNSIGNED_BYTE_3_3_2
:
190 return sizeof(GLubyte
);
191 case GL_UNSIGNED_BYTE_2_3_3_REV
:
192 return sizeof(GLubyte
);
193 case GL_UNSIGNED_SHORT_5_6_5
:
194 return sizeof(GLushort
);
195 case GL_UNSIGNED_SHORT_5_6_5_REV
:
196 return sizeof(GLushort
);
197 case GL_UNSIGNED_SHORT_4_4_4_4
:
198 return sizeof(GLushort
);
199 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
200 return sizeof(GLushort
);
201 case GL_UNSIGNED_SHORT_5_5_5_1
:
202 return sizeof(GLushort
);
203 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
204 return sizeof(GLushort
);
205 case GL_UNSIGNED_INT_8_8_8_8
:
206 return sizeof(GLuint
);
207 case GL_UNSIGNED_INT_8_8_8_8_REV
:
208 return sizeof(GLuint
);
209 case GL_UNSIGNED_INT_10_10_10_2
:
210 return sizeof(GLuint
);
211 case GL_UNSIGNED_INT_2_10_10_10_REV
:
212 return sizeof(GLuint
);
213 case GL_UNSIGNED_SHORT_8_8_MESA
:
214 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
215 return sizeof(GLushort
);
216 case GL_UNSIGNED_INT_24_8_EXT
:
217 return sizeof(GLuint
);
225 * Get the number of components in a pixel format.
227 * \param format pixel format.
229 * \return the number of components in the given format, or -1 if a bad format.
232 _mesa_components_in_format( GLenum format
)
236 case GL_COLOR_INDEX1_EXT
:
237 case GL_COLOR_INDEX2_EXT
:
238 case GL_COLOR_INDEX4_EXT
:
239 case GL_COLOR_INDEX8_EXT
:
240 case GL_COLOR_INDEX12_EXT
:
241 case GL_COLOR_INDEX16_EXT
:
242 case GL_STENCIL_INDEX
:
243 case GL_DEPTH_COMPONENT
:
245 case GL_RED_INTEGER_EXT
:
247 case GL_GREEN_INTEGER_EXT
:
249 case GL_BLUE_INTEGER_EXT
:
251 case GL_ALPHA_INTEGER_EXT
:
253 case GL_LUMINANCE_INTEGER_EXT
:
256 case GL_LUMINANCE_ALPHA
:
257 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
261 case GL_RGB_INTEGER_EXT
:
264 case GL_RGBA_INTEGER_EXT
:
274 case GL_DEPTH_STENCIL_EXT
:
286 * Get the bytes per pixel of pixel format type pair.
288 * \param format pixel format.
289 * \param type pixel type.
291 * \return bytes per pixel, or -1 if a bad format or type was given.
294 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
296 GLint comps
= _mesa_components_in_format( format
);
302 return 0; /* special case */
304 case GL_UNSIGNED_BYTE
:
305 return comps
* sizeof(GLubyte
);
307 case GL_UNSIGNED_SHORT
:
308 return comps
* sizeof(GLshort
);
310 case GL_UNSIGNED_INT
:
311 return comps
* sizeof(GLint
);
313 return comps
* sizeof(GLfloat
);
314 case GL_HALF_FLOAT_ARB
:
315 return comps
* sizeof(GLhalfARB
);
316 case GL_UNSIGNED_BYTE_3_3_2
:
317 case GL_UNSIGNED_BYTE_2_3_3_REV
:
318 if (format
== GL_RGB
|| format
== GL_BGR
)
319 return sizeof(GLubyte
);
321 return -1; /* error */
322 case GL_UNSIGNED_SHORT_5_6_5
:
323 case GL_UNSIGNED_SHORT_5_6_5_REV
:
324 if (format
== GL_RGB
|| format
== GL_BGR
)
325 return sizeof(GLushort
);
327 return -1; /* error */
328 case GL_UNSIGNED_SHORT_4_4_4_4
:
329 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
330 case GL_UNSIGNED_SHORT_5_5_5_1
:
331 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
332 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
333 return sizeof(GLushort
);
336 case GL_UNSIGNED_INT_8_8_8_8
:
337 case GL_UNSIGNED_INT_8_8_8_8_REV
:
338 case GL_UNSIGNED_INT_10_10_10_2
:
339 case GL_UNSIGNED_INT_2_10_10_10_REV
:
340 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
)
341 return sizeof(GLuint
);
344 case GL_UNSIGNED_SHORT_8_8_MESA
:
345 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
346 if (format
== GL_YCBCR_MESA
)
347 return sizeof(GLushort
);
350 case GL_UNSIGNED_INT_24_8_EXT
:
351 if (format
== GL_DEPTH_STENCIL_EXT
)
352 return sizeof(GLuint
);
362 * Test for a legal pixel format and type.
364 * \param format pixel format.
365 * \param type pixel type.
367 * \return GL_TRUE if the given pixel format and type are legal, or GL_FALSE
371 _mesa_is_legal_format_and_type( struct gl_context
*ctx
, GLenum format
, GLenum type
)
375 case GL_STENCIL_INDEX
:
379 case GL_UNSIGNED_BYTE
:
381 case GL_UNSIGNED_SHORT
:
383 case GL_UNSIGNED_INT
:
386 case GL_HALF_FLOAT_ARB
:
387 return ctx
->Extensions
.ARB_half_float_pixel
;
395 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
399 case GL_LUMINANCE_ALPHA
:
400 case GL_DEPTH_COMPONENT
:
403 case GL_UNSIGNED_BYTE
:
405 case GL_UNSIGNED_SHORT
:
407 case GL_UNSIGNED_INT
:
410 case GL_HALF_FLOAT_ARB
:
411 return ctx
->Extensions
.ARB_half_float_pixel
;
416 if (!ctx
->Extensions
.ARB_texture_rg
)
421 case GL_UNSIGNED_BYTE
:
423 case GL_UNSIGNED_SHORT
:
425 case GL_UNSIGNED_INT
:
428 case GL_HALF_FLOAT_ARB
:
429 return ctx
->Extensions
.ARB_half_float_pixel
;
436 case GL_UNSIGNED_BYTE
:
438 case GL_UNSIGNED_SHORT
:
440 case GL_UNSIGNED_INT
:
442 case GL_UNSIGNED_BYTE_3_3_2
:
443 case GL_UNSIGNED_BYTE_2_3_3_REV
:
444 case GL_UNSIGNED_SHORT_5_6_5
:
445 case GL_UNSIGNED_SHORT_5_6_5_REV
:
447 case GL_HALF_FLOAT_ARB
:
448 return ctx
->Extensions
.ARB_half_float_pixel
;
454 /* NOTE: no packed types are supported with BGR. That's
455 * intentional, according to the GL spec.
458 case GL_UNSIGNED_BYTE
:
460 case GL_UNSIGNED_SHORT
:
462 case GL_UNSIGNED_INT
:
465 case GL_HALF_FLOAT_ARB
:
466 return ctx
->Extensions
.ARB_half_float_pixel
;
475 case GL_UNSIGNED_BYTE
:
477 case GL_UNSIGNED_SHORT
:
479 case GL_UNSIGNED_INT
:
481 case GL_UNSIGNED_SHORT_4_4_4_4
:
482 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
483 case GL_UNSIGNED_SHORT_5_5_5_1
:
484 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
485 case GL_UNSIGNED_INT_8_8_8_8
:
486 case GL_UNSIGNED_INT_8_8_8_8_REV
:
487 case GL_UNSIGNED_INT_10_10_10_2
:
488 case GL_UNSIGNED_INT_2_10_10_10_REV
:
490 case GL_HALF_FLOAT_ARB
:
491 return ctx
->Extensions
.ARB_half_float_pixel
;
496 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
497 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
501 case GL_DEPTH_STENCIL_EXT
:
502 if (ctx
->Extensions
.EXT_packed_depth_stencil
503 && type
== GL_UNSIGNED_INT_24_8_EXT
)
511 case GL_UNSIGNED_BYTE
:
513 case GL_UNSIGNED_SHORT
:
515 case GL_UNSIGNED_INT
:
521 case GL_RED_INTEGER_EXT
:
522 case GL_GREEN_INTEGER_EXT
:
523 case GL_BLUE_INTEGER_EXT
:
524 case GL_ALPHA_INTEGER_EXT
:
525 case GL_RGB_INTEGER_EXT
:
526 case GL_RGBA_INTEGER_EXT
:
527 case GL_BGR_INTEGER_EXT
:
528 case GL_BGRA_INTEGER_EXT
:
529 case GL_LUMINANCE_INTEGER_EXT
:
530 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
533 case GL_UNSIGNED_BYTE
:
535 case GL_UNSIGNED_SHORT
:
537 case GL_UNSIGNED_INT
:
538 return ctx
->Extensions
.EXT_texture_integer
;
551 * Test if the given image format is a color/RGBA format (i.e., not color
552 * index, depth, stencil, etc).
553 * \param format the image format value (may by an internal texture format)
554 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
557 _mesa_is_color_format(GLenum format
)
575 case GL_LUMINANCE_ALPHA
:
576 case GL_LUMINANCE4_ALPHA4
:
577 case GL_LUMINANCE6_ALPHA2
:
578 case GL_LUMINANCE8_ALPHA8
:
579 case GL_LUMINANCE12_ALPHA4
:
580 case GL_LUMINANCE12_ALPHA12
:
581 case GL_LUMINANCE16_ALPHA16
:
613 /* float texture formats */
614 case GL_ALPHA16F_ARB
:
615 case GL_ALPHA32F_ARB
:
616 case GL_LUMINANCE16F_ARB
:
617 case GL_LUMINANCE32F_ARB
:
618 case GL_LUMINANCE_ALPHA16F_ARB
:
619 case GL_LUMINANCE_ALPHA32F_ARB
:
620 case GL_INTENSITY16F_ARB
:
621 case GL_INTENSITY32F_ARB
:
630 /* compressed formats */
631 case GL_COMPRESSED_ALPHA
:
632 case GL_COMPRESSED_LUMINANCE
:
633 case GL_COMPRESSED_LUMINANCE_ALPHA
:
634 case GL_COMPRESSED_INTENSITY
:
635 case GL_COMPRESSED_RED
:
636 case GL_COMPRESSED_RG
:
637 case GL_COMPRESSED_RGB
:
638 case GL_COMPRESSED_RGBA
:
643 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
644 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
645 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
646 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
647 case GL_COMPRESSED_RGB_FXT1_3DFX
:
648 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
649 #if FEATURE_EXT_texture_sRGB
652 case GL_SRGB_ALPHA_EXT
:
653 case GL_SRGB8_ALPHA8_EXT
:
654 case GL_SLUMINANCE_ALPHA_EXT
:
655 case GL_SLUMINANCE8_ALPHA8_EXT
:
656 case GL_SLUMINANCE_EXT
:
657 case GL_SLUMINANCE8_EXT
:
658 case GL_COMPRESSED_SRGB_EXT
:
659 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
660 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
661 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
662 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
663 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
664 case GL_COMPRESSED_SLUMINANCE_EXT
:
665 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
666 #endif /* FEATURE_EXT_texture_sRGB */
667 case GL_COMPRESSED_RED_RGTC1
:
668 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
669 case GL_COMPRESSED_RG_RGTC2
:
670 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
671 /* signed, normalized texture formats */
674 /* generic integer formats */
675 case GL_RED_INTEGER_EXT
:
676 case GL_GREEN_INTEGER_EXT
:
677 case GL_BLUE_INTEGER_EXT
:
678 case GL_ALPHA_INTEGER_EXT
:
679 case GL_RGB_INTEGER_EXT
:
680 case GL_RGBA_INTEGER_EXT
:
681 case GL_BGR_INTEGER_EXT
:
682 case GL_BGRA_INTEGER_EXT
:
683 case GL_LUMINANCE_INTEGER_EXT
:
684 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
685 /* sized integer formats */
686 case GL_RGBA32UI_EXT
:
688 case GL_ALPHA32UI_EXT
:
689 case GL_INTENSITY32UI_EXT
:
690 case GL_LUMINANCE32UI_EXT
:
691 case GL_LUMINANCE_ALPHA32UI_EXT
:
692 case GL_RGBA16UI_EXT
:
694 case GL_ALPHA16UI_EXT
:
695 case GL_INTENSITY16UI_EXT
:
696 case GL_LUMINANCE16UI_EXT
:
697 case GL_LUMINANCE_ALPHA16UI_EXT
:
700 case GL_ALPHA8UI_EXT
:
701 case GL_INTENSITY8UI_EXT
:
702 case GL_LUMINANCE8UI_EXT
:
703 case GL_LUMINANCE_ALPHA8UI_EXT
:
706 case GL_ALPHA32I_EXT
:
707 case GL_INTENSITY32I_EXT
:
708 case GL_LUMINANCE32I_EXT
:
709 case GL_LUMINANCE_ALPHA32I_EXT
:
712 case GL_ALPHA16I_EXT
:
713 case GL_INTENSITY16I_EXT
:
714 case GL_LUMINANCE16I_EXT
:
715 case GL_LUMINANCE_ALPHA16I_EXT
:
719 case GL_INTENSITY8I_EXT
:
720 case GL_LUMINANCE8I_EXT
:
721 case GL_LUMINANCE_ALPHA8I_EXT
:
723 case GL_YCBCR_MESA
: /* not considered to be RGB */
732 * Test if the given image format is a color index format.
735 _mesa_is_index_format(GLenum format
)
739 case GL_COLOR_INDEX1_EXT
:
740 case GL_COLOR_INDEX2_EXT
:
741 case GL_COLOR_INDEX4_EXT
:
742 case GL_COLOR_INDEX8_EXT
:
743 case GL_COLOR_INDEX12_EXT
:
744 case GL_COLOR_INDEX16_EXT
:
753 * Test if the given image format is a depth component format.
756 _mesa_is_depth_format(GLenum format
)
759 case GL_DEPTH_COMPONENT
:
760 case GL_DEPTH_COMPONENT16
:
761 case GL_DEPTH_COMPONENT24
:
762 case GL_DEPTH_COMPONENT32
:
771 * Test if the given image format is a stencil format.
774 _mesa_is_stencil_format(GLenum format
)
777 case GL_STENCIL_INDEX
:
778 case GL_DEPTH_STENCIL
:
787 * Test if the given image format is a YCbCr format.
790 _mesa_is_ycbcr_format(GLenum format
)
802 * Test if the given image format is a depth+stencil format.
805 _mesa_is_depthstencil_format(GLenum format
)
808 case GL_DEPTH24_STENCIL8_EXT
:
809 case GL_DEPTH_STENCIL_EXT
:
818 * Test if the given image format is a depth or stencil format.
821 _mesa_is_depth_or_stencil_format(GLenum format
)
824 case GL_DEPTH_COMPONENT
:
825 case GL_DEPTH_COMPONENT16
:
826 case GL_DEPTH_COMPONENT24
:
827 case GL_DEPTH_COMPONENT32
:
828 case GL_STENCIL_INDEX
:
829 case GL_STENCIL_INDEX1_EXT
:
830 case GL_STENCIL_INDEX4_EXT
:
831 case GL_STENCIL_INDEX8_EXT
:
832 case GL_STENCIL_INDEX16_EXT
:
833 case GL_DEPTH_STENCIL_EXT
:
834 case GL_DEPTH24_STENCIL8_EXT
:
843 * Test if the given image format is a dudv format.
846 _mesa_is_dudv_format(GLenum format
)
859 * Test if the given format is an integer (non-normalized) format.
862 _mesa_is_integer_format(GLenum format
)
865 /* generic integer formats */
866 case GL_RED_INTEGER_EXT
:
867 case GL_GREEN_INTEGER_EXT
:
868 case GL_BLUE_INTEGER_EXT
:
869 case GL_ALPHA_INTEGER_EXT
:
870 case GL_RGB_INTEGER_EXT
:
871 case GL_RGBA_INTEGER_EXT
:
872 case GL_BGR_INTEGER_EXT
:
873 case GL_BGRA_INTEGER_EXT
:
874 case GL_LUMINANCE_INTEGER_EXT
:
875 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
876 /* specific integer formats */
877 case GL_RGBA32UI_EXT
:
879 case GL_ALPHA32UI_EXT
:
880 case GL_INTENSITY32UI_EXT
:
881 case GL_LUMINANCE32UI_EXT
:
882 case GL_LUMINANCE_ALPHA32UI_EXT
:
883 case GL_RGBA16UI_EXT
:
885 case GL_ALPHA16UI_EXT
:
886 case GL_INTENSITY16UI_EXT
:
887 case GL_LUMINANCE16UI_EXT
:
888 case GL_LUMINANCE_ALPHA16UI_EXT
:
891 case GL_ALPHA8UI_EXT
:
892 case GL_INTENSITY8UI_EXT
:
893 case GL_LUMINANCE8UI_EXT
:
894 case GL_LUMINANCE_ALPHA8UI_EXT
:
897 case GL_ALPHA32I_EXT
:
898 case GL_INTENSITY32I_EXT
:
899 case GL_LUMINANCE32I_EXT
:
900 case GL_LUMINANCE_ALPHA32I_EXT
:
903 case GL_ALPHA16I_EXT
:
904 case GL_INTENSITY16I_EXT
:
905 case GL_LUMINANCE16I_EXT
:
906 case GL_LUMINANCE_ALPHA16I_EXT
:
910 case GL_INTENSITY8I_EXT
:
911 case GL_LUMINANCE8I_EXT
:
912 case GL_LUMINANCE_ALPHA8I_EXT
:
921 * Test if an image format is a supported compressed format.
922 * \param format the internal format token provided by the user.
923 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
926 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
929 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
930 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
931 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
932 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
933 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
938 return ctx
->Extensions
.S3_s3tc
;
939 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
940 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
941 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
942 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
943 return ctx
->Extensions
.EXT_texture_sRGB
944 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
945 case GL_COMPRESSED_RGB_FXT1_3DFX
:
946 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
947 return ctx
->Extensions
.TDFX_texture_compression_FXT1
;
948 case GL_COMPRESSED_RED_RGTC1
:
949 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
950 case GL_COMPRESSED_RG_RGTC2
:
951 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
952 return ctx
->Extensions
.ARB_texture_compression_rgtc
;
960 * Return the address of a specific pixel in an image (1D, 2D or 3D).
962 * Pixel unpacking/packing parameters are observed according to \p packing.
964 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
965 * \param image starting address of image data
966 * \param width the image width
967 * \param height theimage height
968 * \param format the pixel format
969 * \param type the pixel data type
970 * \param packing the pixelstore attributes
971 * \param img which image in the volume (0 for 1D or 2D images)
972 * \param row row of pixel in the image (0 for 1D images)
973 * \param column column of pixel in the image
975 * \return address of pixel on success, or NULL on error.
977 * \sa gl_pixelstore_attrib.
980 _mesa_image_address( GLuint dimensions
,
981 const struct gl_pixelstore_attrib
*packing
,
983 GLsizei width
, GLsizei height
,
984 GLenum format
, GLenum type
,
985 GLint img
, GLint row
, GLint column
)
987 GLint alignment
; /* 1, 2 or 4 */
988 GLint pixels_per_row
;
989 GLint rows_per_image
;
992 GLint skipimages
; /* for 3-D volume images */
995 ASSERT(dimensions
>= 1 && dimensions
<= 3);
997 alignment
= packing
->Alignment
;
998 if (packing
->RowLength
> 0) {
999 pixels_per_row
= packing
->RowLength
;
1002 pixels_per_row
= width
;
1004 if (packing
->ImageHeight
> 0) {
1005 rows_per_image
= packing
->ImageHeight
;
1008 rows_per_image
= height
;
1011 skippixels
= packing
->SkipPixels
;
1012 /* Note: SKIP_ROWS _is_ used for 1D images */
1013 skiprows
= packing
->SkipRows
;
1014 /* Note: SKIP_IMAGES is only used for 3D images */
1015 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
1017 if (type
== GL_BITMAP
) {
1019 GLint comp_per_pixel
; /* components per pixel */
1020 GLint bytes_per_comp
; /* bytes per component */
1021 GLint bytes_per_row
;
1022 GLint bytes_per_image
;
1024 /* Compute bytes per component */
1025 bytes_per_comp
= _mesa_sizeof_packed_type( type
);
1026 if (bytes_per_comp
< 0) {
1030 /* Compute number of components per pixel */
1031 comp_per_pixel
= _mesa_components_in_format( format
);
1032 if (comp_per_pixel
< 0) {
1036 bytes_per_row
= alignment
1037 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
1039 bytes_per_image
= bytes_per_row
* rows_per_image
;
1041 pixel_addr
= (GLubyte
*) image
1042 + (skipimages
+ img
) * bytes_per_image
1043 + (skiprows
+ row
) * bytes_per_row
1044 + (skippixels
+ column
) / 8;
1047 /* Non-BITMAP data */
1048 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
1051 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
1053 /* The pixel type and format should have been error checked earlier */
1054 assert(bytes_per_pixel
> 0);
1056 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
1057 remainder
= bytes_per_row
% alignment
;
1059 bytes_per_row
+= (alignment
- remainder
);
1061 ASSERT(bytes_per_row
% alignment
== 0);
1063 bytes_per_image
= bytes_per_row
* rows_per_image
;
1065 if (packing
->Invert
) {
1066 /* set pixel_addr to the last row */
1067 topOfImage
= bytes_per_row
* (height
- 1);
1068 bytes_per_row
= -bytes_per_row
;
1074 /* compute final pixel address */
1075 pixel_addr
= (GLubyte
*) image
1076 + (skipimages
+ img
) * bytes_per_image
1078 + (skiprows
+ row
) * bytes_per_row
1079 + (skippixels
+ column
) * bytes_per_pixel
;
1082 return (GLvoid
*) pixel_addr
;
1087 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
1088 const GLvoid
*image
,
1090 GLenum format
, GLenum type
,
1093 return _mesa_image_address(1, packing
, image
, width
, 1,
1094 format
, type
, 0, 0, column
);
1099 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
1100 const GLvoid
*image
,
1101 GLsizei width
, GLsizei height
,
1102 GLenum format
, GLenum type
,
1103 GLint row
, GLint column
)
1105 return _mesa_image_address(2, packing
, image
, width
, height
,
1106 format
, type
, 0, row
, column
);
1111 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
1112 const GLvoid
*image
,
1113 GLsizei width
, GLsizei height
,
1114 GLenum format
, GLenum type
,
1115 GLint img
, GLint row
, GLint column
)
1117 return _mesa_image_address(3, packing
, image
, width
, height
,
1118 format
, type
, img
, row
, column
);
1124 * Compute the stride (in bytes) between image rows.
1126 * \param packing the pixelstore attributes
1127 * \param width image width.
1128 * \param format pixel format.
1129 * \param type pixel data type.
1131 * \return the stride in bytes for the given parameters, or -1 if error
1134 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
1135 GLint width
, GLenum format
, GLenum type
)
1137 GLint bytesPerRow
, remainder
;
1141 if (type
== GL_BITMAP
) {
1142 if (packing
->RowLength
== 0) {
1143 bytesPerRow
= (width
+ 7) / 8;
1146 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1150 /* Non-BITMAP data */
1151 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1152 if (bytesPerPixel
<= 0)
1153 return -1; /* error */
1154 if (packing
->RowLength
== 0) {
1155 bytesPerRow
= bytesPerPixel
* width
;
1158 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1162 remainder
= bytesPerRow
% packing
->Alignment
;
1163 if (remainder
> 0) {
1164 bytesPerRow
+= (packing
->Alignment
- remainder
);
1167 if (packing
->Invert
) {
1168 /* negate the bytes per row (negative row stride) */
1169 bytesPerRow
= -bytesPerRow
;
1177 * Compute the stride between images in a 3D texture (in bytes) for the given
1178 * pixel packing parameters and image width, format and type.
1181 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1182 GLint width
, GLint height
,
1183 GLenum format
, GLenum type
)
1185 GLint bytesPerRow
, bytesPerImage
, remainder
;
1189 if (type
== GL_BITMAP
) {
1190 if (packing
->RowLength
== 0) {
1191 bytesPerRow
= (width
+ 7) / 8;
1194 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1198 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1200 if (bytesPerPixel
<= 0)
1201 return -1; /* error */
1202 if (packing
->RowLength
== 0) {
1203 bytesPerRow
= bytesPerPixel
* width
;
1206 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1210 remainder
= bytesPerRow
% packing
->Alignment
;
1212 bytesPerRow
+= (packing
->Alignment
- remainder
);
1214 if (packing
->ImageHeight
== 0)
1215 bytesPerImage
= bytesPerRow
* height
;
1217 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1219 return bytesPerImage
;
1225 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1226 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1227 * "On" bits will set texels to \p onValue.
1228 * "Off" bits will not modify texels.
1229 * \param width src bitmap width in pixels
1230 * \param height src bitmap height in pixels
1231 * \param unpack bitmap unpacking state
1232 * \param bitmap the src bitmap data
1233 * \param destBuffer start of dest buffer
1234 * \param destStride row stride in dest buffer
1235 * \param onValue if bit is 1, set destBuffer pixel to this value
1238 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1239 const struct gl_pixelstore_attrib
*unpack
,
1240 const GLubyte
*bitmap
,
1241 GLubyte
*destBuffer
, GLint destStride
,
1244 const GLubyte
*srcRow
= (const GLubyte
*)
1245 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1246 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1247 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1248 GL_COLOR_INDEX
, GL_BITMAP
);
1251 #define SET_PIXEL(COL, ROW) \
1252 destBuffer[(ROW) * destStride + (COL)] = onValue;
1254 for (row
= 0; row
< height
; row
++) {
1255 const GLubyte
*src
= srcRow
;
1257 if (unpack
->LsbFirst
) {
1259 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1260 for (col
= 0; col
< width
; col
++) {
1263 SET_PIXEL(col
, row
);
1275 /* get ready for next row */
1281 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1282 for (col
= 0; col
< width
; col
++) {
1285 SET_PIXEL(col
, row
);
1297 /* get ready for next row */
1302 srcRow
+= srcStride
;
1312 * Convert an array of RGBA colors from one datatype to another.
1313 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1316 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
1317 GLenum dstType
, GLvoid
*dst
,
1318 GLuint count
, const GLubyte mask
[])
1320 GLuint tempBuffer
[MAX_WIDTH
][4];
1321 const GLboolean useTemp
= (src
== dst
);
1323 ASSERT(srcType
!= dstType
);
1326 case GL_UNSIGNED_BYTE
:
1327 if (dstType
== GL_UNSIGNED_SHORT
) {
1328 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1329 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1331 for (i
= 0; i
< count
; i
++) {
1332 if (!mask
|| mask
[i
]) {
1333 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
1334 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
1335 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
1336 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
1340 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1343 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1344 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1346 ASSERT(dstType
== GL_FLOAT
);
1347 for (i
= 0; i
< count
; i
++) {
1348 if (!mask
|| mask
[i
]) {
1349 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
1350 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
1351 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
1352 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
1356 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1359 case GL_UNSIGNED_SHORT
:
1360 if (dstType
== GL_UNSIGNED_BYTE
) {
1361 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1362 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1364 for (i
= 0; i
< count
; i
++) {
1365 if (!mask
|| mask
[i
]) {
1366 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
1367 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
1368 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
1369 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
1373 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1376 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1377 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1379 ASSERT(dstType
== GL_FLOAT
);
1380 for (i
= 0; i
< count
; i
++) {
1381 if (!mask
|| mask
[i
]) {
1382 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
1383 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
1384 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
1385 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
1389 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1393 if (dstType
== GL_UNSIGNED_BYTE
) {
1394 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1395 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1397 for (i
= 0; i
< count
; i
++) {
1398 if (!mask
|| mask
[i
]) {
1399 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][RCOMP
], src4
[i
][RCOMP
]);
1400 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][GCOMP
], src4
[i
][GCOMP
]);
1401 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][BCOMP
], src4
[i
][BCOMP
]);
1402 UNCLAMPED_FLOAT_TO_UBYTE(dst1
[i
][ACOMP
], src4
[i
][ACOMP
]);
1406 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1409 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1410 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1412 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
1413 for (i
= 0; i
< count
; i
++) {
1414 if (!mask
|| mask
[i
]) {
1415 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
1416 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
1417 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
1418 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
1422 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1426 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
1434 * Perform basic clipping for glDrawPixels. The image's position and size
1435 * and the unpack SkipPixels and SkipRows are adjusted so that the image
1436 * region is entirely within the window and scissor bounds.
1437 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
1438 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
1439 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
1441 * \return GL_TRUE if image is ready for drawing or
1442 * GL_FALSE if image was completely clipped away (draw nothing)
1445 _mesa_clip_drawpixels(const struct gl_context
*ctx
,
1446 GLint
*destX
, GLint
*destY
,
1447 GLsizei
*width
, GLsizei
*height
,
1448 struct gl_pixelstore_attrib
*unpack
)
1450 const struct gl_framebuffer
*buffer
= ctx
->DrawBuffer
;
1452 if (unpack
->RowLength
== 0) {
1453 unpack
->RowLength
= *width
;
1456 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
1457 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
1460 if (*destX
< buffer
->_Xmin
) {
1461 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
1462 *width
-= (buffer
->_Xmin
- *destX
);
1463 *destX
= buffer
->_Xmin
;
1465 /* right clipping */
1466 if (*destX
+ *width
> buffer
->_Xmax
)
1467 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
1472 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
1473 /* bottom clipping */
1474 if (*destY
< buffer
->_Ymin
) {
1475 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
1476 *height
-= (buffer
->_Ymin
- *destY
);
1477 *destY
= buffer
->_Ymin
;
1480 if (*destY
+ *height
> buffer
->_Ymax
)
1481 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
1483 else { /* upside down */
1485 if (*destY
> buffer
->_Ymax
) {
1486 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
1487 *height
-= (*destY
- buffer
->_Ymax
);
1488 *destY
= buffer
->_Ymax
;
1490 /* bottom clipping */
1491 if (*destY
- *height
< buffer
->_Ymin
)
1492 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
1493 /* adjust destY so it's the first row to write to */
1505 * Perform clipping for glReadPixels. The image's window position
1506 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
1507 * so that the image region is entirely within the window bounds.
1508 * Note: this is different from _mesa_clip_drawpixels() in that the
1509 * scissor box is ignored, and we use the bounds of the current readbuffer
1512 * \return GL_TRUE if image is ready for drawing or
1513 * GL_FALSE if image was completely clipped away (draw nothing)
1516 _mesa_clip_readpixels(const struct gl_context
*ctx
,
1517 GLint
*srcX
, GLint
*srcY
,
1518 GLsizei
*width
, GLsizei
*height
,
1519 struct gl_pixelstore_attrib
*pack
)
1521 const struct gl_framebuffer
*buffer
= ctx
->ReadBuffer
;
1523 if (pack
->RowLength
== 0) {
1524 pack
->RowLength
= *width
;
1529 pack
->SkipPixels
+= (0 - *srcX
);
1530 *width
-= (0 - *srcX
);
1533 /* right clipping */
1534 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
1535 *width
-= (*srcX
+ *width
- buffer
->Width
);
1540 /* bottom clipping */
1542 pack
->SkipRows
+= (0 - *srcY
);
1543 *height
-= (0 - *srcY
);
1547 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
1548 *height
-= (*srcY
+ *height
- buffer
->Height
);
1558 * Do clipping for a glCopyTexSubImage call.
1559 * The framebuffer source region might extend outside the framebuffer
1560 * bounds. Clip the source region against the framebuffer bounds and
1561 * adjust the texture/dest position and size accordingly.
1563 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
1566 _mesa_clip_copytexsubimage(const struct gl_context
*ctx
,
1567 GLint
*destX
, GLint
*destY
,
1568 GLint
*srcX
, GLint
*srcY
,
1569 GLsizei
*width
, GLsizei
*height
)
1571 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
1572 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
1574 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
1575 srcX
, srcY
, width
, height
)) {
1576 *destX
= *destX
+ *srcX
- srcX0
;
1577 *destY
= *destY
+ *srcY
- srcY0
;
1589 * Clip the rectangle defined by (x, y, width, height) against the bounds
1590 * specified by [xmin, xmax) and [ymin, ymax).
1591 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
1594 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
1595 GLint xmax
, GLint ymax
,
1597 GLsizei
*width
, GLsizei
*height
)
1601 *width
-= (xmin
- *x
);
1605 /* right clipping */
1606 if (*x
+ *width
> xmax
)
1607 *width
-= (*x
+ *width
- xmax
);
1612 /* bottom (or top) clipping */
1614 *height
-= (ymin
- *y
);
1618 /* top (or bottom) clipping */
1619 if (*y
+ *height
> ymax
)
1620 *height
-= (*y
+ *height
- ymax
);
1630 * Clip dst coords against Xmax (or Ymax).
1633 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
1634 GLint
*dstX0
, GLint
*dstX1
,
1639 if (*dstX1
> maxValue
) {
1640 /* X1 outside right edge */
1641 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
1642 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1643 /* chop off [t, 1] part */
1644 ASSERT(t
>= 0.0 && t
<= 1.0);
1646 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1647 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1649 else if (*dstX0
> maxValue
) {
1650 /* X0 outside right edge */
1651 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
1652 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1653 /* chop off [t, 1] part */
1654 ASSERT(t
>= 0.0 && t
<= 1.0);
1656 bias
= (*srcX0
< *srcX1
) ? -0.5F
: 0.5F
;
1657 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1663 * Clip dst coords against Xmin (or Ymin).
1666 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
1667 GLint
*dstX0
, GLint
*dstX1
,
1672 if (*dstX0
< minValue
) {
1673 /* X0 outside left edge */
1674 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
1675 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1676 /* chop off [0, t] part */
1677 ASSERT(t
>= 0.0 && t
<= 1.0);
1679 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
; /* flipped??? */
1680 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1682 else if (*dstX1
< minValue
) {
1683 /* X1 outside left edge */
1684 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
1685 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1686 /* chop off [0, t] part */
1687 ASSERT(t
>= 0.0 && t
<= 1.0);
1689 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1690 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1696 * Do clipping of blit src/dest rectangles.
1697 * The dest rect is clipped against both the buffer bounds and scissor bounds.
1698 * The src rect is just clipped against the buffer bounds.
1700 * When either the src or dest rect is clipped, the other is also clipped
1703 * Note that X0 need not be less than X1 (same for Y) for either the source
1704 * and dest rects. That makes the clipping a little trickier.
1706 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
1709 _mesa_clip_blit(struct gl_context
*ctx
,
1710 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
1711 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
1713 const GLint srcXmin
= 0;
1714 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
1715 const GLint srcYmin
= 0;
1716 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
1718 /* these include scissor bounds */
1719 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
1720 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
1721 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
1722 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
1725 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
1726 *srcX0, *srcX1, *dstX0, *dstX1);
1727 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
1728 *srcY0, *srcY1, *dstY0, *dstY1);
1731 /* trivial rejection tests */
1732 if (*dstX0
== *dstX1
)
1733 return GL_FALSE
; /* no width */
1734 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
1735 return GL_FALSE
; /* totally out (left) of bounds */
1736 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
1737 return GL_FALSE
; /* totally out (right) of bounds */
1739 if (*dstY0
== *dstY1
)
1741 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
1743 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
1746 if (*srcX0
== *srcX1
)
1748 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
1750 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
1753 if (*srcY0
== *srcY1
)
1755 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
1757 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
1763 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
1764 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
1765 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
1766 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
1769 * src clip (just swap src/dst values from above)
1771 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
1772 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
1773 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
1774 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
1777 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
1778 *srcX0, *srcX1, *dstX0, *dstX1);
1779 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
1780 *srcY0, *srcY1, *dstY0, *dstY1);
1783 ASSERT(*dstX0
>= dstXmin
);
1784 ASSERT(*dstX0
<= dstXmax
);
1785 ASSERT(*dstX1
>= dstXmin
);
1786 ASSERT(*dstX1
<= dstXmax
);
1788 ASSERT(*dstY0
>= dstYmin
);
1789 ASSERT(*dstY0
<= dstYmax
);
1790 ASSERT(*dstY1
>= dstYmin
);
1791 ASSERT(*dstY1
<= dstYmax
);
1793 ASSERT(*srcX0
>= srcXmin
);
1794 ASSERT(*srcX0
<= srcXmax
);
1795 ASSERT(*srcX1
>= srcXmin
);
1796 ASSERT(*srcX1
<= srcXmax
);
1798 ASSERT(*srcY0
>= srcYmin
);
1799 ASSERT(*srcY0
<= srcYmax
);
1800 ASSERT(*srcY1
>= srcYmin
);
1801 ASSERT(*srcY1
<= srcYmax
);