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.

264 lines
6.7 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose: Implementation of IEditorTexture interface for materials.
  4. //
  5. // $NoKeywords: $
  6. //===========================================================================//
  7. #ifndef MATERIAL_H
  8. #define MATERIAL_H
  9. #pragma once
  10. #include "IEditorTexture.h"
  11. #include "materialsystem/IMaterialVar.h"
  12. #include "materialsystem/IMaterial.h"
  13. class IMaterial;
  14. class CMaterialCache;
  15. class IMaterialSystem;
  16. class IMaterialSystemHardwareConfig;
  17. struct MaterialSystem_Config_t;
  18. struct MaterialCacheEntry_t;
  19. #define INCLUDE_MODEL_MATERIALS 0x01
  20. #define INCLUDE_WORLD_MATERIALS 0x02
  21. #define INCLUDE_ALL_MATERIALS 0xFFFFFFFF
  22. //-----------------------------------------------------------------------------
  23. // Inherit from this to enumerate materials
  24. //-----------------------------------------------------------------------------
  25. class IMaterialEnumerator
  26. {
  27. public:
  28. virtual bool EnumMaterial( const char *pMaterialName, int nContext ) = 0;
  29. };
  30. //-----------------------------------------------------------------------------
  31. // Purpose:
  32. //-----------------------------------------------------------------------------
  33. class CMaterial : public IEditorTexture
  34. {
  35. public:
  36. static bool Initialize( HWND hwnd );
  37. static void ShutDown(void);
  38. static void EnumerateMaterials( IMaterialEnumerator *pEnum, const char *szRoot, int nContext, int nFlags = INCLUDE_ALL_MATERIALS );
  39. static CMaterial *CreateMaterial( const char *pszMaterialName, bool bLoadImmediately, bool* pFound = 0 );
  40. virtual ~CMaterial(void);
  41. void Draw(CDC *pDC, RECT& rect, int iFontHeight, int iIconHeight, DrawTexData_t &DrawTexData); //DWORD dwFlags = (drawCaption|drawIcons));
  42. void FreeData(void);
  43. inline const char *GetName(void) const
  44. {
  45. return(m_szName);
  46. }
  47. int GetShortName(char *pszName) const;
  48. int GetKeywords(char *pszKeywords) const;
  49. void GetSize(SIZE &size) const;
  50. int GetImageDataRGB(void *pImageRGB);
  51. int GetImageDataRGBA(void *pImageRGBA);
  52. // Image dimensions
  53. int GetPreviewImageWidth(void) const;
  54. int GetPreviewImageHeight(void) const;
  55. int GetMappingWidth(void) const;
  56. int GetMappingHeight(void) const;
  57. // todo: remove these. They are the same as GetPreviewImageWidth, etc.
  58. int GetWidth(void) const;
  59. int GetHeight(void) const;
  60. float GetDecalScale(void) const;
  61. const char *GetFileName(void) const;
  62. inline CPalette *GetPalette(void) const
  63. {
  64. return(NULL);
  65. }
  66. inline int GetSurfaceAttributes(void) const
  67. {
  68. return(0);
  69. }
  70. inline int GetSurfaceContents(void) const
  71. {
  72. return(0);
  73. }
  74. inline int GetSurfaceValue(void) const
  75. {
  76. return(0);
  77. }
  78. inline TEXTUREFORMAT GetTextureFormat(void) const
  79. {
  80. return(tfVMT);
  81. }
  82. inline int GetTextureID(void) const
  83. {
  84. return(m_nTextureID);
  85. }
  86. bool HasAlpha(void) const
  87. {
  88. return(false);
  89. }
  90. inline bool HasData(void) const
  91. {
  92. return((m_nPreviewImageWidth != 0) && (m_nPreviewImageHeight != 0));
  93. }
  94. inline bool HasPalette(void) const
  95. {
  96. return(false);
  97. }
  98. inline bool IsDummy(void) const
  99. {
  100. return(false);
  101. }
  102. bool Load(void);
  103. void Reload( bool bFullReload );
  104. inline bool IsLoaded() const
  105. {
  106. return m_bLoaded;
  107. }
  108. inline void SetTextureID(int nTextureID)
  109. {
  110. m_nTextureID = nTextureID;
  111. }
  112. bool IsWater( void ) const;
  113. virtual IMaterial* GetMaterial( bool bForceLoad=true );
  114. protected:
  115. // Used to draw the bitmap for the texture browser
  116. void DrawBitmap( CDC *pDC, RECT& srcRect, RECT& dstRect );
  117. void DrawBrowserIcons( CDC *pDC, RECT& dstRect, bool detectErrors );
  118. void DrawIcon( CDC *pDC, CMaterial* pIcon, RECT& dstRect );
  119. static bool ShouldSkipMaterial(const char *pszName, int nFlags);
  120. // Finds all .VMT files in a particular directory
  121. static bool LoadMaterialsInDirectory( char const* pDirectoryName, int nDirectoryNameLen,
  122. IMaterialEnumerator *pEnum, int nContext, int nFlags );
  123. // Discovers all .VMT files lying under a particular directory recursively
  124. static bool InitDirectoryRecursive( char const* pDirectoryName,
  125. IMaterialEnumerator *pEnum, int nContext, int nFlags );
  126. CMaterial(void);
  127. bool LoadMaterialHeader(IMaterial *material);
  128. bool LoadMaterialImage();
  129. static bool IsIgnoredMaterial( const char *pName );
  130. // Will actually load the material bits
  131. // We don't want to load them all at once because it takes way too long
  132. bool LoadMaterial();
  133. char m_szName[MAX_PATH];
  134. char m_szFileName[MAX_PATH];
  135. char m_szKeywords[MAX_PATH];
  136. int m_nTextureID; // Uniquely identifies this texture in all 3D renderers.
  137. int m_nPreviewImageWidth; // Texture width in texels.
  138. int m_nPreviewImageHeight; // Texture height in texels.
  139. bool m_TranslucentBaseTexture;
  140. bool m_bLoaded; // We don't load these immediately; only when needed..
  141. void *m_pData; // Loaded texel data (NULL if not loaded).
  142. IMaterial *m_pMaterial;
  143. friend class CMaterialImageCache;
  144. };
  145. typedef CMaterial *CMaterialPtr;
  146. //-----------------------------------------------------------------------------
  147. // Purpose:
  148. //-----------------------------------------------------------------------------
  149. class CMaterialCache
  150. {
  151. public:
  152. CMaterialCache(void);
  153. ~CMaterialCache(void);
  154. inline bool CacheExists(void);
  155. bool Create(int nMaxEntries);
  156. CMaterial *CreateMaterial(const char *pszMaterialName);
  157. void AddRef(CMaterial *pMaterial);
  158. void Release(CMaterial *pMaterial);
  159. protected:
  160. CMaterial *FindMaterial(const char *pszMaterialName);
  161. void AddMaterial(CMaterial *pMaterial);
  162. MaterialCacheEntry_t *m_pCache;
  163. int m_nMaxEntries;
  164. int m_nEntries;
  165. };
  166. //-----------------------------------------------------------------------------
  167. // Purpose: Returns true if the cache has been allocated, false if not.
  168. //-----------------------------------------------------------------------------
  169. inline bool CMaterialCache::CacheExists(void)
  170. {
  171. return((m_pCache != NULL) && (m_nMaxEntries > 0));
  172. }
  173. //-----------------------------------------------------------------------------
  174. // returns the material system interface + config
  175. //-----------------------------------------------------------------------------
  176. inline IMaterialSystem *MaterialSystemInterface()
  177. {
  178. return materials;
  179. }
  180. inline MaterialSystem_Config_t& MaterialSystemConfig()
  181. {
  182. extern MaterialSystem_Config_t g_materialSystemConfig;
  183. return g_materialSystemConfig;
  184. }
  185. inline IMaterialSystemHardwareConfig* MaterialSystemHardwareConfig()
  186. {
  187. extern IMaterialSystemHardwareConfig* g_pMaterialSystemHardwareConfig;
  188. return g_pMaterialSystemHardwareConfig;
  189. }
  190. //--------------------------------------------------------------------------------
  191. // call AllocateLightingPreviewtextures to make sure necessary rts are allocated
  192. //--------------------------------------------------------------------------------
  193. void AllocateLightingPreviewtextures(void);
  194. #endif // MATERIAL_H