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.

376 lines
13 KiB

  1. //===== Copyright � 1996-2007, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Revision: $
  6. // $NoKeywords: $
  7. //
  8. // This file contains code to allow us to associate client data with bsp leaves.
  9. //
  10. //===========================================================================//
  11. #if !defined( CLIENTLEAFSYSTEM_H )
  12. #define CLIENTLEAFSYSTEM_H
  13. #ifdef _WIN32
  14. #pragma once
  15. #endif
  16. #include "igamesystem.h"
  17. #include "engine/IClientLeafSystem.h"
  18. #include "cdll_int.h"
  19. #include "ivrenderview.h"
  20. #include "tier1/mempool.h"
  21. #include "tier1/refcount.h"
  22. //-----------------------------------------------------------------------------
  23. // Forward declarations
  24. //-----------------------------------------------------------------------------
  25. struct WorldListInfo_t;
  26. class IClientRenderable;
  27. class Vector;
  28. class CGameTrace;
  29. typedef CGameTrace trace_t;
  30. struct Ray_t;
  31. class Vector2D;
  32. class CStaticProp;
  33. class CVolumeCuller;
  34. //-----------------------------------------------------------------------------
  35. // Render groups
  36. //-----------------------------------------------------------------------------
  37. enum RenderGroup_t
  38. {
  39. RENDER_GROUP_OPAQUE = 0,
  40. RENDER_GROUP_TRANSLUCENT,
  41. RENDER_GROUP_TRANSLUCENT_IGNOREZ,
  42. RENDER_GROUP_COUNT, // Indicates the groups above are real and used for bucketing a scene
  43. };
  44. //-----------------------------------------------------------------------------
  45. // Handle to an renderables in the client leaf system
  46. //-----------------------------------------------------------------------------
  47. enum
  48. {
  49. DETAIL_PROP_RENDER_HANDLE = (ClientRenderHandle_t)0xfffe
  50. };
  51. //-----------------------------------------------------------------------------
  52. // Distance fade information
  53. //-----------------------------------------------------------------------------
  54. struct DistanceFadeInfo_t
  55. {
  56. float m_flMaxDistSqr; // distance at which everything is faded out
  57. float m_flMinDistSqr; // distance at which everything is unfaded
  58. float m_flFalloffFactor; // 1.0f / ( maxDistSqr - MinDistSqr )
  59. // opacity = ( maxDist - distSqr ) * falloffFactor
  60. };
  61. class CClientRenderablesList : public CRefCounted<>
  62. {
  63. DECLARE_FIXEDSIZE_ALLOCATOR( CClientRenderablesList );
  64. public:
  65. CClientRenderablesList()
  66. {
  67. int i;
  68. for( i=0; i < RENDER_GROUP_COUNT; i++ )
  69. {
  70. m_RenderGroupCounts[i] = 0;
  71. }
  72. m_nBoneSetupDependencyCount = 0;
  73. }
  74. enum
  75. {
  76. MAX_GROUP_ENTITIES = 4096,
  77. MAX_BONE_SETUP_DEPENDENCY = 64,
  78. };
  79. struct CEntry
  80. {
  81. IClientRenderable *m_pRenderable;
  82. unsigned short m_iWorldListInfoLeaf; // NOTE: this indexes WorldListInfo_t's leaf list.
  83. RenderableInstance_t m_InstanceData;
  84. uint8 m_nModelType : 6; // See RenderableModelType_t
  85. uint8 m_bShadowDepthNoCache : 1; // the renderable cannot be cached in shadow depth cache
  86. uint8 m_TwoPass : 1;
  87. bool m_bIsCombinedModel;
  88. };
  89. // The leaves for the entries are in the order of the leaves you call CollateRenderablesInLeaf in.
  90. DistanceFadeInfo_t m_DetailFade;
  91. CEntry m_RenderGroups[RENDER_GROUP_COUNT][MAX_GROUP_ENTITIES];
  92. int m_RenderGroupCounts[RENDER_GROUP_COUNT];
  93. int m_nBoneSetupDependencyCount;
  94. IClientRenderable *m_pBoneSetupDependency[MAX_BONE_SETUP_DEPENDENCY];
  95. };
  96. struct ViewmodelRenderableInstance_t : public RenderableInstance_t
  97. {
  98. uint8 m_bTwoPass;
  99. };
  100. //-----------------------------------------------------------------------------
  101. // Render list for viewmodels
  102. //-----------------------------------------------------------------------------
  103. class CViewModelRenderablesList
  104. {
  105. public:
  106. enum
  107. {
  108. VM_GROUP_OPAQUE = 0,
  109. VM_GROUP_TRANSLUCENT,
  110. VM_GROUP_COUNT,
  111. };
  112. struct CEntry
  113. {
  114. IClientRenderable *m_pRenderable;
  115. ViewmodelRenderableInstance_t m_InstanceData;
  116. };
  117. typedef CUtlVectorFixedGrowable< CEntry, 32 > RenderGroups_t;
  118. // The leaves for the entries are in the order of the leaves you call CollateRenderablesInLeaf in.
  119. RenderGroups_t m_RenderGroups[VM_GROUP_COUNT];
  120. };
  121. //-----------------------------------------------------------------------------
  122. // Used to do batched screen size computations
  123. //-----------------------------------------------------------------------------
  124. struct ScreenSizeComputeInfo_t
  125. {
  126. VMatrix m_matViewProj;
  127. Vector m_vecViewUp;
  128. int m_nViewportHeight;
  129. };
  130. void ComputeScreenSizeInfo( ScreenSizeComputeInfo_t *pInfo );
  131. float ComputeScreenSize( const Vector &vecOrigin, float flRadius, const ScreenSizeComputeInfo_t& info );
  132. //-----------------------------------------------------------------------------
  133. // Used by CollateRenderablesInLeaf
  134. //-----------------------------------------------------------------------------
  135. struct SetupRenderInfo_t
  136. {
  137. mutable WorldListInfo_t * m_pWorldListInfo;
  138. mutable CClientRenderablesList *m_pRenderList;
  139. Vector m_vecRenderOrigin;
  140. Vector m_vecRenderForward;
  141. int m_nRenderFrame;
  142. int m_nDetailBuildFrame; // The "render frame" for detail objects
  143. float m_flRenderDistSq;
  144. int m_nViewID;
  145. int m_nBuildViewID;
  146. int m_nOcclustionViewID;
  147. mutable const CVolumeCuller * m_pCSMVolumeCuller;
  148. mutable const Frustum_t* m_pFrustum;
  149. mutable Frustum_t** m_ppFrustumList;
  150. ScreenSizeComputeInfo_t m_screenSizeInfo;
  151. bool m_bDrawDetailObjects : 1;
  152. bool m_bDrawTranslucentObjects : 1;
  153. bool m_bFastEntityRendering: 1;
  154. bool m_bDrawDepthViewNonCachedObjectsOnly : 1;
  155. bool m_bCSMView : 1;
  156. SetupRenderInfo_t()
  157. {
  158. m_pWorldListInfo = NULL;
  159. m_pRenderList = NULL;
  160. m_pCSMVolumeCuller = NULL;
  161. m_pFrustum = NULL;
  162. m_ppFrustumList = NULL;
  163. m_nBuildViewID = -1;
  164. m_nOcclustionViewID = -1;
  165. m_bDrawDetailObjects = true;
  166. m_bDrawTranslucentObjects = true;
  167. m_bFastEntityRendering = false;
  168. m_bDrawDepthViewNonCachedObjectsOnly = false;
  169. m_bCSMView = false;
  170. }
  171. };
  172. //-----------------------------------------------------------------------------
  173. // A handle associated with shadows managed by the client leaf system
  174. //-----------------------------------------------------------------------------
  175. typedef unsigned short ClientLeafShadowHandle_t;
  176. enum
  177. {
  178. CLIENT_LEAF_SHADOW_INVALID_HANDLE = (ClientLeafShadowHandle_t)~0
  179. };
  180. //-----------------------------------------------------------------------------
  181. // The client leaf system
  182. //-----------------------------------------------------------------------------
  183. abstract_class IClientLeafShadowEnum
  184. {
  185. public:
  186. // The user ID is the id passed into CreateShadow
  187. virtual void EnumShadow( ClientShadowHandle_t userId ) = 0;
  188. };
  189. // subclassed by things which wish to add per-leaf data managed by the client leafsystem
  190. class CClientLeafSubSystemData
  191. {
  192. public:
  193. virtual ~CClientLeafSubSystemData( void )
  194. {
  195. }
  196. };
  197. // defines for subsystem ids. each subsystem id uses up one pointer in each leaf
  198. #define CLSUBSYSTEM_DETAILOBJECTS 0
  199. #define N_CLSUBSYSTEMS 1
  200. //-----------------------------------------------------------------------------
  201. // The client leaf system
  202. //-----------------------------------------------------------------------------
  203. abstract_class IClientLeafSystem : public IClientLeafSystemEngine, public IGameSystemPerFrame
  204. {
  205. public:
  206. // Adds and removes renderables from the leaf lists
  207. virtual void AddRenderable( IClientRenderable* pRenderable, bool bRenderWithViewModels, RenderableTranslucencyType_t nType, RenderableModelType_t nModelType, uint32 nSplitscreenEnabled = 0xFFFFFFFF ) = 0;
  208. // This tells if the renderable is in the current PVS. It assumes you've updated the renderable
  209. // with RenderableChanged() calls
  210. virtual bool IsRenderableInPVS( IClientRenderable *pRenderable ) = 0;
  211. virtual void SetSubSystemDataInLeaf( int leaf, int nSubSystemIdx, CClientLeafSubSystemData *pData ) =0;
  212. virtual CClientLeafSubSystemData *GetSubSystemDataInLeaf( int leaf, int nSubSystemIdx ) =0;
  213. virtual void SetDetailObjectsInLeaf( int leaf, int firstDetailObject, int detailObjectCount ) = 0;
  214. virtual void GetDetailObjectsInLeaf( int leaf, int& firstDetailObject, int& detailObjectCount ) = 0;
  215. // Indicates which leaves detail objects should be rendered from, returns the detais objects in the leaf
  216. virtual void DrawDetailObjectsInLeaf( int leaf, int frameNumber, int& firstDetailObject, int& detailObjectCount ) = 0;
  217. // Should we draw detail objects (sprites or models) in this leaf (because it's close enough to the view)
  218. // *and* are there any objects in the leaf?
  219. virtual bool ShouldDrawDetailObjectsInLeaf( int leaf, int frameNumber ) = 0;
  220. // Call this when a renderable origin/angles/bbox parameters has changed
  221. virtual void RenderableChanged( ClientRenderHandle_t handle ) = 0;
  222. // Put renderables into their appropriate lists.
  223. virtual void BuildRenderablesList( const SetupRenderInfo_t &info ) = 0;
  224. #if defined(_PS3)
  225. virtual void BuildRenderablesList_PS3_Epilogue( void ) = 0;
  226. #endif
  227. // Put renderables in the leaf into their appropriate lists.
  228. virtual void CollateViewModelRenderables( CViewModelRenderablesList *pList ) = 0;
  229. // Call this to deactivate static prop rendering..
  230. virtual void DrawStaticProps( bool enable ) = 0;
  231. // Call this to deactivate small object rendering
  232. virtual void DrawSmallEntities( bool enable ) = 0;
  233. // The following methods are related to shadows...
  234. virtual ClientLeafShadowHandle_t AddShadow( ClientShadowHandle_t userId, unsigned short flags ) = 0;
  235. virtual void RemoveShadow( ClientLeafShadowHandle_t h ) = 0;
  236. // Project a shadow
  237. virtual void ProjectShadow( ClientLeafShadowHandle_t handle, int nLeafCount, const int *pLeafList ) = 0;
  238. // Project a projected texture spotlight
  239. virtual void ProjectFlashlight( ClientLeafShadowHandle_t handle, int nLeafCount, const int *pLeafList ) = 0;
  240. // Find all shadow casters in a set of leaves
  241. virtual void EnumerateShadowsInLeaves( int leafCount, WorldListLeafData_t* pLeaves, IClientLeafShadowEnum* pEnum ) = 0;
  242. // Fill in a list of the leaves this renderable is in.
  243. // Returns -1 if the handle is invalid.
  244. virtual int GetRenderableLeaves( ClientRenderHandle_t handle, int leaves[128] ) = 0;
  245. // Get leaves this renderable is in
  246. virtual bool GetRenderableLeaf ( ClientRenderHandle_t handle, int* pOutLeaf, const int* pInIterator = 0, int* pOutIterator = 0 ) = 0;
  247. // Draw translucent objects in the opaque renderables pass
  248. virtual void EnableForceOpaquePass( ClientRenderHandle_t handle, bool bEnable ) = 0;
  249. virtual bool IsEnableForceOpaquePass( ClientRenderHandle_t handle ) const = 0;
  250. // Use alternate translucent sorting algorithm (draw translucent objects in the furthest leaf they lie in)
  251. virtual void EnableAlternateSorting( ClientRenderHandle_t handle, bool bEnable ) = 0;
  252. // Mark this as rendering with viewmodels
  253. virtual void RenderWithViewModels( ClientRenderHandle_t handle, bool bEnable ) = 0;
  254. virtual bool IsRenderingWithViewModels( ClientRenderHandle_t handle ) const = 0;
  255. // Call this if the model changes
  256. virtual void SetTranslucencyType( ClientRenderHandle_t handle, RenderableTranslucencyType_t nType ) = 0;
  257. virtual RenderableTranslucencyType_t GetTranslucencyType( ClientRenderHandle_t handle ) const = 0;
  258. virtual void SetModelType( ClientRenderHandle_t handle, RenderableModelType_t nType = RENDERABLE_MODEL_UNKNOWN_TYPE ) = 0;
  259. virtual void EnableSplitscreenRendering( ClientRenderHandle_t handle, uint32 nFlags ) = 0;
  260. // Suppress rendering of this renderable
  261. virtual void EnableRendering( ClientRenderHandle_t handle, bool bEnable ) = 0;
  262. // Indicates this renderable should bloat its client leaf bounds over time
  263. // used for renderables with oscillating bounds to reduce the cost of
  264. // them reinserting themselves into the tree over and over.
  265. virtual void EnableBloatedBounds( ClientRenderHandle_t handle, bool bEnable ) = 0;
  266. // Indicates this renderable should always recompute its bounds accurately
  267. virtual void DisableCachedRenderBounds( ClientRenderHandle_t handle, bool bDisable ) = 0;
  268. // Recomputes which leaves renderables are in
  269. virtual void RecomputeRenderableLeaves() = 0;
  270. // Warns about leaf reinsertion
  271. virtual void DisableLeafReinsertion( bool bDisable ) = 0;
  272. //Assuming the renderable would be in a properly built render list, generate a render list entry
  273. virtual RenderGroup_t GenerateRenderListEntry( IClientRenderable *pRenderable, CClientRenderablesList::CEntry &entryOut ) = 0;
  274. // Get renderable that render bound intersect with the query box
  275. virtual int GetEntitiesInBox( C_BaseEntity **pEntityList, int listMax, const Vector& vWorldSpaceMins, const Vector& vWorldSpaceMaxs ) = 0;
  276. // Mark as rendering in the reflection
  277. virtual bool IsRenderingInFastReflections( ClientRenderHandle_t handle ) const = 0;
  278. // Enable/disable rendering into the shadow depth buffer
  279. virtual void DisableShadowDepthRendering( ClientRenderHandle_t handle, bool bDisable ) = 0;
  280. // Enable/disable rendering into the CSM buffer and rendering usig CSM's
  281. virtual void DisableCSMRendering( ClientRenderHandle_t handle, bool bDisable ) = 0;
  282. // Enable/disable caching in the shadow depth buffer
  283. virtual void DisableShadowDepthCaching( ClientRenderHandle_t handle, bool bDisable ) = 0;
  284. virtual void ComputeAllBounds( void ) = 0;
  285. #if defined(_PS3)
  286. virtual void PrepRenderablesListForSPU( void ) = 0;
  287. #endif
  288. };
  289. //-----------------------------------------------------------------------------
  290. // Singleton accessor
  291. //-----------------------------------------------------------------------------
  292. extern IClientLeafSystem *g_pClientLeafSystem;
  293. inline IClientLeafSystem* ClientLeafSystem()
  294. {
  295. return g_pClientLeafSystem;
  296. }
  297. #endif // CLIENTLEAFSYSTEM_H