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

📄 texstore.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
/** * Store a 32-bit integer depth component texture image. */GLboolean_mesa_texstore_z32(TEXSTORE_PARAMS){   const GLuint depthScale = 0xffffffff;   (void) dims;   ASSERT(dstFormat == &_mesa_texformat_z32);   ASSERT(dstFormat->TexelBytes == sizeof(GLuint));   if (!ctx->_ImageTransferState &&       !srcPacking->SwapBytes &&       baseInternalFormat == GL_DEPTH_COMPONENT &&       srcFormat == GL_DEPTH_COMPONENT &&       srcType == GL_UNSIGNED_INT) {      /* simple memcpy path */      memcpy_texture(ctx, dims,                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,                     dstRowStride,                     dstImageOffsets,                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,                     srcAddr, srcPacking);   }   else {      /* general path */      GLint img, row;      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++) {            const GLvoid *src = _mesa_image_address(dims, srcPacking,                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);            _mesa_unpack_depth_span(ctx, srcWidth,                                    GL_UNSIGNED_INT, (GLuint *) dstRow,                                    depthScale, srcType, src, srcPacking);            dstRow += dstRowStride;         }      }   }   return GL_TRUE;}#define STRIDE_3D 0/** * Store a 16-bit integer depth component texture image. */GLboolean_mesa_texstore_z16(TEXSTORE_PARAMS){   const GLuint depthScale = 0xffff;   (void) dims;   ASSERT(dstFormat == &_mesa_texformat_z16);   ASSERT(dstFormat->TexelBytes == sizeof(GLushort));   if (!ctx->_ImageTransferState &&       !srcPacking->SwapBytes &&       baseInternalFormat == GL_DEPTH_COMPONENT &&       srcFormat == GL_DEPTH_COMPONENT &&       srcType == GL_UNSIGNED_SHORT) {      /* simple memcpy path */      memcpy_texture(ctx, dims,                     dstFormat, dstAddr, dstXoffset, dstYoffset, dstZoffset,                     dstRowStride,                     dstImageOffsets,                     srcWidth, srcHeight, srcDepth, srcFormat, srcType,                     srcAddr, srcPacking);   }   else {      /* general path */      GLint img, row;      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++) {            const GLvoid *src = _mesa_image_address(dims, srcPacking,                srcAddr, srcWidth, srcHeight, srcFormat, srcType, img, row, 0);            GLushort *dst16 = (GLushort *) dstRow;            _mesa_unpack_depth_span(ctx, srcWidth,                                    GL_UNSIGNED_SHORT, dst16, depthScale,                                    srcType, src, srcPacking);            dstRow += dstRowStride;         }      }   }   return GL_TRUE;}/** * Store an rgb565 or rgb565_rev texture image. */GLboolean_mesa_texstore_rgb565(TEXSTORE_PARAMS){   ASSERT(dstFormat == &_mesa_texformat_rgb565 ||          dstFormat == &_mesa_texformat_rgb565_rev);   ASSERT(dstFormat->TexelBytes == 2);   if (!ctx->_ImageTransferState &&       !srcPacking->SwapBytes &&       dstFormat == &_mesa_texformat_rgb565 &&       baseInternalFormat == GL_RGB &&       srcFormat == GL_RGB &&       srcType == GL_UNSIGNED_SHORT_5_6_5) {      /* 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 &&            baseInternalFormat == GL_RGB &&            srcFormat == GL_RGB &&            srcType == GL_UNSIGNED_BYTE &&            dims == 2) {      /* do optimized tex store */      const GLint srcRowStride = _mesa_image_row_stride(srcPacking, srcWidth,                                                        srcFormat, srcType);      const GLubyte *src = (const GLubyte *)         _mesa_image_address(dims, srcPacking, srcAddr, srcWidth, srcHeight,                             srcFormat, srcType, 0, 0, 0);      GLubyte *dst = (GLubyte *) dstAddr                   + dstYoffset * dstRowStride                   + dstXoffset * dstFormat->TexelBytes;      GLint row, col;      for (row = 0; row < srcHeight; row++) {         const GLubyte *srcUB = (const GLubyte *) src;         GLushort *dstUS = (GLushort *) dst;         /* check for byteswapped format */         if (dstFormat == &_mesa_texformat_rgb565) {            for (col = 0; col < srcWidth; col++) {               dstUS[col] = PACK_COLOR_565( srcUB[0], srcUB[1], srcUB[2] );               srcUB += 3;            }         }         else {            for (col = 0; col < srcWidth; col++) {               dstUS[col] = PACK_COLOR_565_REV( srcUB[0], srcUB[1], srcUB[2] );               srcUB += 3;            }         }         dst += dstRowStride;         src += srcRowStride;      }   }   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 img, row, col;      if (!tempImage)         return GL_FALSE;      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);      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++) {            GLushort *dstUS = (GLushort *) dstRow;            /* check for byteswapped format */            if (dstFormat == &_mesa_texformat_rgb565) {               for (col = 0; col < srcWidth; col++) {                  dstUS[col] = PACK_COLOR_565( CHAN_TO_UBYTE(src[RCOMP]),                                               CHAN_TO_UBYTE(src[GCOMP]),                                               CHAN_TO_UBYTE(src[BCOMP]) );                  src += 3;               }            }            else {               for (col = 0; col < srcWidth; col++) {                  dstUS[col] = PACK_COLOR_565_REV( CHAN_TO_UBYTE(src[RCOMP]),                                                   CHAN_TO_UBYTE(src[GCOMP]),                                                   CHAN_TO_UBYTE(src[BCOMP]) );                  src += 3;               }            }            dstRow += dstRowStride;         }      }      _mesa_free((void *) tempImage);   }   return GL_TRUE;}/** * Store a texture in MESA_FORMAT_RGBA8888 or MESA_FORMAT_RGBA8888_REV. */GLboolean_mesa_texstore_rgba8888(TEXSTORE_PARAMS){   const GLboolean littleEndian = _mesa_little_endian();   ASSERT(dstFormat == &_mesa_texformat_rgba8888 ||          dstFormat == &_mesa_texformat_rgba8888_rev);   ASSERT(dstFormat->TexelBytes == 4);   if (!ctx->_ImageTransferState &&       !srcPacking->SwapBytes &&       dstFormat == &_mesa_texformat_rgba8888 &&       baseInternalFormat == GL_RGBA &&      ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8) ||       (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && !littleEndian) ||       (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||       (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && littleEndian))) {       /* 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_rgba8888_rev &&       baseInternalFormat == GL_RGBA &&      ((srcFormat == GL_RGBA && srcType == GL_UNSIGNED_INT_8_8_8_8_REV) ||       (srcFormat == GL_RGBA && srcType == GL_UNSIGNED_BYTE && littleEndian) ||       (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_INT_8_8_8_8) ||       (srcFormat == GL_ABGR_EXT && srcType == GL_UNSIGNED_BYTE && !littleEndian))) {      /* 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 &&	    (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)) {      GLubyte dstmap[4];      /* dstmap - how to swizzle from RGBA to dst format:       */      if ((littleEndian && dstFormat == &_mesa_texformat_rgba8888) ||	  (!littleEndian && dstFormat == &_mesa_texformat_rgba8888_rev)) {	 dstmap[3] = 0;	 dstmap[2] = 1;	 dstmap[1] = 2;	 dstmap[0] = 3;      }      else {	 dstmap[3] = 3;	 dstmap[2] = 2;	 dstmap[1] = 1;	 dstmap[0] = 0;      }            _mesa_swizzle_ubyte_image(ctx, dims,				srcFormat,				srcType,				baseInternalFormat,				dstmap, 4,				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 img, row, col;      if (!tempImage)         return GL_FALSE;      _mesa_adjust_image_for_convolution(ctx, dims, &srcWidth, &srcHeight);      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++) {            GLuint *dstUI = (GLuint *) dstRow;            if (dstFormat == &_mesa_texformat_rgba8888) {               for (col = 0; col < srcWidth; col++) {                  dstUI[col] = PACK_COLOR_8888( CHAN_TO_UBYTE(src[RCOMP]),                                                CHAN_TO_UBYTE(src[GCOMP]),                                                CHAN_TO_UBYTE(src[BCOMP]),                                                CHAN_TO_UBYTE(src[ACOMP]) );                  src += 4;               }            }            else {               for (col = 0; col < srcWidth; col++) {                  dstUI[col] = PACK_COLOR_8888_REV( CHAN_TO_UBYTE(src[RCOMP]),                                                    CHAN_TO_UBYTE(src[GCOMP]),                                                    CHAN_TO_UBYTE(src[BCOMP]),                                                    CHAN_TO_UBYTE(src[ACOMP]) );                  src += 4;               }            }            dstRow += dstRowStride;         }      }      _mesa_free((void *) tempImage);   }   return GL_TRUE;}GLboolean_mesa_texstore_argb8888(TEXSTORE_PARAMS){   const GLboolean littleEndian = _mesa_little_endian();   ASSERT(dstFormat == &_mesa_texformat_argb8888 ||          dstFormat == &_mesa_texformat_argb8888_rev);   ASSERT(dstFormat->TexelBytes == 4);   if (!ctx->_ImageTransferState &&       !srcPacking->SwapBytes &&       dstFormat == &_mesa_texformat_argb8888 &&       baseInternalFormat == GL_RGBA &&       srcFormat == GL_BGRA &&       ((srcType == GL_UNSIGNED_BYTE && littleEndian) ||        srcType == GL_UNSIGNED_INT_8_8_8_8_REV)) {      /* simple memcpy path (little endian) */      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_argb8888_rev &&       baseInternalFormat == GL_RGBA &&       srcFormat == GL_BGRA &&       ((srcType == GL_UNSIGNED_BYTE && !littleEndian) ||        srcType == GL_UNSIGNED_INT_8_8_8_8)) {      /* simple memcpy path (big endian) */      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_argb8888 &&            srcFormat == GL_RGB &&	    (baseInternalFormat == GL_RGBA ||	     baseInternalFormat == GL_RGB) &&            srcType == GL_UNSIGNED_BYTE) {      int img, row, col;      for (img = 0; img < srcDepth; img++) {         const GLint srcRowStride = _mesa_image_row_stride(srcPacking,                                                 srcWidth, srcFormat, srcType);

⌨️ 快捷键说明

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