~ubuntu-branches/ubuntu/precise/mesa/precise-updates

« back to all changes in this revision

Viewing changes to src/mesa/main/texstore.c

  • Committer: Package Import Robot
  • Author(s): Robert Hooker
  • Date: 2012-02-02 12:05:48 UTC
  • mfrom: (1.7.1) (3.3.27 sid)
  • Revision ID: package-import@ubuntu.com-20120202120548-nvkma85jq0h4coix
Tags: 8.0~rc2-0ubuntu4
Drop drisearchdir handling, it is no longer needed with multiarch
and dri-alternates being removed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
67
67
#include "texcompress_fxt1.h"
68
68
#include "texcompress_rgtc.h"
69
69
#include "texcompress_s3tc.h"
 
70
#include "texcompress_etc.h"
70
71
#include "teximage.h"
71
72
#include "texstore.h"
72
73
#include "enums.h"
340
341
          logicalBaseFormat == GL_LUMINANCE ||
341
342
          logicalBaseFormat == GL_ALPHA ||
342
343
          logicalBaseFormat == GL_INTENSITY ||
343
 
          logicalBaseFormat == GL_COLOR_INDEX ||
344
344
          logicalBaseFormat == GL_DEPTH_COMPONENT);
345
345
 
346
346
   ASSERT(textureBaseFormat == GL_RGBA ||
351
351
          textureBaseFormat == GL_LUMINANCE ||
352
352
          textureBaseFormat == GL_ALPHA ||
353
353
          textureBaseFormat == GL_INTENSITY ||
354
 
          textureBaseFormat == GL_COLOR_INDEX ||
355
354
          textureBaseFormat == GL_DEPTH_COMPONENT);
356
355
 
357
356
   tempImage = (GLfloat *) malloc(srcWidth * srcHeight * srcDepth
460
459
          textureBaseFormat == GL_RED ||
461
460
          textureBaseFormat == GL_LUMINANCE_ALPHA ||
462
461
          textureBaseFormat == GL_LUMINANCE ||
 
462
          textureBaseFormat == GL_INTENSITY ||
463
463
          textureBaseFormat == GL_ALPHA);
464
464
 
465
465
   tempImage = (GLuint *) malloc(srcWidth * srcHeight * srcDepth
515
515
         for (k = 0; k < texComponents; k++) {
516
516
            GLint j = map[k];
517
517
            if (j == ZERO)
518
 
               newImage[i * texComponents + k] = 0.0F;
 
518
               newImage[i * texComponents + k] = 0;
519
519
            else if (j == ONE)
520
 
               newImage[i * texComponents + k] = 1.0F;
 
520
               newImage[i * texComponents + k] = 1;
521
521
            else
522
522
               newImage[i * texComponents + k] = tempImage[i * logComponents + j];
523
523
         }
533
533
 
534
534
 
535
535
/**
536
 
 * Make a temporary (color) texture image with GLchan components.
 
536
 * Make a temporary (color) texture image with GLubyte components.
537
537
 * Apply all needed pixel unpacking and pixel transfer operations.
538
538
 * Note that there are both logicalBaseFormat and textureBaseFormat parameters.
539
539
 * Suppose the user specifies GL_LUMINANCE as the internal texture format
553
553
 * \param srcType  source image type
554
554
 * \param srcAddr  source image address
555
555
 * \param srcPacking  source image pixel packing
556
 
 * \return resulting image with format = textureBaseFormat and type = GLchan.
 
556
 * \return resulting image with format = textureBaseFormat and type = GLubyte.
557
557
 */
558
 
GLchan *
559
 
_mesa_make_temp_chan_image(struct gl_context *ctx, GLuint dims,
560
 
                           GLenum logicalBaseFormat,
561
 
                           GLenum textureBaseFormat,
562
 
                           GLint srcWidth, GLint srcHeight, GLint srcDepth,
563
 
                           GLenum srcFormat, GLenum srcType,
564
 
                           const GLvoid *srcAddr,
565
 
                           const struct gl_pixelstore_attrib *srcPacking)
 
558
GLubyte *
 
559
_mesa_make_temp_ubyte_image(struct gl_context *ctx, GLuint dims,
 
560
                            GLenum logicalBaseFormat,
 
561
                            GLenum textureBaseFormat,
 
562
                            GLint srcWidth, GLint srcHeight, GLint srcDepth,
 
563
                            GLenum srcFormat, GLenum srcType,
 
564
                            const GLvoid *srcAddr,
 
565
                            const struct gl_pixelstore_attrib *srcPacking)
566
566
{
567
567
   GLuint transferOps = ctx->_ImageTransferState;
568
568
   const GLint components = _mesa_components_in_format(logicalBaseFormat);
569
569
   GLint img, row;
570
 
   GLchan *tempImage, *dst;
 
570
   GLubyte *tempImage, *dst;
571
571
 
572
572
   ASSERT(dims >= 1 && dims <= 3);
573
573
 
590
590
          textureBaseFormat == GL_INTENSITY);
591
591
 
592
592
   /* unpack and transfer the source image */
593
 
   tempImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
594
 
                                       * components * sizeof(GLchan));
 
593
   tempImage = (GLubyte *) malloc(srcWidth * srcHeight * srcDepth
 
594
                                       * components * sizeof(GLubyte));
595
595
   if (!tempImage) {
596
596
      return NULL;
597
597
   }
606
606
                                               srcFormat, srcType,
607
607
                                               img, 0, 0);
608
608
      for (row = 0; row < srcHeight; row++) {
609
 
         _mesa_unpack_color_span_chan(ctx, srcWidth, logicalBaseFormat, dst,
610
 
                                      srcFormat, srcType, src, srcPacking,
611
 
                                      transferOps);
 
609
         _mesa_unpack_color_span_ubyte(ctx, srcWidth, logicalBaseFormat, dst,
 
610
                                       srcFormat, srcType, src, srcPacking,
 
611
                                       transferOps);
612
612
         dst += srcWidth * components;
613
613
         src += srcStride;
614
614
      }
618
618
      /* one more conversion step */
619
619
      GLint texComponents = _mesa_components_in_format(textureBaseFormat);
620
620
      GLint logComponents = _mesa_components_in_format(logicalBaseFormat);
621
 
      GLchan *newImage;
 
621
      GLubyte *newImage;
622
622
      GLint i, n;
623
623
      GLubyte map[6];
624
624
 
631
631
       */
632
632
      ASSERT(texComponents >= logComponents);
633
633
 
634
 
      newImage = (GLchan *) malloc(srcWidth * srcHeight * srcDepth
635
 
                                         * texComponents * sizeof(GLchan));
 
634
      newImage = (GLubyte *) malloc(srcWidth * srcHeight * srcDepth
 
635
                                         * texComponents * sizeof(GLubyte));
636
636
      if (!newImage) {
637
637
         free(tempImage);
638
638
         return NULL;
648
648
            if (j == ZERO)
649
649
               newImage[i * texComponents + k] = 0;
650
650
            else if (j == ONE)
651
 
               newImage[i * texComponents + k] = CHAN_MAX;
 
651
               newImage[i * texComponents + k] = 255;
652
652
            else
653
653
               newImage[i * texComponents + k] = tempImage[i * logComponents + j];
654
654
         }
851
851
                          const GLubyte *rgba2dst,
852
852
                          GLuint dstComponents,
853
853
 
854
 
                          GLvoid *dstAddr,
855
 
                          GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
856
854
                          GLint dstRowStride,
857
 
                          const GLuint *dstImageOffsets,
 
855
                          GLubyte **dstSlices,
858
856
 
859
857
                          GLint srcWidth, GLint srcHeight, GLint srcDepth,
860
858
                          const GLvoid *srcAddr,
897
895
       srcRowStride == srcWidth * srcComponents &&
898
896
       dimensions < 3) {
899
897
      /* 1 and 2D images only */
900
 
      GLubyte *dstImage = (GLubyte *) dstAddr
901
 
         + dstYoffset * dstRowStride
902
 
         + dstXoffset * dstComponents;
 
898
      GLubyte *dstImage = dstSlices[0];
903
899
      swizzle_copy(dstImage, dstComponents, srcImage, srcComponents, map, 
904
900
                   srcWidth * srcHeight);
905
901
   }
907
903
      GLint img, row;
