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"
64 #include "texcompress.h"
65 #include "texcompress_fxt1.h"
66 #include "texcompress_s3tc.h"
79 * Texture image storage function.
81 typedef GLboolean (*StoreTexImageFunc
)(TEXSTORE_PARAMS
);
85 * Return GL_TRUE if the given image format is one that be converted
86 * to another format by swizzling.
89 can_swizzle(GLenum logicalBaseFormat
)
91 switch (logicalBaseFormat
) {
94 case GL_LUMINANCE_ALPHA
:
130 #define MAP1(x) MAP4(x, ZERO, ZERO, ZERO)
131 #define MAP2(x,y) MAP4(x, y, ZERO, ZERO)
132 #define MAP3(x,y,z) MAP4(x, y, z, ZERO)
133 #define MAP4(x,y,z,w) { x, y, z, w, ZERO, ONE }
136 static const struct {
139 GLubyte from_rgba
[6];
140 } mappings
[MAX_IDX
] =
150 MAP4(ZERO
, ZERO
, ZERO
, 0),
180 MAP4(0, ZERO
, ZERO
, ONE
),
186 MAP4(ZERO
, 0, ZERO
, ONE
),
192 MAP4(ZERO
, ZERO
, 0, ONE
),
216 MAP4(0, 1, ZERO
, ONE
),
224 * Convert a GL image format enum to an IDX_* value (see above).
227 get_map_idx(GLenum value
)
230 case GL_LUMINANCE
: return IDX_LUMINANCE
;
231 case GL_ALPHA
: return IDX_ALPHA
;
232 case GL_INTENSITY
: return IDX_INTENSITY
;
233 case GL_LUMINANCE_ALPHA
: return IDX_LUMINANCE_ALPHA
;
234 case GL_RGB
: return IDX_RGB
;
235 case GL_RGBA
: return IDX_RGBA
;
236 case GL_RED
: return IDX_RED
;
237 case GL_GREEN
: return IDX_GREEN
;
238 case GL_BLUE
: return IDX_BLUE
;
239 case GL_BGR
: return IDX_BGR
;
240 case GL_BGRA
: return IDX_BGRA
;
241 case GL_ABGR_EXT
: return IDX_ABGR
;
242 case GL_RG
: return IDX_RG
;
244 _mesa_problem(NULL
, "Unexpected inFormat");
251 * When promoting texture formats (see below) we need to compute the
252 * mapping of dest components back to source components.
253 * This function does that.
254 * \param inFormat the incoming format of the texture
255 * \param outFormat the final texture format
256 * \return map[6] a full 6-component map
259 compute_component_mapping(GLenum inFormat
, GLenum outFormat
,
262 const int inFmt
= get_map_idx(inFormat
);
263 const int outFmt
= get_map_idx(outFormat
);
264 const GLubyte
*in2rgba
= mappings
[inFmt
].to_rgba
;
265 const GLubyte
*rgba2out
= mappings
[outFmt
].from_rgba
;
268 for (i
= 0; i
< 4; i
++)
269 map
[i
] = in2rgba
[rgba2out
[i
]];
275 printf("from %x/%s to %x/%s map %d %d %d %d %d %d\n",
276 inFormat
, _mesa_lookup_enum_by_nr(inFormat
),
277 outFormat
, _mesa_lookup_enum_by_nr(outFormat
),
289 * Make a temporary (color) texture image with GLfloat components.
290 * Apply all needed pixel unpacking and pixel transfer operations.
291 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
292 * Suppose the user specifies GL_LUMINANCE as the internal texture format
293 * but the graphics hardware doesn't support luminance textures. So, we might
294 * use an RGB hardware format instead.
295 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
297 * \param ctx the rendering context
298 * \param dims image dimensions: 1, 2 or 3
299 * \param logicalBaseFormat basic texture derived from the user's
300 * internal texture format value
301 * \param textureBaseFormat the actual basic format of the texture
302 * \param srcWidth source image width
303 * \param srcHeight source image height
304 * \param srcDepth source image depth
305 * \param srcFormat source image format
306 * \param srcType source image type
307 * \param srcAddr source image address
308 * \param srcPacking source image pixel packing
309 * \return resulting image with format = textureBaseFormat and type = GLfloat.
312 make_temp_float_image(struct gl_context
*ctx
, GLuint dims
,
313 GLenum logicalBaseFormat
,
314 GLenum textureBaseFormat
,
315 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
316 GLenum srcFormat
, GLenum srcType
,
317 const GLvoid
*srcAddr
,
318 const struct gl_pixelstore_attrib
*srcPacking
)
320 GLuint transferOps
= ctx
->_ImageTransferState
;
322 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
323 const GLint srcStride
=
324 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
328 ASSERT(dims
>= 1 && dims
<= 3);
330 ASSERT(logicalBaseFormat
== GL_RGBA
||
331 logicalBaseFormat
== GL_RGB
||
332 logicalBaseFormat
== GL_RG
||
333 logicalBaseFormat
== GL_RED
||
334 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
335 logicalBaseFormat
== GL_LUMINANCE
||
336 logicalBaseFormat
== GL_ALPHA
||
337 logicalBaseFormat
== GL_INTENSITY
||
338 logicalBaseFormat
== GL_COLOR_INDEX
||
339 logicalBaseFormat
== GL_DEPTH_COMPONENT
);
341 ASSERT(textureBaseFormat
== GL_RGBA
||
342 textureBaseFormat
== GL_RGB
||
343 textureBaseFormat
== GL_RG
||
344 textureBaseFormat
== GL_RED
||
345 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
346 textureBaseFormat
== GL_LUMINANCE
||
347 textureBaseFormat
== GL_ALPHA
||
348 textureBaseFormat
== GL_INTENSITY
||
349 textureBaseFormat
== GL_COLOR_INDEX
||
350 textureBaseFormat
== GL_DEPTH_COMPONENT
);
352 tempImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
353 * components
* sizeof(GLfloat
));
358 for (img
= 0; img
< srcDepth
; img
++) {
360 = (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
364 for (row
= 0; row
< srcHeight
; row
++) {
365 _mesa_unpack_color_span_float(ctx
, srcWidth
, logicalBaseFormat
,
366 dst
, srcFormat
, srcType
, src
,
367 srcPacking
, transferOps
);
368 dst
+= srcWidth
* components
;
373 if (logicalBaseFormat
!= textureBaseFormat
) {
375 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
376 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
381 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
382 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
383 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
385 /* The actual texture format should have at least as many components
386 * as the logical texture format.
388 ASSERT(texComponents
>= logComponents
);
390 newImage
= (GLfloat
*) malloc(srcWidth
* srcHeight
* srcDepth
391 * texComponents
* sizeof(GLfloat
));
397 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
399 n
= srcWidth
* srcHeight
* srcDepth
;
400 for (i
= 0; i
< n
; i
++) {
402 for (k
= 0; k
< texComponents
; k
++) {
405 newImage
[i
* texComponents
+ k
] = 0.0F
;
407 newImage
[i
* texComponents
+ k
] = 1.0F
;
409 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
414 tempImage
= newImage
;
422 * Make a temporary (color) texture image with GLchan components.
423 * Apply all needed pixel unpacking and pixel transfer operations.
424 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
425 * Suppose the user specifies GL_LUMINANCE as the internal texture format
426 * but the graphics hardware doesn't support luminance textures. So, we might
427 * use an RGB hardware format instead.
428 * If logicalBaseFormat != textureBaseFormat we have some extra work to do.
430 * \param ctx the rendering context
431 * \param dims image dimensions: 1, 2 or 3
432 * \param logicalBaseFormat basic texture derived from the user's
433 * internal texture format value
434 * \param textureBaseFormat the actual basic format of the texture
435 * \param srcWidth source image width
436 * \param srcHeight source image height
437 * \param srcDepth source image depth
438 * \param srcFormat source image format
439 * \param srcType source image type
440 * \param srcAddr source image address
441 * \param srcPacking source image pixel packing
442 * \return resulting image with format = textureBaseFormat and type = GLchan.
445 _mesa_make_temp_chan_image(struct gl_context
*ctx
, GLuint dims
,
446 GLenum logicalBaseFormat
,
447 GLenum textureBaseFormat
,
448 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
449 GLenum srcFormat
, GLenum srcType
,
450 const GLvoid
*srcAddr
,
451 const struct gl_pixelstore_attrib
*srcPacking
)
453 GLuint transferOps
= ctx
->_ImageTransferState
;
454 const GLint components
= _mesa_components_in_format(logicalBaseFormat
);
456 GLchan
*tempImage
, *dst
;
458 ASSERT(dims
>= 1 && dims
<= 3);
460 ASSERT(logicalBaseFormat
== GL_RGBA
||
461 logicalBaseFormat
== GL_RGB
||
462 logicalBaseFormat
== GL_RG
||
463 logicalBaseFormat
== GL_RED
||
464 logicalBaseFormat
== GL_LUMINANCE_ALPHA
||
465 logicalBaseFormat
== GL_LUMINANCE
||
466 logicalBaseFormat
== GL_ALPHA
||
467 logicalBaseFormat
== GL_INTENSITY
);
469 ASSERT(textureBaseFormat
== GL_RGBA
||
470 textureBaseFormat
== GL_RGB
||
471 textureBaseFormat
== GL_RG
||
472 textureBaseFormat
== GL_RED
||
473 textureBaseFormat
== GL_LUMINANCE_ALPHA
||
474 textureBaseFormat
== GL_LUMINANCE
||
475 textureBaseFormat
== GL_ALPHA
||
476 textureBaseFormat
== GL_INTENSITY
);
478 /* unpack and transfer the source image */
479 tempImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
480 * components
* sizeof(GLchan
));
486 for (img
= 0; img
< srcDepth
; img
++) {
487 const GLint srcStride
=
488 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
490 (const GLubyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
494 for (row
= 0; row
< srcHeight
; row
++) {
495 _mesa_unpack_color_span_chan(ctx
, srcWidth
, logicalBaseFormat
, dst
,
496 srcFormat
, srcType
, src
, srcPacking
,
498 dst
+= srcWidth
* components
;
503 if (logicalBaseFormat
!= textureBaseFormat
) {
504 /* one more conversion step */
505 GLint texComponents
= _mesa_components_in_format(textureBaseFormat
);
506 GLint logComponents
= _mesa_components_in_format(logicalBaseFormat
);
511 /* we only promote up to RGB, RGBA and LUMINANCE_ALPHA formats for now */
512 ASSERT(textureBaseFormat
== GL_RGB
|| textureBaseFormat
== GL_RGBA
||
513 textureBaseFormat
== GL_LUMINANCE_ALPHA
);
515 /* The actual texture format should have at least as many components
516 * as the logical texture format.
518 ASSERT(texComponents
>= logComponents
);
520 newImage
= (GLchan
*) malloc(srcWidth
* srcHeight
* srcDepth
521 * texComponents
* sizeof(GLchan
));
527 compute_component_mapping(logicalBaseFormat
, textureBaseFormat
, map
);
529 n
= srcWidth
* srcHeight
* srcDepth
;
530 for (i
= 0; i
< n
; i
++) {
532 for (k
= 0; k
< texComponents
; k
++) {
535 newImage
[i
* texComponents
+ k
] = 0;
537 newImage
[i
* texComponents
+ k
] = CHAN_MAX
;
539 newImage
[i
* texComponents
+ k
] = tempImage
[i
* logComponents
+ j
];
544 tempImage
= newImage
;
552 * Copy GLubyte pixels from <src> to <dst> with swizzling.
553 * \param dst destination pixels
554 * \param dstComponents number of color components in destination pixels
555 * \param src source pixels
556 * \param srcComponents number of color components in source pixels
557 * \param map the swizzle mapping. map[X] says where to find the X component
558 * in the source image's pixels. For example, if the source image
559 * is GL_BGRA and X = red, map[0] yields 2.
560 * \param count number of pixels to copy/swizzle.
563 swizzle_copy(GLubyte
*dst
, GLuint dstComponents
, const GLubyte
*src
,
564 GLuint srcComponents
, const GLubyte
*map
, GLuint count
)
566 #define SWZ_CPY(dst, src, count, dstComps, srcComps) \
569 for (i = 0; i < count; i++) { \
571 if (srcComps == 4) { \
572 COPY_4UBV(tmp, src); \
575 for (j = 0; j < srcComps; j++) { \
580 for (j = 0; j < dstComps; j++) { \
581 dst[j] = tmp[map[j]]; \
592 ASSERT(srcComponents
<= 4);
593 ASSERT(dstComponents
<= 4);
595 switch (dstComponents
) {
597 switch (srcComponents
) {
599 SWZ_CPY(dst
, src
, count
, 4, 4);
602 SWZ_CPY(dst
, src
, count
, 4, 3);
605 SWZ_CPY(dst
, src
, count
, 4, 2);
608 SWZ_CPY(dst
, src
, count
, 4, 1);
615 switch (srcComponents
) {
617 SWZ_CPY(dst
, src
, count
, 3, 4);
620 SWZ_CPY(dst
, src
, count
, 3, 3);
623 SWZ_CPY(dst
, src
, count
, 3, 2);
626 SWZ_CPY(dst
, src
, count
, 3, 1);
633 switch (srcComponents
) {
635 SWZ_CPY(dst
, src
, count
, 2, 4);
638 SWZ_CPY(dst
, src
, count
, 2, 3);
641 SWZ_CPY(dst
, src
, count
, 2, 2);
644 SWZ_CPY(dst
, src
, count
, 2, 1);
651 switch (srcComponents
) {
653 SWZ_CPY(dst
, src
, count
, 1, 4);
656 SWZ_CPY(dst
, src
, count
, 1, 3);
659 SWZ_CPY(dst
, src
, count
, 1, 2);
662 SWZ_CPY(dst
, src
, count
, 1, 1);
676 static const GLubyte map_identity
[6] = { 0, 1, 2, 3, ZERO
, ONE
};
677 static const GLubyte map_3210
[6] = { 3, 2, 1, 0, ZERO
, ONE
};
681 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
682 * mapping array depending on endianness.
684 static const GLubyte
*
685 type_mapping( GLenum srcType
)
689 case GL_UNSIGNED_BYTE
:
691 case GL_UNSIGNED_INT_8_8_8_8
:
692 return _mesa_little_endian() ? map_3210
: map_identity
;
693 case GL_UNSIGNED_INT_8_8_8_8_REV
:
694 return _mesa_little_endian() ? map_identity
: map_3210
;
702 * For 1-byte/pixel formats (or 8_8_8_8 packed formats), return a
703 * mapping array depending on pixelstore byte swapping state.
705 static const GLubyte
*
706 byteswap_mapping( GLboolean swapBytes
,
714 case GL_UNSIGNED_BYTE
:
716 case GL_UNSIGNED_INT_8_8_8_8
:
717 case GL_UNSIGNED_INT_8_8_8_8_REV
:
727 * Transfer a GLubyte texture image with component swizzling.
730 _mesa_swizzle_ubyte_image(struct gl_context
*ctx
,
735 GLenum baseInternalFormat
,
737 const GLubyte
*rgba2dst
,
738 GLuint dstComponents
,
741 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
743 const GLuint
*dstImageOffsets
,
745 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
746 const GLvoid
*srcAddr
,
747 const struct gl_pixelstore_attrib
*srcPacking
)
749 GLint srcComponents
= _mesa_components_in_format(srcFormat
);
750 const GLubyte
*srctype2ubyte
, *swap
;
751 GLubyte map
[4], src2base
[6], base2rgba
[6];
753 const GLint srcRowStride
=
754 _mesa_image_row_stride(srcPacking
, srcWidth
,
755 srcFormat
, GL_UNSIGNED_BYTE
);
756 const GLint srcImageStride
757 = _mesa_image_image_stride(srcPacking
, srcWidth
, srcHeight
, srcFormat
,
759 const GLubyte
*srcImage
760 = (const GLubyte
*) _mesa_image_address(dimensions
, srcPacking
, srcAddr
,
761 srcWidth
, srcHeight
, srcFormat
,
762 GL_UNSIGNED_BYTE
, 0, 0, 0);
766 /* Translate from src->baseInternal->GL_RGBA->dst. This will
767 * correctly deal with RGBA->RGB->RGBA conversions where the final
768 * A value must be 0xff regardless of the incoming alpha values.
770 compute_component_mapping(srcFormat
, baseInternalFormat
, src2base
);
771 compute_component_mapping(baseInternalFormat
, GL_RGBA
, base2rgba
);
772 swap
= byteswap_mapping(srcPacking
->SwapBytes
, srcType
);
773 srctype2ubyte
= type_mapping(srcType
);
776 for (i
= 0; i
< 4; i
++)
777 map
[i
] = srctype2ubyte
[swap
[src2base
[base2rgba
[rgba2dst
[i
]]]]];
779 /* printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]); */
781 if (srcComponents
== dstComponents
&&
782 srcRowStride
== dstRowStride
&&
783 srcRowStride
== srcWidth
* srcComponents
&&
785 /* 1 and 2D images only */
786 GLubyte
*dstImage
= (GLubyte
*) dstAddr
787 + dstYoffset
* dstRowStride
788 + dstXoffset
* dstComponents
;
789 swizzle_copy(dstImage
, dstComponents
, srcImage
, srcComponents
, map
,
790 srcWidth
* srcHeight
);
794 for (img
= 0; img
< srcDepth
; img
++) {
795 const GLubyte
*srcRow
= srcImage
;
796 GLubyte
*dstRow
= (GLubyte
*) dstAddr
797 + dstImageOffsets
[dstZoffset
+ img
] * dstComponents
798 + dstYoffset
* dstRowStride
799 + dstXoffset
* dstComponents
;
800 for (row
= 0; row
< srcHeight
; row
++) {
801 swizzle_copy(dstRow
, dstComponents
, srcRow
, srcComponents
, map
, srcWidth
);
802 dstRow
+= dstRowStride
;
803 srcRow
+= srcRowStride
;
805 srcImage
+= srcImageStride
;
812 * Teximage storage routine for when a simple memcpy will do.
813 * No pixel transfer operations or special texel encodings allowed.
814 * 1D, 2D and 3D images supported.
817 memcpy_texture(struct gl_context
*ctx
,
821 GLint dstXoffset
, GLint dstYoffset
, GLint dstZoffset
,
823 const GLuint
*dstImageOffsets
,
824 GLint srcWidth
, GLint srcHeight
, GLint srcDepth
,
825 GLenum srcFormat
, GLenum srcType
,
826 const GLvoid
*srcAddr
,
827 const struct gl_pixelstore_attrib
*srcPacking
)
829 const GLint srcRowStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
831 const GLint srcImageStride
= _mesa_image_image_stride(srcPacking
,
832 srcWidth
, srcHeight
, srcFormat
, srcType
);
833 const GLubyte
*srcImage
= (const GLubyte
*) _mesa_image_address(dimensions
,
834 srcPacking
, srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, 0, 0, 0);
835 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
836 const GLint bytesPerRow
= srcWidth
* texelBytes
;
839 /* XXX update/re-enable for dstImageOffsets array */
840 const GLint bytesPerImage
= srcHeight
* bytesPerRow
;
841 const GLint bytesPerTexture
= srcDepth
* bytesPerImage
;
842 GLubyte
*dstImage
= (GLubyte
*) dstAddr
843 + dstZoffset
* dstImageStride
844 + dstYoffset
* dstRowStride
845 + dstXoffset
* texelBytes
;
847 if (dstRowStride
== srcRowStride
&&
848 dstRowStride
== bytesPerRow
&&
849 ((dstImageStride
== srcImageStride
&&
850 dstImageStride
== bytesPerImage
) ||
853 ctx
->Driver
.TextureMemCpy(dstImage
, srcImage
, bytesPerTexture
);
858 for (img
= 0; img
< srcDepth
; img
++) {
859 const GLubyte
*srcRow
= srcImage
;
860 GLubyte
*dstRow
= dstImage
;
861 for (row
= 0; row
< srcHeight
; row
++) {
862 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
863 dstRow
+= dstRowStride
;
864 srcRow
+= srcRowStride
;
866 srcImage
+= srcImageStride
;
867 dstImage
+= dstImageStride
;
873 for (img
= 0; img
< srcDepth
; img
++) {
874 const GLubyte
*srcRow
= srcImage
;
875 GLubyte
*dstRow
= (GLubyte
*) dstAddr
876 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
877 + dstYoffset
* dstRowStride
878 + dstXoffset
* texelBytes
;
879 for (row
= 0; row
< srcHeight
; row
++) {
880 ctx
->Driver
.TextureMemCpy(dstRow
, srcRow
, bytesPerRow
);
881 dstRow
+= dstRowStride
;
882 srcRow
+= srcRowStride
;
884 srcImage
+= srcImageStride
;
891 * Store a 32-bit integer depth component texture image.
894 _mesa_texstore_z32(TEXSTORE_PARAMS
)
896 const GLuint depthScale
= 0xffffffff;
897 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
899 ASSERT(dstFormat
== MESA_FORMAT_Z32
);
900 ASSERT(texelBytes
== sizeof(GLuint
));
902 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
903 ctx
->Pixel
.DepthBias
== 0.0f
&&
904 !srcPacking
->SwapBytes
&&
905 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
906 srcFormat
== GL_DEPTH_COMPONENT
&&
907 srcType
== GL_UNSIGNED_INT
) {
908 /* simple memcpy path */
909 memcpy_texture(ctx
, dims
,
910 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
913 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
914 srcAddr
, srcPacking
);
919 for (img
= 0; img
< srcDepth
; img
++) {
920 GLubyte
*dstRow
= (GLubyte
*) dstAddr
921 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
922 + dstYoffset
* dstRowStride
923 + dstXoffset
* texelBytes
;
924 for (row
= 0; row
< srcHeight
; row
++) {
925 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
926 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
927 _mesa_unpack_depth_span(ctx
, srcWidth
,
928 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
929 depthScale
, srcType
, src
, srcPacking
);
930 dstRow
+= dstRowStride
;
939 * Store a 24-bit integer depth component texture image.
942 _mesa_texstore_x8_z24(TEXSTORE_PARAMS
)
944 const GLuint depthScale
= 0xffffff;
945 const GLuint texelBytes
= 4;
948 ASSERT(dstFormat
== MESA_FORMAT_X8_Z24
);
953 for (img
= 0; img
< srcDepth
; img
++) {
954 GLubyte
*dstRow
= (GLubyte
*) dstAddr
955 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
956 + dstYoffset
* dstRowStride
957 + dstXoffset
* texelBytes
;
958 for (row
= 0; row
< srcHeight
; row
++) {
959 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
960 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
961 _mesa_unpack_depth_span(ctx
, srcWidth
,
962 GL_UNSIGNED_INT
, (GLuint
*) dstRow
,
963 depthScale
, srcType
, src
, srcPacking
);
964 dstRow
+= dstRowStride
;
973 * Store a 24-bit integer depth component texture image.
976 _mesa_texstore_z24_x8(TEXSTORE_PARAMS
)
978 const GLuint depthScale
= 0xffffff;
979 const GLuint texelBytes
= 4;
982 ASSERT(dstFormat
== MESA_FORMAT_Z24_X8
);
987 for (img
= 0; img
< srcDepth
; img
++) {
988 GLubyte
*dstRow
= (GLubyte
*) dstAddr
989 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
990 + dstYoffset
* dstRowStride
991 + dstXoffset
* texelBytes
;
992 for (row
= 0; row
< srcHeight
; row
++) {
993 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
994 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
995 GLuint
*dst
= (GLuint
*) dstRow
;
997 _mesa_unpack_depth_span(ctx
, srcWidth
,
998 GL_UNSIGNED_INT
, dst
,
999 depthScale
, srcType
, src
, srcPacking
);
1000 for (i
= 0; i
< srcWidth
; i
++)
1002 dstRow
+= dstRowStride
;
1011 * Store a 16-bit integer depth component texture image.
1014 _mesa_texstore_z16(TEXSTORE_PARAMS
)
1016 const GLuint depthScale
= 0xffff;
1017 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1019 ASSERT(dstFormat
== MESA_FORMAT_Z16
);
1020 ASSERT(texelBytes
== sizeof(GLushort
));
1022 if (ctx
->Pixel
.DepthScale
== 1.0f
&&
1023 ctx
->Pixel
.DepthBias
== 0.0f
&&
1024 !srcPacking
->SwapBytes
&&
1025 baseInternalFormat
== GL_DEPTH_COMPONENT
&&
1026 srcFormat
== GL_DEPTH_COMPONENT
&&
1027 srcType
== GL_UNSIGNED_SHORT
) {
1028 /* simple memcpy path */
1029 memcpy_texture(ctx
, dims
,
1030 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1033 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1034 srcAddr
, srcPacking
);
1039 for (img
= 0; img
< srcDepth
; img
++) {
1040 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1041 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1042 + dstYoffset
* dstRowStride
1043 + dstXoffset
* texelBytes
;
1044 for (row
= 0; row
< srcHeight
; row
++) {
1045 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
1046 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
1047 GLushort
*dst16
= (GLushort
*) dstRow
;
1048 _mesa_unpack_depth_span(ctx
, srcWidth
,
1049 GL_UNSIGNED_SHORT
, dst16
, depthScale
,
1050 srcType
, src
, srcPacking
);
1051 dstRow
+= dstRowStride
;
1060 * Store an rgb565 or rgb565_rev texture image.
1063 _mesa_texstore_rgb565(TEXSTORE_PARAMS
)
1065 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1066 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1068 ASSERT(dstFormat
== MESA_FORMAT_RGB565
||
1069 dstFormat
== MESA_FORMAT_RGB565_REV
);
1070 ASSERT(texelBytes
== 2);
1072 if (!ctx
->_ImageTransferState
&&
1073 !srcPacking
->SwapBytes
&&
1074 dstFormat
== MESA_FORMAT_RGB565
&&
1075 baseInternalFormat
== GL_RGB
&&
1076 srcFormat
== GL_RGB
&&
1077 srcType
== GL_UNSIGNED_SHORT_5_6_5
) {
1078 /* simple memcpy path */
1079 memcpy_texture(ctx
, dims
,
1080 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1083 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1084 srcAddr
, srcPacking
);
1086 else if (!ctx
->_ImageTransferState
&&
1087 !srcPacking
->SwapBytes
&&
1088 baseInternalFormat
== GL_RGB
&&
1089 srcFormat
== GL_RGB
&&
1090 srcType
== GL_UNSIGNED_BYTE
&&
1092 /* do optimized tex store */
1093 const GLint srcRowStride
=
1094 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1095 const GLubyte
*src
= (const GLubyte
*)
1096 _mesa_image_address(dims
, srcPacking
, srcAddr
, srcWidth
, srcHeight
,
1097 srcFormat
, srcType
, 0, 0, 0);
1098 GLubyte
*dst
= (GLubyte
*) dstAddr
1099 + dstYoffset
* dstRowStride
1100 + dstXoffset
* texelBytes
;
1102 for (row
= 0; row
< srcHeight
; row
++) {
1103 const GLubyte
*srcUB
= (const GLubyte
*) src
;
1104 GLushort
*dstUS
= (GLushort
*) dst
;
1105 /* check for byteswapped format */
1106 if (dstFormat
== MESA_FORMAT_RGB565
) {
1107 for (col
= 0; col
< srcWidth
; col
++) {
1108 dstUS
[col
] = PACK_COLOR_565( srcUB
[0], srcUB
[1], srcUB
[2] );
1113 for (col
= 0; col
< srcWidth
; col
++) {
1114 dstUS
[col
] = PACK_COLOR_565_REV( srcUB
[0], srcUB
[1], srcUB
[2] );
1118 dst
+= dstRowStride
;
1119 src
+= srcRowStride
;
1124 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1127 srcWidth
, srcHeight
, srcDepth
,
1128 srcFormat
, srcType
, srcAddr
,
1130 const GLchan
*src
= tempImage
;
1131 GLint img
, row
, col
;
1134 for (img
= 0; img
< srcDepth
; img
++) {
1135 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1136 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1137 + dstYoffset
* dstRowStride
1138 + dstXoffset
* texelBytes
;
1139 for (row
= 0; row
< srcHeight
; row
++) {
1140 GLushort
*dstUS
= (GLushort
*) dstRow
;
1141 /* check for byteswapped format */
1142 if (dstFormat
== MESA_FORMAT_RGB565
) {
1143 for (col
= 0; col
< srcWidth
; col
++) {
1144 dstUS
[col
] = PACK_COLOR_565( CHAN_TO_UBYTE(src
[RCOMP
]),
1145 CHAN_TO_UBYTE(src
[GCOMP
]),
1146 CHAN_TO_UBYTE(src
[BCOMP
]) );
1151 for (col
= 0; col
< srcWidth
; col
++) {
1152 dstUS
[col
] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1153 CHAN_TO_UBYTE(src
[GCOMP
]),
1154 CHAN_TO_UBYTE(src
[BCOMP
]) );
1158 dstRow
+= dstRowStride
;
1161 free((void *) tempImage
);
1168 * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV.
1171 _mesa_texstore_rgba8888(TEXSTORE_PARAMS
)
1173 const GLboolean littleEndian
= _mesa_little_endian();
1174 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1175 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1177 ASSERT(dstFormat
== MESA_FORMAT_RGBA8888
||
1178 dstFormat
== MESA_FORMAT_RGBA8888_REV
);
1179 ASSERT(texelBytes
== 4);
1181 if (!ctx
->_ImageTransferState
&&
1182 !srcPacking
->SwapBytes
&&
1183 dstFormat
== MESA_FORMAT_RGBA8888
&&
1184 baseInternalFormat
== GL_RGBA
&&
1185 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1186 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1187 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1188 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
))) {
1189 /* simple memcpy path */
1190 memcpy_texture(ctx
, dims
,
1191 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1194 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1195 srcAddr
, srcPacking
);
1197 else if (!ctx
->_ImageTransferState
&&
1198 !srcPacking
->SwapBytes
&&
1199 dstFormat
== MESA_FORMAT_RGBA8888_REV
&&
1200 baseInternalFormat
== GL_RGBA
&&
1201 ((srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) ||
1202 (srcFormat
== GL_RGBA
&& srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1203 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_INT_8_8_8_8
) ||
1204 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
))) {
1205 /* simple memcpy path */
1206 memcpy_texture(ctx
, dims
,
1207 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1210 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1211 srcAddr
, srcPacking
);
1213 else if (!ctx
->_ImageTransferState
&&
1214 (srcType
== GL_UNSIGNED_BYTE
||
1215 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1216 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1217 can_swizzle(baseInternalFormat
) &&
1218 can_swizzle(srcFormat
)) {
1222 /* dstmap - how to swizzle from RGBA to dst format:
1224 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888
) ||
1225 (!littleEndian
&& dstFormat
== MESA_FORMAT_RGBA8888_REV
)) {
1238 _mesa_swizzle_ubyte_image(ctx
, dims
,
1243 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1244 dstRowStride
, dstImageOffsets
,
1245 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1250 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1253 srcWidth
, srcHeight
, srcDepth
,
1254 srcFormat
, srcType
, srcAddr
,
1256 const GLchan
*src
= tempImage
;
1257 GLint img
, row
, col
;
1260 for (img
= 0; img
< srcDepth
; img
++) {
1261 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1262 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1263 + dstYoffset
* dstRowStride
1264 + dstXoffset
* texelBytes
;
1265 for (row
= 0; row
< srcHeight
; row
++) {
1266 GLuint
*dstUI
= (GLuint
*) dstRow
;
1267 if (dstFormat
== MESA_FORMAT_RGBA8888
) {
1268 for (col
= 0; col
< srcWidth
; col
++) {
1269 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[RCOMP
]),
1270 CHAN_TO_UBYTE(src
[GCOMP
]),
1271 CHAN_TO_UBYTE(src
[BCOMP
]),
1272 CHAN_TO_UBYTE(src
[ACOMP
]) );
1277 for (col
= 0; col
< srcWidth
; col
++) {
1278 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[RCOMP
]),
1279 CHAN_TO_UBYTE(src
[GCOMP
]),
1280 CHAN_TO_UBYTE(src
[BCOMP
]),
1281 CHAN_TO_UBYTE(src
[ACOMP
]) );
1285 dstRow
+= dstRowStride
;
1288 free((void *) tempImage
);
1295 _mesa_texstore_argb8888(TEXSTORE_PARAMS
)
1297 const GLboolean littleEndian
= _mesa_little_endian();
1298 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1299 const GLenum baseFormat
= GL_RGBA
;
1301 ASSERT(dstFormat
== MESA_FORMAT_ARGB8888
||
1302 dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1303 dstFormat
== MESA_FORMAT_XRGB8888
||
1304 dstFormat
== MESA_FORMAT_XRGB8888_REV
);
1305 ASSERT(texelBytes
== 4);
1307 if (!ctx
->_ImageTransferState
&&
1308 !srcPacking
->SwapBytes
&&
1309 (dstFormat
== MESA_FORMAT_ARGB8888
||
1310 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1311 baseInternalFormat
== GL_RGBA
&&
1312 srcFormat
== GL_BGRA
&&
1313 ((srcType
== GL_UNSIGNED_BYTE
&& littleEndian
) ||
1314 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
)) {
1315 /* simple memcpy path (little endian) */
1316 memcpy_texture(ctx
, dims
,
1317 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1320 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1321 srcAddr
, srcPacking
);
1323 else if (!ctx
->_ImageTransferState
&&
1324 !srcPacking
->SwapBytes
&&
1325 (dstFormat
== MESA_FORMAT_ARGB8888_REV
||
1326 dstFormat
== MESA_FORMAT_XRGB8888_REV
) &&
1327 baseInternalFormat
== GL_RGBA
&&
1328 srcFormat
== GL_BGRA
&&
1329 ((srcType
== GL_UNSIGNED_BYTE
&& !littleEndian
) ||
1330 srcType
== GL_UNSIGNED_INT_8_8_8_8
)) {
1331 /* simple memcpy path (big endian) */
1332 memcpy_texture(ctx
, dims
,
1333 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1336 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1337 srcAddr
, srcPacking
);
1339 else if (!ctx
->_ImageTransferState
&&
1340 !srcPacking
->SwapBytes
&&
1341 (dstFormat
== MESA_FORMAT_ARGB8888
||
1342 dstFormat
== MESA_FORMAT_XRGB8888
) &&
1343 srcFormat
== GL_RGB
&&
1344 (baseInternalFormat
== GL_RGBA
||
1345 baseInternalFormat
== GL_RGB
) &&
1346 srcType
== GL_UNSIGNED_BYTE
) {
1348 for (img
= 0; img
< srcDepth
; img
++) {
1349 const GLint srcRowStride
=
1350 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1351 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1352 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1353 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1354 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1355 + dstYoffset
* dstRowStride
1356 + dstXoffset
* texelBytes
;
1357 for (row
= 0; row
< srcHeight
; row
++) {
1358 GLuint
*d4
= (GLuint
*) dstRow
;
1359 for (col
= 0; col
< srcWidth
; col
++) {
1360 d4
[col
] = PACK_COLOR_8888(0xff,
1361 srcRow
[col
* 3 + RCOMP
],
1362 srcRow
[col
* 3 + GCOMP
],
1363 srcRow
[col
* 3 + BCOMP
]);
1365 dstRow
+= dstRowStride
;
1366 srcRow
+= srcRowStride
;
1370 else if (!ctx
->_ImageTransferState
&&
1371 !srcPacking
->SwapBytes
&&
1372 dstFormat
== MESA_FORMAT_ARGB8888
&&
1373 srcFormat
== GL_RGBA
&&
1374 baseInternalFormat
== GL_RGBA
&&
1375 srcType
== GL_UNSIGNED_BYTE
) {
1376 /* same as above case, but src data has alpha too */
1377 GLint img
, row
, col
;
1378 /* For some reason, streaming copies to write-combined regions
1379 * are extremely sensitive to the characteristics of how the
1380 * source data is retrieved. By reordering the source reads to
1381 * be in-order, the speed of this operation increases by half.
1382 * Strangely the same isn't required for the RGB path, above.
1384 for (img
= 0; img
< srcDepth
; img
++) {
1385 const GLint srcRowStride
=
1386 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1387 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1388 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1389 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1390 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1391 + dstYoffset
* dstRowStride
1392 + dstXoffset
* texelBytes
;
1393 for (row
= 0; row
< srcHeight
; row
++) {
1394 GLuint
*d4
= (GLuint
*) dstRow
;
1395 for (col
= 0; col
< srcWidth
; col
++) {
1396 d4
[col
] = PACK_COLOR_8888(srcRow
[col
* 4 + ACOMP
],
1397 srcRow
[col
* 4 + RCOMP
],
1398 srcRow
[col
* 4 + GCOMP
],
1399 srcRow
[col
* 4 + BCOMP
]);
1401 dstRow
+= dstRowStride
;
1402 srcRow
+= srcRowStride
;
1406 else if (!ctx
->_ImageTransferState
&&
1407 (srcType
== GL_UNSIGNED_BYTE
||
1408 srcType
== GL_UNSIGNED_INT_8_8_8_8
||
1409 srcType
== GL_UNSIGNED_INT_8_8_8_8_REV
) &&
1410 can_swizzle(baseInternalFormat
) &&
1411 can_swizzle(srcFormat
)) {
1415 /* dstmap - how to swizzle from RGBA to dst format:
1417 if ((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1418 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
) ||
1419 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1420 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
)) {
1421 dstmap
[3] = 3; /* alpha */
1422 dstmap
[2] = 0; /* red */
1423 dstmap
[1] = 1; /* green */
1424 dstmap
[0] = 2; /* blue */
1427 assert((littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888_REV
) ||
1428 (!littleEndian
&& dstFormat
== MESA_FORMAT_ARGB8888
) ||
1429 (littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888_REV
) ||
1430 (!littleEndian
&& dstFormat
== MESA_FORMAT_XRGB8888
));
1437 _mesa_swizzle_ubyte_image(ctx
, dims
,
1442 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1445 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1450 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1453 srcWidth
, srcHeight
, srcDepth
,
1454 srcFormat
, srcType
, srcAddr
,
1456 const GLchan
*src
= tempImage
;
1457 GLint img
, row
, col
;
1460 for (img
= 0; img
< srcDepth
; img
++) {
1461 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1462 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1463 + dstYoffset
* dstRowStride
1464 + dstXoffset
* texelBytes
;
1465 for (row
= 0; row
< srcHeight
; row
++) {
1466 GLuint
*dstUI
= (GLuint
*) dstRow
;
1467 if (dstFormat
== MESA_FORMAT_ARGB8888
) {
1468 for (col
= 0; col
< srcWidth
; col
++) {
1469 dstUI
[col
] = PACK_COLOR_8888( CHAN_TO_UBYTE(src
[ACOMP
]),
1470 CHAN_TO_UBYTE(src
[RCOMP
]),
1471 CHAN_TO_UBYTE(src
[GCOMP
]),
1472 CHAN_TO_UBYTE(src
[BCOMP
]) );
1476 else if (dstFormat
== MESA_FORMAT_XRGB8888
) {
1477 for (col
= 0; col
< srcWidth
; col
++) {
1478 dstUI
[col
] = PACK_COLOR_8888( 0xff,
1479 CHAN_TO_UBYTE(src
[RCOMP
]),
1480 CHAN_TO_UBYTE(src
[GCOMP
]),
1481 CHAN_TO_UBYTE(src
[BCOMP
]) );
1486 for (col
= 0; col
< srcWidth
; col
++) {
1487 dstUI
[col
] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1488 CHAN_TO_UBYTE(src
[RCOMP
]),
1489 CHAN_TO_UBYTE(src
[GCOMP
]),
1490 CHAN_TO_UBYTE(src
[BCOMP
]) );
1494 dstRow
+= dstRowStride
;
1497 free((void *) tempImage
);
1504 _mesa_texstore_rgb888(TEXSTORE_PARAMS
)
1506 const GLboolean littleEndian
= _mesa_little_endian();
1507 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1508 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1510 ASSERT(dstFormat
== MESA_FORMAT_RGB888
);
1511 ASSERT(texelBytes
== 3);
1513 if (!ctx
->_ImageTransferState
&&
1514 !srcPacking
->SwapBytes
&&
1515 baseInternalFormat
== GL_RGB
&&
1516 srcFormat
== GL_BGR
&&
1517 srcType
== GL_UNSIGNED_BYTE
&&
1519 /* simple memcpy path */
1520 memcpy_texture(ctx
, dims
,
1521 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1524 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1525 srcAddr
, srcPacking
);
1527 else if (!ctx
->_ImageTransferState
&&
1528 !srcPacking
->SwapBytes
&&
1529 srcFormat
== GL_RGBA
&&
1530 srcType
== GL_UNSIGNED_BYTE
) {
1531 /* extract RGB from RGBA */
1532 GLint img
, row
, col
;
1533 for (img
= 0; img
< srcDepth
; img
++) {
1534 const GLint srcRowStride
=
1535 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1536 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1537 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1538 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1539 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1540 + dstYoffset
* dstRowStride
1541 + dstXoffset
* texelBytes
;
1542 for (row
= 0; row
< srcHeight
; row
++) {
1543 for (col
= 0; col
< srcWidth
; col
++) {
1544 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + BCOMP
];
1545 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1546 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + RCOMP
];
1548 dstRow
+= dstRowStride
;
1549 srcRow
+= srcRowStride
;
1553 else if (!ctx
->_ImageTransferState
&&
1554 srcType
== GL_UNSIGNED_BYTE
&&
1555 can_swizzle(baseInternalFormat
) &&
1556 can_swizzle(srcFormat
)) {
1560 /* dstmap - how to swizzle from RGBA to dst format:
1565 dstmap
[3] = ONE
; /* ? */
1567 _mesa_swizzle_ubyte_image(ctx
, dims
,
1572 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1573 dstRowStride
, dstImageOffsets
,
1574 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1579 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1582 srcWidth
, srcHeight
, srcDepth
,
1583 srcFormat
, srcType
, srcAddr
,
1585 const GLchan
*src
= (const GLchan
*) tempImage
;
1586 GLint img
, row
, col
;
1589 for (img
= 0; img
< srcDepth
; img
++) {
1590 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1591 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1592 + dstYoffset
* dstRowStride
1593 + dstXoffset
* texelBytes
;
1594 for (row
= 0; row
< srcHeight
; row
++) {
1597 for (col
= 0; col
< srcWidth
; col
++) {
1598 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1599 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1600 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1605 for (col
= 0; col
< srcWidth
; col
++) {
1606 dstRow
[col
* 3 + 0] = srcUB
[BCOMP
];
1607 dstRow
[col
* 3 + 1] = srcUB
[GCOMP
];
1608 dstRow
[col
* 3 + 2] = srcUB
[RCOMP
];
1613 for (col
= 0; col
< srcWidth
; col
++) {
1614 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[BCOMP
]);
1615 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1616 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[RCOMP
]);
1620 dstRow
+= dstRowStride
;
1623 free((void *) tempImage
);
1630 _mesa_texstore_bgr888(TEXSTORE_PARAMS
)
1632 const GLboolean littleEndian
= _mesa_little_endian();
1633 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1634 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1636 ASSERT(dstFormat
== MESA_FORMAT_BGR888
);
1637 ASSERT(texelBytes
== 3);
1639 if (!ctx
->_ImageTransferState
&&
1640 !srcPacking
->SwapBytes
&&
1641 baseInternalFormat
== GL_RGB
&&
1642 srcFormat
== GL_RGB
&&
1643 srcType
== GL_UNSIGNED_BYTE
&&
1645 /* simple memcpy path */
1646 memcpy_texture(ctx
, dims
,
1647 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1650 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1651 srcAddr
, srcPacking
);
1653 else if (!ctx
->_ImageTransferState
&&
1654 !srcPacking
->SwapBytes
&&
1655 srcFormat
== GL_RGBA
&&
1656 srcType
== GL_UNSIGNED_BYTE
) {
1657 /* extract BGR from RGBA */
1659 for (img
= 0; img
< srcDepth
; img
++) {
1660 const GLint srcRowStride
=
1661 _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
);
1662 GLubyte
*srcRow
= (GLubyte
*) _mesa_image_address(dims
, srcPacking
,
1663 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, 0, 0);
1664 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1665 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1666 + dstYoffset
* dstRowStride
1667 + dstXoffset
* texelBytes
;
1668 for (row
= 0; row
< srcHeight
; row
++) {
1669 for (col
= 0; col
< srcWidth
; col
++) {
1670 dstRow
[col
* 3 + 0] = srcRow
[col
* 4 + RCOMP
];
1671 dstRow
[col
* 3 + 1] = srcRow
[col
* 4 + GCOMP
];
1672 dstRow
[col
* 3 + 2] = srcRow
[col
* 4 + BCOMP
];
1674 dstRow
+= dstRowStride
;
1675 srcRow
+= srcRowStride
;
1679 else if (!ctx
->_ImageTransferState
&&
1680 srcType
== GL_UNSIGNED_BYTE
&&
1681 can_swizzle(baseInternalFormat
) &&
1682 can_swizzle(srcFormat
)) {
1686 /* dstmap - how to swizzle from RGBA to dst format:
1691 dstmap
[3] = ONE
; /* ? */
1693 _mesa_swizzle_ubyte_image(ctx
, dims
,
1698 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1699 dstRowStride
, dstImageOffsets
,
1700 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
1705 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1708 srcWidth
, srcHeight
, srcDepth
,
1709 srcFormat
, srcType
, srcAddr
,
1711 const GLchan
*src
= (const GLchan
*) tempImage
;
1712 GLint img
, row
, col
;
1715 for (img
= 0; img
< srcDepth
; img
++) {
1716 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1717 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1718 + dstYoffset
* dstRowStride
1719 + dstXoffset
* texelBytes
;
1720 for (row
= 0; row
< srcHeight
; row
++) {
1721 for (col
= 0; col
< srcWidth
; col
++) {
1722 dstRow
[col
* 3 + 0] = CHAN_TO_UBYTE(src
[RCOMP
]);
1723 dstRow
[col
* 3 + 1] = CHAN_TO_UBYTE(src
[GCOMP
]);
1724 dstRow
[col
* 3 + 2] = CHAN_TO_UBYTE(src
[BCOMP
]);
1727 dstRow
+= dstRowStride
;
1730 free((void *) tempImage
);
1737 _mesa_texstore_argb4444(TEXSTORE_PARAMS
)
1739 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1740 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1742 ASSERT(dstFormat
== MESA_FORMAT_ARGB4444
||
1743 dstFormat
== MESA_FORMAT_ARGB4444_REV
);
1744 ASSERT(texelBytes
== 2);
1746 if (!ctx
->_ImageTransferState
&&
1747 !srcPacking
->SwapBytes
&&
1748 dstFormat
== MESA_FORMAT_ARGB4444
&&
1749 baseInternalFormat
== GL_RGBA
&&
1750 srcFormat
== GL_BGRA
&&
1751 srcType
== GL_UNSIGNED_SHORT_4_4_4_4_REV
) {
1752 /* simple memcpy path */
1753 memcpy_texture(ctx
, dims
,
1754 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1757 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1758 srcAddr
, srcPacking
);
1762 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1765 srcWidth
, srcHeight
, srcDepth
,
1766 srcFormat
, srcType
, srcAddr
,
1768 const GLchan
*src
= tempImage
;
1769 GLint img
, row
, col
;
1772 for (img
= 0; img
< srcDepth
; img
++) {
1773 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1774 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1775 + dstYoffset
* dstRowStride
1776 + dstXoffset
* texelBytes
;
1777 for (row
= 0; row
< srcHeight
; row
++) {
1778 GLushort
*dstUS
= (GLushort
*) dstRow
;
1779 if (dstFormat
== MESA_FORMAT_ARGB4444
) {
1780 for (col
= 0; col
< srcWidth
; col
++) {
1781 dstUS
[col
] = PACK_COLOR_4444( CHAN_TO_UBYTE(src
[ACOMP
]),
1782 CHAN_TO_UBYTE(src
[RCOMP
]),
1783 CHAN_TO_UBYTE(src
[GCOMP
]),
1784 CHAN_TO_UBYTE(src
[BCOMP
]) );
1789 for (col
= 0; col
< srcWidth
; col
++) {
1790 dstUS
[col
] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1791 CHAN_TO_UBYTE(src
[RCOMP
]),
1792 CHAN_TO_UBYTE(src
[GCOMP
]),
1793 CHAN_TO_UBYTE(src
[BCOMP
]) );
1797 dstRow
+= dstRowStride
;
1800 free((void *) tempImage
);
1806 _mesa_texstore_rgba5551(TEXSTORE_PARAMS
)
1808 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1809 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1811 ASSERT(dstFormat
== MESA_FORMAT_RGBA5551
);
1812 ASSERT(texelBytes
== 2);
1814 if (!ctx
->_ImageTransferState
&&
1815 !srcPacking
->SwapBytes
&&
1816 dstFormat
== MESA_FORMAT_RGBA5551
&&
1817 baseInternalFormat
== GL_RGBA
&&
1818 srcFormat
== GL_RGBA
&&
1819 srcType
== GL_UNSIGNED_SHORT_5_5_5_1
) {
1820 /* simple memcpy path */
1821 memcpy_texture(ctx
, dims
,
1822 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1825 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1826 srcAddr
, srcPacking
);
1830 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1833 srcWidth
, srcHeight
, srcDepth
,
1834 srcFormat
, srcType
, srcAddr
,
1836 const GLchan
*src
=tempImage
;
1837 GLint img
, row
, col
;
1840 for (img
= 0; img
< srcDepth
; img
++) {
1841 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1842 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1843 + dstYoffset
* dstRowStride
1844 + dstXoffset
* texelBytes
;
1845 for (row
= 0; row
< srcHeight
; row
++) {
1846 GLushort
*dstUS
= (GLushort
*) dstRow
;
1847 for (col
= 0; col
< srcWidth
; col
++) {
1848 dstUS
[col
] = PACK_COLOR_5551( CHAN_TO_UBYTE(src
[RCOMP
]),
1849 CHAN_TO_UBYTE(src
[GCOMP
]),
1850 CHAN_TO_UBYTE(src
[BCOMP
]),
1851 CHAN_TO_UBYTE(src
[ACOMP
]) );
1854 dstRow
+= dstRowStride
;
1857 free((void *) tempImage
);
1863 _mesa_texstore_argb1555(TEXSTORE_PARAMS
)
1865 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1866 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1868 ASSERT(dstFormat
== MESA_FORMAT_ARGB1555
||
1869 dstFormat
== MESA_FORMAT_ARGB1555_REV
);
1870 ASSERT(texelBytes
== 2);
1872 if (!ctx
->_ImageTransferState
&&
1873 !srcPacking
->SwapBytes
&&
1874 dstFormat
== MESA_FORMAT_ARGB1555
&&
1875 baseInternalFormat
== GL_RGBA
&&
1876 srcFormat
== GL_BGRA
&&
1877 srcType
== GL_UNSIGNED_SHORT_1_5_5_5_REV
) {
1878 /* simple memcpy path */
1879 memcpy_texture(ctx
, dims
,
1880 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1883 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1884 srcAddr
, srcPacking
);
1888 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
1891 srcWidth
, srcHeight
, srcDepth
,
1892 srcFormat
, srcType
, srcAddr
,
1894 const GLchan
*src
=tempImage
;
1895 GLint img
, row
, col
;
1898 for (img
= 0; img
< srcDepth
; img
++) {
1899 GLubyte
*dstRow
= (GLubyte
*) dstAddr
1900 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
1901 + dstYoffset
* dstRowStride
1902 + dstXoffset
* texelBytes
;
1903 for (row
= 0; row
< srcHeight
; row
++) {
1904 GLushort
*dstUS
= (GLushort
*) dstRow
;
1905 if (dstFormat
== MESA_FORMAT_ARGB1555
) {
1906 for (col
= 0; col
< srcWidth
; col
++) {
1907 dstUS
[col
] = PACK_COLOR_1555( CHAN_TO_UBYTE(src
[ACOMP
]),
1908 CHAN_TO_UBYTE(src
[RCOMP
]),
1909 CHAN_TO_UBYTE(src
[GCOMP
]),
1910 CHAN_TO_UBYTE(src
[BCOMP
]) );
1915 for (col
= 0; col
< srcWidth
; col
++) {
1916 dstUS
[col
] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src
[ACOMP
]),
1917 CHAN_TO_UBYTE(src
[RCOMP
]),
1918 CHAN_TO_UBYTE(src
[GCOMP
]),
1919 CHAN_TO_UBYTE(src
[BCOMP
]) );
1923 dstRow
+= dstRowStride
;
1926 free((void *) tempImage
);
1933 * Do texstore for 2-channel, 8-bit/channel, unsigned normalized formats.
1936 _mesa_texstore_unorm88(TEXSTORE_PARAMS
)
1938 const GLboolean littleEndian
= _mesa_little_endian();
1939 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
1940 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
1942 ASSERT(dstFormat
== MESA_FORMAT_AL88
||
1943 dstFormat
== MESA_FORMAT_AL88_REV
||
1944 dstFormat
== MESA_FORMAT_RG88
||
1945 dstFormat
== MESA_FORMAT_RG88_REV
);
1946 ASSERT(texelBytes
== 2);
1948 if (!ctx
->_ImageTransferState
&&
1949 !srcPacking
->SwapBytes
&&
1950 (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_RG88
) &&
1951 baseInternalFormat
== srcFormat
&&
1952 srcType
== GL_UNSIGNED_BYTE
&&
1954 /* simple memcpy path */
1955 memcpy_texture(ctx
, dims
,
1956 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
1959 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
1960 srcAddr
, srcPacking
);
1962 else if (!ctx
->_ImageTransferState
&&
1964 srcType
== GL_UNSIGNED_BYTE
&&
1965 can_swizzle(baseInternalFormat
) &&
1966 can_swizzle(srcFormat
)) {
1969 /* dstmap - how to swizzle from RGBA to dst format:
1971 if (dstFormat
== MESA_FORMAT_AL88
|| dstFormat
== MESA_FORMAT_AL88_REV
) {
1972 if ((littleEndian
&& dstFormat
== MESA_FORMAT_AL88
) ||
1973 (!littleEndian
&& dstFormat
== MESA_FORMAT_AL88_REV
)) {
1983 if ((littleEndian
&& dstFormat
== MESA_FORMAT_RG88
) ||
1984 (!littleEndian
&& dstFormat
== MESA_FORMAT_RG88_REV
)) {
1993 dstmap
[2] = ZERO
; /* ? */
1994 dstmap
[3] = ONE
; /* ? */
1996 _mesa_swizzle_ubyte_image(ctx
, dims
,
2001 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2002 dstRowStride
, dstImageOffsets
,
2003 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2008 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2011 srcWidth
, srcHeight
, srcDepth
,
2012 srcFormat
, srcType
, srcAddr
,
2014 const GLchan
*src
= tempImage
;
2015 GLint img
, row
, col
;
2018 for (img
= 0; img
< srcDepth
; img
++) {
2019 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2020 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2021 + dstYoffset
* dstRowStride
2022 + dstXoffset
* texelBytes
;
2023 for (row
= 0; row
< srcHeight
; row
++) {
2024 GLushort
*dstUS
= (GLushort
*) dstRow
;
2025 if (dstFormat
== MESA_FORMAT_AL88
||
2026 dstFormat
== MESA_FORMAT_RG88
) {
2027 for (col
= 0; col
< srcWidth
; col
++) {
2028 /* src[0] is luminance, src[1] is alpha */
2029 dstUS
[col
] = PACK_COLOR_88( CHAN_TO_UBYTE(src
[1]),
2030 CHAN_TO_UBYTE(src
[0]) );
2035 for (col
= 0; col
< srcWidth
; col
++) {
2036 /* src[0] is luminance, src[1] is alpha */
2037 dstUS
[col
] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src
[1]),
2038 CHAN_TO_UBYTE(src
[0]) );
2042 dstRow
+= dstRowStride
;
2045 free((void *) tempImage
);
2052 * Do texstore for 2-channel, 16-bit/channel, unsigned normalized formats.
2055 _mesa_texstore_unorm1616(TEXSTORE_PARAMS
)
2057 const GLboolean littleEndian
= _mesa_little_endian();
2058 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2059 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2061 ASSERT(dstFormat
== MESA_FORMAT_AL1616
||
2062 dstFormat
== MESA_FORMAT_AL1616_REV
||
2063 dstFormat
== MESA_FORMAT_RG1616
||
2064 dstFormat
== MESA_FORMAT_RG1616_REV
);
2065 ASSERT(texelBytes
== 4);
2067 if (!ctx
->_ImageTransferState
&&
2068 !srcPacking
->SwapBytes
&&
2069 (dstFormat
== MESA_FORMAT_AL1616
|| dstFormat
== MESA_FORMAT_RG1616
) &&
2070 baseInternalFormat
== srcFormat
&&
2071 srcType
== GL_UNSIGNED_SHORT
&&
2073 /* simple memcpy path */
2074 memcpy_texture(ctx
, dims
,
2075 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2078 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2079 srcAddr
, srcPacking
);
2083 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2086 srcWidth
, srcHeight
, srcDepth
,
2087 srcFormat
, srcType
, srcAddr
,
2089 const GLfloat
*src
= tempImage
;
2090 GLint img
, row
, col
;
2093 for (img
= 0; img
< srcDepth
; img
++) {
2094 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2095 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2096 + dstYoffset
* dstRowStride
2097 + dstXoffset
* texelBytes
;
2098 for (row
= 0; row
< srcHeight
; row
++) {
2099 GLuint
*dstUI
= (GLuint
*) dstRow
;
2100 if (dstFormat
== MESA_FORMAT_AL1616
||
2101 dstFormat
== MESA_FORMAT_RG1616
) {
2102 for (col
= 0; col
< srcWidth
; col
++) {
2105 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2106 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2107 dstUI
[col
] = PACK_COLOR_1616(a
, l
);
2112 for (col
= 0; col
< srcWidth
; col
++) {
2115 UNCLAMPED_FLOAT_TO_USHORT(l
, src
[0]);
2116 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[1]);
2117 dstUI
[col
] = PACK_COLOR_1616_REV(a
, l
);
2121 dstRow
+= dstRowStride
;
2124 free((void *) tempImage
);
2131 _mesa_texstore_r16(TEXSTORE_PARAMS
)
2133 const GLboolean littleEndian
= _mesa_little_endian();
2134 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2135 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2137 ASSERT(dstFormat
== MESA_FORMAT_R16
);
2138 ASSERT(texelBytes
== 2);
2140 if (!ctx
->_ImageTransferState
&&
2141 !srcPacking
->SwapBytes
&&
2142 dstFormat
== MESA_FORMAT_R16
&&
2143 baseInternalFormat
== GL_RED
&&
2144 srcFormat
== GL_RED
&&
2145 srcType
== GL_UNSIGNED_SHORT
&&
2147 /* simple memcpy path */
2148 memcpy_texture(ctx
, dims
,
2149 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2152 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2153 srcAddr
, srcPacking
);
2157 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2160 srcWidth
, srcHeight
, srcDepth
,
2161 srcFormat
, srcType
, srcAddr
,
2163 const GLfloat
*src
= tempImage
;
2164 GLint img
, row
, col
;
2167 for (img
= 0; img
< srcDepth
; img
++) {
2168 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2169 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2170 + dstYoffset
* dstRowStride
2171 + dstXoffset
* texelBytes
;
2172 for (row
= 0; row
< srcHeight
; row
++) {
2173 GLushort
*dstUS
= (GLushort
*) dstRow
;
2174 for (col
= 0; col
< srcWidth
; col
++) {
2177 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2181 dstRow
+= dstRowStride
;
2184 free((void *) tempImage
);
2191 _mesa_texstore_rgba_16(TEXSTORE_PARAMS
)
2193 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2194 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2196 ASSERT(dstFormat
== MESA_FORMAT_RGBA_16
);
2197 ASSERT(texelBytes
== 8);
2199 if (!ctx
->_ImageTransferState
&&
2200 !srcPacking
->SwapBytes
&&
2201 baseInternalFormat
== GL_RGBA
&&
2202 srcFormat
== GL_RGBA
&&
2203 srcType
== GL_UNSIGNED_SHORT
) {
2204 /* simple memcpy path */
2205 memcpy_texture(ctx
, dims
,
2206 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2209 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2210 srcAddr
, srcPacking
);
2214 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2217 srcWidth
, srcHeight
, srcDepth
,
2218 srcFormat
, srcType
, srcAddr
,
2220 const GLfloat
*src
= tempImage
;
2221 GLint img
, row
, col
;
2224 for (img
= 0; img
< srcDepth
; img
++) {
2225 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2226 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2227 + dstYoffset
* dstRowStride
2228 + dstXoffset
* texelBytes
;
2229 for (row
= 0; row
< srcHeight
; row
++) {
2230 GLushort
*dstUS
= (GLushort
*) dstRow
;
2231 for (col
= 0; col
< srcWidth
; col
++) {
2232 GLushort r
, g
, b
, a
;
2234 UNCLAMPED_FLOAT_TO_USHORT(r
, src
[0]);
2235 UNCLAMPED_FLOAT_TO_USHORT(g
, src
[1]);
2236 UNCLAMPED_FLOAT_TO_USHORT(b
, src
[2]);
2237 UNCLAMPED_FLOAT_TO_USHORT(a
, src
[3]);
2244 dstRow
+= dstRowStride
;
2247 free((void *) tempImage
);
2254 _mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS
)
2256 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2257 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2259 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R_16
||
2260 dstFormat
== MESA_FORMAT_SIGNED_RG_16
||
2261 dstFormat
== MESA_FORMAT_SIGNED_RGB_16
||
2262 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
);
2264 if (!ctx
->_ImageTransferState
&&
2265 !srcPacking
->SwapBytes
&&
2266 baseInternalFormat
== GL_RGBA
&&
2267 dstFormat
== MESA_FORMAT_SIGNED_RGBA_16
&&
2268 srcFormat
== GL_RGBA
&&
2269 srcType
== GL_SHORT
) {
2270 /* simple memcpy path */
2271 memcpy_texture(ctx
, dims
,
2272 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2275 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2276 srcAddr
, srcPacking
);
2280 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2283 srcWidth
, srcHeight
, srcDepth
,
2284 srcFormat
, srcType
, srcAddr
,
2286 const GLfloat
*src
= tempImage
;
2287 const GLuint comps
= _mesa_get_format_bytes(dstFormat
) / 2;
2288 GLint img
, row
, col
;
2293 /* Note: tempImage is always float[4] / RGBA. We convert to 1, 2,
2294 * 3 or 4 components/pixel here.
2296 for (img
= 0; img
< srcDepth
; img
++) {
2297 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2298 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2299 + dstYoffset
* dstRowStride
2300 + dstXoffset
* texelBytes
;
2301 for (row
= 0; row
< srcHeight
; row
++) {
2302 GLshort
*dstRowS
= (GLshort
*) dstRow
;
2303 for (col
= 0; col
< srcWidth
; col
++) {
2305 for (c
= 0; c
< comps
; c
++) {
2307 UNCLAMPED_FLOAT_TO_SHORT(p
, src
[col
* 4 + c
]);
2308 dstRowS
[col
* comps
+ c
] = p
;
2311 dstRow
+= dstRowStride
;
2312 src
+= 4 * srcWidth
;
2315 free((void *) tempImage
);
2322 _mesa_texstore_rgb332(TEXSTORE_PARAMS
)
2324 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2325 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2327 ASSERT(dstFormat
== MESA_FORMAT_RGB332
);
2328 ASSERT(texelBytes
== 1);
2330 if (!ctx
->_ImageTransferState
&&
2331 !srcPacking
->SwapBytes
&&
2332 baseInternalFormat
== GL_RGB
&&
2333 srcFormat
== GL_RGB
&& srcType
== GL_UNSIGNED_BYTE_3_3_2
) {
2334 /* simple memcpy path */
2335 memcpy_texture(ctx
, dims
,
2336 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2339 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2340 srcAddr
, srcPacking
);
2344 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2347 srcWidth
, srcHeight
, srcDepth
,
2348 srcFormat
, srcType
, srcAddr
,
2350 const GLchan
*src
= tempImage
;
2351 GLint img
, row
, col
;
2354 for (img
= 0; img
< srcDepth
; img
++) {
2355 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2356 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2357 + dstYoffset
* dstRowStride
2358 + dstXoffset
* texelBytes
;
2359 for (row
= 0; row
< srcHeight
; row
++) {
2360 for (col
= 0; col
< srcWidth
; col
++) {
2361 dstRow
[col
] = PACK_COLOR_332( CHAN_TO_UBYTE(src
[RCOMP
]),
2362 CHAN_TO_UBYTE(src
[GCOMP
]),
2363 CHAN_TO_UBYTE(src
[BCOMP
]) );
2366 dstRow
+= dstRowStride
;
2369 free((void *) tempImage
);
2376 * Texstore for _mesa_texformat_a8, _mesa_texformat_l8, _mesa_texformat_i8.
2379 _mesa_texstore_a8(TEXSTORE_PARAMS
)
2381 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2382 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2384 ASSERT(dstFormat
== MESA_FORMAT_A8
||
2385 dstFormat
== MESA_FORMAT_L8
||
2386 dstFormat
== MESA_FORMAT_I8
||
2387 dstFormat
== MESA_FORMAT_R8
);
2388 ASSERT(texelBytes
== 1);
2390 if (!ctx
->_ImageTransferState
&&
2391 !srcPacking
->SwapBytes
&&
2392 baseInternalFormat
== srcFormat
&&
2393 srcType
== GL_UNSIGNED_BYTE
) {
2394 /* simple memcpy path */
2395 memcpy_texture(ctx
, dims
,
2396 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2399 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2400 srcAddr
, srcPacking
);
2402 else if (!ctx
->_ImageTransferState
&&
2403 srcType
== GL_UNSIGNED_BYTE
&&
2404 can_swizzle(baseInternalFormat
) &&
2405 can_swizzle(srcFormat
)) {
2408 /* dstmap - how to swizzle from RGBA to dst format:
2410 if (dstFormat
== MESA_FORMAT_A8
) {
2416 dstmap
[1] = ZERO
; /* ? */
2417 dstmap
[2] = ZERO
; /* ? */
2418 dstmap
[3] = ONE
; /* ? */
2420 _mesa_swizzle_ubyte_image(ctx
, dims
,
2425 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2426 dstRowStride
, dstImageOffsets
,
2427 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2432 const GLchan
*tempImage
= _mesa_make_temp_chan_image(ctx
, dims
,
2435 srcWidth
, srcHeight
, srcDepth
,
2436 srcFormat
, srcType
, srcAddr
,
2438 const GLchan
*src
= tempImage
;
2439 GLint img
, row
, col
;
2442 for (img
= 0; img
< srcDepth
; img
++) {
2443 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2444 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2445 + dstYoffset
* dstRowStride
2446 + dstXoffset
* texelBytes
;
2447 for (row
= 0; row
< srcHeight
; row
++) {
2448 for (col
= 0; col
< srcWidth
; col
++) {
2449 dstRow
[col
] = CHAN_TO_UBYTE(src
[col
]);
2451 dstRow
+= dstRowStride
;
2455 free((void *) tempImage
);
2463 _mesa_texstore_ci8(TEXSTORE_PARAMS
)
2465 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2467 (void) dims
; (void) baseInternalFormat
;
2468 ASSERT(dstFormat
== MESA_FORMAT_CI8
);
2469 ASSERT(texelBytes
== 1);
2470 ASSERT(baseInternalFormat
== GL_COLOR_INDEX
);
2472 if (!ctx
->_ImageTransferState
&&
2473 !srcPacking
->SwapBytes
&&
2474 srcFormat
== GL_COLOR_INDEX
&&
2475 srcType
== GL_UNSIGNED_BYTE
) {
2476 /* simple memcpy path */
2477 memcpy_texture(ctx
, dims
,
2478 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2481 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2482 srcAddr
, srcPacking
);
2487 for (img
= 0; img
< srcDepth
; img
++) {
2488 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2489 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2490 + dstYoffset
* dstRowStride
2491 + dstXoffset
* texelBytes
;
2492 for (row
= 0; row
< srcHeight
; row
++) {
2493 const GLvoid
*src
= _mesa_image_address(dims
, srcPacking
,
2494 srcAddr
, srcWidth
, srcHeight
, srcFormat
, srcType
, img
, row
, 0);
2495 _mesa_unpack_index_span(ctx
, srcWidth
, GL_UNSIGNED_BYTE
, dstRow
,
2496 srcType
, src
, srcPacking
,
2497 ctx
->_ImageTransferState
);
2498 dstRow
+= dstRowStride
;
2507 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2510 _mesa_texstore_ycbcr(TEXSTORE_PARAMS
)
2512 const GLboolean littleEndian
= _mesa_little_endian();
2513 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2515 (void) ctx
; (void) dims
; (void) baseInternalFormat
;
2517 ASSERT((dstFormat
== MESA_FORMAT_YCBCR
) ||
2518 (dstFormat
== MESA_FORMAT_YCBCR_REV
));
2519 ASSERT(texelBytes
== 2);
2520 ASSERT(ctx
->Extensions
.MESA_ycbcr_texture
);
2521 ASSERT(srcFormat
== GL_YCBCR_MESA
);
2522 ASSERT((srcType
== GL_UNSIGNED_SHORT_8_8_MESA
) ||
2523 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
));
2524 ASSERT(baseInternalFormat
== GL_YCBCR_MESA
);
2526 /* always just memcpy since no pixel transfer ops apply */
2527 memcpy_texture(ctx
, dims
,
2528 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2531 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2532 srcAddr
, srcPacking
);
2534 /* Check if we need byte swapping */
2535 /* XXX the logic here _might_ be wrong */
2536 if (srcPacking
->SwapBytes
^
2537 (srcType
== GL_UNSIGNED_SHORT_8_8_REV_MESA
) ^
2538 (dstFormat
== MESA_FORMAT_YCBCR_REV
) ^
2541 for (img
= 0; img
< srcDepth
; img
++) {
2542 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2543 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2544 + dstYoffset
* dstRowStride
2545 + dstXoffset
* texelBytes
;
2546 for (row
= 0; row
< srcHeight
; row
++) {
2547 _mesa_swap2((GLushort
*) dstRow
, srcWidth
);
2548 dstRow
+= dstRowStride
;
2556 _mesa_texstore_dudv8(TEXSTORE_PARAMS
)
2558 const GLboolean littleEndian
= _mesa_little_endian();
2559 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2561 ASSERT(dstFormat
== MESA_FORMAT_DUDV8
);
2562 ASSERT(texelBytes
== 2);
2563 ASSERT(ctx
->Extensions
.ATI_envmap_bumpmap
);
2564 ASSERT((srcFormat
== GL_DU8DV8_ATI
) ||
2565 (srcFormat
== GL_DUDV_ATI
));
2566 ASSERT(baseInternalFormat
== GL_DUDV_ATI
);
2568 if (!srcPacking
->SwapBytes
&& srcType
== GL_BYTE
&&
2570 /* simple memcpy path */
2571 memcpy_texture(ctx
, dims
,
2572 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2575 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2576 srcAddr
, srcPacking
);
2578 else if (srcType
== GL_BYTE
) {
2581 /* dstmap - how to swizzle from RGBA to dst format:
2591 dstmap
[2] = ZERO
; /* ? */
2592 dstmap
[3] = ONE
; /* ? */
2594 _mesa_swizzle_ubyte_image(ctx
, dims
,
2595 GL_LUMINANCE_ALPHA
, /* hack */
2596 GL_UNSIGNED_BYTE
, /* hack */
2597 GL_LUMINANCE_ALPHA
, /* hack */
2599 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2600 dstRowStride
, dstImageOffsets
,
2601 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2605 /* general path - note this is defined for 2d textures only */
2606 const GLint components
= _mesa_components_in_format(baseInternalFormat
);
2607 const GLint srcStride
= _mesa_image_row_stride(srcPacking
, srcWidth
,
2608 srcFormat
, srcType
);
2609 GLbyte
*tempImage
, *dst
, *src
;
2612 tempImage
= (GLbyte
*) malloc(srcWidth
* srcHeight
* srcDepth
2613 * components
* sizeof(GLbyte
));
2617 src
= (GLbyte
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2618 srcWidth
, srcHeight
,
2623 for (row
= 0; row
< srcHeight
; row
++) {
2624 _mesa_unpack_dudv_span_byte(ctx
, srcWidth
, baseInternalFormat
,
2625 dst
, srcFormat
, srcType
, src
,
2627 dst
+= srcWidth
* components
;
2632 dst
= (GLbyte
*) dstAddr
2633 + dstYoffset
* dstRowStride
2634 + dstXoffset
* texelBytes
;
2635 for (row
= 0; row
< srcHeight
; row
++) {
2636 memcpy(dst
, src
, srcWidth
* texelBytes
);
2637 dst
+= dstRowStride
;
2638 src
+= srcWidth
* texelBytes
;
2640 free((void *) tempImage
);
2647 * Store a texture in MESA_FORMAT_SIGNED_R8 format.
2650 _mesa_texstore_signed_r8(TEXSTORE_PARAMS
)
2652 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2653 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2655 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_R8
);
2656 ASSERT(texelBytes
== 1);
2658 /* XXX look at adding optimized paths */
2661 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2664 srcWidth
, srcHeight
, srcDepth
,
2665 srcFormat
, srcType
, srcAddr
,
2667 const GLfloat
*srcRow
= tempImage
;
2668 GLint img
, row
, col
;
2671 for (img
= 0; img
< srcDepth
; img
++) {
2672 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2673 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2674 + dstYoffset
* dstRowStride
2675 + dstXoffset
* texelBytes
;
2676 for (row
= 0; row
< srcHeight
; row
++) {
2677 GLubyte
*dstB
= (GLubyte
*) dstRow
;
2678 for (col
= 0; col
< srcWidth
; col
++) {
2679 dstB
[col
] = FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]);
2681 dstRow
+= dstRowStride
;
2684 free((void *) tempImage
);
2691 * Store a texture in MESA_FORMAT_SIGNED_RG88 format.
2694 _mesa_texstore_signed_rg88(TEXSTORE_PARAMS
)
2696 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2697 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2699 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RG88
);
2700 ASSERT(texelBytes
== 1);
2702 /* XXX look at adding optimized paths */
2705 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2708 srcWidth
, srcHeight
, srcDepth
,
2709 srcFormat
, srcType
, srcAddr
,
2711 const GLfloat
*srcRow
= tempImage
;
2712 GLint img
, row
, col
;
2715 for (img
= 0; img
< srcDepth
; img
++) {
2716 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2717 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2718 + dstYoffset
* dstRowStride
2719 + dstXoffset
* texelBytes
;
2720 for (row
= 0; row
< srcHeight
; row
++) {
2721 GLushort
*dstUS
= (GLushort
*) dstRow
;
2722 for (col
= 0; col
< srcWidth
; col
++) {
2723 dstUS
[col
] = PACK_COLOR_88(FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2724 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]));
2726 dstRow
+= dstRowStride
;
2729 free((void *) tempImage
);
2736 * Store a texture in MESA_FORMAT_SIGNED_RGBX8888.
2739 _mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS
)
2741 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2742 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2744 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBX8888
);
2745 ASSERT(texelBytes
== 4);
2749 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2752 srcWidth
, srcHeight
, srcDepth
,
2753 srcFormat
, srcType
, srcAddr
,
2755 const GLfloat
*srcRow
= tempImage
;
2756 GLint img
, row
, col
;
2759 for (img
= 0; img
< srcDepth
; img
++) {
2760 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2761 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2762 + dstYoffset
* dstRowStride
2763 + dstXoffset
* texelBytes
;
2764 for (row
= 0; row
< srcHeight
; row
++) {
2765 GLuint
*dstUI
= (GLuint
*) dstRow
;
2766 for (col
= 0; col
< srcWidth
; col
++) {
2767 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2768 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2769 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2773 dstRow
+= dstRowStride
;
2776 free((void *) tempImage
);
2784 * Store a texture in MESA_FORMAT_SIGNED_RGBA8888 or
2785 * MESA_FORMAT_SIGNED_RGBA8888_REV
2788 _mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS
)
2790 const GLboolean littleEndian
= _mesa_little_endian();
2791 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
2792 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
2794 ASSERT(dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
||
2795 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
);
2796 ASSERT(texelBytes
== 4);
2798 if (!ctx
->_ImageTransferState
&&
2799 !srcPacking
->SwapBytes
&&
2800 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
&&
2801 baseInternalFormat
== GL_RGBA
&&
2802 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& !littleEndian
) ||
2803 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& littleEndian
))) {
2804 /* simple memcpy path */
2805 memcpy_texture(ctx
, dims
,
2806 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2809 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2810 srcAddr
, srcPacking
);
2812 else if (!ctx
->_ImageTransferState
&&
2813 !srcPacking
->SwapBytes
&&
2814 dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
&&
2815 baseInternalFormat
== GL_RGBA
&&
2816 ((srcFormat
== GL_RGBA
&& srcType
== GL_BYTE
&& littleEndian
) ||
2817 (srcFormat
== GL_ABGR_EXT
&& srcType
== GL_BYTE
&& !littleEndian
))) {
2818 /* simple memcpy path */
2819 memcpy_texture(ctx
, dims
,
2820 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2823 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2824 srcAddr
, srcPacking
);
2826 else if (!ctx
->_ImageTransferState
&&
2827 (srcType
== GL_BYTE
) &&
2828 can_swizzle(baseInternalFormat
) &&
2829 can_swizzle(srcFormat
)) {
2833 /* dstmap - how to swizzle from RGBA to dst format:
2835 if ((littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) ||
2836 (!littleEndian
&& dstFormat
== MESA_FORMAT_SIGNED_RGBA8888_REV
)) {
2849 _mesa_swizzle_ubyte_image(ctx
, dims
,
2854 dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2855 dstRowStride
, dstImageOffsets
,
2856 srcWidth
, srcHeight
, srcDepth
, srcAddr
,
2861 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
2864 srcWidth
, srcHeight
, srcDepth
,
2865 srcFormat
, srcType
, srcAddr
,
2867 const GLfloat
*srcRow
= tempImage
;
2868 GLint img
, row
, col
;
2871 for (img
= 0; img
< srcDepth
; img
++) {
2872 GLubyte
*dstRow
= (GLubyte
*) dstAddr
2873 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
2874 + dstYoffset
* dstRowStride
2875 + dstXoffset
* texelBytes
;
2876 for (row
= 0; row
< srcHeight
; row
++) {
2877 GLuint
*dstUI
= (GLuint
*) dstRow
;
2878 if (dstFormat
== MESA_FORMAT_SIGNED_RGBA8888
) {
2879 for (col
= 0; col
< srcWidth
; col
++) {
2880 dstUI
[col
] = PACK_COLOR_8888( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2881 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2882 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2883 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2888 for (col
= 0; col
< srcWidth
; col
++) {
2889 dstUI
[col
] = PACK_COLOR_8888_REV( FLOAT_TO_BYTE_TEX(srcRow
[RCOMP
]),
2890 FLOAT_TO_BYTE_TEX(srcRow
[GCOMP
]),
2891 FLOAT_TO_BYTE_TEX(srcRow
[BCOMP
]),
2892 FLOAT_TO_BYTE_TEX(srcRow
[ACOMP
]) );
2896 dstRow
+= dstRowStride
;
2899 free((void *) tempImage
);
2906 * Store a combined depth/stencil texture image.
2909 _mesa_texstore_z24_s8(TEXSTORE_PARAMS
)
2911 const GLuint depthScale
= 0xffffff;
2912 const GLint srcRowStride
2913 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
2917 ASSERT(dstFormat
== MESA_FORMAT_Z24_S8
);
2918 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
|| srcFormat
== GL_DEPTH_COMPONENT
);
2919 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
|| srcType
== GL_UNSIGNED_INT_24_8_EXT
);
2921 if (srcFormat
!= GL_DEPTH_COMPONENT
&& ctx
->Pixel
.DepthScale
== 1.0f
&&
2922 ctx
->Pixel
.DepthBias
== 0.0f
&&
2923 !srcPacking
->SwapBytes
) {
2925 memcpy_texture(ctx
, dims
,
2926 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
2929 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
2930 srcAddr
, srcPacking
);
2932 else if (srcFormat
== GL_DEPTH_COMPONENT
) {
2933 /* In case we only upload depth we need to preserve the stencil */
2934 for (img
= 0; img
< srcDepth
; img
++) {
2935 GLuint
*dstRow
= (GLuint
*) dstAddr
2936 + dstImageOffsets
[dstZoffset
+ img
]
2937 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
2940 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
2941 srcWidth
, srcHeight
,
2944 for (row
= 0; row
< srcHeight
; row
++) {
2945 GLuint depth
[MAX_WIDTH
];
2946 GLubyte stencil
[MAX_WIDTH
];
2948 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
2950 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
2951 keepstencil
= GL_TRUE
;
2953 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
2954 keepdepth
= GL_TRUE
;
2957 if (keepdepth
== GL_FALSE
)
2958 /* the 24 depth bits will be in the low position: */
2959 _mesa_unpack_depth_span(ctx
, srcWidth
,
2960 GL_UNSIGNED_INT
, /* dst type */
2961 keepstencil
? depth
: dstRow
, /* dst addr */
2963 srcType
, src
, srcPacking
);
2965 if (keepstencil
== GL_FALSE
)
2966 /* get the 8-bit stencil values */
2967 _mesa_unpack_stencil_span(ctx
, srcWidth
,
2968 GL_UNSIGNED_BYTE
, /* dst type */
2969 stencil
, /* dst addr */
2970 srcType
, src
, srcPacking
,
2971 ctx
->_ImageTransferState
);
2973 for (i
= 0; i
< srcWidth
; i
++) {
2975 dstRow
[i
] = depth
[i
] << 8 | (dstRow
[i
] & 0x000000FF);
2977 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF00) | (stencil
[i
] & 0xFF);
2980 src
+= srcRowStride
;
2981 dstRow
+= dstRowStride
/ sizeof(GLuint
);
2990 * Store a combined depth/stencil texture image.
2993 _mesa_texstore_s8_z24(TEXSTORE_PARAMS
)
2995 const GLuint depthScale
= 0xffffff;
2996 const GLint srcRowStride
2997 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3001 ASSERT(dstFormat
== MESA_FORMAT_S8_Z24
);
3002 ASSERT(srcFormat
== GL_DEPTH_STENCIL_EXT
||
3003 srcFormat
== GL_DEPTH_COMPONENT
||
3004 srcFormat
== GL_STENCIL_INDEX
);
3005 ASSERT(srcFormat
!= GL_DEPTH_STENCIL_EXT
||
3006 srcType
== GL_UNSIGNED_INT_24_8_EXT
);
3008 for (img
= 0; img
< srcDepth
; img
++) {
3009 GLuint
*dstRow
= (GLuint
*) dstAddr
3010 + dstImageOffsets
[dstZoffset
+ img
]
3011 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3014 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3015 srcWidth
, srcHeight
,
3018 for (row
= 0; row
< srcHeight
; row
++) {
3019 GLuint depth
[MAX_WIDTH
];
3020 GLubyte stencil
[MAX_WIDTH
];
3022 GLboolean keepdepth
= GL_FALSE
, keepstencil
= GL_FALSE
;
3024 if (srcFormat
== GL_DEPTH_COMPONENT
) { /* preserve stencil */
3025 keepstencil
= GL_TRUE
;
3027 else if (srcFormat
== GL_STENCIL_INDEX
) { /* preserve depth */
3028 keepdepth
= GL_TRUE
;
3031 if (keepdepth
== GL_FALSE
)
3032 /* the 24 depth bits will be in the low position: */
3033 _mesa_unpack_depth_span(ctx
, srcWidth
,
3034 GL_UNSIGNED_INT
, /* dst type */
3035 keepstencil
? depth
: dstRow
, /* dst addr */
3037 srcType
, src
, srcPacking
);
3039 if (keepstencil
== GL_FALSE
)
3040 /* get the 8-bit stencil values */
3041 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3042 GL_UNSIGNED_BYTE
, /* dst type */
3043 stencil
, /* dst addr */
3044 srcType
, src
, srcPacking
,
3045 ctx
->_ImageTransferState
);
3047 /* merge stencil values into depth values */
3048 for (i
= 0; i
< srcWidth
; i
++) {
3050 dstRow
[i
] = depth
[i
] | (dstRow
[i
] & 0xFF000000);
3052 dstRow
[i
] = (dstRow
[i
] & 0xFFFFFF) | (stencil
[i
] << 24);
3055 src
+= srcRowStride
;
3056 dstRow
+= dstRowStride
/ sizeof(GLuint
);
3064 * Store simple 8-bit/value stencil texture data.
3067 _mesa_texstore_s8(TEXSTORE_PARAMS
)
3069 ASSERT(dstFormat
== MESA_FORMAT_S8
);
3070 ASSERT(srcFormat
== GL_STENCIL_INDEX
);
3072 if (!ctx
->_ImageTransferState
&&
3073 !srcPacking
->SwapBytes
&&
3074 baseInternalFormat
== srcFormat
&&
3075 srcType
== GL_UNSIGNED_BYTE
) {
3076 /* simple memcpy path */
3077 memcpy_texture(ctx
, dims
,
3078 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3081 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3082 srcAddr
, srcPacking
);
3085 const GLint srcRowStride
3086 = _mesa_image_row_stride(srcPacking
, srcWidth
, srcFormat
, srcType
)
3090 for (img
= 0; img
< srcDepth
; img
++) {
3091 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3092 + dstImageOffsets
[dstZoffset
+ img
]
3093 + dstYoffset
* dstRowStride
/ sizeof(GLuint
)
3096 = (const GLuint
*) _mesa_image_address(dims
, srcPacking
, srcAddr
,
3097 srcWidth
, srcHeight
,
3100 for (row
= 0; row
< srcHeight
; row
++) {
3101 GLubyte stencil
[MAX_WIDTH
];
3104 /* get the 8-bit stencil values */
3105 _mesa_unpack_stencil_span(ctx
, srcWidth
,
3106 GL_UNSIGNED_BYTE
, /* dst type */
3107 stencil
, /* dst addr */
3108 srcType
, src
, srcPacking
,
3109 ctx
->_ImageTransferState
);
3110 /* merge stencil values into depth values */
3111 for (i
= 0; i
< srcWidth
; i
++)
3112 dstRow
[i
] = stencil
[i
];
3114 src
+= srcRowStride
;
3115 dstRow
+= dstRowStride
/ sizeof(GLubyte
);
3126 * Store an image in any of the formats:
3127 * _mesa_texformat_rgba_float32
3128 * _mesa_texformat_rgb_float32
3129 * _mesa_texformat_alpha_float32
3130 * _mesa_texformat_luminance_float32
3131 * _mesa_texformat_luminance_alpha_float32
3132 * _mesa_texformat_intensity_float32
3135 _mesa_texstore_rgba_float32(TEXSTORE_PARAMS
)
3137 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3138 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3139 const GLint components
= _mesa_components_in_format(baseFormat
);
3141 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT32
||
3142 dstFormat
== MESA_FORMAT_RGB_FLOAT32
||
3143 dstFormat
== MESA_FORMAT_ALPHA_FLOAT32
||
3144 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT32
||
3145 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
||
3146 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT32
);
3147 ASSERT(baseInternalFormat
== GL_RGBA
||
3148 baseInternalFormat
== GL_RGB
||
3149 baseInternalFormat
== GL_ALPHA
||
3150 baseInternalFormat
== GL_LUMINANCE
||
3151 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3152 baseInternalFormat
== GL_INTENSITY
);
3153 ASSERT(texelBytes
== components
* sizeof(GLfloat
));
3155 if (!ctx
->_ImageTransferState
&&
3156 !srcPacking
->SwapBytes
&&
3157 baseInternalFormat
== srcFormat
&&
3158 srcType
== GL_FLOAT
) {
3159 /* simple memcpy path */
3160 memcpy_texture(ctx
, dims
,
3161 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3164 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3165 srcAddr
, srcPacking
);
3169 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3172 srcWidth
, srcHeight
, srcDepth
,
3173 srcFormat
, srcType
, srcAddr
,
3175 const GLfloat
*srcRow
= tempImage
;
3180 bytesPerRow
= srcWidth
* components
* sizeof(GLfloat
);
3181 for (img
= 0; img
< srcDepth
; img
++) {
3182 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3183 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3184 + dstYoffset
* dstRowStride
3185 + dstXoffset
* texelBytes
;
3186 for (row
= 0; row
< srcHeight
; row
++) {
3187 memcpy(dstRow
, srcRow
, bytesPerRow
);
3188 dstRow
+= dstRowStride
;
3189 srcRow
+= srcWidth
* components
;
3193 free((void *) tempImage
);
3201 * As above, but store 16-bit floats.
3204 _mesa_texstore_rgba_float16(TEXSTORE_PARAMS
)
3206 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3207 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3208 const GLint components
= _mesa_components_in_format(baseFormat
);
3210 ASSERT(dstFormat
== MESA_FORMAT_RGBA_FLOAT16
||
3211 dstFormat
== MESA_FORMAT_RGB_FLOAT16
||
3212 dstFormat
== MESA_FORMAT_ALPHA_FLOAT16
||
3213 dstFormat
== MESA_FORMAT_LUMINANCE_FLOAT16
||
3214 dstFormat
== MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
||
3215 dstFormat
== MESA_FORMAT_INTENSITY_FLOAT16
);
3216 ASSERT(baseInternalFormat
== GL_RGBA
||
3217 baseInternalFormat
== GL_RGB
||
3218 baseInternalFormat
== GL_ALPHA
||
3219 baseInternalFormat
== GL_LUMINANCE
||
3220 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3221 baseInternalFormat
== GL_INTENSITY
);
3222 ASSERT(texelBytes
== components
* sizeof(GLhalfARB
));
3224 if (!ctx
->_ImageTransferState
&&
3225 !srcPacking
->SwapBytes
&&
3226 baseInternalFormat
== srcFormat
&&
3227 srcType
== GL_HALF_FLOAT_ARB
) {
3228 /* simple memcpy path */
3229 memcpy_texture(ctx
, dims
,
3230 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3233 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3234 srcAddr
, srcPacking
);
3238 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3241 srcWidth
, srcHeight
, srcDepth
,
3242 srcFormat
, srcType
, srcAddr
,
3244 const GLfloat
*src
= tempImage
;
3248 for (img
= 0; img
< srcDepth
; img
++) {
3249 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3250 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3251 + dstYoffset
* dstRowStride
3252 + dstXoffset
* texelBytes
;
3253 for (row
= 0; row
< srcHeight
; row
++) {
3254 GLhalfARB
*dstTexel
= (GLhalfARB
*) dstRow
;
3256 for (i
= 0; i
< srcWidth
* components
; i
++) {
3257 dstTexel
[i
] = _mesa_float_to_half(src
[i
]);
3259 dstRow
+= dstRowStride
;
3260 src
+= srcWidth
* components
;
3264 free((void *) tempImage
);
3270 /* non-normalized, signed int8 */
3272 _mesa_texstore_rgba_int8(TEXSTORE_PARAMS
)
3274 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3275 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3276 const GLint components
= _mesa_components_in_format(baseFormat
);
3278 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT8
);
3279 ASSERT(baseInternalFormat
== GL_RGBA
||
3280 baseInternalFormat
== GL_RGB
||
3281 baseInternalFormat
== GL_ALPHA
||
3282 baseInternalFormat
== GL_LUMINANCE
||
3283 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3284 baseInternalFormat
== GL_INTENSITY
);
3285 ASSERT(texelBytes
== components
* sizeof(GLbyte
));
3287 if (!ctx
->_ImageTransferState
&&
3288 !srcPacking
->SwapBytes
&&
3289 baseInternalFormat
== srcFormat
&&
3290 srcType
== GL_BYTE
) {
3291 /* simple memcpy path */
3292 memcpy_texture(ctx
, dims
,
3293 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3296 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3297 srcAddr
, srcPacking
);
3301 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3304 srcWidth
, srcHeight
, srcDepth
,
3305 srcFormat
, srcType
, srcAddr
,
3307 const GLfloat
*src
= tempImage
;
3311 for (img
= 0; img
< srcDepth
; img
++) {
3312 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3313 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3314 + dstYoffset
* dstRowStride
3315 + dstXoffset
* texelBytes
;
3316 for (row
= 0; row
< srcHeight
; row
++) {
3317 GLbyte
*dstTexel
= (GLbyte
*) dstRow
;
3319 for (i
= 0; i
< srcWidth
* components
; i
++) {
3320 dstTexel
[i
] = (GLbyte
) src
[i
];
3322 dstRow
+= dstRowStride
;
3323 src
+= srcWidth
* components
;
3327 free((void *) tempImage
);
3333 /* non-normalized, signed int16 */
3335 _mesa_texstore_rgba_int16(TEXSTORE_PARAMS
)
3337 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3338 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3339 const GLint components
= _mesa_components_in_format(baseFormat
);
3341 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT16
);
3342 ASSERT(baseInternalFormat
== GL_RGBA
||
3343 baseInternalFormat
== GL_RGB
||
3344 baseInternalFormat
== GL_ALPHA
||
3345 baseInternalFormat
== GL_LUMINANCE
||
3346 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3347 baseInternalFormat
== GL_INTENSITY
);
3348 ASSERT(texelBytes
== components
* sizeof(GLshort
));
3350 if (!ctx
->_ImageTransferState
&&
3351 !srcPacking
->SwapBytes
&&
3352 baseInternalFormat
== srcFormat
&&
3353 srcType
== GL_SHORT
) {
3354 /* simple memcpy path */
3355 memcpy_texture(ctx
, dims
,
3356 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3359 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3360 srcAddr
, srcPacking
);
3364 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3367 srcWidth
, srcHeight
, srcDepth
,
3368 srcFormat
, srcType
, srcAddr
,
3370 const GLfloat
*src
= tempImage
;
3374 for (img
= 0; img
< srcDepth
; img
++) {
3375 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3376 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3377 + dstYoffset
* dstRowStride
3378 + dstXoffset
* texelBytes
;
3379 for (row
= 0; row
< srcHeight
; row
++) {
3380 GLshort
*dstTexel
= (GLshort
*) dstRow
;
3382 for (i
= 0; i
< srcWidth
* components
; i
++) {
3383 dstTexel
[i
] = (GLint
) src
[i
];
3385 dstRow
+= dstRowStride
;
3386 src
+= srcWidth
* components
;
3390 free((void *) tempImage
);
3396 /* non-normalized, signed int32 */
3398 _mesa_texstore_rgba_int32(TEXSTORE_PARAMS
)
3400 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3401 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3402 const GLint components
= _mesa_components_in_format(baseFormat
);
3404 ASSERT(dstFormat
== MESA_FORMAT_RGBA_INT32
);
3405 ASSERT(baseInternalFormat
== GL_RGBA
||
3406 baseInternalFormat
== GL_RGB
||
3407 baseInternalFormat
== GL_ALPHA
||
3408 baseInternalFormat
== GL_LUMINANCE
||
3409 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3410 baseInternalFormat
== GL_INTENSITY
);
3411 ASSERT(texelBytes
== components
* sizeof(GLint
));
3413 if (!ctx
->_ImageTransferState
&&
3414 !srcPacking
->SwapBytes
&&
3415 baseInternalFormat
== srcFormat
&&
3416 srcType
== GL_INT
) {
3417 /* simple memcpy path */
3418 memcpy_texture(ctx
, dims
,
3419 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3422 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3423 srcAddr
, srcPacking
);
3427 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3430 srcWidth
, srcHeight
, srcDepth
,
3431 srcFormat
, srcType
, srcAddr
,
3433 const GLfloat
*src
= tempImage
;
3437 for (img
= 0; img
< srcDepth
; img
++) {
3438 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3439 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3440 + dstYoffset
* dstRowStride
3441 + dstXoffset
* texelBytes
;
3442 for (row
= 0; row
< srcHeight
; row
++) {
3443 GLint
*dstTexel
= (GLint
*) dstRow
;
3445 for (i
= 0; i
< srcWidth
* components
; i
++) {
3446 dstTexel
[i
] = (GLint
) src
[i
];
3448 dstRow
+= dstRowStride
;
3449 src
+= srcWidth
* components
;
3453 free((void *) tempImage
);
3459 /* non-normalized, unsigned int8 */
3461 _mesa_texstore_rgba_uint8(TEXSTORE_PARAMS
)
3463 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3464 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3465 const GLint components
= _mesa_components_in_format(baseFormat
);
3467 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT8
);
3468 ASSERT(baseInternalFormat
== GL_RGBA
||
3469 baseInternalFormat
== GL_RGB
||
3470 baseInternalFormat
== GL_ALPHA
||
3471 baseInternalFormat
== GL_LUMINANCE
||
3472 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3473 baseInternalFormat
== GL_INTENSITY
);
3474 ASSERT(texelBytes
== components
* sizeof(GLubyte
));
3476 if (!ctx
->_ImageTransferState
&&
3477 !srcPacking
->SwapBytes
&&
3478 baseInternalFormat
== srcFormat
&&
3479 srcType
== GL_UNSIGNED_BYTE
) {
3480 /* simple memcpy path */
3481 memcpy_texture(ctx
, dims
,
3482 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3485 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3486 srcAddr
, srcPacking
);
3490 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3493 srcWidth
, srcHeight
, srcDepth
,
3494 srcFormat
, srcType
, srcAddr
,
3496 const GLfloat
*src
= tempImage
;
3500 for (img
= 0; img
< srcDepth
; img
++) {
3501 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3502 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3503 + dstYoffset
* dstRowStride
3504 + dstXoffset
* texelBytes
;
3505 for (row
= 0; row
< srcHeight
; row
++) {
3506 GLubyte
*dstTexel
= (GLubyte
*) dstRow
;
3508 for (i
= 0; i
< srcWidth
* components
; i
++) {
3509 dstTexel
[i
] = (GLubyte
) src
[i
];
3511 dstRow
+= dstRowStride
;
3512 src
+= srcWidth
* components
;
3516 free((void *) tempImage
);
3522 /* non-normalized, unsigned int16 */
3524 _mesa_texstore_rgba_uint16(TEXSTORE_PARAMS
)
3526 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3527 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3528 const GLint components
= _mesa_components_in_format(baseFormat
);
3530 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT16
);
3531 ASSERT(baseInternalFormat
== GL_RGBA
||
3532 baseInternalFormat
== GL_RGB
||
3533 baseInternalFormat
== GL_ALPHA
||
3534 baseInternalFormat
== GL_LUMINANCE
||
3535 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3536 baseInternalFormat
== GL_INTENSITY
);
3537 ASSERT(texelBytes
== components
* sizeof(GLushort
));
3539 if (!ctx
->_ImageTransferState
&&
3540 !srcPacking
->SwapBytes
&&
3541 baseInternalFormat
== srcFormat
&&
3542 srcType
== GL_UNSIGNED_SHORT
) {
3543 /* simple memcpy path */
3544 memcpy_texture(ctx
, dims
,
3545 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3548 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3549 srcAddr
, srcPacking
);
3553 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3556 srcWidth
, srcHeight
, srcDepth
,
3557 srcFormat
, srcType
, srcAddr
,
3559 const GLfloat
*src
= tempImage
;
3563 for (img
= 0; img
< srcDepth
; img
++) {
3564 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3565 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3566 + dstYoffset
* dstRowStride
3567 + dstXoffset
* texelBytes
;
3568 for (row
= 0; row
< srcHeight
; row
++) {
3569 GLushort
*dstTexel
= (GLushort
*) dstRow
;
3571 for (i
= 0; i
< srcWidth
* components
; i
++) {
3572 dstTexel
[i
] = (GLushort
) src
[i
];
3574 dstRow
+= dstRowStride
;
3575 src
+= srcWidth
* components
;
3579 free((void *) tempImage
);
3585 /* non-normalized, unsigned int32 */
3587 _mesa_texstore_rgba_uint32(TEXSTORE_PARAMS
)
3589 const GLuint texelBytes
= _mesa_get_format_bytes(dstFormat
);
3590 const GLenum baseFormat
= _mesa_get_format_base_format(dstFormat
);
3591 const GLint components
= _mesa_components_in_format(baseFormat
);
3593 ASSERT(dstFormat
== MESA_FORMAT_RGBA_UINT32
);
3594 ASSERT(baseInternalFormat
== GL_RGBA
||
3595 baseInternalFormat
== GL_RGB
||
3596 baseInternalFormat
== GL_ALPHA
||
3597 baseInternalFormat
== GL_LUMINANCE
||
3598 baseInternalFormat
== GL_LUMINANCE_ALPHA
||
3599 baseInternalFormat
== GL_INTENSITY
);
3600 ASSERT(texelBytes
== components
* sizeof(GLuint
));
3602 if (!ctx
->_ImageTransferState
&&
3603 !srcPacking
->SwapBytes
&&
3604 baseInternalFormat
== srcFormat
&&
3605 srcType
== GL_UNSIGNED_INT
) {
3606 /* simple memcpy path */
3607 memcpy_texture(ctx
, dims
,
3608 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3611 srcWidth
, srcHeight
, srcDepth
, srcFormat
, srcType
,
3612 srcAddr
, srcPacking
);
3616 const GLfloat
*tempImage
= make_temp_float_image(ctx
, dims
,
3619 srcWidth
, srcHeight
, srcDepth
,
3620 srcFormat
, srcType
, srcAddr
,
3622 const GLfloat
*src
= tempImage
;
3626 for (img
= 0; img
< srcDepth
; img
++) {
3627 GLubyte
*dstRow
= (GLubyte
*) dstAddr
3628 + dstImageOffsets
[dstZoffset
+ img
] * texelBytes
3629 + dstYoffset
* dstRowStride
3630 + dstXoffset
* texelBytes
;
3631 for (row
= 0; row
< srcHeight
; row
++) {
3632 GLuint
*dstTexel
= (GLuint
*) dstRow
;
3634 for (i
= 0; i
< srcWidth
* components
; i
++) {
3635 dstTexel
[i
] = (GLuint
) src
[i
];
3637 dstRow
+= dstRowStride
;
3638 src
+= srcWidth
* components
;
3642 free((void *) tempImage
);
3650 #if FEATURE_EXT_texture_sRGB
3652 _mesa_texstore_srgb8(TEXSTORE_PARAMS
)
3654 gl_format newDstFormat
;
3657 ASSERT(dstFormat
== MESA_FORMAT_SRGB8
);
3659 /* reuse normal rgb texstore code */
3660 newDstFormat
= MESA_FORMAT_RGB888
;
3662 k
= _mesa_texstore_rgb888(ctx
, dims
, baseInternalFormat
,
3663 newDstFormat
, dstAddr
,
3664 dstXoffset
, dstYoffset
, dstZoffset
,
3665 dstRowStride
, dstImageOffsets
,
3666 srcWidth
, srcHeight
, srcDepth
,
3668 srcAddr
, srcPacking
);
3674 _mesa_texstore_srgba8(TEXSTORE_PARAMS
)
3676 gl_format newDstFormat
;
3679 ASSERT(dstFormat
== MESA_FORMAT_SRGBA8
);
3681 /* reuse normal rgba texstore code */
3682 newDstFormat
= MESA_FORMAT_RGBA8888
;
3683 k
= _mesa_texstore_rgba8888(ctx
, dims
, baseInternalFormat
,
3684 newDstFormat
, dstAddr
,
3685 dstXoffset
, dstYoffset
, dstZoffset
,
3686 dstRowStride
, dstImageOffsets
,
3687 srcWidth
, srcHeight
, srcDepth
,
3689 srcAddr
, srcPacking
);
3695 _mesa_texstore_sargb8(TEXSTORE_PARAMS
)
3697 gl_format newDstFormat
;
3700 ASSERT(dstFormat
== MESA_FORMAT_SARGB8
);
3702 /* reuse normal rgba texstore code */
3703 newDstFormat
= MESA_FORMAT_ARGB8888
;
3705 k
= _mesa_texstore_argb8888(ctx
, dims
, baseInternalFormat
,
3706 newDstFormat
, dstAddr
,
3707 dstXoffset
, dstYoffset
, dstZoffset
,
3708 dstRowStride
, dstImageOffsets
,
3709 srcWidth
, srcHeight
, srcDepth
,
3711 srcAddr
, srcPacking
);
3717 _mesa_texstore_sl8(TEXSTORE_PARAMS
)
3719 gl_format newDstFormat
;
3722 ASSERT(dstFormat
== MESA_FORMAT_SL8
);
3724 newDstFormat
= MESA_FORMAT_L8
;
3726 /* _mesa_textore_a8 handles luminance8 too */
3727 k
= _mesa_texstore_a8(ctx
, dims
, baseInternalFormat
,
3728 newDstFormat
, dstAddr
,
3729 dstXoffset
, dstYoffset
, dstZoffset
,
3730 dstRowStride
, dstImageOffsets
,
3731 srcWidth
, srcHeight
, srcDepth
,
3733 srcAddr
, srcPacking
);
3739 _mesa_texstore_sla8(TEXSTORE_PARAMS
)
3741 gl_format newDstFormat
;
3744 ASSERT(dstFormat
== MESA_FORMAT_SLA8
);
3746 /* reuse normal luminance/alpha texstore code */
3747 newDstFormat
= MESA_FORMAT_AL88
;
3749 k
= _mesa_texstore_unorm88(ctx
, dims
, baseInternalFormat
,
3750 newDstFormat
, dstAddr
,
3751 dstXoffset
, dstYoffset
, dstZoffset
,
3752 dstRowStride
, dstImageOffsets
,
3753 srcWidth
, srcHeight
, srcDepth
,
3755 srcAddr
, srcPacking
);
3761 /* these are used only in texstore_funcs[] below */
3762 #define _mesa_texstore_srgb8 NULL
3763 #define _mesa_texstore_srgba8 NULL
3764 #define _mesa_texstore_sargb8 NULL
3765 #define _mesa_texstore_sl8 NULL
3766 #define _mesa_texstore_sla8 NULL
3768 #endif /* FEATURE_EXT_texture_sRGB */
3774 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
3775 * XXX this is somewhat temporary.
3777 static const struct {
3779 StoreTexImageFunc Store
;
3781 texstore_funcs
[MESA_FORMAT_COUNT
] =
3783 { MESA_FORMAT_NONE
, NULL
},
3784 { MESA_FORMAT_RGBA8888
, _mesa_texstore_rgba8888
},
3785 { MESA_FORMAT_RGBA8888_REV
, _mesa_texstore_rgba8888
},
3786 { MESA_FORMAT_ARGB8888
, _mesa_texstore_argb8888
},
3787 { MESA_FORMAT_ARGB8888_REV
, _mesa_texstore_argb8888
},
3788 { MESA_FORMAT_XRGB8888
, _mesa_texstore_argb8888
},
3789 { MESA_FORMAT_XRGB8888_REV
, _mesa_texstore_argb8888
},
3790 { MESA_FORMAT_RGB888
, _mesa_texstore_rgb888
},
3791 { MESA_FORMAT_BGR888
, _mesa_texstore_bgr888
},
3792 { MESA_FORMAT_RGB565
, _mesa_texstore_rgb565
},
3793 { MESA_FORMAT_RGB565_REV
, _mesa_texstore_rgb565
},
3794 { MESA_FORMAT_ARGB4444
, _mesa_texstore_argb4444
},
3795 { MESA_FORMAT_ARGB4444_REV
, _mesa_texstore_argb4444
},
3796 { MESA_FORMAT_RGBA5551
, _mesa_texstore_rgba5551
},
3797 { MESA_FORMAT_ARGB1555
, _mesa_texstore_argb1555
},
3798 { MESA_FORMAT_ARGB1555_REV
, _mesa_texstore_argb1555
},
3799 { MESA_FORMAT_AL88
, _mesa_texstore_unorm88
},
3800 { MESA_FORMAT_AL88_REV
, _mesa_texstore_unorm88
},
3801 { MESA_FORMAT_AL1616
, _mesa_texstore_unorm1616
},
3802 { MESA_FORMAT_AL1616_REV
, _mesa_texstore_unorm1616
},
3803 { MESA_FORMAT_RGB332
, _mesa_texstore_rgb332
},
3804 { MESA_FORMAT_A8
, _mesa_texstore_a8
},
3805 { MESA_FORMAT_L8
, _mesa_texstore_a8
},
3806 { MESA_FORMAT_I8
, _mesa_texstore_a8
},
3807 { MESA_FORMAT_CI8
, _mesa_texstore_ci8
},
3808 { MESA_FORMAT_YCBCR
, _mesa_texstore_ycbcr
},
3809 { MESA_FORMAT_YCBCR_REV
, _mesa_texstore_ycbcr
},
3810 { MESA_FORMAT_R8
, _mesa_texstore_a8
},
3811 { MESA_FORMAT_RG88
, _mesa_texstore_unorm88
},
3812 { MESA_FORMAT_RG88_REV
, _mesa_texstore_unorm88
},
3813 { MESA_FORMAT_R16
, _mesa_texstore_r16
},
3814 { MESA_FORMAT_RG1616
, _mesa_texstore_unorm1616
},
3815 { MESA_FORMAT_RG1616_REV
, _mesa_texstore_unorm1616
},
3816 { MESA_FORMAT_Z24_S8
, _mesa_texstore_z24_s8
},
3817 { MESA_FORMAT_S8_Z24
, _mesa_texstore_s8_z24
},
3818 { MESA_FORMAT_Z16
, _mesa_texstore_z16
},
3819 { MESA_FORMAT_X8_Z24
, _mesa_texstore_x8_z24
},
3820 { MESA_FORMAT_Z24_X8
, _mesa_texstore_z24_x8
},
3821 { MESA_FORMAT_Z32
, _mesa_texstore_z32
},
3822 { MESA_FORMAT_S8
, _mesa_texstore_s8
},
3823 { MESA_FORMAT_SRGB8
, _mesa_texstore_srgb8
},
3824 { MESA_FORMAT_SRGBA8
, _mesa_texstore_srgba8
},
3825 { MESA_FORMAT_SARGB8
, _mesa_texstore_sargb8
},
3826 { MESA_FORMAT_SL8
, _mesa_texstore_sl8
},
3827 { MESA_FORMAT_SLA8
, _mesa_texstore_sla8
},
3828 { MESA_FORMAT_SRGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3829 { MESA_FORMAT_SRGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3830 { MESA_FORMAT_SRGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3831 { MESA_FORMAT_SRGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3832 { MESA_FORMAT_RGB_FXT1
, _mesa_texstore_rgb_fxt1
},
3833 { MESA_FORMAT_RGBA_FXT1
, _mesa_texstore_rgba_fxt1
},
3834 { MESA_FORMAT_RGB_DXT1
, _mesa_texstore_rgb_dxt1
},
3835 { MESA_FORMAT_RGBA_DXT1
, _mesa_texstore_rgba_dxt1
},
3836 { MESA_FORMAT_RGBA_DXT3
, _mesa_texstore_rgba_dxt3
},
3837 { MESA_FORMAT_RGBA_DXT5
, _mesa_texstore_rgba_dxt5
},
3838 { MESA_FORMAT_RGBA_FLOAT32
, _mesa_texstore_rgba_float32
},
3839 { MESA_FORMAT_RGBA_FLOAT16
, _mesa_texstore_rgba_float16
},
3840 { MESA_FORMAT_RGB_FLOAT32
, _mesa_texstore_rgba_float32
},
3841 { MESA_FORMAT_RGB_FLOAT16
, _mesa_texstore_rgba_float16
},
3842 { MESA_FORMAT_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3843 { MESA_FORMAT_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3844 { MESA_FORMAT_LUMINANCE_FLOAT32
, _mesa_texstore_rgba_float32
},
3845 { MESA_FORMAT_LUMINANCE_FLOAT16
, _mesa_texstore_rgba_float16
},
3846 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32
, _mesa_texstore_rgba_float32
},
3847 { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16
, _mesa_texstore_rgba_float16
},
3848 { MESA_FORMAT_INTENSITY_FLOAT32
, _mesa_texstore_rgba_float32
},
3849 { MESA_FORMAT_INTENSITY_FLOAT16
, _mesa_texstore_rgba_float16
},
3851 { MESA_FORMAT_RGBA_INT8
, _mesa_texstore_rgba_int8
},
3852 { MESA_FORMAT_RGBA_INT16
, _mesa_texstore_rgba_int16
},
3853 { MESA_FORMAT_RGBA_INT32
, _mesa_texstore_rgba_int32
},
3854 { MESA_FORMAT_RGBA_UINT8
, _mesa_texstore_rgba_uint8
},
3855 { MESA_FORMAT_RGBA_UINT16
, _mesa_texstore_rgba_uint16
},
3856 { MESA_FORMAT_RGBA_UINT32
, _mesa_texstore_rgba_uint32
},
3858 { MESA_FORMAT_DUDV8
, _mesa_texstore_dudv8
},
3860 { MESA_FORMAT_SIGNED_R8
, _mesa_texstore_signed_r8
},
3861 { MESA_FORMAT_SIGNED_RG88
, _mesa_texstore_signed_rg88
},
3862 { MESA_FORMAT_SIGNED_RGBX8888
, _mesa_texstore_signed_rgbx8888
},
3864 { MESA_FORMAT_SIGNED_RGBA8888
, _mesa_texstore_signed_rgba8888
},
3865 { MESA_FORMAT_SIGNED_RGBA8888_REV
, _mesa_texstore_signed_rgba8888
},
3867 { MESA_FORMAT_SIGNED_R_16
, _mesa_texstore_signed_rgba_16
},
3868 { MESA_FORMAT_SIGNED_RG_16
, _mesa_texstore_signed_rgba_16
},
3869 { MESA_FORMAT_SIGNED_RGB_16
, _mesa_texstore_signed_rgba_16
},
3870 { MESA_FORMAT_SIGNED_RGBA_16
, _mesa_texstore_signed_rgba_16
},
3871 { MESA_FORMAT_RGBA_16
, _mesa_texstore_rgba_16
}
3876 _mesa_texstore_null(TEXSTORE_PARAMS
)
3878 (void) ctx
; (void) dims
;
3879 (void) baseInternalFormat
;
3882 (void) dstXoffset
; (void) dstYoffset
; (void) dstZoffset
;
3883 (void) dstRowStride
; (void) dstImageOffsets
;
3884 (void) srcWidth
; (void) srcHeight
; (void) srcDepth
;
3885 (void) srcFormat
; (void) srcType
;
3889 /* should never happen */
3890 _mesa_problem(NULL
, "_mesa_texstore_null() is called");
3896 * Return the StoreTexImageFunc pointer to store an image in the given format.
3898 static StoreTexImageFunc
3899 _mesa_get_texstore_func(gl_format format
)
3903 for (i
= 0; i
< MESA_FORMAT_COUNT
; i
++) {
3904 ASSERT(texstore_funcs
[i
].Name
== i
);
3907 ASSERT(texstore_funcs
[format
].Name
== format
);
3909 if (texstore_funcs
[format
].Store
)
3910 return texstore_funcs
[format
].Store
;
3912 return _mesa_texstore_null
;
3917 * Store user data into texture memory.
3918 * Called via glTex[Sub]Image1/2/3D()
3921 _mesa_texstore(TEXSTORE_PARAMS
)
3923 StoreTexImageFunc storeImage
;
3926 storeImage
= _mesa_get_texstore_func(dstFormat
);
3928 success
= storeImage(ctx
, dims
, baseInternalFormat
,
3929 dstFormat
, dstAddr
, dstXoffset
, dstYoffset
, dstZoffset
,
3930 dstRowStride
, dstImageOffsets
,
3931 srcWidth
, srcHeight
, srcDepth
,
3932 srcFormat
, srcType
, srcAddr
, srcPacking
);
3938 * Check if an unpack PBO is active prior to fetching a texture image.
3939 * If so, do bounds checking and map the buffer into main memory.
3940 * Any errors detected will be recorded.
3941 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3944 _mesa_validate_pbo_teximage(struct gl_context
*ctx
, GLuint dimensions
,
3945 GLsizei width
, GLsizei height
, GLsizei depth
,
3946 GLenum format
, GLenum type
, const GLvoid
*pixels
,
3947 const struct gl_pixelstore_attrib
*unpack
,
3948 const char *funcName
)
3952 if (!_mesa_is_bufferobj(unpack
->BufferObj
)) {
3956 if (!_mesa_validate_pbo_access(dimensions
, unpack
, width
, height
, depth
,
3957 format
, type
, pixels
)) {
3958 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3962 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
3963 GL_READ_ONLY_ARB
, unpack
->BufferObj
);
3965 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
3969 return ADD_POINTERS(buf
, pixels
);
3974 * Check if an unpack PBO is active prior to fetching a compressed texture
3976 * If so, do bounds checking and map the buffer into main memory.
3977 * Any errors detected will be recorded.
3978 * The caller _must_ call _mesa_unmap_teximage_pbo() too!
3981 _mesa_validate_pbo_compressed_teximage(struct gl_context
*ctx
,
3982 GLsizei imageSize
, const GLvoid
*pixels
,
3983 const struct gl_pixelstore_attrib
*packing
,
3984 const char *funcName
)
3988 if (!_mesa_is_bufferobj(packing
->BufferObj
)) {
3989 /* not using a PBO - return pointer unchanged */
3992 if ((const GLubyte
*) pixels
+ imageSize
>
3993 ((const GLubyte
*) 0) + packing
->BufferObj
->Size
) {
3994 /* out of bounds read! */
3995 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(invalid PBO access");
3999 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4000 GL_READ_ONLY_ARB
, packing
->BufferObj
);
4002 _mesa_error(ctx
, GL_INVALID_OPERATION
, funcName
, "(PBO is mapped");
4006 return ADD_POINTERS(buf
, pixels
);
4011 * This function must be called after either of the validate_pbo_*_teximage()
4012 * functions. It unmaps the PBO buffer if it was mapped earlier.
4015 _mesa_unmap_teximage_pbo(struct gl_context
*ctx
,
4016 const struct gl_pixelstore_attrib
*unpack
)
4018 if (_mesa_is_bufferobj(unpack
->BufferObj
)) {
4019 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
4025 /** Return texture size in bytes */
4027 texture_size(const struct gl_texture_image
*texImage
)
4029 GLuint sz
= _mesa_format_image_size(texImage
->TexFormat
, texImage
->Width
,
4030 texImage
->Height
, texImage
->Depth
);
4035 /** Return row stride in bytes */
4037 texture_row_stride(const struct gl_texture_image
*texImage
)
4039 GLuint stride
= _mesa_format_row_stride(texImage
->TexFormat
,
4047 * This is the software fallback for Driver.TexImage1D()
4048 * and Driver.CopyTexImage1D().
4049 * \sa _mesa_store_teximage2d()
4052 _mesa_store_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4053 GLint internalFormat
,
4054 GLint width
, GLint border
,
4055 GLenum format
, GLenum type
, const GLvoid
*pixels
,
4056 const struct gl_pixelstore_attrib
*packing
,
4057 struct gl_texture_object
*texObj
,
4058 struct gl_texture_image
*texImage
)
4063 /* allocate memory */
4064 sizeInBytes
= texture_size(texImage
);
4065 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4066 if (!texImage
->Data
) {
4067 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4071 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4072 pixels
, packing
, "glTexImage1D");
4074 /* Note: we check for a NULL image pointer here, _after_ we allocated
4075 * memory for the texture. That's what the GL spec calls for.
4080 const GLint dstRowStride
= 0;
4081 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4082 texImage
->TexFormat
,
4084 0, 0, 0, /* dstX/Y/Zoffset */
4086 texImage
->ImageOffsets
,
4088 format
, type
, pixels
, packing
);
4090 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage1D");
4094 _mesa_unmap_teximage_pbo(ctx
, packing
);
4099 * This is the software fallback for Driver.TexImage2D()
4100 * and Driver.CopyTexImage2D().
4102 * This function is oriented toward storing images in main memory, rather
4103 * than VRAM. Device driver's can easily plug in their own replacement.
4106 _mesa_store_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4107 GLint internalFormat
,
4108 GLint width
, GLint height
, GLint border
,
4109 GLenum format
, GLenum type
, const void *pixels
,
4110 const struct gl_pixelstore_attrib
*packing
,
4111 struct gl_texture_object
*texObj
,
4112 struct gl_texture_image
*texImage
)
4117 /* allocate memory */
4118 sizeInBytes
= texture_size(texImage
);
4119 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4120 if (!texImage
->Data
) {
4121 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4125 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4126 pixels
, packing
, "glTexImage2D");
4128 /* Note: we check for a NULL image pointer here, _after_ we allocated
4129 * memory for the texture. That's what the GL spec calls for.
4134 GLint dstRowStride
= texture_row_stride(texImage
);
4135 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4136 texImage
->TexFormat
,
4138 0, 0, 0, /* dstX/Y/Zoffset */
4140 texImage
->ImageOffsets
,
4142 format
, type
, pixels
, packing
);
4144 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage2D");
4148 _mesa_unmap_teximage_pbo(ctx
, packing
);
4154 * This is the software fallback for Driver.TexImage3D()
4155 * and Driver.CopyTexImage3D().
4156 * \sa _mesa_store_teximage2d()
4159 _mesa_store_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4160 GLint internalFormat
,
4161 GLint width
, GLint height
, GLint depth
, GLint border
,
4162 GLenum format
, GLenum type
, const void *pixels
,
4163 const struct gl_pixelstore_attrib
*packing
,
4164 struct gl_texture_object
*texObj
,
4165 struct gl_texture_image
*texImage
)
4170 /* allocate memory */
4171 sizeInBytes
= texture_size(texImage
);
4172 texImage
->Data
= _mesa_alloc_texmemory(sizeInBytes
);
4173 if (!texImage
->Data
) {
4174 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4178 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4179 type
, pixels
, packing
, "glTexImage3D");
4181 /* Note: we check for a NULL image pointer here, _after_ we allocated
4182 * memory for the texture. That's what the GL spec calls for.
4187 GLint dstRowStride
= texture_row_stride(texImage
);
4188 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4189 texImage
->TexFormat
,
4191 0, 0, 0, /* dstX/Y/Zoffset */
4193 texImage
->ImageOffsets
,
4194 width
, height
, depth
,
4195 format
, type
, pixels
, packing
);
4197 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexImage3D");
4201 _mesa_unmap_teximage_pbo(ctx
, packing
);
4208 * This is the software fallback for Driver.TexSubImage1D()
4209 * and Driver.CopyTexSubImage1D().
4212 _mesa_store_texsubimage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4213 GLint xoffset
, GLint width
,
4214 GLenum format
, GLenum type
, const void *pixels
,
4215 const struct gl_pixelstore_attrib
*packing
,
4216 struct gl_texture_object
*texObj
,
4217 struct gl_texture_image
*texImage
)
4219 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4220 pixels
= _mesa_validate_pbo_teximage(ctx
, 1, width
, 1, 1, format
, type
,
4221 pixels
, packing
, "glTexSubImage1D");
4226 const GLint dstRowStride
= 0;
4227 GLboolean success
= _mesa_texstore(ctx
, 1, texImage
->_BaseFormat
,
4228 texImage
->TexFormat
,
4230 xoffset
, 0, 0, /* offsets */
4232 texImage
->ImageOffsets
,
4234 format
, type
, pixels
, packing
);
4236 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage1D");
4240 _mesa_unmap_teximage_pbo(ctx
, packing
);
4246 * This is the software fallback for Driver.TexSubImage2D()
4247 * and Driver.CopyTexSubImage2D().
4250 _mesa_store_texsubimage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4251 GLint xoffset
, GLint yoffset
,
4252 GLint width
, GLint height
,
4253 GLenum format
, GLenum type
, const void *pixels
,
4254 const struct gl_pixelstore_attrib
*packing
,
4255 struct gl_texture_object
*texObj
,
4256 struct gl_texture_image
*texImage
)
4258 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4259 pixels
= _mesa_validate_pbo_teximage(ctx
, 2, width
, height
, 1, format
, type
,
4260 pixels
, packing
, "glTexSubImage2D");
4265 GLint dstRowStride
= texture_row_stride(texImage
);
4266 GLboolean success
= _mesa_texstore(ctx
, 2, texImage
->_BaseFormat
,
4267 texImage
->TexFormat
,
4269 xoffset
, yoffset
, 0,
4271 texImage
->ImageOffsets
,
4273 format
, type
, pixels
, packing
);
4275 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage2D");
4279 _mesa_unmap_teximage_pbo(ctx
, packing
);
4284 * This is the software fallback for Driver.TexSubImage3D().
4285 * and Driver.CopyTexSubImage3D().
4288 _mesa_store_texsubimage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4289 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4290 GLint width
, GLint height
, GLint depth
,
4291 GLenum format
, GLenum type
, const void *pixels
,
4292 const struct gl_pixelstore_attrib
*packing
,
4293 struct gl_texture_object
*texObj
,
4294 struct gl_texture_image
*texImage
)
4296 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4297 pixels
= _mesa_validate_pbo_teximage(ctx
, 3, width
, height
, depth
, format
,
4298 type
, pixels
, packing
,
4304 GLint dstRowStride
= texture_row_stride(texImage
);
4305 GLboolean success
= _mesa_texstore(ctx
, 3, texImage
->_BaseFormat
,
4306 texImage
->TexFormat
,
4308 xoffset
, yoffset
, zoffset
,
4310 texImage
->ImageOffsets
,
4311 width
, height
, depth
,
4312 format
, type
, pixels
, packing
);
4314 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glTexSubImage3D");
4318 _mesa_unmap_teximage_pbo(ctx
, packing
);
4323 * Fallback for Driver.CompressedTexImage1D()
4326 _mesa_store_compressed_teximage1d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4327 GLint internalFormat
,
4328 GLint width
, GLint border
,
4329 GLsizei imageSize
, const GLvoid
*data
,
4330 struct gl_texture_object
*texObj
,
4331 struct gl_texture_image
*texImage
)
4333 /* this space intentionally left blank */
4335 (void) target
; (void) level
;
4336 (void) internalFormat
;
4337 (void) width
; (void) border
;
4338 (void) imageSize
; (void) data
;
4346 * Fallback for Driver.CompressedTexImage2D()
4349 _mesa_store_compressed_teximage2d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4350 GLint internalFormat
,
4351 GLint width
, GLint height
, GLint border
,
4352 GLsizei imageSize
, const GLvoid
*data
,
4353 struct gl_texture_object
*texObj
,
4354 struct gl_texture_image
*texImage
)
4356 (void) width
; (void) height
; (void) border
;
4358 /* This is pretty simple, basically just do a memcpy without worrying
4359 * about the usual image unpacking or image transfer operations.
4363 ASSERT(texImage
->Width
> 0);
4364 ASSERT(texImage
->Height
> 0);
4365 ASSERT(texImage
->Depth
== 1);
4366 ASSERT(texImage
->Data
== NULL
); /* was freed in glCompressedTexImage2DARB */
4368 /* allocate storage */
4369 texImage
->Data
= _mesa_alloc_texmemory(imageSize
);
4370 if (!texImage
->Data
) {
4371 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glCompressedTexImage2DARB");
4375 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4377 "glCompressedTexImage2D");
4382 memcpy(texImage
->Data
, data
, imageSize
);
4384 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4390 * Fallback for Driver.CompressedTexImage3D()
4393 _mesa_store_compressed_teximage3d(struct gl_context
*ctx
, GLenum target
, GLint level
,
4394 GLint internalFormat
,
4395 GLint width
, GLint height
, GLint depth
,
4397 GLsizei imageSize
, const GLvoid
*data
,
4398 struct gl_texture_object
*texObj
,
4399 struct gl_texture_image
*texImage
)
4401 /* this space intentionally left blank */
4403 (void) target
; (void) level
;
4404 (void) internalFormat
;
4405 (void) width
; (void) height
; (void) depth
;
4407 (void) imageSize
; (void) data
;
4415 * Fallback for Driver.CompressedTexSubImage1D()
4418 _mesa_store_compressed_texsubimage1d(struct gl_context
*ctx
, GLenum target
,
4420 GLint xoffset
, GLsizei width
,
4422 GLsizei imageSize
, const GLvoid
*data
,
4423 struct gl_texture_object
*texObj
,
4424 struct gl_texture_image
*texImage
)
4426 /* there are no compressed 1D texture formats yet */
4428 (void) target
; (void) level
;
4429 (void) xoffset
; (void) width
;
4431 (void) imageSize
; (void) data
;
4438 * Fallback for Driver.CompressedTexSubImage2D()
4441 _mesa_store_compressed_texsubimage2d(struct gl_context
*ctx
, GLenum target
,
4443 GLint xoffset
, GLint yoffset
,
4444 GLsizei width
, GLsizei height
,
4446 GLsizei imageSize
, const GLvoid
*data
,
4447 struct gl_texture_object
*texObj
,
4448 struct gl_texture_image
*texImage
)
4450 GLint bytesPerRow
, destRowStride
, srcRowStride
;
4454 const gl_format texFormat
= texImage
->TexFormat
;
4455 const GLint destWidth
= texImage
->Width
;
4458 _mesa_get_format_block_size(texFormat
, &bw
, &bh
);
4463 /* these should have been caught sooner */
4464 ASSERT((width
% bw
) == 0 || width
== 2 || width
== 1);
4465 ASSERT((height
% bh
) == 0 || height
== 2 || height
== 1);
4466 ASSERT((xoffset
% bw
) == 0);
4467 ASSERT((yoffset
% bh
) == 0);
4469 /* get pointer to src pixels (may be in a pbo which we'll map here) */
4470 data
= _mesa_validate_pbo_compressed_teximage(ctx
, imageSize
, data
,
4472 "glCompressedTexSubImage2D");
4476 srcRowStride
= _mesa_format_row_stride(texFormat
, width
);
4477 src
= (const GLubyte
*) data
;
4479 destRowStride
= _mesa_format_row_stride(texFormat
, destWidth
);
4480 dest
= _mesa_compressed_image_address(xoffset
, yoffset
, 0,
4481 texFormat
, destWidth
,
4482 (GLubyte
*) texImage
->Data
);
4484 bytesPerRow
= srcRowStride
; /* bytes per row of blocks */
4485 rows
= height
/ bh
; /* rows in blocks */
4487 /* copy rows of blocks */
4488 for (i
= 0; i
< rows
; i
++) {
4489 memcpy(dest
, src
, bytesPerRow
);
4490 dest
+= destRowStride
;
4491 src
+= srcRowStride
;
4494 _mesa_unmap_teximage_pbo(ctx
, &ctx
->Unpack
);
4499 * Fallback for Driver.CompressedTexSubImage3D()
4502 _mesa_store_compressed_texsubimage3d(struct gl_context
*ctx
, GLenum target
,
4504 GLint xoffset
, GLint yoffset
, GLint zoffset
,
4505 GLsizei width
, GLsizei height
, GLsizei depth
,
4507 GLsizei imageSize
, const GLvoid
*data
,
4508 struct gl_texture_object
*texObj
,
4509 struct gl_texture_image
*texImage
)
4511 /* there are no compressed 3D texture formats yet */
4513 (void) target
; (void) level
;
4514 (void) xoffset
; (void) yoffset
; (void) zoffset
;
4515 (void) width
; (void) height
; (void) depth
;
4517 (void) imageSize
; (void) data
;