⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 texstore.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
         break;      case 2:         SWZ_CPY(dst, src, count, 1, 2);         break;      case 1:         SWZ_CPY(dst, src, count, 1, 1);         break;      default:         ;      }      break;   default:      ;   }#undef SWZ_CPY}static const GLubyte map_identity[6] = { 0, 1, 2, 3, ZERO, ONE };static const GLubyte map_3210[6] = { 3, 2, 1, 0, ZERO, ONE };/* Deal with the _REV input types: */static const GLubyte *type_mapping( GLenum srcType ){   switch (srcType) {   case GL_UNSIGNED_BYTE:      return map_identity;   case GL_UNSIGNED_INT_8_8_8_8:      return _mesa_little_endian() ? map_3210 : map_identity;   case GL_UNSIGNED_INT_8_8_8_8_REV:      return _mesa_little_endian() ? map_identity : map_3210;   default:      return NULL;   }}/* Mapping required if input type is  */static const GLubyte *byteswap_mapping( GLboolean swapBytes,		  GLenum srcType ){   if (!swapBytes)       return map_identity;   switch (srcType) {   case GL_UNSIGNED_BYTE:      return map_identity;   case GL_UNSIGNED_INT_8_8_8_8:   case GL_UNSIGNED_INT_8_8_8_8_REV:      return map_3210;   default:      return NULL;   }}/** * Transfer a GLubyte texture image with component swizzling. */static void_mesa_swizzle_ubyte_image(GLcontext *ctx, 			  GLuint dimensions,			  GLenum srcFormat,			  GLenum srcType,			  GLenum baseInternalFormat,			  const GLubyte *rgba2dst,			  GLuint dstComponents,			  GLvoid *dstAddr,			  GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,			  GLint dstRowStride,                          const GLuint *dstImageOffsets,			  GLint srcWidth, GLint srcHeight, GLint srcDepth,			  const GLvoid *srcAddr,			  const struct gl_pixelstore_attrib *srcPacking ){   GLint srcComponents = _mesa_components_in_format(srcFormat);   const GLubyte *srctype2ubyte, *swap;   GLubyte map[4], src2base[6], base2rgba[6];   GLint i;   const GLint srcRowStride =      _mesa_image_row_stride(srcPacking, srcWidth,                             srcFormat, GL_UNSIGNED_BYTE);   const GLint srcImageStride      = _mesa_image_image_stride(srcPacking, srcWidth, srcHeight, srcFormat,                                 GL_UNSIGNED_BYTE);   const GLubyte *srcImage      = (const GLubyte *) _mesa_image_address(dimensions, srcPacking, srcAddr,                                              srcWidth, srcHeight, srcFormat,                                              GL_UNSIGNED_BYTE, 0, 0, 0);   (void) ctx;   /* Translate from src->baseInternal->GL_RGBA->dst.  This will    * correctly deal with RGBA->RGB->RGBA conversions where the final    * A value must be 0xff regardless of the incoming alpha values.    */   compute_component_mapping(srcFormat, baseInternalFormat, src2base);   compute_component_mapping(baseInternalFormat, GL_RGBA, base2rgba);   swap = byteswap_mapping(srcPacking->SwapBytes, srcType);   srctype2ubyte = type_mapping(srcType);   for (i = 0; i < 4; i++)      map[i] = srctype2ubyte[swap[src2base[base2rgba[rgba2dst[i]]]]];/*    _mesa_printf("map %d %d %d %d\n", map[0], map[1], map[2], map[3]);  */   if (srcRowStride == dstRowStride &&       srcComponents == dstComponents &&       srcRowStride == srcWidth * srcComponents &&       dimensions < 3) {      /* 1 and 2D images only */      GLubyte *dstImage = (GLubyte *) dstAddr         + dstYoffset * dstRowStride         + dstXoffset * dstComponents;      swizzle_copy(dstImage, dstComponents, srcImage, srcComponents, map, 		   srcWidth * srcHeight);   }   else {      GLint img, row;      for (img = 0; img < srcDepth; img++) {         const GLubyte *srcRow = srcImage;         GLubyte *dstRow = (GLubyte *) dstAddr            + dstImageOffsets[dstZoffset + img] * dstComponents            + dstYoffset * dstRowStride            + dstXoffset * dstComponents;         for (row = 0; row < srcHeight; row++) {	    swizzle_copy(dstRow, dstComponents, srcRow, srcComponents, map, srcWidth);            dstRow += dstRowStride;            srcRow += srcRowStride;         }         srcImage += srcImageStride;      }   }}/** * Teximage storage routine for when a simple memcpy will do. * No pixel transfer operations or special texel encodings allowed. * 1D, 2D and 3D images supported. */static voidmemcpy_texture(GLcontext *ctx,	       GLuint dimensions,               const struct gl_texture_format *dstFormat,               GLvoid *dstAddr,               GLint dstXoffset, GLint dstYoffset, GLint dstZoffset,               GLint dstRowStride,               const GLuint *dstImageOffsets,               GLint srcWidth, GLint srcHeight, GLint srcDepth,               GLenum srcFormat, GLenum srcType,               const GLvoid *srcAddr,               const struct gl_pixelstore_attrib *srcPacking){   const GLint srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth,                                                     srcFormat, srcType);   const GLint srcImageStride = _mesa_image_image_stride(srcPacking,                                      srcWidth, srcHeight, srcFormat, srcType);   const GLubyte *srcImage = (const GLubyte *) _mesa_image_address(dimensions,        srcPacking, srcAddr, srcWidth, srcHeight, srcFormat, srcType, 0, 0, 0);   const GLint bytesPerRow = srcWidth * dstFormat->TexelBytes;#if 0   /* XXX update/re-enable for dstImageOffsets array */   const GLint bytesPerImage = srcHeight * bytesPerRow;   const GLint bytesPerTexture = srcDepth * bytesPerImage;   GLubyte *dstImage = (GLubyte *) dstAddr                     + dstZoffset * dstImageStride                     + dstYoffset * dstRowStride                     + dstXoffset * dstFormat->TexelBytes;   if (dstRowStride == srcRowStride &&       dstRowStride == bytesPerRow &&       ((dstImageStride == srcImageStride &&         dstImageStride == bytesPerImage) ||        (srcDepth == 1))) {      /* one big memcpy */      ctx->Driver.TextureMemCpy(dstImage, srcImage, bytesPerTexture);   }   else   {      GLint img, row;      for (img = 0; img < srcDepth; img++) {         const GLubyte *srcRow = srcImage;         GLubyte *dstRow = dstImage;         for (row = 0; row < srcHeight; row++) {            ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);            dstRow += dstRowStride;            srcRow += srcRowStride;         }         srcImage += srcImageStride;         dstImage += dstImageStride;      }   }#endif   GLint img, row;   for (img = 0; img < srcDepth; img++) {      const GLubyte *srcRow = srcImage;      GLubyte *dstRow = (GLubyte *) dstAddr         + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes         + dstYoffset * dstRowStride         + dstXoffset * dstFormat->TexelBytes;      for (row = 0; row < srcHeight; row++) {         ctx->Driver.TextureMemCpy(dstRow, srcRow, bytesPerRow);         dstRow += dstRowStride;         srcRow += srcRowStride;      }      srcImage += srcImageStride;   }}/** * Store an image in any of the formats: *   _mesa_texformat_rgba *   _mesa_texformat_rgb *   _mesa_texformat_alpha *   _mesa_texformat_luminance *   _mesa_texformat_luminance_alpha *   _mesa_texformat_intensity *  */GLboolean_mesa_texstore_rgba(TEXSTORE_PARAMS){   const GLint components = _mesa_components_in_format(baseInternalFormat);   ASSERT(dstFormat == &_mesa_texformat_rgba ||          dstFormat == &_mesa_texformat_rgb ||          dstFormat == &_mesa_texformat_alpha ||          dstFormat == &_mesa_texformat_luminance ||          dstFormat == &_mesa_texformat_luminance_alpha ||          dstFormat == &_mesa_texformat_intensity);   ASSERT(baseInternalFormat == GL_RGBA ||          baseInternalFormat == GL_RGB ||          baseInternalFormat == GL_ALPHA ||          baseInternalFormat == GL_LUMINANCE ||          baseInternalFormat == GL_LUMINANCE_ALPHA ||          baseInternalFormat == GL_INTENSITY);   ASSERT(dstFormat->TexelBytes == components * sizeof(GLchan));   if (!ctx->_ImageTransferState &&       !srcPacking->SwapBytes &&       baseInternalFormat == srcFormat &&       srcType == CHAN_TYPE) {      /* simple memcpy path */      memcpy_texture(ctx, dims,                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,                     dstRowStride,                     dstImageOffsets,                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,                     srcAddr, srcPacking);   }   else if (!ctx->_ImageTransferState &&            !srcPacking->SwapBytes &&            dstFormat == &_mesa_texformat_rgb &&            srcFormat == GL_RGBA &&            srcType == CHAN_TYPE) {      /* extract RGB from RGBA */      GLint img, row, col;      for (img = 0; img < srcDepth; img++) {         GLchan *dstImage = (GLchan *)            ((GLubyte *) dstAddr             + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes             + dstYoffset * dstRowStride             + dstXoffset * dstFormat->TexelBytes);         const GLint srcRowStride = _mesa_image_row_stride(srcPacking,                                                 srcWidth, srcFormat, srcType);         GLchan *srcRow = (GLchan *) _mesa_image_address(dims, srcPacking,                  srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, 0, 0);         GLchan *dstRow = dstImage;         for (row = 0; row < srcHeight; row++) {            for (col = 0; col < srcWidth; col++) {               dstRow[col * 3 + RCOMP] = srcRow[col * 4 + RCOMP];               dstRow[col * 3 + GCOMP] = srcRow[col * 4 + GCOMP];               dstRow[col * 3 + BCOMP] = srcRow[col * 4 + BCOMP];            }            dstRow += dstRowStride / sizeof(GLchan);            srcRow = (GLchan *) ((GLubyte *) srcRow + srcRowStride);         }      }   }   else if (!ctx->_ImageTransferState &&	    CHAN_TYPE == GL_UNSIGNED_BYTE &&	    (srcType == GL_UNSIGNED_BYTE ||	     srcType == GL_UNSIGNED_INT_8_8_8_8 ||	     srcType == GL_UNSIGNED_INT_8_8_8_8_REV) &&	    can_swizzle(baseInternalFormat) &&	    can_swizzle(srcFormat)) {      const GLubyte *dstmap;      GLuint components;      /* dstmap - how to swizzle from RGBA to dst format:       */      if (dstFormat == &_mesa_texformat_rgba) {	 dstmap = mappings[IDX_RGBA].from_rgba;	 components = 4;      }      else if (dstFormat == &_mesa_texformat_rgb) {	 dstmap = mappings[IDX_RGB].from_rgba;	 components = 3;      }      else if (dstFormat == &_mesa_texformat_alpha) {	 dstmap = mappings[IDX_ALPHA].from_rgba;	 components = 1;      }      else if (dstFormat == &_mesa_texformat_luminance) {	 dstmap = mappings[IDX_LUMINANCE].from_rgba;	 components = 1;      }      else if (dstFormat == &_mesa_texformat_luminance_alpha) {	 dstmap = mappings[IDX_LUMINANCE_ALPHA].from_rgba;	 components = 2;      }      else if (dstFormat == &_mesa_texformat_intensity) {	 dstmap = mappings[IDX_INTENSITY].from_rgba;	 components = 1;      }      else {         _mesa_problem(ctx, "Unexpected dstFormat in _mesa_texstore_rgba");         return GL_FALSE;      }      _mesa_swizzle_ubyte_image(ctx, dims,				srcFormat,				srcType,				baseInternalFormat,				dstmap, components,				dstAddr, dstXoffset, dstYoffset, dstZoffset,				dstRowStride, dstImageOffsets,				srcWidth, srcHeight, srcDepth, srcAddr,				srcPacking);         }   else {      /* general path */      const GLchan *tempImage = _mesa_make_temp_chan_image(ctx, dims,                                                 baseInternalFormat,                                                 dstFormat->BaseFormat,                                                 srcWidth, srcHeight, srcDepth,                                                 srcFormat, srcType, srcAddr,                                                 srcPacking);      const GLchan *src = tempImage;      GLint bytesPerRow;      GLint img, row;      if (!tempImage)         return GL_FALSE;      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);      bytesPerRow = srcWidth * components * sizeof(GLchan);      for (img = 0; img < srcDepth; img++) {         GLubyte *dstRow = (GLubyte *) dstAddr            + dstImageOffsets[dstZoffset + img] * dstFormat->TexelBytes            + dstYoffset * dstRowStride            + dstXoffset * dstFormat->TexelBytes;         for (row = 0; row < srcHeight; row++) {            _mesa_memcpy(dstRow, src, bytesPerRow);            dstRow += dstRowStride;            src += srcWidth * components;         }      }      _mesa_free((void *) tempImage);   }   return GL_TRUE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -