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, etc)
50 * These functions can handle most everything, including processing full
51 * images and sub-images.
56 #include "bufferobj.h"
62 #include "texcompress.h"
63 #include "texcompress_fxt1.h"
64 #include "texcompress_s3tc.h"
77 * Texture image storage function.
79 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
83 * Return GL_TRUE if the given image format is one that be converted
84 * to another format by swizzling.
87 can_swizzle(GLenum logicalBaseFormat
)
89 switch (logicalBaseFormat
) {
92 case GL_LUMINANCE_ALPHA
:
128 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
129 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
130 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
131 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
134 static const struct {
137 GLubyte from_rgba
[6];
138 } mappings
[MAX_IDX
] =
148 MAP4(ZERO
, ZERO
, ZERO
, 0),
178 MAP4(0, ZERO
, ZERO
, ONE
),
184 MAP4(ZERO
, 0, ZERO
, ONE
),
190 MAP4(ZERO
, ZERO
, 0, ONE
),
214 MAP4(0, 1, ZERO
, ONE
),
222 * Convert a GL image format enum to an IDX_* value (see above).
225 get_map_idx(GLenum value
)
228 case GL_LUMINANCE
: return IDX_LUMINANCE
;
229 case GL_ALPHA
: return IDX_ALPHA
;
230 case GL_INTENSITY
: return IDX_INTENSITY
;
231 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
232 case GL_RGB
: return IDX_RGB
;
233 case GL_RGBA
: return IDX_RGBA
;
234 case GL_RED
: return IDX_RED
;
235 case GL_GREEN
: return IDX_GREEN
;
236 case GL_BLUE
: return IDX_BLUE
;
237 case GL_BGR
: return IDX_BGR
;
238 case GL_BGRA
: return IDX_BGRA
;
239 case GL_ABGR_EXT
: return IDX_ABGR
;
240 case GL_RG
: return IDX_RG
;
242 _mesa_problem(NULL
, "Unexpected inFormat");
249 * When promoting texture formats (see below) we need to compute the
250 * mapping of dest components back to source components.
251 * This function does that.
252 * \param inFormat the incoming format of the texture
253 * \param outFormat the final texture format
254 * \return map[6] a full 6-component map
257 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
260 const int inFmt
= get_map_idx(inFormat
);
261 const int outFmt
= get_map_idx(outFormat
);
262 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
263 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
266 for (i
= 0; i
< 4; i
++)
267 map
[i
] = in2rgba
[rgba2out
[i
]];
273 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
274 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
275 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
287 * Make a temporary (color) texture image with GLfloat components.
288 * Apply all needed pixel unpacking and pixel transfer operations.
289 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
290 * Suppose the user specifies GL_LUMINANCE as the internal texture format
291 * but the graphics hardware doesn't support luminance textures. So, we might
292 * use an RGB hardware format instead.
293 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
295 * \param ctx the rendering context
296 * \param dims image dimensions: 1, 2 or 3
297 * \param logicalBaseFormat basic texture derived from the user's
298 * internal texture format value
299 * \param textureBaseFormat the actual basic format of the texture
300 * \param srcWidth source image width
301 * \param srcHeight source image height
302 * \param srcDepth source image depth
303 * \param srcFormat source image format
304 * \param srcType source image type
305 * \param srcAddr source image address
306 * \param srcPacking source image pixel packing
307 * \return resulting image with format = textureBaseFormat and type = GLfloat.
310 make_temp_float_image(GLcontext
*ctx
, GLuint dims
,
311 GLenum logicalBaseFormat
,
312 GLenum textureBaseFormat
,
313 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
314 GLenum srcFormat
, GLenum srcType
,
315 const GLvoid
*srcAddr
,
316 const struct gl_pixelstore_attrib
*srcPacking
)
318 GLuint transferOps
= ctx
->_ImageTransferState
;
320 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
321 const GLint srcStride
=
322 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
326 ASSERT(dims
>= 1 && dims
<= 3);
328 ASSERT(logicalBaseFormat
== GL_RGBA
||
329 logicalBaseFormat
== GL_RGB
||
330 logicalBaseFormat
== GL_RG
||
331 logicalBaseFormat
== GL_RED
||
332 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
333 logicalBaseFormat
== GL_LUMINANCE
||
334 logicalBaseFormat
== GL_ALPHA
||
335 logicalBaseFormat
== GL_INTENSITY
||
336 logicalBaseFormat
== GL_COLOR_INDEX
||
337 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
339 ASSERT(textureBaseFormat
== GL_RGBA
||
340 textureBaseFormat
== GL_RGB
||
341 textureBaseFormat
== GL_RG
||
342 textureBaseFormat
== GL_RED
||
343 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
344 textureBaseFormat
== GL_LUMINANCE
||
345 textureBaseFormat
== GL_ALPHA
||
346 textureBaseFormat
== GL_INTENSITY
||
347 textureBaseFormat
== GL_COLOR_INDEX
||
348 textureBaseFormat
== GL_DEPTH_COMPONENT
);
350 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
351 * components
* sizeof(GLfloat
));
356 for (img
= 0; img
< srcDepth
; img
++) {
358 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
362 for (row
= 0; row
< srcHeight
; row
++) {
363 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
364 dst
, srcFormat
, srcType
, src
,
365 srcPacking
, transferOps
);
366 dst
+= srcWidth
* components
;
371 if (logicalBaseFormat
!= textureBaseFormat
) {
373 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
374 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
379 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
380 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
381 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
383 /* The actual texture format should have at least as many components
384 * as the logical texture format.
386 ASSERT(texComponents
>= logComponents
);
388 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
389 * texComponents
* sizeof(GLfloat
));
395 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
397 n
= srcWidth
* srcHeight
* srcDepth
;
398 for (i
= 0; i
< n
; i
++) {
400 for (k
= 0; k
< texComponents
; k
++) {
403 newImage
[i
* texComponents
+ k
] = 0.0F
;
405 newImage
[i
* texComponents
+ k
] = 1.0F
;
407 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
412 tempImage
= newImage
;
420 * Make a temporary (color) texture image with GLchan components.
421 * Apply all needed pixel unpacking and pixel transfer operations.
422 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
423 * Suppose the user specifies GL_LUMINANCE as the internal texture format
424 * but the graphics hardware doesn't support luminance textures. So, we might
425 * use an RGB hardware format instead.
426 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
428 * \param ctx the rendering context
429 * \param dims image dimensions: 1, 2 or 3
430 * \param logicalBaseFormat basic texture derived from the user's
431 * internal texture format value
432 * \param textureBaseFormat the actual basic format of the texture
433 * \param srcWidth source image width
434 * \param srcHeight source image height
435 * \param srcDepth source image depth
436 * \param srcFormat source image format
437 * \param srcType source image type
438 * \param srcAddr source image address
439 * \param srcPacking source image pixel packing
440 * \return resulting image with format = textureBaseFormat and type = GLchan.
443 _mesa_make_temp_chan_image(GLcontext
*ctx
, GLuint dims
,
444 GLenum logicalBaseFormat
,
445 GLenum textureBaseFormat
,
446 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
447 GLenum srcFormat
, GLenum srcType
,
448 const GLvoid
*srcAddr
,
449 const struct gl_pixelstore_attrib
*srcPacking
)
451 GLuint transferOps
= ctx
->_ImageTransferState
;
452 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
454 GLchan
*tempImage
, *dst
;
456 ASSERT(dims
>= 1 && dims
<= 3);
458 ASSERT(logicalBaseFormat
== GL_RGBA
||
459 logicalBaseFormat
== GL_RGB
||
460 logicalBaseFormat
== GL_RG
||
461 logicalBaseFormat
== GL_RED
||
462 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
463 logicalBaseFormat
== GL_LUMINANCE
||
464 logicalBaseFormat
== GL_ALPHA
||
465 logicalBaseFormat
== GL_INTENSITY
);
467 ASSERT(textureBaseFormat
== GL_RGBA
||
468 textureBaseFormat
== GL_RGB
||
469 textureBaseFormat
== GL_RG
||
470 textureBaseFormat
== GL_RED
||
471 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
472 textureBaseFormat
== GL_LUMINANCE
||
473 textureBaseFormat
== GL_ALPHA
||
474 textureBaseFormat
== GL_INTENSITY
);
476 /* unpack and transfer the source image */
477 tempImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
478 * components
* sizeof(GLchan
));
484 for (img
= 0; img
< srcDepth
; img
++) {
485 const GLint srcStride
=
486 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
488 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
492 for (row
= 0; row
< srcHeight
; row
++) {
493 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
494 srcFormat
, srcType
, src
, srcPacking
,
496 dst
+= srcWidth
* components
;
501 if (logicalBaseFormat
!= textureBaseFormat
) {
502 /* one more conversion step */
503 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
504 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
509 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
510 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
511 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
513 /* The actual texture format should have at least as many components
514 * as the logical texture format.
516 ASSERT(texComponents
>= logComponents
);
518 newImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
519 * texComponents
* sizeof(GLchan
));
525 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
527 n
= srcWidth
* srcHeight
* srcDepth
;
528 for (i
= 0; i
< n
; i
++) {
530 for (k
= 0; k
< texComponents
; k
++) {
533 newImage
[i
* texComponents
+ k
] = 0;
535 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
537 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
542 tempImage
= newImage
;
550 * Copy GLubyte pixels from <src> to <dst> with swizzling.
551 * \param dst destination pixels
552 * \param dstComponents number of color components in destination pixels
553 * \param src source pixels
554 * \param srcComponents number of color components in source pixels
555 * \param map the swizzle mapping. map[X] says where to find the X component
556 * in the source image's pixels. For example, if the source image
557 * is GL_BGRA and X = red, map[0] yields 2.
558 * \param count number of pixels to copy/swizzle.
561 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
562 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
564 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
567 for (i = 0; i < count; i++) { \
569 if (srcComps == 4) { \
570 COPY_4UBV(tmp, src); \
573 for (j = 0; j < srcComps; j++) { \
578 for (j = 0; j < dstComps; j++) { \
579 dst[j] = tmp[map[j]]; \
590 ASSERT(srcComponents
<= 4);
591 ASSERT(dstComponents
<= 4);
593 switch (dstComponents
) {
595 switch (srcComponents
) {
597 SWZ_CPY(dst
, src
, count
, 4, 4);
600 SWZ_CPY(dst
, src
, count
, 4, 3);
603 SWZ_CPY(dst
, src
, count
, 4, 2);
606 SWZ_CPY(dst
, src
, count
, 4, 1);
613 switch (srcComponents
) {
615 SWZ_CPY(dst
, src
, count
, 3, 4);
618 SWZ_CPY(dst
, src
, count
, 3, 3);
621 SWZ_CPY(dst
, src
, count
, 3, 2);
624 SWZ_CPY(dst
, src
, count
, 3, 1);
631 switch (srcComponents
) {
633 SWZ_CPY(dst
, src
, count
, 2, 4);
636 SWZ_CPY(dst
, src
, count
, 2, 3);
639 SWZ_CPY(dst
, src
, count
, 2, 2);
642 SWZ_CPY(dst
, src
, count
, 2, 1);
649 switch (srcComponents
) {
651 SWZ_CPY(dst
, src
, count
, 1, 4);
654 SWZ_CPY(dst
, src
, count
, 1, 3);
657 SWZ_CPY(dst
, src
, count
, 1, 2);
660 SWZ_CPY(dst
, src
, count
, 1, 1);
674 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
675 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
679 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
680 * mapping array depending on endianness.
682 static const GLubyte
*
683 type_mapping( GLenum srcType
)
687 case GL_UNSIGNED_BYTE
:
689 case GL_UNSIGNED_INT_8_8_8_8
:
690 return _mesa_little_endian() ? map_3210
: map_identity
;
691 case GL_UNSIGNED_INT_8_8_8_8_REV
:
692 return _mesa_little_endian() ? map_identity
: map_3210
;
700 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
701 * mapping array depending on pixelstore byte swapping state.
703 static const GLubyte
*
704 byteswap_mapping( GLboolean swapBytes
,
712 case GL_UNSIGNED_BYTE
:
714 case GL_UNSIGNED_INT_8_8_8_8
:
715 case GL_UNSIGNED_INT_8_8_8_8_REV
:
725 * Transfer a GLubyte texture image with component swizzling.
728 _mesa_swizzle_ubyte_image(GLcontext
*ctx
,
733 GLenum baseInternalFormat
,
735 const GLubyte
*rgba2dst
,
736 GLuint dstComponents
,
739 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
741 const GLuint
*dstImageOffsets
,
743 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
744 const GLvoid
*srcAddr
,
745 const struct gl_pixelstore_attrib
*srcPacking
)
747 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
748 const GLubyte
*srctype2ubyte
, *swap
;
749 GLubyte map
[4], src2base
[6], base2rgba
[6];
751 const GLint srcRowStride
=
752 _mesa_image_row_stride(srcPacking
, srcWidth
,
753 srcFormat
, GL_UNSIGNED_BYTE
);
754 const GLint srcImageStride
755 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
757 const GLubyte
*srcImage
758 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
759 srcWidth
, srcHeight
, srcFormat
,
760 GL_UNSIGNED_BYTE
, 0, 0, 0);
764 /* Translate from src->baseInternal->GL_RGBA->dst. This will
765 * correctly deal with RGBA->RGB->RGBA conversions where the final
766 * A value must be 0xff regardless of the incoming alpha values.
768 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
769 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
770 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
771 srctype2ubyte
= type_mapping(srcType
);
774 for (i
= 0; i
< 4; i
++)
775 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
777 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
779 if (srcComponents
== dstComponents
&&
780 srcRowStride
== dstRowStride
&&
781 srcRowStride
== srcWidth
* srcComponents
&&
783 /* 1 and 2D images only */
784 GLubyte
*dstImage
= (GLubyte
*) dstAddr
785 + dstYoffset
* dstRowStride
786 + dstXoffset
* dstComponents
;
787 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
788 srcWidth
* srcHeight
);
792 for (img
= 0; img
< srcDepth
; img
++) {
793 const GLubyte
*srcRow
= srcImage
;
794 GLubyte
*dstRow
= (GLubyte
*) dstAddr
795 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
796 + dstYoffset
* dstRowStride
797 + dstXoffset
* dstComponents
;
798 for (row
= 0; row
< srcHeight
; row
++) {
799 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
800 dstRow
+= dstRowStride
;
801 srcRow
+= srcRowStride
;
803 srcImage
+= srcImageStride
;
810 * Teximage storage routine for when a simple memcpy will do.
811 * No pixel transfer operations or special texel encodings allowed.
812 * 1D, 2D and 3D images supported.
815 memcpy_texture(GLcontext
*ctx
,
819 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
821 const GLuint
*dstImageOffsets
,
822 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
823 GLenum srcFormat
, GLenum srcType
,
824 const GLvoid
*srcAddr
,
825 const struct gl_pixelstore_attrib
*srcPacking
)
827 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
829 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
830 srcWidth
, srcHeight
, srcFormat
, srcType
);
831 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
832 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
833 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
834 const GLint bytesPerRow
= srcWidth
* texelBytes
;
837 /* XXX update/re-enable for dstImageOffsets array */
838 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
839 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
840 GLubyte
*dstImage
= (GLubyte
*) dstAddr
841 + dstZoffset
* dstImageStride
842 + dstYoffset
* dstRowStride
843 + dstXoffset
* texelBytes
;
845 if (dstRowStride
== srcRowStride
&&
846 dstRowStride
== bytesPerRow
&&
847 ((dstImageStride
== srcImageStride
&&
848 dstImageStride
== bytesPerImage
) ||
851 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
856 for (img
= 0; img
< srcDepth
; img
++) {
857 const GLubyte
*srcRow
= srcImage
;
858 GLubyte
*dstRow
= dstImage
;
859 for (row
= 0; row
< srcHeight
; row
++) {
860 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
861 dstRow
+= dstRowStride
;
862 srcRow
+= srcRowStride
;
864 srcImage
+= srcImageStride
;
865 dstImage
+= dstImageStride
;
871 for (img
= 0; img
< srcDepth
; img
++) {
872 const GLubyte
*srcRow
= srcImage
;
873 GLubyte
*dstRow
= (GLubyte
*) dstAddr
874 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
875 + dstYoffset
* dstRowStride
876 + dstXoffset
* texelBytes
;
877 for (row
= 0; row
< srcHeight
; row
++) {
878 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
879 dstRow
+= dstRowStride
;
880 srcRow
+= srcRowStride
;
882 srcImage
+= srcImageStride
;
889 * Store a 32-bit integer depth component texture image.
892 _mesa_texstore_z32(TEXSTORE_PARAMS
)
894 const GLuint depthScale
= 0xffffffff;
895 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
897 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
898 ASSERT(texelBytes
== sizeof(GLuint
));
900 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
901 ctx
->Pixel
.DepthBias
== 0.0f
&&
902 !srcPacking
->SwapBytes
&&
903 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
904 srcFormat
== GL_DEPTH_COMPONENT
&&
905 srcType
== GL_UNSIGNED_INT
) {
906 /* simple memcpy path */
907 memcpy_texture(ctx
, dims
,
908 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
911 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
912 srcAddr
, srcPacking
);
917 for (img
= 0; img
< srcDepth
; img
++) {
918 GLubyte
*dstRow
= (GLubyte
*) dstAddr
919 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
920 + dstYoffset
* dstRowStride
921 + dstXoffset
* texelBytes
;
922 for (row
= 0; row
< srcHeight
; row
++) {
923 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
924 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
925 _mesa_unpack_depth_span(ctx
, srcWidth
,
926 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
927 depthScale
, srcType
, src
, srcPacking
);
928 dstRow
+= dstRowStride
;
937 * Store a 24-bit integer depth component texture image.
940 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
942 const GLuint depthScale
= 0xffffff;
943 const GLuint texelBytes
= 4;
946 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
951 for (img
= 0; img
< srcDepth
; img
++) {
952 GLubyte
*dstRow
= (GLubyte
*) dstAddr
953 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
954 + dstYoffset
* dstRowStride
955 + dstXoffset
* texelBytes
;
956 for (row
= 0; row
< srcHeight
; row
++) {
957 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
958 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
959 _mesa_unpack_depth_span(ctx
, srcWidth
,
960 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
961 depthScale
, srcType
, src
, srcPacking
);
962 dstRow
+= dstRowStride
;
971 * Store a 24-bit integer depth component texture image.
974 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
976 const GLuint depthScale
= 0xffffff;
977 const GLuint texelBytes
= 4;
980 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
985 for (img
= 0; img
< srcDepth
; img
++) {
986 GLubyte
*dstRow
= (GLubyte
*) dstAddr
987 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
988 + dstYoffset
* dstRowStride
989 + dstXoffset
* texelBytes
;
990 for (row
= 0; row
< srcHeight
; row
++) {
991 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
992 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
993 GLuint
*dst
= (GLuint
*) dstRow
;
995 _mesa_unpack_depth_span(ctx
, srcWidth
,
996 GL_UNSIGNED_INT
, dst
,
997 depthScale
, srcType
, src
, srcPacking
);
998 for (i
= 0; i
< srcWidth
; i
++)
1000 dstRow
+= dstRowStride
;
1009 * Store a 16-bit integer depth component texture image.
1012 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1014 const GLuint depthScale
= 0xffff;
1015 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1017 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1018 ASSERT(texelBytes
== sizeof(GLushort
));
1020 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1021 ctx
->Pixel
.DepthBias
== 0.0f
&&
1022 !srcPacking
->SwapBytes
&&
1023 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1024 srcFormat
== GL_DEPTH_COMPONENT
&&
1025 srcType
== GL_UNSIGNED_SHORT
) {
1026 /* simple memcpy path */
1027 memcpy_texture(ctx
, dims
,
1028 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1031 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1032 srcAddr
, srcPacking
);
1037 for (img
= 0; img
< srcDepth
; img
++) {
1038 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1039 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1040 + dstYoffset
* dstRowStride
1041 + dstXoffset
* texelBytes
;
1042 for (row
= 0; row
< srcHeight
; row
++) {
1043 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1044 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1045 GLushort
*dst16
= (GLushort
*) dstRow
;
1046 _mesa_unpack_depth_span(ctx
, srcWidth
,
1047 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1048 srcType
, src
, srcPacking
);
1049 dstRow
+= dstRowStride
;
1058 * Store an rgb565 or rgb565_rev texture image.
1061 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1063 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1064 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1066 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1067 dstFormat
== MESA_FORMAT_RGB565_REV
);
1068 ASSERT(texelBytes
== 2);
1070 if (!ctx
->_ImageTransferState
&&
1071 !srcPacking
->SwapBytes
&&
1072 dstFormat
== MESA_FORMAT_RGB565
&&
1073 baseInternalFormat
== GL_RGB
&&
1074 srcFormat
== GL_RGB
&&
1075 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1076 /* simple memcpy path */
1077 memcpy_texture(ctx
, dims
,
1078 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1081 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1082 srcAddr
, srcPacking
);
1084 else if (!ctx
->_ImageTransferState
&&
1085 !srcPacking
->SwapBytes
&&
1086 baseInternalFormat
== GL_RGB
&&
1087 srcFormat
== GL_RGB
&&
1088 srcType
== GL_UNSIGNED_BYTE
&&
1090 /* do optimized tex store */
1091 const GLint srcRowStride
=
1092 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1093 const GLubyte
*src
= (const GLubyte
*)
1094 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1095 srcFormat
, srcType
, 0, 0, 0);
1096 GLubyte
*dst
= (GLubyte
*) dstAddr
1097 + dstYoffset
* dstRowStride
1098 + dstXoffset
* texelBytes
;
1100 for (row
= 0; row
< srcHeight
; row
++) {
1101 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1102 GLushort
*dstUS
= (GLushort
*) dst
;
1103 /* check for byteswapped format */
1104 if (dstFormat
== MESA_FORMAT_RGB565
) {
1105 for (col
= 0; col
< srcWidth
; col
++) {
1106 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1111 for (col
= 0; col
< srcWidth
; col
++) {
1112 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1116 dst
+= dstRowStride
;
1117 src
+= srcRowStride
;
1122 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1125 srcWidth
, srcHeight
, srcDepth
,
1126 srcFormat
, srcType
, srcAddr
,
1128 const GLchan
*src
= tempImage
;
1129 GLint img
, row
, col
;
1132 for (img
= 0; img
< srcDepth
; img
++) {
1133 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1134 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1135 + dstYoffset
* dstRowStride
1136 + dstXoffset
* texelBytes
;
1137 for (row
= 0; row
< srcHeight
; row
++) {
1138 GLushort
*dstUS
= (GLushort
*) dstRow
;
1139 /* check for byteswapped format */
1140 if (dstFormat
== MESA_FORMAT_RGB565
) {
1141 for (col
= 0; col
< srcWidth
; col
++) {
1142 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1143 CHAN_TO_UBYTE(src
[GCOMP
]),
1144 CHAN_TO_UBYTE(src
[BCOMP
]) );
1149 for (col
= 0; col
< srcWidth
; col
++) {
1150 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1151 CHAN_TO_UBYTE(src
[GCOMP
]),
1152 CHAN_TO_UBYTE(src
[BCOMP
]) );
1156 dstRow
+= dstRowStride
;
1159 free((void *) tempImage
);
1166 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1169 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1171 const GLboolean littleEndian
= _mesa_little_endian();
1172 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1173 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1175 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1176 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1177 ASSERT(texelBytes
== 4);
1179 if (!ctx
->_ImageTransferState
&&
1180 !srcPacking
->SwapBytes
&&
1181 dstFormat
== MESA_FORMAT_RGBA8888
&&
1182 baseInternalFormat
== GL_RGBA
&&
1183 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1184 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1185 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1186 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1187 /* simple memcpy path */
1188 memcpy_texture(ctx
, dims
,
1189 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1192 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1193 srcAddr
, srcPacking
);
1195 else if (!ctx
->_ImageTransferState
&&
1196 !srcPacking
->SwapBytes
&&
1197 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1198 baseInternalFormat
== GL_RGBA
&&
1199 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1200 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1201 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1202 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1203 /* simple memcpy path */
1204 memcpy_texture(ctx
, dims
,
1205 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1208 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1209 srcAddr
, srcPacking
);
1211 else if (!ctx
->_ImageTransferState
&&
1212 (srcType
== GL_UNSIGNED_BYTE
||
1213 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1214 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1215 can_swizzle(baseInternalFormat
) &&
1216 can_swizzle(srcFormat
)) {
1220 /* dstmap - how to swizzle from RGBA to dst format:
1222 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1223 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1236 _mesa_swizzle_ubyte_image(ctx
, dims
,
1241 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1242 dstRowStride
, dstImageOffsets
,
1243 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1248 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1251 srcWidth
, srcHeight
, srcDepth
,
1252 srcFormat
, srcType
, srcAddr
,
1254 const GLchan
*src
= tempImage
;
1255 GLint img
, row
, col
;
1258 for (img
= 0; img
< srcDepth
; img
++) {
1259 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1260 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1261 + dstYoffset
* dstRowStride
1262 + dstXoffset
* texelBytes
;
1263 for (row
= 0; row
< srcHeight
; row
++) {
1264 GLuint
*dstUI
= (GLuint
*) dstRow
;
1265 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1266 for (col
= 0; col
< srcWidth
; col
++) {
1267 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1268 CHAN_TO_UBYTE(src
[GCOMP
]),
1269 CHAN_TO_UBYTE(src
[BCOMP
]),
1270 CHAN_TO_UBYTE(src
[ACOMP
]) );
1275 for (col
= 0; col
< srcWidth
; col
++) {
1276 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1277 CHAN_TO_UBYTE(src
[GCOMP
]),
1278 CHAN_TO_UBYTE(src
[BCOMP
]),
1279 CHAN_TO_UBYTE(src
[ACOMP
]) );
1283 dstRow
+= dstRowStride
;
1286 free((void *) tempImage
);
1293 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1295 const GLboolean littleEndian
= _mesa_little_endian();
1296 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1297 const GLenum baseFormat
= GL_RGBA
;
1299 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1300 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1301 dstFormat
== MESA_FORMAT_XRGB8888
||
1302 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1303 ASSERT(texelBytes
== 4);
1305 if (!ctx
->_ImageTransferState
&&
1306 !srcPacking
->SwapBytes
&&
1307 (dstFormat
== MESA_FORMAT_ARGB8888
||
1308 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1309 baseInternalFormat
== GL_RGBA
&&
1310 srcFormat
== GL_BGRA
&&
1311 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1312 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1313 /* simple memcpy path (little endian) */
1314 memcpy_texture(ctx
, dims
,
1315 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1318 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1319 srcAddr
, srcPacking
);
1321 else if (!ctx
->_ImageTransferState
&&
1322 !srcPacking
->SwapBytes
&&
1323 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1324 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1325 baseInternalFormat
== GL_RGBA
&&
1326 srcFormat
== GL_BGRA
&&
1327 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1328 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1329 /* simple memcpy path (big endian) */
1330 memcpy_texture(ctx
, dims
,
1331 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1334 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1335 srcAddr
, srcPacking
);
1337 else if (!ctx
->_ImageTransferState
&&
1338 !srcPacking
->SwapBytes
&&
1339 (dstFormat
== MESA_FORMAT_ARGB8888
||
1340 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1341 srcFormat
== GL_RGB
&&
1342 (baseInternalFormat
== GL_RGBA
||
1343 baseInternalFormat
== GL_RGB
) &&
1344 srcType
== GL_UNSIGNED_BYTE
) {
1346 for (img
= 0; img
< srcDepth
; img
++) {
1347 const GLint srcRowStride
=
1348 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1349 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1350 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1351 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1352 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1353 + dstYoffset
* dstRowStride
1354 + dstXoffset
* texelBytes
;
1355 for (row
= 0; row
< srcHeight
; row
++) {
1356 GLuint
*d4
= (GLuint
*) dstRow
;
1357 for (col
= 0; col
< srcWidth
; col
++) {
1358 d4
[col
] = PACK_COLOR_8888(0xff,
1359 srcRow
[col
* 3 + RCOMP
],
1360 srcRow
[col
* 3 + GCOMP
],
1361 srcRow
[col
* 3 + BCOMP
]);
1363 dstRow
+= dstRowStride
;
1364 srcRow
+= srcRowStride
;
1368 else if (!ctx
->_ImageTransferState
&&
1369 !srcPacking
->SwapBytes
&&
1370 dstFormat
== MESA_FORMAT_ARGB8888
&&
1371 srcFormat
== GL_RGBA
&&
1372 baseInternalFormat
== GL_RGBA
&&
1373 srcType
== GL_UNSIGNED_BYTE
) {
1374 /* same as above case, but src data has alpha too */
1375 GLint img
, row
, col
;
1376 /* For some reason, streaming copies to write-combined regions
1377 * are extremely sensitive to the characteristics of how the
1378 * source data is retrieved. By reordering the source reads to
1379 * be in-order, the speed of this operation increases by half.
1380 * Strangely the same isn't required for the RGB path, above.
1382 for (img
= 0; img
< srcDepth
; img
++) {
1383 const GLint srcRowStride
=
1384 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1385 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1386 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1387 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1388 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1389 + dstYoffset
* dstRowStride
1390 + dstXoffset
* texelBytes
;
1391 for (row
= 0; row
< srcHeight
; row
++) {
1392 GLuint
*d4
= (GLuint
*) dstRow
;
1393 for (col
= 0; col
< srcWidth
; col
++) {
1394 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1395 srcRow
[col
* 4 + RCOMP
],
1396 srcRow
[col
* 4 + GCOMP
],
1397 srcRow
[col
* 4 + BCOMP
]);
1399 dstRow
+= dstRowStride
;
1400 srcRow
+= srcRowStride
;
1404 else if (!ctx
->_ImageTransferState
&&
1405 (srcType
== GL_UNSIGNED_BYTE
||
1406 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1407 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1408 can_swizzle(baseInternalFormat
) &&
1409 can_swizzle(srcFormat
)) {
1413 /* dstmap - how to swizzle from RGBA to dst format:
1415 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1416 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1417 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1418 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1419 dstmap
[3] = 3; /* alpha */
1420 dstmap
[2] = 0; /* red */
1421 dstmap
[1] = 1; /* green */
1422 dstmap
[0] = 2; /* blue */
1425 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1426 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1427 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1428 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1435 _mesa_swizzle_ubyte_image(ctx
, dims
,
1440 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1443 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1448 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1451 srcWidth
, srcHeight
, srcDepth
,
1452 srcFormat
, srcType
, srcAddr
,
1454 const GLchan
*src
= tempImage
;
1455 GLint img
, row
, col
;
1458 for (img
= 0; img
< srcDepth
; img
++) {
1459 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1460 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1461 + dstYoffset
* dstRowStride
1462 + dstXoffset
* texelBytes
;
1463 for (row
= 0; row
< srcHeight
; row
++) {
1464 GLuint
*dstUI
= (GLuint
*) dstRow
;
1465 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1466 for (col
= 0; col
< srcWidth
; col
++) {
1467 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1468 CHAN_TO_UBYTE(src
[RCOMP
]),
1469 CHAN_TO_UBYTE(src
[GCOMP
]),
1470 CHAN_TO_UBYTE(src
[BCOMP
]) );
1474 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1475 for (col
= 0; col
< srcWidth
; col
++) {
1476 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1477 CHAN_TO_UBYTE(src
[RCOMP
]),
1478 CHAN_TO_UBYTE(src
[GCOMP
]),
1479 CHAN_TO_UBYTE(src
[BCOMP
]) );
1484 for (col
= 0; col
< srcWidth
; col
++) {
1485 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1486 CHAN_TO_UBYTE(src
[RCOMP
]),
1487 CHAN_TO_UBYTE(src
[GCOMP
]),
1488 CHAN_TO_UBYTE(src
[BCOMP
]) );
1492 dstRow
+= dstRowStride
;
1495 free((void *) tempImage
);
1502 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1504 const GLboolean littleEndian
= _mesa_little_endian();
1505 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1506 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1508 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1509 ASSERT(texelBytes
== 3);
1511 if (!ctx
->_ImageTransferState
&&
1512 !srcPacking
->SwapBytes
&&
1513 baseInternalFormat
== GL_RGB
&&
1514 srcFormat
== GL_BGR
&&
1515 srcType
== GL_UNSIGNED_BYTE
&&
1517 /* simple memcpy path */
1518 memcpy_texture(ctx
, dims
,
1519 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1522 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1523 srcAddr
, srcPacking
);
1525 else if (!ctx
->_ImageTransferState
&&
1526 !srcPacking
->SwapBytes
&&
1527 srcFormat
== GL_RGBA
&&
1528 srcType
== GL_UNSIGNED_BYTE
) {
1529 /* extract RGB from RGBA */
1530 GLint img
, row
, col
;
1531 for (img
= 0; img
< srcDepth
; img
++) {
1532 const GLint srcRowStride
=
1533 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1534 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1535 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1536 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1537 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1538 + dstYoffset
* dstRowStride
1539 + dstXoffset
* texelBytes
;
1540 for (row
= 0; row
< srcHeight
; row
++) {
1541 for (col
= 0; col
< srcWidth
; col
++) {
1542 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1543 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1544 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1546 dstRow
+= dstRowStride
;
1547 srcRow
+= srcRowStride
;
1551 else if (!ctx
->_ImageTransferState
&&
1552 srcType
== GL_UNSIGNED_BYTE
&&
1553 can_swizzle(baseInternalFormat
) &&
1554 can_swizzle(srcFormat
)) {
1558 /* dstmap - how to swizzle from RGBA to dst format:
1563 dstmap
[3] = ONE
; /* ? */
1565 _mesa_swizzle_ubyte_image(ctx
, dims
,
1570 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1571 dstRowStride
, dstImageOffsets
,
1572 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1577 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1580 srcWidth
, srcHeight
, srcDepth
,
1581 srcFormat
, srcType
, srcAddr
,
1583 const GLchan
*src
= (const GLchan
*) tempImage
;
1584 GLint img
, row
, col
;
1587 for (img
= 0; img
< srcDepth
; img
++) {
1588 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1589 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1590 + dstYoffset
* dstRowStride
1591 + dstXoffset
* texelBytes
;
1592 for (row
= 0; row
< srcHeight
; row
++) {
1595 for (col
= 0; col
< srcWidth
; col
++) {
1596 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1597 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1598 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1603 for (col
= 0; col
< srcWidth
; col
++) {
1604 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1605 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1606 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1611 for (col
= 0; col
< srcWidth
; col
++) {
1612 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1613 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1614 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1618 dstRow
+= dstRowStride
;
1621 free((void *) tempImage
);
1628 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1630 const GLboolean littleEndian
= _mesa_little_endian();
1631 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1632 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1634 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1635 ASSERT(texelBytes
== 3);
1637 if (!ctx
->_ImageTransferState
&&
1638 !srcPacking
->SwapBytes
&&
1639 baseInternalFormat
== GL_RGB
&&
1640 srcFormat
== GL_RGB
&&
1641 srcType
== GL_UNSIGNED_BYTE
&&
1643 /* simple memcpy path */
1644 memcpy_texture(ctx
, dims
,
1645 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1648 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1649 srcAddr
, srcPacking
);
1651 else if (!ctx
->_ImageTransferState
&&
1652 !srcPacking
->SwapBytes
&&
1653 srcFormat
== GL_RGBA
&&
1654 srcType
== GL_UNSIGNED_BYTE
) {
1655 /* extract BGR from RGBA */
1657 for (img
= 0; img
< srcDepth
; img
++) {
1658 const GLint srcRowStride
=
1659 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1660 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1661 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1662 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1663 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1664 + dstYoffset
* dstRowStride
1665 + dstXoffset
* texelBytes
;
1666 for (row
= 0; row
< srcHeight
; row
++) {
1667 for (col
= 0; col
< srcWidth
; col
++) {
1668 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1669 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1670 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1672 dstRow
+= dstRowStride
;
1673 srcRow
+= srcRowStride
;
1677 else if (!ctx
->_ImageTransferState
&&
1678 srcType
== GL_UNSIGNED_BYTE
&&
1679 can_swizzle(baseInternalFormat
) &&
1680 can_swizzle(srcFormat
)) {
1684 /* dstmap - how to swizzle from RGBA to dst format:
1689 dstmap
[3] = ONE
; /* ? */
1691 _mesa_swizzle_ubyte_image(ctx
, dims
,
1696 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1697 dstRowStride
, dstImageOffsets
,
1698 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1703 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1706 srcWidth
, srcHeight
, srcDepth
,
1707 srcFormat
, srcType
, srcAddr
,
1709 const GLchan
*src
= (const GLchan
*) tempImage
;
1710 GLint img
, row
, col
;
1713 for (img
= 0; img
< srcDepth
; img
++) {
1714 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1715 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1716 + dstYoffset
* dstRowStride
1717 + dstXoffset
* texelBytes
;
1718 for (row
= 0; row
< srcHeight
; row
++) {
1719 for (col
= 0; col
< srcWidth
; col
++) {
1720 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1721 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1722 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1725 dstRow
+= dstRowStride
;
1728 free((void *) tempImage
);
1735 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1737 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1738 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1740 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1741 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1742 ASSERT(texelBytes
== 2);
1744 if (!ctx
->_ImageTransferState
&&
1745 !srcPacking
->SwapBytes
&&
1746 dstFormat
== MESA_FORMAT_ARGB4444
&&
1747 baseInternalFormat
== GL_RGBA
&&
1748 srcFormat
== GL_BGRA
&&
1749 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1750 /* simple memcpy path */
1751 memcpy_texture(ctx
, dims
,
1752 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1755 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1756 srcAddr
, srcPacking
);
1760 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1763 srcWidth
, srcHeight
, srcDepth
,
1764 srcFormat
, srcType
, srcAddr
,
1766 const GLchan
*src
= tempImage
;
1767 GLint img
, row
, col
;
1770 for (img
= 0; img
< srcDepth
; img
++) {
1771 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1772 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1773 + dstYoffset
* dstRowStride
1774 + dstXoffset
* texelBytes
;
1775 for (row
= 0; row
< srcHeight
; row
++) {
1776 GLushort
*dstUS
= (GLushort
*) dstRow
;
1777 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1778 for (col
= 0; col
< srcWidth
; col
++) {
1779 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1780 CHAN_TO_UBYTE(src
[RCOMP
]),
1781 CHAN_TO_UBYTE(src
[GCOMP
]),
1782 CHAN_TO_UBYTE(src
[BCOMP
]) );
1787 for (col
= 0; col
< srcWidth
; col
++) {
1788 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1789 CHAN_TO_UBYTE(src
[RCOMP
]),
1790 CHAN_TO_UBYTE(src
[GCOMP
]),
1791 CHAN_TO_UBYTE(src
[BCOMP
]) );
1795 dstRow
+= dstRowStride
;
1798 free((void *) tempImage
);
1804 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1806 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1807 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1809 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1810 ASSERT(texelBytes
== 2);
1812 if (!ctx
->_ImageTransferState
&&
1813 !srcPacking
->SwapBytes
&&
1814 dstFormat
== MESA_FORMAT_RGBA5551
&&
1815 baseInternalFormat
== GL_RGBA
&&
1816 srcFormat
== GL_RGBA
&&
1817 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1818 /* simple memcpy path */
1819 memcpy_texture(ctx
, dims
,
1820 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1823 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1824 srcAddr
, srcPacking
);
1828 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1831 srcWidth
, srcHeight
, srcDepth
,
1832 srcFormat
, srcType
, srcAddr
,
1834 const GLchan
*src
=tempImage
;
1835 GLint img
, row
, col
;
1838 for (img
= 0; img
< srcDepth
; img
++) {
1839 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1840 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1841 + dstYoffset
* dstRowStride
1842 + dstXoffset
* texelBytes
;
1843 for (row
= 0; row
< srcHeight
; row
++) {
1844 GLushort
*dstUS
= (GLushort
*) dstRow
;
1845 for (col
= 0; col
< srcWidth
; col
++) {
1846 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1847 CHAN_TO_UBYTE(src
[GCOMP
]),
1848 CHAN_TO_UBYTE(src
[BCOMP
]),
1849 CHAN_TO_UBYTE(src
[ACOMP
]) );
1852 dstRow
+= dstRowStride
;
1855 free((void *) tempImage
);
1861 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1863 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1864 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1866 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1867 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1868 ASSERT(texelBytes
== 2);
1870 if (!ctx
->_ImageTransferState
&&
1871 !srcPacking
->SwapBytes
&&
1872 dstFormat
== MESA_FORMAT_ARGB1555
&&
1873 baseInternalFormat
== GL_RGBA
&&
1874 srcFormat
== GL_BGRA
&&
1875 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1876 /* simple memcpy path */
1877 memcpy_texture(ctx
, dims
,
1878 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1881 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1882 srcAddr
, srcPacking
);
1886 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1889 srcWidth
, srcHeight
, srcDepth
,
1890 srcFormat
, srcType
, srcAddr
,
1892 const GLchan
*src
=tempImage
;
1893 GLint img
, row
, col
;
1896 for (img
= 0; img
< srcDepth
; img
++) {
1897 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1898 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1899 + dstYoffset
* dstRowStride
1900 + dstXoffset
* texelBytes
;
1901 for (row
= 0; row
< srcHeight
; row
++) {
1902 GLushort
*dstUS
= (GLushort
*) dstRow
;
1903 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1904 for (col
= 0; col
< srcWidth
; col
++) {
1905 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
1906 CHAN_TO_UBYTE(src
[RCOMP
]),
1907 CHAN_TO_UBYTE(src
[GCOMP
]),
1908 CHAN_TO_UBYTE(src
[BCOMP
]) );
1913 for (col
= 0; col
< srcWidth
; col
++) {
1914 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1915 CHAN_TO_UBYTE(src
[RCOMP
]),
1916 CHAN_TO_UBYTE(src
[GCOMP
]),
1917 CHAN_TO_UBYTE(src
[BCOMP
]) );
1921 dstRow
+= dstRowStride
;
1924 free((void *) tempImage
);
1931 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
1934 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
1936 const GLboolean littleEndian
= _mesa_little_endian();
1937 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1938 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1940 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
1941 dstFormat
== MESA_FORMAT_AL88_REV
||
1942 dstFormat
== MESA_FORMAT_RG88
||
1943 dstFormat
== MESA_FORMAT_RG88_REV
);
1944 ASSERT(texelBytes
== 2);
1946 if (!ctx
->_ImageTransferState
&&
1947 !srcPacking
->SwapBytes
&&
1948 (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_RG88
) &&
1949 baseInternalFormat
== srcFormat
&&
1950 srcType
== GL_UNSIGNED_BYTE
&&
1952 /* simple memcpy path */
1953 memcpy_texture(ctx
, dims
,
1954 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1957 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1958 srcAddr
, srcPacking
);
1960 else if (!ctx
->_ImageTransferState
&&
1962 srcType
== GL_UNSIGNED_BYTE
&&
1963 can_swizzle(baseInternalFormat
) &&
1964 can_swizzle(srcFormat
)) {
1967 /* dstmap - how to swizzle from RGBA to dst format:
1969 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
1970 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
1971 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
1981 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
1982 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
1991 dstmap
[2] = ZERO
; /* ? */
1992 dstmap
[3] = ONE
; /* ? */
1994 _mesa_swizzle_ubyte_image(ctx
, dims
,
1999 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2000 dstRowStride
, dstImageOffsets
,
2001 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2006 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2009 srcWidth
, srcHeight
, srcDepth
,
2010 srcFormat
, srcType
, srcAddr
,
2012 const GLchan
*src
= tempImage
;
2013 GLint img
, row
, col
;
2016 for (img
= 0; img
< srcDepth
; img
++) {
2017 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2018 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2019 + dstYoffset
* dstRowStride
2020 + dstXoffset
* texelBytes
;
2021 for (row
= 0; row
< srcHeight
; row
++) {
2022 GLushort
*dstUS
= (GLushort
*) dstRow
;
2023 if (dstFormat
== MESA_FORMAT_AL88
||
2024 dstFormat
== MESA_FORMAT_RG88
) {
2025 for (col
= 0; col
< srcWidth
; col
++) {
2026 /* src[0] is luminance, src[1] is alpha */
2027 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2028 CHAN_TO_UBYTE(src
[0]) );
2033 for (col
= 0; col
< srcWidth
; col
++) {
2034 /* src[0] is luminance, src[1] is alpha */
2035 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2036 CHAN_TO_UBYTE(src
[0]) );
2040 dstRow
+= dstRowStride
;
2043 free((void *) tempImage
);
2050 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2053 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2055 const GLboolean littleEndian
= _mesa_little_endian();
2056 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2057 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2059 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2060 dstFormat
== MESA_FORMAT_AL1616_REV
||
2061 dstFormat
== MESA_FORMAT_RG1616
||
2062 dstFormat
== MESA_FORMAT_RG1616_REV
);
2063 ASSERT(texelBytes
== 4);
2065 if (!ctx
->_ImageTransferState
&&
2066 !srcPacking
->SwapBytes
&&
2067 (dstFormat
== MESA_FORMAT_AL1616
|| dstFormat
== MESA_FORMAT_RG1616
) &&
2068 baseInternalFormat
== srcFormat
&&
2069 srcType
== GL_UNSIGNED_SHORT
&&
2071 /* simple memcpy path */
2072 memcpy_texture(ctx
, dims
,
2073 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2076 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2077 srcAddr
, srcPacking
);
2081 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2084 srcWidth
, srcHeight
, srcDepth
,
2085 srcFormat
, srcType
, srcAddr
,
2087 const GLfloat
*src
= tempImage
;
2088 GLint img
, row
, col
;
2091 for (img
= 0; img
< srcDepth
; img
++) {
2092 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2093 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2094 + dstYoffset
* dstRowStride
2095 + dstXoffset
* texelBytes
;
2096 for (row
= 0; row
< srcHeight
; row
++) {
2097 GLuint
*dstUI
= (GLuint
*) dstRow
;
2098 if (dstFormat
== MESA_FORMAT_AL1616
||
2099 dstFormat
== MESA_FORMAT_RG1616
) {
2100 for (col
= 0; col
< srcWidth
; col
++) {
2103 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2104 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2105 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2110 for (col
= 0; col
< srcWidth
; col
++) {
2113 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2114 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2115 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2119 dstRow
+= dstRowStride
;
2122 free((void *) tempImage
);
2129 _mesa_texstore_r16(TEXSTORE_PARAMS
)
2131 const GLboolean littleEndian
= _mesa_little_endian();
2132 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2133 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2135 ASSERT(dstFormat
== MESA_FORMAT_R16
);
2136 ASSERT(texelBytes
== 2);
2138 if (!ctx
->_ImageTransferState
&&
2139 !srcPacking
->SwapBytes
&&
2140 dstFormat
== MESA_FORMAT_R16
&&
2141 baseInternalFormat
== GL_RED
&&
2142 srcFormat
== GL_RED
&&
2143 srcType
== GL_UNSIGNED_SHORT
&&
2145 /* simple memcpy path */
2146 memcpy_texture(ctx
, dims
,
2147 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2150 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2151 srcAddr
, srcPacking
);
2155 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2158 srcWidth
, srcHeight
, srcDepth
,
2159 srcFormat
, srcType
, srcAddr
,
2161 const GLfloat
*src
= tempImage
;
2162 GLint img
, row
, col
;
2165 for (img
= 0; img
< srcDepth
; img
++) {
2166 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2167 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2168 + dstYoffset
* dstRowStride
2169 + dstXoffset
* texelBytes
;
2170 for (row
= 0; row
< srcHeight
; row
++) {
2171 GLushort
*dstUS
= (GLushort
*) dstRow
;
2172 for (col
= 0; col
< srcWidth
; col
++) {
2175 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2179 dstRow
+= dstRowStride
;
2182 free((void *) tempImage
);
2189 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2191 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2192 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2194 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2195 ASSERT(texelBytes
== 8);
2197 if (!ctx
->_ImageTransferState
&&
2198 !srcPacking
->SwapBytes
&&
2199 baseInternalFormat
== GL_RGBA
&&
2200 srcFormat
== GL_RGBA
&&
2201 srcType
== GL_UNSIGNED_SHORT
) {
2202 /* simple memcpy path */
2203 memcpy_texture(ctx
, dims
,
2204 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2207 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2208 srcAddr
, srcPacking
);
2212 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2215 srcWidth
, srcHeight
, srcDepth
,
2216 srcFormat
, srcType
, srcAddr
,
2218 const GLfloat
*src
= tempImage
;
2219 GLint img
, row
, col
;
2222 for (img
= 0; img
< srcDepth
; img
++) {
2223 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2224 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2225 + dstYoffset
* dstRowStride
2226 + dstXoffset
* texelBytes
;
2227 for (row
= 0; row
< srcHeight
; row
++) {
2228 GLushort
*dstUS
= (GLushort
*) dstRow
;
2229 for (col
= 0; col
< srcWidth
; col
++) {
2230 GLushort r
, g
, b
, a
;
2232 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2233 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2234 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2235 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2242 dstRow
+= dstRowStride
;
2245 free((void *) tempImage
);
2252 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2254 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2255 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2257 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R_16
||
2258 dstFormat
== MESA_FORMAT_SIGNED_RG_16
||
2259 dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2260 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2262 if (!ctx
->_ImageTransferState
&&
2263 !srcPacking
->SwapBytes
&&
2264 baseInternalFormat
== GL_RGBA
&&
2265 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2266 srcFormat
== GL_RGBA
&&
2267 srcType
== GL_SHORT
) {
2268 /* simple memcpy path */
2269 memcpy_texture(ctx
, dims
,
2270 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2273 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2274 srcAddr
, srcPacking
);
2278 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2281 srcWidth
, srcHeight
, srcDepth
,
2282 srcFormat
, srcType
, srcAddr
,
2284 const GLfloat
*src
= tempImage
;
2285 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2286 GLint img
, row
, col
;
2291 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2292 * 3 or 4 components/pixel here.
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 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2301 for (col
= 0; col
< srcWidth
; col
++) {
2303 for (c
= 0; c
< comps
; c
++) {
2305 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2306 dstRowS
[col
* comps
+ c
] = p
;
2309 dstRow
+= dstRowStride
;
2310 src
+= 4 * srcWidth
;
2313 free((void *) tempImage
);
2320 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2322 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2323 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2325 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2326 ASSERT(texelBytes
== 1);
2328 if (!ctx
->_ImageTransferState
&&
2329 !srcPacking
->SwapBytes
&&
2330 baseInternalFormat
== GL_RGB
&&
2331 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2332 /* simple memcpy path */
2333 memcpy_texture(ctx
, dims
,
2334 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2337 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2338 srcAddr
, srcPacking
);
2342 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2345 srcWidth
, srcHeight
, srcDepth
,
2346 srcFormat
, srcType
, srcAddr
,
2348 const GLchan
*src
= tempImage
;
2349 GLint img
, row
, col
;
2352 for (img
= 0; img
< srcDepth
; img
++) {
2353 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2354 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2355 + dstYoffset
* dstRowStride
2356 + dstXoffset
* texelBytes
;
2357 for (row
= 0; row
< srcHeight
; row
++) {
2358 for (col
= 0; col
< srcWidth
; col
++) {
2359 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2360 CHAN_TO_UBYTE(src
[GCOMP
]),
2361 CHAN_TO_UBYTE(src
[BCOMP
]) );
2364 dstRow
+= dstRowStride
;
2367 free((void *) tempImage
);
2374 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2377 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2379 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2380 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2382 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2383 dstFormat
== MESA_FORMAT_L8
||
2384 dstFormat
== MESA_FORMAT_I8
||
2385 dstFormat
== MESA_FORMAT_R8
);
2386 ASSERT(texelBytes
== 1);
2388 if (!ctx
->_ImageTransferState
&&
2389 !srcPacking
->SwapBytes
&&
2390 baseInternalFormat
== srcFormat
&&
2391 srcType
== GL_UNSIGNED_BYTE
) {
2392 /* simple memcpy path */
2393 memcpy_texture(ctx
, dims
,
2394 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2397 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2398 srcAddr
, srcPacking
);
2400 else if (!ctx
->_ImageTransferState
&&
2401 srcType
== GL_UNSIGNED_BYTE
&&
2402 can_swizzle(baseInternalFormat
) &&
2403 can_swizzle(srcFormat
)) {
2406 /* dstmap - how to swizzle from RGBA to dst format:
2408 if (dstFormat
== MESA_FORMAT_A8
) {
2414 dstmap
[1] = ZERO
; /* ? */
2415 dstmap
[2] = ZERO
; /* ? */
2416 dstmap
[3] = ONE
; /* ? */
2418 _mesa_swizzle_ubyte_image(ctx
, dims
,
2423 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2424 dstRowStride
, dstImageOffsets
,
2425 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2430 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2433 srcWidth
, srcHeight
, srcDepth
,
2434 srcFormat
, srcType
, srcAddr
,
2436 const GLchan
*src
= tempImage
;
2437 GLint img
, row
, col
;
2440 for (img
= 0; img
< srcDepth
; img
++) {
2441 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2442 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2443 + dstYoffset
* dstRowStride
2444 + dstXoffset
* texelBytes
;
2445 for (row
= 0; row
< srcHeight
; row
++) {
2446 for (col
= 0; col
< srcWidth
; col
++) {
2447 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2449 dstRow
+= dstRowStride
;
2453 free((void *) tempImage
);
2461 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2463 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2465 (void) dims
; (void) baseInternalFormat
;
2466 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2467 ASSERT(texelBytes
== 1);
2468 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2470 if (!ctx
->_ImageTransferState
&&
2471 !srcPacking
->SwapBytes
&&
2472 srcFormat
== GL_COLOR_INDEX
&&
2473 srcType
== GL_UNSIGNED_BYTE
) {
2474 /* simple memcpy path */
2475 memcpy_texture(ctx
, dims
,
2476 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2479 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2480 srcAddr
, srcPacking
);
2485 for (img
= 0; img
< srcDepth
; img
++) {
2486 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2487 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2488 + dstYoffset
* dstRowStride
2489 + dstXoffset
* texelBytes
;
2490 for (row
= 0; row
< srcHeight
; row
++) {
2491 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2492 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2493 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2494 srcType
, src
, srcPacking
,
2495 ctx
->_ImageTransferState
);
2496 dstRow
+= dstRowStride
;
2505 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2508 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2510 const GLboolean littleEndian
= _mesa_little_endian();
2511 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2513 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2515 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2516 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2517 ASSERT(texelBytes
== 2);
2518 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2519 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2520 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2521 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2522 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2524 /* always just memcpy since no pixel transfer ops apply */
2525 memcpy_texture(ctx
, dims
,
2526 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2529 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2530 srcAddr
, srcPacking
);
2532 /* Check if we need byte swapping */
2533 /* XXX the logic here _might_ be wrong */
2534 if (srcPacking
->SwapBytes
^
2535 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2536 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2539 for (img
= 0; img
< srcDepth
; img
++) {
2540 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2541 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2542 + dstYoffset
* dstRowStride
2543 + dstXoffset
* texelBytes
;
2544 for (row
= 0; row
< srcHeight
; row
++) {
2545 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2546 dstRow
+= dstRowStride
;
2554 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2556 const GLboolean littleEndian
= _mesa_little_endian();
2557 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2559 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2560 ASSERT(texelBytes
== 2);
2561 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2562 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2563 (srcFormat
== GL_DUDV_ATI
));
2564 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2566 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2568 /* simple memcpy path */
2569 memcpy_texture(ctx
, dims
,
2570 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2573 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2574 srcAddr
, srcPacking
);
2576 else if (srcType
== GL_BYTE
) {
2579 /* dstmap - how to swizzle from RGBA to dst format:
2589 dstmap
[2] = ZERO
; /* ? */
2590 dstmap
[3] = ONE
; /* ? */
2592 _mesa_swizzle_ubyte_image(ctx
, dims
,
2593 GL_LUMINANCE_ALPHA
, /* hack */
2594 GL_UNSIGNED_BYTE
, /* hack */
2595 GL_LUMINANCE_ALPHA
, /* hack */
2597 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2598 dstRowStride
, dstImageOffsets
,
2599 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2603 /* general path - note this is defined for 2d textures only */
2604 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2605 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2606 srcFormat
, srcType
);
2607 GLbyte
*tempImage
, *dst
, *src
;
2610 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2611 * components
* sizeof(GLbyte
));
2615 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2616 srcWidth
, srcHeight
,
2621 for (row
= 0; row
< srcHeight
; row
++) {
2622 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2623 dst
, srcFormat
, srcType
, src
,
2625 dst
+= srcWidth
* components
;
2630 dst
= (GLbyte
*) dstAddr
2631 + dstYoffset
* dstRowStride
2632 + dstXoffset
* texelBytes
;
2633 for (row
= 0; row
< srcHeight
; row
++) {
2634 memcpy(dst
, src
, srcWidth
* texelBytes
);
2635 dst
+= dstRowStride
;
2636 src
+= srcWidth
* texelBytes
;
2638 free((void *) tempImage
);
2645 * Store a texture in MESA_FORMAT_SIGNED_R8 format.
2648 _mesa_texstore_signed_r8(TEXSTORE_PARAMS
)
2650 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2651 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2653 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R8
);
2654 ASSERT(texelBytes
== 1);
2656 /* XXX look at adding optimized paths */
2659 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2662 srcWidth
, srcHeight
, srcDepth
,
2663 srcFormat
, srcType
, srcAddr
,
2665 const GLfloat
*srcRow
= tempImage
;
2666 GLint img
, row
, col
;
2669 for (img
= 0; img
< srcDepth
; img
++) {
2670 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2671 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2672 + dstYoffset
* dstRowStride
2673 + dstXoffset
* texelBytes
;
2674 for (row
= 0; row
< srcHeight
; row
++) {
2675 GLubyte
*dstB
= (GLubyte
*) dstRow
;
2676 for (col
= 0; col
< srcWidth
; col
++) {
2677 dstB
[col
] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2679 dstRow
+= dstRowStride
;
2682 free((void *) tempImage
);
2689 * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
2692 _mesa_texstore_signed_rg88(TEXSTORE_PARAMS
)
2694 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2695 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2697 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RG88
);
2698 ASSERT(texelBytes
== 1);
2700 /* XXX look at adding optimized paths */
2703 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2706 srcWidth
, srcHeight
, srcDepth
,
2707 srcFormat
, srcType
, srcAddr
,
2709 const GLfloat
*srcRow
= tempImage
;
2710 GLint img
, row
, col
;
2713 for (img
= 0; img
< srcDepth
; img
++) {
2714 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2715 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2716 + dstYoffset
* dstRowStride
2717 + dstXoffset
* texelBytes
;
2718 for (row
= 0; row
< srcHeight
; row
++) {
2719 GLushort
*dstUS
= (GLushort
*) dstRow
;
2720 for (col
= 0; col
< srcWidth
; col
++) {
2721 dstUS
[col
] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2722 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]));
2724 dstRow
+= dstRowStride
;
2727 free((void *) tempImage
);
2734 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2737 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2739 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2740 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2742 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2743 ASSERT(texelBytes
== 4);
2747 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2750 srcWidth
, srcHeight
, srcDepth
,
2751 srcFormat
, srcType
, srcAddr
,
2753 const GLfloat
*srcRow
= tempImage
;
2754 GLint img
, row
, col
;
2757 for (img
= 0; img
< srcDepth
; img
++) {
2758 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2759 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2760 + dstYoffset
* dstRowStride
2761 + dstXoffset
* texelBytes
;
2762 for (row
= 0; row
< srcHeight
; row
++) {
2763 GLuint
*dstUI
= (GLuint
*) dstRow
;
2764 for (col
= 0; col
< srcWidth
; col
++) {
2765 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2766 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2767 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2771 dstRow
+= dstRowStride
;
2774 free((void *) tempImage
);
2782 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
2783 * MESA_FORMAT_SIGNED_RGBA8888_REV
2786 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2788 const GLboolean littleEndian
= _mesa_little_endian();
2789 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2790 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2792 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2793 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2794 ASSERT(texelBytes
== 4);
2796 if (!ctx
->_ImageTransferState
&&
2797 !srcPacking
->SwapBytes
&&
2798 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
2799 baseInternalFormat
== GL_RGBA
&&
2800 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
2801 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
2802 /* simple memcpy path */
2803 memcpy_texture(ctx
, dims
,
2804 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2807 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2808 srcAddr
, srcPacking
);
2810 else if (!ctx
->_ImageTransferState
&&
2811 !srcPacking
->SwapBytes
&&
2812 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
2813 baseInternalFormat
== GL_RGBA
&&
2814 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
2815 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
2816 /* simple memcpy path */
2817 memcpy_texture(ctx
, dims
,
2818 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2821 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2822 srcAddr
, srcPacking
);
2824 else if (!ctx
->_ImageTransferState
&&
2825 (srcType
== GL_BYTE
) &&
2826 can_swizzle(baseInternalFormat
) &&
2827 can_swizzle(srcFormat
)) {
2831 /* dstmap - how to swizzle from RGBA to dst format:
2833 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
2834 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
2847 _mesa_swizzle_ubyte_image(ctx
, dims
,
2852 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2853 dstRowStride
, dstImageOffsets
,
2854 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2859 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2862 srcWidth
, srcHeight
, srcDepth
,
2863 srcFormat
, srcType
, srcAddr
,
2865 const GLfloat
*srcRow
= tempImage
;
2866 GLint img
, row
, col
;
2869 for (img
= 0; img
< srcDepth
; img
++) {
2870 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2871 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2872 + dstYoffset
* dstRowStride
2873 + dstXoffset
* texelBytes
;
2874 for (row
= 0; row
< srcHeight
; row
++) {
2875 GLuint
*dstUI
= (GLuint
*) dstRow
;
2876 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2877 for (col
= 0; col
< srcWidth
; col
++) {
2878 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2879 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2880 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2881 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2886 for (col
= 0; col
< srcWidth
; col
++) {
2887 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2888 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2889 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2890 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2894 dstRow
+= dstRowStride
;
2897 free((void *) tempImage
);
2904 * Store a combined depth/stencil texture image.
2907 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2909 const GLuint depthScale
= 0xffffff;
2910 const GLint srcRowStride
2911 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2915 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
2916 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2917 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2919 if (srcFormat
!= GL_DEPTH_COMPONENT
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
2920 ctx
->Pixel
.DepthBias
== 0.0f
&&
2921 !srcPacking
->SwapBytes
) {
2923 memcpy_texture(ctx
, dims
,
2924 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2927 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2928 srcAddr
, srcPacking
);
2930 else if (srcFormat
== GL_DEPTH_COMPONENT
) {
2931 /* In case we only upload depth we need to preserve the stencil */
2932 for (img
= 0; img
< srcDepth
; img
++) {
2933 GLuint
*dstRow
= (GLuint
*) dstAddr
2934 + dstImageOffsets
[dstZoffset
+ img
]
2935 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2938 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2939 srcWidth
, srcHeight
,
2942 for (row
= 0; row
< srcHeight
; row
++) {
2943 GLuint depth
[MAX_WIDTH
];
2944 GLubyte stencil
[MAX_WIDTH
];
2946 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2948 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2949 keepstencil
= GL_TRUE
;
2951 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2952 keepdepth
= GL_TRUE
;
2955 if (keepdepth
== GL_FALSE
)
2956 /* the 24 depth bits will be in the low position: */
2957 _mesa_unpack_depth_span(ctx
, srcWidth
,
2958 GL_UNSIGNED_INT
, /* dst type */
2959 keepstencil
? depth
: dstRow
, /* dst addr */
2961 srcType
, src
, srcPacking
);
2963 if (keepstencil
== GL_FALSE
)
2964 /* get the 8-bit stencil values */
2965 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2966 GL_UNSIGNED_BYTE
, /* dst type */
2967 stencil
, /* dst addr */
2968 srcType
, src
, srcPacking
,
2969 ctx
->_ImageTransferState
);
2971 for (i
= 0; i
< srcWidth
; i
++) {
2973 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2975 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
2978 src
+= srcRowStride
;
2979 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2988 * Store a combined depth/stencil texture image.
2991 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2993 const GLuint depthScale
= 0xffffff;
2994 const GLint srcRowStride
2995 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2999 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3000 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3001 srcFormat
== GL_DEPTH_COMPONENT
||
3002 srcFormat
== GL_STENCIL_INDEX
);
3003 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3004 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3006 for (img
= 0; img
< srcDepth
; img
++) {
3007 GLuint
*dstRow
= (GLuint
*) dstAddr
3008 + dstImageOffsets
[dstZoffset
+ img
]
3009 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3012 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3013 srcWidth
, srcHeight
,
3016 for (row
= 0; row
< srcHeight
; row
++) {
3017 GLuint depth
[MAX_WIDTH
];
3018 GLubyte stencil
[MAX_WIDTH
];
3020 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3022 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3023 keepstencil
= GL_TRUE
;
3025 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3026 keepdepth
= GL_TRUE
;
3029 if (keepdepth
== GL_FALSE
)
3030 /* the 24 depth bits will be in the low position: */
3031 _mesa_unpack_depth_span(ctx
, srcWidth
,
3032 GL_UNSIGNED_INT
, /* dst type */
3033 keepstencil
? depth
: dstRow
, /* dst addr */
3035 srcType
, src
, srcPacking
);
3037 if (keepstencil
== GL_FALSE
)
3038 /* get the 8-bit stencil values */
3039 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3040 GL_UNSIGNED_BYTE
, /* dst type */
3041 stencil
, /* dst addr */
3042 srcType
, src
, srcPacking
,
3043 ctx
->_ImageTransferState
);
3045 /* merge stencil values into depth values */
3046 for (i
= 0; i
< srcWidth
; i
++) {
3048 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3050 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3053 src
+= srcRowStride
;
3054 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3062 * Store simple 8-bit/value stencil texture data.
3065 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3067 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3068 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3070 if (!ctx
->_ImageTransferState
&&
3071 !srcPacking
->SwapBytes
&&
3072 baseInternalFormat
== srcFormat
&&
3073 srcType
== GL_UNSIGNED_BYTE
) {
3074 /* simple memcpy path */
3075 memcpy_texture(ctx
, dims
,
3076 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3079 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3080 srcAddr
, srcPacking
);
3083 const GLint srcRowStride
3084 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3088 for (img
= 0; img
< srcDepth
; img
++) {
3089 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3090 + dstImageOffsets
[dstZoffset
+ img
]
3091 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3094 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3095 srcWidth
, srcHeight
,
3098 for (row
= 0; row
< srcHeight
; row
++) {
3099 GLubyte stencil
[MAX_WIDTH
];
3102 /* get the 8-bit stencil values */
3103 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3104 GL_UNSIGNED_BYTE
, /* dst type */
3105 stencil
, /* dst addr */
3106 srcType
, src
, srcPacking
,
3107 ctx
->_ImageTransferState
);
3108 /* merge stencil values into depth values */
3109 for (i
= 0; i
< srcWidth
; i
++)
3110 dstRow
[i
] = stencil
[i
];
3112 src
+= srcRowStride
;
3113 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3124 * Store an image in any of the formats:
3125 * _mesa_texformat_rgba_float32
3126 * _mesa_texformat_rgb_float32
3127 * _mesa_texformat_alpha_float32
3128 * _mesa_texformat_luminance_float32
3129 * _mesa_texformat_luminance_alpha_float32
3130 * _mesa_texformat_intensity_float32
3133 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3135 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3136 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3137 const GLint components
= _mesa_components_in_format(baseFormat
);
3139 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3140 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3141 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3142 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3143 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3144 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
3145 ASSERT(baseInternalFormat
== GL_RGBA
||
3146 baseInternalFormat
== GL_RGB
||
3147 baseInternalFormat
== GL_ALPHA
||
3148 baseInternalFormat
== GL_LUMINANCE
||
3149 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3150 baseInternalFormat
== GL_INTENSITY
);
3151 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3153 if (!ctx
->_ImageTransferState
&&
3154 !srcPacking
->SwapBytes
&&
3155 baseInternalFormat
== srcFormat
&&
3156 srcType
== GL_FLOAT
) {
3157 /* simple memcpy path */
3158 memcpy_texture(ctx
, dims
,
3159 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3162 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3163 srcAddr
, srcPacking
);
3167 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3170 srcWidth
, srcHeight
, srcDepth
,
3171 srcFormat
, srcType
, srcAddr
,
3173 const GLfloat
*srcRow
= tempImage
;
3178 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3179 for (img
= 0; img
< srcDepth
; img
++) {
3180 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3181 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3182 + dstYoffset
* dstRowStride
3183 + dstXoffset
* texelBytes
;
3184 for (row
= 0; row
< srcHeight
; row
++) {
3185 memcpy(dstRow
, srcRow
, bytesPerRow
);
3186 dstRow
+= dstRowStride
;
3187 srcRow
+= srcWidth
* components
;
3191 free((void *) tempImage
);
3199 * As above, but store 16-bit floats.
3202 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3204 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3205 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3206 const GLint components
= _mesa_components_in_format(baseFormat
);
3208 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3209 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3210 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3211 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3212 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3213 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
3214 ASSERT(baseInternalFormat
== GL_RGBA
||
3215 baseInternalFormat
== GL_RGB
||
3216 baseInternalFormat
== GL_ALPHA
||
3217 baseInternalFormat
== GL_LUMINANCE
||
3218 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3219 baseInternalFormat
== GL_INTENSITY
);
3220 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3222 if (!ctx
->_ImageTransferState
&&
3223 !srcPacking
->SwapBytes
&&
3224 baseInternalFormat
== srcFormat
&&
3225 srcType
== GL_HALF_FLOAT_ARB
) {
3226 /* simple memcpy path */
3227 memcpy_texture(ctx
, dims
,
3228 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3231 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3232 srcAddr
, srcPacking
);
3236 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3239 srcWidth
, srcHeight
, srcDepth
,
3240 srcFormat
, srcType
, srcAddr
,
3242 const GLfloat
*src
= tempImage
;
3246 for (img
= 0; img
< srcDepth
; img
++) {
3247 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3248 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3249 + dstYoffset
* dstRowStride
3250 + dstXoffset
* texelBytes
;
3251 for (row
= 0; row
< srcHeight
; row
++) {
3252 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3254 for (i
= 0; i
< srcWidth
* components
; i
++) {
3255 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3257 dstRow
+= dstRowStride
;
3258 src
+= srcWidth
* components
;
3262 free((void *) tempImage
);
3268 /* non-normalized, signed int8 */
3270 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3272 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3273 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3274 const GLint components
= _mesa_components_in_format(baseFormat
);
3276 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT8
);
3277 ASSERT(baseInternalFormat
== GL_RGBA
||
3278 baseInternalFormat
== GL_RGB
||
3279 baseInternalFormat
== GL_ALPHA
||
3280 baseInternalFormat
== GL_LUMINANCE
||
3281 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3282 baseInternalFormat
== GL_INTENSITY
);
3283 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3285 if (!ctx
->_ImageTransferState
&&
3286 !srcPacking
->SwapBytes
&&
3287 baseInternalFormat
== srcFormat
&&
3288 srcType
== GL_BYTE
) {
3289 /* simple memcpy path */
3290 memcpy_texture(ctx
, dims
,
3291 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3294 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3295 srcAddr
, srcPacking
);
3299 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3302 srcWidth
, srcHeight
, srcDepth
,
3303 srcFormat
, srcType
, srcAddr
,
3305 const GLfloat
*src
= tempImage
;
3309 for (img
= 0; img
< srcDepth
; img
++) {
3310 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3311 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3312 + dstYoffset
* dstRowStride
3313 + dstXoffset
* texelBytes
;
3314 for (row
= 0; row
< srcHeight
; row
++) {
3315 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3317 for (i
= 0; i
< srcWidth
* components
; i
++) {
3318 dstTexel
[i
] = (GLbyte
) src
[i
];
3320 dstRow
+= dstRowStride
;
3321 src
+= srcWidth
* components
;
3325 free((void *) tempImage
);
3331 /* non-normalized, signed int16 */
3333 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3335 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3336 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3337 const GLint components
= _mesa_components_in_format(baseFormat
);
3339 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT16
);
3340 ASSERT(baseInternalFormat
== GL_RGBA
||
3341 baseInternalFormat
== GL_RGB
||
3342 baseInternalFormat
== GL_ALPHA
||
3343 baseInternalFormat
== GL_LUMINANCE
||
3344 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3345 baseInternalFormat
== GL_INTENSITY
);
3346 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3348 if (!ctx
->_ImageTransferState
&&
3349 !srcPacking
->SwapBytes
&&
3350 baseInternalFormat
== srcFormat
&&
3351 srcType
== GL_INT
) {
3352 /* simple memcpy path */
3353 memcpy_texture(ctx
, dims
,
3354 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3357 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3358 srcAddr
, srcPacking
);
3362 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3365 srcWidth
, srcHeight
, srcDepth
,
3366 srcFormat
, srcType
, srcAddr
,
3368 const GLfloat
*src
= tempImage
;
3372 for (img
= 0; img
< srcDepth
; img
++) {
3373 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3374 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3375 + dstYoffset
* dstRowStride
3376 + dstXoffset
* texelBytes
;
3377 for (row
= 0; row
< srcHeight
; row
++) {
3378 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3380 for (i
= 0; i
< srcWidth
* components
; i
++) {
3381 dstTexel
[i
] = (GLint
) src
[i
];
3383 dstRow
+= dstRowStride
;
3384 src
+= srcWidth
* components
;
3388 free((void *) tempImage
);
3394 /* non-normalized, signed int32 */
3396 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3398 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3399 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3400 const GLint components
= _mesa_components_in_format(baseFormat
);
3402 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT32
);
3403 ASSERT(baseInternalFormat
== GL_RGBA
||
3404 baseInternalFormat
== GL_RGB
||
3405 baseInternalFormat
== GL_ALPHA
||
3406 baseInternalFormat
== GL_LUMINANCE
||
3407 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3408 baseInternalFormat
== GL_INTENSITY
);
3409 ASSERT(texelBytes
== components
* sizeof(GLint
));
3411 if (!ctx
->_ImageTransferState
&&
3412 !srcPacking
->SwapBytes
&&
3413 baseInternalFormat
== srcFormat
&&
3414 srcType
== GL_INT
) {
3415 /* simple memcpy path */
3416 memcpy_texture(ctx
, dims
,
3417 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3420 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3421 srcAddr
, srcPacking
);
3425 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3428 srcWidth
, srcHeight
, srcDepth
,
3429 srcFormat
, srcType
, srcAddr
,
3431 const GLfloat
*src
= tempImage
;
3435 for (img
= 0; img
< srcDepth
; img
++) {
3436 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3437 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3438 + dstYoffset
* dstRowStride
3439 + dstXoffset
* texelBytes
;
3440 for (row
= 0; row
< srcHeight
; row
++) {
3441 GLint
*dstTexel
= (GLint
*) dstRow
;
3443 for (i
= 0; i
< srcWidth
* components
; i
++) {
3444 dstTexel
[i
] = (GLint
) src
[i
];
3446 dstRow
+= dstRowStride
;
3447 src
+= srcWidth
* components
;
3451 free((void *) tempImage
);
3457 /* non-normalized, unsigned int8 */
3459 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3461 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3462 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3463 const GLint components
= _mesa_components_in_format(baseFormat
);
3465 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT8
);
3466 ASSERT(baseInternalFormat
== GL_RGBA
||
3467 baseInternalFormat
== GL_RGB
||
3468 baseInternalFormat
== GL_ALPHA
||
3469 baseInternalFormat
== GL_LUMINANCE
||
3470 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3471 baseInternalFormat
== GL_INTENSITY
);
3472 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3474 if (!ctx
->_ImageTransferState
&&
3475 !srcPacking
->SwapBytes
&&
3476 baseInternalFormat
== srcFormat
&&
3477 srcType
== GL_UNSIGNED_BYTE
) {
3478 /* simple memcpy path */
3479 memcpy_texture(ctx
, dims
,
3480 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3483 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3484 srcAddr
, srcPacking
);
3488 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3491 srcWidth
, srcHeight
, srcDepth
,
3492 srcFormat
, srcType
, srcAddr
,
3494 const GLfloat
*src
= tempImage
;
3498 for (img
= 0; img
< srcDepth
; img
++) {
3499 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3500 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3501 + dstYoffset
* dstRowStride
3502 + dstXoffset
* texelBytes
;
3503 for (row
= 0; row
< srcHeight
; row
++) {
3504 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3506 for (i
= 0; i
< srcWidth
* components
; i
++) {
3507 dstTexel
[i
] = (GLubyte
) src
[i
];
3509 dstRow
+= dstRowStride
;
3510 src
+= srcWidth
* components
;
3514 free((void *) tempImage
);
3520 /* non-normalized, unsigned int16 */
3522 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3524 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3525 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3526 const GLint components
= _mesa_components_in_format(baseFormat
);
3528 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT16
);
3529 ASSERT(baseInternalFormat
== GL_RGBA
||
3530 baseInternalFormat
== GL_RGB
||
3531 baseInternalFormat
== GL_ALPHA
||
3532 baseInternalFormat
== GL_LUMINANCE
||
3533 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3534 baseInternalFormat
== GL_INTENSITY
);
3535 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3537 if (!ctx
->_ImageTransferState
&&
3538 !srcPacking
->SwapBytes
&&
3539 baseInternalFormat
== srcFormat
&&
3540 srcType
== GL_UNSIGNED_SHORT
) {
3541 /* simple memcpy path */
3542 memcpy_texture(ctx
, dims
,
3543 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3546 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3547 srcAddr
, srcPacking
);
3551 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3554 srcWidth
, srcHeight
, srcDepth
,
3555 srcFormat
, srcType
, srcAddr
,
3557 const GLfloat
*src
= tempImage
;
3561 for (img
= 0; img
< srcDepth
; img
++) {
3562 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3563 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3564 + dstYoffset
* dstRowStride
3565 + dstXoffset
* texelBytes
;
3566 for (row
= 0; row
< srcHeight
; row
++) {
3567 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3569 for (i
= 0; i
< srcWidth
* components
; i
++) {
3570 dstTexel
[i
] = (GLushort
) src
[i
];
3572 dstRow
+= dstRowStride
;
3573 src
+= srcWidth
* components
;
3577 free((void *) tempImage
);
3583 /* non-normalized, unsigned int32 */
3585 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3587 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3588 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3589 const GLint components
= _mesa_components_in_format(baseFormat
);
3591 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT32
);
3592 ASSERT(baseInternalFormat
== GL_RGBA
||
3593 baseInternalFormat
== GL_RGB
||
3594 baseInternalFormat
== GL_ALPHA
||
3595 baseInternalFormat
== GL_LUMINANCE
||
3596 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3597 baseInternalFormat
== GL_INTENSITY
);
3598 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3600 if (!ctx
->_ImageTransferState
&&
3601 !srcPacking
->SwapBytes
&&
3602 baseInternalFormat
== srcFormat
&&
3603 srcType
== GL_UNSIGNED_INT
) {
3604 /* simple memcpy path */
3605 memcpy_texture(ctx
, dims
,
3606 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3609 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3610 srcAddr
, srcPacking
);
3614 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3617 srcWidth
, srcHeight
, srcDepth
,
3618 srcFormat
, srcType
, srcAddr
,
3620 const GLfloat
*src
= tempImage
;
3624 for (img
= 0; img
< srcDepth
; img
++) {
3625 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3626 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3627 + dstYoffset
* dstRowStride
3628 + dstXoffset
* texelBytes
;
3629 for (row
= 0; row
< srcHeight
; row
++) {
3630 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3632 for (i
= 0; i
< srcWidth
* components
; i
++) {
3633 dstTexel
[i
] = (GLuint
) src
[i
];
3635 dstRow
+= dstRowStride
;
3636 src
+= srcWidth
* components
;
3640 free((void *) tempImage
);
3648 #if FEATURE_EXT_texture_sRGB
3650 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3652 gl_format newDstFormat
;
3655 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3657 /* reuse normal rgb texstore code */
3658 newDstFormat
= MESA_FORMAT_RGB888
;
3660 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3661 newDstFormat
, dstAddr
,
3662 dstXoffset
, dstYoffset
, dstZoffset
,
3663 dstRowStride
, dstImageOffsets
,
3664 srcWidth
, srcHeight
, srcDepth
,
3666 srcAddr
, srcPacking
);
3672 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3674 gl_format newDstFormat
;
3677 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3679 /* reuse normal rgba texstore code */
3680 newDstFormat
= MESA_FORMAT_RGBA8888
;
3681 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3682 newDstFormat
, dstAddr
,
3683 dstXoffset
, dstYoffset
, dstZoffset
,
3684 dstRowStride
, dstImageOffsets
,
3685 srcWidth
, srcHeight
, srcDepth
,
3687 srcAddr
, srcPacking
);
3693 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3695 gl_format newDstFormat
;
3698 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3700 /* reuse normal rgba texstore code */
3701 newDstFormat
= MESA_FORMAT_ARGB8888
;
3703 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3704 newDstFormat
, dstAddr
,
3705 dstXoffset
, dstYoffset
, dstZoffset
,
3706 dstRowStride
, dstImageOffsets
,
3707 srcWidth
, srcHeight
, srcDepth
,
3709 srcAddr
, srcPacking
);
3715 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3717 gl_format newDstFormat
;
3720 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3722 newDstFormat
= MESA_FORMAT_L8
;
3724 /* _mesa_textore_a8 handles luminance8 too */
3725 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
3726 newDstFormat
, dstAddr
,
3727 dstXoffset
, dstYoffset
, dstZoffset
,
3728 dstRowStride
, dstImageOffsets
,
3729 srcWidth
, srcHeight
, srcDepth
,
3731 srcAddr
, srcPacking
);
3737 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3739 gl_format newDstFormat
;
3742 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3744 /* reuse normal luminance/alpha texstore code */
3745 newDstFormat
= MESA_FORMAT_AL88
;
3747 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3748 newDstFormat
, dstAddr
,
3749 dstXoffset
, dstYoffset
, dstZoffset
,
3750 dstRowStride
, dstImageOffsets
,
3751 srcWidth
, srcHeight
, srcDepth
,
3753 srcAddr
, srcPacking
);
3759 /* these are used only in texstore_funcs[] below */
3760 #define _mesa_texstore_srgb8 NULL
3761 #define _mesa_texstore_srgba8 NULL
3762 #define _mesa_texstore_sargb8 NULL
3763 #define _mesa_texstore_sl8 NULL
3764 #define _mesa_texstore_sla8 NULL
3766 #endif /* FEATURE_EXT_texture_sRGB */
3772 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
3773 * XXX this is somewhat temporary.
3775 static const struct {
3777 StoreTexImageFunc Store
;
3779 texstore_funcs
[MESA_FORMAT_COUNT
] =
3781 { MESA_FORMAT_NONE
, NULL
},
3782 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
3783 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
3784 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
3785 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
3786 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
3787 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
3788 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
3789 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
3790 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
3791 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
3792 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
3793 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
3794 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
3795 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
3796 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
3797 { MESA_FORMAT_AL88
, _mesa_texstore_unorm88
},
3798 { MESA_FORMAT_AL88_REV
, _mesa_texstore_unorm88
},
3799 { MESA_FORMAT_AL1616
, _mesa_texstore_unorm1616
},
3800 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_unorm1616
},
3801 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
3802 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
3803 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
3804 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
3805 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
3806 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
3807 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
3808 { MESA_FORMAT_R8
, _mesa_texstore_a8
},
3809 { MESA_FORMAT_RG88
, _mesa_texstore_unorm88
},
3810 { MESA_FORMAT_RG88_REV
, _mesa_texstore_unorm88
},
3811 { MESA_FORMAT_R16
, _mesa_texstore_r16
},
3812 { MESA_FORMAT_RG1616
, _mesa_texstore_unorm1616
},
3813 { MESA_FORMAT_RG1616_REV
, _mesa_texstore_unorm1616
},
3814 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
3815 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
3816 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
3817 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
3818 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
3819 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
3820 { MESA_FORMAT_S8
, _mesa_texstore_s8
},
3821 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
3822 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
3823 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
3824 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
3825 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
3826 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3827 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3828 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3829 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3830 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
3831 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
3832 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3833 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3834 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3835 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3836 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
3837 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
3838 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
3839 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
3840 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3841 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3842 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
3843 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
3844 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3845 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3846 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
3847 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
3849 { MESA_FORMAT_RGBA_INT8
, _mesa_texstore_rgba_int8
},
3850 { MESA_FORMAT_RGBA_INT16
, _mesa_texstore_rgba_int16
},
3851 { MESA_FORMAT_RGBA_INT32
, _mesa_texstore_rgba_int32
},
3852 { MESA_FORMAT_RGBA_UINT8
, _mesa_texstore_rgba_uint8
},
3853 { MESA_FORMAT_RGBA_UINT16
, _mesa_texstore_rgba_uint16
},
3854 { MESA_FORMAT_RGBA_UINT32
, _mesa_texstore_rgba_uint32
},
3856 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
3858 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_signed_r8
},
3859 { MESA_FORMAT_SIGNED_RG88
, _mesa_texstore_signed_rg88
},
3860 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
3862 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
3863 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
3865 { MESA_FORMAT_SIGNED_R_16
, _mesa_texstore_signed_rgba_16
},
3866 { MESA_FORMAT_SIGNED_RG_16
, _mesa_texstore_signed_rgba_16
},
3867 { MESA_FORMAT_SIGNED_RGB_16
, _mesa_texstore_signed_rgba_16
},
3868 { MESA_FORMAT_SIGNED_RGBA_16
, _mesa_texstore_signed_rgba_16
},
3869 { MESA_FORMAT_RGBA_16
, _mesa_texstore_rgba_16
}
3874 _mesa_texstore_null(TEXSTORE_PARAMS
)
3876 (void) ctx
; (void) dims
;
3877 (void) baseInternalFormat
;
3880 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
3881 (void) dstRowStride
; (void) dstImageOffsets
;
3882 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
3883 (void) srcFormat
; (void) srcType
;
3887 /* should never happen */
3888 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
3894 * Return the StoreTexImageFunc pointer to store an image in the given format.
3896 static StoreTexImageFunc
3897 _mesa_get_texstore_func(gl_format format
)
3901 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
3902 ASSERT(texstore_funcs
[i
].Name
== i
);
3905 ASSERT(texstore_funcs
[format
].Name
== format
);
3907 if (texstore_funcs
[format
].Store
)
3908 return texstore_funcs
[format
].Store
;
3910 return _mesa_texstore_null
;
3915 * Store user data into texture memory.
3916 * Called via glTex[Sub]Image1/2/3D()
3919 _mesa_texstore(TEXSTORE_PARAMS
)
3921 StoreTexImageFunc storeImage
;
3924 storeImage
= _mesa_get_texstore_func(dstFormat
);
3926 success
= storeImage(ctx
, dims
, baseInternalFormat
,
3927 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3928 dstRowStride
, dstImageOffsets
,
3929 srcWidth
, srcHeight
, srcDepth
,
3930 srcFormat
, srcType
, srcAddr
, srcPacking
);
3936 * Check if an unpack PBO is active prior to fetching a texture image.
3937 * If so, do bounds checking and map the buffer into main memory.
3938 * Any errors detected will be recorded.
3939 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3942 _mesa_validate_pbo_teximage(GLcontext
*ctx
, GLuint dimensions
,
3943 GLsizei width
, GLsizei height
, GLsizei depth
,
3944 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3945 const struct gl_pixelstore_attrib
*unpack
,
3946 const char *funcName
)
3950 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
3954 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
3955 format
, type
, pixels
)) {
3956 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3960 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3961 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
3963 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3967 return ADD_POINTERS(buf
, pixels
);
3972 * Check if an unpack PBO is active prior to fetching a compressed texture
3974 * If so, do bounds checking and map the buffer into main memory.
3975 * Any errors detected will be recorded.
3976 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3979 _mesa_validate_pbo_compressed_teximage(GLcontext
*ctx
,
3980 GLsizei imageSize
, const GLvoid
*pixels
,
3981 const struct gl_pixelstore_attrib
*packing
,
3982 const char *funcName
)
3986 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
3987 /* not using a PBO - return pointer unchanged */
3990 if ((const GLubyte
*) pixels
+ imageSize
>
3991 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
3992 /* out of bounds read! */
3993 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3997 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3998 GL_READ_ONLY_ARB
, packing
->BufferObj
);
4000 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
4004 return ADD_POINTERS(buf
, pixels
);
4009 * This function must be called after either of the validate_pbo_*_teximage()
4010 * functions. It unmaps the PBO buffer if it was mapped earlier.
4013 _mesa_unmap_teximage_pbo(GLcontext
*ctx
,
4014 const struct gl_pixelstore_attrib
*unpack
)
4016 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
4017 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4023 /** Return texture size in bytes */
4025 texture_size(const struct gl_texture_image
*texImage
)
4027 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
4028 texImage
->Height
, texImage
->Depth
);
4033 /** Return row stride in bytes */
4035 texture_row_stride(const struct gl_texture_image
*texImage
)
4037 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
4045 * This is the software fallback for Driver.TexImage1D()
4046 * and Driver.CopyTexImage1D().
4047 * \sa _mesa_store_teximage2d()
4050 _mesa_store_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
4051 GLint internalFormat
,
4052 GLint width
, GLint border
,
4053 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4054 const struct gl_pixelstore_attrib
*packing
,
4055 struct gl_texture_object
*texObj
,
4056 struct gl_texture_image
*texImage
)
4061 /* allocate memory */
4062 sizeInBytes
= texture_size(texImage
);
4063 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4064 if (!texImage
->Data
) {
4065 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4069 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4070 pixels
, packing
, "glTexImage1D");
4072 /* Note: we check for a NULL image pointer here, _after_ we allocated
4073 * memory for the texture. That's what the GL spec calls for.
4078 const GLint dstRowStride
= 0;
4079 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4080 texImage
->TexFormat
,
4082 0, 0, 0, /* dstX/Y/Zoffset */
4084 texImage
->ImageOffsets
,
4086 format
, type
, pixels
, packing
);
4088 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4092 _mesa_unmap_teximage_pbo(ctx
, packing
);
4097 * This is the software fallback for Driver.TexImage2D()
4098 * and Driver.CopyTexImage2D().
4100 * This function is oriented toward storing images in main memory, rather
4101 * than VRAM. Device driver's can easily plug in their own replacement.
4104 _mesa_store_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
4105 GLint internalFormat
,
4106 GLint width
, GLint height
, GLint border
,
4107 GLenum format
, GLenum type
, const void *pixels
,
4108 const struct gl_pixelstore_attrib
*packing
,
4109 struct gl_texture_object
*texObj
,
4110 struct gl_texture_image
*texImage
)
4115 /* allocate memory */
4116 sizeInBytes
= texture_size(texImage
);
4117 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4118 if (!texImage
->Data
) {
4119 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4123 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4124 pixels
, packing
, "glTexImage2D");
4126 /* Note: we check for a NULL image pointer here, _after_ we allocated
4127 * memory for the texture. That's what the GL spec calls for.
4132 GLint dstRowStride
= texture_row_stride(texImage
);
4133 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4134 texImage
->TexFormat
,
4136 0, 0, 0, /* dstX/Y/Zoffset */
4138 texImage
->ImageOffsets
,
4140 format
, type
, pixels
, packing
);
4142 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4146 _mesa_unmap_teximage_pbo(ctx
, packing
);
4152 * This is the software fallback for Driver.TexImage3D()
4153 * and Driver.CopyTexImage3D().
4154 * \sa _mesa_store_teximage2d()
4157 _mesa_store_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
4158 GLint internalFormat
,
4159 GLint width
, GLint height
, GLint depth
, GLint border
,
4160 GLenum format
, GLenum type
, const void *pixels
,
4161 const struct gl_pixelstore_attrib
*packing
,
4162 struct gl_texture_object
*texObj
,
4163 struct gl_texture_image
*texImage
)
4168 /* allocate memory */
4169 sizeInBytes
= texture_size(texImage
);
4170 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4171 if (!texImage
->Data
) {
4172 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4176 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4177 type
, pixels
, packing
, "glTexImage3D");
4179 /* Note: we check for a NULL image pointer here, _after_ we allocated
4180 * memory for the texture. That's what the GL spec calls for.
4185 GLint dstRowStride
= texture_row_stride(texImage
);
4186 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4187 texImage
->TexFormat
,
4189 0, 0, 0, /* dstX/Y/Zoffset */
4191 texImage
->ImageOffsets
,
4192 width
, height
, depth
,
4193 format
, type
, pixels
, packing
);
4195 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4199 _mesa_unmap_teximage_pbo(ctx
, packing
);
4206 * This is the software fallback for Driver.TexSubImage1D()
4207 * and Driver.CopyTexSubImage1D().
4210 _mesa_store_texsubimage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
4211 GLint xoffset
, GLint width
,
4212 GLenum format
, GLenum type
, const void *pixels
,
4213 const struct gl_pixelstore_attrib
*packing
,
4214 struct gl_texture_object
*texObj
,
4215 struct gl_texture_image
*texImage
)
4217 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4218 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4219 pixels
, packing
, "glTexSubImage1D");
4224 const GLint dstRowStride
= 0;
4225 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4226 texImage
->TexFormat
,
4228 xoffset
, 0, 0, /* offsets */
4230 texImage
->ImageOffsets
,
4232 format
, type
, pixels
, packing
);
4234 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4238 _mesa_unmap_teximage_pbo(ctx
, packing
);
4244 * This is the software fallback for Driver.TexSubImage2D()
4245 * and Driver.CopyTexSubImage2D().
4248 _mesa_store_texsubimage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
4249 GLint xoffset
, GLint yoffset
,
4250 GLint width
, GLint height
,
4251 GLenum format
, GLenum type
, const void *pixels
,
4252 const struct gl_pixelstore_attrib
*packing
,
4253 struct gl_texture_object
*texObj
,
4254 struct gl_texture_image
*texImage
)
4256 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4257 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4258 pixels
, packing
, "glTexSubImage2D");
4263 GLint dstRowStride
= texture_row_stride(texImage
);
4264 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4265 texImage
->TexFormat
,
4267 xoffset
, yoffset
, 0,
4269 texImage
->ImageOffsets
,
4271 format
, type
, pixels
, packing
);
4273 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4277 _mesa_unmap_teximage_pbo(ctx
, packing
);
4282 * This is the software fallback for Driver.TexSubImage3D().
4283 * and Driver.CopyTexSubImage3D().
4286 _mesa_store_texsubimage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
4287 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4288 GLint width
, GLint height
, GLint depth
,
4289 GLenum format
, GLenum type
, const void *pixels
,
4290 const struct gl_pixelstore_attrib
*packing
,
4291 struct gl_texture_object
*texObj
,
4292 struct gl_texture_image
*texImage
)
4294 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4295 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4296 type
, pixels
, packing
,
4302 GLint dstRowStride
= texture_row_stride(texImage
);
4303 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4304 texImage
->TexFormat
,
4306 xoffset
, yoffset
, zoffset
,
4308 texImage
->ImageOffsets
,
4309 width
, height
, depth
,
4310 format
, type
, pixels
, packing
);
4312 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4316 _mesa_unmap_teximage_pbo(ctx
, packing
);
4321 * Fallback for Driver.CompressedTexImage1D()
4324 _mesa_store_compressed_teximage1d(GLcontext
*ctx
, GLenum target
, GLint level
,
4325 GLint internalFormat
,
4326 GLint width
, GLint border
,
4327 GLsizei imageSize
, const GLvoid
*data
,
4328 struct gl_texture_object
*texObj
,
4329 struct gl_texture_image
*texImage
)
4331 /* this space intentionally left blank */
4333 (void) target
; (void) level
;
4334 (void) internalFormat
;
4335 (void) width
; (void) border
;
4336 (void) imageSize
; (void) data
;
4344 * Fallback for Driver.CompressedTexImage2D()
4347 _mesa_store_compressed_teximage2d(GLcontext
*ctx
, GLenum target
, GLint level
,
4348 GLint internalFormat
,
4349 GLint width
, GLint height
, GLint border
,
4350 GLsizei imageSize
, const GLvoid
*data
,
4351 struct gl_texture_object
*texObj
,
4352 struct gl_texture_image
*texImage
)
4354 (void) width
; (void) height
; (void) border
;
4356 /* This is pretty simple, basically just do a memcpy without worrying
4357 * about the usual image unpacking or image transfer operations.
4361 ASSERT(texImage
->Width
> 0);
4362 ASSERT(texImage
->Height
> 0);
4363 ASSERT(texImage
->Depth
== 1);
4364 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
4366 /* allocate storage */
4367 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
4368 if (!texImage
->Data
) {
4369 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
4373 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4375 "glCompressedTexImage2D");
4380 memcpy(texImage
->Data
, data
, imageSize
);
4382 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4388 * Fallback for Driver.CompressedTexImage3D()
4391 _mesa_store_compressed_teximage3d(GLcontext
*ctx
, GLenum target
, GLint level
,
4392 GLint internalFormat
,
4393 GLint width
, GLint height
, GLint depth
,
4395 GLsizei imageSize
, const GLvoid
*data
,
4396 struct gl_texture_object
*texObj
,
4397 struct gl_texture_image
*texImage
)
4399 /* this space intentionally left blank */
4401 (void) target
; (void) level
;
4402 (void) internalFormat
;
4403 (void) width
; (void) height
; (void) depth
;
4405 (void) imageSize
; (void) data
;
4413 * Fallback for Driver.CompressedTexSubImage1D()
4416 _mesa_store_compressed_texsubimage1d(GLcontext
*ctx
, GLenum target
,
4418 GLint xoffset
, GLsizei width
,
4420 GLsizei imageSize
, const GLvoid
*data
,
4421 struct gl_texture_object
*texObj
,
4422 struct gl_texture_image
*texImage
)
4424 /* there are no compressed 1D texture formats yet */
4426 (void) target
; (void) level
;
4427 (void) xoffset
; (void) width
;
4429 (void) imageSize
; (void) data
;
4436 * Fallback for Driver.CompressedTexSubImage2D()
4439 _mesa_store_compressed_texsubimage2d(GLcontext
*ctx
, GLenum target
,
4441 GLint xoffset
, GLint yoffset
,
4442 GLsizei width
, GLsizei height
,
4444 GLsizei imageSize
, const GLvoid
*data
,
4445 struct gl_texture_object
*texObj
,
4446 struct gl_texture_image
*texImage
)
4448 GLint bytesPerRow
, destRowStride
, srcRowStride
;
4452 const gl_format texFormat
= texImage
->TexFormat
;
4453 const GLint destWidth
= texImage
->Width
;
4456 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4461 /* these should have been caught sooner */
4462 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
4463 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
4464 ASSERT((xoffset
% bw
) == 0);
4465 ASSERT((yoffset
% bh
) == 0);
4467 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4468 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4470 "glCompressedTexSubImage2D");
4474 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4475 src
= (const GLubyte
*) data
;
4477 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
4478 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
4479 texFormat
, destWidth
,
4480 (GLubyte
*) texImage
->Data
);
4482 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4483 rows
= height
/ bh
; /* rows in blocks */
4485 /* copy rows of blocks */
4486 for (i
= 0; i
< rows
; i
++) {
4487 memcpy(dest
, src
, bytesPerRow
);
4488 dest
+= destRowStride
;
4489 src
+= srcRowStride
;
4492 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4497 * Fallback for Driver.CompressedTexSubImage3D()
4500 _mesa_store_compressed_texsubimage3d(GLcontext
*ctx
, GLenum target
,
4502 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4503 GLsizei width
, GLsizei height
, GLsizei depth
,
4505 GLsizei imageSize
, const GLvoid
*data
,
4506 struct gl_texture_object
*texObj
,
4507 struct gl_texture_image
*texImage
)
4509 /* there are no compressed 3D texture formats yet */
4511 (void) target
; (void) level
;
4512 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4513 (void) width
; (void) height
; (void) depth
;
4515 (void) imageSize
; (void) data
;