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.

108 lines
3.4 KiB

  1. //========= Copyright 1996-2012, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Provide custom texture generation (compositing) for use on weapons and clothing
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef CUSTOM_MATERIAL_H
  8. #define CUSTOM_MATERIAL_H
  9. #include "materialsystem/MaterialSystemUtil.h"
  10. #include "materialsystem/icustommaterial.h"
  11. #include "materialsystem/icustommaterialmanager.h"
  12. #include "convar.h"
  13. #include "utlvector.h"
  14. #include "utlmap.h"
  15. //#define DISABLE_CUSTOM_MATERIAL_GENERATION
  16. class IVisualsDataProcessor;
  17. class IVisualsDataCompare;
  18. class ICompositeTexture;
  19. class CCompositeTexture;
  20. class KeyValues;
  21. //
  22. // Custom Materials
  23. //
  24. // This handles making a material to contain composite textures,
  25. // and it will be used during rendering of the model(s)
  26. //
  27. class CCustomMaterial : public ICustomMaterial
  28. {
  29. public:
  30. CCustomMaterial( KeyValues *pKeyValues );
  31. virtual ~CCustomMaterial();
  32. // inherited from ICustomMaterial
  33. // returns the actual end result material to be used for drawing the model
  34. virtual IMaterial *GetMaterial() { return m_Material; } // the material reference converts itself into an IMaterial
  35. virtual void AddTexture( ICompositeTexture *pTexture );
  36. virtual ICompositeTexture *GetTexture( int nIndex );
  37. virtual bool IsValid() const { return m_bValid; }
  38. virtual bool CheckRegenerate( int nSize );
  39. virtual const char* GetBaseMaterialName( void ) { return m_szBaseMaterialName; }
  40. // ----
  41. void SetBaseMaterialName( const char* szNmae );
  42. void Shutdown();
  43. void SetValid( bool bState ) { m_bValid = bState; }
  44. void Usage( int& nTextures, int& nMaterials );
  45. bool TexturesReady() const;
  46. void RegenerateTextures();
  47. bool ShouldRelease();
  48. bool Compare( const CUtlVector< SCompositeTextureInfo > &vecTextures );
  49. // actually creates the internal material that references the textures (which need to be finalized before calling this)
  50. void Finalize();
  51. private:
  52. void CreateProceduralMaterial( const char *pMaterialName, KeyValues *pKeyValues );
  53. void DestroyProceduralMaterial();
  54. CMaterialReference m_Material;
  55. CUtlVector< CCompositeTexture * > m_pTextures;
  56. bool m_bValid;
  57. int m_nModelMaterialIndex;
  58. KeyValues *m_pVMTKeyValues;
  59. const char *m_szBaseMaterialName;
  60. static int m_nMaterialCount;
  61. };
  62. class CCustomMaterialManager : public ICustomMaterialManager
  63. {
  64. public:
  65. CCustomMaterialManager();
  66. virtual ~CCustomMaterialManager();
  67. bool Init();
  68. void Shutdown();
  69. virtual bool Process();
  70. virtual ICustomMaterial *GetOrCreateCustomMaterial( KeyValues *pKeyValues, const CUtlVector< SCompositeTextureInfo > &vecTextureInfos, bool bIgnorePicMip = false );
  71. virtual int DebugGetNumActiveCustomMaterials();
  72. virtual bool GetVMTKeyValues( const char *pszVMTName, KeyValues **ppVMTKeyValues );
  73. private:
  74. CON_COMMAND_MEMBER_F( CCustomMaterialManager, "mat_reloadallcustommaterials", ReloadAllMaterials, "Reloads all custom materials", FCVAR_CHEAT | FCVAR_CLIENTDLL );
  75. CON_COMMAND_MEMBER_F( CCustomMaterialManager, "mat_custommaterialusage", Usage, "Show memory usage for custom weapon materials.", FCVAR_CLIENTDLL );
  76. CON_COMMAND_MEMBER_F( CCustomMaterialManager, "mat_reloadvmtcache", ReloadVmtCache, "Reload vmts from vmtcache.txt.", FCVAR_CHEAT | FCVAR_CLIENTDLL | FCVAR_DEVELOPMENTONLY );
  77. void DestroyMaterials();
  78. CUtlVector< CCustomMaterial * > m_pCustomMaterials;
  79. CUtlMap< const char *, KeyValues * > m_mapVMTKeyValues;
  80. };
  81. #endif // CUSTOM_MATERIAL_H