/*!*************************************************************************** @Function PVRTTextureTile @Modified pOut The tiled texture in system memory @Input pIn The source texture @Input nRepeatCnt Number of times to repeat the source texture @Description Allocates and fills, in system memory, a texture large enough to repeat the source texture specified number of times. *****************************************************************************/ void PVRTTextureTile( PVRTextureHeaderV3 **pOut, const PVRTextureHeaderV3 * const pIn, const int nRepeatCnt) { unsigned int nFormat = 0, nType = 0, nBPP, nSize, nElW = 0, nElH = 0, nElD = 0; PVRTuint8 *pMmSrc, *pMmDst; unsigned int nLevel; PVRTextureHeaderV3 *psTexHeaderNew; _ASSERT(pIn->u32Width); _ASSERT(pIn->u32Width == pIn->u32Height); _ASSERT(nRepeatCnt > 1); PVRTGetOGLES2TextureFormat(*pIn,nFormat,nFormat,nType); PVRTGetFormatMinDims(pIn->u64PixelFormat,nElW,nElH,nElD); nBPP = PVRTGetBitsPerPixel(pIn->u64PixelFormat); nSize = pIn->u32Width * nRepeatCnt; psTexHeaderNew = PVRTTextureCreate(nSize, nSize, nElW, nElH, nBPP, true); *psTexHeaderNew = *pIn; pMmDst = (PVRTuint8*)psTexHeaderNew + sizeof(*psTexHeaderNew); pMmSrc = (PVRTuint8*)pIn + sizeof(*pIn); for(nLevel = 0; ((unsigned int)1 << nLevel) < nSize; ++nLevel) { int nBlocksDstW = PVRT_MAX((unsigned int)1, (nSize >> nLevel) / nElW); int nBlocksDstH = PVRT_MAX((unsigned int)1, (nSize >> nLevel) / nElH); int nBlocksSrcW = PVRT_MAX((unsigned int)1, (pIn->u32Width >> nLevel) / nElW); int nBlocksSrcH = PVRT_MAX((unsigned int)1, (pIn->u32Height >> nLevel) / nElH); int nBlocksS = nBPP * nElW * nElH / 8; PVRTTextureLoadTiled( pMmDst, nBlocksDstW, nBlocksDstH, pMmSrc, nBlocksSrcW, nBlocksSrcH, nBlocksS, (/*pIn->u64PixelFormat>=ePVRTPF_PVRTCI_2bpp_RGB &&*/ pIn->u64PixelFormat<=ePVRTPF_PVRTCI_4bpp_RGBA) ? true : false); pMmDst += nBlocksDstW * nBlocksDstH * nBlocksS; pMmSrc += nBlocksSrcW * nBlocksSrcH * nBlocksS; } psTexHeaderNew->u32Width = nSize; psTexHeaderNew->u32Height = nSize; psTexHeaderNew->u32MIPMapCount = nLevel+1; *pOut = psTexHeaderNew; }
/*!*************************************************************************** @Function PVRTTextureTile @Modified pOut The tiled texture in system memory @Input pIn The source texture @Input nRepeatCnt Number of times to repeat the source texture @Description Allocates and fills, in system memory, a texture large enough to repeat the source texture specified number of times. *****************************************************************************/ void PVRTTextureTile( PVR_Texture_Header **pOut, const PVR_Texture_Header * const pIn, const int nRepeatCnt) { unsigned int nFormat = 0, nType = 0, nBPP, nSize, nElW = 0, nElH = 0; PVRTuint8 *pMmSrc, *pMmDst; unsigned int nLevel; PVR_Texture_Header *psTexHeaderNew; _ASSERT(pIn->dwWidth); _ASSERT(pIn->dwWidth == pIn->dwHeight); _ASSERT(nRepeatCnt > 1); switch(pIn->dwpfFlags & PVRTEX_PIXELTYPE) { case OGL_RGBA_5551: nFormat = GL_UNSIGNED_SHORT_5_5_5_1; nType = GL_RGBA; nElW = 1; nElH = 1; break; case OGL_RGBA_8888: nFormat = GL_UNSIGNED_BYTE; nType = GL_RGBA; nElW = 1; nElH = 1; break; case OGL_PVRTC2: nFormat = GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG; nType = 0; nElW = 8; nElH = 4; break; case OGL_PVRTC4: nFormat = GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG; nType = 0; nElW = 4; nElH = 4; break; } nBPP = PVRTTextureFormatGetBPP(nFormat, nType); nSize = pIn->dwWidth * nRepeatCnt; psTexHeaderNew = PVRTTextureCreate(nSize, nSize, nElW, nElH, nBPP, true); *psTexHeaderNew = *pIn; pMmDst = (PVRTuint8*)psTexHeaderNew + sizeof(*psTexHeaderNew); pMmSrc = (PVRTuint8*)pIn + sizeof(*pIn); for(nLevel = 0; ((unsigned int)1 << nLevel) < nSize; ++nLevel) { int nBlocksDstW = PVRT_MAX((unsigned int)1, (nSize >> nLevel) / nElW); int nBlocksDstH = PVRT_MAX((unsigned int)1, (nSize >> nLevel) / nElH); int nBlocksSrcW = PVRT_MAX((unsigned int)1, (pIn->dwWidth >> nLevel) / nElW); int nBlocksSrcH = PVRT_MAX((unsigned int)1, (pIn->dwHeight >> nLevel) / nElH); int nBlocksS = nBPP * nElW * nElH / 8; PVRTTextureLoadTiled( pMmDst, nBlocksDstW, nBlocksDstH, pMmSrc, nBlocksSrcW, nBlocksSrcH, nBlocksS, (pIn->dwpfFlags & PVRTEX_TWIDDLE) ? true : false); pMmDst += nBlocksDstW * nBlocksDstH * nBlocksS; pMmSrc += nBlocksSrcW * nBlocksSrcH * nBlocksS; } psTexHeaderNew->dwWidth = nSize; psTexHeaderNew->dwHeight = nSize; psTexHeaderNew->dwMipMapCount = nLevel; *pOut = psTexHeaderNew; }