2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (c) 2008-2009 VMware, Inc.
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.
32 * The GL texture image functions in teximage.c basically just do
33 * error checking and data structure allocation. They in turn call
34 * device driver functions which actually copy/convert/store the user's
37 * However, most device drivers will be able to use the fallback functions
38 * in this file. That is, most drivers will have the following bit of
40 * ctx->Driver.TexImage1D = _mesa_store_teximage1d;
41 * ctx->Driver.TexImage2D = _mesa_store_teximage2d;
42 * ctx->Driver.TexImage3D = _mesa_store_teximage3d;
45 * Texture image processing is actually kind of complicated. We have to do:
46 * Format/type conversions
48 * pixel transfer (scale, bais, lookup, convolution!, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
64 #include "texcompress.h"
65 #include "texcompress_fxt1.h"
66 #include "texcompress_s3tc.h"
68 #include "texformat.h"
81 * Texture image storage function.
83 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
87 * Return GL_TRUE if the given image format is one that be converted
88 * to another format by swizzling.
91 can_swizzle(GLenum logicalBaseFormat
)
93 switch (logicalBaseFormat
) {
96 case GL_LUMINANCE_ALPHA
:
130 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
131 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
132 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
133 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
136 static const struct {
139 GLubyte from_rgba
[6];
140 } mappings
[MAX_IDX
] =
150 MAP4(ZERO
, ZERO
, ZERO
, 0),
181 MAP4(0, ZERO
, ZERO
, ONE
),
187 MAP4(ZERO
, 0, ZERO
, ONE
),
193 MAP4(ZERO
, ZERO
, 0, ONE
),
219 * Convert a GL image format enum to an IDX_* value (see above).
222 get_map_idx(GLenum value
)
225 case GL_LUMINANCE
: return IDX_LUMINANCE
;
226 case GL_ALPHA
: return IDX_ALPHA
;
227 case GL_INTENSITY
: return IDX_INTENSITY
;
228 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
229 case GL_RGB
: return IDX_RGB
;
230 case GL_RGBA
: return IDX_RGBA
;
231 case GL_RED
: return IDX_RED
;
232 case GL_GREEN
: return IDX_GREEN
;
233 case GL_BLUE
: return IDX_BLUE
;
234 case GL_BGR
: return IDX_BGR
;
235 case GL_BGRA
: return IDX_BGRA
;
236 case GL_ABGR_EXT
: return IDX_ABGR
;
238 _mesa_problem(NULL
, "Unexpected inFormat");
245 * When promoting texture formats (see below) we need to compute the
246 * mapping of dest components back to source components.
247 * This function does that.
248 * \param inFormat the incoming format of the texture
249 * \param outFormat the final texture format
250 * \return map[6] a full 6-component map
253 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
256 const int inFmt
= get_map_idx(inFormat
);
257 const int outFmt
= get_map_idx(outFormat
);
258 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
259 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
262 for (i
= 0; i
< 4; i
++)
263 map
[i
] = in2rgba
[rgba2out
[i
]];
269 _mesa_printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
270 inFormat, _mesa_lookup_enum_by_nr(inFormat),
271 outFormat, _mesa_lookup_enum_by_nr(outFormat),
282 #if !FEATURE_convolve
284 _mesa_adjust_image_for_convolution(GLcontext
*ctx
, GLuint dims
,
285 GLsizei
*srcWidth
, GLsizei
*srcHeight
)
293 * Make a temporary (color) texture image with GLfloat components.
294 * Apply all needed pixel unpacking and pixel transfer operations.
295 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
296 * Suppose the user specifies GL_LUMINANCE as the internal texture format
297 * but the graphics hardware doesn't support luminance textures. So, might
298 * use an RGB hardware format instead.
299 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
301 * \param ctx the rendering context
302 * \param dims image dimensions: 1, 2 or 3
303 * \param logicalBaseFormat basic texture derived from the user's
304 * internal texture format value
305 * \param textureBaseFormat the actual basic format of the texture
306 * \param srcWidth source image width
307 * \param srcHeight source image height
308 * \param srcDepth source image depth
309 * \param srcFormat source image format
310 * \param srcType source image type
311 * \param srcAddr source image address
312 * \param srcPacking source image pixel packing
313 * \return resulting image with format = textureBaseFormat and type = GLfloat.
316 make_temp_float_image(GLcontext
*ctx
, GLuint dims
,
317 GLenum logicalBaseFormat
,
318 GLenum textureBaseFormat
,
319 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
320 GLenum srcFormat
, GLenum srcType
,
321 const GLvoid
*srcAddr
,
322 const struct gl_pixelstore_attrib
*srcPacking
)
324 GLuint transferOps
= ctx
->_ImageTransferState
;
327 ASSERT(dims
>= 1 && dims
<= 3);
329 ASSERT(logicalBaseFormat
== GL_RGBA
||
330 logicalBaseFormat
== GL_RGB
||
331 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
332 logicalBaseFormat
== GL_LUMINANCE
||
333 logicalBaseFormat
== GL_ALPHA
||
334 logicalBaseFormat
== GL_INTENSITY
||
335 logicalBaseFormat
== GL_COLOR_INDEX
||
336 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
338 ASSERT(textureBaseFormat
== GL_RGBA
||
339 textureBaseFormat
== GL_RGB
||
340 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
341 textureBaseFormat
== GL_LUMINANCE
||
342 textureBaseFormat
== GL_ALPHA
||
343 textureBaseFormat
== GL_INTENSITY
||
344 textureBaseFormat
== GL_COLOR_INDEX
||
345 textureBaseFormat
== GL_DEPTH_COMPONENT
);
347 /* conventional color image */
349 if ((dims
== 1 && ctx
->Pixel
.Convolution1DEnabled
) ||
350 (dims
>= 2 && ctx
->Pixel
.Convolution2DEnabled
) ||
351 (dims
>= 2 && ctx
->Pixel
.Separable2DEnabled
)) {
352 /* need image convolution */
353 const GLuint preConvTransferOps
354 = (transferOps
& IMAGE_PRE_CONVOLUTION_BITS
) | IMAGE_CLAMP_BIT
;
355 const GLuint postConvTransferOps
356 = (transferOps
& IMAGE_POST_CONVOLUTION_BITS
) | IMAGE_CLAMP_BIT
;
358 GLint convWidth
, convHeight
;
361 /* pre-convolution image buffer (3D) */
362 tempImage
= (GLfloat
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
363 * 4 * sizeof(GLfloat
));
367 /* post-convolution image buffer (2D) */
368 convImage
= (GLfloat
*) _mesa_malloc(srcWidth
* srcHeight
369 * 4 * sizeof(GLfloat
));
371 _mesa_free(tempImage
);
375 /* loop over 3D image slices */
376 for (img
= 0; img
< srcDepth
; img
++) {
377 GLfloat
*dst
= tempImage
+ img
* (srcWidth
* srcHeight
* 4);
379 /* unpack and do transfer ops up to convolution */
380 for (row
= 0; row
< srcHeight
; row
++) {
381 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
382 srcAddr
, srcWidth
, srcHeight
,
383 srcFormat
, srcType
, img
, row
, 0);
384 _mesa_unpack_color_span_float(ctx
, srcWidth
, GL_RGBA
, dst
,
385 srcFormat
, srcType
, src
,
391 /* size after optional convolution */
392 convWidth
= srcWidth
;
393 convHeight
= srcHeight
;
398 GLfloat
*src
= tempImage
+ img
* (srcWidth
* srcHeight
* 4);
400 ASSERT(ctx
->Pixel
.Convolution1DEnabled
);
401 _mesa_convolve_1d_image(ctx
, &convWidth
, src
, convImage
);
404 if (ctx
->Pixel
.Convolution2DEnabled
) {
405 _mesa_convolve_2d_image(ctx
, &convWidth
, &convHeight
,
409 ASSERT(ctx
->Pixel
.Separable2DEnabled
);
410 _mesa_convolve_sep_image(ctx
, &convWidth
, &convHeight
,
416 /* do post-convolution transfer and pack into tempImage */
418 const GLint logComponents
419 = _mesa_components_in_format(logicalBaseFormat
);
420 const GLfloat
*src
= convImage
;
421 GLfloat
*dst
= tempImage
+ img
* (convWidth
* convHeight
* 4);
422 for (row
= 0; row
< convHeight
; row
++) {
423 _mesa_pack_rgba_span_float(ctx
, convWidth
,
424 (GLfloat (*)[4]) src
,
425 logicalBaseFormat
, GL_FLOAT
,
426 dst
, &ctx
->DefaultPacking
,
427 postConvTransferOps
);
428 src
+= convWidth
* 4;
429 dst
+= convWidth
* logComponents
;
432 } /* loop over 3D image slices */
434 _mesa_free(convImage
);
436 /* might need these below */
437 srcWidth
= convWidth
;
438 srcHeight
= convHeight
;
442 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
443 const GLint srcStride
= _mesa_image_row_stride(srcPacking
,
444 srcWidth
, srcFormat
, srcType
);
448 tempImage
= (GLfloat
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
449 * components
* sizeof(GLfloat
));
454 for (img
= 0; img
< srcDepth
; img
++) {
456 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
460 for (row
= 0; row
< srcHeight
; row
++) {
461 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
462 dst
, srcFormat
, srcType
, src
,
463 srcPacking
, transferOps
);
464 dst
+= srcWidth
* components
;
470 if (logicalBaseFormat
!= textureBaseFormat
) {
472 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
473 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
478 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
479 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
480 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
482 /* The actual texture format should have at least as many components
483 * as the logical texture format.
485 ASSERT(texComponents
>= logComponents
);
487 newImage
= (GLfloat
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
488 * texComponents
* sizeof(GLfloat
));
490 _mesa_free(tempImage
);
494 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
496 n
= srcWidth
* srcHeight
* srcDepth
;
497 for (i
= 0; i
< n
; i
++) {
499 for (k
= 0; k
< texComponents
; k
++) {
502 newImage
[i
* texComponents
+ k
] = 0.0F
;
504 newImage
[i
* texComponents
+ k
] = 1.0F
;
506 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
510 _mesa_free(tempImage
);
511 tempImage
= newImage
;
519 * Make a temporary (color) texture image with GLchan components.
520 * Apply all needed pixel unpacking and pixel transfer operations.
521 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
522 * Suppose the user specifies GL_LUMINANCE as the internal texture format
523 * but the graphics hardware doesn't support luminance textures. So, might
524 * use an RGB hardware format instead.
525 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
527 * \param ctx the rendering context
528 * \param dims image dimensions: 1, 2 or 3
529 * \param logicalBaseFormat basic texture derived from the user's
530 * internal texture format value
531 * \param textureBaseFormat the actual basic format of the texture
532 * \param srcWidth source image width
533 * \param srcHeight source image height
534 * \param srcDepth source image depth
535 * \param srcFormat source image format
536 * \param srcType source image type
537 * \param srcAddr source image address
538 * \param srcPacking source image pixel packing
539 * \return resulting image with format = textureBaseFormat and type = GLchan.
542 _mesa_make_temp_chan_image(GLcontext
*ctx
, GLuint dims
,
543 GLenum logicalBaseFormat
,
544 GLenum textureBaseFormat
,
545 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
546 GLenum srcFormat
, GLenum srcType
,
547 const GLvoid
*srcAddr
,
548 const struct gl_pixelstore_attrib
*srcPacking
)
550 GLuint transferOps
= ctx
->_ImageTransferState
;
551 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
552 GLboolean freeSrcImage
= GL_FALSE
;
554 GLchan
*tempImage
, *dst
;
556 ASSERT(dims
>= 1 && dims
<= 3);
558 ASSERT(logicalBaseFormat
== GL_RGBA
||
559 logicalBaseFormat
== GL_RGB
||
560 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
561 logicalBaseFormat
== GL_LUMINANCE
||
562 logicalBaseFormat
== GL_ALPHA
||
563 logicalBaseFormat
== GL_INTENSITY
);
565 ASSERT(textureBaseFormat
== GL_RGBA
||
566 textureBaseFormat
== GL_RGB
||
567 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
568 textureBaseFormat
== GL_LUMINANCE
||
569 textureBaseFormat
== GL_ALPHA
||
570 textureBaseFormat
== GL_INTENSITY
);
573 if ((dims
== 1 && ctx
->Pixel
.Convolution1DEnabled
) ||
574 (dims
>= 2 && ctx
->Pixel
.Convolution2DEnabled
) ||
575 (dims
>= 2 && ctx
->Pixel
.Separable2DEnabled
)) {
576 /* get convolved image */
577 GLfloat
*convImage
= make_temp_float_image(ctx
, dims
,
580 srcWidth
, srcHeight
, srcDepth
,
582 srcAddr
, srcPacking
);
585 /* the convolved image is our new source image */
587 srcFormat
= logicalBaseFormat
;
589 srcPacking
= &ctx
->DefaultPacking
;
590 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
592 freeSrcImage
= GL_TRUE
;
596 /* unpack and transfer the source image */
597 tempImage
= (GLchan
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
598 * components
* sizeof(GLchan
));
603 for (img
= 0; img
< srcDepth
; img
++) {
604 const GLint srcStride
= _mesa_image_row_stride(srcPacking
,
608 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
612 for (row
= 0; row
< srcHeight
; row
++) {
613 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
614 srcFormat
, srcType
, src
, srcPacking
,
616 dst
+= srcWidth
* components
;
621 /* If we made a temporary image for convolution, free it here */
623 _mesa_free((void *) srcAddr
);
626 if (logicalBaseFormat
!= textureBaseFormat
) {
627 /* one more conversion step */
628 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
629 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
634 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
635 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
636 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
638 /* The actual texture format should have at least as many components
639 * as the logical texture format.
641 ASSERT(texComponents
>= logComponents
);
643 newImage
= (GLchan
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
644 * texComponents
* sizeof(GLchan
));
646 _mesa_free(tempImage
);
650 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
652 n
= srcWidth
* srcHeight
* srcDepth
;
653 for (i
= 0; i
< n
; i
++) {
655 for (k
= 0; k
< texComponents
; k
++) {
658 newImage
[i
* texComponents
+ k
] = 0;
660 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
662 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
666 _mesa_free(tempImage
);
667 tempImage
= newImage
;
675 * Copy GLubyte pixels from <src> to <dst> with swizzling.
676 * \param dst destination pixels
677 * \param dstComponents number of color components in destination pixels
678 * \param src source pixels
679 * \param srcComponents number of color components in source pixels
680 * \param map the swizzle mapping. map[X] says where to find the X component
681 * in the source image's pixels. For example, if the source image
682 * is GL_BGRA and X = red, map[0] yields 2.
683 * \param count number of pixels to copy/swizzle.
686 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
687 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
689 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
692 for (i = 0; i < count; i++) { \
694 if (srcComps == 4) { \
695 COPY_4UBV(tmp, src); \
698 for (j = 0; j < srcComps; j++) { \
703 for (j = 0; j < dstComps; j++) { \
704 dst[j] = tmp[map[j]]; \
715 ASSERT(srcComponents
<= 4);
716 ASSERT(dstComponents
<= 4);
718 switch (dstComponents
) {
720 switch (srcComponents
) {
722 SWZ_CPY(dst
, src
, count
, 4, 4);
725 SWZ_CPY(dst
, src
, count
, 4, 3);
728 SWZ_CPY(dst
, src
, count
, 4, 2);
731 SWZ_CPY(dst
, src
, count
, 4, 1);
738 switch (srcComponents
) {
740 SWZ_CPY(dst
, src
, count
, 3, 4);
743 SWZ_CPY(dst
, src
, count
, 3, 3);
746 SWZ_CPY(dst
, src
, count
, 3, 2);
749 SWZ_CPY(dst
, src
, count
, 3, 1);
756 switch (srcComponents
) {
758 SWZ_CPY(dst
, src
, count
, 2, 4);
761 SWZ_CPY(dst
, src
, count
, 2, 3);
764 SWZ_CPY(dst
, src
, count
, 2, 2);
767 SWZ_CPY(dst
, src
, count
, 2, 1);
774 switch (srcComponents
) {
776 SWZ_CPY(dst
, src
, count
, 1, 4);
779 SWZ_CPY(dst
, src
, count
, 1, 3);
782 SWZ_CPY(dst
, src
, count
, 1, 2);
785 SWZ_CPY(dst
, src
, count
, 1, 1);
799 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
800 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
802 /* Deal with the _REV input types:
804 static const GLubyte
*
805 type_mapping( GLenum srcType
)
809 case GL_UNSIGNED_BYTE
:
811 case GL_UNSIGNED_INT_8_8_8_8
:
812 return _mesa_little_endian() ? map_3210
: map_identity
;
813 case GL_UNSIGNED_INT_8_8_8_8_REV
:
814 return _mesa_little_endian() ? map_identity
: map_3210
;
820 /* Mapping required if input type is
822 static const GLubyte
*
823 byteswap_mapping( GLboolean swapBytes
,
831 case GL_UNSIGNED_BYTE
:
833 case GL_UNSIGNED_INT_8_8_8_8
:
834 case GL_UNSIGNED_INT_8_8_8_8_REV
:
844 * Transfer a GLubyte texture image with component swizzling.
847 _mesa_swizzle_ubyte_image(GLcontext
*ctx
,
852 GLenum baseInternalFormat
,
854 const GLubyte
*rgba2dst
,
855 GLuint dstComponents
,
858 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
860 const GLuint
*dstImageOffsets
,
862 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
863 const GLvoid
*srcAddr
,
864 const struct gl_pixelstore_attrib
*srcPacking
)
866 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
867 const GLubyte
*srctype2ubyte
, *swap
;
868 GLubyte map
[4], src2base
[6], base2rgba
[6];
870 const GLint srcRowStride
=
871 _mesa_image_row_stride(srcPacking
, srcWidth
,
872 srcFormat
, GL_UNSIGNED_BYTE
);
873 const GLint srcImageStride
874 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
876 const GLubyte
*srcImage
877 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
878 srcWidth
, srcHeight
, srcFormat
,
879 GL_UNSIGNED_BYTE
, 0, 0, 0);
883 /* Translate from src->baseInternal->GL_RGBA->dst. This will
884 * correctly deal with RGBA->RGB->RGBA conversions where the final
885 * A value must be 0xff regardless of the incoming alpha values.
887 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
888 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
889 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
890 srctype2ubyte
= type_mapping(srcType
);
893 for (i
= 0; i
< 4; i
++)
894 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
896 /* _mesa_printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
898 if (srcComponents
== dstComponents
&&
899 srcRowStride
== dstRowStride
&&
900 srcRowStride
== srcWidth
* srcComponents
&&
902 /* 1 and 2D images only */
903 GLubyte
*dstImage
= (GLubyte
*) dstAddr
904 + dstYoffset
* dstRowStride
905 + dstXoffset
* dstComponents
;
906 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
907 srcWidth
* srcHeight
);
911 for (img
= 0; img
< srcDepth
; img
++) {
912 const GLubyte
*srcRow
= srcImage
;
913 GLubyte
*dstRow
= (GLubyte
*) dstAddr
914 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
915 + dstYoffset
* dstRowStride
916 + dstXoffset
* dstComponents
;
917 for (row
= 0; row
< srcHeight
; row
++) {
918 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
919 dstRow
+= dstRowStride
;
920 srcRow
+= srcRowStride
;
922 srcImage
+= srcImageStride
;
929 * Teximage storage routine for when a simple memcpy will do.
930 * No pixel transfer operations or special texel encodings allowed.
931 * 1D, 2D and 3D images supported.
934 memcpy_texture(GLcontext
*ctx
,
938 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
940 const GLuint
*dstImageOffsets
,
941 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
942 GLenum srcFormat
, GLenum srcType
,
943 const GLvoid
*srcAddr
,
944 const struct gl_pixelstore_attrib
*srcPacking
)
946 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
948 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
949 srcWidth
, srcHeight
, srcFormat
, srcType
);
950 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
951 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
952 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
953 const GLint bytesPerRow
= srcWidth
* texelBytes
;
956 /* XXX update/re-enable for dstImageOffsets array */
957 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
958 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
959 GLubyte
*dstImage
= (GLubyte
*) dstAddr
960 + dstZoffset
* dstImageStride
961 + dstYoffset
* dstRowStride
962 + dstXoffset
* texelBytes
;
964 if (dstRowStride
== srcRowStride
&&
965 dstRowStride
== bytesPerRow
&&
966 ((dstImageStride
== srcImageStride
&&
967 dstImageStride
== bytesPerImage
) ||
970 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
975 for (img
= 0; img
< srcDepth
; img
++) {
976 const GLubyte
*srcRow
= srcImage
;
977 GLubyte
*dstRow
= dstImage
;
978 for (row
= 0; row
< srcHeight
; row
++) {
979 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
980 dstRow
+= dstRowStride
;
981 srcRow
+= srcRowStride
;
983 srcImage
+= srcImageStride
;
984 dstImage
+= dstImageStride
;
990 for (img
= 0; img
< srcDepth
; img
++) {
991 const GLubyte
*srcRow
= srcImage
;
992 GLubyte
*dstRow
= (GLubyte
*) dstAddr
993 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
994 + dstYoffset
* dstRowStride
995 + dstXoffset
* texelBytes
;
996 for (row
= 0; row
< srcHeight
; row
++) {
997 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
998 dstRow
+= dstRowStride
;
999 srcRow
+= srcRowStride
;
1001 srcImage
+= srcImageStride
;
1008 * Store a 32-bit integer depth component texture image.
1011 _mesa_texstore_z32(TEXSTORE_PARAMS
)
1013 const GLuint depthScale
= 0xffffffff;
1014 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1016 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
1017 ASSERT(texelBytes
== sizeof(GLuint
));
1019 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1020 ctx
->Pixel
.DepthBias
== 0.0f
&&
1021 !srcPacking
->SwapBytes
&&
1022 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1023 srcFormat
== GL_DEPTH_COMPONENT
&&
1024 srcType
== GL_UNSIGNED_INT
) {
1025 /* simple memcpy path */
1026 memcpy_texture(ctx
, dims
,
1027 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1030 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1031 srcAddr
, srcPacking
);
1036 for (img
= 0; img
< srcDepth
; img
++) {
1037 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1038 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1039 + dstYoffset
* dstRowStride
1040 + dstXoffset
* texelBytes
;
1041 for (row
= 0; row
< srcHeight
; row
++) {
1042 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1043 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1044 _mesa_unpack_depth_span(ctx
, srcWidth
,
1045 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
1046 depthScale
, srcType
, src
, srcPacking
);
1047 dstRow
+= dstRowStride
;
1057 * Store a 16-bit integer depth component texture image.
1060 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1062 const GLuint depthScale
= 0xffff;
1063 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1065 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1066 ASSERT(texelBytes
== sizeof(GLushort
));
1068 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1069 ctx
->Pixel
.DepthBias
== 0.0f
&&
1070 !srcPacking
->SwapBytes
&&
1071 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1072 srcFormat
== GL_DEPTH_COMPONENT
&&
1073 srcType
== GL_UNSIGNED_SHORT
) {
1074 /* simple memcpy path */
1075 memcpy_texture(ctx
, dims
,
1076 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1079 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1080 srcAddr
, srcPacking
);
1085 for (img
= 0; img
< srcDepth
; img
++) {
1086 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1087 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1088 + dstYoffset
* dstRowStride
1089 + dstXoffset
* texelBytes
;
1090 for (row
= 0; row
< srcHeight
; row
++) {
1091 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1092 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1093 GLushort
*dst16
= (GLushort
*) dstRow
;
1094 _mesa_unpack_depth_span(ctx
, srcWidth
,
1095 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1096 srcType
, src
, srcPacking
);
1097 dstRow
+= dstRowStride
;
1106 * Store an rgb565 or rgb565_rev texture image.
1109 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1111 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1112 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1114 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1115 dstFormat
== MESA_FORMAT_RGB565_REV
);
1116 ASSERT(texelBytes
== 2);
1118 if (!ctx
->_ImageTransferState
&&
1119 !srcPacking
->SwapBytes
&&
1120 dstFormat
== MESA_FORMAT_RGB565
&&
1121 baseInternalFormat
== GL_RGB
&&
1122 srcFormat
== GL_RGB
&&
1123 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1124 /* simple memcpy path */
1125 memcpy_texture(ctx
, dims
,
1126 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1129 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1130 srcAddr
, srcPacking
);
1132 else if (!ctx
->_ImageTransferState
&&
1133 !srcPacking
->SwapBytes
&&
1134 baseInternalFormat
== GL_RGB
&&
1135 srcFormat
== GL_RGB
&&
1136 srcType
== GL_UNSIGNED_BYTE
&&
1138 /* do optimized tex store */
1139 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
1140 srcFormat
, srcType
);
1141 const GLubyte
*src
= (const GLubyte
*)
1142 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1143 srcFormat
, srcType
, 0, 0, 0);
1144 GLubyte
*dst
= (GLubyte
*) dstAddr
1145 + dstYoffset
* dstRowStride
1146 + dstXoffset
* texelBytes
;
1148 for (row
= 0; row
< srcHeight
; row
++) {
1149 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1150 GLushort
*dstUS
= (GLushort
*) dst
;
1151 /* check for byteswapped format */
1152 if (dstFormat
== MESA_FORMAT_RGB565
) {
1153 for (col
= 0; col
< srcWidth
; col
++) {
1154 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1159 for (col
= 0; col
< srcWidth
; col
++) {
1160 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1164 dst
+= dstRowStride
;
1165 src
+= srcRowStride
;
1170 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1173 srcWidth
, srcHeight
, srcDepth
,
1174 srcFormat
, srcType
, srcAddr
,
1176 const GLchan
*src
= tempImage
;
1177 GLint img
, row
, col
;
1180 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1181 for (img
= 0; img
< srcDepth
; img
++) {
1182 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1183 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1184 + dstYoffset
* dstRowStride
1185 + dstXoffset
* texelBytes
;
1186 for (row
= 0; row
< srcHeight
; row
++) {
1187 GLushort
*dstUS
= (GLushort
*) dstRow
;
1188 /* check for byteswapped format */
1189 if (dstFormat
== MESA_FORMAT_RGB565
) {
1190 for (col
= 0; col
< srcWidth
; col
++) {
1191 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1192 CHAN_TO_UBYTE(src
[GCOMP
]),
1193 CHAN_TO_UBYTE(src
[BCOMP
]) );
1198 for (col
= 0; col
< srcWidth
; col
++) {
1199 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1200 CHAN_TO_UBYTE(src
[GCOMP
]),
1201 CHAN_TO_UBYTE(src
[BCOMP
]) );
1205 dstRow
+= dstRowStride
;
1208 _mesa_free((void *) tempImage
);
1215 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1218 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1220 const GLboolean littleEndian
= _mesa_little_endian();
1221 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1222 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1224 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1225 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1226 ASSERT(texelBytes
== 4);
1228 if (!ctx
->_ImageTransferState
&&
1229 !srcPacking
->SwapBytes
&&
1230 dstFormat
== MESA_FORMAT_RGBA8888
&&
1231 baseInternalFormat
== GL_RGBA
&&
1232 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1233 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1234 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1235 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1236 /* simple memcpy path */
1237 memcpy_texture(ctx
, dims
,
1238 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1241 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1242 srcAddr
, srcPacking
);
1244 else if (!ctx
->_ImageTransferState
&&
1245 !srcPacking
->SwapBytes
&&
1246 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1247 baseInternalFormat
== GL_RGBA
&&
1248 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1249 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1250 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1251 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1252 /* simple memcpy path */
1253 memcpy_texture(ctx
, dims
,
1254 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1257 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1258 srcAddr
, srcPacking
);
1260 else if (!ctx
->_ImageTransferState
&&
1261 (srcType
== GL_UNSIGNED_BYTE
||
1262 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1263 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1264 can_swizzle(baseInternalFormat
) &&
1265 can_swizzle(srcFormat
)) {
1269 /* dstmap - how to swizzle from RGBA to dst format:
1271 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1272 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1285 _mesa_swizzle_ubyte_image(ctx
, dims
,
1290 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1291 dstRowStride
, dstImageOffsets
,
1292 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1297 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1300 srcWidth
, srcHeight
, srcDepth
,
1301 srcFormat
, srcType
, srcAddr
,
1303 const GLchan
*src
= tempImage
;
1304 GLint img
, row
, col
;
1307 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1308 for (img
= 0; img
< srcDepth
; img
++) {
1309 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1310 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1311 + dstYoffset
* dstRowStride
1312 + dstXoffset
* texelBytes
;
1313 for (row
= 0; row
< srcHeight
; row
++) {
1314 GLuint
*dstUI
= (GLuint
*) dstRow
;
1315 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1316 for (col
= 0; col
< srcWidth
; col
++) {
1317 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1318 CHAN_TO_UBYTE(src
[GCOMP
]),
1319 CHAN_TO_UBYTE(src
[BCOMP
]),
1320 CHAN_TO_UBYTE(src
[ACOMP
]) );
1325 for (col
= 0; col
< srcWidth
; col
++) {
1326 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1327 CHAN_TO_UBYTE(src
[GCOMP
]),
1328 CHAN_TO_UBYTE(src
[BCOMP
]),
1329 CHAN_TO_UBYTE(src
[ACOMP
]) );
1333 dstRow
+= dstRowStride
;
1336 _mesa_free((void *) tempImage
);
1343 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1345 const GLboolean littleEndian
= _mesa_little_endian();
1346 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1347 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1349 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1350 dstFormat
== MESA_FORMAT_ARGB8888_REV
);
1351 ASSERT(texelBytes
== 4);
1353 if (!ctx
->_ImageTransferState
&&
1354 !srcPacking
->SwapBytes
&&
1355 dstFormat
== MESA_FORMAT_ARGB8888
&&
1356 baseInternalFormat
== GL_RGBA
&&
1357 srcFormat
== GL_BGRA
&&
1358 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1359 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1360 /* simple memcpy path (little endian) */
1361 memcpy_texture(ctx
, dims
,
1362 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1365 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1366 srcAddr
, srcPacking
);
1368 else if (!ctx
->_ImageTransferState
&&
1369 !srcPacking
->SwapBytes
&&
1370 dstFormat
== MESA_FORMAT_ARGB8888_REV
&&
1371 baseInternalFormat
== GL_RGBA
&&
1372 srcFormat
== GL_BGRA
&&
1373 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1374 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1375 /* simple memcpy path (big endian) */
1376 memcpy_texture(ctx
, dims
,
1377 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1380 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1381 srcAddr
, srcPacking
);
1383 else if (!ctx
->_ImageTransferState
&&
1384 !srcPacking
->SwapBytes
&&
1385 dstFormat
== MESA_FORMAT_ARGB8888
&&
1386 srcFormat
== GL_RGB
&&
1387 (baseInternalFormat
== GL_RGBA
||
1388 baseInternalFormat
== GL_RGB
) &&
1389 srcType
== GL_UNSIGNED_BYTE
) {
1391 for (img
= 0; img
< srcDepth
; img
++) {
1392 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
,
1393 srcWidth
, srcFormat
, srcType
);
1394 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1395 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1396 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1397 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1398 + dstYoffset
* dstRowStride
1399 + dstXoffset
* texelBytes
;
1400 for (row
= 0; row
< srcHeight
; row
++) {
1401 GLuint
*d4
= (GLuint
*) dstRow
;
1402 for (col
= 0; col
< srcWidth
; col
++) {
1403 d4
[col
] = PACK_COLOR_8888(0xff,
1404 srcRow
[col
* 3 + RCOMP
],
1405 srcRow
[col
* 3 + GCOMP
],
1406 srcRow
[col
* 3 + BCOMP
]);
1408 dstRow
+= dstRowStride
;
1409 srcRow
+= srcRowStride
;
1413 else if (!ctx
->_ImageTransferState
&&
1414 !srcPacking
->SwapBytes
&&
1415 dstFormat
== MESA_FORMAT_ARGB8888
&&
1416 srcFormat
== GL_RGBA
&&
1417 baseInternalFormat
== GL_RGBA
&&
1418 srcType
== GL_UNSIGNED_BYTE
) {
1419 /* same as above case, but src data has alpha too */
1420 GLint img
, row
, col
;
1421 /* For some reason, streaming copies to write-combined regions
1422 * are extremely sensitive to the characteristics of how the
1423 * source data is retrieved. By reordering the source reads to
1424 * be in-order, the speed of this operation increases by half.
1425 * Strangely the same isn't required for the RGB path, above.
1427 for (img
= 0; img
< srcDepth
; img
++) {
1428 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
,
1429 srcWidth
, srcFormat
, srcType
);
1430 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1431 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1432 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1433 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1434 + dstYoffset
* dstRowStride
1435 + dstXoffset
* texelBytes
;
1436 for (row
= 0; row
< srcHeight
; row
++) {
1437 GLuint
*d4
= (GLuint
*) dstRow
;
1438 for (col
= 0; col
< srcWidth
; col
++) {
1439 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1440 srcRow
[col
* 4 + RCOMP
],
1441 srcRow
[col
* 4 + GCOMP
],
1442 srcRow
[col
* 4 + BCOMP
]);
1444 dstRow
+= dstRowStride
;
1445 srcRow
+= srcRowStride
;
1449 else if (!ctx
->_ImageTransferState
&&
1450 (srcType
== GL_UNSIGNED_BYTE
||
1451 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1452 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1453 can_swizzle(baseInternalFormat
) &&
1454 can_swizzle(srcFormat
)) {
1458 /* dstmap - how to swizzle from RGBA to dst format:
1460 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1461 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
)) {
1462 dstmap
[3] = 3; /* alpha */
1463 dstmap
[2] = 0; /* red */
1464 dstmap
[1] = 1; /* green */
1465 dstmap
[0] = 2; /* blue */
1468 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1469 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
));
1476 _mesa_swizzle_ubyte_image(ctx
, dims
,
1482 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1485 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1490 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1493 srcWidth
, srcHeight
, srcDepth
,
1494 srcFormat
, srcType
, srcAddr
,
1496 const GLchan
*src
= tempImage
;
1497 GLint img
, row
, col
;
1500 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1501 for (img
= 0; img
< srcDepth
; img
++) {
1502 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1503 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1504 + dstYoffset
* dstRowStride
1505 + dstXoffset
* texelBytes
;
1506 for (row
= 0; row
< srcHeight
; row
++) {
1507 GLuint
*dstUI
= (GLuint
*) dstRow
;
1508 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1509 for (col
= 0; col
< srcWidth
; col
++) {
1510 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1511 CHAN_TO_UBYTE(src
[RCOMP
]),
1512 CHAN_TO_UBYTE(src
[GCOMP
]),
1513 CHAN_TO_UBYTE(src
[BCOMP
]) );
1518 for (col
= 0; col
< srcWidth
; col
++) {
1519 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1520 CHAN_TO_UBYTE(src
[RCOMP
]),
1521 CHAN_TO_UBYTE(src
[GCOMP
]),
1522 CHAN_TO_UBYTE(src
[BCOMP
]) );
1526 dstRow
+= dstRowStride
;
1529 _mesa_free((void *) tempImage
);
1536 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1538 const GLboolean littleEndian
= _mesa_little_endian();
1539 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1540 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1542 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1543 ASSERT(texelBytes
== 3);
1545 if (!ctx
->_ImageTransferState
&&
1546 !srcPacking
->SwapBytes
&&
1547 baseInternalFormat
== GL_RGB
&&
1548 srcFormat
== GL_BGR
&&
1549 srcType
== GL_UNSIGNED_BYTE
&&
1551 /* simple memcpy path */
1552 memcpy_texture(ctx
, dims
,
1553 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1556 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1557 srcAddr
, srcPacking
);
1559 else if (!ctx
->_ImageTransferState
&&
1560 !srcPacking
->SwapBytes
&&
1561 srcFormat
== GL_RGBA
&&
1562 srcType
== GL_UNSIGNED_BYTE
) {
1563 /* extract RGB from RGBA */
1564 GLint img
, row
, col
;
1565 for (img
= 0; img
< srcDepth
; img
++) {
1566 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
,
1567 srcWidth
, srcFormat
, srcType
);
1568 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1569 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1570 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1571 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1572 + dstYoffset
* dstRowStride
1573 + dstXoffset
* texelBytes
;
1574 for (row
= 0; row
< srcHeight
; row
++) {
1575 for (col
= 0; col
< srcWidth
; col
++) {
1576 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1577 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1578 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1580 dstRow
+= dstRowStride
;
1581 srcRow
+= srcRowStride
;
1585 else if (!ctx
->_ImageTransferState
&&
1586 srcType
== GL_UNSIGNED_BYTE
&&
1587 can_swizzle(baseInternalFormat
) &&
1588 can_swizzle(srcFormat
)) {
1592 /* dstmap - how to swizzle from RGBA to dst format:
1597 dstmap
[3] = ONE
; /* ? */
1599 _mesa_swizzle_ubyte_image(ctx
, dims
,
1604 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1605 dstRowStride
, dstImageOffsets
,
1606 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1611 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1614 srcWidth
, srcHeight
, srcDepth
,
1615 srcFormat
, srcType
, srcAddr
,
1617 const GLchan
*src
= (const GLchan
*) tempImage
;
1618 GLint img
, row
, col
;
1621 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1622 for (img
= 0; img
< srcDepth
; img
++) {
1623 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1624 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1625 + dstYoffset
* dstRowStride
1626 + dstXoffset
* texelBytes
;
1627 for (row
= 0; row
< srcHeight
; row
++) {
1630 for (col
= 0; col
< srcWidth
; col
++) {
1631 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1632 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1633 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1638 for (col
= 0; col
< srcWidth
; col
++) {
1639 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1640 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1641 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1646 for (col
= 0; col
< srcWidth
; col
++) {
1647 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1648 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1649 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1653 dstRow
+= dstRowStride
;
1656 _mesa_free((void *) tempImage
);
1663 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1665 const GLboolean littleEndian
= _mesa_little_endian();
1666 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1667 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1669 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1670 ASSERT(texelBytes
== 3);
1672 if (!ctx
->_ImageTransferState
&&
1673 !srcPacking
->SwapBytes
&&
1674 baseInternalFormat
== GL_RGB
&&
1675 srcFormat
== GL_RGB
&&
1676 srcType
== GL_UNSIGNED_BYTE
&&
1678 /* simple memcpy path */
1679 memcpy_texture(ctx
, dims
,
1680 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1683 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1684 srcAddr
, srcPacking
);
1686 else if (!ctx
->_ImageTransferState
&&
1687 !srcPacking
->SwapBytes
&&
1688 srcFormat
== GL_RGBA
&&
1689 srcType
== GL_UNSIGNED_BYTE
) {
1690 /* extract BGR from RGBA */
1692 for (img
= 0; img
< srcDepth
; img
++) {
1693 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
,
1694 srcWidth
, srcFormat
, srcType
);
1695 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1696 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1697 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1698 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1699 + dstYoffset
* dstRowStride
1700 + dstXoffset
* texelBytes
;
1701 for (row
= 0; row
< srcHeight
; row
++) {
1702 for (col
= 0; col
< srcWidth
; col
++) {
1703 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1704 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1705 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1707 dstRow
+= dstRowStride
;
1708 srcRow
+= srcRowStride
;
1712 else if (!ctx
->_ImageTransferState
&&
1713 srcType
== GL_UNSIGNED_BYTE
&&
1714 can_swizzle(baseInternalFormat
) &&
1715 can_swizzle(srcFormat
)) {
1719 /* dstmap - how to swizzle from RGBA to dst format:
1724 dstmap
[3] = ONE
; /* ? */
1726 _mesa_swizzle_ubyte_image(ctx
, dims
,
1731 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1732 dstRowStride
, dstImageOffsets
,
1733 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1738 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1741 srcWidth
, srcHeight
, srcDepth
,
1742 srcFormat
, srcType
, srcAddr
,
1744 const GLchan
*src
= (const GLchan
*) tempImage
;
1745 GLint img
, row
, col
;
1748 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1749 for (img
= 0; img
< srcDepth
; img
++) {
1750 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1751 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1752 + dstYoffset
* dstRowStride
1753 + dstXoffset
* texelBytes
;
1754 for (row
= 0; row
< srcHeight
; row
++) {
1755 for (col
= 0; col
< srcWidth
; col
++) {
1756 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1757 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1758 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1761 dstRow
+= dstRowStride
;
1764 _mesa_free((void *) tempImage
);
1771 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1773 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1774 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1776 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1777 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1778 ASSERT(texelBytes
== 2);
1780 if (!ctx
->_ImageTransferState
&&
1781 !srcPacking
->SwapBytes
&&
1782 dstFormat
== MESA_FORMAT_ARGB4444
&&
1783 baseInternalFormat
== GL_RGBA
&&
1784 srcFormat
== GL_BGRA
&&
1785 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1786 /* simple memcpy path */
1787 memcpy_texture(ctx
, dims
,
1788 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1791 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1792 srcAddr
, srcPacking
);
1796 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1799 srcWidth
, srcHeight
, srcDepth
,
1800 srcFormat
, srcType
, srcAddr
,
1802 const GLchan
*src
= tempImage
;
1803 GLint img
, row
, col
;
1806 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1807 for (img
= 0; img
< srcDepth
; img
++) {
1808 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1809 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1810 + dstYoffset
* dstRowStride
1811 + dstXoffset
* texelBytes
;
1812 for (row
= 0; row
< srcHeight
; row
++) {
1813 GLushort
*dstUS
= (GLushort
*) dstRow
;
1814 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1815 for (col
= 0; col
< srcWidth
; col
++) {
1816 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1817 CHAN_TO_UBYTE(src
[RCOMP
]),
1818 CHAN_TO_UBYTE(src
[GCOMP
]),
1819 CHAN_TO_UBYTE(src
[BCOMP
]) );
1824 for (col
= 0; col
< srcWidth
; col
++) {
1825 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1826 CHAN_TO_UBYTE(src
[RCOMP
]),
1827 CHAN_TO_UBYTE(src
[GCOMP
]),
1828 CHAN_TO_UBYTE(src
[BCOMP
]) );
1832 dstRow
+= dstRowStride
;
1835 _mesa_free((void *) tempImage
);
1841 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1843 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1844 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1846 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1847 ASSERT(texelBytes
== 2);
1849 if (!ctx
->_ImageTransferState
&&
1850 !srcPacking
->SwapBytes
&&
1851 dstFormat
== MESA_FORMAT_RGBA5551
&&
1852 baseInternalFormat
== GL_RGBA
&&
1853 srcFormat
== GL_RGBA
&&
1854 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1855 /* simple memcpy path */
1856 memcpy_texture(ctx
, dims
,
1857 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1860 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1861 srcAddr
, srcPacking
);
1865 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1868 srcWidth
, srcHeight
, srcDepth
,
1869 srcFormat
, srcType
, srcAddr
,
1871 const GLchan
*src
=tempImage
;
1872 GLint img
, row
, col
;
1875 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1876 for (img
= 0; img
< srcDepth
; img
++) {
1877 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1878 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1879 + dstYoffset
* dstRowStride
1880 + dstXoffset
* texelBytes
;
1881 for (row
= 0; row
< srcHeight
; row
++) {
1882 GLushort
*dstUS
= (GLushort
*) dstRow
;
1883 for (col
= 0; col
< srcWidth
; col
++) {
1884 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1885 CHAN_TO_UBYTE(src
[GCOMP
]),
1886 CHAN_TO_UBYTE(src
[BCOMP
]),
1887 CHAN_TO_UBYTE(src
[ACOMP
]) );
1890 dstRow
+= dstRowStride
;
1893 _mesa_free((void *) tempImage
);
1899 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1901 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1902 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1904 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1905 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1906 ASSERT(texelBytes
== 2);
1908 if (!ctx
->_ImageTransferState
&&
1909 !srcPacking
->SwapBytes
&&
1910 dstFormat
== MESA_FORMAT_ARGB1555
&&
1911 baseInternalFormat
== GL_RGBA
&&
1912 srcFormat
== GL_BGRA
&&
1913 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1914 /* simple memcpy path */
1915 memcpy_texture(ctx
, dims
,
1916 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1919 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1920 srcAddr
, srcPacking
);
1924 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1927 srcWidth
, srcHeight
, srcDepth
,
1928 srcFormat
, srcType
, srcAddr
,
1930 const GLchan
*src
=tempImage
;
1931 GLint img
, row
, col
;
1934 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
1935 for (img
= 0; img
< srcDepth
; img
++) {
1936 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1937 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1938 + dstYoffset
* dstRowStride
1939 + dstXoffset
* texelBytes
;
1940 for (row
= 0; row
< srcHeight
; row
++) {
1941 GLushort
*dstUS
= (GLushort
*) dstRow
;
1942 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1943 for (col
= 0; col
< srcWidth
; col
++) {
1944 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
1945 CHAN_TO_UBYTE(src
[RCOMP
]),
1946 CHAN_TO_UBYTE(src
[GCOMP
]),
1947 CHAN_TO_UBYTE(src
[BCOMP
]) );
1952 for (col
= 0; col
< srcWidth
; col
++) {
1953 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1954 CHAN_TO_UBYTE(src
[RCOMP
]),
1955 CHAN_TO_UBYTE(src
[GCOMP
]),
1956 CHAN_TO_UBYTE(src
[BCOMP
]) );
1960 dstRow
+= dstRowStride
;
1963 _mesa_free((void *) tempImage
);
1970 _mesa_texstore_al88(TEXSTORE_PARAMS
)
1972 const GLboolean littleEndian
= _mesa_little_endian();
1973 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1974 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1976 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
1977 dstFormat
== MESA_FORMAT_AL88_REV
);
1978 ASSERT(texelBytes
== 2);
1980 if (!ctx
->_ImageTransferState
&&
1981 !srcPacking
->SwapBytes
&&
1982 dstFormat
== MESA_FORMAT_AL88
&&
1983 baseInternalFormat
== GL_LUMINANCE_ALPHA
&&
1984 srcFormat
== GL_LUMINANCE_ALPHA
&&
1985 srcType
== GL_UNSIGNED_BYTE
&&
1987 /* simple memcpy path */
1988 memcpy_texture(ctx
, dims
,
1989 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1992 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1993 srcAddr
, srcPacking
);
1995 else if (!ctx
->_ImageTransferState
&&
1997 srcType
== GL_UNSIGNED_BYTE
&&
1998 can_swizzle(baseInternalFormat
) &&
1999 can_swizzle(srcFormat
)) {
2003 /* dstmap - how to swizzle from RGBA to dst format:
2005 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
2006 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
2014 dstmap
[2] = ZERO
; /* ? */
2015 dstmap
[3] = ONE
; /* ? */
2017 _mesa_swizzle_ubyte_image(ctx
, dims
,
2022 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2023 dstRowStride
, dstImageOffsets
,
2024 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2029 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2032 srcWidth
, srcHeight
, srcDepth
,
2033 srcFormat
, srcType
, srcAddr
,
2035 const GLchan
*src
= tempImage
;
2036 GLint img
, row
, col
;
2039 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2040 for (img
= 0; img
< srcDepth
; img
++) {
2041 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2042 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2043 + dstYoffset
* dstRowStride
2044 + dstXoffset
* texelBytes
;
2045 for (row
= 0; row
< srcHeight
; row
++) {
2046 GLushort
*dstUS
= (GLushort
*) dstRow
;
2047 if (dstFormat
== MESA_FORMAT_AL88
) {
2048 for (col
= 0; col
< srcWidth
; col
++) {
2049 /* src[0] is luminance, src[1] is alpha */
2050 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2051 CHAN_TO_UBYTE(src
[0]) );
2056 for (col
= 0; col
< srcWidth
; col
++) {
2057 /* src[0] is luminance, src[1] is alpha */
2058 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2059 CHAN_TO_UBYTE(src
[0]) );
2063 dstRow
+= dstRowStride
;
2066 _mesa_free((void *) tempImage
);
2073 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2075 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2076 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2078 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2079 ASSERT(texelBytes
== 1);
2081 if (!ctx
->_ImageTransferState
&&
2082 !srcPacking
->SwapBytes
&&
2083 baseInternalFormat
== GL_RGB
&&
2084 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2085 /* simple memcpy path */
2086 memcpy_texture(ctx
, dims
,
2087 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2090 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2091 srcAddr
, srcPacking
);
2095 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2098 srcWidth
, srcHeight
, srcDepth
,
2099 srcFormat
, srcType
, srcAddr
,
2101 const GLchan
*src
= tempImage
;
2102 GLint img
, row
, col
;
2105 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2106 for (img
= 0; img
< srcDepth
; img
++) {
2107 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2108 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2109 + dstYoffset
* dstRowStride
2110 + dstXoffset
* texelBytes
;
2111 for (row
= 0; row
< srcHeight
; row
++) {
2112 for (col
= 0; col
< srcWidth
; col
++) {
2113 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2114 CHAN_TO_UBYTE(src
[GCOMP
]),
2115 CHAN_TO_UBYTE(src
[BCOMP
]) );
2118 dstRow
+= dstRowStride
;
2121 _mesa_free((void *) tempImage
);
2128 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2131 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2133 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2134 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2136 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2137 dstFormat
== MESA_FORMAT_L8
||
2138 dstFormat
== MESA_FORMAT_I8
);
2139 ASSERT(texelBytes
== 1);
2141 if (!ctx
->_ImageTransferState
&&
2142 !srcPacking
->SwapBytes
&&
2143 baseInternalFormat
== srcFormat
&&
2144 srcType
== GL_UNSIGNED_BYTE
) {
2145 /* simple memcpy path */
2146 memcpy_texture(ctx
, dims
,
2147 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2150 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2151 srcAddr
, srcPacking
);
2153 else if (!ctx
->_ImageTransferState
&&
2154 srcType
== GL_UNSIGNED_BYTE
&&
2155 can_swizzle(baseInternalFormat
) &&
2156 can_swizzle(srcFormat
)) {
2160 /* dstmap - how to swizzle from RGBA to dst format:
2162 if (dstFormat
== MESA_FORMAT_A8
) {
2168 dstmap
[1] = ZERO
; /* ? */
2169 dstmap
[2] = ZERO
; /* ? */
2170 dstmap
[3] = ONE
; /* ? */
2172 _mesa_swizzle_ubyte_image(ctx
, dims
,
2177 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2178 dstRowStride
, dstImageOffsets
,
2179 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2184 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2187 srcWidth
, srcHeight
, srcDepth
,
2188 srcFormat
, srcType
, srcAddr
,
2190 const GLchan
*src
= tempImage
;
2191 GLint img
, row
, col
;
2194 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2195 for (img
= 0; img
< srcDepth
; img
++) {
2196 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2197 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2198 + dstYoffset
* dstRowStride
2199 + dstXoffset
* texelBytes
;
2200 for (row
= 0; row
< srcHeight
; row
++) {
2201 for (col
= 0; col
< srcWidth
; col
++) {
2202 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2204 dstRow
+= dstRowStride
;
2208 _mesa_free((void *) tempImage
);
2216 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2218 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2220 (void) dims
; (void) baseInternalFormat
;
2221 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2222 ASSERT(texelBytes
== 1);
2223 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2225 if (!ctx
->_ImageTransferState
&&
2226 !srcPacking
->SwapBytes
&&
2227 srcFormat
== GL_COLOR_INDEX
&&
2228 srcType
== GL_UNSIGNED_BYTE
) {
2229 /* simple memcpy path */
2230 memcpy_texture(ctx
, dims
,
2231 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2234 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2235 srcAddr
, srcPacking
);
2240 for (img
= 0; img
< srcDepth
; img
++) {
2241 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2242 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2243 + dstYoffset
* dstRowStride
2244 + dstXoffset
* texelBytes
;
2245 for (row
= 0; row
< srcHeight
; row
++) {
2246 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2247 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2248 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2249 srcType
, src
, srcPacking
,
2250 ctx
->_ImageTransferState
);
2251 dstRow
+= dstRowStride
;
2260 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2263 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2265 const GLboolean littleEndian
= _mesa_little_endian();
2266 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2268 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2270 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2271 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2272 ASSERT(texelBytes
== 2);
2273 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2274 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2275 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2276 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2277 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2279 /* always just memcpy since no pixel transfer ops apply */
2280 memcpy_texture(ctx
, dims
,
2281 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2284 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2285 srcAddr
, srcPacking
);
2287 /* Check if we need byte swapping */
2288 /* XXX the logic here _might_ be wrong */
2289 if (srcPacking
->SwapBytes
^
2290 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2291 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2294 for (img
= 0; img
< srcDepth
; img
++) {
2295 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2296 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2297 + dstYoffset
* dstRowStride
2298 + dstXoffset
* texelBytes
;
2299 for (row
= 0; row
< srcHeight
; row
++) {
2300 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2301 dstRow
+= dstRowStride
;
2309 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2311 const GLboolean littleEndian
= _mesa_little_endian();
2312 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2314 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2315 ASSERT(texelBytes
== 2);
2316 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2317 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2318 (srcFormat
== GL_DUDV_ATI
));
2319 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2321 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2323 /* simple memcpy path */
2324 memcpy_texture(ctx
, dims
,
2325 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2328 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2329 srcAddr
, srcPacking
);
2331 else if (srcType
== GL_BYTE
) {
2335 /* dstmap - how to swizzle from RGBA to dst format:
2345 dstmap
[2] = ZERO
; /* ? */
2346 dstmap
[3] = ONE
; /* ? */
2348 _mesa_swizzle_ubyte_image(ctx
, dims
,
2349 GL_LUMINANCE_ALPHA
, /* hack */
2350 GL_UNSIGNED_BYTE
, /* hack */
2351 GL_LUMINANCE_ALPHA
, /* hack */
2353 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2354 dstRowStride
, dstImageOffsets
,
2355 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2359 /* general path - note this is defined for 2d textures only */
2360 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2361 const GLint srcStride
= _mesa_image_row_stride(srcPacking
,
2362 srcWidth
, srcFormat
, srcType
);
2363 GLbyte
*tempImage
, *dst
, *src
;
2366 tempImage
= (GLbyte
*) _mesa_malloc(srcWidth
* srcHeight
* srcDepth
2367 * components
* sizeof(GLbyte
));
2371 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2372 srcWidth
, srcHeight
,
2377 for (row
= 0; row
< srcHeight
; row
++) {
2378 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2379 dst
, srcFormat
, srcType
, src
,
2381 dst
+= srcWidth
* components
;
2386 dst
= (GLbyte
*) dstAddr
2387 + dstYoffset
* dstRowStride
2388 + dstXoffset
* texelBytes
;
2389 for (row
= 0; row
< srcHeight
; row
++) {
2390 memcpy(dst
, src
, srcWidth
* texelBytes
);
2391 dst
+= dstRowStride
;
2392 src
+= srcWidth
* texelBytes
;
2394 _mesa_free((void *) tempImage
);
2400 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or MESA_FORMAT_SIGNED_RGBA8888_REV
2403 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2405 const GLboolean littleEndian
= _mesa_little_endian();
2406 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2407 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2409 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2410 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2411 ASSERT(texelBytes
== 4);
2413 if (!ctx
->_ImageTransferState
&&
2414 !srcPacking
->SwapBytes
&&
2415 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
2416 baseInternalFormat
== GL_RGBA
&&
2417 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
2418 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
2419 /* simple memcpy path */
2420 memcpy_texture(ctx
, dims
,
2421 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2424 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2425 srcAddr
, srcPacking
);
2427 else if (!ctx
->_ImageTransferState
&&
2428 !srcPacking
->SwapBytes
&&
2429 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
2430 baseInternalFormat
== GL_RGBA
&&
2431 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
2432 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
2433 /* simple memcpy path */
2434 memcpy_texture(ctx
, dims
,
2435 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2438 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2439 srcAddr
, srcPacking
);
2441 else if (!ctx
->_ImageTransferState
&&
2442 (srcType
== GL_BYTE
) &&
2443 can_swizzle(baseInternalFormat
) &&
2444 can_swizzle(srcFormat
)) {
2448 /* dstmap - how to swizzle from RGBA to dst format:
2450 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
2451 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
2464 _mesa_swizzle_ubyte_image(ctx
, dims
,
2469 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2470 dstRowStride
, dstImageOffsets
,
2471 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2476 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2479 srcWidth
, srcHeight
, srcDepth
,
2480 srcFormat
, srcType
, srcAddr
,
2482 const GLfloat
*srcRow
= tempImage
;
2483 GLint img
, row
, col
;
2486 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2487 for (img
= 0; img
< srcDepth
; img
++) {
2488 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2489 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2490 + dstYoffset
* dstRowStride
2491 + dstXoffset
* texelBytes
;
2492 for (row
= 0; row
< srcHeight
; row
++) {
2493 GLuint
*dstUI
= (GLuint
*) dstRow
;
2494 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2495 for (col
= 0; col
< srcWidth
; col
++) {
2496 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2497 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2498 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2499 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2504 for (col
= 0; col
< srcWidth
; col
++) {
2505 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2506 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2507 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2508 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2512 dstRow
+= dstRowStride
;
2515 _mesa_free((void *) tempImage
);
2521 * Store a combined depth/stencil texture image.
2524 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2526 const GLfloat depthScale
= (GLfloat
) 0xffffff;
2527 const GLint srcRowStride
2528 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2532 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
2533 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2534 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2536 /* In case we only upload depth we need to preserve the stencil */
2537 if (srcFormat
== GL_DEPTH_COMPONENT
) {
2538 for (img
= 0; img
< srcDepth
; img
++) {
2539 GLuint
*dstRow
= (GLuint
*) dstAddr
2540 + dstImageOffsets
[dstZoffset
+ img
]
2541 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2544 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2545 srcWidth
, srcHeight
,
2548 for (row
= 0; row
< srcHeight
; row
++) {
2549 GLuint depth
[MAX_WIDTH
];
2551 _mesa_unpack_depth_span(ctx
, srcWidth
,
2552 GL_UNSIGNED_INT
, /* dst type */
2553 depth
, /* dst addr */
2555 srcType
, src
, srcPacking
);
2557 for (i
= 0; i
< srcWidth
; i
++)
2558 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2560 src
+= srcRowStride
;
2561 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2565 else if (ctx
->Pixel
.DepthScale
== 1.0f
&&
2566 ctx
->Pixel
.DepthBias
== 0.0f
&&
2567 !srcPacking
->SwapBytes
) {
2569 memcpy_texture(ctx
, dims
,
2570 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2573 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2574 srcAddr
, srcPacking
);
2578 const GLint srcRowStride
2579 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2583 for (img
= 0; img
< srcDepth
; img
++) {
2584 GLuint
*dstRow
= (GLuint
*) dstAddr
2585 + dstImageOffsets
[dstZoffset
+ img
]
2586 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2589 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2590 srcWidth
, srcHeight
,
2593 for (row
= 0; row
< srcHeight
; row
++) {
2594 GLubyte stencil
[MAX_WIDTH
];
2596 /* the 24 depth bits will be in the high position: */
2597 _mesa_unpack_depth_span(ctx
, srcWidth
,
2598 GL_UNSIGNED_INT_24_8_EXT
, /* dst type */
2599 dstRow
, /* dst addr */
2600 (GLuint
) depthScale
,
2601 srcType
, src
, srcPacking
);
2602 /* get the 8-bit stencil values */
2603 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2604 GL_UNSIGNED_BYTE
, /* dst type */
2605 stencil
, /* dst addr */
2606 srcType
, src
, srcPacking
,
2607 ctx
->_ImageTransferState
);
2608 /* merge stencil values into depth values */
2609 for (i
= 0; i
< srcWidth
; i
++)
2610 dstRow
[i
] |= stencil
[i
];
2612 src
+= srcRowStride
;
2613 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2622 * Store a combined depth/stencil texture image.
2625 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2627 const GLuint depthScale
= 0xffffff;
2628 const GLint srcRowStride
2629 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2633 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
2634 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2635 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2637 /* In case we only upload depth we need to preserve the stencil */
2638 if (srcFormat
== GL_DEPTH_COMPONENT
) {
2639 for (img
= 0; img
< srcDepth
; img
++) {
2640 GLuint
*dstRow
= (GLuint
*) dstAddr
2641 + dstImageOffsets
[dstZoffset
+ img
]
2642 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2645 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2646 srcWidth
, srcHeight
,
2649 for (row
= 0; row
< srcHeight
; row
++) {
2650 GLuint depth
[MAX_WIDTH
];
2652 _mesa_unpack_depth_span(ctx
, srcWidth
,
2653 GL_UNSIGNED_INT
, /* dst type */
2654 depth
, /* dst addr */
2656 srcType
, src
, srcPacking
);
2658 for (i
= 0; i
< srcWidth
; i
++)
2659 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
2661 src
+= srcRowStride
;
2662 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2667 for (img
= 0; img
< srcDepth
; img
++) {
2668 GLuint
*dstRow
= (GLuint
*) dstAddr
2669 + dstImageOffsets
[dstZoffset
+ img
]
2670 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2673 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2674 srcWidth
, srcHeight
,
2677 for (row
= 0; row
< srcHeight
; row
++) {
2678 GLubyte stencil
[MAX_WIDTH
];
2680 /* the 24 depth bits will be in the low position: */
2681 _mesa_unpack_depth_span(ctx
, srcWidth
,
2682 GL_UNSIGNED_INT
, /* dst type */
2683 dstRow
, /* dst addr */
2685 srcType
, src
, srcPacking
);
2686 /* get the 8-bit stencil values */
2687 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2688 GL_UNSIGNED_BYTE
, /* dst type */
2689 stencil
, /* dst addr */
2690 srcType
, src
, srcPacking
,
2691 ctx
->_ImageTransferState
);
2692 /* merge stencil values into depth values */
2693 for (i
= 0; i
< srcWidth
; i
++)
2694 dstRow
[i
] |= stencil
[i
] << 24;
2696 src
+= srcRowStride
;
2697 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2705 * Store an image in any of the formats:
2706 * _mesa_texformat_rgba_float32
2707 * _mesa_texformat_rgb_float32
2708 * _mesa_texformat_alpha_float32
2709 * _mesa_texformat_luminance_float32
2710 * _mesa_texformat_luminance_alpha_float32
2711 * _mesa_texformat_intensity_float32
2714 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
2716 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2717 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2718 const GLint components
= _mesa_components_in_format(baseFormat
);
2720 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
2721 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
2722 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
2723 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
2724 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
2725 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
2726 ASSERT(baseInternalFormat
== GL_RGBA
||
2727 baseInternalFormat
== GL_RGB
||
2728 baseInternalFormat
== GL_ALPHA
||
2729 baseInternalFormat
== GL_LUMINANCE
||
2730 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2731 baseInternalFormat
== GL_INTENSITY
);
2732 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
2734 if (!ctx
->_ImageTransferState
&&
2735 !srcPacking
->SwapBytes
&&
2736 baseInternalFormat
== srcFormat
&&
2737 srcType
== GL_FLOAT
) {
2738 /* simple memcpy path */
2739 memcpy_texture(ctx
, dims
,
2740 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2743 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2744 srcAddr
, srcPacking
);
2748 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2751 srcWidth
, srcHeight
, srcDepth
,
2752 srcFormat
, srcType
, srcAddr
,
2754 const GLfloat
*srcRow
= tempImage
;
2759 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2760 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
2761 for (img
= 0; img
< srcDepth
; img
++) {
2762 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2763 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2764 + dstYoffset
* dstRowStride
2765 + dstXoffset
* texelBytes
;
2766 for (row
= 0; row
< srcHeight
; row
++) {
2767 _mesa_memcpy(dstRow
, srcRow
, bytesPerRow
);
2768 dstRow
+= dstRowStride
;
2769 srcRow
+= srcWidth
* components
;
2773 _mesa_free((void *) tempImage
);
2780 * As above, but store 16-bit floats.
2783 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
2785 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2786 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2787 const GLint components
= _mesa_components_in_format(baseFormat
);
2789 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
2790 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
2791 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
2792 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
2793 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
2794 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
2795 ASSERT(baseInternalFormat
== GL_RGBA
||
2796 baseInternalFormat
== GL_RGB
||
2797 baseInternalFormat
== GL_ALPHA
||
2798 baseInternalFormat
== GL_LUMINANCE
||
2799 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
2800 baseInternalFormat
== GL_INTENSITY
);
2801 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
2803 if (!ctx
->_ImageTransferState
&&
2804 !srcPacking
->SwapBytes
&&
2805 baseInternalFormat
== srcFormat
&&
2806 srcType
== GL_HALF_FLOAT_ARB
) {
2807 /* simple memcpy path */
2808 memcpy_texture(ctx
, dims
,
2809 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2812 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2813 srcAddr
, srcPacking
);
2817 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2820 srcWidth
, srcHeight
, srcDepth
,
2821 srcFormat
, srcType
, srcAddr
,
2823 const GLfloat
*src
= tempImage
;
2827 _mesa_adjust_image_for_convolution(ctx
, dims
, &srcWidth
, &srcHeight
);
2828 for (img
= 0; img
< srcDepth
; img
++) {
2829 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2830 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2831 + dstYoffset
* dstRowStride
2832 + dstXoffset
* texelBytes
;
2833 for (row
= 0; row
< srcHeight
; row
++) {
2834 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
2836 for (i
= 0; i
< srcWidth
* components
; i
++) {
2837 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
2839 dstRow
+= dstRowStride
;
2840 src
+= srcWidth
* components
;
2844 _mesa_free((void *) tempImage
);
2850 #if FEATURE_EXT_texture_sRGB
2852 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
2854 gl_format newDstFormat
;
2857 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
2859 /* reuse normal rgb texstore code */
2860 newDstFormat
= MESA_FORMAT_RGB888
;
2862 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
2863 newDstFormat
, dstAddr
,
2864 dstXoffset
, dstYoffset
, dstZoffset
,
2865 dstRowStride
, dstImageOffsets
,
2866 srcWidth
, srcHeight
, srcDepth
,
2868 srcAddr
, srcPacking
);
2874 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
2876 gl_format newDstFormat
;
2879 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
2881 /* reuse normal rgba texstore code */
2882 newDstFormat
= MESA_FORMAT_RGBA8888
;
2883 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
2884 newDstFormat
, dstAddr
,
2885 dstXoffset
, dstYoffset
, dstZoffset
,
2886 dstRowStride
, dstImageOffsets
,
2887 srcWidth
, srcHeight
, srcDepth
,
2889 srcAddr
, srcPacking
);
2895 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
2897 gl_format newDstFormat
;
2900 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
2902 /* reuse normal rgba texstore code */
2903 newDstFormat
= MESA_FORMAT_ARGB8888
;
2905 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
2906 newDstFormat
, dstAddr
,
2907 dstXoffset
, dstYoffset
, dstZoffset
,
2908 dstRowStride
, dstImageOffsets
,
2909 srcWidth
, srcHeight
, srcDepth
,
2911 srcAddr
, srcPacking
);
2917 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
2919 gl_format newDstFormat
;
2922 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
2924 newDstFormat
= MESA_FORMAT_L8
;
2926 /* _mesa_textore_a8 handles luminance8 too */
2927 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
2928 newDstFormat
, dstAddr
,
2929 dstXoffset
, dstYoffset
, dstZoffset
,
2930 dstRowStride
, dstImageOffsets
,
2931 srcWidth
, srcHeight
, srcDepth
,
2933 srcAddr
, srcPacking
);
2939 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
2941 gl_format newDstFormat
;
2944 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
2946 /* reuse normal luminance/alpha texstore code */
2947 newDstFormat
= MESA_FORMAT_AL88
;
2949 k
= _mesa_texstore_al88(ctx
, dims
, baseInternalFormat
,
2950 newDstFormat
, dstAddr
,
2951 dstXoffset
, dstYoffset
, dstZoffset
,
2952 dstRowStride
, dstImageOffsets
,
2953 srcWidth
, srcHeight
, srcDepth
,
2955 srcAddr
, srcPacking
);
2959 #endif /* FEATURE_EXT_texture_sRGB */
2965 * Table mapping MESA_FORMAT_8 to _mesa_texstore_*()
2966 * XXX this is somewhat temporary.
2970 StoreTexImageFunc Store
;
2972 texstore_funcs
[MESA_FORMAT_COUNT
] =
2974 { MESA_FORMAT_NONE
, NULL
},
2975 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
2976 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
2977 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
2978 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
2979 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
2980 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
2981 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
2982 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
2983 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
2984 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
2985 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
2986 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
2987 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
2988 { MESA_FORMAT_AL88
, _mesa_texstore_al88
},
2989 { MESA_FORMAT_AL88_REV
, _mesa_texstore_al88
},
2990 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
2991 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
2992 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
2993 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
2994 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
2995 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
2996 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
2997 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
2998 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
2999 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
3000 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
3001 { MESA_FORMAT_S8
, NULL
/*_mesa_texstore_s8*/ },
3002 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
3003 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
3004 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
3005 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
3006 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
3007 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3008 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3009 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3010 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3011 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
3012 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
3013 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3014 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3015 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3016 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3017 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
3018 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
3019 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
3020 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
3021 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3022 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3023 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
3024 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
3025 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3026 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3027 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
3028 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
3029 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
3030 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
3031 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
3036 * Return the StoreTexImageFunc pointer to store an image in the given format.
3038 static StoreTexImageFunc
3039 _mesa_get_texstore_func(gl_format format
)
3043 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
3044 ASSERT(texstore_funcs
[i
].Name
== i
);
3047 ASSERT(texstore_funcs
[format
].Name
== format
);
3048 return texstore_funcs
[format
].Store
;
3053 * Store user data into texture memory.
3054 * Called via glTex[Sub]Image1/2/3D()
3057 _mesa_texstore(TEXSTORE_PARAMS
)
3059 StoreTexImageFunc storeImage
;
3062 storeImage
= _mesa_get_texstore_func(dstFormat
);
3066 success
= storeImage(ctx
, dims
, baseInternalFormat
,
3067 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3068 dstRowStride
, dstImageOffsets
,
3069 srcWidth
, srcHeight
, srcDepth
,
3070 srcFormat
, srcType
, srcAddr
, srcPacking
);
3076 * Check if an unpack PBO is active prior to fetching a texture image.
3077 * If so, do bounds checking and map the buffer into main memory.
3078 * Any errors detected will be recorded.
3079 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3082 _mesa_validate_pbo_teximage(GLcontext
*ctx
, GLuint dimensions
,
3083 GLsizei width
, GLsizei height
, GLsizei depth
,
3084 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3085 const struct gl_pixelstore_attrib
*unpack
,
3086 const char *funcName
)
3090 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
3094 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
3095 format
, type
, pixels
)) {
3096 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3100 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3101 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
3103 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3107 return ADD_POINTERS(buf
, pixels
);
3112 * Check if an unpack PBO is active prior to fetching a compressed texture
3114 * If so, do bounds checking and map the buffer into main memory.
3115 * Any errors detected will be recorded.
3116 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3119 _mesa_validate_pbo_compressed_teximage(GLcontext
*ctx
,
3120 GLsizei imageSize
, const GLvoid
*pixels
,
3121 const struct gl_pixelstore_attrib
*packing
,
3122 const char *funcName
)
3126 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
3127 /* not using a PBO - return pointer unchanged */
3130 if ((const GLubyte
*) pixels
+ imageSize
>
3131 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
3132 /* out of bounds read! */
3133 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3137 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3138 GL_READ_ONLY_ARB
, packing
->BufferObj
);
3140 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3144 return ADD_POINTERS(buf
, pixels
);
3149 * This function must be called after either of the validate_pbo_*_teximage()
3150 * functions. It unmaps the PBO buffer if it was mapped earlier.
3153 _mesa_unmap_teximage_pbo(GLcontext
*ctx
,
3154 const struct gl_pixelstore_attrib
*unpack
)
3156 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
3157 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3165 * Adaptor for fetching a GLchan texel from a float-valued texture.
3168 fetch_texel_float_to_chan(const struct gl_texture_image
*texImage
,
3169 GLint i
, GLint j
, GLint k
, GLchan
*texelOut
)
3172 GLenum baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
3174 ASSERT(texImage
->FetchTexelf
);
3175 texImage
->FetchTexelf(texImage
, i
, j
, k
, temp
);
3176 if (baseFormat
== GL_DEPTH_COMPONENT
||
3177 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
3178 /* just one channel */
3179 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[0], temp
[0]);
3183 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[0], temp
[0]);
3184 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[1], temp
[1]);
3185 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[2], temp
[2]);
3186 UNCLAMPED_FLOAT_TO_CHAN(texelOut
[3], temp
[3]);
3192 * Adaptor for fetching a float texel from a GLchan-valued texture.
3195 fetch_texel_chan_to_float(const struct gl_texture_image
*texImage
,
3196 GLint i
, GLint j
, GLint k
, GLfloat
*texelOut
)
3199 GLenum baseFormat
= _mesa_get_format_base_format(texImage
->TexFormat
);
3201 ASSERT(texImage
->FetchTexelc
);
3202 texImage
->FetchTexelc(texImage
, i
, j
, k
, temp
);
3203 if (baseFormat
== GL_DEPTH_COMPONENT
||
3204 baseFormat
== GL_DEPTH_STENCIL_EXT
) {
3205 /* just one channel */
3206 texelOut
[0] = CHAN_TO_FLOAT(temp
[0]);
3210 texelOut
[0] = CHAN_TO_FLOAT(temp
[0]);
3211 texelOut
[1] = CHAN_TO_FLOAT(temp
[1]);
3212 texelOut
[2] = CHAN_TO_FLOAT(temp
[2]);
3213 texelOut
[3] = CHAN_TO_FLOAT(temp
[3]);
3219 * Initialize the texture image's FetchTexelc and FetchTexelf methods.
3222 _mesa_set_fetch_functions(struct gl_texture_image
*texImage
, GLuint dims
)
3224 ASSERT(dims
== 1 || dims
== 2 || dims
== 3);
3225 ASSERT(texImage
->TexFormat
);
3227 texImage
->FetchTexelf
=
3228 _mesa_get_texel_fetch_func(texImage
->TexFormat
, dims
);
3230 /* now check if we need to use a float/chan adaptor */
3231 if (!texImage
->FetchTexelc
) {
3232 texImage
->FetchTexelc
= fetch_texel_float_to_chan
;
3234 else if (!texImage
->FetchTexelf
) {
3235 texImage
->FetchTexelf
= fetch_texel_chan_to_float
;
3239 ASSERT(texImage
->FetchTexelc
);
3240 ASSERT(texImage
->FetchTexelf
);
3245 compute_texture_size(GLcontext
*ctx
, struct gl_texture_image
*texImage
)
3247 texImage
->IsCompressed
=
3248 _mesa_is_format_compressed(texImage
->TexFormat
);
3250 if (texImage
->IsCompressed
) {
3251 texImage
->CompressedSize
=
3252 ctx
->Driver
.CompressedTextureSize(ctx
, texImage
->Width
,
3253 texImage
->Height
, texImage
->Depth
,
3254 texImage
->TexFormat
);
3257 /* non-compressed format */
3258 texImage
->CompressedSize
= 0;
3265 * This is the software fallback for Driver.TexImage1D()
3266 * and Driver.CopyTexImage1D().
3267 * \sa _mesa_store_teximage2d()
3268 * Note that the width may not be the actual texture width since it may
3269 * be changed by convolution w/ GL_REDUCE. The texImage->Width field will
3270 * have the actual texture size.
3273 _mesa_store_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3274 GLint internalFormat
,
3275 GLint width
, GLint border
,
3276 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3277 const struct gl_pixelstore_attrib
*packing
,
3278 struct gl_texture_object
*texObj
,
3279 struct gl_texture_image
*texImage
)
3285 = ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
3286 ASSERT(texImage
->TexFormat
);
3288 _mesa_set_fetch_functions(texImage
, 1);
3289 compute_texture_size(ctx
, texImage
);
3291 /* allocate memory */
3292 if (texImage
->IsCompressed
)
3293 sizeInBytes
= texImage
->CompressedSize
;
3295 sizeInBytes
= texImage
->Width
* _mesa_get_format_bytes(texImage
->TexFormat
);
3296 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3297 if (!texImage
->Data
) {
3298 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
3302 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
3303 pixels
, packing
, "glTexImage1D");
3305 /* Note: we check for a NULL image pointer here, _after_ we allocated
3306 * memory for the texture. That's what the GL spec calls for.
3311 const GLint dstRowStride
= 0;
3314 success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
3315 texImage
->TexFormat
,
3317 0, 0, 0, /* dstX/Y/Zoffset */
3319 texImage
->ImageOffsets
,
3321 format
, type
, pixels
, packing
);
3323 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
3327 _mesa_unmap_teximage_pbo(ctx
, packing
);
3332 * This is the software fallback for Driver.TexImage2D()
3333 * and Driver.CopyTexImage2D().
3335 * This function is oriented toward storing images in main memory, rather
3336 * than VRAM. Device driver's can easily plug in their own replacement.
3338 * Note: width and height may be pre-convolved dimensions, but
3339 * texImage->Width and texImage->Height will be post-convolved dimensions.
3342 _mesa_store_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3343 GLint internalFormat
,
3344 GLint width
, GLint height
, GLint border
,
3345 GLenum format
, GLenum type
, const void *pixels
,
3346 const struct gl_pixelstore_attrib
*packing
,
3347 struct gl_texture_object
*texObj
,
3348 struct gl_texture_image
*texImage
)
3350 GLint texelBytes
, sizeInBytes
;
3354 = ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
3355 ASSERT(texImage
->TexFormat
);
3357 _mesa_set_fetch_functions(texImage
, 2);
3358 compute_texture_size(ctx
, texImage
);
3360 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
3362 /* allocate memory */
3363 if (texImage
->IsCompressed
)
3364 sizeInBytes
= texImage
->CompressedSize
;
3366 sizeInBytes
= texImage
->Width
* texImage
->Height
* texelBytes
;
3367 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3368 if (!texImage
->Data
) {
3369 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
3373 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
3374 pixels
, packing
, "glTexImage2D");
3376 /* Note: we check for a NULL image pointer here, _after_ we allocated
3377 * memory for the texture. That's what the GL spec calls for.
3385 if (texImage
->IsCompressed
) {
3387 = _mesa_compressed_row_stride(texImage
->TexFormat
, width
);
3390 dstRowStride
= texImage
->RowStride
* texelBytes
;
3393 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
3394 texImage
->TexFormat
,
3396 0, 0, 0, /* dstX/Y/Zoffset */
3398 texImage
->ImageOffsets
,
3400 format
, type
, pixels
, packing
);
3403 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
3407 _mesa_unmap_teximage_pbo(ctx
, packing
);
3413 * This is the software fallback for Driver.TexImage3D()
3414 * and Driver.CopyTexImage3D().
3415 * \sa _mesa_store_teximage2d()
3418 _mesa_store_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3419 GLint internalFormat
,
3420 GLint width
, GLint height
, GLint depth
, GLint border
,
3421 GLenum format
, GLenum type
, const void *pixels
,
3422 const struct gl_pixelstore_attrib
*packing
,
3423 struct gl_texture_object
*texObj
,
3424 struct gl_texture_image
*texImage
)
3426 GLint texelBytes
, sizeInBytes
;
3430 = ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, format
, type
);
3431 ASSERT(texImage
->TexFormat
);
3433 _mesa_set_fetch_functions(texImage
, 3);
3434 compute_texture_size(ctx
, texImage
);
3436 texelBytes
= _mesa_get_format_bytes(texImage
->TexFormat
);
3438 /* allocate memory */
3439 if (texImage
->IsCompressed
)
3440 sizeInBytes
= texImage
->CompressedSize
;
3442 sizeInBytes
= width
* height
* depth
* texelBytes
;
3443 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
3444 if (!texImage
->Data
) {
3445 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
3449 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
3450 type
, pixels
, packing
, "glTexImage3D");
3452 /* Note: we check for a NULL image pointer here, _after_ we allocated
3453 * memory for the texture. That's what the GL spec calls for.
3461 if (texImage
->IsCompressed
) {
3463 = _mesa_compressed_row_stride(texImage
->TexFormat
, width
);
3466 dstRowStride
= texImage
->RowStride
* texelBytes
;
3469 success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
3470 texImage
->TexFormat
,
3472 0, 0, 0, /* dstX/Y/Zoffset */
3474 texImage
->ImageOffsets
,
3475 width
, height
, depth
,
3476 format
, type
, pixels
, packing
);
3478 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
3482 _mesa_unmap_teximage_pbo(ctx
, packing
);
3489 * This is the software fallback for Driver.TexSubImage1D()
3490 * and Driver.CopyTexSubImage1D().
3493 _mesa_store_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3494 GLint xoffset
, GLint width
,
3495 GLenum format
, GLenum type
, const void *pixels
,
3496 const struct gl_pixelstore_attrib
*packing
,
3497 struct gl_texture_object
*texObj
,
3498 struct gl_texture_image
*texImage
)
3500 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3501 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
3502 pixels
, packing
, "glTexSubImage1D");
3507 const GLint dstRowStride
= 0;
3510 success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
3511 texImage
->TexFormat
,
3513 xoffset
, 0, 0, /* offsets */
3515 texImage
->ImageOffsets
,
3517 format
, type
, pixels
, packing
);
3519 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
3523 _mesa_unmap_teximage_pbo(ctx
, packing
);
3529 * This is the software fallback for Driver.TexSubImage2D()
3530 * and Driver.CopyTexSubImage2D().
3533 _mesa_store_texsubimage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3534 GLint xoffset
, GLint yoffset
,
3535 GLint width
, GLint height
,
3536 GLenum format
, GLenum type
, const void *pixels
,
3537 const struct gl_pixelstore_attrib
*packing
,
3538 struct gl_texture_object
*texObj
,
3539 struct gl_texture_image
*texImage
)
3541 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3542 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
3543 pixels
, packing
, "glTexSubImage2D");
3548 GLint dstRowStride
= 0;
3551 if (texImage
->IsCompressed
) {
3552 dstRowStride
= _mesa_compressed_row_stride(texImage
->TexFormat
,
3556 dstRowStride
= texImage
->RowStride
*
3557 _mesa_get_format_bytes(texImage
->TexFormat
);
3560 success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
3561 texImage
->TexFormat
,
3563 xoffset
, yoffset
, 0,
3565 texImage
->ImageOffsets
,
3567 format
, type
, pixels
, packing
);
3569 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
3573 _mesa_unmap_teximage_pbo(ctx
, packing
);
3578 * This is the software fallback for Driver.TexSubImage3D().
3579 * and Driver.CopyTexSubImage3D().
3582 _mesa_store_texsubimage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3583 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3584 GLint width
, GLint height
, GLint depth
,
3585 GLenum format
, GLenum type
, const void *pixels
,
3586 const struct gl_pixelstore_attrib
*packing
,
3587 struct gl_texture_object
*texObj
,
3588 struct gl_texture_image
*texImage
)
3590 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3591 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
3592 type
, pixels
, packing
,
3601 if (texImage
->IsCompressed
) {
3602 dstRowStride
= _mesa_compressed_row_stride(texImage
->TexFormat
,
3606 dstRowStride
= texImage
->RowStride
*
3607 _mesa_get_format_bytes(texImage
->TexFormat
);
3610 success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
3611 texImage
->TexFormat
,
3613 xoffset
, yoffset
, zoffset
,
3615 texImage
->ImageOffsets
,
3616 width
, height
, depth
,
3617 format
, type
, pixels
, packing
);
3619 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
3623 _mesa_unmap_teximage_pbo(ctx
, packing
);
3628 * Fallback for Driver.CompressedTexImage1D()
3631 _mesa_store_compressed_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
3632 GLint internalFormat
,
3633 GLint width
, GLint border
,
3634 GLsizei imageSize
, const GLvoid
*data
,
3635 struct gl_texture_object
*texObj
,
3636 struct gl_texture_image
*texImage
)
3638 /* this space intentionally left blank */
3640 (void) target
; (void) level
;
3641 (void) internalFormat
;
3642 (void) width
; (void) border
;
3643 (void) imageSize
; (void) data
;
3651 * Fallback for Driver.CompressedTexImage2D()
3654 _mesa_store_compressed_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
3655 GLint internalFormat
,
3656 GLint width
, GLint height
, GLint border
,
3657 GLsizei imageSize
, const GLvoid
*data
,
3658 struct gl_texture_object
*texObj
,
3659 struct gl_texture_image
*texImage
)
3661 (void) width
; (void) height
; (void) border
;
3663 /* This is pretty simple, basically just do a memcpy without worrying
3664 * about the usual image unpacking or image transfer operations.
3668 ASSERT(texImage
->Width
> 0);
3669 ASSERT(texImage
->Height
> 0);
3670 ASSERT(texImage
->Depth
== 1);
3671 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
3674 = ctx
->Driver
.ChooseTextureFormat(ctx
, internalFormat
, 0, 0);
3675 ASSERT(texImage
->TexFormat
);
3677 _mesa_set_fetch_functions(texImage
, 2);
3678 compute_texture_size(ctx
, texImage
);
3680 /* allocate storage */
3681 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
3682 if (!texImage
->Data
) {
3683 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
3687 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
3689 "glCompressedTexImage2D");
3694 ASSERT(texImage
->CompressedSize
== (GLuint
) imageSize
);
3695 MEMCPY(texImage
->Data
, data
, imageSize
);
3697 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
3703 * Fallback for Driver.CompressedTexImage3D()
3706 _mesa_store_compressed_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
3707 GLint internalFormat
,
3708 GLint width
, GLint height
, GLint depth
,
3710 GLsizei imageSize
, const GLvoid
*data
,
3711 struct gl_texture_object
*texObj
,
3712 struct gl_texture_image
*texImage
)
3714 /* this space intentionally left blank */
3716 (void) target
; (void) level
;
3717 (void) internalFormat
;
3718 (void) width
; (void) height
; (void) depth
;
3720 (void) imageSize
; (void) data
;
3728 * Fallback for Driver.CompressedTexSubImage1D()
3731 _mesa_store_compressed_texsubimage1d(GLcontext
*ctx
, GLenum target
,
3733 GLint xoffset
, GLsizei width
,
3735 GLsizei imageSize
, const GLvoid
*data
,
3736 struct gl_texture_object
*texObj
,
3737 struct gl_texture_image
*texImage
)
3739 /* there are no compressed 1D texture formats yet */
3741 (void) target
; (void) level
;
3742 (void) xoffset
; (void) width
;
3744 (void) imageSize
; (void) data
;
3751 * Fallback for Driver.CompressedTexSubImage2D()
3754 _mesa_store_compressed_texsubimage2d(GLcontext
*ctx
, GLenum target
,
3756 GLint xoffset
, GLint yoffset
,
3757 GLsizei width
, GLsizei height
,
3759 GLsizei imageSize
, const GLvoid
*data
,
3760 struct gl_texture_object
*texObj
,
3761 struct gl_texture_image
*texImage
)
3763 GLint bytesPerRow
, destRowStride
, srcRowStride
;
3767 const gl_format texFormat
= texImage
->TexFormat
;
3771 /* these should have been caught sooner */
3772 ASSERT((width
& 3) == 0 || width
== 2 || width
== 1);
3773 ASSERT((height
& 3) == 0 || height
== 2 || height
== 1);
3774 ASSERT((xoffset
& 3) == 0);
3775 ASSERT((yoffset
& 3) == 0);
3777 /* get pointer to src pixels (may be in a pbo which we'll map here) */
3778 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
3780 "glCompressedTexSubImage2D");
3784 srcRowStride
= _mesa_compressed_row_stride(texFormat
, width
);
3785 src
= (const GLubyte
*) data
;
3787 destRowStride
= _mesa_compressed_row_stride(texFormat
, texImage
->Width
);
3788 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
3791 (GLubyte
*) texImage
->Data
);
3793 bytesPerRow
= srcRowStride
;
3796 for (i
= 0; i
< rows
; i
++) {
3797 MEMCPY(dest
, src
, bytesPerRow
);
3798 dest
+= destRowStride
;
3799 src
+= srcRowStride
;
3802 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
3807 * Fallback for Driver.CompressedTexSubImage3D()
3810 _mesa_store_compressed_texsubimage3d(GLcontext
*ctx
, GLenum target
,
3812 GLint xoffset
, GLint yoffset
, GLint zoffset
,
3813 GLsizei width
, GLsizei height
, GLsizei depth
,
3815 GLsizei imageSize
, const GLvoid
*data
,
3816 struct gl_texture_object
*texObj
,
3817 struct gl_texture_image
*texImage
)
3819 /* there are no compressed 3D texture formats yet */
3821 (void) target
; (void) level
;
3822 (void) xoffset
; (void) yoffset
; (void) zoffset
;
3823 (void) width
; (void) height
; (void) depth
;
3825 (void) imageSize
; (void) data
;