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.

162 lines
10 KiB

  1. //========= Copyright � 1996-2005, 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. //TODO: Investigate if this can change over the course of a frame.
  49. virtual void GetLowResColorSample( float s, float t, float *color ) const;
  50. //Functions that need to be queue friendly, the whole reason for this wrapper class.
  51. virtual IMaterialVar * FindVar( const char *varName, bool *found, bool complain = true );
  52. virtual IMaterialVar * FindVarFast( char const *pVarName, unsigned int *pToken );
  53. virtual IMaterialVar **GetShaderParams( void );
  54. virtual void DecrementReferenceCount( void );
  55. virtual void DeleteIfUnreferenced();
  56. virtual void RecomputeStateSnapshots();
  57. virtual bool IsTranslucent();
  58. virtual bool IsTranslucentUnderModulation( float fAlphaModulation ) const;
  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 float GetAlphaModulation();
  71. virtual void GetColorModulation( float *r, float *g, float *b );
  72. virtual void CallBindProxy( void *proxyData, ICallQueue *pCallQueue );
  73. virtual void PrecacheMappingDimensions( );
  74. virtual void FindRepresentativeTexture( void );
  75. virtual bool WasReloadedFromWhitelist() { return m_pRealTimeVersion->WasReloadedFromWhitelist(); }
  76. #define QUEUEFRIENDLY_USED_INTERNALLY_ASSERT AssertMsg( 0, "CMaterial_QueueFriendly used internally within materialsystem. Update the calling code to use a realtime CMaterial." )
  77. //------------------------------------------------------------------------------
  78. // IMaterialInternal interfaces. Internal systems should not be using this queue
  79. // wrapper class at all. Switch to the real time pointer in the calling code.
  80. //------------------------------------------------------------------------------
  81. virtual int GetReferenceCount( ) const { return m_pRealTimeVersion->GetReferenceCount(); }
  82. virtual void SetEnumerationID( int id ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetEnumerationID( id ); }
  83. virtual void SetNeedsWhiteLightmap( bool val ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetNeedsWhiteLightmap( val ); }
  84. virtual bool GetNeedsWhiteLightmap( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetNeedsWhiteLightmap(); }
  85. virtual void Uncache( bool bPreserveVars = false ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->Uncache( bPreserveVars ); }
  86. virtual void Precache() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->Precache(); }
  87. // If provided, pKeyValues and pPatchKeyValues should come from LoadVMTFile()
  88. virtual bool PrecacheVars( KeyValues *pKeyValues = NULL, KeyValues *pPatchKeyValues = NULL, CUtlVector<FileNameHandle_t> *pIncludes = NULL ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->PrecacheVars( pKeyValues, pPatchKeyValues, pIncludes ); }
  89. virtual void ReloadTextures() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ReloadTextures(); }
  90. virtual void SetMinLightmapPageID( int pageID ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetMinLightmapPageID( pageID ); }
  91. virtual void SetMaxLightmapPageID( int pageID ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->SetMaxLightmapPageID( pageID ); }
  92. virtual int GetMinLightmapPageID( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetMinLightmapPageID(); }
  93. virtual int GetMaxLightmapPageID( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetMaxLightmapPageID(); }
  94. virtual IShader *GetShader() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetShader(); }
  95. virtual bool IsPrecached( ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsPrecached(); }
  96. virtual bool IsPrecachedVars() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsPrecachedVars(); }
  97. virtual void DrawMesh( VertexCompressionType_t vertexCompression, bool bIsAlphaModulating, bool bRenderingPreTessPatchMesh ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->DrawMesh( vertexCompression, bIsAlphaModulating, bRenderingPreTessPatchMesh ); }
  98. virtual VertexFormat_t GetVertexUsage() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetVertexUsage(); }
  99. virtual bool PerformDebugTrace() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->PerformDebugTrace(); }
  100. virtual bool NoDebugOverride() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->NoDebugOverride(); }
  101. virtual void ToggleSuppression() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ToggleSuppression(); }
  102. virtual bool IsSuppressed() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsSuppressed(); }
  103. virtual void ToggleDebugTrace() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ToggleDebugTrace(); }
  104. virtual bool UseFog() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->UseFog(); }
  105. virtual void AddMaterialVar( IMaterialVar *pMaterialVar ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->AddMaterialVar( pMaterialVar ); }
  106. virtual ShaderRenderState_t *GetRenderState() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetRenderState(); }
  107. virtual bool IsManuallyCreated() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsManuallyCreated(); }
  108. virtual bool NeedsFixedFunctionFlashlight() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->NeedsFixedFunctionFlashlight(); }
  109. virtual bool IsUsingVertexID() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsUsingVertexID(); }
  110. virtual void MarkAsPreloaded( bool bSet ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->MarkAsPreloaded( bSet ); }
  111. virtual bool IsPreloaded() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsPreloaded(); }
  112. virtual void ArtificialAddRef() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ArtificialAddRef(); }
  113. virtual void ArtificialRelease() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ArtificialRelease(); }
  114. virtual void ReportVarChanged( IMaterialVar *pVar ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; m_pRealTimeVersion->ReportVarChanged( pVar ); }
  115. virtual uint32 GetChangeID() const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->GetChangeID(); }
  116. virtual bool IsTranslucentInternal( float fAlphaModulation ) const { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->IsTranslucentInternal( fAlphaModulation ); }
  117. virtual void DecideShouldReloadFromWhitelist( IFileList *pFileList ) { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->DecideShouldReloadFromWhitelist( pFileList ); }
  118. virtual void ReloadFromWhitelistIfMarked() { QUEUEFRIENDLY_USED_INTERNALLY_ASSERT; return m_pRealTimeVersion->ReloadFromWhitelistIfMarked(); }
  119. virtual bool IsRealTimeVersion( void ) const;
  120. virtual IMaterialInternal *GetRealTimeVersion( void );
  121. virtual IMaterialInternal *GetQueueFriendlyVersion( void );
  122. void SetRealTimeVersion( IMaterialInternal *pRealTimeVersion ) { m_pRealTimeVersion = pRealTimeVersion; }
  123. void UpdateToRealTime( void ); //update cached off variables using the real time version as a base.
  124. virtual void CompactMaterialVars() {}
  125. // The material system should be asking, and it should be working with the realtime version only.
  126. virtual bool HasQueueFriendlyProxies() const { Assert( !"Unexpected call to HasQueueFriendlyProxies" ); return false; }
  127. virtual bool SetTempExcluded( bool bSet, int nExcludedDimensionLimit );
  128. protected:
  129. IMaterialInternal *m_pRealTimeVersion; //the material we're wrapping with queued delays
  130. private:
  131. //some calls need to know what state the material would be in right now if the queue had completed.
  132. float m_fAlphaModulationOnQueueCompletion;
  133. Vector m_vColorModulationOnQueueCompletion;
  134. };
  135. #endif //#ifndef CMATERIAL_QUEUEFRIENDLY_H