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.

161 lines
5.8 KiB

  1. //========= Copyright 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. //-----------------------------------------------------------------------------
  31. // Interface for materials used only within the material system
  32. //-----------------------------------------------------------------------------
  33. abstract_class IMaterialInternal : public IMaterial
  34. {
  35. public:
  36. // class factory methods
  37. static IMaterialInternal* CreateMaterial( char const* pMaterialName, const char *pTextureGroupName, KeyValues *pKeyValues = NULL );
  38. static void DestroyMaterial( IMaterialInternal* pMaterial );
  39. // If supplied, pKeyValues and pPatchKeyValues should come from LoadVMTFile()
  40. static IMaterialInternal* CreateMaterialSubRect( char const* pMaterialName, const char *pTextureGroupName,
  41. KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, bool bAssumeCreateFromFile = false );
  42. static void DestroyMaterialSubRect( IMaterialInternal* pMaterial );
  43. // refcount
  44. virtual int GetReferenceCount( ) const = 0;
  45. // enumeration id
  46. virtual void SetEnumerationID( int id ) = 0;
  47. // White lightmap methods
  48. virtual void SetNeedsWhiteLightmap( bool val ) = 0;
  49. virtual bool GetNeedsWhiteLightmap( ) const = 0;
  50. // load/unload
  51. virtual void Uncache( bool bPreserveVars = false ) = 0;
  52. virtual void Precache() = 0;
  53. // If supplied, pKeyValues and pPatchKeyValues should come from LoadVMTFile()
  54. virtual bool PrecacheVars( KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, CUtlVector<FileNameHandle_t> *pIncludes = NULL, int nFindContext = MATERIAL_FINDCONTEXT_NONE ) = 0;
  55. // reload all textures used by this materals
  56. virtual void ReloadTextures() = 0;
  57. // lightmap pages associated with this material
  58. virtual void SetMinLightmapPageID( int pageID ) = 0;
  59. virtual void SetMaxLightmapPageID( int pageID ) = 0;;
  60. virtual int GetMinLightmapPageID( ) const = 0;
  61. virtual int GetMaxLightmapPageID( ) const = 0;
  62. virtual IShader *GetShader() const = 0;
  63. // Can we use it?
  64. virtual bool IsPrecached( ) const = 0;
  65. virtual bool IsPrecachedVars() const = 0;
  66. // main draw method
  67. virtual void DrawMesh( VertexCompressionType_t vertexCompression ) = 0;
  68. // Gets the vertex format
  69. virtual VertexFormat_t GetVertexFormat() const = 0;
  70. virtual VertexFormat_t GetVertexUsage() const = 0;
  71. // Performs a debug trace on this material
  72. virtual bool PerformDebugTrace() const = 0;
  73. // Can we override this material in debug?
  74. virtual bool NoDebugOverride() const = 0;
  75. // Should we draw?
  76. virtual void ToggleSuppression() = 0;
  77. // Are we suppressed?
  78. virtual bool IsSuppressed() const = 0;
  79. // Should we debug?
  80. virtual void ToggleDebugTrace() = 0;
  81. // Do we use fog?
  82. virtual bool UseFog() const = 0;
  83. // Adds a material variable to the material
  84. virtual void AddMaterialVar( IMaterialVar *pMaterialVar ) = 0;
  85. // Gets the renderstate
  86. virtual ShaderRenderState_t *GetRenderState() = 0;
  87. // Was this manually created (not read from a file?)
  88. virtual bool IsManuallyCreated() const = 0;
  89. virtual bool NeedsFixedFunctionFlashlight() const = 0;
  90. virtual bool IsUsingVertexID() const = 0;
  91. // Identifies a material mounted through the preload path
  92. virtual void MarkAsPreloaded( bool bSet ) = 0;
  93. virtual bool IsPreloaded() const = 0;
  94. // Conditonally increments the refcount
  95. virtual void ArtificialAddRef( void ) = 0;
  96. virtual void ArtificialRelease( void ) = 0;
  97. virtual void ReportVarChanged( IMaterialVar *pVar ) = 0;
  98. virtual uint32 GetChangeID() const = 0;
  99. virtual bool IsTranslucentInternal( float fAlphaModulation ) const = 0;
  100. //Is this the queue friendly or realtime version of the material?
  101. virtual bool IsRealTimeVersion( void ) const = 0;
  102. virtual void ClearContextData( void )
  103. {
  104. }
  105. //easy swapping between the queue friendly and realtime versions of the material
  106. virtual IMaterialInternal *GetRealTimeVersion( void ) = 0;
  107. virtual IMaterialInternal *GetQueueFriendlyVersion( void ) = 0;
  108. virtual void PrecacheMappingDimensions( void ) = 0;
  109. virtual void FindRepresentativeTexture( void ) = 0;
  110. // These are used when a new whitelist is passed in. First materials to be reloaded are flagged, then they are reloaded.
  111. virtual void DecideShouldReloadFromWhitelist( IFileList *pFileList ) = 0;
  112. virtual void ReloadFromWhitelistIfMarked() = 0;
  113. };
  114. extern void InsertKeyValues( KeyValues& dst, KeyValues& src, bool bCheckForExistence, bool bRecursive = false );
  115. extern void WriteKeyValuesToFile( const char *pFileName, KeyValues& keyValues );
  116. extern void ExpandPatchFile( KeyValues& keyValues, KeyValues &patchKeyValues );
  117. // patchKeyValues accumulates keys applied by VMT patch files (this is necessary to make $fallbackmaterial
  118. // work properly - the patch keys need to be reapplied when the fallback VMT is loaded). It may contain
  119. // previously accumulated patch keys on entry, and may contain more encountered patch keys on exit.
  120. extern bool LoadVMTFile( KeyValues &vmtKeyValues, KeyValues &patchKeyValues, const char *pMaterialName, bool bUsesUNCFilename, CUtlVector<FileNameHandle_t> *pIncludes );
  121. #endif // IMATERIALINTERNAL_H