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.
38 #include "mfeatures.h"
44 * \return GL_TRUE if type is packed pixel type, GL_FALSE otherwise.
47 _mesa_type_is_packed(GLenum type
)
50 case GL_UNSIGNED_BYTE_3_3_2
:
51 case GL_UNSIGNED_BYTE_2_3_3_REV
:
52 case MESA_UNSIGNED_BYTE_4_4
:
53 case GL_UNSIGNED_SHORT_5_6_5
:
54 case GL_UNSIGNED_SHORT_5_6_5_REV
:
55 case GL_UNSIGNED_SHORT_4_4_4_4
:
56 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
57 case GL_UNSIGNED_SHORT_5_5_5_1
:
58 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
59 case GL_UNSIGNED_INT_8_8_8_8
:
60 case GL_UNSIGNED_INT_8_8_8_8_REV
:
61 case GL_UNSIGNED_INT_10_10_10_2
:
62 case GL_UNSIGNED_INT_2_10_10_10_REV
:
63 case GL_UNSIGNED_SHORT_8_8_MESA
:
64 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
65 case GL_UNSIGNED_INT_24_8_EXT
:
66 case GL_UNSIGNED_INT_5_9_9_9_REV
:
67 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
68 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
78 * Flip the order of the 2 bytes in each word in the given array.
81 * \param n number of words.
84 _mesa_swap2( GLushort
*p
, GLuint n
)
87 for (i
= 0; i
< n
; i
++) {
88 p
[i
] = (p
[i
] >> 8) | ((p
[i
] << 8) & 0xff00);
95 * Flip the order of the 4 bytes in each word in the given array.
98 _mesa_swap4( GLuint
*p
, GLuint n
)
101 for (i
= 0; i
< n
; i
++) {
104 | ((b
>> 8) & 0xff00)
105 | ((b
<< 8) & 0xff0000)
106 | ((b
<< 24) & 0xff000000);
113 * Get the size of a GL data type.
115 * \param type GL data type.
117 * \return the size, in bytes, of the given data type, 0 if a GL_BITMAP, or -1
118 * if an invalid type enum.
121 _mesa_sizeof_type( GLenum type
)
126 case GL_UNSIGNED_BYTE
:
127 return sizeof(GLubyte
);
129 return sizeof(GLbyte
);
130 case GL_UNSIGNED_SHORT
:
131 return sizeof(GLushort
);
133 return sizeof(GLshort
);
134 case GL_UNSIGNED_INT
:
135 return sizeof(GLuint
);
137 return sizeof(GLint
);
139 return sizeof(GLfloat
);
141 return sizeof(GLdouble
);
142 case GL_HALF_FLOAT_ARB
:
143 return sizeof(GLhalfARB
);
145 return sizeof(GLfixed
);
153 * Same as _mesa_sizeof_type() but also accepting the packed pixel
157 _mesa_sizeof_packed_type( GLenum type
)
162 case GL_UNSIGNED_BYTE
:
163 return sizeof(GLubyte
);
165 return sizeof(GLbyte
);
166 case GL_UNSIGNED_SHORT
:
167 return sizeof(GLushort
);
169 return sizeof(GLshort
);
170 case GL_UNSIGNED_INT
:
171 return sizeof(GLuint
);
173 return sizeof(GLint
);
174 case GL_HALF_FLOAT_ARB
:
175 return sizeof(GLhalfARB
);
177 return sizeof(GLfloat
);
178 case GL_UNSIGNED_BYTE_3_3_2
:
179 case GL_UNSIGNED_BYTE_2_3_3_REV
:
180 case MESA_UNSIGNED_BYTE_4_4
:
181 return sizeof(GLubyte
);
182 case GL_UNSIGNED_SHORT_5_6_5
:
183 case GL_UNSIGNED_SHORT_5_6_5_REV
:
184 case GL_UNSIGNED_SHORT_4_4_4_4
:
185 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
186 case GL_UNSIGNED_SHORT_5_5_5_1
:
187 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
188 case GL_UNSIGNED_SHORT_8_8_MESA
:
189 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
190 return sizeof(GLushort
);
191 case GL_UNSIGNED_INT_8_8_8_8
:
192 case GL_UNSIGNED_INT_8_8_8_8_REV
:
193 case GL_UNSIGNED_INT_10_10_10_2
:
194 case GL_UNSIGNED_INT_2_10_10_10_REV
:
195 case GL_UNSIGNED_INT_24_8_EXT
:
196 case GL_UNSIGNED_INT_5_9_9_9_REV
:
197 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
198 return sizeof(GLuint
);
199 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
208 * Get the number of components in a pixel format.
210 * \param format pixel format.
212 * \return the number of components in the given format, or -1 if a bad format.
215 _mesa_components_in_format( GLenum format
)
219 case GL_STENCIL_INDEX
:
220 case GL_DEPTH_COMPONENT
:
222 case GL_RED_INTEGER_EXT
:
224 case GL_GREEN_INTEGER_EXT
:
226 case GL_BLUE_INTEGER_EXT
:
228 case GL_ALPHA_INTEGER_EXT
:
230 case GL_LUMINANCE_INTEGER_EXT
:
234 case GL_LUMINANCE_ALPHA
:
235 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
238 case GL_DEPTH_STENCIL_EXT
:
246 case GL_RGB_INTEGER_EXT
:
247 case GL_BGR_INTEGER_EXT
:
253 case GL_RGBA_INTEGER_EXT
:
254 case GL_BGRA_INTEGER_EXT
:
264 * Get the bytes per pixel of pixel format type pair.
266 * \param format pixel format.
267 * \param type pixel type.
269 * \return bytes per pixel, or -1 if a bad format or type was given.
272 _mesa_bytes_per_pixel( GLenum format
, GLenum type
)
274 GLint comps
= _mesa_components_in_format( format
);
280 return 0; /* special case */
282 case GL_UNSIGNED_BYTE
:
283 return comps
* sizeof(GLubyte
);
285 case GL_UNSIGNED_SHORT
:
286 return comps
* sizeof(GLshort
);
288 case GL_UNSIGNED_INT
:
289 return comps
* sizeof(GLint
);
291 return comps
* sizeof(GLfloat
);
292 case GL_HALF_FLOAT_ARB
:
293 return comps
* sizeof(GLhalfARB
);
294 case GL_UNSIGNED_BYTE_3_3_2
:
295 case GL_UNSIGNED_BYTE_2_3_3_REV
:
296 if (format
== GL_RGB
|| format
== GL_BGR
||
297 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
298 return sizeof(GLubyte
);
300 return -1; /* error */
301 case GL_UNSIGNED_SHORT_5_6_5
:
302 case GL_UNSIGNED_SHORT_5_6_5_REV
:
303 if (format
== GL_RGB
|| format
== GL_BGR
||
304 format
== GL_RGB_INTEGER_EXT
|| format
== GL_BGR_INTEGER_EXT
)
305 return sizeof(GLushort
);
307 return -1; /* error */
308 case GL_UNSIGNED_SHORT_4_4_4_4
:
309 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
310 case GL_UNSIGNED_SHORT_5_5_5_1
:
311 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
312 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
313 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
314 return sizeof(GLushort
);
317 case GL_UNSIGNED_INT_8_8_8_8
:
318 case GL_UNSIGNED_INT_8_8_8_8_REV
:
319 case GL_UNSIGNED_INT_10_10_10_2
:
320 case GL_UNSIGNED_INT_2_10_10_10_REV
:
321 if (format
== GL_RGBA
|| format
== GL_BGRA
|| format
== GL_ABGR_EXT
||
322 format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
)
323 return sizeof(GLuint
);
326 case GL_UNSIGNED_SHORT_8_8_MESA
:
327 case GL_UNSIGNED_SHORT_8_8_REV_MESA
:
328 if (format
== GL_YCBCR_MESA
)
329 return sizeof(GLushort
);
332 case GL_UNSIGNED_INT_24_8_EXT
:
333 if (format
== GL_DEPTH_STENCIL_EXT
)
334 return sizeof(GLuint
);
337 case GL_UNSIGNED_INT_5_9_9_9_REV
:
338 if (format
== GL_RGB
)
339 return sizeof(GLuint
);
342 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
343 if (format
== GL_RGB
)
344 return sizeof(GLuint
);
347 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
348 if (format
== GL_DEPTH_STENCIL
)
359 * Do error checking of format/type combinations for glReadPixels,
360 * glDrawPixels and glTex[Sub]Image. Note that depending on the format
361 * and type values, we may either generate GL_INVALID_OPERATION or
364 * \param format pixel format.
365 * \param type pixel type.
367 * \return GL_INVALID_ENUM, GL_INVALID_OPERATION or GL_NO_ERROR
370 _mesa_error_check_format_and_type(const struct gl_context
*ctx
,
371 GLenum format
, GLenum type
)
373 /* special type-based checks (see glReadPixels, glDrawPixels error lists) */
376 if (format
!= GL_COLOR_INDEX
&& format
!= GL_STENCIL_INDEX
) {
377 return GL_INVALID_ENUM
;
381 case GL_UNSIGNED_BYTE_3_3_2
:
382 case GL_UNSIGNED_BYTE_2_3_3_REV
:
383 case GL_UNSIGNED_SHORT_5_6_5
:
384 case GL_UNSIGNED_SHORT_5_6_5_REV
:
385 if (format
== GL_RGB
) {
388 if (format
== GL_RGB_INTEGER_EXT
&&
389 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
392 return GL_INVALID_OPERATION
;
394 case GL_UNSIGNED_SHORT_4_4_4_4
:
395 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
396 case GL_UNSIGNED_SHORT_5_5_5_1
:
397 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
398 case GL_UNSIGNED_INT_8_8_8_8
:
399 case GL_UNSIGNED_INT_8_8_8_8_REV
:
400 case GL_UNSIGNED_INT_10_10_10_2
:
401 case GL_UNSIGNED_INT_2_10_10_10_REV
:
402 if (format
== GL_RGBA
||
404 format
== GL_ABGR_EXT
) {
407 if ((format
== GL_RGBA_INTEGER_EXT
|| format
== GL_BGRA_INTEGER_EXT
) &&
408 ctx
->Extensions
.ARB_texture_rgb10_a2ui
) {
411 return GL_INVALID_OPERATION
;
413 case GL_UNSIGNED_INT_24_8
:
414 if (!ctx
->Extensions
.EXT_packed_depth_stencil
) {
415 return GL_INVALID_ENUM
;
417 if (format
!= GL_DEPTH_STENCIL
) {
418 return GL_INVALID_OPERATION
;
422 case GL_FLOAT_32_UNSIGNED_INT_24_8_REV
:
423 if (!ctx
->Extensions
.ARB_depth_buffer_float
) {
424 return GL_INVALID_ENUM
;
426 if (format
!= GL_DEPTH_STENCIL
) {
427 return GL_INVALID_OPERATION
;
431 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
432 if (!ctx
->Extensions
.EXT_packed_float
) {
433 return GL_INVALID_ENUM
;
435 if (format
!= GL_RGB
) {
436 return GL_INVALID_OPERATION
;
444 /* now, for each format, check the type for compatibility */
447 case GL_STENCIL_INDEX
:
451 case GL_UNSIGNED_BYTE
:
453 case GL_UNSIGNED_SHORT
:
455 case GL_UNSIGNED_INT
:
459 return ctx
->Extensions
.ARB_half_float_pixel
460 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
462 return GL_INVALID_ENUM
;
469 #if 0 /* not legal! see table 3.6 of the 1.5 spec */
473 case GL_LUMINANCE_ALPHA
:
474 case GL_DEPTH_COMPONENT
:
477 case GL_UNSIGNED_BYTE
:
479 case GL_UNSIGNED_SHORT
:
481 case GL_UNSIGNED_INT
:
485 return ctx
->Extensions
.ARB_half_float_pixel
486 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
488 return GL_INVALID_ENUM
;
492 if (!ctx
->Extensions
.ARB_texture_rg
)
493 return GL_INVALID_ENUM
;
496 case GL_UNSIGNED_BYTE
:
498 case GL_UNSIGNED_SHORT
:
500 case GL_UNSIGNED_INT
:
504 return ctx
->Extensions
.ARB_half_float_pixel
505 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
507 return GL_INVALID_ENUM
;
513 case GL_UNSIGNED_BYTE
:
515 case GL_UNSIGNED_SHORT
:
517 case GL_UNSIGNED_INT
:
519 case GL_UNSIGNED_BYTE_3_3_2
:
520 case GL_UNSIGNED_BYTE_2_3_3_REV
:
521 case GL_UNSIGNED_SHORT_5_6_5
:
522 case GL_UNSIGNED_SHORT_5_6_5_REV
:
525 return ctx
->Extensions
.ARB_half_float_pixel
526 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
527 case GL_UNSIGNED_INT_5_9_9_9_REV
:
528 return ctx
->Extensions
.EXT_texture_shared_exponent
529 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
530 case GL_UNSIGNED_INT_10F_11F_11F_REV
:
531 return ctx
->Extensions
.EXT_packed_float
532 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
534 return GL_INVALID_ENUM
;
539 /* NOTE: no packed types are supported with BGR. That's
540 * intentional, according to the GL spec.
543 case GL_UNSIGNED_BYTE
:
545 case GL_UNSIGNED_SHORT
:
547 case GL_UNSIGNED_INT
:
551 return ctx
->Extensions
.ARB_half_float_pixel
552 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
554 return GL_INVALID_ENUM
;
562 case GL_UNSIGNED_BYTE
:
564 case GL_UNSIGNED_SHORT
:
566 case GL_UNSIGNED_INT
:
568 case GL_UNSIGNED_SHORT_4_4_4_4
:
569 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
570 case GL_UNSIGNED_SHORT_5_5_5_1
:
571 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
572 case GL_UNSIGNED_INT_8_8_8_8
:
573 case GL_UNSIGNED_INT_8_8_8_8_REV
:
574 case GL_UNSIGNED_INT_10_10_10_2
:
575 case GL_UNSIGNED_INT_2_10_10_10_REV
:
578 return ctx
->Extensions
.ARB_half_float_pixel
579 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
581 return GL_INVALID_ENUM
;
585 if (!ctx
->Extensions
.MESA_ycbcr_texture
)
586 return GL_INVALID_ENUM
;
587 if (type
== GL_UNSIGNED_SHORT_8_8_MESA
||
588 type
== GL_UNSIGNED_SHORT_8_8_REV_MESA
)
591 return GL_INVALID_OPERATION
;
593 case GL_DEPTH_STENCIL_EXT
:
594 if (ctx
->Extensions
.EXT_packed_depth_stencil
&&
595 type
== GL_UNSIGNED_INT_24_8
)
597 else if (ctx
->Extensions
.ARB_depth_buffer_float
&&
598 type
== GL_FLOAT_32_UNSIGNED_INT_24_8_REV
)
601 return GL_INVALID_ENUM
;
605 if (!ctx
->Extensions
.ATI_envmap_bumpmap
)
606 return GL_INVALID_ENUM
;
609 case GL_UNSIGNED_BYTE
:
611 case GL_UNSIGNED_SHORT
:
613 case GL_UNSIGNED_INT
:
617 return GL_INVALID_ENUM
;
620 /* integer-valued formats */
621 case GL_RED_INTEGER_EXT
:
622 case GL_GREEN_INTEGER_EXT
:
623 case GL_BLUE_INTEGER_EXT
:
624 case GL_ALPHA_INTEGER_EXT
:
628 case GL_UNSIGNED_BYTE
:
630 case GL_UNSIGNED_SHORT
:
632 case GL_UNSIGNED_INT
:
633 return (ctx
->VersionMajor
>= 3 ||
634 ctx
->Extensions
.EXT_texture_integer
)
635 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
637 return GL_INVALID_ENUM
;
640 case GL_RGB_INTEGER_EXT
:
643 case GL_UNSIGNED_BYTE
:
645 case GL_UNSIGNED_SHORT
:
647 case GL_UNSIGNED_INT
:
648 return (ctx
->VersionMajor
>= 3 ||
649 ctx
->Extensions
.EXT_texture_integer
)
650 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
651 case GL_UNSIGNED_BYTE_3_3_2
:
652 case GL_UNSIGNED_BYTE_2_3_3_REV
:
653 case GL_UNSIGNED_SHORT_5_6_5
:
654 case GL_UNSIGNED_SHORT_5_6_5_REV
:
655 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
656 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
658 return GL_INVALID_ENUM
;
661 case GL_BGR_INTEGER_EXT
:
664 case GL_UNSIGNED_BYTE
:
666 case GL_UNSIGNED_SHORT
:
668 case GL_UNSIGNED_INT
:
669 /* NOTE: no packed formats w/ BGR format */
670 return (ctx
->VersionMajor
>= 3 ||
671 ctx
->Extensions
.EXT_texture_integer
)
672 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
674 return GL_INVALID_ENUM
;
677 case GL_RGBA_INTEGER_EXT
:
678 case GL_BGRA_INTEGER_EXT
:
681 case GL_UNSIGNED_BYTE
:
683 case GL_UNSIGNED_SHORT
:
685 case GL_UNSIGNED_INT
:
686 return (ctx
->VersionMajor
>= 3 ||
687 ctx
->Extensions
.EXT_texture_integer
)
688 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
689 case GL_UNSIGNED_SHORT_4_4_4_4
:
690 case GL_UNSIGNED_SHORT_4_4_4_4_REV
:
691 case GL_UNSIGNED_SHORT_5_5_5_1
:
692 case GL_UNSIGNED_SHORT_1_5_5_5_REV
:
693 case GL_UNSIGNED_INT_8_8_8_8
:
694 case GL_UNSIGNED_INT_8_8_8_8_REV
:
695 case GL_UNSIGNED_INT_10_10_10_2
:
696 case GL_UNSIGNED_INT_2_10_10_10_REV
:
697 return ctx
->Extensions
.ARB_texture_rgb10_a2ui
698 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
700 return GL_INVALID_ENUM
;
703 case GL_LUMINANCE_INTEGER_EXT
:
704 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
707 case GL_UNSIGNED_BYTE
:
709 case GL_UNSIGNED_SHORT
:
711 case GL_UNSIGNED_INT
:
712 return ctx
->Extensions
.EXT_texture_integer
713 ? GL_NO_ERROR
: GL_INVALID_ENUM
;
715 return GL_INVALID_ENUM
;
719 return GL_INVALID_ENUM
;
726 * Test if the given image format is a color/RGBA format (i.e., not color
727 * index, depth, stencil, etc).
728 * \param format the image format value (may by an internal texture format)
729 * \return GL_TRUE if its a color/RGBA format, GL_FALSE otherwise.
732 _mesa_is_color_format(GLenum format
)
750 case GL_LUMINANCE_ALPHA
:
751 case GL_LUMINANCE4_ALPHA4
:
752 case GL_LUMINANCE6_ALPHA2
:
753 case GL_LUMINANCE8_ALPHA8
:
754 case GL_LUMINANCE12_ALPHA4
:
755 case GL_LUMINANCE12_ALPHA12
:
756 case GL_LUMINANCE16_ALPHA16
:
789 /* float texture formats */
790 case GL_ALPHA16F_ARB
:
791 case GL_ALPHA32F_ARB
:
792 case GL_LUMINANCE16F_ARB
:
793 case GL_LUMINANCE32F_ARB
:
794 case GL_LUMINANCE_ALPHA16F_ARB
:
795 case GL_LUMINANCE_ALPHA32F_ARB
:
796 case GL_INTENSITY16F_ARB
:
797 case GL_INTENSITY32F_ARB
:
806 /* compressed formats */
807 case GL_COMPRESSED_ALPHA
:
808 case GL_COMPRESSED_LUMINANCE
:
809 case GL_COMPRESSED_LUMINANCE_ALPHA
:
810 case GL_COMPRESSED_INTENSITY
:
811 case GL_COMPRESSED_RED
:
812 case GL_COMPRESSED_RG
:
813 case GL_COMPRESSED_RGB
:
814 case GL_COMPRESSED_RGBA
:
819 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
820 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
821 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
822 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
823 case GL_COMPRESSED_RGB_FXT1_3DFX
:
824 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
825 #if FEATURE_EXT_texture_sRGB
828 case GL_SRGB_ALPHA_EXT
:
829 case GL_SRGB8_ALPHA8_EXT
:
830 case GL_SLUMINANCE_ALPHA_EXT
:
831 case GL_SLUMINANCE8_ALPHA8_EXT
:
832 case GL_SLUMINANCE_EXT
:
833 case GL_SLUMINANCE8_EXT
:
834 case GL_COMPRESSED_SRGB_EXT
:
835 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
836 case GL_COMPRESSED_SRGB_ALPHA_EXT
:
837 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
838 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
839 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
840 case GL_COMPRESSED_SLUMINANCE_EXT
:
841 case GL_COMPRESSED_SLUMINANCE_ALPHA_EXT
:
842 #endif /* FEATURE_EXT_texture_sRGB */
843 case GL_COMPRESSED_RED_RGTC1
:
844 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
845 case GL_COMPRESSED_RG_RGTC2
:
846 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
847 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
848 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
849 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
850 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
851 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
852 case GL_ETC1_RGB8_OES
:
853 /* generic integer formats */
854 case GL_RED_INTEGER_EXT
:
855 case GL_GREEN_INTEGER_EXT
:
856 case GL_BLUE_INTEGER_EXT
:
857 case GL_ALPHA_INTEGER_EXT
:
858 case GL_RGB_INTEGER_EXT
:
859 case GL_RGBA_INTEGER_EXT
:
860 case GL_BGR_INTEGER_EXT
:
861 case GL_BGRA_INTEGER_EXT
:
863 case GL_LUMINANCE_INTEGER_EXT
:
864 case GL_LUMINANCE_ALPHA_INTEGER_EXT
:
865 /* sized integer formats */
866 case GL_RGBA32UI_EXT
:
870 case GL_ALPHA32UI_EXT
:
871 case GL_INTENSITY32UI_EXT
:
872 case GL_LUMINANCE32UI_EXT
:
873 case GL_LUMINANCE_ALPHA32UI_EXT
:
874 case GL_RGBA16UI_EXT
:
878 case GL_ALPHA16UI_EXT
:
879 case GL_INTENSITY16UI_EXT
:
880 case GL_LUMINANCE16UI_EXT
:
881 case GL_LUMINANCE_ALPHA16UI_EXT
:
886 case GL_ALPHA8UI_EXT
:
887 case GL_INTENSITY8UI_EXT
:
888 case GL_LUMINANCE8UI_EXT
:
889 case GL_LUMINANCE_ALPHA8UI_EXT
:
894 case GL_ALPHA32I_EXT
:
895 case GL_INTENSITY32I_EXT
:
896 case GL_LUMINANCE32I_EXT
:
897 case GL_LUMINANCE_ALPHA32I_EXT
:
902 case GL_ALPHA16I_EXT
:
903 case GL_INTENSITY16I_EXT
:
904 case GL_LUMINANCE16I_EXT
:
905 case GL_LUMINANCE_ALPHA16I_EXT
:
911 case GL_INTENSITY8I_EXT
:
912 case GL_LUMINANCE8I_EXT
:
913 case GL_LUMINANCE_ALPHA8I_EXT
:
914 /* signed, normalized texture formats */
926 case GL_RGBA16_SNORM
:
928 case GL_ALPHA8_SNORM
:
929 case GL_ALPHA16_SNORM
:
930 case GL_LUMINANCE_SNORM
:
931 case GL_LUMINANCE8_SNORM
:
932 case GL_LUMINANCE16_SNORM
:
933 case GL_LUMINANCE_ALPHA_SNORM
:
934 case GL_LUMINANCE8_ALPHA8_SNORM
:
935 case GL_LUMINANCE16_ALPHA16_SNORM
:
936 case GL_INTENSITY_SNORM
:
937 case GL_INTENSITY8_SNORM
:
938 case GL_INTENSITY16_SNORM
:
940 case GL_R11F_G11F_B10F
:
943 case GL_YCBCR_MESA
: /* not considered to be RGB */
952 * Test if the given image format is a depth component format.
955 _mesa_is_depth_format(GLenum format
)
958 case GL_DEPTH_COMPONENT
:
959 case GL_DEPTH_COMPONENT16
:
960 case GL_DEPTH_COMPONENT24
:
961 case GL_DEPTH_COMPONENT32
:
962 case GL_DEPTH_COMPONENT32F
:
971 * Test if the given image format is a stencil format.
974 _mesa_is_stencil_format(GLenum format
)
977 case GL_STENCIL_INDEX
:
986 * Test if the given image format is a YCbCr format.
989 _mesa_is_ycbcr_format(GLenum format
)
1001 * Test if the given image format is a depth+stencil format.
1004 _mesa_is_depthstencil_format(GLenum format
)
1007 case GL_DEPTH24_STENCIL8_EXT
:
1008 case GL_DEPTH_STENCIL_EXT
:
1009 case GL_DEPTH32F_STENCIL8
:
1018 * Test if the given image format is a depth or stencil format.
1021 _mesa_is_depth_or_stencil_format(GLenum format
)
1024 case GL_DEPTH_COMPONENT
:
1025 case GL_DEPTH_COMPONENT16
:
1026 case GL_DEPTH_COMPONENT24
:
1027 case GL_DEPTH_COMPONENT32
:
1028 case GL_STENCIL_INDEX
:
1029 case GL_STENCIL_INDEX1_EXT
:
1030 case GL_STENCIL_INDEX4_EXT
:
1031 case GL_STENCIL_INDEX8_EXT
:
1032 case GL_STENCIL_INDEX16_EXT
:
1033 case GL_DEPTH_STENCIL_EXT
:
1034 case GL_DEPTH24_STENCIL8_EXT
:
1035 case GL_DEPTH_COMPONENT32F
:
1036 case GL_DEPTH32F_STENCIL8
:
1045 * Test if the given image format is a dudv format.
1048 _mesa_is_dudv_format(GLenum format
)
1061 * Test if an image format is a supported compressed format.
1062 * \param format the internal format token provided by the user.
1063 * \return GL_TRUE if compressed, GL_FALSE if uncompressed
1066 _mesa_is_compressed_format(struct gl_context
*ctx
, GLenum format
)
1069 case GL_COMPRESSED_RGB_S3TC_DXT1_EXT
:
1070 case GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
:
1071 case GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
:
1072 case GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:
1073 return ctx
->Extensions
.EXT_texture_compression_s3tc
;
1078 return ctx
->Extensions
.S3_s3tc
;
1079 case GL_COMPRESSED_SRGB_S3TC_DXT1_EXT
:
1080 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT
:
1081 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT
:
1082 case GL_COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT
:
1083 return ctx
->Extensions
.EXT_texture_sRGB
1084 && ctx
->Extensions
.EXT_texture_compression_s3tc
;
1085 case GL_COMPRESSED_RGB_FXT1_3DFX
:
1086 case GL_COMPRESSED_RGBA_FXT1_3DFX
:
1087 return ctx
->Extensions
.TDFX_texture_compression_FXT1
;
1088 case GL_COMPRESSED_RED_RGTC1
:
1089 case GL_COMPRESSED_SIGNED_RED_RGTC1
:
1090 case GL_COMPRESSED_RG_RGTC2
:
1091 case GL_COMPRESSED_SIGNED_RG_RGTC2
:
1092 return ctx
->Extensions
.ARB_texture_compression_rgtc
;
1093 case GL_COMPRESSED_LUMINANCE_LATC1_EXT
:
1094 case GL_COMPRESSED_SIGNED_LUMINANCE_LATC1_EXT
:
1095 case GL_COMPRESSED_LUMINANCE_ALPHA_LATC2_EXT
:
1096 case GL_COMPRESSED_SIGNED_LUMINANCE_ALPHA_LATC2_EXT
:
1097 return ctx
->Extensions
.EXT_texture_compression_latc
;
1098 case GL_COMPRESSED_LUMINANCE_ALPHA_3DC_ATI
:
1099 return ctx
->Extensions
.ATI_texture_compression_3dc
;
1100 case GL_ETC1_RGB8_OES
:
1101 return ctx
->Extensions
.OES_compressed_ETC1_RGB8_texture
;
1103 case GL_PALETTE4_RGB8_OES
:
1104 case GL_PALETTE4_RGBA8_OES
:
1105 case GL_PALETTE4_R5_G6_B5_OES
:
1106 case GL_PALETTE4_RGBA4_OES
:
1107 case GL_PALETTE4_RGB5_A1_OES
:
1108 case GL_PALETTE8_RGB8_OES
:
1109 case GL_PALETTE8_RGBA8_OES
:
1110 case GL_PALETTE8_R5_G6_B5_OES
:
1111 case GL_PALETTE8_RGBA4_OES
:
1112 case GL_PALETTE8_RGB5_A1_OES
:
1113 return ctx
->API
== API_OPENGLES
;
1122 * Does the given base texture/renderbuffer format have the channel
1126 _mesa_base_format_has_channel(GLenum base_format
, GLenum pname
)
1129 case GL_TEXTURE_RED_SIZE
:
1130 case GL_TEXTURE_RED_TYPE
:
1131 case GL_RENDERBUFFER_RED_SIZE_EXT
:
1132 case GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE
:
1133 if (base_format
== GL_RED
||
1134 base_format
== GL_RG
||
1135 base_format
== GL_RGB
||
1136 base_format
== GL_RGBA
) {
1140 case GL_TEXTURE_GREEN_SIZE
:
1141 case GL_TEXTURE_GREEN_TYPE
:
1142 case GL_RENDERBUFFER_GREEN_SIZE_EXT
:
1143 case GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE
:
1144 if (base_format
== GL_RG
||
1145 base_format
== GL_RGB
||
1146 base_format
== GL_RGBA
) {
1150 case GL_TEXTURE_BLUE_SIZE
:
1151 case GL_TEXTURE_BLUE_TYPE
:
1152 case GL_RENDERBUFFER_BLUE_SIZE_EXT
:
1153 case GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE
:
1154 if (base_format
== GL_RGB
||
1155 base_format
== GL_RGBA
) {
1159 case GL_TEXTURE_ALPHA_SIZE
:
1160 case GL_TEXTURE_ALPHA_TYPE
:
1161 case GL_RENDERBUFFER_ALPHA_SIZE_EXT
:
1162 case GL_FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE
:
1163 if (base_format
== GL_RGBA
||
1164 base_format
== GL_ALPHA
||
1165 base_format
== GL_LUMINANCE_ALPHA
) {
1169 case GL_TEXTURE_LUMINANCE_SIZE
:
1170 case GL_TEXTURE_LUMINANCE_TYPE
:
1171 if (base_format
== GL_LUMINANCE
||
1172 base_format
== GL_LUMINANCE_ALPHA
) {
1176 case GL_TEXTURE_INTENSITY_SIZE
:
1177 case GL_TEXTURE_INTENSITY_TYPE
:
1178 if (base_format
== GL_INTENSITY
) {
1182 case GL_TEXTURE_DEPTH_SIZE
:
1183 case GL_TEXTURE_DEPTH_TYPE
:
1184 case GL_RENDERBUFFER_DEPTH_SIZE_EXT
:
1185 case GL_FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE
:
1186 if (base_format
== GL_DEPTH_STENCIL
||
1187 base_format
== GL_DEPTH_COMPONENT
) {
1191 case GL_RENDERBUFFER_STENCIL_SIZE_EXT
:
1192 case GL_FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE
:
1193 if (base_format
== GL_DEPTH_STENCIL
||
1194 base_format
== GL_STENCIL_INDEX
) {
1199 _mesa_warning(NULL
, "%s: Unexpected channel token 0x%x\n",
1200 __FUNCTION__
, pname
);
1209 * Return the byte offset of a specific pixel in an image (1D, 2D or 3D).
1211 * Pixel unpacking/packing parameters are observed according to \p packing.
1213 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
1214 * \param packing the pixelstore attributes
1215 * \param width the image width
1216 * \param height the image height
1217 * \param format the pixel format (must be validated beforehand)
1218 * \param type the pixel data type (must be validated beforehand)
1219 * \param img which image in the volume (0 for 1D or 2D images)
1220 * \param row row of pixel in the image (0 for 1D images)
1221 * \param column column of pixel in the image
1223 * \return offset of pixel.
1225 * \sa gl_pixelstore_attrib.
1228 _mesa_image_offset( GLuint dimensions
,
1229 const struct gl_pixelstore_attrib
*packing
,
1230 GLsizei width
, GLsizei height
,
1231 GLenum format
, GLenum type
,
1232 GLint img
, GLint row
, GLint column
)
1234 GLint alignment
; /* 1, 2 or 4 */
1235 GLint pixels_per_row
;
1236 GLint rows_per_image
;
1239 GLint skipimages
; /* for 3-D volume images */
1242 ASSERT(dimensions
>= 1 && dimensions
<= 3);
1244 alignment
= packing
->Alignment
;
1245 if (packing
->RowLength
> 0) {
1246 pixels_per_row
= packing
->RowLength
;
1249 pixels_per_row
= width
;
1251 if (packing
->ImageHeight
> 0) {
1252 rows_per_image
= packing
->ImageHeight
;
1255 rows_per_image
= height
;
1258 skippixels
= packing
->SkipPixels
;
1259 /* Note: SKIP_ROWS _is_ used for 1D images */
1260 skiprows
= packing
->SkipRows
;
1261 /* Note: SKIP_IMAGES is only used for 3D images */
1262 skipimages
= (dimensions
== 3) ? packing
->SkipImages
: 0;
1264 if (type
== GL_BITMAP
) {
1266 GLint bytes_per_row
;
1267 GLint bytes_per_image
;
1268 /* components per pixel for color or stencil index: */
1269 const GLint comp_per_pixel
= 1;
1271 /* The pixel type and format should have been error checked earlier */
1272 assert(format
== GL_COLOR_INDEX
|| format
== GL_STENCIL_INDEX
);
1274 bytes_per_row
= alignment
1275 * CEILING( comp_per_pixel
*pixels_per_row
, 8*alignment
);
1277 bytes_per_image
= bytes_per_row
* rows_per_image
;
1279 offset
= (skipimages
+ img
) * bytes_per_image
1280 + (skiprows
+ row
) * bytes_per_row
1281 + (skippixels
+ column
) / 8;
1284 /* Non-BITMAP data */
1285 GLint bytes_per_pixel
, bytes_per_row
, remainder
, bytes_per_image
;
1288 bytes_per_pixel
= _mesa_bytes_per_pixel( format
, type
);
1290 /* The pixel type and format should have been error checked earlier */
1291 assert(bytes_per_pixel
> 0);
1293 bytes_per_row
= pixels_per_row
* bytes_per_pixel
;
1294 remainder
= bytes_per_row
% alignment
;
1296 bytes_per_row
+= (alignment
- remainder
);
1298 ASSERT(bytes_per_row
% alignment
== 0);
1300 bytes_per_image
= bytes_per_row
* rows_per_image
;
1302 if (packing
->Invert
) {
1303 /* set pixel_addr to the last row */
1304 topOfImage
= bytes_per_row
* (height
- 1);
1305 bytes_per_row
= -bytes_per_row
;
1311 /* compute final pixel address */
1312 offset
= (skipimages
+ img
) * bytes_per_image
1314 + (skiprows
+ row
) * bytes_per_row
1315 + (skippixels
+ column
) * bytes_per_pixel
;
1323 * Return the address of a specific pixel in an image (1D, 2D or 3D).
1325 * Pixel unpacking/packing parameters are observed according to \p packing.
1327 * \param dimensions either 1, 2 or 3 to indicate dimensionality of image
1328 * \param packing the pixelstore attributes
1329 * \param image starting address of image data
1330 * \param width the image width
1331 * \param height the image height
1332 * \param format the pixel format (must be validated beforehand)
1333 * \param type the pixel data type (must be validated beforehand)
1334 * \param img which image in the volume (0 for 1D or 2D images)
1335 * \param row row of pixel in the image (0 for 1D images)
1336 * \param column column of pixel in the image
1338 * \return address of pixel.
1340 * \sa gl_pixelstore_attrib.
1343 _mesa_image_address( GLuint dimensions
,
1344 const struct gl_pixelstore_attrib
*packing
,
1345 const GLvoid
*image
,
1346 GLsizei width
, GLsizei height
,
1347 GLenum format
, GLenum type
,
1348 GLint img
, GLint row
, GLint column
)
1350 const GLubyte
*addr
= (const GLubyte
*) image
;
1352 addr
+= _mesa_image_offset(dimensions
, packing
, width
, height
,
1353 format
, type
, img
, row
, column
);
1355 return (GLvoid
*) addr
;
1360 _mesa_image_address1d( const struct gl_pixelstore_attrib
*packing
,
1361 const GLvoid
*image
,
1363 GLenum format
, GLenum type
,
1366 return _mesa_image_address(1, packing
, image
, width
, 1,
1367 format
, type
, 0, 0, column
);
1372 _mesa_image_address2d( const struct gl_pixelstore_attrib
*packing
,
1373 const GLvoid
*image
,
1374 GLsizei width
, GLsizei height
,
1375 GLenum format
, GLenum type
,
1376 GLint row
, GLint column
)
1378 return _mesa_image_address(2, packing
, image
, width
, height
,
1379 format
, type
, 0, row
, column
);
1384 _mesa_image_address3d( const struct gl_pixelstore_attrib
*packing
,
1385 const GLvoid
*image
,
1386 GLsizei width
, GLsizei height
,
1387 GLenum format
, GLenum type
,
1388 GLint img
, GLint row
, GLint column
)
1390 return _mesa_image_address(3, packing
, image
, width
, height
,
1391 format
, type
, img
, row
, column
);
1397 * Compute the stride (in bytes) between image rows.
1399 * \param packing the pixelstore attributes
1400 * \param width image width.
1401 * \param format pixel format.
1402 * \param type pixel data type.
1404 * \return the stride in bytes for the given parameters, or -1 if error
1407 _mesa_image_row_stride( const struct gl_pixelstore_attrib
*packing
,
1408 GLint width
, GLenum format
, GLenum type
)
1410 GLint bytesPerRow
, remainder
;
1414 if (type
== GL_BITMAP
) {
1415 if (packing
->RowLength
== 0) {
1416 bytesPerRow
= (width
+ 7) / 8;
1419 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1423 /* Non-BITMAP data */
1424 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1425 if (bytesPerPixel
<= 0)
1426 return -1; /* error */
1427 if (packing
->RowLength
== 0) {
1428 bytesPerRow
= bytesPerPixel
* width
;
1431 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1435 remainder
= bytesPerRow
% packing
->Alignment
;
1436 if (remainder
> 0) {
1437 bytesPerRow
+= (packing
->Alignment
- remainder
);
1440 if (packing
->Invert
) {
1441 /* negate the bytes per row (negative row stride) */
1442 bytesPerRow
= -bytesPerRow
;
1450 * Compute the stride between images in a 3D texture (in bytes) for the given
1451 * pixel packing parameters and image width, format and type.
1454 _mesa_image_image_stride( const struct gl_pixelstore_attrib
*packing
,
1455 GLint width
, GLint height
,
1456 GLenum format
, GLenum type
)
1458 GLint bytesPerRow
, bytesPerImage
, remainder
;
1462 if (type
== GL_BITMAP
) {
1463 if (packing
->RowLength
== 0) {
1464 bytesPerRow
= (width
+ 7) / 8;
1467 bytesPerRow
= (packing
->RowLength
+ 7) / 8;
1471 const GLint bytesPerPixel
= _mesa_bytes_per_pixel(format
, type
);
1473 if (bytesPerPixel
<= 0)
1474 return -1; /* error */
1475 if (packing
->RowLength
== 0) {
1476 bytesPerRow
= bytesPerPixel
* width
;
1479 bytesPerRow
= bytesPerPixel
* packing
->RowLength
;
1483 remainder
= bytesPerRow
% packing
->Alignment
;
1485 bytesPerRow
+= (packing
->Alignment
- remainder
);
1487 if (packing
->ImageHeight
== 0)
1488 bytesPerImage
= bytesPerRow
* height
;
1490 bytesPerImage
= bytesPerRow
* packing
->ImageHeight
;
1492 return bytesPerImage
;
1498 * "Expand" a bitmap from 1-bit per pixel to 8-bits per pixel.
1499 * This is typically used to convert a bitmap into a GLubyte/pixel texture.
1500 * "On" bits will set texels to \p onValue.
1501 * "Off" bits will not modify texels.
1502 * \param width src bitmap width in pixels
1503 * \param height src bitmap height in pixels
1504 * \param unpack bitmap unpacking state
1505 * \param bitmap the src bitmap data
1506 * \param destBuffer start of dest buffer
1507 * \param destStride row stride in dest buffer
1508 * \param onValue if bit is 1, set destBuffer pixel to this value
1511 _mesa_expand_bitmap(GLsizei width
, GLsizei height
,
1512 const struct gl_pixelstore_attrib
*unpack
,
1513 const GLubyte
*bitmap
,
1514 GLubyte
*destBuffer
, GLint destStride
,
1517 const GLubyte
*srcRow
= (const GLubyte
*)
1518 _mesa_image_address2d(unpack
, bitmap
, width
, height
,
1519 GL_COLOR_INDEX
, GL_BITMAP
, 0, 0);
1520 const GLint srcStride
= _mesa_image_row_stride(unpack
, width
,
1521 GL_COLOR_INDEX
, GL_BITMAP
);
1524 #define SET_PIXEL(COL, ROW) \
1525 destBuffer[(ROW) * destStride + (COL)] = onValue;
1527 for (row
= 0; row
< height
; row
++) {
1528 const GLubyte
*src
= srcRow
;
1530 if (unpack
->LsbFirst
) {
1532 GLubyte mask
= 1U << (unpack
->SkipPixels
& 0x7);
1533 for (col
= 0; col
< width
; col
++) {
1536 SET_PIXEL(col
, row
);
1548 /* get ready for next row */
1554 GLubyte mask
= 128U >> (unpack
->SkipPixels
& 0x7);
1555 for (col
= 0; col
< width
; col
++) {
1558 SET_PIXEL(col
, row
);
1570 /* get ready for next row */
1575 srcRow
+= srcStride
;
1585 * Convert an array of RGBA colors from one datatype to another.
1586 * NOTE: src may equal dst. In that case, we use a temporary buffer.
1589 _mesa_convert_colors(GLenum srcType
, const GLvoid
*src
,
1590 GLenum dstType
, GLvoid
*dst
,
1591 GLuint count
, const GLubyte mask
[])
1594 const GLboolean useTemp
= (src
== dst
);
1596 tempBuffer
= malloc(count
* MAX_PIXEL_BYTES
);
1600 ASSERT(srcType
!= dstType
);
1603 case GL_UNSIGNED_BYTE
:
1604 if (dstType
== GL_UNSIGNED_SHORT
) {
1605 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1606 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1608 for (i
= 0; i
< count
; i
++) {
1609 if (!mask
|| mask
[i
]) {
1610 dst2
[i
][RCOMP
] = UBYTE_TO_USHORT(src1
[i
][RCOMP
]);
1611 dst2
[i
][GCOMP
] = UBYTE_TO_USHORT(src1
[i
][GCOMP
]);
1612 dst2
[i
][BCOMP
] = UBYTE_TO_USHORT(src1
[i
][BCOMP
]);
1613 dst2
[i
][ACOMP
] = UBYTE_TO_USHORT(src1
[i
][ACOMP
]);
1617 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1620 const GLubyte (*src1
)[4] = (const GLubyte (*)[4]) src
;
1621 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1623 ASSERT(dstType
== GL_FLOAT
);
1624 for (i
= 0; i
< count
; i
++) {
1625 if (!mask
|| mask
[i
]) {
1626 dst4
[i
][RCOMP
] = UBYTE_TO_FLOAT(src1
[i
][RCOMP
]);
1627 dst4
[i
][GCOMP
] = UBYTE_TO_FLOAT(src1
[i
][GCOMP
]);
1628 dst4
[i
][BCOMP
] = UBYTE_TO_FLOAT(src1
[i
][BCOMP
]);
1629 dst4
[i
][ACOMP
] = UBYTE_TO_FLOAT(src1
[i
][ACOMP
]);
1633 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1636 case GL_UNSIGNED_SHORT
:
1637 if (dstType
== GL_UNSIGNED_BYTE
) {
1638 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1639 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1641 for (i
= 0; i
< count
; i
++) {
1642 if (!mask
|| mask
[i
]) {
1643 dst1
[i
][RCOMP
] = USHORT_TO_UBYTE(src2
[i
][RCOMP
]);
1644 dst1
[i
][GCOMP
] = USHORT_TO_UBYTE(src2
[i
][GCOMP
]);
1645 dst1
[i
][BCOMP
] = USHORT_TO_UBYTE(src2
[i
][BCOMP
]);
1646 dst1
[i
][ACOMP
] = USHORT_TO_UBYTE(src2
[i
][ACOMP
]);
1650 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1653 const GLushort (*src2
)[4] = (const GLushort (*)[4]) src
;
1654 GLfloat (*dst4
)[4] = (GLfloat (*)[4]) (useTemp
? tempBuffer
: dst
);
1656 ASSERT(dstType
== GL_FLOAT
);
1657 for (i
= 0; i
< count
; i
++) {
1658 if (!mask
|| mask
[i
]) {
1659 dst4
[i
][RCOMP
] = USHORT_TO_FLOAT(src2
[i
][RCOMP
]);
1660 dst4
[i
][GCOMP
] = USHORT_TO_FLOAT(src2
[i
][GCOMP
]);
1661 dst4
[i
][BCOMP
] = USHORT_TO_FLOAT(src2
[i
][BCOMP
]);
1662 dst4
[i
][ACOMP
] = USHORT_TO_FLOAT(src2
[i
][ACOMP
]);
1666 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLfloat
));
1670 if (dstType
== GL_UNSIGNED_BYTE
) {
1671 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1672 GLubyte (*dst1
)[4] = (GLubyte (*)[4]) (useTemp
? tempBuffer
: dst
);
1674 for (i
= 0; i
< count
; i
++) {
1675 if (!mask
|| mask
[i
])
1676 _mesa_unclamped_float_rgba_to_ubyte(dst1
[i
], src4
[i
]);
1679 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLubyte
));
1682 const GLfloat (*src4
)[4] = (const GLfloat (*)[4]) src
;
1683 GLushort (*dst2
)[4] = (GLushort (*)[4]) (useTemp
? tempBuffer
: dst
);
1685 ASSERT(dstType
== GL_UNSIGNED_SHORT
);
1686 for (i
= 0; i
< count
; i
++) {
1687 if (!mask
|| mask
[i
]) {
1688 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][RCOMP
], src4
[i
][RCOMP
]);
1689 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][GCOMP
], src4
[i
][GCOMP
]);
1690 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][BCOMP
], src4
[i
][BCOMP
]);
1691 UNCLAMPED_FLOAT_TO_USHORT(dst2
[i
][ACOMP
], src4
[i
][ACOMP
]);
1695 memcpy(dst
, tempBuffer
, count
* 4 * sizeof(GLushort
));
1699 _mesa_problem(NULL
, "Invalid datatype in _mesa_convert_colors");
1709 * Perform basic clipping for glDrawPixels. The image's position and size
1710 * and the unpack SkipPixels and SkipRows are adjusted so that the image
1711 * region is entirely within the window and scissor bounds.
1712 * NOTE: this will only work when glPixelZoom is (1, 1) or (1, -1).
1713 * If Pixel.ZoomY is -1, *destY will be changed to be the first row which
1714 * we'll actually write. Beforehand, *destY-1 is the first drawing row.
1716 * \return GL_TRUE if image is ready for drawing or
1717 * GL_FALSE if image was completely clipped away (draw nothing)
1720 _mesa_clip_drawpixels(const struct gl_context
*ctx
,
1721 GLint
*destX
, GLint
*destY
,
1722 GLsizei
*width
, GLsizei
*height
,
1723 struct gl_pixelstore_attrib
*unpack
)
1725 const struct gl_framebuffer
*buffer
= ctx
->DrawBuffer
;
1727 if (unpack
->RowLength
== 0) {
1728 unpack
->RowLength
= *width
;
1731 ASSERT(ctx
->Pixel
.ZoomX
== 1.0F
);
1732 ASSERT(ctx
->Pixel
.ZoomY
== 1.0F
|| ctx
->Pixel
.ZoomY
== -1.0F
);
1735 if (*destX
< buffer
->_Xmin
) {
1736 unpack
->SkipPixels
+= (buffer
->_Xmin
- *destX
);
1737 *width
-= (buffer
->_Xmin
- *destX
);
1738 *destX
= buffer
->_Xmin
;
1740 /* right clipping */
1741 if (*destX
+ *width
> buffer
->_Xmax
)
1742 *width
-= (*destX
+ *width
- buffer
->_Xmax
);
1747 if (ctx
->Pixel
.ZoomY
== 1.0F
) {
1748 /* bottom clipping */
1749 if (*destY
< buffer
->_Ymin
) {
1750 unpack
->SkipRows
+= (buffer
->_Ymin
- *destY
);
1751 *height
-= (buffer
->_Ymin
- *destY
);
1752 *destY
= buffer
->_Ymin
;
1755 if (*destY
+ *height
> buffer
->_Ymax
)
1756 *height
-= (*destY
+ *height
- buffer
->_Ymax
);
1758 else { /* upside down */
1760 if (*destY
> buffer
->_Ymax
) {
1761 unpack
->SkipRows
+= (*destY
- buffer
->_Ymax
);
1762 *height
-= (*destY
- buffer
->_Ymax
);
1763 *destY
= buffer
->_Ymax
;
1765 /* bottom clipping */
1766 if (*destY
- *height
< buffer
->_Ymin
)
1767 *height
-= (buffer
->_Ymin
- (*destY
- *height
));
1768 /* adjust destY so it's the first row to write to */
1780 * Perform clipping for glReadPixels. The image's window position
1781 * and size, and the pack skipPixels, skipRows and rowLength are adjusted
1782 * so that the image region is entirely within the window bounds.
1783 * Note: this is different from _mesa_clip_drawpixels() in that the
1784 * scissor box is ignored, and we use the bounds of the current readbuffer
1787 * \return GL_TRUE if region to read is in bounds
1788 * GL_FALSE if region is completely out of bounds (nothing to read)
1791 _mesa_clip_readpixels(const struct gl_context
*ctx
,
1792 GLint
*srcX
, GLint
*srcY
,
1793 GLsizei
*width
, GLsizei
*height
,
1794 struct gl_pixelstore_attrib
*pack
)
1796 const struct gl_framebuffer
*buffer
= ctx
->ReadBuffer
;
1798 if (pack
->RowLength
== 0) {
1799 pack
->RowLength
= *width
;
1804 pack
->SkipPixels
+= (0 - *srcX
);
1805 *width
-= (0 - *srcX
);
1808 /* right clipping */
1809 if (*srcX
+ *width
> (GLsizei
) buffer
->Width
)
1810 *width
-= (*srcX
+ *width
- buffer
->Width
);
1815 /* bottom clipping */
1817 pack
->SkipRows
+= (0 - *srcY
);
1818 *height
-= (0 - *srcY
);
1822 if (*srcY
+ *height
> (GLsizei
) buffer
->Height
)
1823 *height
-= (*srcY
+ *height
- buffer
->Height
);
1833 * Do clipping for a glCopyTexSubImage call.
1834 * The framebuffer source region might extend outside the framebuffer
1835 * bounds. Clip the source region against the framebuffer bounds and
1836 * adjust the texture/dest position and size accordingly.
1838 * \return GL_FALSE if region is totally clipped, GL_TRUE otherwise.
1841 _mesa_clip_copytexsubimage(const struct gl_context
*ctx
,
1842 GLint
*destX
, GLint
*destY
,
1843 GLint
*srcX
, GLint
*srcY
,
1844 GLsizei
*width
, GLsizei
*height
)
1846 const struct gl_framebuffer
*fb
= ctx
->ReadBuffer
;
1847 const GLint srcX0
= *srcX
, srcY0
= *srcY
;
1849 if (_mesa_clip_to_region(0, 0, fb
->Width
, fb
->Height
,
1850 srcX
, srcY
, width
, height
)) {
1851 *destX
= *destX
+ *srcX
- srcX0
;
1852 *destY
= *destY
+ *srcY
- srcY0
;
1864 * Clip the rectangle defined by (x, y, width, height) against the bounds
1865 * specified by [xmin, xmax) and [ymin, ymax).
1866 * \return GL_FALSE if rect is totally clipped, GL_TRUE otherwise.
1869 _mesa_clip_to_region(GLint xmin
, GLint ymin
,
1870 GLint xmax
, GLint ymax
,
1872 GLsizei
*width
, GLsizei
*height
)
1876 *width
-= (xmin
- *x
);
1880 /* right clipping */
1881 if (*x
+ *width
> xmax
)
1882 *width
-= (*x
+ *width
- xmax
);
1887 /* bottom (or top) clipping */
1889 *height
-= (ymin
- *y
);
1893 /* top (or bottom) clipping */
1894 if (*y
+ *height
> ymax
)
1895 *height
-= (*y
+ *height
- ymax
);
1905 * Clip dst coords against Xmax (or Ymax).
1908 clip_right_or_top(GLint
*srcX0
, GLint
*srcX1
,
1909 GLint
*dstX0
, GLint
*dstX1
,
1914 if (*dstX1
> maxValue
) {
1915 /* X1 outside right edge */
1916 ASSERT(*dstX0
< maxValue
); /* X0 should be inside right edge */
1917 t
= (GLfloat
) (maxValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1918 /* chop off [t, 1] part */
1919 ASSERT(t
>= 0.0 && t
<= 1.0);
1921 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1922 *srcX1
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1924 else if (*dstX0
> maxValue
) {
1925 /* X0 outside right edge */
1926 ASSERT(*dstX1
< maxValue
); /* X1 should be inside right edge */
1927 t
= (GLfloat
) (maxValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1928 /* chop off [t, 1] part */
1929 ASSERT(t
>= 0.0 && t
<= 1.0);
1931 bias
= (*srcX0
< *srcX1
) ? -0.5F
: 0.5F
;
1932 *srcX0
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1938 * Clip dst coords against Xmin (or Ymin).
1941 clip_left_or_bottom(GLint
*srcX0
, GLint
*srcX1
,
1942 GLint
*dstX0
, GLint
*dstX1
,
1947 if (*dstX0
< minValue
) {
1948 /* X0 outside left edge */
1949 ASSERT(*dstX1
> minValue
); /* X1 should be inside left edge */
1950 t
= (GLfloat
) (minValue
- *dstX0
) / (GLfloat
) (*dstX1
- *dstX0
);
1951 /* chop off [0, t] part */
1952 ASSERT(t
>= 0.0 && t
<= 1.0);
1954 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
; /* flipped??? */
1955 *srcX0
= *srcX0
+ (GLint
) (t
* (*srcX1
- *srcX0
) + bias
);
1957 else if (*dstX1
< minValue
) {
1958 /* X1 outside left edge */
1959 ASSERT(*dstX0
> minValue
); /* X0 should be inside left edge */
1960 t
= (GLfloat
) (minValue
- *dstX1
) / (GLfloat
) (*dstX0
- *dstX1
);
1961 /* chop off [0, t] part */
1962 ASSERT(t
>= 0.0 && t
<= 1.0);
1964 bias
= (*srcX0
< *srcX1
) ? 0.5F
: -0.5F
;
1965 *srcX1
= *srcX1
+ (GLint
) (t
* (*srcX0
- *srcX1
) + bias
);
1971 * Do clipping of blit src/dest rectangles.
1972 * The dest rect is clipped against both the buffer bounds and scissor bounds.
1973 * The src rect is just clipped against the buffer bounds.
1975 * When either the src or dest rect is clipped, the other is also clipped
1978 * Note that X0 need not be less than X1 (same for Y) for either the source
1979 * and dest rects. That makes the clipping a little trickier.
1981 * \return GL_TRUE if anything is left to draw, GL_FALSE if totally clipped
1984 _mesa_clip_blit(struct gl_context
*ctx
,
1985 GLint
*srcX0
, GLint
*srcY0
, GLint
*srcX1
, GLint
*srcY1
,
1986 GLint
*dstX0
, GLint
*dstY0
, GLint
*dstX1
, GLint
*dstY1
)
1988 const GLint srcXmin
= 0;
1989 const GLint srcXmax
= ctx
->ReadBuffer
->Width
;
1990 const GLint srcYmin
= 0;
1991 const GLint srcYmax
= ctx
->ReadBuffer
->Height
;
1993 /* these include scissor bounds */
1994 const GLint dstXmin
= ctx
->DrawBuffer
->_Xmin
;
1995 const GLint dstXmax
= ctx
->DrawBuffer
->_Xmax
;
1996 const GLint dstYmin
= ctx
->DrawBuffer
->_Ymin
;
1997 const GLint dstYmax
= ctx
->DrawBuffer
->_Ymax
;
2000 printf("PreClipX: src: %d .. %d dst: %d .. %d\n",
2001 *srcX0, *srcX1, *dstX0, *dstX1);
2002 printf("PreClipY: src: %d .. %d dst: %d .. %d\n",
2003 *srcY0, *srcY1, *dstY0, *dstY1);
2006 /* trivial rejection tests */
2007 if (*dstX0
== *dstX1
)
2008 return GL_FALSE
; /* no width */
2009 if (*dstX0
<= dstXmin
&& *dstX1
<= dstXmin
)
2010 return GL_FALSE
; /* totally out (left) of bounds */
2011 if (*dstX0
>= dstXmax
&& *dstX1
>= dstXmax
)
2012 return GL_FALSE
; /* totally out (right) of bounds */
2014 if (*dstY0
== *dstY1
)
2016 if (*dstY0
<= dstYmin
&& *dstY1
<= dstYmin
)
2018 if (*dstY0
>= dstYmax
&& *dstY1
>= dstYmax
)
2021 if (*srcX0
== *srcX1
)
2023 if (*srcX0
<= srcXmin
&& *srcX1
<= srcXmin
)
2025 if (*srcX0
>= srcXmax
&& *srcX1
>= srcXmax
)
2028 if (*srcY0
== *srcY1
)
2030 if (*srcY0
<= srcYmin
&& *srcY1
<= srcYmin
)
2032 if (*srcY0
>= srcYmax
&& *srcY1
>= srcYmax
)
2038 clip_right_or_top(srcX0
, srcX1
, dstX0
, dstX1
, dstXmax
);
2039 clip_right_or_top(srcY0
, srcY1
, dstY0
, dstY1
, dstYmax
);
2040 clip_left_or_bottom(srcX0
, srcX1
, dstX0
, dstX1
, dstXmin
);
2041 clip_left_or_bottom(srcY0
, srcY1
, dstY0
, dstY1
, dstYmin
);
2044 * src clip (just swap src/dst values from above)
2046 clip_right_or_top(dstX0
, dstX1
, srcX0
, srcX1
, srcXmax
);
2047 clip_right_or_top(dstY0
, dstY1
, srcY0
, srcY1
, srcYmax
);
2048 clip_left_or_bottom(dstX0
, dstX1
, srcX0
, srcX1
, srcXmin
);
2049 clip_left_or_bottom(dstY0
, dstY1
, srcY0
, srcY1
, srcYmin
);
2052 printf("PostClipX: src: %d .. %d dst: %d .. %d\n",
2053 *srcX0, *srcX1, *dstX0, *dstX1);
2054 printf("PostClipY: src: %d .. %d dst: %d .. %d\n",
2055 *srcY0, *srcY1, *dstY0, *dstY1);
2058 ASSERT(*dstX0
>= dstXmin
);
2059 ASSERT(*dstX0
<= dstXmax
);
2060 ASSERT(*dstX1
>= dstXmin
);
2061 ASSERT(*dstX1
<= dstXmax
);
2063 ASSERT(*dstY0
>= dstYmin
);
2064 ASSERT(*dstY0
<= dstYmax
);
2065 ASSERT(*dstY1
>= dstYmin
);
2066 ASSERT(*dstY1
<= dstYmax
);
2068 ASSERT(*srcX0
>= srcXmin
);
2069 ASSERT(*srcX0
<= srcXmax
);
2070 ASSERT(*srcX1
>= srcXmin
);
2071 ASSERT(*srcX1
<= srcXmax
);
2073 ASSERT(*srcY0
>= srcYmin
);
2074 ASSERT(*srcY0
<= srcYmax
);
2075 ASSERT(*srcY1
>= srcYmin
);
2076 ASSERT(*srcY1
<= srcYmax
);