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.

132 lines
4.3 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ================================== //
  2. //
  3. // Purpose: Defines a texture compositor which uses simple operations and shaders to
  4. // create complex procedural textures.
  5. //
  6. //============================================================================================== //
  7. #ifndef CTEXTURECOMPOSITOR_H
  8. #define CTEXTURECOMPOSITOR_H
  9. #include "materialsystem/itexturecompositor.h"
  10. #include "materialsystem/combineoperations.h"
  11. class CTCStage;
  12. // ------------------------------------------------------------------------------------------------
  13. struct RenderTarget_t
  14. {
  15. int m_nWidth;
  16. int m_nHeight;
  17. ITexture* m_pRT;
  18. };
  19. // ------------------------------------------------------------------------------------------------
  20. class CTextureCompositor : public ITextureCompositor
  21. {
  22. public:
  23. CTextureCompositor( int _width, int _height, int nTeam, const char* pCompositeName, uint64 nRandomSeed, uint32 nTexCompositeCreateFlags );
  24. virtual int AddRef() OVERRIDE;
  25. virtual int Release() OVERRIDE;
  26. virtual int GetRefCount() const OVERRIDE { return m_nReferenceCount; }
  27. virtual void Update() OVERRIDE;
  28. virtual ITexture* GetResultTexture() const OVERRIDE;
  29. virtual ECompositeResolveStatus GetResolveStatus() const OVERRIDE;
  30. virtual void ScheduleResolve() OVERRIDE;
  31. void Resolve();
  32. void Error( bool _retry, PRINTF_FORMAT_STRING const char* _debugDevMsg, ... );
  33. void SetRootStage( CTCStage* _rootStage );
  34. ITexture* AllocateCompositorRenderTarget( );
  35. void ReleaseCompositorRenderTarget( ITexture* _tex );
  36. int GetTeamNumber() const { return m_nTeam; }
  37. const CUtlString& GetName() const { return m_CompositeName; }
  38. uint32 GetCreateFlags() const { return m_nTexCompositeCreateFlags; }
  39. void GetTextureName( char* pOutBuffer, int nBufferLen ) const;
  40. void GetSeed( uint32* pOutHi, uint32* pOutLo ) const;
  41. void SetTemplate( const char* pTemplate ) { m_TemplateName = pTemplate; }
  42. bool UsesTemplate() const { return m_TemplateName.IsEmpty() == false; }
  43. const CUtlString& GetTemplateName() const { return m_TemplateName; }
  44. protected:
  45. virtual ~CTextureCompositor();
  46. void Restart();
  47. private:
  48. void Shutdown();
  49. CInterlockedInt m_nReferenceCount;
  50. int m_nWidth;
  51. int m_nHeight;
  52. int m_nTeam;
  53. uint64 m_nRandomSeed;
  54. CTCStage* m_pRootStage;
  55. ECompositeResolveStatus m_ResolveStatus;
  56. // Did an error occur
  57. bool m_bError;
  58. // And is it fatal, or should we try again?
  59. bool m_bFatal;
  60. CUtlVector<RenderTarget_t> m_RenderTargetPool;
  61. int m_nRenderTargetsAllocated;
  62. int m_nCompositePaintKitId;
  63. CUtlString m_CompositeName;
  64. CUtlString m_TemplateName;
  65. uint32 m_nTexCompositeCreateFlags;
  66. bool m_bHasTeamSpecifics;
  67. };
  68. // ------------------------------------------------------------------------------------------------
  69. class CTextureCompositorTemplate
  70. {
  71. public:
  72. static CTextureCompositorTemplate* Create( const char* pName, KeyValues* pTmplDesc );
  73. ~CTextureCompositorTemplate();
  74. /* const */ KeyValues* GetKV() /* const */ { return m_pKV; }
  75. const CUtlString& GetName() const { return m_Name; }
  76. bool ResolveDependencies() const;
  77. bool HasDependencyCycles(); // Not const because we update m_bCheckedForCycles
  78. void SetImplementsName( const CUtlString& implementsName ) { m_ImplementsName = implementsName; }
  79. bool ImplementsTemplate() const { return m_ImplementsName.IsEmpty() == false; }
  80. const CUtlString& GetImplementsName() const { return m_ImplementsName; }
  81. void SetCheckedForCycles( bool checked ) { m_bCheckedForCycles = checked; }
  82. bool HasCheckedForCycles() const { return m_bCheckedForCycles; }
  83. private:
  84. CTextureCompositorTemplate( const char* pName, KeyValues* pKV )
  85. : m_pKV( pKV )
  86. , m_Name( pName )
  87. , m_bCheckedForCycles( false )
  88. { }
  89. KeyValues* m_pKV;
  90. // Our own name
  91. CUtlString m_Name;
  92. // If we are an implementation of another template, what is that template's name?
  93. CUtlString m_ImplementsName;
  94. // Have we checked this template and it's hierarchy for cycles? If so we can early out on future checks.
  95. bool m_bCheckedForCycles;
  96. };
  97. // ------------------------------------------------------------------------------------------------
  98. const char *GetCombinedMaterialName( ECombineOperation eMaterial );
  99. CTextureCompositor* CreateTextureCompositor( int _w, int _h, const char* pCompositeName, int nTeamNum, uint64 _randomSeed, KeyValues* _stageDesc, uint32 texCompositeCreateFlags );
  100. #endif /* CTEXTURECOMPOSITOR_H */