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.
34 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
37 _mesa_type_is_packed(GLenum type
)
40 case GL_UNSIGNED_BYTE_3_3_2
:
41 case GL_UNSIGNED_BYTE_2_3_3_REV
:
42 case MESA_UNSIGNED_BYTE_4_4
:
43 case GL_UNSIGNED_SHORT_5_6_5
:
44 case GL_UNSIGNED_SHORT_5_6_5_REV
:
45 case GL_UNSIGNED_SHORT_4_4_4_4
:
46 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
47 case GL_UNSIGNED_SHORT_5_5_5_1
:
48 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
49 case GL_UNSIGNED_INT_8_8_8_8
:
50 case GL_UNSIGNED_INT_8_8_8_8_REV
:
51 case GL_UNSIGNED_SHORT_8_8_MESA
:
52 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
53 case GL_UNSIGNED_INT_5_9_9_9_REV
:
54 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
64 * Flip the order of the 2 bytes in each word in the given array.
67 * \param n number of words.
70 _mesa_swap2( GLushort
*p
, GLuint n
)
73 for (i
= 0; i
< n
; i
++) {
74 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
81 * Flip the order of the 4 bytes in each word in the given array.
84 _mesa_swap4( GLuint
*p
, GLuint n
)
87 for (i
= 0; i
< n
; i
++) {
91 | ((b
<< 8) & 0xff0000)
92 | ((b
<< 24) & 0xff000000);
99 * Get the size of a GL data type.
101 * \param type GL data type.
103 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
104 * if an invalid type enum.
107 _mesa_sizeof_type( GLenum type
)
112 case GL_UNSIGNED_BYTE
:
113 return sizeof(GLubyte
);
115 return sizeof(GLbyte
);
116 case GL_UNSIGNED_SHORT
:
117 return sizeof(GLushort
);
119 return sizeof(GLshort
);
120 case GL_UNSIGNED_INT
:
121 return sizeof(GLuint
);
123 return sizeof(GLint
);
125 return sizeof(GLfloat
);
127 return sizeof(GLdouble
);
129 return sizeof(GLfixed
);
137 * Same as _mesa_sizeof_type() but also accepting the packed pixel
141 _mesa_sizeof_packed_type( GLenum type
)
146 case GL_UNSIGNED_BYTE
:
147 return sizeof(GLubyte
);
149 return sizeof(GLbyte
);
150 case GL_UNSIGNED_SHORT
:
151 return sizeof(GLushort
);
153 return sizeof(GLshort
);
154 case GL_UNSIGNED_INT
:
155 return sizeof(GLuint
);
157 return sizeof(GLint
);
159 return sizeof(GLfloat
);
160 case GL_UNSIGNED_BYTE_3_3_2
:
161 case GL_UNSIGNED_BYTE_2_3_3_REV
:
162 case MESA_UNSIGNED_BYTE_4_4
:
163 return sizeof(GLubyte
);
164 case GL_UNSIGNED_SHORT_5_6_5
:
165 case GL_UNSIGNED_SHORT_5_6_5_REV
:
166 case GL_UNSIGNED_SHORT_4_4_4_4
:
167 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
168 case GL_UNSIGNED_SHORT_5_5_5_1
:
169 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
170 case GL_UNSIGNED_SHORT_8_8_MESA
:
171 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
172 return sizeof(GLushort
);
173 case GL_UNSIGNED_INT_8_8_8_8
:
174 case GL_UNSIGNED_INT_8_8_8_8_REV
:
175 case GL_UNSIGNED_INT_5_9_9_9_REV
:
176 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
177 return sizeof(GLuint
);
185 * Get the number of components in a pixel format.
187 * \param format pixel format.
189 * \return the number of components in the given format, or -1 if a bad format.
192 _mesa_components_in_format( GLenum format
)
196 case GL_STENCIL_INDEX
:
197 case GL_DEPTH_COMPONENT
:
199 case GL_RED_INTEGER_EXT
:
201 case GL_GREEN_INTEGER_EXT
:
203 case GL_BLUE_INTEGER_EXT
:
205 case GL_ALPHA_INTEGER_EXT
:
207 case GL_LUMINANCE_INTEGER_EXT
:
211 case GL_LUMINANCE_ALPHA
:
212 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
220 case GL_RGB_INTEGER_EXT
:
221 case GL_BGR_INTEGER_EXT
:
227 case GL_RGBA_INTEGER_EXT
:
228 case GL_BGRA_INTEGER_EXT
:
238 * Get the bytes per pixel of pixel format type pair.
240 * \param format pixel format.
241 * \param type pixel type.
243 * \return bytes per pixel, or -1 if a bad format or type was given.
246 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
248 GLint comps
= _mesa_components_in_format( format
);
254 return 0; /* special case */
256 case GL_UNSIGNED_BYTE
:
257 return comps
* sizeof(GLubyte
);
259 case GL_UNSIGNED_SHORT
:
260 return comps
* sizeof(GLshort
);
262 case GL_UNSIGNED_INT
:
263 return comps
* sizeof(GLint
);
265 return comps
* sizeof(GLfloat
);
266 case GL_UNSIGNED_BYTE_3_3_2
:
267 case GL_UNSIGNED_BYTE_2_3_3_REV
:
268 if (format
== GL_RGB
|| format
== GL_BGR
||
269 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
270 return sizeof(GLubyte
);
272 return -1; /* error */
273 case GL_UNSIGNED_SHORT_5_6_5
:
274 case GL_UNSIGNED_SHORT_5_6_5_REV
:
275 if (format
== GL_RGB
|| format
== GL_BGR
||
276 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
277 return sizeof(GLushort
);
279 return -1; /* error */
280 case GL_UNSIGNED_SHORT_4_4_4_4
:
281 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
282 case GL_UNSIGNED_SHORT_5_5_5_1
:
283 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
284 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
285 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
286 return sizeof(GLushort
);
289 case GL_UNSIGNED_INT_8_8_8_8
:
290 case GL_UNSIGNED_INT_8_8_8_8_REV
:
291 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
292 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
293 return sizeof(GLuint
);
296 case GL_UNSIGNED_SHORT_8_8_MESA
:
297 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
298 if (format
== GL_YCBCR_MESA
)
299 return sizeof(GLushort
);
302 case GL_UNSIGNED_INT_5_9_9_9_REV
:
303 if (format
== GL_RGB
)
304 return sizeof(GLuint
);
307 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
308 if (format
== GL_RGB
)
309 return sizeof(GLuint
);
319 * Do error checking of format/type combinations for glReadPixels,
320 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
321 * and type values, we may either generate GL_INVALID_OPERATION or
324 * \param format pixel format.
325 * \param type pixel type.
327 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
330 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
331 GLenum format
, GLenum type
)
333 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
336 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
337 return GL_INVALID_ENUM
;
341 case GL_UNSIGNED_BYTE_3_3_2
:
342 case GL_UNSIGNED_BYTE_2_3_3_REV
:
343 case GL_UNSIGNED_SHORT_5_6_5
:
344 case GL_UNSIGNED_SHORT_5_6_5_REV
:
345 if (format
== GL_RGB
) {
348 return GL_INVALID_OPERATION
;
350 case GL_UNSIGNED_SHORT_4_4_4_4
:
351 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
352 case GL_UNSIGNED_SHORT_5_5_5_1
:
353 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
354 case GL_UNSIGNED_INT_8_8_8_8
:
355 case GL_UNSIGNED_INT_8_8_8_8_REV
:
356 if (format
== GL_RGBA
||
358 format
== GL_ABGR_EXT
) {
361 return GL_INVALID_OPERATION
;
367 /* now, for each format, check the type for compatibility */
370 case GL_STENCIL_INDEX
:
374 case GL_UNSIGNED_BYTE
:
376 case GL_UNSIGNED_SHORT
:
378 case GL_UNSIGNED_INT
:
382 return GL_INVALID_ENUM
;
389 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
393 case GL_LUMINANCE_ALPHA
:
394 case GL_DEPTH_COMPONENT
:
397 case GL_UNSIGNED_BYTE
:
399 case GL_UNSIGNED_SHORT
:
401 case GL_UNSIGNED_INT
:
405 return GL_INVALID_ENUM
;
411 case GL_UNSIGNED_BYTE
:
413 case GL_UNSIGNED_SHORT
:
415 case GL_UNSIGNED_INT
:
417 case GL_UNSIGNED_BYTE_3_3_2
:
418 case GL_UNSIGNED_BYTE_2_3_3_REV
:
419 case GL_UNSIGNED_SHORT_5_6_5
:
420 case GL_UNSIGNED_SHORT_5_6_5_REV
:
423 return GL_INVALID_ENUM
;
428 /* NOTE: no packed types are supported with BGR. That's
429 * intentional, according to the GL spec.
432 case GL_UNSIGNED_BYTE
:
434 case GL_UNSIGNED_SHORT
:
436 case GL_UNSIGNED_INT
:
440 return GL_INVALID_ENUM
;
448 case GL_UNSIGNED_BYTE
:
450 case GL_UNSIGNED_SHORT
:
452 case GL_UNSIGNED_INT
:
454 case GL_UNSIGNED_SHORT_4_4_4_4
:
455 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
456 case GL_UNSIGNED_SHORT_5_5_5_1
:
457 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
458 case GL_UNSIGNED_INT_8_8_8_8
:
459 case GL_UNSIGNED_INT_8_8_8_8_REV
:
462 return GL_INVALID_ENUM
;
466 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
467 return GL_INVALID_ENUM
;
468 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
469 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
472 return GL_INVALID_OPERATION
;
474 /* integer-valued formats */
475 case GL_RED_INTEGER_EXT
:
476 case GL_GREEN_INTEGER_EXT
:
477 case GL_BLUE_INTEGER_EXT
:
478 case GL_ALPHA_INTEGER_EXT
:
482 case GL_UNSIGNED_BYTE
:
484 case GL_UNSIGNED_SHORT
:
486 case GL_UNSIGNED_INT
:
487 return (ctx
->VersionMajor
>= 3 ||
488 ctx
->Extensions
.EXT_texture_integer
)
489 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
491 return GL_INVALID_ENUM
;
494 case GL_RGB_INTEGER_EXT
:
497 case GL_UNSIGNED_BYTE
:
499 case GL_UNSIGNED_SHORT
:
501 case GL_UNSIGNED_INT
:
502 return (ctx
->VersionMajor
>= 3 ||
503 ctx
->Extensions
.EXT_texture_integer
)
504 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
506 return GL_INVALID_ENUM
;
509 case GL_BGR_INTEGER_EXT
:
512 case GL_UNSIGNED_BYTE
:
514 case GL_UNSIGNED_SHORT
:
516 case GL_UNSIGNED_INT
:
517 /* NOTE: no packed formats w/ BGR format */
518 return (ctx
->VersionMajor
>= 3 ||
519 ctx
->Extensions
.EXT_texture_integer
)
520 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
522 return GL_INVALID_ENUM
;
525 case GL_RGBA_INTEGER_EXT
:
526 case GL_BGRA_INTEGER_EXT
:
529 case GL_UNSIGNED_BYTE
:
531 case GL_UNSIGNED_SHORT
:
533 case GL_UNSIGNED_INT
:
534 return (ctx
->VersionMajor
>= 3 ||
535 ctx
->Extensions
.EXT_texture_integer
)
536 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
538 return GL_INVALID_ENUM
;
541 case GL_LUMINANCE_INTEGER_EXT
:
542 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
545 case GL_UNSIGNED_BYTE
:
547 case GL_UNSIGNED_SHORT
:
549 case GL_UNSIGNED_INT
:
550 return ctx
->Extensions
.EXT_texture_integer
551 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
553 return GL_INVALID_ENUM
;
557 return GL_INVALID_ENUM
;
564 * Test if the given image format is a color/RGBA format (i.e., not color
565 * index, depth, stencil, etc).
566 * \param format the image format value (may by an internal texture format)
567 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
570 _mesa_is_color_format(GLenum format
)
588 case GL_LUMINANCE_ALPHA
:
589 case GL_LUMINANCE4_ALPHA4
:
590 case GL_LUMINANCE6_ALPHA2
:
591 case GL_LUMINANCE8_ALPHA8
:
592 case GL_LUMINANCE12_ALPHA4
:
593 case GL_LUMINANCE12_ALPHA12
:
594 case GL_LUMINANCE16_ALPHA16
:
626 /* float texture formats */
627 case GL_ALPHA16F_ARB
:
628 case GL_ALPHA32F_ARB
:
629 case GL_LUMINANCE16F_ARB
:
630 case GL_LUMINANCE32F_ARB
:
631 case GL_LUMINANCE_ALPHA16F_ARB
:
632 case GL_LUMINANCE_ALPHA32F_ARB
:
633 case GL_INTENSITY16F_ARB
:
634 case GL_INTENSITY32F_ARB
:
643 /* generic integer formats */
644 case GL_RED_INTEGER_EXT
:
645 case GL_GREEN_INTEGER_EXT
:
646 case GL_BLUE_INTEGER_EXT
:
647 case GL_ALPHA_INTEGER_EXT
:
648 case GL_RGB_INTEGER_EXT
:
649 case GL_RGBA_INTEGER_EXT
:
650 case GL_BGR_INTEGER_EXT
:
651 case GL_BGRA_INTEGER_EXT
:
652 case GL_LUMINANCE_INTEGER_EXT
:
653 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
654 /* sized integer formats */
655 case GL_RGBA32UI_EXT
:
657 case GL_ALPHA32UI_EXT
:
658 case GL_INTENSITY32UI_EXT
:
659 case GL_LUMINANCE32UI_EXT
:
660 case GL_LUMINANCE_ALPHA32UI_EXT
:
661 case GL_RGBA16UI_EXT
:
663 case GL_ALPHA16UI_EXT
:
664 case GL_INTENSITY16UI_EXT
:
665 case GL_LUMINANCE16UI_EXT
:
666 case GL_LUMINANCE_ALPHA16UI_EXT
:
669 case GL_ALPHA8UI_EXT
:
670 case GL_INTENSITY8UI_EXT
:
671 case GL_LUMINANCE8UI_EXT
:
672 case GL_LUMINANCE_ALPHA8UI_EXT
:
675 case GL_ALPHA32I_EXT
:
676 case GL_INTENSITY32I_EXT
:
677 case GL_LUMINANCE32I_EXT
:
678 case GL_LUMINANCE_ALPHA32I_EXT
:
681 case GL_ALPHA16I_EXT
:
682 case GL_INTENSITY16I_EXT
:
683 case GL_LUMINANCE16I_EXT
:
684 case GL_LUMINANCE_ALPHA16I_EXT
:
688 case GL_INTENSITY8I_EXT
:
689 case GL_LUMINANCE8I_EXT
:
690 case GL_LUMINANCE_ALPHA8I_EXT
:
691 case GL_R11F_G11F_B10F
:
694 case GL_YCBCR_MESA
: /* not considered to be RGB */
703 * Test if the given image format is a depth component format.
706 _mesa_is_depth_format(GLenum format
)
709 case GL_DEPTH_COMPONENT
:
710 case GL_DEPTH_COMPONENT16
:
711 case GL_DEPTH_COMPONENT24
:
712 case GL_DEPTH_COMPONENT32
:
721 * Test if the given image format is a stencil format.
724 _mesa_is_stencil_format(GLenum format
)
727 case GL_STENCIL_INDEX
:
736 * Test if the given image format is a YCbCr format.
739 _mesa_is_ycbcr_format(GLenum format
)
751 * Test if the given image format is a depth or stencil format.
754 _mesa_is_depth_or_stencil_format(GLenum format
)
757 case GL_DEPTH_COMPONENT
:
758 case GL_DEPTH_COMPONENT16
:
759 case GL_DEPTH_COMPONENT24
:
760 case GL_DEPTH_COMPONENT32
:
761 case GL_STENCIL_INDEX
:
762 case GL_STENCIL_INDEX1_EXT
:
763 case GL_STENCIL_INDEX4_EXT
:
764 case GL_STENCIL_INDEX8_EXT
:
765 case GL_STENCIL_INDEX16_EXT
:
774 * Test if the given format is an integer (non-normalized) format.
777 _mesa_is_integer_format(GLenum format
)
780 /* generic integer formats */
781 case GL_RED_INTEGER_EXT
:
782 case GL_GREEN_INTEGER_EXT
:
783 case GL_BLUE_INTEGER_EXT
:
784 case GL_ALPHA_INTEGER_EXT
:
785 case GL_RGB_INTEGER_EXT
:
786 case GL_RGBA_INTEGER_EXT
:
787 case GL_BGR_INTEGER_EXT
:
788 case GL_BGRA_INTEGER_EXT
:
789 case GL_LUMINANCE_INTEGER_EXT
:
790 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
792 /* specific integer formats */
793 case GL_RGBA32UI_EXT
:
797 case GL_ALPHA32UI_EXT
:
798 case GL_INTENSITY32UI_EXT
:
799 case GL_LUMINANCE32UI_EXT
:
800 case GL_LUMINANCE_ALPHA32UI_EXT
:
801 case GL_RGBA16UI_EXT
:
805 case GL_ALPHA16UI_EXT
:
806 case GL_INTENSITY16UI_EXT
:
807 case GL_LUMINANCE16UI_EXT
:
808 case GL_LUMINANCE_ALPHA16UI_EXT
:
813 case GL_ALPHA8UI_EXT
:
814 case GL_INTENSITY8UI_EXT
:
815 case GL_LUMINANCE8UI_EXT
:
816 case GL_LUMINANCE_ALPHA8UI_EXT
:
821 case GL_ALPHA32I_EXT
:
822 case GL_INTENSITY32I_EXT
:
823 case GL_LUMINANCE32I_EXT
:
824 case GL_LUMINANCE_ALPHA32I_EXT
:
829 case GL_ALPHA16I_EXT
:
830 case GL_INTENSITY16I_EXT
:
831 case GL_LUMINANCE16I_EXT
:
832 case GL_LUMINANCE_ALPHA16I_EXT
:
838 case GL_INTENSITY8I_EXT
:
839 case GL_LUMINANCE8I_EXT
:
840 case GL_LUMINANCE_ALPHA8I_EXT
:
850 * Does the given base texture/renderbuffer format have the channel
854 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
857 case GL_TEXTURE_RED_SIZE
:
858 case GL_TEXTURE_RED_TYPE
:
859 case GL_RENDERBUFFER_RED_SIZE_EXT
:
860 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
861 if (base_format
== GL_RED
||
862 base_format
== GL_RG
||
863 base_format
== GL_RGB
||
864 base_format
== GL_RGBA
) {
868 case GL_TEXTURE_GREEN_SIZE
:
869 case GL_TEXTURE_GREEN_TYPE
:
870 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
871 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
872 if (base_format
== GL_RG
||
873 base_format
== GL_RGB
||
874 base_format
== GL_RGBA
) {
878 case GL_TEXTURE_BLUE_SIZE
:
879 case GL_TEXTURE_BLUE_TYPE
:
880 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
881 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
882 if (base_format
== GL_RGB
||
883 base_format
== GL_RGBA
) {
887 case GL_TEXTURE_ALPHA_SIZE
:
888 case GL_TEXTURE_ALPHA_TYPE
:
889 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
890 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
891 if (base_format
== GL_RGBA
||
892 base_format
== GL_ALPHA
||
893 base_format
== GL_LUMINANCE_ALPHA
) {
897 case GL_TEXTURE_LUMINANCE_SIZE
:
898 case GL_TEXTURE_LUMINANCE_TYPE
:
899 if (base_format
== GL_LUMINANCE
||
900 base_format
== GL_LUMINANCE_ALPHA
) {
904 case GL_TEXTURE_INTENSITY_SIZE
:
905 case GL_TEXTURE_INTENSITY_TYPE
:
906 if (base_format
== GL_INTENSITY
) {
910 case GL_TEXTURE_DEPTH_SIZE
:
911 case GL_TEXTURE_DEPTH_TYPE
:
912 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
913 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
914 if (base_format
== GL_DEPTH_COMPONENT
) {
918 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
919 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
920 if (base_format
== GL_STENCIL_INDEX
) {
925 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
926 __FUNCTION__
, pname
);
935 * Return the byte offset of a specific pixel in an image (1D, 2D or 3D).
937 * Pixel unpacking/packing parameters are observed according to \p packing.
939 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
940 * \param packing the pixelstore attributes
941 * \param width the image width
942 * \param height the image height
943 * \param format the pixel format (must be validated beforehand)
944 * \param type the pixel data type (must be validated beforehand)
945 * \param img which image in the volume (0 for 1D or 2D images)
946 * \param row row of pixel in the image (0 for 1D images)
947 * \param column column of pixel in the image
949 * \return offset of pixel.
951 * \sa gl_pixelstore_attrib.
954 _mesa_image_offset( GLuint dimensions
,
955 const struct gl_pixelstore_attrib
*packing
,
956 GLsizei width
, GLsizei height
,
957 GLenum format
, GLenum type
,
958 GLint img
, GLint row
, GLint column
)
960 GLint alignment
; /* 1, 2 or 4 */
961 GLint pixels_per_row
;
962 GLint rows_per_image
;
965 GLint skipimages
; /* for 3-D volume images */
968 ASSERT(dimensions
>= 1 && dimensions
<= 3);
970 alignment
= packing
->Alignment
;
971 if (packing
->RowLength
> 0) {
972 pixels_per_row
= packing
->RowLength
;
975 pixels_per_row
= width
;
977 if (packing
->ImageHeight
> 0) {
978 rows_per_image
= packing
->ImageHeight
;
981 rows_per_image
= height
;
984 skippixels
= packing
->SkipPixels
;
985 /* Note: SKIP_ROWS _is_ used for 1D images */
986 skiprows
= packing
->SkipRows
;
987 /* Note: SKIP_IMAGES is only used for 3D images */
988 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
990 if (type
== GL_BITMAP
) {
993 GLint bytes_per_image
;
994 /* components per pixel for color or stencil index: */
995 const GLint comp_per_pixel
= 1;
997 /* The pixel type and format should have been error checked earlier */
998 assert(format
== GL_COLOR_INDEX
|| format
== GL_STENCIL_INDEX
);
1000 bytes_per_row
= alignment
1001 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
1003 bytes_per_image
= bytes_per_row
* rows_per_image
;
1005 offset
= (skipimages
+ img
) * bytes_per_image
1006 + (skiprows
+ row
) * bytes_per_row
1007 + (skippixels
+ column
) / 8;
1010 /* Non-BITMAP data */
1011 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
1014 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
1016 /* The pixel type and format should have been error checked earlier */
1017 assert(bytes_per_pixel
> 0);
1019 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
1020 remainder
= bytes_per_row
% alignment
;
1022 bytes_per_row
+= (alignment
- remainder
);
1024 ASSERT(bytes_per_row
% alignment
== 0);
1026 bytes_per_image
= bytes_per_row
* rows_per_image
;
1028 if (packing
->Invert
) {
1029 /* set pixel_addr to the last row */
1030 topOfImage
= bytes_per_row
* (height
- 1);
1031 bytes_per_row
= -bytes_per_row
;
1037 /* compute final pixel address */
1038 offset
= (skipimages
+ img
) * bytes_per_image
1040 + (skiprows
+ row
) * bytes_per_row
1041 + (skippixels
+ column
) * bytes_per_pixel
;
1049 * Return the address of a specific pixel in an image (1D, 2D or 3D).
1051 * Pixel unpacking/packing parameters are observed according to \p packing.
1053 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
1054 * \param packing the pixelstore attributes
1055 * \param image starting address of image data
1056 * \param width the image width
1057 * \param height the image height
1058 * \param format the pixel format (must be validated beforehand)
1059 * \param type the pixel data type (must be validated beforehand)
1060 * \param img which image in the volume (0 for 1D or 2D images)
1061 * \param row row of pixel in the image (0 for 1D images)
1062 * \param column column of pixel in the image
1064 * \return address of pixel.
1066 * \sa gl_pixelstore_attrib.
1069 _mesa_image_address( GLuint dimensions
,
1070 const struct gl_pixelstore_attrib
*packing
,
1071 const GLvoid
*image
,
1072 GLsizei width
, GLsizei height
,
1073 GLenum format
, GLenum type
,
1074 GLint img
, GLint row
, GLint column
)
1076 const GLubyte
*addr
= (const GLubyte
*) image
;
1078 addr
+= _mesa_image_offset(dimensions
, packing
, width
, height
,
1079 format
, type
, img
, row
, column
);
1081 return (GLvoid
*) addr
;
1086 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
1087 const GLvoid
*image
,
1089 GLenum format
, GLenum type
,
1092 return _mesa_image_address(1, packing
, image
, width
, 1,
1093 format
, type
, 0, 0, column
);
1098 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
1099 const GLvoid
*image
,
1100 GLsizei width
, GLsizei height
,
1101 GLenum format
, GLenum type
,
1102 GLint row
, GLint column
)
1104 return _mesa_image_address(2, packing
, image
, width
, height
,
1105 format
, type
, 0, row
, column
);
1110 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
1111 const GLvoid
*image
,
1112 GLsizei width
, GLsizei height
,
1113 GLenum format
, GLenum type
,
1114 GLint img
, GLint row
, GLint column
)
1116 return _mesa_image_address(3, packing
, image
, width
, height
,
1117 format
, type
, img
, row
, column
);
1123 * Compute the stride (in bytes) between image rows.
1125 * \param packing the pixelstore attributes
1126 * \param width image width.
1127 * \param format pixel format.
1128 * \param type pixel data type.
1130 * \return the stride in bytes for the given parameters, or -1 if error
1133 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
1134 GLint width
, GLenum format
, GLenum type
)
1136 GLint bytesPerRow
, remainder
;
1140 if (type
== GL_BITMAP
) {
1141 if (packing
->RowLength
== 0) {
1142 bytesPerRow
= (width
+ 7) / 8;
1145 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1149 /* Non-BITMAP data */
1150 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1151 if (bytesPerPixel
<= 0)
1152 return -1; /* error */
1153 if (packing
->RowLength
== 0) {
1154 bytesPerRow
= bytesPerPixel
* width
;
1157 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1161 remainder
= bytesPerRow
% packing
->Alignment
;
1162 if (remainder
> 0) {
1163 bytesPerRow
+= (packing
->Alignment
- remainder
);
1166 if (packing
->Invert
) {
1167 /* negate the bytes per row (negative row stride) */
1168 bytesPerRow
= -bytesPerRow
;
1176 * Compute the stride between images in a 3D texture (in bytes) for the given
1177 * pixel packing parameters and image width, format and type.
1180 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1181 GLint width
, GLint height
,
1182 GLenum format
, GLenum type
)
1184 GLint bytesPerRow
, bytesPerImage
, remainder
;
1188 if (type
== GL_BITMAP
) {
1189 if (packing
->RowLength
== 0) {
1190 bytesPerRow
= (width
+ 7) / 8;
1193 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1197 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1199 if (bytesPerPixel
<= 0)
1200 return -1; /* error */
1201 if (packing
->RowLength
== 0) {
1202 bytesPerRow
= bytesPerPixel
* width
;
1205 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1209 remainder
= bytesPerRow
% packing
->Alignment
;
1211 bytesPerRow
+= (packing
->Alignment
- remainder
);
1213 if (packing
->ImageHeight
== 0)
1214 bytesPerImage
= bytesPerRow
* height
;
1216 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1218 return bytesPerImage
;
1224 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1225 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1226 * "On" bits will set texels to \p onValue.
1227 * "Off" bits will not modify texels.
1228 * \param width src bitmap width in pixels
1229 * \param height src bitmap height in pixels
1230 * \param unpack bitmap unpacking state
1231 * \param bitmap the src bitmap data
1232 * \param destBuffer start of dest buffer
1233 * \param destStride row stride in dest buffer
1234 * \param onValue if bit is 1, set destBuffer pixel to this value
1237 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1238 const struct gl_pixelstore_attrib
*unpack
,
1239 const GLubyte
*bitmap
,
1240 GLubyte
*destBuffer
, GLint destStride
,
1243 const GLubyte
*srcRow
= (const GLubyte
*)
1244 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1245 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1246 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1247 GL_COLOR_INDEX
, GL_BITMAP
);
1250 #define SET_PIXEL(COL, ROW) \
1251 destBuffer[(ROW) * destStride + (COL)] = onValue;
1253 for (row
= 0; row
< height
; row
++) {
1254 const GLubyte
*src
= srcRow
;
1256 if (unpack
->LsbFirst
) {
1258 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1259 for (col
= 0; col
< width
; col
++) {
1262 SET_PIXEL(col
, row
);
1274 /* get ready for next row */
1280 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1281 for (col
= 0; col
< width
; col
++) {
1284 SET_PIXEL(col
, row
);
1296 /* get ready for next row */
1301 srcRow
+= srcStride
;
1311 * Convert an array of RGBA colors from one datatype to another.
1312 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1315 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
1316 GLenum dstType
, GLvoid
*dst
,
1317 GLuint count
, const GLubyte mask
[])
1320 const GLboolean useTemp
= (src
== dst
);
1322 tempBuffer
= malloc(count
* MAX_PIXEL_BYTES
);
1326 ASSERT(srcType
!= dstType
);
1329 case GL_UNSIGNED_BYTE
:
1330 if (dstType
== GL_UNSIGNED_SHORT
) {
1331 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1332 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1334 for (i
= 0; i
< count
; i
++) {
1335 if (!mask
|| mask
[i
]) {
1336 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
1337 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
1338 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
1339 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
1343 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1346 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1347 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1349 ASSERT(dstType
== GL_FLOAT
);
1350 for (i
= 0; i
< count
; i
++) {
1351 if (!mask
|| mask
[i
]) {
1352 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
1353 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
1354 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
1355 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
1359 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1362 case GL_UNSIGNED_SHORT
:
1363 if (dstType
== GL_UNSIGNED_BYTE
) {
1364 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1365 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1367 for (i
= 0; i
< count
; i
++) {
1368 if (!mask
|| mask
[i
]) {
1369 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
1370 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
1371 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
1372 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
1376 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1379 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1380 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1382 ASSERT(dstType
== GL_FLOAT
);
1383 for (i
= 0; i
< count
; i
++) {
1384 if (!mask
|| mask
[i
]) {
1385 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
1386 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
1387 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
1388 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
1392 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1396 if (dstType
== GL_UNSIGNED_BYTE
) {
1397 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1398 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1400 for (i
= 0; i
< count
; i
++) {
1401 if (!mask
|| mask
[i
])
1402 _mesa_unclamped_float_rgba_to_ubyte(dst1
[i
], src4
[i
]);
1405 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1408 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1409 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1411 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
1412 for (i
= 0; i
< count
; i
++) {
1413 if (!mask
|| mask
[i
]) {
1414 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
1415 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
1416 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
1417 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
1421 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1425 _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 region to read is in bounds
1514 * GL_FALSE if region is completely out of bounds (nothing to read)
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
);