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.

99 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. #ifndef MATERIALSYSTEMUTIL_H
  10. #define MATERIALSYSTEMUTIL_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "bitmap/imageformat.h" //ImageFormat enum definition
  15. #include "materialsystem/imaterialsystem.h" // RenderTargetSizeMode_t and MaterialRenderTargetDepth_t definition
  16. //-----------------------------------------------------------------------------
  17. // Forward declarations
  18. //-----------------------------------------------------------------------------
  19. class IMaterial;
  20. class ITexture;
  21. class KeyValues;
  22. class KeyValues;
  23. //-----------------------------------------------------------------------------
  24. // Little utility class to deal with material references
  25. //-----------------------------------------------------------------------------
  26. class CMaterialReference
  27. {
  28. public:
  29. // constructor, destructor
  30. CMaterialReference( char const* pMaterialName = 0, const char *pTextureGroupName = 0, bool bComplain = true );
  31. ~CMaterialReference();
  32. // Attach to a material
  33. void Init( const char* pMaterialName, const char *pTextureGroupName, bool bComplain = true );
  34. void Init( const char *pMaterialName, KeyValues *pVMTKeyValues );
  35. void Init( IMaterial* pMaterial );
  36. void Init( CMaterialReference& ref );
  37. void Init( const char *pMaterialName, const char *pTextureGroupName, KeyValues *pVMTKeyValues );
  38. // Detach from a material
  39. void Shutdown();
  40. bool IsValid() { return m_pMaterial != 0; }
  41. // Automatic casts to IMaterial
  42. operator IMaterial*() { return m_pMaterial; }
  43. operator IMaterial*() const { return m_pMaterial; }
  44. operator IMaterial const*() const { return m_pMaterial; }
  45. IMaterial* operator->() { return m_pMaterial; }
  46. private:
  47. IMaterial* m_pMaterial;
  48. };
  49. //-----------------------------------------------------------------------------
  50. // Little utility class to deal with texture references
  51. //-----------------------------------------------------------------------------
  52. class CTextureReference
  53. {
  54. public:
  55. // constructor, destructor
  56. CTextureReference( );
  57. CTextureReference( const CTextureReference &ref );
  58. ~CTextureReference();
  59. // Attach to a texture
  60. void Init( char const* pTexture, const char *pTextureGroupName, bool bComplain = true );
  61. void InitProceduralTexture( const char *pTextureName, const char *pTextureGroupName, int w, int h, ImageFormat fmt, int nFlags );
  62. void InitRenderTarget( int w, int h, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, MaterialRenderTargetDepth_t depth, bool bHDR, char *pStrOptionalName = NULL );
  63. #if defined( _X360 )
  64. // used when RT coupling is disparate (texture is DDR based, surface is EDRAM based)
  65. void InitRenderTargetTexture( int width, int height, RenderTargetSizeMode_t sizeMode, ImageFormat fmt, MaterialRenderTargetDepth_t depth, bool bHDR, char *pStrOptionalName = NULL );
  66. void InitRenderTargetSurface( int width, int height, ImageFormat fmt, bool bSameAsTexture );
  67. #endif
  68. void Init( ITexture* pTexture );
  69. // Detach from a texture
  70. void Shutdown( bool bDeleteIfUnReferenced = false );
  71. bool IsValid() { return m_pTexture != 0; }
  72. // Automatic casts to ITexture
  73. operator ITexture*() { return m_pTexture; }
  74. operator ITexture const*() const { return m_pTexture; }
  75. ITexture* operator->() { return m_pTexture; }
  76. // Assignment operator
  77. void operator=( CTextureReference &ref );
  78. private:
  79. ITexture* m_pTexture;
  80. };
  81. #endif // !MATERIALSYSTEMUTIL_H