908
904
      for (img = 0; img < srcDepth; img++) {
909
905
         const GLubyte *srcRow = srcImage;
910
 
         GLubyte *dstRow = (GLubyte *) dstAddr
911
 
            + dstImageOffsets[dstZoffset + img] * dstComponents
912
 
            + dstYoffset * dstRowStride
913
 
            + dstXoffset * dstComponents;
 
906
         GLubyte *dstRow = dstSlices[img];
914
907
         for (row = 0; row < srcHeight; row++) {
915
908
            swizzle_copy(dstRow, dstComponents, srcRow, srcComponents, map, srcWidth);
916
909
            dstRow += dstRowStride;
931
924
memcpy_texture(struct gl_context *ctx,
932
925
               GLuint dimensions,
933
926
               gl_format dstFormat,
934
 
               GLvoid *dstAddr,
935
 
               GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,
936
927
               GLint dstRowStride,
937
 
               const GLuint *dstImageOffsets,
 
928
               GLubyte **dstSlices,
938
929
               GLint srcWidth, GLint srcHeight, GLint srcDepth,
939
930
               GLenum srcFormat, GLenum srcType,
940
931
               const GLvoid *srcAddr,
949
940
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
950
941
   const GLint bytesPerRow = srcWidth * texelBytes;
951
942
 
952
 
#if 0
953
 
   /* XXX update/re-enable for dstImageOffsets array */
954
 
   const GLint bytesPerImage = srcHeight * bytesPerRow;
955
 
   const GLint bytesPerTexture = srcDepth * bytesPerImage;
956
 
   GLubyte *dstImage = (GLubyte *) dstAddr
957
 
                     + dstZoffset * dstImageStride
958
 
                     + dstYoffset * dstRowStride
959
 
                     + dstXoffset * texelBytes;
960
 
 
961
943
   if (dstRowStride == srcRowStride &&
962
 
       dstRowStride == bytesPerRow &&
963
 
       ((dstImageStride == srcImageStride &&
964
 
         dstImageStride == bytesPerImage) ||
965
 
        (srcDepth == 1))) {
966
 
      /* one big memcpy */
967
 
      ctx->Driver.TextureMemCpy(dstImage, srcImage, bytesPerTexture);
 
944
       dstRowStride == bytesPerRow) {
 
945
      /* memcpy image by image */
 
946
      GLint img;
 
947
      for (img = 0; img < srcDepth; img++) {
 
948
         GLubyte *dstImage = dstSlices[img];
 
949
         memcpy(dstImage, srcImage, bytesPerRow * srcHeight);
 
950
         srcImage += srcImageStride;
 
951
      }
968
952
   }
969
 
   else
970
 
   {
 
953
   else {
 
954
      /* memcpy row by row */
971
955
      GLint img, row;
972
956
      for (img = 0; img < srcDepth; img++) {
973
957
         const GLubyte *srcRow = srcImage;
974
 
         GLubyte *dstRow = dstImage;
 
958
         GLubyte *dstRow = dstSlices[img];
975
959
         for (row = 0; row < srcHeight; row++) {
976
 
            ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
 
960
            memcpy(dstRow, srcRow, bytesPerRow);
977
961
            dstRow += dstRowStride;
978
962
            srcRow += srcRowStride;
979
963
         }
980
964
         srcImage += srcImageStride;
981
 
         dstImage += dstImageStride;
982
 
      }
983
 
   }
984
 
#endif
985
 
 
986
 
   GLint img, row;
987
 
   for (img = 0; img < srcDepth; img++) {
988
 
      const GLubyte *srcRow = srcImage;
989
 
      GLubyte *dstRow = (GLubyte *) dstAddr
990
 
         + dstImageOffsets[dstZoffset + img] * texelBytes
991
 
         + dstYoffset * dstRowStride
992
 
         + dstXoffset * texelBytes;
993
 
      for (row = 0; row < srcHeight; row++) {
994
 
         ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);
995
 
         dstRow += dstRowStride;
996
 
         srcRow += srcRowStride;
997
 
      }
998
 
      srcImage += srcImageStride;
 
965
      }
999
966
   }
1000
967
}
1001
968
 
1002
969
 
1003
970
 
1004
971
/**
1005
 
 * Store a 32-bit integer depth component texture image.
 
972
 * Store a 32-bit integer or float depth component texture image.
1006
973
 */
1007
974
static GLboolean
1008
975
_mesa_texstore_z32(TEXSTORE_PARAMS)
1009
976
{
1010
977
   const GLuint depthScale = 0xffffffff;
1011
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
 
978
   GLenum dstType;
1012
979
   (void) dims;
1013
 
   ASSERT(dstFormat == MESA_FORMAT_Z32);
1014
 
   ASSERT(texelBytes == sizeof(GLuint));
 
980
   ASSERT(dstFormat == MESA_FORMAT_Z32 ||
 
981
          dstFormat == MESA_FORMAT_Z32_FLOAT);
 
982
   ASSERT(_mesa_get_format_bytes(dstFormat) == sizeof(GLuint));
 
983
 
 
984
   if (dstFormat == MESA_FORMAT_Z32)
 
985
      dstType = GL_UNSIGNED_INT;
 
986
   else
 
987
      dstType = GL_FLOAT;
1015
988
 
1016
989
   if (ctx->Pixel.DepthScale == 1.0f &&
1017
990
       ctx->Pixel.DepthBias == 0.0f &&
1018
991
       !srcPacking->SwapBytes &&
1019
992
       baseInternalFormat == GL_DEPTH_COMPONENT &&
1020
993
       srcFormat == GL_DEPTH_COMPONENT &&
1021
 
       srcType == GL_UNSIGNED_INT) {
 
994
       srcType == dstType) {
1022
995
      /* simple memcpy path */
1023
996
      memcpy_texture(ctx, dims,
1024
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1025
 
                     dstRowStride,
1026
 
                     dstImageOffsets,
 
997
                     dstFormat,
 
998
                     dstRowStride, dstSlices,
1027
999
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1028
1000
                     srcAddr, srcPacking);
1029
1001
   }
1031
1003
      /* general path */
1032
1004
      GLint img, row;
1033
1005
      for (img = 0; img < srcDepth; img++) {
1034
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1035
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1036
 
            + dstYoffset * dstRowStride
1037
 
            + dstXoffset * texelBytes;
 
1006
         GLubyte *dstRow = dstSlices[img];
1038
1007
         for (row = 0; row < srcHeight; row++) {
1039
1008
            const GLvoid *src = _mesa_image_address(dims, srcPacking,
1040
1009
                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1041
1010
            _mesa_unpack_depth_span(ctx, srcWidth,
1042
 
                                    GL_UNSIGNED_INT, (GLuint *) dstRow,
 
1011
                                    dstType, dstRow,
1043
1012
                                    depthScale, srcType, src, srcPacking);
1044
1013
            dstRow += dstRowStride;
1045
1014
         }
1056
1025
_mesa_texstore_x8_z24(TEXSTORE_PARAMS)
1057
1026
{
1058
1027
   const GLuint depthScale = 0xffffff;
1059
 
   const GLuint texelBytes = 4;
1060
1028
 
1061
1029
   (void) dims;
1062
1030
   ASSERT(dstFormat == MESA_FORMAT_X8_Z24);
1065
1033
      /* general path */
1066
1034
      GLint img, row;
1067
1035
      for (img = 0; img < srcDepth; img++) {
1068
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1069
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1070
 
            + dstYoffset * dstRowStride
1071
 
            + dstXoffset * texelBytes;
 
1036
         GLubyte *dstRow = dstSlices[img];
1072
1037
         for (row = 0; row < srcHeight; row++) {
1073
1038
            const GLvoid *src = _mesa_image_address(dims, srcPacking,
1074
1039
                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1090
1055
_mesa_texstore_z24_x8(TEXSTORE_PARAMS)
1091
1056
{
1092
1057
   const GLuint depthScale = 0xffffff;
1093
 
   const GLuint texelBytes = 4;
1094
1058
 
1095
1059
   (void) dims;
1096
1060
   ASSERT(dstFormat == MESA_FORMAT_Z24_X8);
1099
1063
      /* general path */
1100
1064
      GLint img, row;
1101
1065
      for (img = 0; img < srcDepth; img++) {
1102
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1103
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1104
 
            + dstYoffset * dstRowStride
1105
 
            + dstXoffset * texelBytes;
 
1066
         GLubyte *dstRow = dstSlices[img];
1106
1067
         for (row = 0; row < srcHeight; row++) {
1107
1068
            const GLvoid *src = _mesa_image_address(dims, srcPacking,
1108
1069
                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1128
1089
_mesa_texstore_z16(TEXSTORE_PARAMS)
1129
1090
{
1130
1091
   const GLuint depthScale = 0xffff;
1131
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1132
1092
   (void) dims;
1133
1093
   ASSERT(dstFormat == MESA_FORMAT_Z16);
1134
 
   ASSERT(texelBytes == sizeof(GLushort));
 
1094
   ASSERT(_mesa_get_format_bytes(dstFormat) == sizeof(GLushort));
1135
1095
 
1136
1096
   if (ctx->Pixel.DepthScale == 1.0f &&
1137
1097
       ctx->Pixel.DepthBias == 0.0f &&
1141
1101
       srcType == GL_UNSIGNED_SHORT) {
1142
1102
      /* simple memcpy path */
1143
1103
      memcpy_texture(ctx, dims,
1144
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1145
 
                     dstRowStride,
1146
 
                     dstImageOffsets,
 
1104
                     dstFormat,
 
1105
                     dstRowStride, dstSlices,
1147
1106
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1148
1107
                     srcAddr, srcPacking);
1149
1108
   }
1151
1110
      /* general path */
1152
1111
      GLint img, row;
1153
1112
      for (img = 0; img < srcDepth; img++) {
1154
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1155
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1156
 
            + dstYoffset * dstRowStride
1157
 
            + dstXoffset * texelBytes;
 
1113
         GLubyte *dstRow = dstSlices[img];
1158
1114
         for (row = 0; row < srcHeight; row++) {
1159
1115
            const GLvoid *src = _mesa_image_address(dims, srcPacking,
1160
1116
                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
1176
1132
static GLboolean
1177
1133
_mesa_texstore_rgb565(TEXSTORE_PARAMS)
1178
1134
{
1179
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1180
1135
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1181
1136
 
1182
1137
   ASSERT(dstFormat == MESA_FORMAT_RGB565 ||
1183
1138
          dstFormat == MESA_FORMAT_RGB565_REV);
1184
 
   ASSERT(texelBytes == 2);
 
1139
   ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
1185
1140
 
1186
1141
   if (!ctx->_ImageTransferState &&
1187
1142
       !srcPacking->SwapBytes &&
1191
1146
       srcType == GL_UNSIGNED_SHORT_5_6_5) {
1192
1147
      /* simple memcpy path */
1193
1148
      memcpy_texture(ctx, dims,
1194
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1195
 
                     dstRowStride,
1196
 
                     dstImageOffsets,
 
1149
                     dstFormat,
 
1150
                     dstRowStride, dstSlices,
1197
1151
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1198
1152
                     srcAddr, srcPacking);
1199
1153
   }
1209
1163
      const GLubyte *src = (const GLubyte *)
1210
1164
         _mesa_image_address(dims, srcPacking, srcAddr, srcWidth, srcHeight,
1211
1165
                             srcFormat, srcType, 0, 0, 0);
1212
 
      GLubyte *dst = (GLubyte *) dstAddr
1213
 
                   + dstYoffset * dstRowStride
1214
 
                   + dstXoffset * texelBytes;
 
1166
      GLubyte *dst = dstSlices[0];
1215
1167
      GLint row, col;
1216
1168
      for (row = 0; row < srcHeight; row++) {
1217
1169
         const GLubyte *srcUB = (const GLubyte *) src;
1235
1187
   }
1236
1188
   else {
1237
1189
      /* general path */
1238
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
1190
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1239
1191
                                                 baseInternalFormat,
1240
1192
                                                 baseFormat,
1241
1193
                                                 srcWidth, srcHeight, srcDepth,
1242
1194
                                                 srcFormat, srcType, srcAddr,
1243
1195
                                                 srcPacking);
1244
 
      const GLchan *src = tempImage;
 
1196
      const GLubyte *src = tempImage;
1245
1197
      GLint img, row, col;
1246
1198
      if (!tempImage)
1247
1199
         return GL_FALSE;
1248
1200
      for (img = 0; img < srcDepth; img++) {
1249
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1250
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1251
 
            + dstYoffset * dstRowStride
1252
 
            + dstXoffset * texelBytes;
 
1201
         GLubyte *dstRow = dstSlices[img];
1253
1202
         for (row = 0; row < srcHeight; row++) {
1254
1203
            GLushort *dstUS = (GLushort *) dstRow;
1255
1204
            /* check for byteswapped format */
1256
1205
            if (dstFormat == MESA_FORMAT_RGB565) {
1257
1206
               for (col = 0; col < srcWidth; col++) {
1258
 
                  dstUS[col] = PACK_COLOR_565( CHAN_TO_UBYTE(src[RCOMP]),
1259
 
                                               CHAN_TO_UBYTE(src[GCOMP]),
1260
 
                                               CHAN_TO_UBYTE(src[BCOMP]) );
 
1207
                  dstUS[col] = PACK_COLOR_565( src[RCOMP],
 
1208
                                               src[GCOMP],
 
1209
                                               src[BCOMP] );
1261
1210
                  src += 3;
1262
1211
               }
1263
1212
            }
1264
1213
            else {
1265
1214
               for (col = 0; col < srcWidth; col++) {
1266
 
                  dstUS[col] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src[RCOMP]),
1267
 
                                                   CHAN_TO_UBYTE(src[GCOMP]),
1268
 
                                                   CHAN_TO_UBYTE(src[BCOMP]) );
 
1215
                  dstUS[col] = PACK_COLOR_565_REV( src[RCOMP],
 
1216
                                                   src[GCOMP],
 
1217
                                                   src[BCOMP] );
1269
1218
                  src += 3;
1270
1219
               }
1271
1220
            }
1285
1234
_mesa_texstore_rgba8888(TEXSTORE_PARAMS)
1286
1235
{
1287
1236
   const GLboolean littleEndian = _mesa_little_endian();
1288
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1289
1237
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1290
1238
 
1291
1239
   ASSERT(dstFormat == MESA_FORMAT_RGBA8888 ||
1292
 
          dstFormat == MESA_FORMAT_RGBA8888_REV);
1293
 
   ASSERT(texelBytes == 4);
 
1240
          dstFormat == MESA_FORMAT_RGBA8888_REV ||
 
1241
          dstFormat == MESA_FORMAT_RGBX8888 ||
 
1242
          dstFormat == MESA_FORMAT_RGBX8888_REV);
 
1243
   ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
1294
1244
 
1295
1245
   if (!ctx->_ImageTransferState &&
1296
1246
       !srcPacking->SwapBytes &&
1297
 
       dstFormat == MESA_FORMAT_RGBA8888 &&
 
1247
      (dstFormat == MESA_FORMAT_RGBA8888 ||
 
1248
       dstFormat == MESA_FORMAT_RGBX8888) &&
1298
1249
       baseInternalFormat == GL_RGBA &&
1299
1250
      ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8) ||
1300
1251
       (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && !littleEndian) ||
1302
1253
       (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && littleEndian))) {
1303
1254
       /* simple memcpy path */
1304
1255
      memcpy_texture(ctx, dims,
1305
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1306
 
                     dstRowStride,
1307
 
                     dstImageOffsets,
 
1256
                     dstFormat,
 
1257
                     dstRowStride, dstSlices,
1308
1258
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1309
1259
                     srcAddr, srcPacking);
1310
1260
   }
1311
1261
   else if (!ctx->_ImageTransferState &&
1312
1262
       !srcPacking->SwapBytes &&
1313
 
       dstFormat == MESA_FORMAT_RGBA8888_REV &&
 
1263
      (dstFormat == MESA_FORMAT_RGBA8888_REV ||
 
1264
       dstFormat == MESA_FORMAT_RGBX8888_REV) &&
1314
1265
       baseInternalFormat == GL_RGBA &&
1315
1266
      ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||
1316
1267
       (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && littleEndian) ||
1318
1269
       (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && !littleEndian))) {
1319
1270
      /* simple memcpy path */
1320
1271
      memcpy_texture(ctx, dims,
1321
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1322
 
                     dstRowStride,
1323
 
                     dstImageOffsets,
 
1272
                     dstFormat,
 
1273
                     dstRowStride, dstSlices,
1324
1274
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1325
1275
                     srcAddr, srcPacking);
1326
1276
   }
1335
1285
 
1336
1286
      /* dstmap - how to swizzle from RGBA to dst format:
1337
1287
       */
1338
 
      if ((littleEndian && dstFormat == MESA_FORMAT_RGBA8888) ||
1339
 
          (!littleEndian && dstFormat == MESA_FORMAT_RGBA8888_REV)) {
 
1288
      if ((littleEndian && (dstFormat == MESA_FORMAT_RGBA8888 ||
 
1289
                            dstFormat == MESA_FORMAT_RGBX8888)) ||
 
1290
          (!littleEndian && (dstFormat == MESA_FORMAT_RGBA8888_REV ||
 
1291
                             dstFormat == MESA_FORMAT_RGBX8888_REV))) {
1340
1292
         dstmap[3] = 0;
1341
1293
         dstmap[2] = 1;
1342
1294
         dstmap[1] = 2;
1354
1306
                                srcType,
1355
1307
                                baseInternalFormat,
1356
1308
                                dstmap, 4,
1357
 
                                dstAddr, dstXoffset, dstYoffset, dstZoffset,
1358
 
                                dstRowStride, dstImageOffsets,
 
1309
                                dstRowStride, dstSlices,
1359
1310
                                srcWidth, srcHeight, srcDepth, srcAddr,
1360
1311
                                srcPacking);      
1361
1312
   }
1362
1313
   else {
1363
1314
      /* general path */
1364
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
1315
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1365
1316
                                                 baseInternalFormat,
1366
1317
                                                 baseFormat,
1367
1318
                                                 srcWidth, srcHeight, srcDepth,
1368
1319
                                                 srcFormat, srcType, srcAddr,
1369
1320
                                                 srcPacking);
1370
 
      const GLchan *src = tempImage;
 
1321
      const GLubyte *src = tempImage;
1371
1322
      GLint img, row, col;
1372
1323
      if (!tempImage)
1373
1324
         return GL_FALSE;
1374
1325
      for (img = 0; img < srcDepth; img++) {
1375
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1376
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1377
 
            + dstYoffset * dstRowStride
1378
 
            + dstXoffset * texelBytes;
 
1326
         GLubyte *dstRow = dstSlices[img];
1379
1327
         for (row = 0; row < srcHeight; row++) {
1380
1328
            GLuint *dstUI = (GLuint *) dstRow;
1381
 
            if (dstFormat == MESA_FORMAT_RGBA8888) {
 
1329
            if (dstFormat == MESA_FORMAT_RGBA8888 ||
 
1330
                dstFormat == MESA_FORMAT_RGBX8888) {
1382
1331
               for (col = 0; col < srcWidth; col++) {
1383
 
                  dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[RCOMP]),
1384
 
                                                CHAN_TO_UBYTE(src[GCOMP]),
1385
 
                                                CHAN_TO_UBYTE(src[BCOMP]),
1386
 
                                                CHAN_TO_UBYTE(src[ACOMP]) );
 
1332
                  dstUI[col] = PACK_COLOR_8888( src[RCOMP],
 
1333
                                                src[GCOMP],
 
1334
                                                src[BCOMP],
 
1335
                                                src[ACOMP] );
1387
1336
                  src += 4;
1388
1337
               }
1389
1338
            }
1390
1339
            else {
1391
1340
               for (col = 0; col < srcWidth; col++) {
1392
 
                  dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[RCOMP]),
1393
 
                                                    CHAN_TO_UBYTE(src[GCOMP]),
1394
 
                                                    CHAN_TO_UBYTE(src[BCOMP]),
1395
 
                                                    CHAN_TO_UBYTE(src[ACOMP]) );
 
1341
                  dstUI[col] = PACK_COLOR_8888_REV( src[RCOMP],
 
1342
                                                    src[GCOMP],
 
1343
                                                    src[BCOMP],
 
1344
                                                    src[ACOMP] );
1396
1345
                  src += 4;
1397
1346
               }
1398
1347
            }
1409
1358
_mesa_texstore_argb8888(TEXSTORE_PARAMS)
1410
1359
{
1411
1360
   const GLboolean littleEndian = _mesa_little_endian();
1412
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1413
1361
   const GLenum baseFormat = GL_RGBA;
1414
1362
 
1415
1363
   ASSERT(dstFormat == MESA_FORMAT_ARGB8888 ||
1416
1364
          dstFormat == MESA_FORMAT_ARGB8888_REV ||
1417
1365
          dstFormat == MESA_FORMAT_XRGB8888 ||
1418
1366
          dstFormat == MESA_FORMAT_XRGB8888_REV );
1419
 
   ASSERT(texelBytes == 4);
 
1367
   ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
1420
1368
 
1421
1369
   if (!ctx->_ImageTransferState &&
1422
1370
       !srcPacking->SwapBytes &&
1428
1376
        srcType == GL_UNSIGNED_INT_8_8_8_8_REV)) {
1429
1377
      /* simple memcpy path (little endian) */
1430
1378
      memcpy_texture(ctx, dims,
1431
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1432
 
                     dstRowStride,
1433
 
                     dstImageOffsets,
 
1379
                     dstFormat,
 
1380
                     dstRowStride, dstSlices,
1434
1381
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1435
1382
                     srcAddr, srcPacking);
1436
1383
   }
1444
1391
        srcType == GL_UNSIGNED_INT_8_8_8_8)) {
1445
1392
      /* simple memcpy path (big endian) */
1446
1393
      memcpy_texture(ctx, dims,
1447
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1448
 
                     dstRowStride,
1449
 
                     dstImageOffsets,
 
1394
                     dstFormat,
 
1395
                     dstRowStride, dstSlices,
1450
1396
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1451
1397
                     srcAddr, srcPacking);
1452
1398
   }
1464
1410
            _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1465
1411
         GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1466
1412
                  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1467
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1468
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1469
 
            + dstYoffset * dstRowStride
1470
 
            + dstXoffset * texelBytes;
 
1413
         GLubyte *dstRow = dstSlices[img];
1471
1414
         for (row = 0; row < srcHeight; row++) {
1472
1415
            GLuint *d4 = (GLuint *) dstRow;
1473
1416
            for (col = 0; col < srcWidth; col++) {
1500
1443
            _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1501
1444
         GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1502
1445
                  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1503
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1504
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1505
 
            + dstYoffset * dstRowStride
1506
 
            + dstXoffset * texelBytes;
 
1446
         GLubyte *dstRow = dstSlices[img];
1507
1447
         for (row = 0; row < srcHeight; row++) {
1508
1448
            GLuint *d4 = (GLuint *) dstRow;
1509
1449
            for (col = 0; col < srcWidth; col++) {
1553
1493
                                srcType,
1554
1494
                                baseInternalFormat,
1555
1495
                                dstmap, 4,
1556
 
                                dstAddr, dstXoffset, dstYoffset, dstZoffset,
1557
1496
                                dstRowStride,
1558
 
                                dstImageOffsets,
 
1497
                                dstSlices,
1559
1498
                                srcWidth, srcHeight, srcDepth, srcAddr,
1560
1499
                                srcPacking);      
1561
1500
   }
1562
1501
   else {
1563
1502
      /* general path */
1564
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
1503
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1565
1504
                                                 baseInternalFormat,
1566
1505
                                                 baseFormat,
1567
1506
                                                 srcWidth, srcHeight, srcDepth,
1568
1507
                                                 srcFormat, srcType, srcAddr,
1569
1508
                                                 srcPacking);
1570
 
      const GLchan *src = tempImage;
 
1509
      const GLubyte *src = tempImage;
1571
1510
      GLint img, row, col;
1572
1511
      if (!tempImage)
1573
1512
         return GL_FALSE;
1574
1513
      for (img = 0; img < srcDepth; img++) {
1575
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1576
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1577
 
            + dstYoffset * dstRowStride
1578
 
            + dstXoffset * texelBytes;
 
1514
         GLubyte *dstRow = dstSlices[img];
1579
1515
         for (row = 0; row < srcHeight; row++) {
1580
1516
            GLuint *dstUI = (GLuint *) dstRow;
1581
1517
            if (dstFormat == MESA_FORMAT_ARGB8888) {
1582
1518
               for (col = 0; col < srcWidth; col++) {
1583
 
                  dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[ACOMP]),
1584
 
                                                CHAN_TO_UBYTE(src[RCOMP]),
1585
 
                                                CHAN_TO_UBYTE(src[GCOMP]),
1586
 
                                                CHAN_TO_UBYTE(src[BCOMP]) );
 
1519
                  dstUI[col] = PACK_COLOR_8888( src[ACOMP],
 
1520
                                                src[RCOMP],
 
1521
                                                src[GCOMP],
 
1522
                                                src[BCOMP] );
1587
1523
                  src += 4;
1588
1524
               }
1589
1525
            }
1590
1526
            else if (dstFormat == MESA_FORMAT_XRGB8888) {
1591
1527
               for (col = 0; col < srcWidth; col++) {
1592
1528
                  dstUI[col] = PACK_COLOR_8888( 0xff,
1593
 
                                                CHAN_TO_UBYTE(src[RCOMP]),
1594
 
                                                CHAN_TO_UBYTE(src[GCOMP]),
1595
 
                                                CHAN_TO_UBYTE(src[BCOMP]) );
 
1529
                                                src[RCOMP],
 
1530
                                                src[GCOMP],
 
1531
                                                src[BCOMP] );
1596
1532
                  src += 4;
1597
1533
               }
1598
1534
            }
1599
1535
            else {
1600
1536
               for (col = 0; col < srcWidth; col++) {
1601
 
                  dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[ACOMP]),
1602
 
                                                    CHAN_TO_UBYTE(src[RCOMP]),
1603
 
                                                    CHAN_TO_UBYTE(src[GCOMP]),
1604
 
                                                    CHAN_TO_UBYTE(src[BCOMP]) );
 
1537
                  dstUI[col] = PACK_COLOR_8888_REV( src[ACOMP],
 
1538
                                                    src[RCOMP],
 
1539
                                                    src[GCOMP],
 
1540
                                                    src[BCOMP] );
1605
1541
                  src += 4;
1606
1542
               }
1607
1543
            }
1618
1554
_mesa_texstore_rgb888(TEXSTORE_PARAMS)
1619
1555
{
1620
1556
   const GLboolean littleEndian = _mesa_little_endian();
1621
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1622
1557
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1623
1558
 
1624
1559
   ASSERT(dstFormat == MESA_FORMAT_RGB888);
1625
 
   ASSERT(texelBytes == 3);
 
1560
   ASSERT(_mesa_get_format_bytes(dstFormat) == 3);
1626
1561
 
1627
1562
   if (!ctx->_ImageTransferState &&
1628
1563
       !srcPacking->SwapBytes &&
1632
1567
       littleEndian) {
1633
1568
      /* simple memcpy path */
1634
1569
      memcpy_texture(ctx, dims,
1635
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1636
 
                     dstRowStride,
1637
 
                     dstImageOffsets,
 
1570
                     dstFormat,
 
1571
                     dstRowStride, dstSlices,
1638
1572
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1639
1573
                     srcAddr, srcPacking);
1640
1574
   }
1649
1583
            _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1650
1584
         GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1651
1585
                  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1652
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1653
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1654
 
            + dstYoffset * dstRowStride
1655
 
            + dstXoffset * texelBytes;
 
1586
         GLubyte *dstRow = dstSlices[img];
1656
1587
         for (row = 0; row < srcHeight; row++) {
1657
1588
            for (col = 0; col < srcWidth; col++) {
1658
1589
               dstRow[col * 3 + 0] = srcRow[col * 4 + BCOMP];
1683
1614
                                srcType,
1684
1615
                                baseInternalFormat,
1685
1616
                                dstmap, 3,
1686
 
                                dstAddr, dstXoffset, dstYoffset, dstZoffset,
1687
 
                                dstRowStride, dstImageOffsets,
 
1617
                                dstRowStride, dstSlices,
1688
1618
                                srcWidth, srcHeight, srcDepth, srcAddr,
1689
1619
                                srcPacking);      
1690
1620
   }
1691
1621
   else {
1692
1622
      /* general path */
1693
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
1623
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1694
1624
                                                 baseInternalFormat,
1695
1625
                                                 baseFormat,
1696
1626
                                                 srcWidth, srcHeight, srcDepth,
1697
1627
                                                 srcFormat, srcType, srcAddr,
1698
1628
                                                 srcPacking);
1699
 
      const GLchan *src = (const GLchan *) tempImage;
 
1629
      const GLubyte *src = (const GLubyte *) tempImage;
1700
1630
      GLint img, row, col;
1701
1631
      if (!tempImage)
1702
1632
         return GL_FALSE;
1703
1633
      for (img = 0; img < srcDepth; img++) {
1704
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1705
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1706
 
            + dstYoffset * dstRowStride
1707
 
            + dstXoffset * texelBytes;
 
1634
         GLubyte *dstRow = dstSlices[img];
1708
1635
         for (row = 0; row < srcHeight; row++) {
1709
1636
#if 0
1710
1637
            if (littleEndian) {
1711
1638
               for (col = 0; col < srcWidth; col++) {
1712
 
                  dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[RCOMP]);
1713
 
                  dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
1714
 
                  dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[BCOMP]);
 
1639
                  dstRow[col * 3 + 0] = src[RCOMP];
 
1640
                  dstRow[col * 3 + 1] = src[GCOMP];
 
1641
                  dstRow[col * 3 + 2] = src[BCOMP];
1715
1642
                  srcUB += 3;
1716
1643
               }
1717
1644
            }
1725
1652
            }
1726
1653
#else
1727
1654
            for (col = 0; col < srcWidth; col++) {
1728
 
               dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[BCOMP]);
1729
 
               dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
1730
 
               dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[RCOMP]);
 
1655
               dstRow[col * 3 + 0] = src[BCOMP];
 
1656
               dstRow[col * 3 + 1] = src[GCOMP];
 
1657
               dstRow[col * 3 + 2] = src[RCOMP];
1731
1658
               src += 3;
1732
1659
            }
1733
1660
#endif
1744
1671
_mesa_texstore_bgr888(TEXSTORE_PARAMS)
1745
1672
{
1746
1673
   const GLboolean littleEndian = _mesa_little_endian();
1747
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1748
1674
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1749
1675
 
1750
1676
   ASSERT(dstFormat == MESA_FORMAT_BGR888);
1751
 
   ASSERT(texelBytes == 3);
 
1677
   ASSERT(_mesa_get_format_bytes(dstFormat) == 3);
1752
1678
 
1753
1679
   if (!ctx->_ImageTransferState &&
1754
1680
       !srcPacking->SwapBytes &&
1758
1684
       littleEndian) {
1759
1685
      /* simple memcpy path */
1760
1686
      memcpy_texture(ctx, dims,
1761
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1762
 
                     dstRowStride,
1763
 
                     dstImageOffsets,
 
1687
                     dstFormat,
 
1688
                     dstRowStride, dstSlices,
1764
1689
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1765
1690
                     srcAddr, srcPacking);
1766
1691
   }
1775
1700
            _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
1776
1701
         GLubyte *srcRow = (GLubyte *) _mesa_image_address(dims, srcPacking,
1777
1702
                  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);
1778
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1779
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1780
 
            + dstYoffset * dstRowStride
1781
 
            + dstXoffset * texelBytes;
 
1703
         GLubyte *dstRow = dstSlices[img];
1782
1704
         for (row = 0; row < srcHeight; row++) {
1783
1705
            for (col = 0; col < srcWidth; col++) {
1784
1706
               dstRow[col * 3 + 0] = srcRow[col * 4 + RCOMP];
1809
1731
                                srcType,
1810
1732
                                baseInternalFormat,
1811
1733
                                dstmap, 3,
1812
 
                                dstAddr, dstXoffset, dstYoffset, dstZoffset,
1813
 
                                dstRowStride, dstImageOffsets,
 
1734
                                dstRowStride, dstSlices,
1814
1735
                                srcWidth, srcHeight, srcDepth, srcAddr,
1815
1736
                                srcPacking);      
1816
1737
   }   
1817
1738
   else {
1818
1739
      /* general path */
1819
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
1740
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1820
1741
                                                 baseInternalFormat,
1821
1742
                                                 baseFormat,
1822
1743
                                                 srcWidth, srcHeight, srcDepth,
1823
1744
                                                 srcFormat, srcType, srcAddr,
1824
1745
                                                 srcPacking);
1825
 
      const GLchan *src = (const GLchan *) tempImage;
 
1746
      const GLubyte *src = (const GLubyte *) tempImage;
1826
1747
      GLint img, row, col;
1827
1748
      if (!tempImage)
1828
1749
         return GL_FALSE;
1829
1750
      for (img = 0; img < srcDepth; img++) {
1830
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1831
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1832
 
            + dstYoffset * dstRowStride
1833
 
            + dstXoffset * texelBytes;
 
1751
         GLubyte *dstRow = dstSlices[img];
1834
1752
         for (row = 0; row < srcHeight; row++) {
1835
1753
            for (col = 0; col < srcWidth; col++) {
1836
 
               dstRow[col * 3 + 0] = CHAN_TO_UBYTE(src[RCOMP]);
1837
 
               dstRow[col * 3 + 1] = CHAN_TO_UBYTE(src[GCOMP]);
1838
 
               dstRow[col * 3 + 2] = CHAN_TO_UBYTE(src[BCOMP]);
 
1754
               dstRow[col * 3 + 0] = src[RCOMP];
 
1755
               dstRow[col * 3 + 1] = src[GCOMP];
 
1756
               dstRow[col * 3 + 2] = src[BCOMP];
1839
1757
               src += 3;
1840
1758
            }
1841
1759
            dstRow += dstRowStride;
1850
1768
static GLboolean
1851
1769
_mesa_texstore_argb4444(TEXSTORE_PARAMS)
1852
1770
{
1853
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1854
1771
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1855
1772
 
1856
1773
   ASSERT(dstFormat == MESA_FORMAT_ARGB4444 ||
1857
1774
          dstFormat == MESA_FORMAT_ARGB4444_REV);
1858
 
   ASSERT(texelBytes == 2);
 
1775
   ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
1859
1776
 
1860
1777
   if (!ctx->_ImageTransferState &&
1861
1778
       !srcPacking->SwapBytes &&
1865
1782
       srcType == GL_UNSIGNED_SHORT_4_4_4_4_REV) {
1866
1783
      /* simple memcpy path */
1867
1784
      memcpy_texture(ctx, dims,
1868
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1869
 
                     dstRowStride,
1870
 
                     dstImageOffsets,
 
1785
                     dstFormat,
 
1786
                     dstRowStride, dstSlices,
1871
1787
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1872
1788
                     srcAddr, srcPacking);
1873
1789
   }
1874
1790
   else {
1875
1791
      /* general path */
1876
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
1792
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1877
1793
                                                 baseInternalFormat,
1878
1794
                                                 baseFormat,
1879
1795
                                                 srcWidth, srcHeight, srcDepth,
1880
1796
                                                 srcFormat, srcType, srcAddr,
1881
1797
                                                 srcPacking);
1882
 
      const GLchan *src = tempImage;
 
1798
      const GLubyte *src = tempImage;
1883
1799
      GLint img, row, col;
1884
1800
      if (!tempImage)
1885
1801
         return GL_FALSE;
1886
1802
      for (img = 0; img < srcDepth; img++) {
1887
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1888
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1889
 
            + dstYoffset * dstRowStride
1890
 
            + dstXoffset * texelBytes;
 
1803
         GLubyte *dstRow = dstSlices[img];
1891
1804
         for (row = 0; row < srcHeight; row++) {
1892
1805
            GLushort *dstUS = (GLushort *) dstRow;
1893
1806
            if (dstFormat == MESA_FORMAT_ARGB4444) {
1894
1807
               for (col = 0; col < srcWidth; col++) {
1895
 
                  dstUS[col] = PACK_COLOR_4444( CHAN_TO_UBYTE(src[ACOMP]),
1896
 
                                                CHAN_TO_UBYTE(src[RCOMP]),
1897
 
                                                CHAN_TO_UBYTE(src[GCOMP]),
1898
 
                                                CHAN_TO_UBYTE(src[BCOMP]) );
 
1808
                  dstUS[col] = PACK_COLOR_4444( src[ACOMP],
 
1809
                                                src[RCOMP],
 
1810
                                                src[GCOMP],
 
1811
                                                src[BCOMP] );
1899
1812
                  src += 4;
1900
1813
               }
1901
1814
            }
1902
1815
            else {
1903
1816
               for (col = 0; col < srcWidth; col++) {
1904
 
                  dstUS[col] = PACK_COLOR_4444_REV( CHAN_TO_UBYTE(src[ACOMP]),
1905
 
                                                    CHAN_TO_UBYTE(src[RCOMP]),
1906
 
                                                    CHAN_TO_UBYTE(src[GCOMP]),
1907
 
                                                    CHAN_TO_UBYTE(src[BCOMP]) );
 
1817
                  dstUS[col] = PACK_COLOR_4444_REV( src[ACOMP],
 
1818
                                                    src[RCOMP],
 
1819
                                                    src[GCOMP],
 
1820
                                                    src[BCOMP] );
1908
1821
                  src += 4;
1909
1822
               }
1910
1823
            }
1919
1832
static GLboolean
1920
1833
_mesa_texstore_rgba5551(TEXSTORE_PARAMS)
1921
1834
{
1922
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1923
1835
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1924
1836
 
1925
1837
   ASSERT(dstFormat == MESA_FORMAT_RGBA5551);
1926
 
   ASSERT(texelBytes == 2);
 
1838
   ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
1927
1839
 
1928
1840
   if (!ctx->_ImageTransferState &&
1929
1841
       !srcPacking->SwapBytes &&
1933
1845
       srcType == GL_UNSIGNED_SHORT_5_5_5_1) {
1934
1846
      /* simple memcpy path */
1935
1847
      memcpy_texture(ctx, dims,
1936
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1937
 
                     dstRowStride,
1938
 
                     dstImageOffsets,
 
1848
                     dstFormat,
 
1849
                     dstRowStride, dstSlices,
1939
1850
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1940
1851
                     srcAddr, srcPacking);
1941
1852
   }
1942
1853
   else {
1943
1854
      /* general path */
1944
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
1855
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
1945
1856
                                                 baseInternalFormat,
1946
1857
                                                 baseFormat,
1947
1858
                                                 srcWidth, srcHeight, srcDepth,
1948
1859
                                                 srcFormat, srcType, srcAddr,
1949
1860
                                                 srcPacking);
1950
 
      const GLchan *src =tempImage;
 
1861
      const GLubyte *src =tempImage;
1951
1862
      GLint img, row, col;
1952
1863
      if (!tempImage)
1953
1864
         return GL_FALSE;
1954
1865
      for (img = 0; img < srcDepth; img++) {
1955
 
         GLubyte *dstRow = (GLubyte *) dstAddr
1956
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
1957
 
            + dstYoffset * dstRowStride
1958
 
            + dstXoffset * texelBytes;
 
1866
         GLubyte *dstRow = dstSlices[img];
1959
1867
         for (row = 0; row < srcHeight; row++) {
1960
1868
            GLushort *dstUS = (GLushort *) dstRow;
1961
1869
            for (col = 0; col < srcWidth; col++) {
1962
 
               dstUS[col] = PACK_COLOR_5551( CHAN_TO_UBYTE(src[RCOMP]),
1963
 
                                             CHAN_TO_UBYTE(src[GCOMP]),
1964
 
                                             CHAN_TO_UBYTE(src[BCOMP]),
1965
 
                                             CHAN_TO_UBYTE(src[ACOMP]) );
 
1870
               dstUS[col] = PACK_COLOR_5551( src[RCOMP],
 
1871
                                             src[GCOMP],
 
1872
                                             src[BCOMP],
 
1873
                                             src[ACOMP] );
1966
1874
              src += 4;
1967
1875
            }
1968
1876
            dstRow += dstRowStride;
1976
1884
static GLboolean
1977
1885
_mesa_texstore_argb1555(TEXSTORE_PARAMS)
1978
1886
{
1979
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
1980
1887
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
1981
1888
 
1982
1889
   ASSERT(dstFormat == MESA_FORMAT_ARGB1555 ||
1983
1890
          dstFormat == MESA_FORMAT_ARGB1555_REV);
1984
 
   ASSERT(texelBytes == 2);
 
1891
   ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
1985
1892
 
1986
1893
   if (!ctx->_ImageTransferState &&
1987
1894
       !srcPacking->SwapBytes &&
1991
1898
       srcType == GL_UNSIGNED_SHORT_1_5_5_5_REV) {
1992
1899
      /* simple memcpy path */
1993
1900
      memcpy_texture(ctx, dims,
1994
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
1995
 
                     dstRowStride,
1996
 
                     dstImageOffsets,
 
1901
                     dstFormat,
 
1902
                     dstRowStride, dstSlices,
1997
1903
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
1998
1904
                     srcAddr, srcPacking);
1999
1905
   }
2000
1906
   else {
2001
1907
      /* general path */
2002
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
1908
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
2003
1909
                                                 baseInternalFormat,
2004
1910
                                                 baseFormat,
2005
1911
                                                 srcWidth, srcHeight, srcDepth,
2006
1912
                                                 srcFormat, srcType, srcAddr,
2007
1913
                                                 srcPacking);
2008
 
      const GLchan *src =tempImage;
 
1914
      const GLubyte *src =tempImage;
2009
1915
      GLint img, row, col;
2010
1916
      if (!tempImage)
2011
1917
         return GL_FALSE;
2012
1918
      for (img = 0; img < srcDepth; img++) {
2013
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2014
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2015
 
            + dstYoffset * dstRowStride
2016
 
            + dstXoffset * texelBytes;
 
1919
         GLubyte *dstRow = dstSlices[img];
2017
1920
         for (row = 0; row < srcHeight; row++) {
2018
1921
            GLushort *dstUS = (GLushort *) dstRow;
2019
1922
            if (dstFormat == MESA_FORMAT_ARGB1555) {
2020
1923
               for (col = 0; col < srcWidth; col++) {
2021
 
                  dstUS[col] = PACK_COLOR_1555( CHAN_TO_UBYTE(src[ACOMP]),
2022
 
                                                CHAN_TO_UBYTE(src[RCOMP]),
2023
 
                                                CHAN_TO_UBYTE(src[GCOMP]),
2024
 
                                                CHAN_TO_UBYTE(src[BCOMP]) );
 
1924
                  dstUS[col] = PACK_COLOR_1555( src[ACOMP],
 
1925
                                                src[RCOMP],
 
1926
                                                src[GCOMP],
 
1927
                                                src[BCOMP] );
2025
1928
                  src += 4;
2026
1929
               }
2027
1930
            }
2028
1931
            else {
2029
1932
               for (col = 0; col < srcWidth; col++) {
2030
 
                  dstUS[col] = PACK_COLOR_1555_REV( CHAN_TO_UBYTE(src[ACOMP]),
2031
 
                                                    CHAN_TO_UBYTE(src[RCOMP]),
2032
 
                                                    CHAN_TO_UBYTE(src[GCOMP]),
2033
 
                                                    CHAN_TO_UBYTE(src[BCOMP]) );
 
1933
                  dstUS[col] = PACK_COLOR_1555_REV( src[ACOMP],
 
1934
                                                    src[RCOMP],
 
1935
                                                    src[GCOMP],
 
1936
                                                    src[BCOMP] );
2034
1937
                  src += 4;
2035
1938
               }
2036
1939
            }
2046
1949
static GLboolean
2047
1950
_mesa_texstore_argb2101010(TEXSTORE_PARAMS)
2048
1951
{
2049
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2050
1952
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2051
1953
 
2052
1954
   ASSERT(dstFormat == MESA_FORMAT_ARGB2101010);
2053
 
   ASSERT(texelBytes == 4);
 
1955
   ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
2054
1956
 
2055
1957
   if (!ctx->_ImageTransferState &&
2056
1958
       !srcPacking->SwapBytes &&
2060
1962
       baseInternalFormat == GL_RGBA) {
2061
1963
      /* simple memcpy path */
2062
1964
      memcpy_texture(ctx, dims,
2063
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2064
 
                     dstRowStride,
2065
 
                     dstImageOffsets,
 
1965
                     dstFormat,
 
1966
                     dstRowStride, dstSlices,
2066
1967
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2067
1968
                     srcAddr, srcPacking);
2068
1969
   }
2080
1981
      if (!tempImage)
2081
1982
         return GL_FALSE;
2082
1983
      for (img = 0; img < srcDepth; img++) {
2083
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2084
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2085
 
            + dstYoffset * dstRowStride
2086
 
            + dstXoffset * texelBytes;
 
1984
         GLubyte *dstRow = dstSlices[img];
2087
1985
         if (baseInternalFormat == GL_RGBA) {
2088
1986
            for (row = 0; row < srcHeight; row++) {
2089
1987
               GLuint *dstUI = (GLuint *) dstRow;
2129
2027
static GLboolean
2130
2028
_mesa_texstore_unorm44(TEXSTORE_PARAMS)
2131
2029
{
2132
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2133
2030
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2134
2031
 
2135
2032
   ASSERT(dstFormat == MESA_FORMAT_AL44);
2136
 
   ASSERT(texelBytes == 1);
 
2033
   ASSERT(_mesa_get_format_bytes(dstFormat) == 1);
2137
2034
 
2138
2035
   {
2139
2036
      /* general path */
2140
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
2037
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
2141
2038
                                                 baseInternalFormat,
2142
2039
                                                 baseFormat,
2143
2040
                                                 srcWidth, srcHeight, srcDepth,
2144
2041
                                                 srcFormat, srcType, srcAddr,
2145
2042
                                                 srcPacking);
2146
 
      const GLchan *src = tempImage;
 
2043
      const GLubyte *src = tempImage;
2147
2044
      GLint img, row, col;
2148
2045
      if (!tempImage)
2149
2046
         return GL_FALSE;
2150
2047
      for (img = 0; img < srcDepth; img++) {
2151
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2152
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2153
 
            + dstYoffset * dstRowStride
2154
 
            + dstXoffset * texelBytes;
 
2048
         GLubyte *dstRow = dstSlices[img];
2155
2049
         for (row = 0; row < srcHeight; row++) {
2156
2050
            GLubyte *dstUS = (GLubyte *) dstRow;
2157
2051
            for (col = 0; col < srcWidth; col++) {
2158
2052
               /* src[0] is luminance, src[1] is alpha */
2159
 
               dstUS[col] = PACK_COLOR_44( CHAN_TO_UBYTE(src[1]),
2160
 
                                           CHAN_TO_UBYTE(src[0]) );
 
2053
               dstUS[col] = PACK_COLOR_44( src[1],
 
2054
                                           src[0] );
2161
2055
               src += 2;
2162
2056
            }
2163
2057
            dstRow += dstRowStride;
2176
2070
_mesa_texstore_unorm88(TEXSTORE_PARAMS)
2177
2071
{
2178
2072
   const GLboolean littleEndian = _mesa_little_endian();
2179
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2180
2073
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2181
2074
 
2182
2075
   ASSERT(dstFormat == MESA_FORMAT_AL88 ||
2183
2076
          dstFormat == MESA_FORMAT_AL88_REV ||
2184
 
          dstFormat == MESA_FORMAT_RG88 ||
2185
 
          dstFormat == MESA_FORMAT_RG88_REV);
2186
 
   ASSERT(texelBytes == 2);
 
2077
          dstFormat == MESA_FORMAT_GR88 ||
 
2078
          dstFormat == MESA_FORMAT_RG88);
 
2079
   ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
2187
2080
 
2188
2081
   if (!ctx->_ImageTransferState &&
2189
2082
       !srcPacking->SwapBytes &&
2190
2083
       ((dstFormat == MESA_FORMAT_AL88 &&
2191
2084
         baseInternalFormat == GL_LUMINANCE_ALPHA &&
2192
2085
         srcFormat == GL_LUMINANCE_ALPHA) ||
2193
 
        (dstFormat == MESA_FORMAT_RG88 &&
 
2086
        (dstFormat == MESA_FORMAT_GR88 &&
2194
2087
         baseInternalFormat == srcFormat)) &&
2195
2088
       srcType == GL_UNSIGNED_BYTE &&
2196
2089
       littleEndian) {
2197
2090
      /* simple memcpy path */
2198
2091
      memcpy_texture(ctx, dims,
2199
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2200
 
                     dstRowStride,
2201
 
                     dstImageOffsets,
 
2092
                     dstFormat,
 
2093
                     dstRowStride, dstSlices,
2202
2094
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2203
2095
                     srcAddr, srcPacking);
2204
2096
   }
2223
2115
         }
2224
2116
      }
2225
2117
      else {
2226
 
         if ((littleEndian && dstFormat == MESA_FORMAT_RG88) ||
2227
 
             (!littleEndian && dstFormat == MESA_FORMAT_RG88_REV)) {
 
2118
         if ((littleEndian && dstFormat == MESA_FORMAT_GR88) ||
 
2119
             (!littleEndian && dstFormat == MESA_FORMAT_RG88)) {
2228
2120
            dstmap[0] = 0;
2229
2121
            dstmap[1] = 1;
2230
2122
         }
2241
2133
                                srcType,
2242
2134
                                baseInternalFormat,
2243
2135
                                dstmap, 2,
2244
 
                                dstAddr, dstXoffset, dstYoffset, dstZoffset,
2245
 
                                dstRowStride, dstImageOffsets,
 
2136
                                dstRowStride, dstSlices,
2246
2137
                                srcWidth, srcHeight, srcDepth, srcAddr,
2247
2138
                                srcPacking);      
2248
2139
   }   
2249
2140
   else {
2250
2141
      /* general path */
2251
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
2142
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
2252
2143
                                                 baseInternalFormat,
2253
2144
                                                 baseFormat,
2254
2145
                                                 srcWidth, srcHeight, srcDepth,
2255
2146
                                                 srcFormat, srcType, srcAddr,
2256
2147
                                                 srcPacking);
2257
 
      const GLchan *src = tempImage;
 
2148
      const GLubyte *src = tempImage;
2258
2149
      GLint img, row, col;
2259
2150
      if (!tempImage)
2260
2151
         return GL_FALSE;
2261
2152
      for (img = 0; img < srcDepth; img++) {
2262
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2263
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2264
 
            + dstYoffset * dstRowStride
2265
 
            + dstXoffset * texelBytes;
 
2153
         GLubyte *dstRow = dstSlices[img];
2266
2154
         for (row = 0; row < srcHeight; row++) {
2267
2155
            GLushort *dstUS = (GLushort *) dstRow;
2268
2156
            if (dstFormat == MESA_FORMAT_AL88 ||
2269
 
                dstFormat == MESA_FORMAT_RG88) {
 
2157
                dstFormat == MESA_FORMAT_GR88) {
2270
2158
               for (col = 0; col < srcWidth; col++) {
2271
 
                  /* src[0] is luminance, src[1] is alpha */
2272
 
                 dstUS[col] = PACK_COLOR_88( CHAN_TO_UBYTE(src[1]),
2273
 
                                             CHAN_TO_UBYTE(src[0]) );
 
2159
                  /* src[0] is luminance (or R), src[1] is alpha (or G) */
 
2160
                 dstUS[col] = PACK_COLOR_88( src[1],
 
2161
                                             src[0] );
2274
2162
                 src += 2;
2275
2163
               }
2276
2164
            }
2277
2165
            else {
2278
2166
               for (col = 0; col < srcWidth; col++) {
2279
 
                  /* src[0] is luminance, src[1] is alpha */
2280
 
                 dstUS[col] = PACK_COLOR_88_REV( CHAN_TO_UBYTE(src[1]),
2281
 
                                                 CHAN_TO_UBYTE(src[0]) );
 
2167
                  /* src[0] is luminance (or R), src[1] is alpha (or G) */
 
2168
                 dstUS[col] = PACK_COLOR_88_REV( src[1],
 
2169
                                                 src[0] );
2282
2170
                 src += 2;
2283
2171
               }
2284
2172
            }
2298
2186
_mesa_texstore_unorm1616(TEXSTORE_PARAMS)
2299
2187
{
2300
2188
   const GLboolean littleEndian = _mesa_little_endian();
2301
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2302
2189
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2303
2190
 
2304
2191
   ASSERT(dstFormat == MESA_FORMAT_AL1616 ||
2305
2192
          dstFormat == MESA_FORMAT_AL1616_REV ||
2306
2193
          dstFormat == MESA_FORMAT_RG1616 ||
2307
2194
          dstFormat == MESA_FORMAT_RG1616_REV);
2308
 
   ASSERT(texelBytes == 4);
 
2195
   ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
2309
2196
 
2310
2197
   if (!ctx->_ImageTransferState &&
2311
2198
       !srcPacking->SwapBytes &&
2318
2205
       littleEndian) {
2319
2206
      /* simple memcpy path */
2320
2207
      memcpy_texture(ctx, dims,
2321
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2322
 
                     dstRowStride,
2323
 
                     dstImageOffsets,
 
2208
                     dstFormat,
 
2209
                     dstRowStride, dstSlices,
2324
2210
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2325
2211
                     srcAddr, srcPacking);
2326
2212
   }
2338
2224
      if (!tempImage)
2339
2225
         return GL_FALSE;
2340
2226
      for (img = 0; img < srcDepth; img++) {
2341
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2342
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2343
 
            + dstYoffset * dstRowStride
2344
 
            + dstXoffset * texelBytes;
 
2227
         GLubyte *dstRow = dstSlices[img];
2345
2228
         for (row = 0; row < srcHeight; row++) {
2346
2229
            GLuint *dstUI = (GLuint *) dstRow;
2347
2230
            if (dstFormat == MESA_FORMAT_AL1616 ||
2379
2262
_mesa_texstore_unorm16(TEXSTORE_PARAMS)
2380
2263
{
2381
2264
   const GLboolean littleEndian = _mesa_little_endian();
2382
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2383
2265
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2384
2266
 
2385
2267
   ASSERT(dstFormat == MESA_FORMAT_R16 ||
2386
2268
          dstFormat == MESA_FORMAT_A16 ||
2387
2269
          dstFormat == MESA_FORMAT_L16 ||
2388
2270
          dstFormat == MESA_FORMAT_I16);
2389
 
   ASSERT(texelBytes == 2);
 
2271
   ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
2390
2272
 
2391
2273
   if (!ctx->_ImageTransferState &&
2392
2274
       !srcPacking->SwapBytes &&
2395
2277
       littleEndian) {
2396
2278
      /* simple memcpy path */
2397
2279
      memcpy_texture(ctx, dims,
2398
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2399
 
                     dstRowStride,
2400
 
                     dstImageOffsets,
 
2280
                     dstFormat,
 
2281
                     dstRowStride, dstSlices,
2401
2282
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2402
2283
                     srcAddr, srcPacking);
2403
2284
   }
2415
2296
      if (!tempImage)
2416
2297
         return GL_FALSE;
2417
2298
      for (img = 0; img < srcDepth; img++) {
2418
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2419
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2420
 
            + dstYoffset * dstRowStride
2421
 
            + dstXoffset * texelBytes;
 
2299
         GLubyte *dstRow = dstSlices[img];
2422
2300
         for (row = 0; row < srcHeight; row++) {
2423
2301
            GLushort *dstUS = (GLushort *) dstRow;
2424
2302
            for (col = 0; col < srcWidth; col++) {
2440
2318
static GLboolean
2441
2319
_mesa_texstore_rgba_16(TEXSTORE_PARAMS)
2442
2320
{
2443
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2444
2321
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2445
2322
 
2446
2323
   ASSERT(dstFormat == MESA_FORMAT_RGBA_16);
2447
 
   ASSERT(texelBytes == 8);
 
2324
   ASSERT(_mesa_get_format_bytes(dstFormat) == 8);
2448
2325
 
2449
2326
   if (!ctx->_ImageTransferState &&
2450
2327
       !srcPacking->SwapBytes &&
2453
2330
       srcType == GL_UNSIGNED_SHORT) {
2454
2331
      /* simple memcpy path */
2455
2332
      memcpy_texture(ctx, dims,
2456
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2457
 
                     dstRowStride,
2458
 
                     dstImageOffsets,
 
2333
                     dstFormat,
 
2334
                     dstRowStride, dstSlices,
2459
2335
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2460
2336
                     srcAddr, srcPacking);
2461
2337
   }
2473
2349
      if (!tempImage)
2474
2350
         return GL_FALSE;
2475
2351
      for (img = 0; img < srcDepth; img++) {
2476
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2477
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2478
 
            + dstYoffset * dstRowStride
2479
 
            + dstXoffset * texelBytes;
 
2352
         GLubyte *dstRow = dstSlices[img];
2480
2353
         for (row = 0; row < srcHeight; row++) {
2481
2354
            GLushort *dstUS = (GLushort *) dstRow;
2482
2355
            for (col = 0; col < srcWidth; col++) {
2504
2377
static GLboolean
2505
2378
_mesa_texstore_signed_rgba_16(TEXSTORE_PARAMS)
2506
2379
{
2507
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2508
2380
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2509
2381
 
2510
2382
   ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGB_16 ||
2518
2390
       srcType == GL_SHORT) {
2519
2391
      /* simple memcpy path */
2520
2392
      memcpy_texture(ctx, dims,
2521
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2522
 
                     dstRowStride,
2523
 
                     dstImageOffsets,
 
2393
                     dstFormat,
 
2394
                     dstRowStride, dstSlices,
2524
2395
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2525
2396
                     srcAddr, srcPacking);
2526
2397
   }
2544
2415
       * 3 or 4 components/pixel here.
2545
2416
       */
2546
2417
      for (img = 0; img < srcDepth; img++) {
2547
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2548
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2549
 
            + dstYoffset * dstRowStride
2550
 
            + dstXoffset * texelBytes;
 
2418
         GLubyte *dstRow = dstSlices[img];
2551
2419
         for (row = 0; row < srcHeight; row++) {
2552
2420
            GLshort *dstRowS = (GLshort *) dstRow;
2553
2421
            if (dstFormat == MESA_FORMAT_SIGNED_RGBA_16) {
2584
2452
static GLboolean
2585
2453
_mesa_texstore_rgb332(TEXSTORE_PARAMS)
2586
2454
{
2587
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2588
2455
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2589
2456
 
2590
2457
   ASSERT(dstFormat == MESA_FORMAT_RGB332);
2591
 
   ASSERT(texelBytes == 1);
 
2458
   ASSERT(_mesa_get_format_bytes(dstFormat) == 1);
2592
2459
 
2593
2460
   if (!ctx->_ImageTransferState &&
2594
2461
       !srcPacking->SwapBytes &&
2596
2463
       srcFormat == GL_RGB && srcType == GL_UNSIGNED_BYTE_3_3_2) {
2597
2464
      /* simple memcpy path */
2598
2465
      memcpy_texture(ctx, dims,
2599
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2600
 
                     dstRowStride,
2601
 
                     dstImageOffsets,
 
2466
                     dstFormat,
 
2467
                     dstRowStride, dstSlices,
2602
2468
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2603
2469
                     srcAddr, srcPacking);
2604
2470
   }
2605
2471
   else {
2606
2472
      /* general path */
2607
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
2473
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
2608
2474
                                                 baseInternalFormat,
2609
2475
                                                 baseFormat,
2610
2476
                                                 srcWidth, srcHeight, srcDepth,
2611
2477
                                                 srcFormat, srcType, srcAddr,
2612
2478
                                                 srcPacking);
2613
 
      const GLchan *src = tempImage;
 
2479
      const GLubyte *src = tempImage;
2614
2480
      GLint img, row, col;
2615
2481
      if (!tempImage)
2616
2482
         return GL_FALSE;
2617
2483
      for (img = 0; img < srcDepth; img++) {
2618
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2619
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2620
 
            + dstYoffset * dstRowStride
2621
 
            + dstXoffset * texelBytes;
 
2484
         GLubyte *dstRow = dstSlices[img];
2622
2485
         for (row = 0; row < srcHeight; row++) {
2623
2486
            for (col = 0; col < srcWidth; col++) {
2624
 
               dstRow[col] = PACK_COLOR_332( CHAN_TO_UBYTE(src[RCOMP]),
2625
 
                                             CHAN_TO_UBYTE(src[GCOMP]),
2626
 
                                             CHAN_TO_UBYTE(src[BCOMP]) );
 
2487
               dstRow[col] = PACK_COLOR_332( src[RCOMP],
 
2488
                                             src[GCOMP],
 
2489
                                             src[BCOMP] );
2627
2490
               src += 3;
2628
2491
            }
2629
2492
            dstRow += dstRowStride;
2641
2504
static GLboolean
2642
2505
_mesa_texstore_unorm8(TEXSTORE_PARAMS)
2643
2506
{
2644
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2645
2507
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2646
2508
 
2647
2509
   ASSERT(dstFormat == MESA_FORMAT_A8 ||
2648
2510
          dstFormat == MESA_FORMAT_L8 ||
2649
2511
          dstFormat == MESA_FORMAT_I8 ||
2650
2512
          dstFormat == MESA_FORMAT_R8);
2651
 
   ASSERT(texelBytes == 1);
 
2513
   ASSERT(_mesa_get_format_bytes(dstFormat) == 1);
2652
2514
 
2653
2515
   if (!ctx->_ImageTransferState &&
2654
2516
       !srcPacking->SwapBytes &&
2656
2518
       srcType == GL_UNSIGNED_BYTE) {
2657
2519
      /* simple memcpy path */
2658
2520
      memcpy_texture(ctx, dims,
2659
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2660
 
                     dstRowStride,
2661
 
                     dstImageOffsets,
 
2521
                     dstFormat,
 
2522
                     dstRowStride, dstSlices,
2662
2523
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2663
2524
                     srcAddr, srcPacking);
2664
2525
   }
2685
2546
                                srcType,
2686
2547
                                baseInternalFormat,
2687
2548
                                dstmap, 1,
2688
 
                                dstAddr, dstXoffset, dstYoffset, dstZoffset,
2689
 
                                dstRowStride, dstImageOffsets,
 
2549
                                dstRowStride, dstSlices,
2690
2550
                                srcWidth, srcHeight, srcDepth, srcAddr,
2691
2551
                                srcPacking);      
2692
2552
   }   
2693
2553
   else {
2694
2554
      /* general path */
2695
 
      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,
 
2555
      const GLubyte *tempImage = _mesa_make_temp_ubyte_image(ctx, dims,
2696
2556
                                                 baseInternalFormat,
2697
2557
                                                 baseFormat,
2698
2558
                                                 srcWidth, srcHeight, srcDepth,
2699
2559
                                                 srcFormat, srcType, srcAddr,
2700
2560
                                                 srcPacking);
2701
 
      const GLchan *src = tempImage;
 
2561
      const GLubyte *src = tempImage;
2702
2562
      GLint img, row, col;
2703
2563
      if (!tempImage)
2704
2564
         return GL_FALSE;
2705
2565
      for (img = 0; img < srcDepth; img++) {
2706
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2707
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2708
 
            + dstYoffset * dstRowStride
2709
 
            + dstXoffset * texelBytes;
 
2566
         GLubyte *dstRow = dstSlices[img];
2710
2567
         for (row = 0; row < srcHeight; row++) {
2711
2568
            for (col = 0; col < srcWidth; col++) {
2712
 
               dstRow[col] = CHAN_TO_UBYTE(src[col]);
 
2569
               dstRow[col] = src[col];
2713
2570
            }
2714
2571
            dstRow += dstRowStride;
2715
2572
            src += srcWidth;
2722
2579
 
2723
2580
 
2724
2581
 
2725
 
static GLboolean
2726
 
_mesa_texstore_ci8(TEXSTORE_PARAMS)
2727
 
{
2728
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2729
 
 
2730
 
   (void) dims; (void) baseInternalFormat;
2731
 
   ASSERT(dstFormat == MESA_FORMAT_CI8);
2732
 
   ASSERT(texelBytes == 1);
2733
 
   ASSERT(baseInternalFormat == GL_COLOR_INDEX);
2734
 
 
2735
 
   if (!ctx->_ImageTransferState &&
2736
 
       !srcPacking->SwapBytes &&
2737
 
       srcFormat == GL_COLOR_INDEX &&
2738
 
       srcType == GL_UNSIGNED_BYTE) {
2739
 
      /* simple memcpy path */
2740
 
      memcpy_texture(ctx, dims,
2741
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2742
 
                     dstRowStride,
2743
 
                     dstImageOffsets,
2744
 
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2745
 
                     srcAddr, srcPacking);
2746
 
   }
2747
 
   else {
2748
 
      /* general path */
2749
 
      GLint img, row;
2750
 
      for (img = 0; img < srcDepth; img++) {
2751
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2752
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2753
 
            + dstYoffset * dstRowStride
2754
 
            + dstXoffset * texelBytes;
2755
 
         for (row = 0; row < srcHeight; row++) {
2756
 
            const GLvoid *src = _mesa_image_address(dims, srcPacking,
2757
 
                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);
2758
 
            _mesa_unpack_index_span(ctx, srcWidth, GL_UNSIGNED_BYTE, dstRow,
2759
 
                                    srcType, src, srcPacking,
2760
 
                                    ctx->_ImageTransferState);
2761
 
            dstRow += dstRowStride;
2762
 
         }
2763
 
      }
2764
 
   }
2765
 
   return GL_TRUE;
2766
 
}
2767
 
 
2768
 
 
2769
2582
/**
2770
2583
 * Texstore for _mesa_texformat_ycbcr or _mesa_texformat_ycbcr_REV.
2771
2584
 */
2773
2586
_mesa_texstore_ycbcr(TEXSTORE_PARAMS)
2774
2587
{
2775
2588
   const GLboolean littleEndian = _mesa_little_endian();
2776
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2777
2589
 
2778
2590
   (void) ctx; (void) dims; (void) baseInternalFormat;
2779
2591
 
2780
2592
   ASSERT((dstFormat == MESA_FORMAT_YCBCR) ||
2781
2593
          (dstFormat == MESA_FORMAT_YCBCR_REV));
2782
 
   ASSERT(texelBytes == 2);
 
2594
   ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
2783
2595
   ASSERT(ctx->Extensions.MESA_ycbcr_texture);
2784
2596
   ASSERT(srcFormat == GL_YCBCR_MESA);
2785
2597
   ASSERT((srcType == GL_UNSIGNED_SHORT_8_8_MESA) ||
2788
2600
 
2789
2601
   /* always just memcpy since no pixel transfer ops apply */
2790
2602
   memcpy_texture(ctx, dims,
2791
 
                  dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2792
 
                  dstRowStride,
2793
 
                  dstImageOffsets,
 
2603
                  dstFormat,
 
2604
                  dstRowStride, dstSlices,
2794
2605
                  srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2795
2606
                  srcAddr, srcPacking);
2796
2607
 
2802
2613
       !littleEndian) {
2803
2614
      GLint img, row;
2804
2615
      for (img = 0; img < srcDepth; img++) {
2805
 
         GLubyte *dstRow = (GLubyte *) dstAddr
2806
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2807
 
            + dstYoffset * dstRowStride
2808
 
            + dstXoffset * texelBytes;
 
2616
         GLubyte *dstRow = dstSlices[img];
2809
2617
         for (row = 0; row < srcHeight; row++) {
2810
2618
            _mesa_swap2((GLushort *) dstRow, srcWidth);
2811
2619
            dstRow += dstRowStride;
2832
2640
       littleEndian) {
2833
2641
      /* simple memcpy path */
2834
2642
      memcpy_texture(ctx, dims,
2835
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2836
 
                     dstRowStride,
2837
 
                     dstImageOffsets,
 
2643
                     dstFormat,
 
2644
                     dstRowStride, dstSlices,
2838
2645
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2839
2646
                     srcAddr, srcPacking);
2840
2647
   }
2859
2666
                                GL_UNSIGNED_BYTE, /* hack */
2860
2667
                                GL_LUMINANCE_ALPHA, /* hack */
2861
2668
                                dstmap, 2,
2862
 
                                dstAddr, dstXoffset, dstYoffset, dstZoffset,
2863
 
                                dstRowStride, dstImageOffsets,
 
2669
                                dstRowStride, dstSlices,
2864
2670
                                srcWidth, srcHeight, srcDepth, srcAddr,
2865
2671
                                srcPacking);      
2866
2672
   }   
2892
2698
      }
2893
2699
 
2894
2700
      src = tempImage;
2895
 
      dst = (GLbyte *) dstAddr
2896
 
            + dstYoffset * dstRowStride
2897
 
            + dstXoffset * texelBytes;
 
2701
      dst = (GLbyte *) dstSlices[0];
2898
2702
      for (row = 0; row < srcHeight; row++) {
2899
2703
         memcpy(dst, src, srcWidth * texelBytes);
2900
2704
         dst += dstRowStride;
2912
2716
static GLboolean
2913
2717
_mesa_texstore_snorm8(TEXSTORE_PARAMS)
2914
2718
{
2915
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2916
2719
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2917
2720
 
2918
2721
   ASSERT(dstFormat == MESA_FORMAT_SIGNED_A8 ||
2919
2722
          dstFormat == MESA_FORMAT_SIGNED_L8 ||
2920
2723
          dstFormat == MESA_FORMAT_SIGNED_I8 ||
2921
2724
          dstFormat == MESA_FORMAT_SIGNED_R8);
2922
 
   ASSERT(texelBytes == 1);
 
2725
   ASSERT(_mesa_get_format_bytes(dstFormat) == 1);
2923
2726
 
2924
2727
   if (!ctx->_ImageTransferState &&
2925
2728
       !srcPacking->SwapBytes &&
2927
2730
       srcType == GL_BYTE) {
2928
2731
      /* simple memcpy path */
2929
2732
      memcpy_texture(ctx, dims,
2930
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2931
 
                     dstRowStride,
2932
 
                     dstImageOffsets,
 
2733
                     dstFormat,
 
2734
                     dstRowStride, dstSlices,
2933
2735
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2934
2736
                     srcAddr, srcPacking);
2935
2737
   }
2947
2749
      if (!tempImage)
2948
2750
         return GL_FALSE;
2949
2751
      for (img = 0; img < srcDepth; img++) {
2950
 
         GLbyte *dstRow = (GLbyte *) dstAddr
2951
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
2952
 
            + dstYoffset * dstRowStride
2953
 
            + dstXoffset * texelBytes;
 
2752
         GLbyte *dstRow = (GLbyte *) dstSlices[img];
2954
2753
         for (row = 0; row < srcHeight; row++) {
2955
2754
            for (col = 0; col < srcWidth; col++) {
2956
2755
               dstRow[col] = FLOAT_TO_BYTE_TEX(src[col]);
2972
2771
_mesa_texstore_snorm88(TEXSTORE_PARAMS)
2973
2772
{
2974
2773
   const GLboolean littleEndian = _mesa_little_endian();
2975
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
2976
2774
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
2977
2775
 
2978
2776
   ASSERT(dstFormat == MESA_FORMAT_SIGNED_AL88 ||
2979
2777
          dstFormat == MESA_FORMAT_SIGNED_RG88_REV);
2980
 
   ASSERT(texelBytes == 2);
 
2778
   ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
2981
2779
 
2982
2780
   if (!ctx->_ImageTransferState &&
2983
2781
       !srcPacking->SwapBytes &&
2986
2784
       littleEndian) {
2987
2785
      /* simple memcpy path */
2988
2786
      memcpy_texture(ctx, dims,
2989
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
2990
 
                     dstRowStride,
2991
 
                     dstImageOffsets,
 
2787
                     dstFormat,
 
2788
                     dstRowStride, dstSlices,
2992
2789
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
2993
2790
                     srcAddr, srcPacking);
2994
2791
   }
3006
2803
      if (!tempImage)
3007
2804
         return GL_FALSE;
3008
2805
      for (img = 0; img < srcDepth; img++) {
3009
 
         GLbyte *dstRow = (GLbyte *) dstAddr
3010
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3011
 
            + dstYoffset * dstRowStride
3012
 
            + dstXoffset * texelBytes;
 
2806
         GLbyte *dstRow = (GLbyte *) dstSlices[img];
3013
2807
         for (row = 0; row < srcHeight; row++) {
3014
2808
            GLbyte *dst = dstRow;
3015
2809
            for (col = 0; col < srcWidth; col++) {
3031
2825
_mesa_texstore_snorm16(TEXSTORE_PARAMS)
3032
2826
{
3033
2827
   const GLboolean littleEndian = _mesa_little_endian();
3034
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3035
2828
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3036
2829
 
3037
2830
   ASSERT(dstFormat == MESA_FORMAT_SIGNED_R16 ||
3038
2831
          dstFormat == MESA_FORMAT_SIGNED_A16 ||
3039
2832
          dstFormat == MESA_FORMAT_SIGNED_L16 ||
3040
2833
          dstFormat == MESA_FORMAT_SIGNED_I16);
3041
 
   ASSERT(texelBytes == 2);
 
2834
   ASSERT(_mesa_get_format_bytes(dstFormat) == 2);
3042
2835
 
3043
2836
   if (!ctx->_ImageTransferState &&
3044
2837
       !srcPacking->SwapBytes &&
3047
2840
       littleEndian) {
3048
2841
      /* simple memcpy path */
3049
2842
      memcpy_texture(ctx, dims,
3050
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3051
 
                     dstRowStride,
3052
 
                     dstImageOffsets,
 
2843
                     dstFormat,
 
2844
                     dstRowStride, dstSlices,
3053
2845
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3054
2846
                     srcAddr, srcPacking);
3055
2847
   }
3067
2859
      if (!tempImage)
3068
2860
         return GL_FALSE;
3069
2861
      for (img = 0; img < srcDepth; img++) {
3070
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3071
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3072
 
            + dstYoffset * dstRowStride
3073
 
            + dstXoffset * texelBytes;
 
2862
         GLubyte *dstRow = dstSlices[img];
3074
2863
         for (row = 0; row < srcHeight; row++) {
3075
2864
            GLshort *dstUS = (GLshort *) dstRow;
3076
2865
            for (col = 0; col < srcWidth; col++) {
3095
2884
_mesa_texstore_snorm1616(TEXSTORE_PARAMS)
3096
2885
{
3097
2886
   const GLboolean littleEndian = _mesa_little_endian();
3098
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3099
2887
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3100
2888
 
3101
2889
   ASSERT(dstFormat == MESA_FORMAT_SIGNED_AL1616 ||
3102
2890
          dstFormat == MESA_FORMAT_SIGNED_GR1616);
3103
 
   ASSERT(texelBytes == 4);
 
2891
   ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
3104
2892
 
3105
2893
   if (!ctx->_ImageTransferState &&
3106
2894
       !srcPacking->SwapBytes &&
3109
2897
       littleEndian) {
3110
2898
      /* simple memcpy path */
3111
2899
      memcpy_texture(ctx, dims,
3112
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3113
 
                     dstRowStride,
3114
 
                     dstImageOffsets,
 
2900
                     dstFormat,
 
2901
                     dstRowStride, dstSlices,
3115
2902
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3116
2903
                     srcAddr, srcPacking);
3117
2904
   }
3129
2916
      if (!tempImage)
3130
2917
         return GL_FALSE;
3131
2918
      for (img = 0; img < srcDepth; img++) {
3132
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3133
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3134
 
            + dstYoffset * dstRowStride
3135
 
            + dstXoffset * texelBytes;
 
2919
         GLubyte *dstRow = dstSlices[img];
3136
2920
         for (row = 0; row < srcHeight; row++) {
3137
2921
            GLshort *dst = (GLshort *) dstRow;
3138
2922
            for (col = 0; col < srcWidth; col++) {
3159
2943
static GLboolean
3160
2944
_mesa_texstore_signed_rgbx8888(TEXSTORE_PARAMS)
3161
2945
{
3162
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3163
2946
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3164
2947
 
3165
2948
   ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBX8888);
3166
 
   ASSERT(texelBytes == 4);
 
2949
   ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
3167
2950
 
3168
2951
   {
3169
2952
      /* general path */
3179
2962
      if (!tempImage)
3180
2963
         return GL_FALSE;
3181
2964
      for (img = 0; img < srcDepth; img++) {
3182
 
         GLbyte *dstRow = (GLbyte *) dstAddr
3183
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3184
 
            + dstYoffset * dstRowStride
3185
 
            + dstXoffset * texelBytes;
 
2965
         GLbyte *dstRow = (GLbyte *) dstSlices[img];
3186
2966
         for (row = 0; row < srcHeight; row++) {
3187
2967
            GLbyte *dst = dstRow;
3188
2968
            for (col = 0; col < srcWidth; col++) {
3211
2991
_mesa_texstore_signed_rgba8888(TEXSTORE_PARAMS)
3212
2992
{
3213
2993
   const GLboolean littleEndian = _mesa_little_endian();
3214
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3215
2994
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3216
2995
 
3217
2996
   ASSERT(dstFormat == MESA_FORMAT_SIGNED_RGBA8888 ||
3218
2997
          dstFormat == MESA_FORMAT_SIGNED_RGBA8888_REV);
3219
 
   ASSERT(texelBytes == 4);
 
2998
   ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
3220
2999
 
3221
3000
   if (!ctx->_ImageTransferState &&
3222
3001
       !srcPacking->SwapBytes &&
3226
3005
       (srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && littleEndian))) {
3227
3006
       /* simple memcpy path */
3228
3007
      memcpy_texture(ctx, dims,
3229
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3230
 
                     dstRowStride,
3231
 
                     dstImageOffsets,
 
3008
                     dstFormat,
 
3009
                     dstRowStride, dstSlices,
3232
3010
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3233
3011
                     srcAddr, srcPacking);
3234
3012
   }
3240
3018
       (srcFormat == GL_ABGR_EXT && srcType == GL_BYTE && !littleEndian))) {
3241
3019
      /* simple memcpy path */
3242
3020
      memcpy_texture(ctx, dims,
3243
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3244
 
                     dstRowStride,
3245
 
                     dstImageOffsets,
 
3021
                     dstFormat,
 
3022
                     dstRowStride, dstSlices,
3246
3023
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3247
3024
                     srcAddr, srcPacking);
3248
3025
   }
3260
3037
      if (!tempImage)
3261
3038
         return GL_FALSE;
3262
3039
      for (img = 0; img < srcDepth; img++) {
3263
 
         GLbyte *dstRow = (GLbyte *) dstAddr
3264
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3265
 
            + dstYoffset * dstRowStride
3266
 
            + dstXoffset * texelBytes;
 
3040
         GLbyte *dstRow = (GLbyte *) dstSlices[img];
3267
3041
         for (row = 0; row < srcHeight; row++) {
3268
3042
            GLbyte *dst = dstRow;
3269
3043
            if (dstFormat == MESA_FORMAT_SIGNED_RGBA8888) {
3303
3077
{
3304
3078
   const GLuint depthScale = 0xffffff;
3305
3079
   const GLint srcRowStride
3306
 
      = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
3307
 
      / sizeof(GLuint);
 
3080
      = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
3308
3081
   GLint img, row;
3309
3082
 
3310
3083
   ASSERT(dstFormat == MESA_FORMAT_Z24_S8);
3318
3091
       !srcPacking->SwapBytes) {
3319
3092
      /* simple path */
3320
3093
      memcpy_texture(ctx, dims,
3321
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3322
 
                     dstRowStride,
3323
 
                     dstImageOffsets,
 
3094
                     dstFormat,
 
3095
                     dstRowStride, dstSlices,
3324
3096
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3325
3097
                     srcAddr, srcPacking);
3326
3098
   }
3328
3100
            srcFormat == GL_STENCIL_INDEX) {
3329
3101
      /* In case we only upload depth we need to preserve the stencil */
3330
3102
      for (img = 0; img < srcDepth; img++) {
3331
 
         GLuint *dstRow = (GLuint *) dstAddr
3332
 
            + dstImageOffsets[dstZoffset + img]
3333
 
            + dstYoffset * dstRowStride / sizeof(GLuint)
3334
 
            + dstXoffset;
3335
 
         const GLuint *src
3336
 
            = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
 
3103
         GLuint *dstRow = (GLuint *) dstSlices[img];
 
3104
         const GLubyte *src
 
3105
            = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
3337
3106
                  srcWidth, srcHeight,
3338
3107
                  srcFormat, srcType,
3339
3108
                  img, 0, 0);
3390
3159
{
3391
3160
   const GLuint depthScale = 0xffffff;
3392
3161
   const GLint srcRowStride
3393
 
      = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
3394
 
      / sizeof(GLuint);
 
3162
      = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
3395
3163
   GLint img, row;
3396
3164
 
3397
3165
   ASSERT(dstFormat == MESA_FORMAT_S8_Z24);
3402
3170
          srcType == GL_UNSIGNED_INT_24_8_EXT);
3403
3171
 
3404
3172
   for (img = 0; img < srcDepth; img++) {
3405
 
      GLuint *dstRow = (GLuint *) dstAddr
3406
 
         + dstImageOffsets[dstZoffset + img]
3407
 
         + dstYoffset * dstRowStride / sizeof(GLuint)
3408
 
         + dstXoffset;
3409
 
      const GLuint *src
3410
 
         = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
 
3173
      GLuint *dstRow = (GLuint *) dstSlices[img];
 
3174
      const GLubyte *src
 
3175
         = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
3411
3176
                                                srcWidth, srcHeight,
3412
3177
                                                srcFormat, srcType,
3413
3178
                                                img, 0, 0);
3471
3236
       srcType == GL_UNSIGNED_BYTE) {
3472
3237
      /* simple memcpy path */
3473
3238
      memcpy_texture(ctx, dims,
3474
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3475
 
                     dstRowStride,
3476
 
                     dstImageOffsets,
 
3239
                     dstFormat,
 
3240
                     dstRowStride, dstSlices,
3477
3241
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3478
3242
                     srcAddr, srcPacking);
3479
3243
   }
3480
3244
   else {
3481
3245
      const GLint srcRowStride
3482
 
         = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
3483
 
         / sizeof(GLuint);
 
3246
         = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType);
3484
3247
      GLint img, row;
3485
3248
      
3486
3249
      for (img = 0; img < srcDepth; img++) {
3487
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3488
 
            + dstImageOffsets[dstZoffset + img]
3489
 
            + dstYoffset * dstRowStride / sizeof(GLuint)
3490
 
            + dstXoffset;
3491
 
         const GLuint *src
3492
 
            = (const GLuint *) _mesa_image_address(dims, srcPacking, srcAddr,
 
3250
         GLubyte *dstRow = dstSlices[img];
 
3251
         const GLubyte *src
 
3252
            = (const GLubyte *) _mesa_image_address(dims, srcPacking, srcAddr,
3493
3253
                                                   srcWidth, srcHeight,
3494
3254
                                                   srcFormat, srcType,
3495
3255
                                                   img, 0, 0);
3530
3290
static GLboolean
3531
3291
_mesa_texstore_rgba_float32(TEXSTORE_PARAMS)
3532
3292
{
3533
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3534
3293
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3535
3294
   const GLint components = _mesa_components_in_format(baseFormat);
3536
3295
 
3550
3309
          baseInternalFormat == GL_INTENSITY ||
3551
3310
          baseInternalFormat == GL_RED ||
3552
3311
          baseInternalFormat == GL_RG);
3553
 
   ASSERT(texelBytes == components * sizeof(GLfloat));
 
3312
   ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLfloat));
3554
3313
 
3555
3314
   if (!ctx->_ImageTransferState &&
3556
3315
       !srcPacking->SwapBytes &&
3559
3318
       srcType == GL_FLOAT) {
3560
3319
      /* simple memcpy path */
3561
3320
      memcpy_texture(ctx, dims,
3562
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3563
 
                     dstRowStride,
3564
 
                     dstImageOffsets,
 
3321
                     dstFormat,
 
3322
                     dstRowStride, dstSlices,
3565
3323
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3566
3324
                     srcAddr, srcPacking);
3567
3325
   }
3581
3339
         return GL_FALSE;
3582
3340
      bytesPerRow = srcWidth * components * sizeof(GLfloat);
3583
3341
      for (img = 0; img < srcDepth; img++) {
3584
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3585
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3586
 
            + dstYoffset * dstRowStride
3587
 
            + dstXoffset * texelBytes;
 
3342
         GLubyte *dstRow = dstSlices[img];
3588
3343
         for (row = 0; row < srcHeight; row++) {
3589
3344
            memcpy(dstRow, srcRow, bytesPerRow);
3590
3345
            dstRow += dstRowStride;
3605
3360
static GLboolean
3606
3361
_mesa_texstore_rgba_float16(TEXSTORE_PARAMS)
3607
3362
{
3608
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3609
3363
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3610
3364
   const GLint components = _mesa_components_in_format(baseFormat);
3611
3365
 
3625
3379
          baseInternalFormat == GL_INTENSITY ||
3626
3380
          baseInternalFormat == GL_RED ||
3627
3381
          baseInternalFormat == GL_RG);
3628
 
   ASSERT(texelBytes == components * sizeof(GLhalfARB));
 
3382
   ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLhalfARB));
3629
3383
 
3630
3384
   if (!ctx->_ImageTransferState &&
3631
3385
       !srcPacking->SwapBytes &&
3634
3388
       srcType == GL_HALF_FLOAT_ARB) {
3635
3389
      /* simple memcpy path */
3636
3390
      memcpy_texture(ctx, dims,
3637
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3638
 
                     dstRowStride,
3639
 
                     dstImageOffsets,
 
3391
                     dstFormat,
 
3392
                     dstRowStride, dstSlices,
3640
3393
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3641
3394
                     srcAddr, srcPacking);
3642
3395
   }
3654
3407
      if (!tempImage)
3655
3408
         return GL_FALSE;
3656
3409
      for (img = 0; img < srcDepth; img++) {
3657
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3658
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3659
 
            + dstYoffset * dstRowStride
3660
 
            + dstXoffset * texelBytes;
 
3410
         GLubyte *dstRow = dstSlices[img];
3661
3411
         for (row = 0; row < srcHeight; row++) {
3662
3412
            GLhalfARB *dstTexel = (GLhalfARB *) dstRow;
3663
3413
            GLint i;
3679
3429
static GLboolean
3680
3430
_mesa_texstore_rgba_int8(TEXSTORE_PARAMS)
3681
3431
{
3682
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3683
3432
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3684
3433
   const GLint components = _mesa_components_in_format(baseFormat);
3685
3434
 
3686
 
   ASSERT(dstFormat == MESA_FORMAT_RGBA_INT8);
 
3435
   ASSERT(dstFormat == MESA_FORMAT_R_INT8 ||
 
3436
          dstFormat == MESA_FORMAT_RG_INT8 ||
 
3437
          dstFormat == MESA_FORMAT_RGB_INT8 ||
 
3438
          dstFormat == MESA_FORMAT_RGBA_INT8 ||
 
3439
          dstFormat == MESA_FORMAT_ALPHA_INT8 ||
 
3440
          dstFormat == MESA_FORMAT_INTENSITY_INT8 ||
 
3441
          dstFormat == MESA_FORMAT_LUMINANCE_INT8 ||
 
3442
          dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_INT8);
3687
3443
   ASSERT(baseInternalFormat == GL_RGBA ||
3688
3444
          baseInternalFormat == GL_RGB ||
 
3445
          baseInternalFormat == GL_RG ||
 
3446
          baseInternalFormat == GL_RED ||
3689
3447
          baseInternalFormat == GL_ALPHA ||
3690
3448
          baseInternalFormat == GL_LUMINANCE ||
3691
3449
          baseInternalFormat == GL_LUMINANCE_ALPHA ||
3692
3450
          baseInternalFormat == GL_INTENSITY);
3693
 
   ASSERT(texelBytes == components * sizeof(GLbyte));
 
3451
   ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLbyte));
3694
3452
 
3695
3453
   /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3696
3454
    * to integer formats.
3700
3458
       srcType == GL_BYTE) {
3701
3459
      /* simple memcpy path */
3702
3460
      memcpy_texture(ctx, dims,
3703
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3704
 
                     dstRowStride,
3705
 
                     dstImageOffsets,
 
3461
                     dstFormat,
 
3462
                     dstRowStride, dstSlices,
3706
3463
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3707
3464
                     srcAddr, srcPacking);
3708
3465
   }
3719
3476
      if (!tempImage)
3720
3477
         return GL_FALSE;
3721
3478
      for (img = 0; img < srcDepth; img++) {
3722
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3723
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3724
 
            + dstYoffset * dstRowStride
3725
 
            + dstXoffset * texelBytes;
 
3479
         GLubyte *dstRow = dstSlices[img];
3726
3480
         for (row = 0; row < srcHeight; row++) {
3727
3481
            GLbyte *dstTexel = (GLbyte *) dstRow;
3728
3482
            GLint i;
3744
3498
static GLboolean
3745
3499
_mesa_texstore_rgba_int16(TEXSTORE_PARAMS)
3746
3500
{
3747
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3748
3501
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3749
3502
   const GLint components = _mesa_components_in_format(baseFormat);
3750
3503
 
3751
 
   ASSERT(dstFormat == MESA_FORMAT_RGBA_INT16);
 
3504
   ASSERT(dstFormat == MESA_FORMAT_R_INT16 ||
 
3505
          dstFormat == MESA_FORMAT_RG_INT16 ||
 
3506
          dstFormat == MESA_FORMAT_RGB_INT16 ||
 
3507
          dstFormat == MESA_FORMAT_RGBA_INT16 ||
 
3508
          dstFormat == MESA_FORMAT_ALPHA_INT16 ||
 
3509
          dstFormat == MESA_FORMAT_LUMINANCE_INT16 ||
 
3510
          dstFormat == MESA_FORMAT_INTENSITY_INT16 ||
 
3511
          dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_INT16);
3752
3512
   ASSERT(baseInternalFormat == GL_RGBA ||
3753
3513
          baseInternalFormat == GL_RGB ||
 
3514
          baseInternalFormat == GL_RG ||
 
3515
          baseInternalFormat == GL_RED ||
3754
3516
          baseInternalFormat == GL_ALPHA ||
3755
3517
          baseInternalFormat == GL_LUMINANCE ||
3756
3518
          baseInternalFormat == GL_LUMINANCE_ALPHA ||
3757
3519
          baseInternalFormat == GL_INTENSITY);
3758
 
   ASSERT(texelBytes == components * sizeof(GLshort));
 
3520
   ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLshort));
3759
3521
 
3760
3522
   /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3761
3523
    * to integer formats.
3765
3527
       srcType == GL_SHORT) {
3766
3528
      /* simple memcpy path */
3767
3529
      memcpy_texture(ctx, dims,
3768
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3769
 
                     dstRowStride,
3770
 
                     dstImageOffsets,
 
3530
                     dstFormat,
 
3531
                     dstRowStride, dstSlices,
3771
3532
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3772
3533
                     srcAddr, srcPacking);
3773
3534
   }
3784
3545
      if (!tempImage)
3785
3546
         return GL_FALSE;
3786
3547
      for (img = 0; img < srcDepth; img++) {
3787
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3788
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3789
 
            + dstYoffset * dstRowStride
3790
 
            + dstXoffset * texelBytes;
 
3548
         GLubyte *dstRow = dstSlices[img];
3791
3549
         for (row = 0; row < srcHeight; row++) {
3792
3550
            GLshort *dstTexel = (GLshort *) dstRow;
3793
3551
            GLint i;
3809
3567
static GLboolean
3810
3568
_mesa_texstore_rgba_int32(TEXSTORE_PARAMS)
3811
3569
{
3812
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3813
3570
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3814
3571
   const GLint components = _mesa_components_in_format(baseFormat);
3815
3572
 
3816
 
   ASSERT(dstFormat == MESA_FORMAT_RGBA_INT32);
 
3573
   ASSERT(dstFormat == MESA_FORMAT_R_INT32 ||
 
3574
          dstFormat == MESA_FORMAT_RG_INT32 ||
 
3575
          dstFormat == MESA_FORMAT_RGB_INT32 ||
 
3576
          dstFormat == MESA_FORMAT_RGBA_INT32 ||
 
3577
          dstFormat == MESA_FORMAT_ALPHA_INT32 ||
 
3578
          dstFormat == MESA_FORMAT_INTENSITY_INT32 ||
 
3579
          dstFormat == MESA_FORMAT_LUMINANCE_INT32 ||
 
3580
          dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_INT32);
3817
3581
   ASSERT(baseInternalFormat == GL_RGBA ||
3818
3582
          baseInternalFormat == GL_RGB ||
 
3583
          baseInternalFormat == GL_RG ||
 
3584
          baseInternalFormat == GL_RED ||
3819
3585
          baseInternalFormat == GL_ALPHA ||
3820
3586
          baseInternalFormat == GL_LUMINANCE ||
3821
3587
          baseInternalFormat == GL_LUMINANCE_ALPHA ||
3822
3588
          baseInternalFormat == GL_INTENSITY);
3823
 
   ASSERT(texelBytes == components * sizeof(GLint));
 
3589
   ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLint));
3824
3590
 
3825
3591
   /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3826
3592
    * to integer formats.
3830
3596
       srcType == GL_INT) {
3831
3597
      /* simple memcpy path */
3832
3598
      memcpy_texture(ctx, dims,
3833
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3834
 
                     dstRowStride,
3835
 
                     dstImageOffsets,
 
3599
                     dstFormat,
 
3600
                     dstRowStride, dstSlices,
3836
3601
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3837
3602
                     srcAddr, srcPacking);
3838
3603
   }
3849
3614
      if (!tempImage)
3850
3615
         return GL_FALSE;
3851
3616
      for (img = 0; img < srcDepth; img++) {
3852
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3853
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3854
 
            + dstYoffset * dstRowStride
3855
 
            + dstXoffset * texelBytes;
 
3617
         GLubyte *dstRow = dstSlices[img];
3856
3618
         for (row = 0; row < srcHeight; row++) {
3857
3619
            GLint *dstTexel = (GLint *) dstRow;
3858
3620
            GLint i;
3874
3636
static GLboolean
3875
3637
_mesa_texstore_rgba_uint8(TEXSTORE_PARAMS)
3876
3638
{
3877
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3878
3639
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3879
3640
   const GLint components = _mesa_components_in_format(baseFormat);
3880
3641
 
3881
 
   ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT8);
 
3642
   ASSERT(dstFormat == MESA_FORMAT_R_UINT8 ||
 
3643
          dstFormat == MESA_FORMAT_RG_UINT8 ||
 
3644
          dstFormat == MESA_FORMAT_RGB_UINT8 ||
 
3645
          dstFormat == MESA_FORMAT_RGBA_UINT8 ||
 
3646
          dstFormat == MESA_FORMAT_ALPHA_UINT8 ||
 
3647
          dstFormat == MESA_FORMAT_INTENSITY_UINT8 ||
 
3648
          dstFormat == MESA_FORMAT_LUMINANCE_UINT8 ||
 
3649
          dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_UINT8);
3882
3650
   ASSERT(baseInternalFormat == GL_RGBA ||
3883
3651
          baseInternalFormat == GL_RGB ||
 
3652
          baseInternalFormat == GL_RG ||
 
3653
          baseInternalFormat == GL_RED ||
3884
3654
          baseInternalFormat == GL_ALPHA ||
3885
3655
          baseInternalFormat == GL_LUMINANCE ||
3886
3656
          baseInternalFormat == GL_LUMINANCE_ALPHA ||
3887
3657
          baseInternalFormat == GL_INTENSITY);
3888
 
   ASSERT(texelBytes == components * sizeof(GLubyte));
 
3658
   ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLubyte));
3889
3659
 
3890
3660
   /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3891
3661
    * to integer formats.
3895
3665
       srcType == GL_UNSIGNED_BYTE) {
3896
3666
      /* simple memcpy path */
3897
3667
      memcpy_texture(ctx, dims,
3898
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3899
 
                     dstRowStride,
3900
 
                     dstImageOffsets,
 
3668
                     dstFormat,
 
3669
                     dstRowStride, dstSlices,
3901
3670
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3902
3671
                     srcAddr, srcPacking);
3903
3672
   }
3912
3681
      if (!tempImage)
3913
3682
         return GL_FALSE;
3914
3683
      for (img = 0; img < srcDepth; img++) {
3915
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3916
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3917
 
            + dstYoffset * dstRowStride
3918
 
            + dstXoffset * texelBytes;
 
3684
         GLubyte *dstRow = dstSlices[img];
3919
3685
         for (row = 0; row < srcHeight; row++) {
3920
3686
            GLubyte *dstTexel = (GLubyte *) dstRow;
3921
3687
            GLint i;
3937
3703
static GLboolean
3938
3704
_mesa_texstore_rgba_uint16(TEXSTORE_PARAMS)
3939
3705
{
3940
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
3941
3706
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
3942
3707
   const GLint components = _mesa_components_in_format(baseFormat);
3943
3708
 
3944
 
   ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT16);
 
3709
   ASSERT(dstFormat == MESA_FORMAT_R_UINT16 ||
 
3710
          dstFormat == MESA_FORMAT_RG_UINT16 ||
 
3711
          dstFormat == MESA_FORMAT_RGB_UINT16 ||
 
3712
          dstFormat == MESA_FORMAT_RGBA_UINT16 ||
 
3713
          dstFormat == MESA_FORMAT_ALPHA_UINT16 ||
 
3714
          dstFormat == MESA_FORMAT_INTENSITY_UINT16 ||
 
3715
          dstFormat == MESA_FORMAT_LUMINANCE_UINT16 ||
 
3716
          dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_UINT16);
3945
3717
   ASSERT(baseInternalFormat == GL_RGBA ||
3946
3718
          baseInternalFormat == GL_RGB ||
 
3719
          baseInternalFormat == GL_RG ||
 
3720
          baseInternalFormat == GL_RED ||
3947
3721
          baseInternalFormat == GL_ALPHA ||
3948
3722
          baseInternalFormat == GL_LUMINANCE ||
3949
3723
          baseInternalFormat == GL_LUMINANCE_ALPHA ||
3950
3724
          baseInternalFormat == GL_INTENSITY);
3951
 
   ASSERT(texelBytes == components * sizeof(GLushort));
 
3725
   ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLushort));
3952
3726
 
3953
3727
   /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
3954
3728
    * to integer formats.
3958
3732
       srcType == GL_UNSIGNED_SHORT) {
3959
3733
      /* simple memcpy path */
3960
3734
      memcpy_texture(ctx, dims,
3961
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
3962
 
                     dstRowStride,
3963
 
                     dstImageOffsets,
 
3735
                     dstFormat,
 
3736
                     dstRowStride, dstSlices,
3964
3737
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
3965
3738
                     srcAddr, srcPacking);
3966
3739
   }
3975
3748
      if (!tempImage)
3976
3749
         return GL_FALSE;
3977
3750
      for (img = 0; img < srcDepth; img++) {
3978
 
         GLubyte *dstRow = (GLubyte *) dstAddr
3979
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
3980
 
            + dstYoffset * dstRowStride
3981
 
            + dstXoffset * texelBytes;
 
3751
         GLubyte *dstRow = dstSlices[img];
3982
3752
         for (row = 0; row < srcHeight; row++) {
3983
3753
            GLushort *dstTexel = (GLushort *) dstRow;
3984
3754
            GLint i;
4000
3770
static GLboolean
4001
3771
_mesa_texstore_rgba_uint32(TEXSTORE_PARAMS)
4002
3772
{
4003
 
   const GLuint texelBytes = _mesa_get_format_bytes(dstFormat);
4004
3773
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
4005
3774
   const GLint components = _mesa_components_in_format(baseFormat);
4006
3775
 
4007
 
   ASSERT(dstFormat == MESA_FORMAT_RGBA_UINT32);
 
3776
   ASSERT(dstFormat == MESA_FORMAT_R_UINT32 ||
 
3777
          dstFormat == MESA_FORMAT_RG_UINT32 ||
 
3778
          dstFormat == MESA_FORMAT_RGB_UINT32 ||
 
3779
          dstFormat == MESA_FORMAT_RGBA_UINT32 ||
 
3780
          dstFormat == MESA_FORMAT_ALPHA_UINT32 ||
 
3781
          dstFormat == MESA_FORMAT_INTENSITY_UINT32 ||
 
3782
          dstFormat == MESA_FORMAT_LUMINANCE_UINT32 ||
 
3783
          dstFormat == MESA_FORMAT_LUMINANCE_ALPHA_UINT32);
4008
3784
   ASSERT(baseInternalFormat == GL_RGBA ||
4009
3785
          baseInternalFormat == GL_RGB ||
 
3786
          baseInternalFormat == GL_RG ||
 
3787
          baseInternalFormat == GL_RED ||
4010
3788
          baseInternalFormat == GL_ALPHA ||
4011
3789
          baseInternalFormat == GL_LUMINANCE ||
4012
3790
          baseInternalFormat == GL_LUMINANCE_ALPHA ||
4013
3791
          baseInternalFormat == GL_INTENSITY);
4014
 
   ASSERT(texelBytes == components * sizeof(GLuint));
 
3792
   ASSERT(_mesa_get_format_bytes(dstFormat) == components * sizeof(GLuint));
4015
3793
 
4016
3794
   /* Note: Pixel transfer ops (scale, bias, table lookup) do not apply
4017
3795
    * to integer formats.
4021
3799
       srcType == GL_UNSIGNED_INT) {
4022
3800
      /* simple memcpy path */
4023
3801
      memcpy_texture(ctx, dims,
4024
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
4025
 
                     dstRowStride,
4026
 
                     dstImageOffsets,
 
3802
                     dstFormat,
 
3803
                     dstRowStride, dstSlices,
4027
3804
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
4028
3805
                     srcAddr, srcPacking);
4029
3806
   }
4038
3815
      if (!tempImage)
4039
3816
         return GL_FALSE;
4040
3817
      for (img = 0; img < srcDepth; img++) {
4041
 
         GLubyte *dstRow = (GLubyte *) dstAddr
4042
 
            + dstImageOffsets[dstZoffset + img] * texelBytes
4043
 
            + dstYoffset * dstRowStride
4044
 
            + dstXoffset * texelBytes;
 
3818
         GLubyte *dstRow = dstSlices[img];
4045
3819
         for (row = 0; row < srcHeight; row++) {
4046
3820
            GLuint *dstTexel = (GLuint *) dstRow;
4047
3821
            GLint i;
4074
3848
   newDstFormat = MESA_FORMAT_RGB888;
4075
3849
 
4076
3850
   k = _mesa_texstore_rgb888(ctx, dims, baseInternalFormat,
4077
 
                             newDstFormat, dstAddr,
4078
 
                             dstXoffset, dstYoffset, dstZoffset,
4079
 
                             dstRowStride, dstImageOffsets,
 
3851
                             newDstFormat,
 
3852
                             dstRowStride, dstSlices,
4080
3853
                             srcWidth, srcHeight, srcDepth,
4081
3854
                             srcFormat, srcType,
4082
3855
                             srcAddr, srcPacking);
4095
3868
   /* reuse normal rgba texstore code */
4096
3869
   newDstFormat = MESA_FORMAT_RGBA8888;
4097
3870
   k = _mesa_texstore_rgba8888(ctx, dims, baseInternalFormat,
4098
 
                               newDstFormat, dstAddr,
4099
 
                               dstXoffset, dstYoffset, dstZoffset,
4100
 
                               dstRowStride, dstImageOffsets,
 
3871
                               newDstFormat,
 
3872
                               dstRowStride, dstSlices,
4101
3873
                               srcWidth, srcHeight, srcDepth,
4102
3874
                               srcFormat, srcType,
4103
3875
                               srcAddr, srcPacking);
4117
3889
   newDstFormat = MESA_FORMAT_ARGB8888;
4118
3890
 
4119
3891
   k = _mesa_texstore_argb8888(ctx, dims, baseInternalFormat,
4120
 
                               newDstFormat, dstAddr,
4121
 
                               dstXoffset, dstYoffset, dstZoffset,
4122
 
                               dstRowStride, dstImageOffsets,
 
3892
                               newDstFormat,
 
3893
                               dstRowStride, dstSlices,
4123
3894
                               srcWidth, srcHeight, srcDepth,
4124
3895
                               srcFormat, srcType,
4125
3896
                               srcAddr, srcPacking);
4139
3910
 
4140
3911
   /* _mesa_textore_a8 handles luminance8 too */
4141
3912
   k = _mesa_texstore_unorm8(ctx, dims, baseInternalFormat,
4142
 
                         newDstFormat, dstAddr,
4143
 
                         dstXoffset, dstYoffset, dstZoffset,
4144
 
                         dstRowStride, dstImageOffsets,
4145
 
                         srcWidth, srcHeight, srcDepth,
4146
 
                         srcFormat, srcType,
4147
 
                         srcAddr, srcPacking);
 
3913
                             newDstFormat,
 
3914
                             dstRowStride, dstSlices,
 
3915
                             srcWidth, srcHeight, srcDepth,
 
3916
                             srcFormat, srcType,
 
3917
                             srcAddr, srcPacking);
4148
3918
   return k;
4149
3919
}
4150
3920
 
4161
3931
   newDstFormat = MESA_FORMAT_AL88;
4162
3932
 
4163
3933
   k = _mesa_texstore_unorm88(ctx, dims, baseInternalFormat,
4164
 
                              newDstFormat, dstAddr,
4165
 
                              dstXoffset, dstYoffset, dstZoffset,
4166
 
                              dstRowStride, dstImageOffsets,
 
3934
                              newDstFormat,
 
3935
                              dstRowStride, dstSlices,
4167
3936
                              srcWidth, srcHeight, srcDepth,
4168
3937
                              srcFormat, srcType,
4169
3938
                              srcAddr, srcPacking);
4195
3964
       srcType == GL_UNSIGNED_INT_5_9_9_9_REV) {
4196
3965
      /* simple memcpy path */
4197
3966
      memcpy_texture(ctx, dims,
4198
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
4199
 
                     dstRowStride,
4200
 
                     dstImageOffsets,
 
3967
                     dstFormat,
 
3968
                     dstRowStride, dstSlices,
4201
3969
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
4202
3970
                     srcAddr, srcPacking);
4203
3971
   }
4215
3983
      if (!tempImage)
4216
3984
         return GL_FALSE;
4217
3985
      for (img = 0; img < srcDepth; img++) {
4218
 
         GLubyte *dstRow = (GLubyte *) dstAddr
4219
 
            + dstImageOffsets[dstZoffset + img] * 4
4220
 
            + dstYoffset * dstRowStride
4221
 
            + dstXoffset * 4;
 
3986
         GLubyte *dstRow = dstSlices[img];
4222
3987
         for (row = 0; row < srcHeight; row++) {
4223
3988
            GLuint *dstUI = (GLuint*)dstRow;
4224
3989
            for (col = 0; col < srcWidth; col++) {
4248
4013
       srcType == GL_UNSIGNED_INT_10F_11F_11F_REV) {
4249
4014
      /* simple memcpy path */
4250
4015
      memcpy_texture(ctx, dims,
4251
 
                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
4252
 
                     dstRowStride,
4253
 
                     dstImageOffsets,
 
4016
                     dstFormat,
 
4017
                     dstRowStride, dstSlices,
4254
4018
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
4255
4019
                     srcAddr, srcPacking);
4256
4020
   }
4268
4032
      if (!tempImage)
4269
4033
         return GL_FALSE;
4270
4034
      for (img = 0; img < srcDepth; img++) {
4271
 
         GLubyte *dstRow = (GLubyte *) dstAddr
4272
 
            + dstImageOffsets[dstZoffset + img] * 4
4273
 
            + dstYoffset * dstRowStride
4274
 
            + dstXoffset * 4;
 
4035
         GLubyte *dstRow = dstSlices[img];
4275
4036
         for (row = 0; row < srcHeight; row++) {
4276
4037
            GLuint *dstUI = (GLuint*)dstRow;
4277
4038
            for (col = 0; col < srcWidth; col++) {
4288
4049
}
4289
4050
 
4290
4051
 
4291
 
 
4292
 
/**
4293
 
 * Table mapping MESA_FORMAT_* to _mesa_texstore_*()
4294
 
 * XXX this is somewhat temporary.
4295
 
 */
4296
 
static const struct {
4297
 
   gl_format Name;
4298
 
   StoreTexImageFunc Store;
4299
 
}
4300
 
texstore_funcs[MESA_FORMAT_COUNT] =
4301
 
{
4302
 
   { MESA_FORMAT_NONE, NULL },
4303
 
   { MESA_FORMAT_RGBA8888, _mesa_texstore_rgba8888 },
4304
 
   { MESA_FORMAT_RGBA8888_REV, _mesa_texstore_rgba8888 },
4305
 
   { MESA_FORMAT_ARGB8888, _mesa_texstore_argb8888 },
4306
 
   { MESA_FORMAT_ARGB8888_REV, _mesa_texstore_argb8888 },
4307
 
   { MESA_FORMAT_XRGB8888, _mesa_texstore_argb8888 },
4308
 
   { MESA_FORMAT_XRGB8888_REV, _mesa_texstore_argb8888 },
4309
 
   { MESA_FORMAT_RGB888, _mesa_texstore_rgb888 },
4310
 
   { MESA_FORMAT_BGR888, _mesa_texstore_bgr888 },
4311
 
   { MESA_FORMAT_RGB565, _mesa_texstore_rgb565 },
4312
 
   { MESA_FORMAT_RGB565_REV, _mesa_texstore_rgb565 },
4313
 
   { MESA_FORMAT_ARGB4444, _mesa_texstore_argb4444 },
4314
 
   { MESA_FORMAT_ARGB4444_REV, _mesa_texstore_argb4444 },
4315
 
   { MESA_FORMAT_RGBA5551, _mesa_texstore_rgba5551 },
4316
 
   { MESA_FORMAT_ARGB1555, _mesa_texstore_argb1555 },
4317
 
   { MESA_FORMAT_ARGB1555_REV, _mesa_texstore_argb1555 },
4318
 
   { MESA_FORMAT_AL44, _mesa_texstore_unorm44 },
4319
 
   { MESA_FORMAT_AL88, _mesa_texstore_unorm88 },
4320
 
   { MESA_FORMAT_AL88_REV, _mesa_texstore_unorm88 },
4321
 
   { MESA_FORMAT_AL1616, _mesa_texstore_unorm1616 },
4322
 
   { MESA_FORMAT_AL1616_REV, _mesa_texstore_unorm1616 },
4323
 
   { MESA_FORMAT_RGB332, _mesa_texstore_rgb332 },
4324
 
   { MESA_FORMAT_A8, _mesa_texstore_unorm8 },
4325
 
   { MESA_FORMAT_A16, _mesa_texstore_unorm16 },
4326
 
   { MESA_FORMAT_L8, _mesa_texstore_unorm8 },
4327
 
   { MESA_FORMAT_L16, _mesa_texstore_unorm16 },
4328
 
   { MESA_FORMAT_I8, _mesa_texstore_unorm8 },
4329
 
   { MESA_FORMAT_I16, _mesa_texstore_unorm16 },
4330
 
   { MESA_FORMAT_CI8, _mesa_texstore_ci8 },
4331
 
   { MESA_FORMAT_YCBCR, _mesa_texstore_ycbcr },
4332
 
   { MESA_FORMAT_YCBCR_REV, _mesa_texstore_ycbcr },
4333
 
   { MESA_FORMAT_R8, _mesa_texstore_unorm8 },
4334
 
   { MESA_FORMAT_RG88, _mesa_texstore_unorm88 },
4335
 
   { MESA_FORMAT_RG88_REV, _mesa_texstore_unorm88 },
4336
 
   { MESA_FORMAT_R16, _mesa_texstore_unorm16 },
4337
 
   { MESA_FORMAT_RG1616, _mesa_texstore_unorm1616 },
4338
 
   { MESA_FORMAT_RG1616_REV, _mesa_texstore_unorm1616 },
4339
 
   { MESA_FORMAT_ARGB2101010, _mesa_texstore_argb2101010 },
4340
 
   { MESA_FORMAT_Z24_S8, _mesa_texstore_z24_s8 },
4341
 
   { MESA_FORMAT_S8_Z24, _mesa_texstore_s8_z24 },
4342
 
   { MESA_FORMAT_Z16, _mesa_texstore_z16 },
4343
 
   { MESA_FORMAT_X8_Z24, _mesa_texstore_x8_z24 },
4344
 
   { MESA_FORMAT_Z24_X8, _mesa_texstore_z24_x8 },
4345
 
   { MESA_FORMAT_Z32, _mesa_texstore_z32 },
4346
 
   { MESA_FORMAT_S8, _mesa_texstore_s8 },
4347
 
   { MESA_FORMAT_SRGB8, _mesa_texstore_srgb8 },
4348
 
   { MESA_FORMAT_SRGBA8, _mesa_texstore_srgba8 },
4349
 
   { MESA_FORMAT_SARGB8, _mesa_texstore_sargb8 },
4350
 
   { MESA_FORMAT_SL8, _mesa_texstore_sl8 },
4351
 
   { MESA_FORMAT_SLA8, _mesa_texstore_sla8 },
4352
 
   { MESA_FORMAT_SRGB_DXT1, _mesa_texstore_rgb_dxt1 },
4353
 
   { MESA_FORMAT_SRGBA_DXT1, _mesa_texstore_rgba_dxt1 },
4354
 
   { MESA_FORMAT_SRGBA_DXT3, _mesa_texstore_rgba_dxt3 },
4355
 
   { MESA_FORMAT_SRGBA_DXT5, _mesa_texstore_rgba_dxt5 },
4356
 
   { MESA_FORMAT_RGB_FXT1, _mesa_texstore_rgb_fxt1 },
4357
 
   { MESA_FORMAT_RGBA_FXT1, _mesa_texstore_rgba_fxt1 },
4358
 
   { MESA_FORMAT_RGB_DXT1, _mesa_texstore_rgb_dxt1 },
4359
 
   { MESA_FORMAT_RGBA_DXT1, _mesa_texstore_rgba_dxt1 },
4360
 
   { MESA_FORMAT_RGBA_DXT3, _mesa_texstore_rgba_dxt3 },
4361
 
   { MESA_FORMAT_RGBA_DXT5, _mesa_texstore_rgba_dxt5 },
4362
 
   { MESA_FORMAT_RGBA_FLOAT32, _mesa_texstore_rgba_float32 },
4363
 
   { MESA_FORMAT_RGBA_FLOAT16, _mesa_texstore_rgba_float16 },
4364
 
   { MESA_FORMAT_RGB_FLOAT32, _mesa_texstore_rgba_float32 },
4365
 
   { MESA_FORMAT_RGB_FLOAT16, _mesa_texstore_rgba_float16 },
4366
 
   { MESA_FORMAT_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
4367
 
   { MESA_FORMAT_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
4368
 
   { MESA_FORMAT_LUMINANCE_FLOAT32, _mesa_texstore_rgba_float32 },
4369
 
   { MESA_FORMAT_LUMINANCE_FLOAT16, _mesa_texstore_rgba_float16 },
4370
 
   { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32, _mesa_texstore_rgba_float32 },
4371
 
   { MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16, _mesa_texstore_rgba_float16 },
4372
 
   { MESA_FORMAT_INTENSITY_FLOAT32, _mesa_texstore_rgba_float32 },
4373
 
   { MESA_FORMAT_INTENSITY_FLOAT16, _mesa_texstore_rgba_float16 },
4374
 
   { MESA_FORMAT_R_FLOAT32, _mesa_texstore_rgba_float32 },
4375
 
   { MESA_FORMAT_R_FLOAT16, _mesa_texstore_rgba_float16 },
4376
 
   { MESA_FORMAT_RG_FLOAT32, _mesa_texstore_rgba_float32 },
4377
 
   { MESA_FORMAT_RG_FLOAT16, _mesa_texstore_rgba_float16 },
4378
 
 
4379
 
   { MESA_FORMAT_RGBA_INT8, _mesa_texstore_rgba_int8 },
4380
 
   { MESA_FORMAT_RGBA_INT16, _mesa_texstore_rgba_int16 },
4381
 
   { MESA_FORMAT_RGBA_INT32, _mesa_texstore_rgba_int32 },
4382
 
   { MESA_FORMAT_RGBA_UINT8, _mesa_texstore_rgba_uint8 },
4383
 
   { MESA_FORMAT_RGBA_UINT16, _mesa_texstore_rgba_uint16 },
4384
 
   { MESA_FORMAT_RGBA_UINT32, _mesa_texstore_rgba_uint32 },
4385
 
 
4386
 
   { MESA_FORMAT_DUDV8, _mesa_texstore_dudv8 },
4387
 
 
4388
 
   { MESA_FORMAT_SIGNED_R8, _mesa_texstore_snorm8 },
4389
 
   { MESA_FORMAT_SIGNED_RG88_REV, _mesa_texstore_snorm88 },
4390
 
   { MESA_FORMAT_SIGNED_RGBX8888, _mesa_texstore_signed_rgbx8888 },
4391
 
 
4392
 
   { MESA_FORMAT_SIGNED_RGBA8888, _mesa_texstore_signed_rgba8888 },
4393
 
   { MESA_FORMAT_SIGNED_RGBA8888_REV, _mesa_texstore_signed_rgba8888 },
4394
 
 
4395
 
   { MESA_FORMAT_SIGNED_R16, _mesa_texstore_snorm16 },
4396
 
   { MESA_FORMAT_SIGNED_GR1616, _mesa_texstore_snorm1616 },
4397
 
   { MESA_FORMAT_SIGNED_RGB_16, _mesa_texstore_signed_rgba_16 },
4398
 
   { MESA_FORMAT_SIGNED_RGBA_16, _mesa_texstore_signed_rgba_16 },
4399
 
   { MESA_FORMAT_RGBA_16, _mesa_texstore_rgba_16 },
4400
 
 
4401
 
   { MESA_FORMAT_RED_RGTC1, _mesa_texstore_red_rgtc1 },
4402
 
   { MESA_FORMAT_SIGNED_RED_RGTC1, _mesa_texstore_signed_red_rgtc1 },
4403
 
   { MESA_FORMAT_RG_RGTC2, _mesa_texstore_rg_rgtc2 },
4404
 
   { MESA_FORMAT_SIGNED_RG_RGTC2, _mesa_texstore_signed_rg_rgtc2 },
4405
 
 
4406
 
   /* Re-use the R/RG texstore functions.
4407
 
    * The code is generic enough to handle LATC too. */
4408
 
   { MESA_FORMAT_L_LATC1, _mesa_texstore_red_rgtc1 },
4409
 
   { MESA_FORMAT_SIGNED_L_LATC1, _mesa_texstore_signed_red_rgtc1 },
4410
 
   { MESA_FORMAT_LA_LATC2, _mesa_texstore_rg_rgtc2 },
4411
 
   { MESA_FORMAT_SIGNED_LA_LATC2, _mesa_texstore_signed_rg_rgtc2 },
4412
 
 
4413
 
   { MESA_FORMAT_SIGNED_A8, _mesa_texstore_snorm8 },
4414
 
   { MESA_FORMAT_SIGNED_L8, _mesa_texstore_snorm8 },
4415
 
   { MESA_FORMAT_SIGNED_AL88, _mesa_texstore_snorm88 },
4416
 
   { MESA_FORMAT_SIGNED_I8, _mesa_texstore_snorm8 },
4417
 
 
4418
 
   { MESA_FORMAT_SIGNED_A16, _mesa_texstore_snorm16 },
4419
 
   { MESA_FORMAT_SIGNED_L16, _mesa_texstore_snorm16 },
4420
 
   { MESA_FORMAT_SIGNED_AL1616, _mesa_texstore_snorm1616 },
4421
 
   { MESA_FORMAT_SIGNED_I16, _mesa_texstore_snorm16 },
4422
 
 
4423
 
   { MESA_FORMAT_RGB9_E5_FLOAT, _mesa_texstore_rgb9_e5 },
4424
 
   { MESA_FORMAT_R11_G11_B10_FLOAT, _mesa_texstore_r11_g11_b10f },
4425
 
};
4426
 
 
 
4052
static GLboolean
 
4053
_mesa_texstore_z32f_x24s8(TEXSTORE_PARAMS)
 
4054
{
 
4055
   ASSERT(dstFormat == MESA_FORMAT_Z32_FLOAT_X24S8);
 
4056
   ASSERT(srcFormat == GL_DEPTH_STENCIL ||
 
4057
          srcFormat == GL_DEPTH_COMPONENT ||
 
4058
          srcFormat == GL_STENCIL_INDEX);
 
4059
   ASSERT(srcFormat != GL_DEPTH_STENCIL ||
 
4060
          srcType == GL_FLOAT_32_UNSIGNED_INT_24_8_REV);
 
4061
 
 
4062
   if (srcFormat == GL_DEPTH_STENCIL &&
 
4063
       ctx->Pixel.DepthScale == 1.0f &&
 
4064
       ctx->Pixel.DepthBias == 0.0f &&
 
4065
       !srcPacking->SwapBytes) {
 
4066
      /* simple path */
 
4067
      memcpy_texture(ctx, dims,
 
4068
                     dstFormat,
 
4069
                     dstRowStride, dstSlices,
 
4070
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
 
4071
                     srcAddr, srcPacking);
 
4072
   }
 
4073
   else if (srcFormat == GL_DEPTH_COMPONENT ||
 
4074
            srcFormat == GL_STENCIL_INDEX) {
 
4075
      GLint img, row;
 
4076
      const GLint srcRowStride
 
4077
         = _mesa_image_row_stride(srcPacking, srcWidth, srcFormat, srcType)
 
4078
         / sizeof(uint64_t);
 
4079
 
 
4080
      /* In case we only upload depth we need to preserve the stencil */
 
4081
      for (img = 0; img < srcDepth; img++) {
 
4082
         uint64_t *dstRow = (uint64_t *) dstSlices[img];
 
4083
         const uint64_t *src
 
4084
            = (const uint64_t *) _mesa_image_address(dims, srcPacking, srcAddr,
 
4085
                  srcWidth, srcHeight,
 
4086
                  srcFormat, srcType,
 
4087
                  img, 0, 0);
 
4088
         for (row = 0; row < srcHeight; row++) {
 
4089
            /* The unpack functions with:
 
4090
             *    dstType = GL_FLOAT_32_UNSIGNED_INT_24_8_REV
 
4091
             * only write their own dword, so the other dword (stencil
 
4092
             * or depth) is preserved. */
 
4093
            if (srcFormat != GL_STENCIL_INDEX)
 
4094
               _mesa_unpack_depth_span(ctx, srcWidth,
 
4095
                                       GL_FLOAT_32_UNSIGNED_INT_24_8_REV, /* dst type */
 
4096
                                       dstRow, /* dst addr */
 
4097
                                       ~0U, srcType, src, srcPacking);
 
4098
 
 
4099
            if (srcFormat != GL_DEPTH_COMPONENT)
 
4100
               _mesa_unpack_stencil_span(ctx, srcWidth,
 
4101
                                         GL_FLOAT_32_UNSIGNED_INT_24_8_REV, /* dst type */
 
4102
                                         dstRow, /* dst addr */
 
4103
                                         srcType, src, srcPacking,
 
4104
                                         ctx->_ImageTransferState);
 
4105
 
 
4106
            src += srcRowStride;
 
4107
            dstRow += dstRowStride / sizeof(uint64_t);
 
4108
         }
 
4109
      }
 
4110
   }
 
4111
   return GL_TRUE;
 
4112
}
 
4113
 
 
4114
static GLboolean
 
4115
_mesa_texstore_argb2101010_uint(TEXSTORE_PARAMS)
 
4116
{
 
4117
   const GLenum baseFormat = _mesa_get_format_base_format(dstFormat);
 
4118
 
 
4119
   ASSERT(dstFormat == MESA_FORMAT_ARGB2101010_UINT);
 
4120
   ASSERT(_mesa_get_format_bytes(dstFormat) == 4);
 
4121
 
 
4122
   if (!srcPacking->SwapBytes &&
 
4123
       dstFormat == MESA_FORMAT_ARGB2101010_UINT &&
 
4124
       srcFormat == GL_BGRA_INTEGER_EXT &&
 
4125
       srcType == GL_UNSIGNED_INT_2_10_10_10_REV &&
 
4126
       baseInternalFormat == GL_RGBA) {
 
4127
      /* simple memcpy path */
 
4128
      memcpy_texture(ctx, dims,
 
4129
                     dstFormat,
 
4130
                     dstRowStride, dstSlices,
 
4131
                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,
 
4132
                     srcAddr, srcPacking);
 
4133
   }
 
4134
   else {
 
4135
      /* general path */
 
4136
      const GLuint *tempImage = make_temp_uint_image(ctx, dims,
 
4137
                                                     baseInternalFormat,
 
4138
                                                     baseFormat,
 
4139
                                                     srcWidth, srcHeight,
 
4140
                                                     srcDepth, srcFormat,
 
4141
                                                     srcType, srcAddr,
 
4142
                                                     srcPacking);
 
4143
      const GLuint *src = tempImage;
 
4144
      GLint img, row, col;
 
4145
      if (!tempImage)
 
4146
         return GL_FALSE;
 
4147
      for (img = 0; img < srcDepth; img++) {
 
4148
         GLubyte *dstRow = dstSlices[img];
 
4149
 
 
4150
         for (row = 0; row < srcHeight; row++) {
 
4151
            GLuint *dstUI = (GLuint *) dstRow;
 
4152
            for (col = 0; col < srcWidth; col++) {
 
4153
               GLushort a,r,g,b;
 
4154
               r = src[RCOMP];
 
4155
               g = src[GCOMP];
 
4156
               b = src[BCOMP];
 
4157
               a = src[ACOMP];
 
4158
               dstUI[col] = (a << 30) | (r << 20) | (g << 10) | (b);
 
4159
               src += 4;
 
4160
            }
 
4161
            dstRow += dstRowStride;
 
4162
         }
 
4163
      }
 
4164
      free((void *) tempImage);
 
4165
   }
 
4166
   return GL_TRUE;
 
4167
}
4427
4168
 
4428
4169
static GLboolean
4429
4170
_mesa_texstore_null(TEXSTORE_PARAMS)
4431
4172
   (void) ctx; (void) dims;
4432
4173
   (void) baseInternalFormat;
4433
4174
   (void) dstFormat;
4434
 
   (void) dstAddr;
4435
 
   (void) dstXoffset; (void) dstYoffset; (void) dstZoffset;
4436
 
   (void) dstRowStride; (void) dstImageOffsets;
 
4175
   (void) dstRowStride; (void) dstSlices,
4437
4176
   (void) srcWidth; (void) srcHeight; (void) srcDepth;
4438
4177
   (void) srcFormat; (void) srcType;
4439
4178
   (void) srcAddr;
4451
4190
static StoreTexImageFunc
4452
4191
_mesa_get_texstore_func(gl_format format)
4453
4192
{
4454
 
#ifdef DEBUG
4455
 
   GLuint i;
4456
 
   for (i = 0; i < MESA_FORMAT_COUNT; i++) {
4457
 
      ASSERT(texstore_funcs[i].Name == i);
 
4193
   static StoreTexImageFunc table[MESA_FORMAT_COUNT];
 
4194
   static GLboolean initialized = GL_FALSE;
 
4195
 
 
4196
   if (!initialized) {
 
4197
      table[MESA_FORMAT_NONE] = _mesa_texstore_null;
 
4198
 
 
4199
      table[MESA_FORMAT_RGBA8888] = _mesa_texstore_rgba8888;
 
4200
      table[MESA_FORMAT_RGBA8888_REV] = _mesa_texstore_rgba8888;
 
4201
      table[MESA_FORMAT_ARGB8888] = _mesa_texstore_argb8888;
 
4202
      table[MESA_FORMAT_ARGB8888_REV] = _mesa_texstore_argb8888;
 
4203
      table[MESA_FORMAT_RGBX8888] = _mesa_texstore_rgba8888;
 
4204
      table[MESA_FORMAT_RGBX8888_REV] = _mesa_texstore_rgba8888;
 
4205
      table[MESA_FORMAT_XRGB8888] = _mesa_texstore_argb8888;
 
4206
      table[MESA_FORMAT_XRGB8888_REV] = _mesa_texstore_argb8888;
 
4207
      table[MESA_FORMAT_RGB888] = _mesa_texstore_rgb888;
 
4208
      table[MESA_FORMAT_BGR888] = _mesa_texstore_bgr888;
 
4209
      table[MESA_FORMAT_RGB565] = _mesa_texstore_rgb565;
 
4210
      table[MESA_FORMAT_RGB565_REV] = _mesa_texstore_rgb565;
 
4211
      table[MESA_FORMAT_ARGB4444] = _mesa_texstore_argb4444;
 
4212
      table[MESA_FORMAT_ARGB4444_REV] = _mesa_texstore_argb4444;
 
4213
      table[MESA_FORMAT_RGBA5551] = _mesa_texstore_rgba5551;
 
4214
      table[MESA_FORMAT_ARGB1555] = _mesa_texstore_argb1555;
 
4215
      table[MESA_FORMAT_ARGB1555_REV] = _mesa_texstore_argb1555;
 
4216
      table[MESA_FORMAT_AL44] = _mesa_texstore_unorm44;
 
4217
      table[MESA_FORMAT_AL88] = _mesa_texstore_unorm88;
 
4218
      table[MESA_FORMAT_AL88_REV] = _mesa_texstore_unorm88;
 
4219
      table[MESA_FORMAT_AL1616] = _mesa_texstore_unorm1616;
 
4220
      table[MESA_FORMAT_AL1616_REV] = _mesa_texstore_unorm1616;
 
4221
      table[MESA_FORMAT_RGB332] = _mesa_texstore_rgb332;
 
4222
      table[MESA_FORMAT_A8] = _mesa_texstore_unorm8;
 
4223
      table[MESA_FORMAT_A16] = _mesa_texstore_unorm16;
 
4224
      table[MESA_FORMAT_L8] = _mesa_texstore_unorm8;
 
4225
      table[MESA_FORMAT_L16] = _mesa_texstore_unorm16;
 
4226
      table[MESA_FORMAT_I8] = _mesa_texstore_unorm8;
 
4227
      table[MESA_FORMAT_I16] = _mesa_texstore_unorm16;
 
4228
      table[MESA_FORMAT_YCBCR] = _mesa_texstore_ycbcr;
 
4229
      table[MESA_FORMAT_YCBCR_REV] = _mesa_texstore_ycbcr;
 
4230
      table[MESA_FORMAT_R8] = _mesa_texstore_unorm8;
 
4231
      table[MESA_FORMAT_GR88] = _mesa_texstore_unorm88;
 
4232
      table[MESA_FORMAT_RG88] = _mesa_texstore_unorm88;
 
4233
      table[MESA_FORMAT_R16] = _mesa_texstore_unorm16;
 
4234
      table[MESA_FORMAT_RG1616] = _mesa_texstore_unorm1616;
 
4235
      table[MESA_FORMAT_RG1616_REV] = _mesa_texstore_unorm1616;
 
4236
      table[MESA_FORMAT_ARGB2101010] = _mesa_texstore_argb2101010;
 
4237
      table[MESA_FORMAT_Z24_S8] = _mesa_texstore_z24_s8;
 
4238
      table[MESA_FORMAT_S8_Z24] = _mesa_texstore_s8_z24;
 
4239
      table[MESA_FORMAT_Z16] = _mesa_texstore_z16;
 
4240
      table[MESA_FORMAT_X8_Z24] = _mesa_texstore_x8_z24;
 
4241
      table[MESA_FORMAT_Z24_X8] = _mesa_texstore_z24_x8;
 
4242
      table[MESA_FORMAT_Z32] = _mesa_texstore_z32;
 
4243
      table[MESA_FORMAT_S8] = _mesa_texstore_s8;
 
4244
      table[MESA_FORMAT_SRGB8] = _mesa_texstore_srgb8;
 
4245
      table[MESA_FORMAT_SRGBA8] = _mesa_texstore_srgba8;
 
4246
      table[MESA_FORMAT_SARGB8] = _mesa_texstore_sargb8;
 
4247
      table[MESA_FORMAT_SL8] = _mesa_texstore_sl8;
 
4248
      table[MESA_FORMAT_SLA8] = _mesa_texstore_sla8;
 
4249
      table[MESA_FORMAT_SRGB_DXT1] = _mesa_texstore_rgb_dxt1;
 
4250
      table[MESA_FORMAT_SRGBA_DXT1] = _mesa_texstore_rgba_dxt1;
 
4251
      table[MESA_FORMAT_SRGBA_DXT3] = _mesa_texstore_rgba_dxt3;
 
4252
      table[MESA_FORMAT_SRGBA_DXT5] = _mesa_texstore_rgba_dxt5;
 
4253
      table[MESA_FORMAT_RGB_FXT1] = _mesa_texstore_rgb_fxt1;
 
4254
      table[MESA_FORMAT_RGBA_FXT1] = _mesa_texstore_rgba_fxt1;
 
4255
      table[MESA_FORMAT_RGB_DXT1] = _mesa_texstore_rgb_dxt1;
 
4256
      table[MESA_FORMAT_RGBA_DXT1] = _mesa_texstore_rgba_dxt1;
 
4257
      table[MESA_FORMAT_RGBA_DXT3] = _mesa_texstore_rgba_dxt3;
 
4258
      table[MESA_FORMAT_RGBA_DXT5] = _mesa_texstore_rgba_dxt5;
 
4259
      table[MESA_FORMAT_RGBA_FLOAT32] = _mesa_texstore_rgba_float32;
 
4260
      table[MESA_FORMAT_RGBA_FLOAT16] = _mesa_texstore_rgba_float16;
 
4261
      table[MESA_FORMAT_RGB_FLOAT32] = _mesa_texstore_rgba_float32;
 
4262
      table[MESA_FORMAT_RGB_FLOAT16] = _mesa_texstore_rgba_float16;
 
4263
      table[MESA_FORMAT_ALPHA_FLOAT32] = _mesa_texstore_rgba_float32;
 
4264
      table[MESA_FORMAT_ALPHA_FLOAT16] = _mesa_texstore_rgba_float16;
 
4265
      table[MESA_FORMAT_LUMINANCE_FLOAT32] = _mesa_texstore_rgba_float32;
 
4266
      table[MESA_FORMAT_LUMINANCE_FLOAT16] = _mesa_texstore_rgba_float16;
 
4267
      table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32] = _mesa_texstore_rgba_float32;
 
4268
      table[MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16] = _mesa_texstore_rgba_float16;
 
4269
      table[MESA_FORMAT_INTENSITY_FLOAT32] = _mesa_texstore_rgba_float32;
 
4270
      table[MESA_FORMAT_INTENSITY_FLOAT16] = _mesa_texstore_rgba_float16;
 
4271
      table[MESA_FORMAT_R_FLOAT32] = _mesa_texstore_rgba_float32;
 
4272
      table[MESA_FORMAT_R_FLOAT16] = _mesa_texstore_rgba_float16;
 
4273
      table[MESA_FORMAT_RG_FLOAT32] = _mesa_texstore_rgba_float32;
 
4274
      table[MESA_FORMAT_RG_FLOAT16] = _mesa_texstore_rgba_float16;
 
4275
      table[MESA_FORMAT_DUDV8] = _mesa_texstore_dudv8;
 
4276
      table[MESA_FORMAT_SIGNED_R8] = _mesa_texstore_snorm8;
 
4277
      table[MESA_FORMAT_SIGNED_RG88_REV] = _mesa_texstore_snorm88;
 
4278
      table[MESA_FORMAT_SIGNED_RGBX8888] = _mesa_texstore_signed_rgbx8888;
 
4279
      table[MESA_FORMAT_SIGNED_RGBA8888] = _mesa_texstore_signed_rgba8888;
 
4280
      table[MESA_FORMAT_SIGNED_RGBA8888_REV] = _mesa_texstore_signed_rgba8888;
 
4281
      table[MESA_FORMAT_SIGNED_R16] = _mesa_texstore_snorm16;
 
4282
      table[MESA_FORMAT_SIGNED_GR1616] = _mesa_texstore_snorm1616;
 
4283
      table[MESA_FORMAT_SIGNED_RGB_16] = _mesa_texstore_signed_rgba_16;
 
4284
      table[MESA_FORMAT_SIGNED_RGBA_16] = _mesa_texstore_signed_rgba_16;
 
4285
      table[MESA_FORMAT_RGBA_16] = _mesa_texstore_rgba_16;
 
4286
      table[MESA_FORMAT_RED_RGTC1] = _mesa_texstore_red_rgtc1;
 
4287
      table[MESA_FORMAT_SIGNED_RED_RGTC1] = _mesa_texstore_signed_red_rgtc1;
 
4288
      table[MESA_FORMAT_RG_RGTC2] = _mesa_texstore_rg_rgtc2;
 
4289
      table[MESA_FORMAT_SIGNED_RG_RGTC2] = _mesa_texstore_signed_rg_rgtc2;
 
4290
      table[MESA_FORMAT_L_LATC1] = _mesa_texstore_red_rgtc1;
 
4291
      table[MESA_FORMAT_SIGNED_L_LATC1] = _mesa_texstore_signed_red_rgtc1;
 
4292
      table[MESA_FORMAT_LA_LATC2] = _mesa_texstore_rg_rgtc2;
 
4293
      table[MESA_FORMAT_SIGNED_LA_LATC2] = _mesa_texstore_signed_rg_rgtc2;
 
4294
      table[MESA_FORMAT_ETC1_RGB8] = _mesa_texstore_etc1_rgb8;
 
4295
      table[MESA_FORMAT_SIGNED_A8] = _mesa_texstore_snorm8;
 
4296
      table[MESA_FORMAT_SIGNED_L8] = _mesa_texstore_snorm8;
 
4297
      table[MESA_FORMAT_SIGNED_AL88] = _mesa_texstore_snorm88;
 
4298
      table[MESA_FORMAT_SIGNED_I8] = _mesa_texstore_snorm8;
 
4299
      table[MESA_FORMAT_SIGNED_A16] = _mesa_texstore_snorm16;
 
4300
      table[MESA_FORMAT_SIGNED_L16] = _mesa_texstore_snorm16;
 
4301
      table[MESA_FORMAT_SIGNED_AL1616] = _mesa_texstore_snorm1616;
 
4302
      table[MESA_FORMAT_SIGNED_I16] = _mesa_texstore_snorm16;
 
4303
      table[MESA_FORMAT_RGB9_E5_FLOAT] = _mesa_texstore_rgb9_e5;
 
4304
      table[MESA_FORMAT_R11_G11_B10_FLOAT] = _mesa_texstore_r11_g11_b10f;
 
4305
      table[MESA_FORMAT_Z32_FLOAT] = _mesa_texstore_z32;
 
4306
      table[MESA_FORMAT_Z32_FLOAT_X24S8] = _mesa_texstore_z32f_x24s8;
 
4307
 
 
4308
      table[MESA_FORMAT_ALPHA_UINT8] = _mesa_texstore_rgba_uint8;
 
4309
      table[MESA_FORMAT_ALPHA_UINT16] = _mesa_texstore_rgba_uint16;
 
4310
      table[MESA_FORMAT_ALPHA_UINT32] = _mesa_texstore_rgba_uint32;
 
4311
      table[MESA_FORMAT_ALPHA_INT8] = _mesa_texstore_rgba_int8;
 
4312
      table[MESA_FORMAT_ALPHA_INT16] = _mesa_texstore_rgba_int16;
 
4313
      table[MESA_FORMAT_ALPHA_INT32] = _mesa_texstore_rgba_int32;
 
4314
 
 
4315
      table[MESA_FORMAT_INTENSITY_UINT8] = _mesa_texstore_rgba_uint8;
 
4316
      table[MESA_FORMAT_INTENSITY_UINT16] = _mesa_texstore_rgba_uint16;
 
4317
      table[MESA_FORMAT_INTENSITY_UINT32] = _mesa_texstore_rgba_uint32;
 
4318
      table[MESA_FORMAT_INTENSITY_INT8] = _mesa_texstore_rgba_int8;
 
4319
      table[MESA_FORMAT_INTENSITY_INT16] = _mesa_texstore_rgba_int16;
 
4320
      table[MESA_FORMAT_INTENSITY_INT32] = _mesa_texstore_rgba_int32;
 
4321
 
 
4322
      table[MESA_FORMAT_LUMINANCE_UINT8] = _mesa_texstore_rgba_uint8;
 
4323
      table[MESA_FORMAT_LUMINANCE_UINT16] = _mesa_texstore_rgba_uint16;
 
4324
      table[MESA_FORMAT_LUMINANCE_UINT32] = _mesa_texstore_rgba_uint32;
 
4325
      table[MESA_FORMAT_LUMINANCE_INT8] = _mesa_texstore_rgba_int8;
 
4326
      table[MESA_FORMAT_LUMINANCE_INT16] = _mesa_texstore_rgba_int16;
 
4327
      table[MESA_FORMAT_LUMINANCE_INT32] = _mesa_texstore_rgba_int32;
 
4328
 
 
4329
      table[MESA_FORMAT_LUMINANCE_ALPHA_UINT8] = _mesa_texstore_rgba_uint8;
 
4330
      table[MESA_FORMAT_LUMINANCE_ALPHA_UINT16] = _mesa_texstore_rgba_uint16;
 
4331
      table[MESA_FORMAT_LUMINANCE_ALPHA_UINT32] = _mesa_texstore_rgba_uint32;
 
4332
      table[MESA_FORMAT_LUMINANCE_ALPHA_INT8] = _mesa_texstore_rgba_int8;
 
4333
      table[MESA_FORMAT_LUMINANCE_ALPHA_INT16] = _mesa_texstore_rgba_int16;
 
4334
      table[MESA_FORMAT_LUMINANCE_ALPHA_INT32] = _mesa_texstore_rgba_int32;
 
4335
 
 
4336
      table[MESA_FORMAT_R_INT8] = _mesa_texstore_rgba_int8;
 
4337
      table[MESA_FORMAT_RG_INT8] = _mesa_texstore_rgba_int8;
 
4338
      table[MESA_FORMAT_RGB_INT8] = _mesa_texstore_rgba_int8;
 
4339
      table[MESA_FORMAT_RGBA_INT8] = _mesa_texstore_rgba_int8;
 
4340
      table[MESA_FORMAT_R_INT16] = _mesa_texstore_rgba_int16;
 
4341
      table[MESA_FORMAT_RG_INT16] = _mesa_texstore_rgba_int16;
 
4342
      table[MESA_FORMAT_RGB_INT16] = _mesa_texstore_rgba_int16;
 
4343
      table[MESA_FORMAT_RGBA_INT16] = _mesa_texstore_rgba_int16;
 
4344
      table[MESA_FORMAT_R_INT32] = _mesa_texstore_rgba_int32;
 
4345
      table[MESA_FORMAT_RG_INT32] = _mesa_texstore_rgba_int32;
 
4346
      table[MESA_FORMAT_RGB_INT32] = _mesa_texstore_rgba_int32;
 
4347
      table[MESA_FORMAT_RGBA_INT32] = _mesa_texstore_rgba_int32;
 
4348
 
 
4349
      table[MESA_FORMAT_R_UINT8] = _mesa_texstore_rgba_uint8;
 
4350
      table[MESA_FORMAT_RG_UINT8] = _mesa_texstore_rgba_uint8;
 
4351
      table[MESA_FORMAT_RGB_UINT8] = _mesa_texstore_rgba_uint8;
 
4352
      table[MESA_FORMAT_RGBA_UINT8] = _mesa_texstore_rgba_uint8;
 
4353
      table[MESA_FORMAT_R_UINT16] = _mesa_texstore_rgba_uint16;
 
4354
      table[MESA_FORMAT_RG_UINT16] = _mesa_texstore_rgba_uint16;
 
4355
      table[MESA_FORMAT_RGB_UINT16] = _mesa_texstore_rgba_uint16;
 
4356
      table[MESA_FORMAT_RGBA_UINT16] = _mesa_texstore_rgba_uint16;
 
4357
      table[MESA_FORMAT_R_UINT32] = _mesa_texstore_rgba_uint32;
 
4358
      table[MESA_FORMAT_RG_UINT32] = _mesa_texstore_rgba_uint32;
 
4359
      table[MESA_FORMAT_RGB_UINT32] = _mesa_texstore_rgba_uint32;
 
4360
      table[MESA_FORMAT_RGBA_UINT32] = _mesa_texstore_rgba_uint32;
 
4361
 
 
4362
      table[MESA_FORMAT_ARGB2101010_UINT] = _mesa_texstore_argb2101010_uint;
 
4363
      initialized = GL_TRUE;
4458
4364
   }
4459
 
#endif
4460
 
   ASSERT(texstore_funcs[format].Name == format);
4461
4365
 
4462
 
   if (texstore_funcs[format].Store)
4463
 
      return texstore_funcs[format].Store;
4464
 
   else
4465
 
      return _mesa_texstore_null;
 
4366
   ASSERT(table[format]);
 
4367
   return table[format];
4466
4368
}
4467
4369
 
4468
4370
 
4479
4381
   storeImage = _mesa_get_texstore_func(dstFormat);
4480
4382
 
4481
4383
   success = storeImage(ctx, dims, baseInternalFormat,
4482
 
                        dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,
4483
 
                        dstRowStride, dstImageOffsets,
 
4384
                        dstFormat,
 
4385
                        dstRowStride, dstSlices,
4484
4386
                        srcWidth, srcHeight, srcDepth,
4485
4387
                        srcFormat, srcType, srcAddr, srcPacking);
4486
4388
   return success;
4487
4389
}
4488
4390
 
4489
4391
 
4490
 
/** Return texture size in bytes */
4491
 
static GLuint
4492
 
texture_size(const struct gl_texture_image *texImage)
4493
 
{
4494
 
   GLuint sz = _mesa_format_image_size(texImage->TexFormat, texImage->Width,
4495
 
                                       texImage->Height, texImage->Depth);
4496
 
   return sz;
4497
 
}
4498
 
 
4499
 
 
4500
 
/** Return row stride in bytes */
4501
 
static GLuint
4502
 
texture_row_stride(const struct gl_texture_image *texImage)
4503
 
{
4504
 
   GLuint stride = _mesa_format_row_stride(texImage->TexFormat,
4505
 
                                           texImage->Width);
4506
 
   return stride;
4507
 
}
4508
 
 
4509
 
 
4510
 
 
4511
 
/**
4512
 
 * This is the software fallback for Driver.TexImage1D()
4513
 
 * and Driver.CopyTexImage1D().
4514
 
 * \sa _mesa_store_teximage2d()
 
4392
/**
 
4393
 * Normally, we'll only _write_ texel data to a texture when we map it.
 
4394
 * But if the user is providing depth or stencil values and the texture
 
4395
 * image is a combined depth/stencil format, we'll actually read from
 
4396
 * the texture buffer too (in order to insert the depth or stencil values.
 
4397
 * \param userFormat  the user-provided image format
 
4398
 * \param texFormat  the destination texture format
 
4399
 */
 
4400
static GLbitfield
 
4401
get_read_write_mode(GLenum userFormat, gl_format texFormat)
 
4402
{
 
4403
   if ((userFormat == GL_STENCIL_INDEX || userFormat == GL_DEPTH_COMPONENT)
 
4404
       && _mesa_get_format_base_format(texFormat) == GL_DEPTH_STENCIL)
 
4405
      return GL_MAP_READ_BIT | GL_MAP_WRITE_BIT;
 
4406
   else
 
4407
      return GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT;
 
4408
}
 
4409
 
 
4410
 
 
4411
/**
 
4412
 * Helper function for storing 1D, 2D, 3D whole and subimages into texture
 
4413
 * memory.
 
4414
 * The source of the image data may be user memory or a PBO.  In the later
 
4415
 * case, we'll map the PBO, copy from it, then unmap it.
 
4416
 */
 
4417
static void
 
4418
store_texsubimage(struct gl_context *ctx,
 
4419
                  struct gl_texture_image *texImage,
 
4420
                  GLint xoffset, GLint yoffset, GLint zoffset,
 
4421
                  GLint width, GLint height, GLint depth,
 
4422
                  GLenum format, GLenum type, const GLvoid *pixels,
 
4423
                  const struct gl_pixelstore_attrib *packing,
 
4424
                  const char *caller)
 
4425
 
 
4426
{
 
4427
   const GLbitfield mapMode = get_read_write_mode(format, texImage->TexFormat);
 
4428
   const GLenum target = texImage->TexObject->Target;
 
4429
   GLboolean success = GL_FALSE;
 
4430
   GLuint dims, slice, numSlices = 1, sliceOffset = 0;
 
4431
   GLint srcImageStride = 0;
 
4432
   const GLubyte *src;
 
4433
 
 
4434
   assert(xoffset + width <= texImage->Width);
 
4435
   assert(yoffset + height <= texImage->Height);
 
4436
   assert(zoffset + depth <= texImage->Depth);
 
4437
 
 
4438
   switch (target) {
 
4439
   case GL_TEXTURE_1D:
 
4440
      dims = 1;
 
4441
      break;
 
4442
   case GL_TEXTURE_2D_ARRAY:
 
4443
   case GL_TEXTURE_3D:
 
4444
      dims = 3;
 
4445
      break;
 
4446
   default:
 
4447
      dims = 2;
 
4448
   }
 
4449
 
 
4450
   /* get pointer to src pixels (may be in a pbo which we'll map here) */
 
4451
   src = (const GLubyte *)
 
4452
      _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
 
4453
                                  format, type, pixels, packing, caller);
 
4454
   if (!src)
 
4455
      return;
 
4456
 
 
4457
   /* compute slice info (and do some sanity checks) */
 
4458
   switch (target) {
 
4459
   case GL_TEXTURE_2D:
 
4460
   case GL_TEXTURE_RECTANGLE:
 
4461
   case GL_TEXTURE_CUBE_MAP:
 
4462
      /* one image slice, nothing special needs to be done */
 
4463
      break;
 
4464
   case GL_TEXTURE_1D:
 
4465
      assert(height == 1);
 
4466
      assert(depth == 1);
 
4467
      assert(yoffset == 0);
 
4468
      assert(zoffset == 0);
 
4469
      break;
 
4470
   case GL_TEXTURE_1D_ARRAY:
 
4471
      assert(depth == 1);
 
4472
      assert(zoffset == 0);
 
4473
      numSlices = height;
 
4474
      sliceOffset = yoffset;
 
4475
      height = 1;
 
4476
      yoffset = 0;
 
4477
      srcImageStride = _mesa_image_row_stride(packing, width, format, type);
 
4478
      break;
 
4479
   case GL_TEXTURE_2D_ARRAY:
 
4480
      numSlices = depth;
 
4481
      sliceOffset = zoffset;
 
4482
      depth = 1;
 
4483
      zoffset = 0;
 
4484
      srcImageStride = _mesa_image_image_stride(packing, width, height,
 
4485
                                                format, type);
 
4486
      break;
 
4487
   case GL_TEXTURE_3D:
 
4488
      /* we'll store 3D images as a series of slices */
 
4489
      numSlices = depth;
 
4490
      sliceOffset = zoffset;
 
4491
      srcImageStride = _mesa_image_image_stride(packing, width, height,
 
4492
                                                format, type);
 
4493
      break;
 
4494
   default:
 
4495
      _mesa_warning(ctx, "Unexpected target 0x%x in store_texsubimage()", target);
 
4496
      return;
 
4497
   }
 
4498
 
 
4499
   assert(numSlices == 1 || srcImageStride != 0);
 
4500
 
 
4501
   for (slice = 0; slice < numSlices; slice++) {
 
4502
      GLubyte *dstMap;
 
4503
      GLint dstRowStride;
 
4504
 
 
4505
      ctx->Driver.MapTextureImage(ctx, texImage,
 
4506
                                  slice + sliceOffset,
 
4507
                                  xoffset, yoffset, width, height,
 
4508
                                  mapMode, &dstMap, &dstRowStride);
 
4509
      if (dstMap) {
 
4510
         /* Note: we're only storing a 2D (or 1D) slice at a time but we need
 
4511
          * to pass the right 'dims' value so that GL_UNPACK_SKIP_IMAGES is
 
4512
          * used for 3D images.
 
4513
          */
 
4514
         success = _mesa_texstore(ctx, dims, texImage->_BaseFormat,
 
4515
                                  texImage->TexFormat,
 
4516
                                  dstRowStride,
 
4517
                                  &dstMap,
 
4518
                                  width, height, 1,  /* w, h, d */
 
4519
                                  format, type, src, packing);
 
4520
 
 
4521
         ctx->Driver.UnmapTextureImage(ctx, texImage, slice + sliceOffset);
 
4522
      }
 
4523
 
 
4524
      src += srcImageStride;
 
4525
 
 
4526
      if (!success)
 
4527
         break;
 
4528
   }
 
4529
 
 
4530
   if (!success)
 
4531
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s", caller);
 
4532
 
 
4533
   _mesa_unmap_teximage_pbo(ctx, packing);
 
4534
}
 
4535
 
 
4536
 
 
4537
 
 
4538
/**
 
4539
 * This is the fallback for Driver.TexImage1D().
4515
4540
 */
4516
4541
void
4517
 
_mesa_store_teximage1d(struct gl_context *ctx, GLenum target, GLint level,
 
4542
_mesa_store_teximage1d(struct gl_context *ctx,
 
4543
                       struct gl_texture_image *texImage,
4518
4544
                       GLint internalFormat,
4519
4545
                       GLint width, GLint border,
4520
4546
                       GLenum format, GLenum type, const GLvoid *pixels,
4521
 
                       const struct gl_pixelstore_attrib *packing,
4522
 
                       struct gl_texture_object *texObj,
4523
 
                       struct gl_texture_image *texImage)
 
4547
                       const struct gl_pixelstore_attrib *packing)
4524
4548
{
4525
 
   GLuint sizeInBytes;
4526
 
   (void) border;
 
4549
   if (width == 0)
 
4550
      return;
4527
4551
 
4528
 
   /* allocate memory */
4529
 
   sizeInBytes = texture_size(texImage);
4530
 
   texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
4531
 
   if (!texImage->Data) {
 
4552
   /* allocate storage for texture data */
 
4553
   if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
 
4554
                                            width, 1, 1)) {
4532
4555
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
4533
4556
      return;
4534
4557
   }
4535
4558
 
4536
 
   pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
4537
 
                                        pixels, packing, "glTexImage1D");
4538
 
   if (!pixels) {
4539
 
      /* Note: we check for a NULL image pointer here, _after_ we allocated
4540
 
       * memory for the texture.  That's what the GL spec calls for.
4541
 
       */
4542
 
      return;
4543
 
   }
4544
 
   else {
4545
 
      const GLint dstRowStride = 0;
4546
 
      GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
4547
 
                                         texImage->TexFormat,
4548
 
                                         texImage->Data,
4549
 
                                         0, 0, 0,  /* dstX/Y/Zoffset */
4550
 
                                         dstRowStride,
4551
 
                                         texImage->ImageOffsets,
4552
 
                                         width, 1, 1,
4553
 
                                         format, type, pixels, packing);
4554
 
      if (!success) {
4555
 
         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage1D");
4556
 
      }
4557
 
   }
4558
 
 
4559
 
   _mesa_unmap_teximage_pbo(ctx, packing);
 
4559
   store_texsubimage(ctx, texImage,
 
4560
                     0, 0, 0, width, 1, 1,
 
4561
                     format, type, pixels, packing, "glTexImage1D");
4560
4562
}
4561
4563
 
4562
4564
 
4563
4565
/**
4564
 
 * This is the software fallback for Driver.TexImage2D()
4565
 
 * and Driver.CopyTexImage2D().
4566
 
 *
4567
 
 * This function is oriented toward storing images in main memory, rather
4568
 
 * than VRAM.  Device driver's can easily plug in their own replacement.
 
4566
 * This is the fallback for Driver.TexImage2D().
4569
4567
 */
4570
4568
void
4571
 
_mesa_store_teximage2d(struct gl_context *ctx, GLenum target, GLint level,
 
4569
_mesa_store_teximage2d(struct gl_context *ctx,
 
4570
                       struct gl_texture_image *texImage,
4572
4571
                       GLint internalFormat,
4573
4572
                       GLint width, GLint height, GLint border,
4574
4573
                       GLenum format, GLenum type, const void *pixels,
4575
 
                       const struct gl_pixelstore_attrib *packing,
4576
 
                       struct gl_texture_object *texObj,
4577
 
                       struct gl_texture_image *texImage)
 
4574
                       const struct gl_pixelstore_attrib *packing)
4578
4575
{
4579
 
   GLuint sizeInBytes;
4580
 
   (void) border;
 
4576
   if (width == 0 || height == 0)
 
4577
      return;
4581
4578
 
4582
 
   /* allocate memory */
4583
 
   sizeInBytes = texture_size(texImage);
4584
 
   texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
4585
 
   if (!texImage->Data) {
 
4579
   /* allocate storage for texture data */
 
4580
   if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
 
4581
                                            width, height, 1)) {
4586
4582
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
4587
4583
      return;
4588
4584
   }
4589
4585
 
4590
 
   pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
4591
 
                                        pixels, packing, "glTexImage2D");
4592
 
   if (!pixels) {
4593
 
      /* Note: we check for a NULL image pointer here, _after_ we allocated
4594
 
       * memory for the texture.  That's what the GL spec calls for.
4595
 
       */
4596
 
      return;
4597
 
   }
4598
 
   else {
4599
 
      GLint dstRowStride = texture_row_stride(texImage);
4600
 
      GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
4601
 
                                         texImage->TexFormat,
4602
 
                                         texImage->Data,
4603
 
                                         0, 0, 0,  /* dstX/Y/Zoffset */
4604
 
                                         dstRowStride,
4605
 
                                         texImage->ImageOffsets,
4606
 
                                         width, height, 1,
4607
 
                                         format, type, pixels, packing);
4608
 
      if (!success) {
4609
 
         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage2D");
4610
 
      }
4611
 
   }
4612
 
 
4613
 
   _mesa_unmap_teximage_pbo(ctx, packing);
 
4586
   store_texsubimage(ctx, texImage,
 
4587
                     0, 0, 0, width, height, 1,
 
4588
                     format, type, pixels, packing, "glTexImage2D");
4614
4589
}
4615
4590
 
4616
4591
 
4617
4592
 
4618
4593
/**
4619
 
 * This is the software fallback for Driver.TexImage3D()
4620
 
 * and Driver.CopyTexImage3D().
4621
 
 * \sa _mesa_store_teximage2d()
 
4594
 * This is the fallback for Driver.TexImage3D().
4622
4595
 */
4623
4596
void
4624
 
_mesa_store_teximage3d(struct gl_context *ctx, GLenum target, GLint level,
 
4597
_mesa_store_teximage3d(struct gl_context *ctx,
 
4598
                       struct gl_texture_image *texImage,
4625
4599
                       GLint internalFormat,
4626
4600
                       GLint width, GLint height, GLint depth, GLint border,
4627
4601
                       GLenum format, GLenum type, const void *pixels,
4628
 
                       const struct gl_pixelstore_attrib *packing,
4629
 
                       struct gl_texture_object *texObj,
4630
 
                       struct gl_texture_image *texImage)
 
4602
                       const struct gl_pixelstore_attrib *packing)
4631
4603
{
4632
 
   GLuint sizeInBytes;
4633
 
   (void) border;
 
4604
   if (width == 0 || height == 0 || depth == 0)
 
4605
      return;
4634
4606
 
4635
 
   /* allocate memory */
4636
 
   sizeInBytes = texture_size(texImage);
4637
 
   texImage->Data = _mesa_alloc_texmemory(sizeInBytes);
4638
 
   if (!texImage->Data) {
 
4607
   /* allocate storage for texture data */
 
4608
   if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
 
4609
                                            width, height, depth)) {
4639
4610
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
4640
4611
      return;
4641
4612
   }
4642
4613
 
4643
 
   pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
4644
 
                                        type, pixels, packing, "glTexImage3D");
4645
 
   if (!pixels) {
4646
 
      /* Note: we check for a NULL image pointer here, _after_ we allocated
4647
 
       * memory for the texture.  That's what the GL spec calls for.
4648
 
       */
4649
 
      return;
4650
 
   }
4651
 
   else {
4652
 
      GLint dstRowStride = texture_row_stride(texImage);
4653
 
      GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
4654
 
                                         texImage->TexFormat,
4655
 
                                         texImage->Data,
4656
 
                                         0, 0, 0,  /* dstX/Y/Zoffset */
4657
 
                                         dstRowStride,
4658
 
                                         texImage->ImageOffsets,
4659
 
                                         width, height, depth,
4660
 
                                         format, type, pixels, packing);
4661
 
      if (!success) {
4662
 
         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
4663
 
      }
4664
 
   }
4665
 
 
4666
 
   _mesa_unmap_teximage_pbo(ctx, packing);
 
4614
   store_texsubimage(ctx, texImage,
 
4615
                     0, 0, 0, width, height, depth,
 
4616
                     format, type, pixels, packing, "glTexImage3D");
4667
4617
}
4668
4618
 
4669
4619
 
4670
4620
 
4671
4621
 
4672
4622
/*
4673
 
 * This is the software fallback for Driver.TexSubImage1D()
4674
 
 * and Driver.CopyTexSubImage1D().
 
4623
 * This is the fallback for Driver.TexSubImage1D().
4675
4624
 */
4676
4625
void
4677
 
_mesa_store_texsubimage1d(struct gl_context *ctx, GLenum target, GLint level,
 
4626
_mesa_store_texsubimage1d(struct gl_context *ctx,
 
4627
                          struct gl_texture_image *texImage,
4678
4628
                          GLint xoffset, GLint width,
4679
4629
                          GLenum format, GLenum type, const void *pixels,
4680
 
                          const struct gl_pixelstore_attrib *packing,
4681
 
                          struct gl_texture_object *texObj,
4682
 
                          struct gl_texture_image *texImage)
 
4630
                          const struct gl_pixelstore_attrib *packing)
4683
4631
{
4684
 
   /* get pointer to src pixels (may be in a pbo which we'll map here) */
4685
 
   pixels = _mesa_validate_pbo_teximage(ctx, 1, width, 1, 1, format, type,
4686
 
                                        pixels, packing, "glTexSubImage1D");
4687
 
   if (!pixels)
4688
 
      return;
4689
 
 
4690
 
   {
4691
 
      const GLint dstRowStride = 0;
4692
 
      GLboolean success = _mesa_texstore(ctx, 1, texImage->_BaseFormat,
4693
 
                                         texImage->TexFormat,
4694
 
                                         texImage->Data,
4695
 
                                         xoffset, 0, 0,  /* offsets */
4696
 
                                         dstRowStride,
4697
 
                                         texImage->ImageOffsets,
4698
 
                                         width, 1, 1,
4699
 
                                         format, type, pixels, packing);
4700
 
      if (!success) {
4701
 
         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage1D");
4702
 
      }
4703
 
   }
4704
 
 
4705
 
   _mesa_unmap_teximage_pbo(ctx, packing);
 
4632
   store_texsubimage(ctx, texImage,
 
4633
                     xoffset, 0, 0, width, 1, 1,
 
4634
                     format, type, pixels, packing, "glTexSubImage1D");
4706
4635
}
4707
4636
 
4708
4637
 
4709
4638
 
4710
4639
/**
4711
 
 * This is the software fallback for Driver.TexSubImage2D()
4712
 
 * and Driver.CopyTexSubImage2D().
 
4640
 * This is the fallback for Driver.TexSubImage2D().
4713
4641
 */
4714
4642
void
4715
 
_mesa_store_texsubimage2d(struct gl_context *ctx, GLenum target, GLint level,
 
4643
_mesa_store_texsubimage2d(struct gl_context *ctx,
 
4644
                          struct gl_texture_image *texImage,
4716
4645
                          GLint xoffset, GLint yoffset,
4717
4646
                          GLint width, GLint height,
4718
4647
                          GLenum format, GLenum type, const void *pixels,
4719
 
                          const struct gl_pixelstore_attrib *packing,
4720
 
                          struct gl_texture_object *texObj,
4721
 
                          struct gl_texture_image *texImage)
 
4648
                          const struct gl_pixelstore_attrib *packing)
4722
4649
{
4723
 
   /* get pointer to src pixels (may be in a pbo which we'll map here) */
4724
 
   pixels = _mesa_validate_pbo_teximage(ctx, 2, width, height, 1, format, type,
4725
 
                                        pixels, packing, "glTexSubImage2D");
4726
 
   if (!pixels)
4727
 
      return;
4728
 
 
4729
 
   {
4730
 
      GLint dstRowStride = texture_row_stride(texImage);
4731
 
      GLboolean success = _mesa_texstore(ctx, 2, texImage->_BaseFormat,
4732
 
                                         texImage->TexFormat,
4733
 
                                         texImage->Data,
4734
 
                                         xoffset, yoffset, 0,
4735
 
                                         dstRowStride,
4736
 
                                         texImage->ImageOffsets,
4737
 
                                         width, height, 1,
4738
 
                                         format, type, pixels, packing);
4739
 
      if (!success) {
4740
 
         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage2D");
4741
 
      }
4742
 
   }
4743
 
 
4744
 
   _mesa_unmap_teximage_pbo(ctx, packing);
 
4650
   store_texsubimage(ctx, texImage,
 
4651
                     xoffset, yoffset, 0, width, height, 1,
 
4652
                     format, type, pixels, packing, "glTexSubImage2D");
4745
4653
}
4746
4654
 
4747
4655
 
4748
4656
/*
4749
 
 * This is the software fallback for Driver.TexSubImage3D().
4750
 
 * and Driver.CopyTexSubImage3D().
 
4657
 * This is the fallback for Driver.TexSubImage3D().
4751
4658
 */
4752
4659
void
4753
 
_mesa_store_texsubimage3d(struct gl_context *ctx, GLenum target, GLint level,
 
4660
_mesa_store_texsubimage3d(struct gl_context *ctx,
 
4661
                          struct gl_texture_image *texImage,
4754
4662
                          GLint xoffset, GLint yoffset, GLint zoffset,
4755
4663
                          GLint width, GLint height, GLint depth,
4756
4664
                          GLenum format, GLenum type, const void *pixels,
4757
 
                          const struct gl_pixelstore_attrib *packing,
4758
 
                          struct gl_texture_object *texObj,
4759
 
                          struct gl_texture_image *texImage)
 
4665
                          const struct gl_pixelstore_attrib *packing)
4760
4666
{
4761
 
   /* get pointer to src pixels (may be in a pbo which we'll map here) */
4762
 
   pixels = _mesa_validate_pbo_teximage(ctx, 3, width, height, depth, format,
4763
 
                                        type, pixels, packing,
4764
 
                                        "glTexSubImage3D");
4765
 
   if (!pixels)
4766
 
      return;
4767
 
 
4768
 
   {
4769
 
      GLint dstRowStride = texture_row_stride(texImage);
4770
 
      GLboolean success = _mesa_texstore(ctx, 3, texImage->_BaseFormat,
4771
 
                                         texImage->TexFormat,
4772
 
                                         texImage->Data,
4773
 
                                         xoffset, yoffset, zoffset,
4774
 
                                         dstRowStride,
4775
 
                                         texImage->ImageOffsets,
4776
 
                                         width, height, depth,
4777
 
                                         format, type, pixels, packing);
4778
 
      if (!success) {
4779
 
         _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexSubImage3D");
4780
 
      }
4781
 
   }
4782
 
 
4783
 
   _mesa_unmap_teximage_pbo(ctx, packing);
 
4667
   store_texsubimage(ctx, texImage,
 
4668
                     xoffset, yoffset, zoffset, width, height, depth,
 
4669
                     format, type, pixels, packing, "glTexSubImage3D");
4784
4670
}
4785
4671
 
4786
4672
 
4789
4675
 */
4790
4676
void
4791
4677
_mesa_store_compressed_teximage1d(struct gl_context *ctx,
4792
 
                                  GLenum target, GLint level,
 
4678
                                  struct gl_texture_image *texImage,
4793
4679
                                  GLint internalFormat,
4794
4680
                                  GLint width, GLint border,
4795
 
                                  GLsizei imageSize, const GLvoid *data,
4796
 
                                  struct gl_texture_object *texObj,
4797
 
                                  struct gl_texture_image *texImage)
 
4681
                                  GLsizei imageSize, const GLvoid *data)
4798
4682
{
4799
 
   /* this space intentionally left blank */
 
4683
   /* no compressed 1D image formats at this time */
4800
4684
   (void) ctx;
4801
 
   (void) target; (void) level;
4802
4685
   (void) internalFormat;
4803
4686
   (void) width; (void) border;
4804
4687
   (void) imageSize; (void) data;
4805
 
   (void) texObj;
4806
4688
   (void) texImage;
4807
4689
}
4808
4690
 
4813
4695
 */
4814
4696
void
4815
4697
_mesa_store_compressed_teximage2d(struct gl_context *ctx,
4816
 
                                  GLenum target, GLint level,
 
4698
                                  struct gl_texture_image *texImage,
4817
4699
                                  GLint internalFormat,
4818
4700
                                  GLint width, GLint height, GLint border,
4819
 
                                  GLsizei imageSize, const GLvoid *data,
4820
 
                                  struct gl_texture_object *texObj,
4821
 
                                  struct gl_texture_image *texImage)
 
4701
                                  GLsizei imageSize, const GLvoid *data)
4822
4702
{
4823
 
   (void) width; (void) height; (void) border;
4824
 
 
4825
 
   /* This is pretty simple, basically just do a memcpy without worrying
4826
 
    * about the usual image unpacking or image transfer operations.
 
4703
   /* This is pretty simple, because unlike the general texstore path we don't
 
4704
    * have to worry about the usual image unpacking or image transfer
 
4705
    * operations.
4827
4706
    */
4828
 
   ASSERT(texObj);
4829
4707
   ASSERT(texImage);
4830
4708
   ASSERT(texImage->Width > 0);
4831
4709
   ASSERT(texImage->Height > 0);
4832
4710
   ASSERT(texImage->Depth == 1);
4833
 
   ASSERT(texImage->Data == NULL); /* was freed in glCompressedTexImage2DARB */
4834
4711
 
4835
 
   /* allocate storage */
4836
 
   texImage->Data = _mesa_alloc_texmemory(imageSize);
4837
 
   if (!texImage->Data) {
4838
 
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2DARB");
 
4712
   /* allocate storage for texture data */
 
4713
   if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
 
4714
                                            width, height, 1)) {
 
4715
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexImage2D");
4839
4716
      return;
4840
4717
   }
4841
4718
 
4842
 
   data = _mesa_validate_pbo_compressed_teximage(ctx, imageSize, data,
4843
 
                                                 &ctx->Unpack,
4844
 
                                                 "glCompressedTexImage2D");
4845
 
   if (!data)
4846
 
      return;
4847
 
 
4848
 
   /* copy the data */
4849
 
   memcpy(texImage->Data, data, imageSize);
4850
 
 
4851
 
   _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
 
4719
   _mesa_store_compressed_texsubimage2d(ctx, texImage,
 
4720
                                        0, 0,
 
4721
                                        width, height,
 
4722
                                        texImage->TexFormat,
 
4723
                                        imageSize, data);
4852
4724
}
4853
4725
 
4854
4726
 
4858
4730
 */
4859
4731
void
4860
4732
_mesa_store_compressed_teximage3d(struct gl_context *ctx,
4861
 
                                  GLenum target, GLint level,
 
4733
                                  struct gl_texture_image *texImage,
4862
4734
                                  GLint internalFormat,
4863
4735
                                  GLint width, GLint height, GLint depth,
4864
4736
                                  GLint border,
4865
 
                                  GLsizei imageSize, const GLvoid *data,
4866
 
                                  struct gl_texture_object *texObj,
4867
 
                                  struct gl_texture_image *texImage)
 
4737
                                  GLsizei imageSize, const GLvoid *data)
4868
4738
{
4869
4739
   /* this space intentionally left blank */
4870
4740
   (void) ctx;
4871
 
   (void) target; (void) level;
4872
4741
   (void) internalFormat;
4873
4742
   (void) width; (void) height; (void) depth;
4874
4743
   (void) border;
4875
4744
   (void) imageSize; (void) data;
4876
 
   (void) texObj;
4877
4745
   (void) texImage;
4878
4746
}
4879
4747
 
4883
4751
 * Fallback for Driver.CompressedTexSubImage1D()
4884
4752
 */
4885
4753
void
4886
 
_mesa_store_compressed_texsubimage1d(struct gl_context *ctx, GLenum target,
4887
 
                                     GLint level,
 
4754
_mesa_store_compressed_texsubimage1d(struct gl_context *ctx,
 
4755
                                     struct gl_texture_image *texImage,
4888
4756
                                     GLint xoffset, GLsizei width,
4889
4757
                                     GLenum format,
4890
 
                                     GLsizei imageSize, const GLvoid *data,
4891
 
                                     struct gl_texture_object *texObj,
4892
 
                                     struct gl_texture_image *texImage)
 
4758
                                     GLsizei imageSize, const GLvoid *data)
4893
4759
{
4894
4760
   /* there are no compressed 1D texture formats yet */
4895
4761
   (void) ctx;
4896
 
   (void) target; (void) level;
4897
4762
   (void) xoffset; (void) width;
4898
4763
   (void) format;
4899
4764
   (void) imageSize; (void) data;
4900
 
   (void) texObj;
4901
4765
   (void) texImage;
4902
4766
}
4903
4767
 
4906
4770
 * Fallback for Driver.CompressedTexSubImage2D()
4907
4771
 */
4908
4772
void
4909
 
_mesa_store_compressed_texsubimage2d(struct gl_context *ctx, GLenum target,
4910
 
                                     GLint level,
 
4773
_mesa_store_compressed_texsubimage2d(struct gl_context *ctx,
 
4774
                                     struct gl_texture_image *texImage,
4911
4775
                                     GLint xoffset, GLint yoffset,
4912
4776
                                     GLsizei width, GLsizei height,
4913
4777
                                     GLenum format,
4914
 
                                     GLsizei imageSize, const GLvoid *data,
4915
 
                                     struct gl_texture_object *texObj,
4916
 
                                     struct gl_texture_image *texImage)
 
4778
                                     GLsizei imageSize, const GLvoid *data)
4917
4779
{
4918
 
   GLint bytesPerRow, destRowStride, srcRowStride;
 
4780
   GLint bytesPerRow, dstRowStride, srcRowStride;
4919
4781
   GLint i, rows;
4920
 
   GLubyte *dest;
 
4782
   GLubyte *dstMap;
4921
4783
   const GLubyte *src;
4922
4784
   const gl_format texFormat = texImage->TexFormat;
4923
 
   const GLint destWidth = texImage->Width;
4924
4785
   GLuint bw, bh;
4925
4786
 
4926
4787
   _mesa_get_format_block_size(texFormat, &bw, &bh);
4927
4788
 
4928
 
   (void) level;
4929
 
   (void) format;
4930
 
 
4931
4789
   /* these should have been caught sooner */
4932
 
   ASSERT((width % bw) == 0 || width == 2 || width == 1);
4933
 
   ASSERT((height % bh) == 0 || height == 2 || height == 1);
 
4790
   ASSERT((width % bw) == 0 || width < bw);
 
4791
   ASSERT((height % bh) == 0 || height < bh);
4934
4792
   ASSERT((xoffset % bw) == 0);
4935
4793
   ASSERT((yoffset % bh) == 0);
4936
4794
 
4944
4802
   srcRowStride = _mesa_format_row_stride(texFormat, width);
4945
4803
   src = (const GLubyte *) data;
4946
4804
 
4947
 
   destRowStride = _mesa_format_row_stride(texFormat, destWidth);
4948
 
   dest = _mesa_compressed_image_address(xoffset, yoffset, 0,
4949
 
                                         texFormat, destWidth,
4950
 
                                         (GLubyte *) texImage->Data);
4951
 
 
4952
 
   bytesPerRow = srcRowStride;  /* bytes per row of blocks */
4953
 
   rows = height / bh;  /* rows in blocks */
4954
 
 
4955
 
   /* copy rows of blocks */
4956
 
   for (i = 0; i < rows; i++) {
4957
 
      memcpy(dest, src, bytesPerRow);
4958
 
      dest += destRowStride;
4959
 
      src += srcRowStride;
 
4805
   /* Map dest texture buffer */
 
4806
   ctx->Driver.MapTextureImage(ctx, texImage, 0,
 
4807
                               xoffset, yoffset, width, height,
 
4808
                               GL_MAP_WRITE_BIT | GL_MAP_INVALIDATE_RANGE_BIT,
 
4809
                               &dstMap, &dstRowStride);
 
4810
 
 
4811
   if (dstMap) {
 
4812
      bytesPerRow = srcRowStride;  /* bytes per row of blocks */
 
4813
      rows = (height + bh - 1) / bh;  /* rows in blocks */
 
4814
 
 
4815
      /* copy rows of blocks */
 
4816
      for (i = 0; i < rows; i++) {
 
4817
         memcpy(dstMap, src, bytesPerRow);
 
4818
         dstMap += dstRowStride;
 
4819
         src += srcRowStride;
 
4820
      }
 
4821
 
 
4822
      ctx->Driver.UnmapTextureImage(ctx, texImage, 0);
 
4823
   }
 
4824
   else {
 
4825
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glCompressedTexSubImage2D");
4960
4826
   }
4961
4827
 
4962
4828
   _mesa_unmap_teximage_pbo(ctx, &ctx->Unpack);
4967
4833
 * Fallback for Driver.CompressedTexSubImage3D()
4968
4834
 */
4969
4835
void
4970
 
_mesa_store_compressed_texsubimage3d(struct gl_context *ctx, GLenum target,
4971
 
                                GLint level,
4972
 
                                GLint xoffset, GLint yoffset, GLint zoffset,
4973
 
                                GLsizei width, GLsizei height, GLsizei depth,
4974
 
                                GLenum format,
4975
 
                                GLsizei imageSize, const GLvoid *data,
4976
 
                                struct gl_texture_object *texObj,
4977
 
                                struct gl_texture_image *texImage)
 
4836
_mesa_store_compressed_texsubimage3d(struct gl_context *ctx,
 
4837
                                     struct gl_texture_image *texImage,
 
4838
                                     GLint xoffset, GLint yoffset, GLint zoffset,
 
4839
                                     GLsizei width, GLsizei height, GLsizei depth,
 
4840
                                     GLenum format,
 
4841
                                     GLsizei imageSize, const GLvoid *data)
4978
4842
{
4979
4843
   /* there are no compressed 3D texture formats yet */
4980
4844
   (void) ctx;
4981
 
   (void) target; (void) level;
4982
4845
   (void) xoffset; (void) yoffset; (void) zoffset;
4983
4846
   (void) width; (void) height; (void) depth;
4984
4847
   (void) format;
4985
4848
   (void) imageSize; (void) data;
4986
 
   (void) texObj;
4987
4849
   (void) texImage;
4988
4850
}