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.

110 lines
3.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef R_AREAPORTAL_H
  8. #define R_AREAPORTAL_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "utlvector.h"
  13. #include "gl_model_private.h"
  14. class Frustum_t;
  15. // Used to clip area portals. The coordinates here are in normalized
  16. // view space (-1,-1) - (1,1)
  17. // BUGBUG: NOTE!!!: These are left->right, and bottom->top, so a full rect is left=-1,top=1,right=1,bottom=-1
  18. class CPortalRect
  19. {
  20. public:
  21. float left, top, right, bottom;
  22. };
  23. // ---------------------------------------------------------------------------- //
  24. // Functions.
  25. // ---------------------------------------------------------------------------- //
  26. // Copies GetBaseLocalClient().pAreaBits, finds the area the viewer is in, and figures out what
  27. // other areas are visible. The new bits are placed in g_RenderAreaBits.
  28. void R_SetupAreaBits( int iForceViewLeaf = -1, const VisOverrideData_t* pVisData = NULL, float *pWaterReflectionHeight = NULL );
  29. // Ask if an area is visible to the renderer.
  30. unsigned char R_IsAreaVisible( int area );
  31. void R_Areaportal_LevelInit();
  32. void R_Areaportal_LevelShutdown();
  33. inline bool CullNodeSIMD( const Frustum_t &frustum, mnode_t *pNode )
  34. {
  35. fltx4 center4 = LoadAlignedSIMD( pNode->m_vecCenter );
  36. fltx4 centerx = SplatXSIMD(center4);
  37. fltx4 centery = SplatYSIMD(center4);
  38. fltx4 centerz = SplatZSIMD(center4);
  39. fltx4 extents4 = LoadAlignedSIMD( pNode->m_vecHalfDiagonal );
  40. fltx4 extx = SplatXSIMD(extents4);
  41. fltx4 exty = SplatYSIMD(extents4);
  42. fltx4 extz = SplatZSIMD(extents4);
  43. // compute the dot product of the normal and the farthest corner
  44. for ( int i = 0; i < 2; i++ )
  45. {
  46. fltx4 xTotalBack = AddSIMD( MulSIMD( frustum.planes[i].nX, centerx ), MulSIMD(frustum.planes[i].nXAbs, extx ) );
  47. fltx4 yTotalBack = AddSIMD( MulSIMD( frustum.planes[i].nY, centery ), MulSIMD(frustum.planes[i].nYAbs, exty ) );
  48. fltx4 zTotalBack = AddSIMD( MulSIMD( frustum.planes[i].nZ, centerz ), MulSIMD(frustum.planes[i].nZAbs, extz ) );
  49. fltx4 dotBack = AddSIMD( xTotalBack, AddSIMD(yTotalBack, zTotalBack) );
  50. // if plane of the farthest corner is behind the plane, then the box is completely outside this plane
  51. #if defined( _X360 )
  52. if ( !XMVector3GreaterOrEqual( dotBack, frustum.planes[i].dist ) )
  53. return true;
  54. #elif defined( _PS3 )
  55. if ( vec_any_lt( dotBack, frustum.planes[i].dist ) )
  56. return true;
  57. #else
  58. fltx4 isOut = ( fltx4 ) CmpLtSIMD( dotBack, frustum.planes[i].dist );
  59. if ( IsAnyTrue( isOut ) )
  60. return true;
  61. #endif
  62. }
  63. return false;
  64. }
  65. // Decides if the node can be seen through the area portals (ie: if you're
  66. // looking out a window with an areaportal in it, this will clip out the
  67. // stuff to the sides).
  68. bool R_CullNode( mnode_t *pNode );
  69. const Frustum_t* GetAreaFrustum( int area );
  70. // get a list of all area frustums
  71. int GetAllAreaFrustums( Frustum_t **pFrustumList, int listMax );
  72. bool R_ShouldUseAreaFrustum( int area );
  73. // ---------------------------------------------------------------------------- //
  74. // Globals.
  75. // ---------------------------------------------------------------------------- //
  76. extern ConVar r_DrawPortals;
  77. // Used when r_DrawPortals is on. Draws the screen space rects for each portal.
  78. extern CUtlVector<CPortalRect> g_PortalRects;
  79. // ---------------------------------------------------------------------------- //
  80. // Inlines.
  81. // ---------------------------------------------------------------------------- //
  82. inline unsigned char R_IsAreaVisible( int area )
  83. {
  84. extern unsigned char g_RenderAreaBits[32];
  85. return g_RenderAreaBits[area>>3] & GetBitForBitnum(area&7);
  86. }
  87. #endif // R_AREAPORTAL_H