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.

100 lines
3.6 KiB

  1. //============ Copyright (c) Valve Corporation, All rights reserved. ============
  2. #ifndef VOLUME_CULLER_H
  3. #define VOLUME_CULLER_H
  4. #ifdef _WIN32
  5. #pragma once
  6. #endif
  7. #include "vector.h"
  8. #include "vplane.h"
  9. #include "ssemath.h"
  10. class CVolumeCuller : public CAlignedNewDelete< 16 >
  11. {
  12. public:
  13. inline CVolumeCuller() { Clear(); }
  14. inline void Clear() { m_nNumInclusionVolumePlanes = 0; m_bHasExclusionFrustum = false; m_bHasBaseFrustum = false; m_bCullSmallObjects = false; ClearCullCheckStats(); }
  15. inline bool IsValid() const { return m_bHasExclusionFrustum || ( m_nNumInclusionVolumePlanes != 0 ); }
  16. // Returns false if box is culled.
  17. bool CheckBox( const VectorAligned &mins, const VectorAligned &maxs ) const;
  18. bool CheckBox( const Vector &mins, const Vector &maxs ) const;
  19. bool CheckBoxCenterHalfDiagonal( const VectorAligned &center, const VectorAligned &halfDiagonal ) const;
  20. enum
  21. {
  22. cNumBaseFrustumPlanes = 6,
  23. cNumExclusionFrustumPlanes = 6,
  24. // cMaxInclusionVolumePlanes must at least have enough room to hold the planes output by CSunLightManager::ComputeCullingVolumePlanes().
  25. cMaxInclusionVolumePlanes = 12
  26. };
  27. // Base frustum
  28. inline bool HasBaseFrustum() const { return m_bHasBaseFrustum; }
  29. // Specify NULL to disable the base frustum.
  30. void SetBaseFrustumPlanes( const VPlane *pPlanes );
  31. void GetBaseFrustumPlanes( VPlane *pBasePlanes ) const;
  32. int GetNumBaseFrustumPlanes() const { return cNumBaseFrustumPlanes; }
  33. // Exclusion frustum
  34. inline bool HasExclusionFrustum() const { return m_bHasExclusionFrustum; }
  35. // Specify NULL to disable the exclusion frustum.
  36. void SetExclusionFrustumPlanes( const VPlane *pPlanes );
  37. int GetNumExclusionFrustumPlanes() const { return cNumExclusionFrustumPlanes; }
  38. const fltx4 *GetExclusionFrustumPlanes() const { return m_ExclusionFrustumPlanes; }
  39. // Inclusion volume
  40. inline bool HasInclusionVolume() const { return m_nNumInclusionVolumePlanes != 0; }
  41. // Specify NULL to disable the inclusion volume.
  42. void SetInclusionVolumePlanes( const VPlane *pPlanes, uint nNumPlanes );
  43. int GetNumInclusionVolumePlanes() const { return m_nNumInclusionVolumePlanes; }
  44. const fltx4 *GetInclusionVolumePlanes() const { return m_InclusionVolumePlanes; }
  45. bool GetCullSmallObjects() const { return m_bCullSmallObjects; }
  46. float GetSmallObjectCullVolumeThreshold() const { return m_flSmallObjectCullVolumeThreshold; }
  47. void SetCullSmallObjects(bool bCullSmallObjects, float flCullVolumeThreshold ) { m_bCullSmallObjects = bCullSmallObjects; m_flSmallObjectCullVolumeThreshold = flCullVolumeThreshold; }
  48. struct CullCheckStats_t
  49. {
  50. uint m_nTotalAABB;
  51. uint m_nTotalAABBPassed;
  52. uint m_nTotalCenterHalfDiagonal;
  53. uint m_nTotalCenterHalfDiagonalPassed;
  54. };
  55. inline void ClearCullCheckStats() { memset( &m_Stats, 0, sizeof( m_Stats ) ); }
  56. inline CullCheckStats_t &GetStats() const { return m_Stats; }
  57. private:
  58. // Objects which are not inside or touch the base planes are culled.
  59. fourplanes_t m_baseplanes[2];
  60. // Objects totally within the exclusion frustum are culled (i.e. anything completely inside the exclusion region must be culled).
  61. fltx4 m_ExclusionFrustumPlanes[cNumExclusionFrustumPlanes];
  62. // Objects totally outside of the inclusion region are culled (i.e. anything touching or inside the occlusion region cannot be culled).
  63. fltx4 m_InclusionVolumePlanes[cMaxInclusionVolumePlanes];
  64. uint m_nNumInclusionVolumePlanes;
  65. bool m_bHasBaseFrustum : 1;
  66. bool m_bHasExclusionFrustum : 1;
  67. bool m_bCullSmallObjects : 1;
  68. float m_flSmallObjectCullVolumeThreshold;
  69. mutable CullCheckStats_t m_Stats;
  70. };
  71. #endif // VOLUME_CULLER_H