1 /*!**************************************************************************** 2 3 @file PVRTTexture.h 4 @copyright Copyright (c) Imagination Technologies Limited. 5 @brief Texture loading. 6 7 ******************************************************************************/ 8 #ifndef _PVRTTEXTURE_H_ 9 #define _PVRTTEXTURE_H_ 10 11 #include "PVRTGlobal.h" 12 13 /***************************************************************************** 14 * Texture related constants and enumerations. 15 *****************************************************************************/ 16 // V3 Header Identifiers. 17 const PVRTuint32 PVRTEX3_IDENT = 0x03525650; // 'P''V''R'3 18 const PVRTuint32 PVRTEX3_IDENT_REV = 0x50565203; 19 // If endianness is backwards then PVR3 will read as 3RVP, hence why it is written as an int. 20 21 //Current version texture identifiers 22 const PVRTuint32 PVRTEX_CURR_IDENT = PVRTEX3_IDENT; 23 const PVRTuint32 PVRTEX_CURR_IDENT_REV = PVRTEX3_IDENT_REV; 24 25 // PVR Header file flags. Condition if true. If false, opposite is true unless specified. 26 const PVRTuint32 PVRTEX3_FILE_COMPRESSED = (1<<0); // Texture has been file compressed using PVRTexLib (currently unused) 27 const PVRTuint32 PVRTEX3_PREMULTIPLIED = (1<<1); // Texture has been premultiplied by alpha value. 28 29 // Mip Map level specifier constants. Other levels are specified by 1,2...n 30 const PVRTint32 PVRTEX_TOPMIPLEVEL = 0; 31 const PVRTint32 PVRTEX_ALLMIPLEVELS = -1; //This is a special number used simply to return a total of all MIP levels when dealing with data sizes. 32 33 //values for each meta data type that we know about. Texture arrays hinge on each surface being identical in all but content, including meta data. 34 //If the meta data varies even slightly then a new texture should be used. It is possible to write your own extension to get around this however. 35 enum EPVRTMetaData 36 { 37 ePVRTMetaDataTextureAtlasCoords=0, 38 ePVRTMetaDataBumpData, 39 ePVRTMetaDataCubeMapOrder, 40 ePVRTMetaDataTextureOrientation, 41 ePVRTMetaDataBorderData, 42 ePVRTMetaDataPadding, 43 ePVRTMetaDataNumMetaDataTypes 44 }; 45 46 enum EPVRTAxis 47 { 48 ePVRTAxisX = 0, 49 ePVRTAxisY = 1, 50 ePVRTAxisZ = 2 51 }; 52 53 enum EPVRTOrientation 54 { 55 ePVRTOrientLeft = 1<<ePVRTAxisX, 56 ePVRTOrientRight= 0, 57 ePVRTOrientUp = 1<<ePVRTAxisY, 58 ePVRTOrientDown = 0, 59 ePVRTOrientOut = 1<<ePVRTAxisZ, 60 ePVRTOrientIn = 0 61 }; 62 63 enum EPVRTColourSpace 64 { 65 ePVRTCSpacelRGB, 66 ePVRTCSpacesRGB, 67 ePVRTCSpaceNumSpaces 68 }; 69 70 //Compressed pixel formats 71 enum EPVRTPixelFormat 72 { 73 ePVRTPF_PVRTCI_2bpp_RGB, 74 ePVRTPF_PVRTCI_2bpp_RGBA, 75 ePVRTPF_PVRTCI_4bpp_RGB, 76 ePVRTPF_PVRTCI_4bpp_RGBA, 77 ePVRTPF_PVRTCII_2bpp, 78 ePVRTPF_PVRTCII_4bpp, 79 ePVRTPF_ETC1, 80 ePVRTPF_DXT1, 81 ePVRTPF_DXT2, 82 ePVRTPF_DXT3, 83 ePVRTPF_DXT4, 84 ePVRTPF_DXT5, 85 86 //These formats are identical to some DXT formats. 87 ePVRTPF_BC1 = ePVRTPF_DXT1, 88 ePVRTPF_BC2 = ePVRTPF_DXT3, 89 ePVRTPF_BC3 = ePVRTPF_DXT5, 90 91 //These are currently unsupported: 92 ePVRTPF_BC4, 93 ePVRTPF_BC5, 94 ePVRTPF_BC6, 95 ePVRTPF_BC7, 96 97 //These are supported 98 ePVRTPF_UYVY, 99 ePVRTPF_YUY2, 100 ePVRTPF_BW1bpp, 101 ePVRTPF_SharedExponentR9G9B9E5, 102 ePVRTPF_RGBG8888, 103 ePVRTPF_GRGB8888, 104 ePVRTPF_ETC2_RGB, 105 ePVRTPF_ETC2_RGBA, 106 ePVRTPF_ETC2_RGB_A1, 107 ePVRTPF_EAC_R11, 108 ePVRTPF_EAC_RG11, 109 110 //Invalid value 111 ePVRTPF_NumCompressedPFs 112 }; 113 114 //Variable Type Names 115 enum EPVRTVariableType 116 { 117 ePVRTVarTypeUnsignedByteNorm, 118 ePVRTVarTypeSignedByteNorm, 119 ePVRTVarTypeUnsignedByte, 120 ePVRTVarTypeSignedByte, 121 ePVRTVarTypeUnsignedShortNorm, 122 ePVRTVarTypeSignedShortNorm, 123 ePVRTVarTypeUnsignedShort, 124 ePVRTVarTypeSignedShort, 125 ePVRTVarTypeUnsignedIntegerNorm, 126 ePVRTVarTypeSignedIntegerNorm, 127 ePVRTVarTypeUnsignedInteger, 128 ePVRTVarTypeSignedInteger, 129 ePVRTVarTypeSignedFloat, ePVRTVarTypeFloat=ePVRTVarTypeSignedFloat, //the name ePVRTVarTypeFloat is now deprecated. 130 ePVRTVarTypeUnsignedFloat, 131 ePVRTVarTypeNumVarTypes 132 }; 133 134 //A 64 bit pixel format ID & this will give you the high bits of a pixel format to check for a compressed format. 135 static const PVRTuint64 PVRTEX_PFHIGHMASK=0xffffffff00000000ull; 136 137 /***************************************************************************** 138 * Texture header structures. 139 *****************************************************************************/ 140 141 /*!*********************************************************************** 142 @struct MetaDataBlock 143 @brief A struct containing a block of extraneous meta data for a texture. 144 *************************************************************************/ 145 struct MetaDataBlock 146 { 147 PVRTuint32 DevFOURCC; ///< A 4cc descriptor of the data type's creator. Values equating to values between 'P' 'V' 'R' 0 and 'P' 'V' 'R' 255 will be used by our headers. 148 PVRTuint32 u32Key; ///< A DWORD (enum value) identifying the data type, and thus how to read it. 149 PVRTuint32 u32DataSize; ///< Size of the Data member. 150 PVRTuint8* Data; ///< Data array, can be absolutely anything, the loader needs to know how to handle it based on DevFOURCC and Key. Use new operator to assign to it. 151 152 /*!*********************************************************************** 153 @fn MetaDataBlock 154 @brief Meta Data Block Constructor 155 *************************************************************************/ 156 MetaDataBlock() : DevFOURCC(0), u32Key(0), u32DataSize(0), Data(NULL) 157 {} 158 159 /*!*********************************************************************** 160 @fn MetaDataBlock 161 @brief Meta Data Block Copy Constructor 162 *************************************************************************/ 163 MetaDataBlock(const MetaDataBlock& rhs) : DevFOURCC(rhs.DevFOURCC), u32Key(rhs.u32Key), u32DataSize(rhs.u32DataSize) 164 { 165 //Copy the data across. 166 Data = new PVRTuint8[u32DataSize]; 167 for (PVRTuint32 uiDataAmt=0; uiDataAmt<u32DataSize; ++uiDataAmt) 168 { 169 Data[uiDataAmt]=rhs.Data[uiDataAmt]; 170 } 171 } 172 173 /*!*********************************************************************** 174 @fn ~MetaDataBlock 175 @brief Meta Data Block Destructor 176 *************************************************************************/ 177 ~MetaDataBlock() 178 { 179 if (Data) 180 delete [] Data; 181 Data = NULL; 182 } 183 184 /*!*********************************************************************** 185 @fn SizeOfBlock 186 @return size_t Size (in a file) of the block. 187 @brief Returns the number of extra bytes this will add to any output files. 188 *************************************************************************/ 189 size_t SizeOfBlock() const 190 { 191 return sizeof(DevFOURCC)+sizeof(u32Key)+sizeof(u32DataSize)+u32DataSize; 192 } 193 194 /*!*********************************************************************** 195 @brief Assigns one MetaDataBlock to the other. 196 @return MetaDataBlock This MetaDataBlock after the operation. 197 *************************************************************************/ 198 MetaDataBlock& operator=(const MetaDataBlock& rhs) 199 { 200 if (&rhs==this) 201 return *this; 202 203 //Remove pre-existing data. 204 if (Data) 205 delete [] Data; 206 Data=NULL; 207 208 //Copy the basic parameters 209 DevFOURCC=rhs.DevFOURCC; 210 u32Key=rhs.u32Key; 211 u32DataSize=rhs.u32DataSize; 212 213 //Copy the data across. 214 if (rhs.Data) 215 { 216 Data = new PVRTuint8[u32DataSize]; 217 for (PVRTuint32 uiDataAmt=0; uiDataAmt<u32DataSize; ++uiDataAmt) 218 { 219 Data[uiDataAmt]=rhs.Data[uiDataAmt]; 220 } 221 } 222 223 return *this; 224 } 225 226 /*!*************************************************************************** 227 @fn ReadFromPtr 228 @param[in] pDataCursor The data to read 229 @brief Reads from a pointer of memory in to the meta data block. 230 *****************************************************************************/ 231 bool ReadFromPtr(const unsigned char** pDataCursor); 232 }; 233 234 #pragma pack(push,4) 235 236 /*!*************************************************************************** 237 @struct PVRTextureHeaderV3 238 @brief A header for a PVR texture. 239 @details Contains everything required to read a texture accurately, and nothing more. Extraneous data is stored in a MetaDataBlock. 240 Correct use of the texture may rely on MetaDataBlock, but accurate data loading can be done through the standard header alone. 241 *****************************************************************************/ 242 struct PVRTextureHeaderV3{ 243 PVRTuint32 u32Version; ///< Version of the file header, used to identify it. 244 PVRTuint32 u32Flags; ///< Various format flags. 245 PVRTuint64 u64PixelFormat; ///< The pixel format, 8cc value storing the 4 channel identifiers and their respective sizes. 246 PVRTuint32 u32ColourSpace; ///< The Colour Space of the texture, currently either linear RGB or sRGB. 247 PVRTuint32 u32ChannelType; ///< Variable type that the channel is stored in. Supports signed/unsigned int/short/byte or float for now. 248 PVRTuint32 u32Height; ///< Height of the texture. 249 PVRTuint32 u32Width; ///< Width of the texture. 250 PVRTuint32 u32Depth; ///< Depth of the texture. (Z-slices) 251 PVRTuint32 u32NumSurfaces; ///< Number of members in a Texture Array. 252 PVRTuint32 u32NumFaces; ///< Number of faces in a Cube Map. Maybe be a value other than 6. 253 PVRTuint32 u32MIPMapCount; ///< Number of MIP Maps in the texture - NB: Includes top level. 254 PVRTuint32 u32MetaDataSize; ///< Size of the accompanying meta data. 255 256 /*!*************************************************************************** 257 @brief Constructor for the header - used to make sure that the header is initialised usefully. 258 The initial pixel format is an invalid one and must be set. 259 *****************************************************************************/ 260 PVRTextureHeaderV3() : 261 u32Version(PVRTEX3_IDENT), ///< Version of the file header. 262 u32Flags(0), ///< Format flags. 263 u64PixelFormat(ePVRTPF_NumCompressedPFs), ///< The pixel format. 264 u32ColourSpace(0), ///< The Colour Space of the texture. 265 u32ChannelType(0), ///< Variable type that the channel is stored in. 266 u32Height(1), ///< Height of the texture. 267 u32Width(1), ///< Width of the texture. 268 u32Depth(1), ///< Depth of the texture. (Z-slices) 269 u32NumSurfaces(1), ///< Number of members in a Texture Array. 270 u32NumFaces(1), ///< Number of faces in a Cube Map. Maybe be a value other than 6. 271 u32MIPMapCount(1), ///< Number of MIP Maps in the texture - NB: Includes top level. 272 u32MetaDataSize(0) ///< Size of the accompanying meta data. 273 {} 274 }; 275 #pragma pack(pop) 276 #define PVRTEX3_HEADERSIZE 52 277 278 /*!*************************************************************************** 279 @brief Describes the Version 2 header of a PVR texture header. 280 *****************************************************************************/ 281 struct PVR_Texture_Header 282 { 283 PVRTuint32 dwHeaderSize; /*!< size of the structure */ 284 PVRTuint32 dwHeight; /*!< height of surface to be created */ 285 PVRTuint32 dwWidth; /*!< width of input surface */ 286 PVRTuint32 dwMipMapCount; /*!< number of mip-map levels requested */ 287 PVRTuint32 dwpfFlags; /*!< pixel format flags */ 288 PVRTuint32 dwTextureDataSize; /*!< Total size in bytes */ 289 PVRTuint32 dwBitCount; /*!< number of bits per pixel */ 290 PVRTuint32 dwRBitMask; /*!< mask for red bit */ 291 PVRTuint32 dwGBitMask; /*!< mask for green bits */ 292 PVRTuint32 dwBBitMask; /*!< mask for blue bits */ 293 PVRTuint32 dwAlphaBitMask; /*!< mask for alpha channel */ 294 PVRTuint32 dwPVR; /*!< magic number identifying pvr file */ 295 PVRTuint32 dwNumSurfs; /*!< the number of surfaces present in the pvr */ 296 } ; 297 298 /***************************************************************************** 299 * Legacy (V2 and V1) ENUMS 300 *****************************************************************************/ 301 302 /*!*************************************************************************** 303 @brief Legacy pixel type. DEPRECATED. 304 *****************************************************************************/ 305 enum PVRTPixelType 306 { 307 MGLPT_ARGB_4444 = 0x00, 308 MGLPT_ARGB_1555, 309 MGLPT_RGB_565, 310 MGLPT_RGB_555, 311 MGLPT_RGB_888, 312 MGLPT_ARGB_8888, 313 MGLPT_ARGB_8332, 314 MGLPT_I_8, 315 MGLPT_AI_88, 316 MGLPT_1_BPP, 317 MGLPT_VY1UY0, 318 MGLPT_Y1VY0U, 319 MGLPT_PVRTC2, 320 MGLPT_PVRTC4, 321 322 // OpenGL version of pixel types 323 OGL_RGBA_4444= 0x10, 324 OGL_RGBA_5551, 325 OGL_RGBA_8888, 326 OGL_RGB_565, 327 OGL_RGB_555, 328 OGL_RGB_888, 329 OGL_I_8, 330 OGL_AI_88, 331 OGL_PVRTC2, 332 OGL_PVRTC4, 333 OGL_BGRA_8888, 334 OGL_A_8, 335 OGL_PVRTCII4, ///< Not in use 336 OGL_PVRTCII2, ///< Not in use 337 338 // S3TC Encoding 339 D3D_DXT1 = 0x20, 340 D3D_DXT2, 341 D3D_DXT3, 342 D3D_DXT4, 343 D3D_DXT5, 344 345 //RGB Formats 346 D3D_RGB_332, 347 D3D_AL_44, 348 D3D_LVU_655, 349 D3D_XLVU_8888, 350 D3D_QWVU_8888, 351 352 //10 bit integer - 2 bit alpha 353 D3D_ABGR_2101010, 354 D3D_ARGB_2101010, 355 D3D_AWVU_2101010, 356 357 //16 bit integers 358 D3D_GR_1616, 359 D3D_VU_1616, 360 D3D_ABGR_16161616, 361 362 //Float Formats 363 D3D_R16F, 364 D3D_GR_1616F, 365 D3D_ABGR_16161616F, 366 367 //32 bits per channel 368 D3D_R32F, 369 D3D_GR_3232F, 370 D3D_ABGR_32323232F, 371 372 // Ericsson 373 ETC_RGB_4BPP, 374 ETC_RGBA_EXPLICIT, ///< Unimplemented 375 ETC_RGBA_INTERPOLATED, ///< Unimplemented 376 377 D3D_A8 = 0x40, 378 D3D_V8U8, 379 D3D_L16, 380 381 D3D_L8, 382 D3D_AL_88, 383 384 //Y'UV Colourspace 385 D3D_UYVY, 386 D3D_YUY2, 387 388 // DX10 389 DX10_R32G32B32A32_FLOAT= 0x50, 390 DX10_R32G32B32A32_UINT , 391 DX10_R32G32B32A32_SINT, 392 393 DX10_R32G32B32_FLOAT, 394 DX10_R32G32B32_UINT, 395 DX10_R32G32B32_SINT, 396 397 DX10_R16G16B16A16_FLOAT , 398 DX10_R16G16B16A16_UNORM, 399 DX10_R16G16B16A16_UINT , 400 DX10_R16G16B16A16_SNORM , 401 DX10_R16G16B16A16_SINT , 402 403 DX10_R32G32_FLOAT , 404 DX10_R32G32_UINT , 405 DX10_R32G32_SINT , 406 407 DX10_R10G10B10A2_UNORM , 408 DX10_R10G10B10A2_UINT , 409 410 DX10_R11G11B10_FLOAT , ///< Unimplemented 411 412 DX10_R8G8B8A8_UNORM , 413 DX10_R8G8B8A8_UNORM_SRGB , 414 DX10_R8G8B8A8_UINT , 415 DX10_R8G8B8A8_SNORM , 416 DX10_R8G8B8A8_SINT , 417 418 DX10_R16G16_FLOAT , 419 DX10_R16G16_UNORM , 420 DX10_R16G16_UINT , 421 DX10_R16G16_SNORM , 422 DX10_R16G16_SINT , 423 424 DX10_R32_FLOAT , 425 DX10_R32_UINT , 426 DX10_R32_SINT , 427 428 DX10_R8G8_UNORM , 429 DX10_R8G8_UINT , 430 DX10_R8G8_SNORM , 431 DX10_R8G8_SINT , 432 433 DX10_R16_FLOAT , 434 DX10_R16_UNORM , 435 DX10_R16_UINT , 436 DX10_R16_SNORM , 437 DX10_R16_SINT , 438 439 DX10_R8_UNORM, 440 DX10_R8_UINT, 441 DX10_R8_SNORM, 442 DX10_R8_SINT, 443 444 DX10_A8_UNORM, 445 DX10_R1_UNORM, 446 DX10_R9G9B9E5_SHAREDEXP, ///< Unimplemented 447 DX10_R8G8_B8G8_UNORM, ///< Unimplemented 448 DX10_G8R8_G8B8_UNORM, ///< Unimplemented 449 450 DX10_BC1_UNORM, 451 DX10_BC1_UNORM_SRGB, 452 453 DX10_BC2_UNORM, 454 DX10_BC2_UNORM_SRGB, 455 456 DX10_BC3_UNORM, 457 DX10_BC3_UNORM_SRGB, 458 459 DX10_BC4_UNORM, ///< Unimplemented 460 DX10_BC4_SNORM, ///< Unimplemented 461 462 DX10_BC5_UNORM, ///< Unimplemented 463 DX10_BC5_SNORM, ///< Unimplemented 464 465 // OpenVG 466 467 /* RGB{A,X} channel ordering */ 468 ePT_VG_sRGBX_8888 = 0x90, 469 ePT_VG_sRGBA_8888, 470 ePT_VG_sRGBA_8888_PRE, 471 ePT_VG_sRGB_565, 472 ePT_VG_sRGBA_5551, 473 ePT_VG_sRGBA_4444, 474 ePT_VG_sL_8, 475 ePT_VG_lRGBX_8888, 476 ePT_VG_lRGBA_8888, 477 ePT_VG_lRGBA_8888_PRE, 478 ePT_VG_lL_8, 479 ePT_VG_A_8, 480 ePT_VG_BW_1, 481 482 /* {A,X}RGB channel ordering */ 483 ePT_VG_sXRGB_8888, 484 ePT_VG_sARGB_8888, 485 ePT_VG_sARGB_8888_PRE, 486 ePT_VG_sARGB_1555, 487 ePT_VG_sARGB_4444, 488 ePT_VG_lXRGB_8888, 489 ePT_VG_lARGB_8888, 490 ePT_VG_lARGB_8888_PRE, 491 492 /* BGR{A,X} channel ordering */ 493 ePT_VG_sBGRX_8888, 494 ePT_VG_sBGRA_8888, 495 ePT_VG_sBGRA_8888_PRE, 496 ePT_VG_sBGR_565, 497 ePT_VG_sBGRA_5551, 498 ePT_VG_sBGRA_4444, 499 ePT_VG_lBGRX_8888, 500 ePT_VG_lBGRA_8888, 501 ePT_VG_lBGRA_8888_PRE, 502 503 /* {A,X}BGR channel ordering */ 504 ePT_VG_sXBGR_8888, 505 ePT_VG_sABGR_8888 , 506 ePT_VG_sABGR_8888_PRE, 507 ePT_VG_sABGR_1555, 508 ePT_VG_sABGR_4444, 509 ePT_VG_lXBGR_8888, 510 ePT_VG_lABGR_8888, 511 ePT_VG_lABGR_8888_PRE, 512 513 // max cap for iterating 514 END_OF_PIXEL_TYPES, 515 516 MGLPT_NOTYPE = 0xffffffff 517 518 }; 519 520 /***************************************************************************** 521 * Legacy constants (V1/V2) 522 *****************************************************************************/ 523 524 const PVRTuint32 PVRTEX_MIPMAP = (1<<8); ///< Has mip map levels. DEPRECATED. 525 const PVRTuint32 PVRTEX_TWIDDLE = (1<<9); ///< Is twiddled. DEPRECATED. 526 const PVRTuint32 PVRTEX_BUMPMAP = (1<<10); ///< Has normals encoded for a bump map. DEPRECATED. 527 const PVRTuint32 PVRTEX_TILING = (1<<11); ///< Is bordered for tiled pvr. DEPRECATED. 528 const PVRTuint32 PVRTEX_CUBEMAP = (1<<12); ///< Is a cubemap/skybox. DEPRECATED. 529 const PVRTuint32 PVRTEX_FALSEMIPCOL = (1<<13); ///< Are there false coloured MIP levels. DEPRECATED. 530 const PVRTuint32 PVRTEX_VOLUME = (1<<14); ///< Is this a volume texture. DEPRECATED. 531 const PVRTuint32 PVRTEX_ALPHA = (1<<15); ///< v2.1. Is there transparency info in the texture. DEPRECATED. 532 const PVRTuint32 PVRTEX_VERTICAL_FLIP = (1<<16); ///< v2.1. Is the texture vertically flipped. DEPRECATED. 533 534 const PVRTuint32 PVRTEX_PIXELTYPE = 0xff; ///< Pixel type is always in the last 16bits of the flags. DEPRECATED. 535 const PVRTuint32 PVRTEX_IDENTIFIER = 0x21525650; ///< The pvr identifier is the characters 'P','V','R'. DEPRECATED. 536 537 const PVRTuint32 PVRTEX_V1_HEADER_SIZE = 44; ///< Old header size was 44 for identification purposes. DEPRECATED. 538 539 const PVRTuint32 PVRTC2_MIN_TEXWIDTH = 16; ///< DEPRECATED. 540 const PVRTuint32 PVRTC2_MIN_TEXHEIGHT = 8; ///< DEPRECATED. 541 const PVRTuint32 PVRTC4_MIN_TEXWIDTH = 8; ///< DEPRECATED. 542 const PVRTuint32 PVRTC4_MIN_TEXHEIGHT = 8; ///< DEPRECATED. 543 const PVRTuint32 ETC_MIN_TEXWIDTH = 4; ///< DEPRECATED. 544 const PVRTuint32 ETC_MIN_TEXHEIGHT = 4; ///< DEPRECATED. 545 const PVRTuint32 DXT_MIN_TEXWIDTH = 4; ///< DEPRECATED. 546 const PVRTuint32 DXT_MIN_TEXHEIGHT = 4; ///< DEPRECATED. 547 548 /**************************************************************************** 549 ** Functions 550 ****************************************************************************/ 551 552 /*!*************************************************************************** 553 @fn PVRTTextureCreate 554 @param[in] w Size of the texture 555 @param[in] h Size of the texture 556 @param[in] wMin Minimum size of a texture level 557 @param[in] hMin Minimum size of a texture level 558 @param[in] nBPP Bits per pixel of the format 559 @param[in] bMIPMap Create memory for MIP-map levels also? 560 @return Allocated texture memory (must be free()d) 561 @brief Creates a PVRTextureHeaderV3 structure, including room for 562 the specified texture, in memory. 563 *****************************************************************************/ 564 PVRTextureHeaderV3 *PVRTTextureCreate( 565 unsigned int w, 566 unsigned int h, 567 const unsigned int wMin, 568 const unsigned int hMin, 569 const unsigned int nBPP, 570 const bool bMIPMap); 571 572 /*!*************************************************************************** 573 @fn PVRTTextureTile 574 @param[in,out] pOut The tiled texture in system memory 575 @param[in] pIn The source texture 576 @param[in] nRepeatCnt Number of times to repeat the source texture 577 @brief Allocates and fills, in system memory, a texture large enough 578 to repeat the source texture specified number of times. 579 *****************************************************************************/ 580 void PVRTTextureTile( 581 PVRTextureHeaderV3 **pOut, 582 const PVRTextureHeaderV3 * const pIn, 583 const int nRepeatCnt); 584 585 /**************************************************************************** 586 ** Internal Functions 587 ****************************************************************************/ 588 //Preprocessor definitions to generate a pixelID for use when consts are needed. For example - switch statements. These should be evaluated by the compiler rather than at run time - assuming that arguments are all constant. 589 590 //Generate a 4 channel PixelID. 591 #define PVRTGENPIXELID4(C1Name, C2Name, C3Name, C4Name, C1Bits, C2Bits, C3Bits, C4Bits) ( ( (PVRTuint64)C1Name) + ( (PVRTuint64)C2Name<<8) + ( (PVRTuint64)C3Name<<16) + ( (PVRTuint64)C4Name<<24) + ( (PVRTuint64)C1Bits<<32) + ( (PVRTuint64)C2Bits<<40) + ( (PVRTuint64)C3Bits<<48) + ( (PVRTuint64)C4Bits<<56) ) 592 593 //Generate a 1 channel PixelID. 594 #define PVRTGENPIXELID3(C1Name, C2Name, C3Name, C1Bits, C2Bits, C3Bits)( PVRTGENPIXELID4(C1Name, C2Name, C3Name, 0, C1Bits, C2Bits, C3Bits, 0) ) 595 596 //Generate a 2 channel PixelID. 597 #define PVRTGENPIXELID2(C1Name, C2Name, C1Bits, C2Bits) ( PVRTGENPIXELID4(C1Name, C2Name, 0, 0, C1Bits, C2Bits, 0, 0) ) 598 599 //Generate a 3 channel PixelID. 600 #define PVRTGENPIXELID1(C1Name, C1Bits) ( PVRTGENPIXELID4(C1Name, 0, 0, 0, C1Bits, 0, 0, 0)) 601 602 //Forward declaration of CPVRTMap. 603 template <typename KeyType, typename DataType> 604 class CPVRTMap; 605 606 607 /*!*********************************************************************** 608 @fn PVRTGetBitsPerPixel 609 @param[in] u64PixelFormat A PVR Pixel Format ID. 610 @return const PVRTuint32 Number of bits per pixel. 611 @brief Returns the number of bits per pixel in a PVR Pixel Format 612 identifier. 613 *************************************************************************/ 614 PVRTuint32 PVRTGetBitsPerPixel(PVRTuint64 u64PixelFormat); 615 616 /*!*********************************************************************** 617 @fn PVRTGetFormatMinDims 618 @param[in] u64PixelFormat A PVR Pixel Format ID. 619 @param[in,out] minX Returns the minimum width. 620 @param[in,out] minY Returns the minimum height. 621 @param[in,out] minZ Returns the minimum depth. 622 @brief Gets the minimum dimensions (x,y,z) for a given pixel format. 623 *************************************************************************/ 624 void PVRTGetFormatMinDims(PVRTuint64 u64PixelFormat, PVRTuint32 &minX, PVRTuint32 &minY, PVRTuint32 &minZ); 625 626 /*!*********************************************************************** 627 @fn PVRTConvertOldTextureHeaderToV3 628 @param[in] LegacyHeader Legacy header for conversion. 629 @param[in,out] NewHeader New header to output into. 630 @param[in,out] pMetaData MetaData Map to output into. 631 @brief Converts a legacy texture header (V1 or V2) to a current 632 generation header (V3) 633 *************************************************************************/ 634 void PVRTConvertOldTextureHeaderToV3(const PVR_Texture_Header* LegacyHeader, PVRTextureHeaderV3& NewHeader, CPVRTMap<PVRTuint32, CPVRTMap<PVRTuint32,MetaDataBlock> >* pMetaData); 635 636 /*!*********************************************************************** 637 @fn PVRTMapLegacyTextureEnumToNewFormat 638 @param[in] OldFormat Legacy Enumeration Value 639 @param[in,out] newType New PixelType identifier. 640 @param[in,out] newCSpace New ColourSpace 641 @param[in,out] newChanType New Channel Type 642 @param[in,out] isPreMult Whether format is pre-multiplied 643 @brief Maps a legacy enumeration value to the new PVR3 style format. 644 *************************************************************************/ 645 void PVRTMapLegacyTextureEnumToNewFormat(PVRTPixelType OldFormat, PVRTuint64& newType, EPVRTColourSpace& newCSpace, EPVRTVariableType& newChanType, bool& isPreMult); 646 647 /*!*************************************************************************** 648 @fn PVRTTextureLoadTiled 649 @param[in,out] pDst Texture to place the tiled data 650 @param[in] nWidthDst Width of destination texture 651 @param[in] nHeightDst Height of destination texture 652 @param[in] pSrc Texture to tile 653 @param[in] nWidthSrc Width of source texture 654 @param[in] nHeightSrc Height of source texture 655 @param[in] nElementSize Bytes per pixel 656 @param[in] bTwiddled True if the data is twiddled 657 @brief Needed by PVRTTextureTile() in the various PVRTTextureAPIs 658 *****************************************************************************/ 659 void PVRTTextureLoadTiled( 660 PVRTuint8 * const pDst, 661 const unsigned int nWidthDst, 662 const unsigned int nHeightDst, 663 const PVRTuint8 * const pSrc, 664 const unsigned int nWidthSrc, 665 const unsigned int nHeightSrc, 666 const unsigned int nElementSize, 667 const bool bTwiddled); 668 669 670 /*!*************************************************************************** 671 @fn PVRTTextureTwiddle 672 @param[out] a Twiddled value 673 @param[in] u Coordinate axis 0 674 @param[in] v Coordinate axis 1 675 @brief Combine a 2D coordinate into a twiddled value 676 *****************************************************************************/ 677 void PVRTTextureTwiddle(unsigned int &a, const unsigned int u, const unsigned int v); 678 679 /*!*************************************************************************** 680 @fn PVRTTextureDeTwiddle 681 @param[out] u Coordinate axis 0 682 @param[out] v Coordinate axis 1 683 @param[in] a Twiddled value 684 @brief Extract 2D coordinates from a twiddled value. 685 *****************************************************************************/ 686 void PVRTTextureDeTwiddle(unsigned int &u, unsigned int &v, const unsigned int a); 687 688 /*!*********************************************************************** 689 @fn PVRTGetTextureDataSize 690 @param[in] sTextureHeader Specifies the texture header. 691 @param[in] iMipLevel Specifies a mip level to check, 'PVRTEX_ALLMIPLEVELS' 692 can be passed to get the size of all MIP levels. 693 @param[in] bAllSurfaces Size of all surfaces is calculated if true, 694 only a single surface if false. 695 @param[in] bAllFaces Size of all faces is calculated if true, 696 only a single face if false. 697 @return PVRTuint32 Size in BYTES of the specified texture area. 698 @brief Gets the size in BYTES of the texture, given various input 699 parameters. User can retrieve the size of either all 700 surfaces or a single surface, all faces or a single face and 701 all MIP-Maps or a single specified MIP level. 702 *************************************************************************/ 703 PVRTuint32 PVRTGetTextureDataSize(PVRTextureHeaderV3 sTextureHeader, PVRTint32 iMipLevel=PVRTEX_ALLMIPLEVELS, bool bAllSurfaces = true, bool bAllFaces = true); 704 705 #endif /* _PVRTTEXTURE_H_ */ 706 707 /***************************************************************************** 708 End of file (PVRTTexture.h) 709 *****************************************************************************/ 710 711