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.

186 lines
6.6 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef IMATERIALINTERNAL_H
  9. #define IMATERIALINTERNAL_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. // identifier was truncated to '255' characters in the debug information
  14. #pragma warning(disable: 4786)
  15. #include "materialsystem/imaterialsystem.h"
  16. #include "materialsystem/imaterial.h"
  17. #include "shaderapi/ishaderapi.h"
  18. #include "filesystem.h"
  19. //-----------------------------------------------------------------------------
  20. // forward declarations
  21. //-----------------------------------------------------------------------------
  22. enum MaterialPrimitiveType_t;
  23. class IShader;
  24. class IMesh;
  25. class IVertexBuffer;
  26. class IIndexBuffer;
  27. struct Shader_VertexArrayData_t;
  28. struct ShaderRenderState_t;
  29. class KeyValues;
  30. class CBasePerMaterialContextData;
  31. struct tokencache_t
  32. {
  33. unsigned short symbol;
  34. unsigned char varIndex;
  35. unsigned char cached : 1;
  36. unsigned char subrect : 1;
  37. };
  38. //-----------------------------------------------------------------------------
  39. // Interface for materials used only within the material system
  40. //-----------------------------------------------------------------------------
  41. abstract_class IMaterialInternal : public IMaterial
  42. {
  43. public:
  44. // class factory methods
  45. static IMaterialInternal* CreateMaterial( char const* pMaterialName, const char *pTextureGroupName, KeyValues *pKeyValues = NULL );
  46. static void DestroyMaterial( IMaterialInternal* pMaterial );
  47. // If supplied, pKeyValues and pPatchKeyValues should come from LoadVMTFile()
  48. static IMaterialInternal* CreateMaterialSubRect( char const* pMaterialName, const char *pTextureGroupName,
  49. KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, bool bAssumeCreateFromFile = false );
  50. static void DestroyMaterialSubRect( IMaterialInternal* pMaterial );
  51. // refcount
  52. virtual int GetReferenceCount( ) const = 0;
  53. // enumeration id
  54. virtual void SetEnumerationID( int id ) = 0;
  55. // White lightmap methods
  56. virtual void SetNeedsWhiteLightmap( bool val ) = 0;
  57. virtual bool GetNeedsWhiteLightmap( ) const = 0;
  58. // load/unload
  59. virtual void Uncache( bool bPreserveVars = false ) = 0;
  60. virtual void Precache() = 0;
  61. // If supplied, pKeyValues and pPatchKeyValues should come from LoadVMTFile()
  62. virtual bool PrecacheVars( KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, CUtlVector<FileNameHandle_t> *pIncludes = NULL ) = 0;
  63. // reload all textures used by this materals
  64. virtual void ReloadTextures() = 0;
  65. // lightmap pages associated with this material
  66. virtual void SetMinLightmapPageID( int pageID ) = 0;
  67. virtual void SetMaxLightmapPageID( int pageID ) = 0;;
  68. virtual int GetMinLightmapPageID( ) const = 0;
  69. virtual int GetMaxLightmapPageID( ) const = 0;
  70. virtual IShader *GetShader() const = 0;
  71. virtual IMaterialVar** GetVars() { return NULL; }
  72. // Can we use it?
  73. virtual bool IsPrecached( ) const = 0;
  74. virtual bool IsPrecachedVars() const = 0;
  75. // main draw method
  76. virtual CBasePerMaterialContextData **GetContextData( int modulationFlags ) { return NULL; }
  77. virtual StateSnapshot_t GetSnapshotId( int modulation, int renderPass ) { return (StateSnapshot_t)-1; }
  78. virtual unsigned char* GetInstanceCommandBuffer( int modulation ) { return NULL; }
  79. virtual void DrawMesh( VertexCompressionType_t vertexCompression, bool bIsAlphaModulating, bool bUsingPreTessPatches ) = 0;
  80. // Gets the vertex format
  81. virtual VertexFormat_t GetVertexFormat() const = 0;
  82. virtual VertexFormat_t GetVertexUsage() const = 0;
  83. // Performs a debug trace on this material
  84. virtual bool PerformDebugTrace() const = 0;
  85. // Can we override this material in debug?
  86. virtual bool NoDebugOverride() const = 0;
  87. // Should we draw?
  88. virtual void ToggleSuppression() = 0;
  89. // Are we suppressed?
  90. virtual bool IsSuppressed() const = 0;
  91. // Should we debug?
  92. virtual void ToggleDebugTrace() = 0;
  93. // Do we use fog?
  94. virtual bool UseFog() const = 0;
  95. // Adds a material variable to the material
  96. virtual void AddMaterialVar( IMaterialVar *pMaterialVar ) = 0;
  97. // Gets the renderstate
  98. virtual ShaderRenderState_t *GetRenderState() = 0;
  99. // Was this manually created (not read from a file?)
  100. virtual bool IsManuallyCreated() const = 0;
  101. virtual bool NeedsFixedFunctionFlashlight() const = 0;
  102. virtual bool IsUsingVertexID() const = 0;
  103. // Identifies a material mounted through the preload path
  104. virtual void MarkAsPreloaded( bool bSet ) = 0;
  105. virtual bool IsPreloaded() const = 0;
  106. // Conditonally increments the refcount
  107. virtual void ArtificialAddRef( void ) = 0;
  108. virtual void ArtificialRelease( void ) = 0;
  109. virtual void ReportVarChanged( IMaterialVar *pVar ) = 0;
  110. virtual uint32 GetChangeID() const = 0;
  111. virtual uint32 GetChangeTimestamp() const { return 0; }
  112. virtual bool IsTranslucentInternal( float fAlphaModulation ) const = 0;
  113. //Is this the queue friendly or realtime version of the material?
  114. virtual bool IsRealTimeVersion( void ) const = 0;
  115. virtual void ClearContextData( void )
  116. {
  117. }
  118. //easy swapping between the queue friendly and realtime versions of the material
  119. virtual IMaterialInternal *GetRealTimeVersion( void ) = 0;
  120. virtual IMaterialInternal *GetQueueFriendlyVersion( void ) = 0;
  121. virtual void PrecacheMappingDimensions( void ) = 0;
  122. virtual void FindRepresentativeTexture( void ) = 0;
  123. // These are used when a new whitelist is passed in. First materials to be reloaded are flagged, then they are reloaded.
  124. virtual void DecideShouldReloadFromWhitelist( IFileList *pFileList ) = 0;
  125. virtual void ReloadFromWhitelistIfMarked() = 0;
  126. virtual void CompactMaterialVars() = 0;
  127. // Are any of the proxies attached to this material callable from the queued thread?
  128. virtual bool HasQueueFriendlyProxies() const = 0;
  129. };
  130. extern void InsertKeyValues( KeyValues& dst, KeyValues& src, bool bCheckForExistence );
  131. extern void WriteKeyValuesToFile( const char *pFileName, KeyValues& keyValues );
  132. extern void ExpandPatchFile( KeyValues& keyValues, KeyValues &patchKeyValues );
  133. // patchKeyValues accumulates keys applied by VMT patch files (this is necessary to make $fallbackmaterial
  134. // work properly - the patch keys need to be reapplied when the fallback VMT is loaded). It may contain
  135. // previously accumulated patch keys on entry, and may contain more encountered patch keys on exit.
  136. extern bool LoadVMTFile( KeyValues &vmtKeyValues, KeyValues &patchKeyValues, const char *pMaterialName, bool bUsesUNCFilename, CUtlVector<FileNameHandle_t> *pIncludes );
  137. extern void CompactMaterialVars( IMaterialVar **ppMaterialVars, int nVars );
  138. extern void CompactMaterialVarHeap();
  139. #endif // IMATERIALINTERNAL_H