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.

184 lines
5.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // A class representing a procedural texture
  4. //
  5. //=============================================================================
  6. #ifndef DMETEXTURE_H
  7. #define DMETEXTURE_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmelement.h"
  12. #include "materialsystem/MaterialSystemUtil.h"
  13. #include "movieobjects/dmeimage.h"
  14. //-----------------------------------------------------------------------------
  15. // Forward declarations
  16. //-----------------------------------------------------------------------------
  17. class ITexture;
  18. class IMesh;
  19. enum ImageFormat;
  20. class IVTFTexture;
  21. //-----------------------------------------------------------------------------
  22. // Compression types
  23. //-----------------------------------------------------------------------------
  24. enum DmeTextureCompress_t
  25. {
  26. DMETEXTURE_COMPRESS_DEFAULT = 0,
  27. DMETEXTURE_COMPRESS_NONE,
  28. DMETEXTURE_COMPRESS_DXT1,
  29. DMETEXTURE_COMPRESS_DXT5,
  30. };
  31. //-----------------------------------------------------------------------------
  32. // Filter types
  33. //-----------------------------------------------------------------------------
  34. enum DmeTextureFilter_t
  35. {
  36. DMETEXTURE_FILTER_DEFAULT = 0,
  37. DMETEXTURE_FILTER_ANISOTROPIC,
  38. DMETEXTURE_FILTER_TRILINEAR,
  39. DMETEXTURE_FILTER_BILINEAR,
  40. DMETEXTURE_FILTER_POINT,
  41. };
  42. //-----------------------------------------------------------------------------
  43. // Mipmap types
  44. //-----------------------------------------------------------------------------
  45. enum DmeTextureMipmap_t
  46. {
  47. DMETEXTURE_MIPMAP_DEFAULT = 0,
  48. DMETEXTURE_MIPMAP_ALL_LEVELS,
  49. DMETEXTURE_MIPMAP_NONE,
  50. };
  51. //-----------------------------------------------------------------------------
  52. // A base class for textures
  53. //-----------------------------------------------------------------------------
  54. class CDmeBaseTexture : public CDmElement
  55. {
  56. DEFINE_ELEMENT( CDmeBaseTexture, CDmElement );
  57. public:
  58. ITexture *GetCachedTexture();
  59. // Compression type
  60. void SetCompressionType( DmeTextureCompress_t type );
  61. DmeTextureCompress_t GetCompressionType() const;
  62. // Filter type
  63. void SetFilterType( DmeTextureFilter_t type );
  64. DmeTextureFilter_t GetFilterType() const;
  65. // Mipmap type
  66. void SetMipmapType( DmeTextureMipmap_t type );
  67. DmeTextureMipmap_t GetMipmapType() const;
  68. public:
  69. CDmAttributeVar<bool> m_bClampS;
  70. CDmAttributeVar<bool> m_bClampT;
  71. CDmAttributeVar<bool> m_bClampU;
  72. CDmAttributeVar<bool> m_bNoDebugOverride;
  73. CDmAttributeVar<bool> m_bNoLod;
  74. CDmAttributeVar<bool> m_bNiceFiltered;
  75. CDmAttributeVar<bool> m_bNormalMap;
  76. CDmAttributeVar<float> m_flBumpScale;
  77. protected:
  78. // Computes texture flags
  79. int CalcTextureFlags( int nDepth ) const;
  80. // Computes the desired texture format based on flags
  81. ImageFormat ComputeDesiredImageFormat( ImageFormat srcFormat, int nWidth, int nHeight, int nDepth, int nFlags );
  82. CDmAttributeVar<int> m_nCompressType;
  83. CDmAttributeVar<int> m_nFilterType;
  84. CDmAttributeVar<int> m_nMipmapType;
  85. // Computed values
  86. CTextureReference m_Texture;
  87. IVTFTexture *m_pVTFTexture;
  88. Vector m_vecReflectivity;
  89. };
  90. //-----------------------------------------------------------------------------
  91. // Inline methods
  92. //-----------------------------------------------------------------------------
  93. inline void CDmeBaseTexture::SetCompressionType( DmeTextureCompress_t type )
  94. {
  95. m_nCompressType = type;
  96. }
  97. inline DmeTextureCompress_t CDmeBaseTexture::GetCompressionType() const
  98. {
  99. return (DmeTextureCompress_t)m_nCompressType.Get();
  100. }
  101. inline void CDmeBaseTexture::SetFilterType( DmeTextureFilter_t type )
  102. {
  103. m_nFilterType = type;
  104. }
  105. inline DmeTextureFilter_t CDmeBaseTexture::GetFilterType() const
  106. {
  107. return (DmeTextureFilter_t)m_nFilterType.Get();
  108. }
  109. inline void CDmeBaseTexture::SetMipmapType( DmeTextureMipmap_t type )
  110. {
  111. m_nMipmapType = type;
  112. }
  113. inline DmeTextureMipmap_t CDmeBaseTexture::GetMipmapType() const
  114. {
  115. return (DmeTextureMipmap_t)m_nMipmapType.Get();
  116. }
  117. //-----------------------------------------------------------------------------
  118. // A class representing a texture
  119. //-----------------------------------------------------------------------------
  120. class CDmeTexture : public CDmeBaseTexture
  121. {
  122. DEFINE_ELEMENT( CDmeTexture, CDmeBaseTexture );
  123. public:
  124. virtual void Resolve();
  125. private:
  126. // Array of images in an animated texture
  127. CDmAttributeVarElementArray< CDmeImage > m_Images;
  128. };
  129. //-----------------------------------------------------------------------------
  130. // A class representing a cube texture
  131. //-----------------------------------------------------------------------------
  132. class CDmeCubeTexture : public CDmeBaseTexture
  133. {
  134. DEFINE_ELEMENT( CDmeCubeTexture, CDmeBaseTexture );
  135. public:
  136. virtual void Resolve();
  137. private:
  138. // Array of images in an animated texture
  139. CDmAttributeVarElementArray< CDmeImage > m_ImagesPosX;
  140. CDmAttributeVarElementArray< CDmeImage > m_ImagesNegX;
  141. CDmAttributeVarElementArray< CDmeImage > m_ImagesPosY;
  142. CDmAttributeVarElementArray< CDmeImage > m_ImagesNegY;
  143. CDmAttributeVarElementArray< CDmeImage > m_ImagesPosZ;
  144. CDmAttributeVarElementArray< CDmeImage > m_ImagesNegZ;
  145. };
  146. #endif // DMETEXTURE_H