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.

162 lines
10 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //
  7. //=============================================================================//
  8. #ifndef CMATERIAL_QUEUEFRIENDLY_H
  9. #define CMATERIAL_QUEUEFRIENDLY_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "imaterialinternal.h"
  14. class CMaterial_QueueFriendly : public IMaterialInternal //wraps a CMaterial with queue friendly functions for game/engine code. materialsystem/shaderapi code should use CMaterial directly.
  15. {
  16. public:
  17. virtual const char * GetName() const;
  18. virtual const char * GetTextureGroupName() const;
  19. virtual PreviewImageRetVal_t GetPreviewImageProperties( int *width, int *height, ImageFormat *imageFormat, bool* isTranslucent ) const;
  20. virtual PreviewImageRetVal_t GetPreviewImage( unsigned char *data, int width, int height, ImageFormat imageFormat ) const;
  21. virtual int GetMappingWidth( );
  22. virtual int GetMappingHeight( );
  23. virtual int GetNumAnimationFrames( );
  24. virtual bool InMaterialPage( void );
  25. virtual void GetMaterialOffset( float *pOffset );
  26. virtual void GetMaterialScale( float *pScale );
  27. virtual IMaterial *GetMaterialPage( void );
  28. virtual void IncrementReferenceCount( void );
  29. virtual int GetEnumerationID( void ) const;
  30. virtual bool HasProxy( void ) const;
  31. virtual void GetReflectivity( Vector& reflect );
  32. virtual bool GetPropertyFlag( MaterialPropertyTypes_t type );
  33. virtual bool IsTwoSided();
  34. virtual int ShaderParamCount() const;
  35. virtual bool IsErrorMaterial() const; //should probably return the realtime error material instead of this wrapper for it
  36. virtual bool IsSpriteCard(); //lets just assume nobody changes the shader to spritecard and immediately asks if it's a spritecard
  37. //TODO: Investigate if these are likely to change at all when setting vars/flags
  38. virtual bool IsAlphaTested();
  39. virtual bool IsVertexLit();
  40. virtual VertexFormat_t GetVertexFormat() const;
  41. virtual bool UsesEnvCubemap( void );
  42. virtual bool NeedsTangentSpace( void );
  43. virtual bool NeedsSoftwareSkinning( void );
  44. virtual int GetNumPasses( void );
  45. virtual int GetTextureMemoryBytes( void );
  46. virtual bool NeedsLightmapBlendAlpha( void );
  47. virtual bool NeedsSoftwareLighting( void );
  48. virtual MorphFormat_t GetMorphFormat() const;
  49. //TODO: Investigate if this can change over the course of a frame.
  50. virtual void GetLowResColorSample( float s, float t, float *color ) const;
  51. //Functions that need to be queue friendly, the whole reason for this wrapper class.
  52. virtual IMaterialVar * FindVar( const char *varName, bool *found, bool complain = true );
  53. virtual IMaterialVar * FindVarFast( char const *pVarName, unsigned int *pToken );
  54. virtual IMaterialVar **GetShaderParams( void );
  55. virtual void DecrementReferenceCount( void );
  56. virtual void DeleteIfUnreferenced();
  57. virtual void RecomputeStateSnapshots();
  58. virtual bool IsTranslucent();
  59. virtual bool NeedsPowerOfTwoFrameBufferTexture( bool bCheckSpecificToThisFrame = true );
  60. virtual bool NeedsFullFrameBufferTexture( bool bCheckSpecificToThisFrame = true );
  61. virtual void AlphaModulate( float alpha );
  62. virtual void ColorModulate( float r, float g, float b );
  63. virtual void SetMaterialVarFlag( MaterialVarFlags_t flag, bool on );
  64. virtual bool GetMaterialVarFlag( MaterialVarFlags_t flag ) const;
  65. virtual void SetShader( const char *pShaderName );
  66. virtual void SetShaderAndParams( KeyValues *pKeyValues );
  67. virtual const char * GetShaderName() const;
  68. virtual void Refresh();
  69. virtual void RefreshPreservingMaterialVars();
  70. virtual void SetUseFixedFunctionBakedLighting( bool bEnable );
  71. virtual float GetAlphaModulation();
  72. virtual void GetColorModulation( float *r, float *g, float *b );
  73. virtual void CallBindProxy( void *proxyData );
  74. virtual IMaterial *CheckProxyReplacement( void *proxyData );
  75. virtual void PrecacheMappingDimensions( );
  76. virtual void FindRepresentativeTexture( void );
  77. virtual bool WasReloadedFromWhitelist() { return m_pRealTimeVersion->WasReloadedFromWhitelist(); }
  78. virtual bool IsPrecached( ) const { return m_pRealTimeVersion->IsPrecached(); }
  79. #define QUEUEFRIENDLY_USED_INTERNALLY_ASSERT AssertMsg( 0, "CMaterial_QueueFriendly used internally within materialsystem. Update the calling code to use a realtime CMaterial." )
  80. //------------------------------------------------------------------------------
  81. // IMaterialInternal interfaces. Internal systems should not be using this queue
  82. // wrapper class at all. Switch to the real time pointer in the calling code.
  83. //------------------------------------------------------------------------------
  84. virtual int GetReferenceCount( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetReferenceCount(); }
  85. virtual void SetEnumerationID( int id ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetEnumerationID( id ); }
  86. virtual void SetNeedsWhiteLightmap( bool val ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetNeedsWhiteLightmap( val ); }
  87. virtual bool GetNeedsWhiteLightmap( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetNeedsWhiteLightmap(); }
  88. virtual void Uncache( bool bPreserveVars = false ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->Uncache( bPreserveVars ); }
  89. virtual void Precache() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->Precache(); }
  90. // If provided, pKeyValues and pPatchKeyValues should come from LoadVMTFile()
  91. virtual bool PrecacheVars( KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, CUtlVector<FileNameHandle_t> *pIncludes = NULL, int nFindContext = MATERIAL_FINDCONTEXT_NONE ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->PrecacheVars( pKeyValues, pPatchKeyValues, pIncludes, nFindContext ); }
  92. virtual void ReloadTextures() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ReloadTextures(); }
  93. virtual void SetMinLightmapPageID( int pageID ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetMinLightmapPageID( pageID ); }
  94. virtual void SetMaxLightmapPageID( int pageID ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetMaxLightmapPageID( pageID ); }
  95. virtual int GetMinLightmapPageID( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetMinLightmapPageID(); }
  96. virtual int GetMaxLightmapPageID( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetMaxLightmapPageID(); }
  97. virtual IShader *GetShader() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetShader(); }
  98. virtual bool IsPrecachedVars() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsPrecachedVars(); }
  99. virtual void DrawMesh( VertexCompressionType_t vertexCompression ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->DrawMesh( vertexCompression ); }
  100. virtual VertexFormat_t GetVertexUsage() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetVertexUsage(); }
  101. virtual bool PerformDebugTrace() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->PerformDebugTrace(); }
  102. virtual bool NoDebugOverride() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->NoDebugOverride(); }
  103. virtual void ToggleSuppression() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ToggleSuppression(); }
  104. virtual bool IsSuppressed() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsSuppressed(); }
  105. virtual void ToggleDebugTrace() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ToggleDebugTrace(); }
  106. virtual bool UseFog() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->UseFog(); }
  107. virtual void AddMaterialVar( IMaterialVar *pMaterialVar ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->AddMaterialVar( pMaterialVar ); }
  108. virtual ShaderRenderState_t *GetRenderState() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetRenderState(); }
  109. virtual bool IsManuallyCreated() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsManuallyCreated(); }
  110. virtual bool NeedsFixedFunctionFlashlight() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->NeedsFixedFunctionFlashlight(); }
  111. virtual bool IsUsingVertexID() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsUsingVertexID(); }
  112. virtual void MarkAsPreloaded( bool bSet ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->MarkAsPreloaded( bSet ); }
  113. virtual bool IsPreloaded() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsPreloaded(); }
  114. virtual void ArtificialAddRef() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ArtificialAddRef(); }
  115. virtual void ArtificialRelease() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ArtificialRelease(); }
  116. virtual void ReportVarChanged( IMaterialVar *pVar ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ReportVarChanged( pVar ); }
  117. virtual uint32 GetChangeID() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetChangeID(); }
  118. virtual bool IsTranslucentInternal( float fAlphaModulation ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsTranslucentInternal( fAlphaModulation ); }
  119. virtual void DecideShouldReloadFromWhitelist( IFileList *pFileList ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->DecideShouldReloadFromWhitelist( pFileList ); }
  120. virtual void ReloadFromWhitelistIfMarked() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->ReloadFromWhitelistIfMarked(); }
  121. virtual bool IsRealTimeVersion( void ) const;
  122. virtual IMaterialInternal *GetRealTimeVersion( void );
  123. virtual IMaterialInternal *GetQueueFriendlyVersion( void );
  124. void SetRealTimeVersion( IMaterialInternal *pRealTimeVersion )
  125. {
  126. m_pRealTimeVersion = pRealTimeVersion;
  127. m_nReferenceCount = m_pRealTimeVersion->GetReferenceCount();
  128. }
  129. void UpdateToRealTime( void ); //update cached off variables using the real time version as a base.
  130. protected:
  131. IMaterialInternal *m_pRealTimeVersion; //the material we're wrapping with queued delays
  132. private:
  133. //some calls need to know what state the material would be in right now if the queue had completed.
  134. float m_fAlphaModulationOnQueueCompletion;
  135. Vector m_vColorModulationOnQueueCompletion;
  136. int m_nReferenceCount; // Only ever accessed from the main thread.
  137. };
  138. #endif //#ifndef CMATERIAL_QUEUEFRIENDLY_H