Counter Strike : Global Offensive Source Code
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.

117 lines
3.0 KiB

  1. //========= Copyright c 1996-2011, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //====================================================================================//
  7. #ifndef __VTFCOMBINE_H
  8. #define __VTFCOMBINE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "mdlcombine.h"
  13. class KeyValues;
  14. struct VTFFileHeader_t;
  15. struct ResourceEntryInfo;
  16. class CSimpleTexturePacker;
  17. //#define DEBUG_VTF_COMBINE 1
  18. #define MAX_COMBINED_MIP_LEVELS 11
  19. #define MAX_COMBINED_WIDTH 1024
  20. #define MAX_COMBINED_HEIGHT 1024
  21. #define MAX_COMBINED_TEXTURE_MEMORY ( ( 1024 + ( ( MAX_COMBINED_WIDTH >> 2 ) * ( MAX_COMBINED_HEIGHT >> 2 ) * 16 * 2 ) ) )
  22. #define ATLAS_INFO_GROUP_INDEX 0
  23. #define ATLAS_INFO_MATERIAL_INDEX 1
  24. #define ATLAS_INFO_COUNT (ATLAS_INFO_MATERIAL_INDEX + 1)
  25. enum
  26. {
  27. COMBINED_MATERIAL_FLAG_NOCULL = 0x00000001,
  28. };
  29. struct AtlasGroupData
  30. {
  31. int m_nNumMaterials;
  32. int m_nMaterialIndices[ COMBINER_MAX_MATERIALS ];
  33. CUtlBuffer *m_pVTFData[ COMBINER_MAX_MATERIALS ];
  34. VTFFileHeader_t *m_pVTFFileHeader[ COMBINER_MAX_MATERIALS ];
  35. ResourceEntryInfo *m_pResources[ COMBINER_MAX_MATERIALS ];
  36. bool m_bIsFlat[ COMBINER_MAX_MATERIALS ];
  37. KeyValues *m_pCombinedMaterialKVs;
  38. byte m_CombinedTextureMemory[ COMBINER_MAX_TEXTURES_PER_MATERIAL ][ MAX_COMBINED_TEXTURE_MEMORY ];
  39. int m_nCombinedTextureSize[ COMBINER_MAX_TEXTURES_PER_MATERIAL ];
  40. VTFFileHeader_t *m_CombinedHeaders[ COMBINER_MAX_TEXTURES_PER_MATERIAL ];
  41. CSimpleTexturePacker *m_pSimpleTexturePacker;
  42. };
  43. class CTextureCombine
  44. {
  45. public:
  46. CTextureCombine( );
  47. void Init( TCombinedStudioData *pCombinedStudioData );
  48. void Cleanup( );
  49. int AddMaterial( const char *pszFileName );
  50. void Resolve( );
  51. void GetTextureInfo( int nIndex, Vector2D &vStartST, Vector2D &vSizeST, Vector2D &vPixelSize );
  52. void FreeCombinedMaterials( );
  53. int GetAtlasGroupIndex( int nIndex ) const
  54. {
  55. Assert( nIndex < COMBINER_MAX_MATERIALS );
  56. return m_nMaterialAtlasInfo[ nIndex ][ ATLAS_INFO_GROUP_INDEX ];
  57. }
  58. int GetAtlasGroupMaterialIndex( int nIndex ) const
  59. {
  60. Assert( nIndex < COMBINER_MAX_MATERIALS );
  61. return m_nMaterialAtlasInfo[ nIndex ][ ATLAS_INFO_MATERIAL_INDEX ];
  62. }
  63. private:
  64. TCombinedStudioData *m_pCombinedStudioData;
  65. int m_nNumMaterials;
  66. char m_szMaterials[ COMBINER_MAX_MATERIALS ][ MAX_PATH ];
  67. int m_nMaterialAtlasInfo[ COMBINER_MAX_MATERIALS ][ ATLAS_INFO_COUNT ];
  68. int m_nMaxAtlasGroup;
  69. AtlasGroupData m_AtlasGroups[ COMBINER_MAX_ATLAS_GROUPS ];
  70. KeyValues *m_pMaterialKVs[ COMBINER_MAX_MATERIALS ];
  71. int m_nMaterialToTexture;
  72. void GatherAtlasInfo( );
  73. void FindMaterialToTexture( );
  74. void AddNonAtlasedMaterial( int nMaterial );
  75. bool LoadVTFs( int nAtlasGroup, const char *pszTextureField, const char *pszFlatReplacement, char szTextureNames[ COMBINER_MAX_MATERIALS ][ MAX_PATH ] );
  76. bool CombineTexture( int nAtlasGroup, int nTexture, const char *pszTextureField, const char *pszFlatReplacement );
  77. friend class CSimpleTexturePacker;
  78. };
  79. extern CTextureCombine& GetTextureCombiner();
  80. #endif // __VTFCOMBINE_H