Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

632 lines
23 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef VTF_H
  8. #define VTF_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "bitmap/imageformat.h"
  13. #include "tier0/platform.h"
  14. // #define VTF_FILE_FORMAT_ONLY to just include the vtf header and none of the code declaration
  15. #ifndef VTF_FILE_FORMAT_ONLY
  16. //-----------------------------------------------------------------------------
  17. // Forward declarations
  18. //-----------------------------------------------------------------------------
  19. class CUtlBuffer;
  20. class Vector;
  21. struct Rect_t;
  22. class IFileSystem;
  23. //-----------------------------------------------------------------------------
  24. // Texture flags
  25. //-----------------------------------------------------------------------------
  26. enum CompiledVtfFlags
  27. {
  28. // flags from the *.txt config file
  29. TEXTUREFLAGS_POINTSAMPLE = 0x00000001,
  30. TEXTUREFLAGS_TRILINEAR = 0x00000002,
  31. TEXTUREFLAGS_CLAMPS = 0x00000004,
  32. TEXTUREFLAGS_CLAMPT = 0x00000008,
  33. TEXTUREFLAGS_ANISOTROPIC = 0x00000010,
  34. TEXTUREFLAGS_HINT_DXT5 = 0x00000020,
  35. TEXTUREFLAGS_SRGB = 0x00000040,
  36. TEXTUREFLAGS_NORMAL = 0x00000080,
  37. TEXTUREFLAGS_NOMIP = 0x00000100,
  38. TEXTUREFLAGS_NOLOD = 0x00000200,
  39. TEXTUREFLAGS_ALL_MIPS = 0x00000400,
  40. TEXTUREFLAGS_PROCEDURAL = 0x00000800,
  41. // These are automatically generated by vtex from the texture data.
  42. TEXTUREFLAGS_ONEBITALPHA = 0x00001000,
  43. TEXTUREFLAGS_EIGHTBITALPHA = 0x00002000,
  44. // newer flags from the *.txt config file
  45. TEXTUREFLAGS_ENVMAP = 0x00004000,
  46. TEXTUREFLAGS_RENDERTARGET = 0x00008000,
  47. TEXTUREFLAGS_DEPTHRENDERTARGET = 0x00010000,
  48. TEXTUREFLAGS_NODEBUGOVERRIDE = 0x00020000,
  49. TEXTUREFLAGS_SINGLECOPY = 0x00040000,
  50. TEXTUREFLAGS_STAGING_MEMORY = 0x00080000,
  51. TEXTUREFLAGS_IMMEDIATE_CLEANUP = 0x00100000,
  52. TEXTUREFLAGS_IGNORE_PICMIP = 0x00200000,
  53. TEXTUREFLAGS_UNUSED_00400000 = 0x00400000,
  54. TEXTUREFLAGS_NODEPTHBUFFER = 0x00800000,
  55. TEXTUREFLAGS_UNUSED_01000000 = 0x01000000,
  56. TEXTUREFLAGS_CLAMPU = 0x02000000,
  57. TEXTUREFLAGS_VERTEXTEXTURE = 0x04000000, // Useable as a vertex texture
  58. TEXTUREFLAGS_SSBUMP = 0x08000000,
  59. TEXTUREFLAGS_UNUSED_10000000 = 0x10000000,
  60. // Clamp to border color on all texture coordinates
  61. TEXTUREFLAGS_BORDER = 0x20000000,
  62. TEXTUREFLAGS_STREAMABLE_COARSE = 0x40000000,
  63. TEXTUREFLAGS_STREAMABLE_FINE = 0x80000000,
  64. TEXTUREFLAGS_STREAMABLE = ( TEXTUREFLAGS_STREAMABLE_COARSE | TEXTUREFLAGS_STREAMABLE_FINE )
  65. };
  66. enum VersionedVtfFlags
  67. {
  68. VERSIONED_VTF_FLAGS_MASK_7_3 = ~0xD1780400, // For a ver 7.3 or earlier only these flags are valid
  69. };
  70. struct VtfProcessingOptions
  71. {
  72. uint32 cbSize; // Set to sizeof( VtfProcessingOptions )
  73. //
  74. // Flags0
  75. //
  76. enum Flags0
  77. {
  78. // Have a channel decaying to a given decay goal for the given last number of mips
  79. OPT_DECAY_R = 0x00000001, // Red decays
  80. OPT_DECAY_G = 0x00000002, // Green decays
  81. OPT_DECAY_B = 0x00000004, // Blue decays
  82. OPT_DECAY_A = 0x00000008, // Alpha decays
  83. OPT_DECAY_EXP_R = 0x00000010, // Channel R decays exponentially (otherwise linearly)
  84. OPT_DECAY_EXP_G = 0x00000020, // Channel G decays exponentially (otherwise linearly)
  85. OPT_DECAY_EXP_B = 0x00000040, // Channel B decays exponentially (otherwise linearly)
  86. OPT_DECAY_EXP_A = 0x00000080, // Channel A decays exponentially (otherwise linearly)
  87. OPT_NOCOMPRESS = 0x00000100, // Use uncompressed image format
  88. OPT_NORMAL_DUDV = 0x00000200, // dU dV normal map
  89. OPT_FILTER_NICE = 0x00000400, // Use nice filtering
  90. OPT_SET_ALPHA_ONEOVERMIP = 0x00001000, // Alpha = 1/miplevel
  91. OPT_PREMULT_COLOR_ONEOVERMIP = 0x00002000, // Color *= 1/miplevel
  92. OPT_MIP_ALPHATEST = 0x00004000, // Alpha-tested mip generation
  93. };
  94. uint32 flags0; // A combination of "Flags0"
  95. //
  96. // Decay settings
  97. //
  98. uint8 clrDecayGoal[4]; // Goal colors for R G B A
  99. uint8 numNotDecayMips[4]; // Number of first mips unaffected by decay (0 means all below mip0)
  100. float fDecayExponentBase[4]; // For exponential decay the base number (e.g. 0.75)
  101. };
  102. //-----------------------------------------------------------------------------
  103. // Cubemap face indices
  104. //-----------------------------------------------------------------------------
  105. enum CubeMapFaceIndex_t
  106. {
  107. CUBEMAP_FACE_RIGHT = 0,
  108. CUBEMAP_FACE_LEFT,
  109. CUBEMAP_FACE_BACK, // NOTE: This face is in the +y direction?!?!?
  110. CUBEMAP_FACE_FRONT, // NOTE: This face is in the -y direction!?!?
  111. CUBEMAP_FACE_UP,
  112. CUBEMAP_FACE_DOWN,
  113. // This is the fallback for low-end
  114. CUBEMAP_FACE_SPHEREMAP,
  115. // NOTE: Cubemaps have *7* faces; the 7th is the fallback spheremap
  116. CUBEMAP_FACE_COUNT
  117. };
  118. //-----------------------------------------------------------------------------
  119. // Enumeration used for spheremap generation
  120. //-----------------------------------------------------------------------------
  121. enum LookDir_t
  122. {
  123. LOOK_DOWN_X = 0,
  124. LOOK_DOWN_NEGX,
  125. LOOK_DOWN_Y,
  126. LOOK_DOWN_NEGY,
  127. LOOK_DOWN_Z,
  128. LOOK_DOWN_NEGZ,
  129. };
  130. //-----------------------------------------------------------------------------
  131. // What mipmap (and coarser) is always available when we ship
  132. //-----------------------------------------------------------------------------
  133. #define STREAMING_START_MIPMAP 3
  134. //-----------------------------------------------------------------------------
  135. // Use this image format if you want to perform tool operations on the texture
  136. //-----------------------------------------------------------------------------
  137. #define IMAGE_FORMAT_DEFAULT ((ImageFormat)-2)
  138. //-----------------------------------------------------------------------------
  139. // Interface to get at various bits of a VTF texture
  140. //-----------------------------------------------------------------------------
  141. class IVTFTexture
  142. {
  143. public:
  144. virtual ~IVTFTexture() {}
  145. // Initializes the texture and allocates space for the bits
  146. // In most cases, you shouldn't force the mip count.
  147. virtual bool Init( int nWidth, int nHeight, int nDepth, ImageFormat fmt, int nFlags, int iFrameCount, int nForceMipCount = -1 ) = 0;
  148. // Methods to set other texture fields
  149. virtual void SetBumpScale( float flScale ) = 0;
  150. virtual void SetReflectivity( const Vector &vecReflectivity ) = 0;
  151. // Methods to initialize the low-res image
  152. virtual void InitLowResImage( int nWidth, int nHeight, ImageFormat fmt ) = 0;
  153. // set the resource data (for writers). pass size=0 to delete data. if pdata is not null,
  154. // the resource data will be copied from *pData
  155. virtual void *SetResourceData( uint32 eType, void const *pData, size_t nDataSize ) = 0;
  156. // find the resource data and return a pointer to it. The data pointed to by this pointer will
  157. // go away when the ivtftexture does. retruns null if resource not present
  158. virtual void *GetResourceData( uint32 eType, size_t *pDataSize ) const = 0;
  159. // Locates the resource entry info if it's present, easier than crawling array types
  160. virtual bool HasResourceEntry( uint32 eType ) const = 0;
  161. // Retrieve available resource types of this IVTFTextures
  162. // arrTypesBuffer buffer to be filled with resource types available.
  163. // numTypesBufferElems how many resource types the buffer can accomodate.
  164. // Returns:
  165. // number of resource types available (can be greater than "numTypesBufferElems"
  166. // in which case only first "numTypesBufferElems" are copied to "arrTypesBuffer")
  167. virtual unsigned int GetResourceTypes( uint32 *arrTypesBuffer, int numTypesBufferElems ) const = 0;
  168. // When unserializing, we can skip a certain number of mip levels,
  169. // and we also can just load everything but the image data
  170. // NOTE: If you load only the buffer header, you'll need to use the
  171. // VTFBufferHeaderSize() method below to only read that much from the file
  172. // NOTE: If you skip mip levels, the height + width of the texture will
  173. // change to reflect the size of the largest read in mip level
  174. virtual bool Unserialize( CUtlBuffer &buf, bool bHeaderOnly = false, int nSkipMipLevels = 0 ) = 0;
  175. virtual bool Serialize( CUtlBuffer &buf ) = 0;
  176. // These are methods to help with optimization:
  177. // Once the header is read in, they indicate where to start reading
  178. // other data (measured from file start), and how many bytes to read....
  179. virtual void LowResFileInfo( int *pStartLocation, int *pSizeInBytes) const = 0;
  180. virtual void ImageFileInfo( int nFrame, int nFace, int nMip, int *pStartLocation, int *pSizeInBytes) const = 0;
  181. virtual int FileSize( int nMipSkipCount = 0 ) const = 0;
  182. // Attributes...
  183. virtual int Width() const = 0;
  184. virtual int Height() const = 0;
  185. virtual int Depth() const = 0;
  186. virtual int MipCount() const = 0;
  187. // returns the size of one row of a particular mip level
  188. virtual int RowSizeInBytes( int nMipLevel ) const = 0;
  189. // returns the size of one face of a particular mip level
  190. virtual int FaceSizeInBytes( int nMipLevel ) const = 0;
  191. virtual ImageFormat Format() const = 0;
  192. virtual int FaceCount() const = 0;
  193. virtual int FrameCount() const = 0;
  194. virtual int Flags() const = 0;
  195. virtual float BumpScale() const = 0;
  196. virtual int LowResWidth() const = 0;
  197. virtual int LowResHeight() const = 0;
  198. virtual ImageFormat LowResFormat() const = 0;
  199. // NOTE: reflectivity[0] = blue, [1] = greem, [2] = red
  200. virtual const Vector &Reflectivity() const = 0;
  201. virtual bool IsCubeMap() const = 0;
  202. virtual bool IsNormalMap() const = 0;
  203. virtual bool IsVolumeTexture() const = 0;
  204. // Computes the dimensions of a particular mip level
  205. virtual void ComputeMipLevelDimensions( int iMipLevel, int *pMipWidth, int *pMipHeight, int *pMipDepth ) const = 0;
  206. // Computes the size (in bytes) of a single mipmap of a single face of a single frame
  207. virtual int ComputeMipSize( int iMipLevel ) const = 0;
  208. // Computes the size of a subrect (specified at the top mip level) at a particular lower mip level
  209. virtual void ComputeMipLevelSubRect( Rect_t* pSrcRect, int nMipLevel, Rect_t *pSubRect ) const = 0;
  210. // Computes the size (in bytes) of a single face of a single frame
  211. // All mip levels starting at the specified mip level are included
  212. virtual int ComputeFaceSize( int iStartingMipLevel = 0 ) const = 0;
  213. // Computes the total size (in bytes) of all faces, all frames
  214. virtual int ComputeTotalSize() const = 0;
  215. // Returns the base address of the image data
  216. virtual unsigned char *ImageData() = 0;
  217. // Returns a pointer to the data associated with a particular frame, face, and mip level
  218. virtual unsigned char *ImageData( int iFrame, int iFace, int iMipLevel ) = 0;
  219. // Returns a pointer to the data associated with a particular frame, face, mip level, and offset
  220. virtual unsigned char *ImageData( int iFrame, int iFace, int iMipLevel, int x, int y, int z = 0 ) = 0;
  221. // Returns the base address of the low-res image data
  222. virtual unsigned char *LowResImageData() = 0;
  223. // Converts the textures image format. Use IMAGE_FORMAT_DEFAULT
  224. // if you want to be able to use various tool functions below
  225. virtual void ConvertImageFormat( ImageFormat fmt, bool bNormalToDUDV ) = 0;
  226. // NOTE: The following methods only work on textures using the
  227. // IMAGE_FORMAT_DEFAULT!
  228. // Generate spheremap based on the current cube faces (only works for cubemaps)
  229. // The look dir indicates the direction of the center of the sphere
  230. // NOTE: Only call this *after* cube faces have been correctly
  231. // oriented (using FixCubemapFaceOrientation)
  232. virtual void GenerateSpheremap( LookDir_t lookDir = LOOK_DOWN_Z ) = 0;
  233. // Generate spheremap based on the current cube faces (only works for cubemaps)
  234. // The look dir indicates the direction of the center of the sphere
  235. // NOTE: Only call this *after* cube faces have been correctly
  236. // oriented (using FixCubemapFaceOrientation)
  237. virtual void GenerateHemisphereMap( unsigned char *pSphereMapBitsRGBA, int targetWidth,
  238. int targetHeight, LookDir_t lookDir, int iFrame ) = 0;
  239. // Fixes the cubemap faces orientation from our standard to the
  240. // standard the material system needs.
  241. virtual void FixCubemapFaceOrientation( ) = 0;
  242. // Generates mipmaps from the base mip levels
  243. virtual void GenerateMipmaps() = 0;
  244. // Put 1/miplevel (1..n) into alpha.
  245. virtual void PutOneOverMipLevelInAlpha() = 0;
  246. // Computes the reflectivity
  247. virtual void ComputeReflectivity( ) = 0;
  248. // Computes the alpha flags
  249. virtual void ComputeAlphaFlags() = 0;
  250. // Generate the low-res image bits
  251. virtual bool ConstructLowResImage() = 0;
  252. // Gets the texture all internally consistent assuming you've loaded
  253. // mip 0 of all faces of all frames
  254. virtual void PostProcess(bool bGenerateSpheremap, LookDir_t lookDir = LOOK_DOWN_Z, bool bAllowFixCubemapOrientation = true) = 0;
  255. // Blends adjacent pixels on cubemap borders, since the card doesn't do it. If the texture
  256. // is S3TC compressed, then it has to do it AFTER the texture has been compressed to prevent
  257. // artifacts along the edges.
  258. //
  259. // If bSkybox is true, it assumes the faces are oriented in the way the engine draws the skybox
  260. // (which happens to be different from the way cubemaps have their faces).
  261. virtual void MatchCubeMapBorders( int iStage, ImageFormat finalFormat, bool bSkybox ) = 0;
  262. // Sets threshhold values for alphatest mipmapping
  263. virtual void SetAlphaTestThreshholds( float flBase, float flHighFreq ) = 0;
  264. #if defined( _X360 )
  265. virtual int UpdateOrCreate( const char *pFilename, const char *pPathID = NULL, bool bForce = false ) = 0;
  266. virtual bool UnserializeFromBuffer( CUtlBuffer &buf, bool bBufferIsVolatile, bool bHeaderOnly, bool bPreloadOnly, int nMipSkipCount ) = 0;
  267. virtual int FileSize( bool bPreloadOnly, int nMipSkipCount ) const = 0;
  268. virtual int MappingWidth() const = 0;
  269. virtual int MappingHeight() const = 0;
  270. virtual int MappingDepth() const = 0;
  271. virtual int MipSkipCount() const = 0;
  272. virtual bool IsPreTiled() const = 0;
  273. virtual unsigned char *LowResImageSample() = 0;
  274. virtual void ReleaseImageMemory() = 0;
  275. #endif
  276. // Sets post-processing flags (settings are copied, pointer passed to distinguish between structure versions)
  277. virtual void SetPostProcessingSettings( VtfProcessingOptions const *pOptions ) = 0;
  278. // Like Unserialize, but allows you to additionally specify some flags to forcibly enable.
  279. virtual bool UnserializeEx( CUtlBuffer &buf, bool bHeaderOnly = false, int nForceFlags = 0, int nSkipMipLevels = 0 ) = 0;
  280. // Data is included in [ finest, coarsest ] mips--other ranges have garbage. This is particularly useful for
  281. // streaming textures.
  282. virtual void GetMipmapRange( int* pOutFinest, int* pOutCoarsest ) = 0;
  283. };
  284. //-----------------------------------------------------------------------------
  285. // Class factory
  286. //-----------------------------------------------------------------------------
  287. IVTFTexture *CreateVTFTexture();
  288. void DestroyVTFTexture( IVTFTexture *pTexture );
  289. //-----------------------------------------------------------------------------
  290. // Allows us to only load in the first little bit of the VTF file to get info
  291. // Clients should read this much into a UtlBuffer and then pass it in to
  292. // Unserialize
  293. //-----------------------------------------------------------------------------
  294. int VTFFileHeaderSize( int nMajorVersion = -1, int nMinorVersion = -1 );
  295. //-----------------------------------------------------------------------------
  296. // 360 Conversion
  297. //-----------------------------------------------------------------------------
  298. typedef bool (*CompressFunc_t)( CUtlBuffer &inputBuffer, CUtlBuffer &outputBuffer );
  299. bool ConvertVTFTo360Format( const char *pDebugName, CUtlBuffer &sourceBuf, CUtlBuffer &targetBuf, CompressFunc_t pCompressFunc );
  300. //-----------------------------------------------------------------------------
  301. // 360 Preload
  302. //-----------------------------------------------------------------------------
  303. bool GetVTFPreload360Data( const char *pDebugName, CUtlBuffer &fileBufferIn, CUtlBuffer &preloadBufferOut );
  304. #include "mathlib/vector.h"
  305. #endif // VTF_FILE_FORMAT_ONLY
  306. //-----------------------------------------------------------------------------
  307. // Disk format for VTF files ver. 7.2 and earlier
  308. //
  309. // NOTE: After the header is the low-res image data
  310. // Then follows image data, which is sorted in the following manner
  311. //
  312. // for each mip level (starting with 1x1, and getting larger)
  313. // for each animation frame
  314. // for each face
  315. // store the image data for the face
  316. //
  317. // NOTE: In memory, we store the data in the following manner:
  318. // for each animation frame
  319. // for each face
  320. // for each mip level (starting with the largest, and getting smaller)
  321. // store the image data for the face
  322. //
  323. // This is done because the various image manipulation function we have
  324. // expect this format
  325. //-----------------------------------------------------------------------------
  326. // Disk format for VTF files ver. 7.3
  327. //
  328. // NOTE: After the header is the array of ResourceEntryInfo structures,
  329. // number of elements in the array is defined by "numResources".
  330. // there are entries for:
  331. // eRsrcLowResImage = low-res image data
  332. // eRsrcSheet = sheet data
  333. // eRsrcImage = image data
  334. // {
  335. // for each mip level (starting with 1x1, and getting larger)
  336. // for each animation frame
  337. // for each face
  338. // store the image data for the face
  339. //
  340. // NOTE: In memory, we store the data in the following manner:
  341. // for each animation frame
  342. // for each face
  343. // for each mip level (starting with the largest, and getting smaller)
  344. // store the image data for the face
  345. // }
  346. //
  347. //-----------------------------------------------------------------------------
  348. #include "datamap.h"
  349. #pragma pack(1)
  350. // version number for the disk texture cache
  351. #define VTF_MAJOR_VERSION 7
  352. #define VTF_MINOR_VERSION 4
  353. //-----------------------------------------------------------------------------
  354. // !!!!CRITICAL!!!! BEFORE YOU CHANGE THE FORMAT
  355. //
  356. // The structure sizes ARE NOT what they appear, regardless of Pack(1).
  357. // The "VectorAligned" causes invisible padding in the FINAL derived structure.
  358. //
  359. // Each VTF format has been silently plagued by this.
  360. //
  361. // LOOK AT A 7.3 FILE. The 7.3 structure ends at 0x48 as you would expect by
  362. // counting structure bytes. But, the "Infos" start at 0x50! because the PC
  363. // compiler pads, the 360 compiler does NOT.
  364. //-----------------------------------------------------------------------------
  365. struct VTFFileBaseHeader_t
  366. {
  367. DECLARE_BYTESWAP_DATADESC();
  368. char fileTypeString[4]; // "VTF" Valve texture file
  369. int version[2]; // version[0].version[1]
  370. int headerSize;
  371. };
  372. struct VTFFileHeaderV7_1_t : public VTFFileBaseHeader_t
  373. {
  374. DECLARE_BYTESWAP_DATADESC();
  375. unsigned short width;
  376. unsigned short height;
  377. unsigned int flags;
  378. unsigned short numFrames;
  379. unsigned short startFrame;
  380. #if !defined( POSIX ) && !defined( _X360 )
  381. VectorAligned reflectivity;
  382. #else
  383. // must manually align in order to maintain pack(1) expected layout with existing binaries
  384. char pad1[4];
  385. Vector reflectivity;
  386. char pad2[4];
  387. #endif
  388. float bumpScale;
  389. ImageFormat imageFormat;
  390. unsigned char numMipLevels;
  391. ImageFormat lowResImageFormat;
  392. unsigned char lowResImageWidth;
  393. unsigned char lowResImageHeight;
  394. };
  395. struct VTFFileHeaderV7_2_t : public VTFFileHeaderV7_1_t
  396. {
  397. DECLARE_BYTESWAP_DATADESC();
  398. unsigned short depth;
  399. };
  400. #define BYTE_POS( byteVal, shft ) uint32( uint32(uint8(byteVal)) << uint8(shft * 8) )
  401. #if !defined( _X360 )
  402. #define MK_VTF_RSRC_ID(a, b, c) uint32( BYTE_POS(a, 0) | BYTE_POS(b, 1) | BYTE_POS(c, 2) )
  403. #define MK_VTF_RSRCF(d) BYTE_POS(d, 3)
  404. #else
  405. #define MK_VTF_RSRC_ID(a, b, c) uint32( BYTE_POS(a, 3) | BYTE_POS(b, 2) | BYTE_POS(c, 1) )
  406. #define MK_VTF_RSRCF(d) BYTE_POS(d, 0)
  407. #endif
  408. // Special section for stock resources types
  409. enum ResourceEntryType
  410. {
  411. // Legacy stock resources, readin/writing are handled differently (i.e. they do not have the length tag word!)
  412. VTF_LEGACY_RSRC_LOW_RES_IMAGE = MK_VTF_RSRC_ID( 0x01, 0, 0 ), // Low-res image data
  413. VTF_LEGACY_RSRC_IMAGE = MK_VTF_RSRC_ID( 0x30, 0, 0 ), // Image data
  414. // New extended resource
  415. VTF_RSRC_SHEET = MK_VTF_RSRC_ID( 0x10, 0, 0 ), // Sheet data
  416. };
  417. // Bytes with special meaning when set in a resource type
  418. enum ResourceEntryTypeFlag
  419. {
  420. RSRCF_HAS_NO_DATA_CHUNK = MK_VTF_RSRCF( 0x02 ), // Resource doesn't have a corresponding data chunk
  421. RSRCF_MASK = MK_VTF_RSRCF( 0xFF ) // Mask for all the flags
  422. };
  423. // Header details constants
  424. enum HeaderDetails
  425. {
  426. MAX_RSRC_DICTIONARY_ENTRIES = 32, // Max number of resources in dictionary
  427. MAX_X360_RSRC_DICTIONARY_ENTRIES = 4, // 360 needs this to be slim, otherwise preload size suffers
  428. };
  429. struct ResourceEntryInfo
  430. {
  431. union
  432. {
  433. unsigned int eType; // Use MK_VTF_??? macros to be endian compliant with the type
  434. unsigned char chTypeBytes[4];
  435. };
  436. unsigned int resData; // Resource data or offset from the beginning of the file
  437. };
  438. struct VTFFileHeaderV7_3_t : public VTFFileHeaderV7_2_t
  439. {
  440. DECLARE_BYTESWAP_DATADESC();
  441. char pad4[3];
  442. unsigned int numResources;
  443. #if defined( _X360 ) || defined( POSIX )
  444. // must manually align in order to maintain pack(1) expected layout with existing binaries
  445. char pad5[8];
  446. #endif
  447. // AFTER THE IMPLICIT PADDING CAUSED BY THE COMPILER....
  448. // *** followed by *** ResourceEntryInfo resources[0];
  449. // Array of resource entry infos sorted ascending by type
  450. };
  451. struct VTFFileHeader_t : public VTFFileHeaderV7_3_t
  452. {
  453. DECLARE_BYTESWAP_DATADESC();
  454. };
  455. #define VTF_X360_MAJOR_VERSION 0x0360
  456. #define VTF_X360_MINOR_VERSION 8
  457. struct VTFFileHeaderX360_t : public VTFFileBaseHeader_t
  458. {
  459. DECLARE_BYTESWAP_DATADESC();
  460. unsigned int flags;
  461. unsigned short width; // actual width of data in file
  462. unsigned short height; // actual height of data in file
  463. unsigned short depth; // actual depth of data in file
  464. unsigned short numFrames;
  465. unsigned short preloadDataSize; // exact size of preload data (may extend into image!)
  466. unsigned char mipSkipCount; // used to resconstruct mapping dimensions
  467. unsigned char numResources;
  468. Vector reflectivity; // Resides on 16 byte boundary!
  469. float bumpScale;
  470. ImageFormat imageFormat;
  471. unsigned char lowResImageSample[4];
  472. unsigned int compressedSize;
  473. // *** followed by *** ResourceEntryInfo resources[0];
  474. };
  475. ///////////////////////////
  476. // Resource Extensions //
  477. ///////////////////////////
  478. // extended texture lod control:
  479. #define VTF_RSRC_TEXTURE_LOD_SETTINGS ( MK_VTF_RSRC_ID( 'L','O','D' ) )
  480. struct TextureLODControlSettings_t
  481. {
  482. // What to clamp the dimenstions to, mip-map wise, when at picmip 0. keeps texture from
  483. // exceeding (1<<m_ResolutionClamp) at picmip 0. at picmip 1, it won't exceed
  484. // (1<<(m_ResolutionClamp-1)), etc.
  485. uint8 m_ResolutionClampX;
  486. uint8 m_ResolutionClampY;
  487. uint8 m_ResolutionClampX_360;
  488. uint8 m_ResolutionClampY_360;
  489. };
  490. // Extended flags and settings:
  491. #define VTF_RSRC_TEXTURE_SETTINGS_EX ( MK_VTF_RSRC_ID( 'T','S','0' ) )
  492. struct TextureSettingsEx_t
  493. {
  494. enum Flags0 // flags0 byte mask
  495. {
  496. UNUSED = 0x01,
  497. };
  498. uint8 m_flags0; // a bitwise combination of Flags0
  499. uint8 m_flags1; // set to zero. for future expansion.
  500. uint8 m_flags2; // set to zero. for future expansion.
  501. uint8 m_flags3; // set to zero. for future expansion.
  502. };
  503. #define VTF_RSRC_TEXTURE_CRC ( MK_VTF_RSRC_ID( 'C','R','C' ) )
  504. #define VTF_RSRC_TEXTURE_STREAM_SETTINGS ( MK_VTF_RSRC_ID( 'S', 'T', 'R' ) )
  505. struct TextureStreamSettings_t
  506. {
  507. uint8 m_firstAvailableMip;
  508. uint8 m_lastAvailableMip;
  509. uint8 m_reserved0;
  510. uint8 m_reserved1;
  511. };
  512. #pragma pack()
  513. #endif // VTF_H