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.

194 lines
5.0 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // A class representing draw settings for Dme things
  4. //
  5. //=============================================================================
  6. #ifndef DMEDRAWSETTINGS_H
  7. #define DMEDRAWSETTINGS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "datamodel/dmelement.h"
  12. #include "materialsystem/MaterialSystemUtil.h"
  13. #include "tier1/utlstack.h"
  14. //-----------------------------------------------------------------------------
  15. //
  16. //-----------------------------------------------------------------------------
  17. class CDmeDag;
  18. //-----------------------------------------------------------------------------
  19. //
  20. //-----------------------------------------------------------------------------
  21. class CDmeDrawSettings : public CDmElement
  22. {
  23. DEFINE_ELEMENT( CDmeDrawSettings, CDmElement );
  24. public:
  25. enum DrawType_t
  26. {
  27. DRAW_INVALID = -1,
  28. DRAW_SMOOTH,
  29. DRAW_FLAT,
  30. DRAW_WIREFRAME,
  31. DRAW_BOUNDINGBOX,
  32. STANDARD_DRAW_COUNT
  33. };
  34. // resolve internal data from changed attributes
  35. virtual void Resolve();
  36. DrawType_t GetDrawType() const;
  37. DrawType_t SetDrawType( int drawType );
  38. void PushDrawType();
  39. void PopDrawType();
  40. bool Shaded() const {
  41. const DrawType_t drawType = GetDrawType();
  42. return drawType == DRAW_SMOOTH || drawType == DRAW_FLAT;
  43. }
  44. bool GetBackfaceCulling() const { return m_bBackfaceCulling.Get(); }
  45. void SetBackfaceCulling( bool val ) { m_bBackfaceCulling.Set( val ); }
  46. bool GetWireframeOnShaded() const { return m_bWireframeOnShaded.Get(); }
  47. void SetWireframeOnShaded( bool val ) { m_bWireframeOnShaded.Set( val ); }
  48. bool GetXRay() const { return m_bXRay.Get(); }
  49. void SetXRay( bool val ) { m_bXRay.Set( val ); }
  50. bool GetGrayShade() const { return m_bGrayShade.Get(); }
  51. void SetGrayShade( bool val ) { m_bGrayShade.Set( val ); }
  52. bool GetNormals() const { return m_bNormals.Get(); }
  53. void SetNormals( bool val ) { m_bNormals.Set( val ); }
  54. float GetNormalLength() const { return m_NormalLength.Get(); }
  55. void SetNormalLength( float val ) { m_NormalLength.Set( val ); }
  56. const Color &GetColor() const { return m_Color.Get(); }
  57. void SetColor( Color val ) { m_Color.Set( val ); }
  58. bool Drawable( CDmElement *pElement );
  59. void BindWireframe();
  60. void BindWireframeOnShaded();
  61. void BindGray();
  62. void BindUnlitGray();
  63. bool GetDeltaHighlight() const { return m_bDeltaHighlight; }
  64. void SetDeltaHighlight( bool bDeltaHighlight ) { m_bDeltaHighlight.Set( bDeltaHighlight ); }
  65. bool IsAMaterialBound() const {
  66. return m_IsAMaterialBound;
  67. }
  68. void DrawDag( CDmeDag *pDag );
  69. CUtlVector< Vector > &GetHighlightPoints() { return m_vHighlightPoints; }
  70. public:
  71. CDmaVar< int > m_DrawType;
  72. CDmaVar< bool > m_bBackfaceCulling;
  73. CDmaVar< bool > m_bWireframeOnShaded;
  74. CDmaVar< bool > m_bXRay;
  75. CDmaVar< bool > m_bGrayShade;
  76. CDmaVar< bool > m_bNormals;
  77. CDmaVar< float > m_NormalLength;
  78. CDmaVar< Color > m_Color;
  79. CDmaVar< bool > m_bDeltaHighlight;
  80. CDmaVar< float > m_flHighlightSize;
  81. CDmaVar< Color > m_cHighlightColor;
  82. protected:
  83. void BuildKnownDrawableTypes();
  84. static bool s_bWireframeMaterialInitialized;
  85. static CMaterialReference s_WireframeMaterial;
  86. static bool s_bWireframeOnShadedMaterialInitialized;
  87. static CMaterialReference s_WireframeOnShadedMaterial;
  88. static bool s_bFlatGrayMaterial;
  89. static CMaterialReference s_FlatGrayMaterial;
  90. static bool s_bUnlitGrayMaterial;
  91. static CMaterialReference s_UnlitGrayMaterial;
  92. static CUtlRBTree< CUtlSymbol > s_KnownDrawableTypes;
  93. CUtlRBTree< CUtlSymbol > m_NotDrawable;
  94. CUtlStack< DrawType_t > m_drawTypeStack;
  95. bool m_IsAMaterialBound;
  96. // Points to highlight
  97. CUtlVector< Vector > m_vHighlightPoints;
  98. };
  99. //-----------------------------------------------------------------------------
  100. //
  101. //-----------------------------------------------------------------------------
  102. inline CDmeDrawSettings::DrawType_t CDmeDrawSettings::SetDrawType( int drawType )
  103. {
  104. if ( drawType < 0 || drawType >= STANDARD_DRAW_COUNT )
  105. {
  106. drawType = DRAW_SMOOTH;
  107. }
  108. m_DrawType.Set( drawType );
  109. return GetDrawType();
  110. }
  111. //-----------------------------------------------------------------------------
  112. //
  113. //-----------------------------------------------------------------------------
  114. inline CDmeDrawSettings::DrawType_t CDmeDrawSettings::GetDrawType() const
  115. {
  116. const int drawType( m_DrawType.Get() );
  117. if ( drawType < 0 || drawType >= STANDARD_DRAW_COUNT )
  118. return DRAW_SMOOTH;
  119. return static_cast< DrawType_t >( drawType );
  120. }
  121. //-----------------------------------------------------------------------------
  122. //
  123. //-----------------------------------------------------------------------------
  124. inline void CDmeDrawSettings::PushDrawType()
  125. {
  126. m_drawTypeStack.Push( GetDrawType() );
  127. }
  128. //-----------------------------------------------------------------------------
  129. //
  130. //-----------------------------------------------------------------------------
  131. inline void CDmeDrawSettings::PopDrawType()
  132. {
  133. if ( m_drawTypeStack.Count() )
  134. {
  135. DrawType_t drawType = GetDrawType();
  136. m_drawTypeStack.Pop( drawType );
  137. SetDrawType( drawType );
  138. }
  139. }
  140. #endif // DMEDRAWSETTINGS_H