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.

869 lines
28 KiB

  1. //===== Copyright 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. //===========================================================================//
  6. #if !defined( VIEWRENDER_H )
  7. #define VIEWRENDER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "shareddefs.h"
  12. #include "tier1/utlstack.h"
  13. #include "tier2/tier2.h"
  14. #include "iviewrender.h"
  15. #include "view_shared.h"
  16. #if defined(_PS3)
  17. #include "buildrenderables_ps3.h"
  18. #endif
  19. #include "mathlib/volumeculler.h"
  20. #include "vstdlib/jobthread.h"
  21. //-----------------------------------------------------------------------------
  22. // Forward declarations
  23. //-----------------------------------------------------------------------------
  24. class ConVar;
  25. class CClientRenderablesList;
  26. class IClientVehicle;
  27. class C_PointCamera;
  28. class C_EnvProjectedTexture;
  29. class IScreenSpaceEffect;
  30. class CClientViewSetup;
  31. class CViewRender;
  32. struct ClientWorldListInfo_t;
  33. class C_BaseEntity;
  34. class CJob;
  35. #ifdef HL2_EPISODIC
  36. class CStunEffect;
  37. #endif // HL2_EPISODIC
  38. //-----------------------------------------------------------------------------
  39. // Data specific to intro mode to control rendering.
  40. //-----------------------------------------------------------------------------
  41. struct IntroDataBlendPass_t
  42. {
  43. int m_BlendMode;
  44. float m_Alpha; // in [0.0f,1.0f] This needs to add up to 1.0 for all passes, unless you are fading out.
  45. };
  46. struct IntroData_t
  47. {
  48. bool m_bDrawPrimary;
  49. Vector m_vecCameraView;
  50. QAngle m_vecCameraViewAngles;
  51. float m_playerViewFOV;
  52. CUtlVector<IntroDataBlendPass_t> m_Passes;
  53. // Fade overriding for the intro
  54. float m_flCurrentFadeColor[4];
  55. };
  56. // Robin, make this point at something to get intro mode.
  57. extern IntroData_t *g_pIntroData;
  58. // This identifies the view for certain systems that are unique per view (e.g. pixel visibility)
  59. // NOTE: This is identifying which logical part of the scene an entity is being redered in
  60. // This is not identifying a particular render target necessarily. This is mostly needed for entities that
  61. // can be rendered more than once per frame (pixel vis queries need to be identified per-render call)
  62. enum view_id_t
  63. {
  64. VIEW_ILLEGAL = -2,
  65. VIEW_NONE = -1,
  66. VIEW_MAIN = 0,
  67. VIEW_3DSKY = 1,
  68. VIEW_MONITOR = 2,
  69. VIEW_REFLECTION = 3,
  70. VIEW_REFRACTION = 4,
  71. VIEW_INTRO_PLAYER = 5,
  72. VIEW_INTRO_CAMERA = 6,
  73. VIEW_SHADOW_DEPTH_TEXTURE = 7,
  74. VIEW_SSAO = 8,
  75. VIEW_ID_COUNT
  76. };
  77. view_id_t CurrentViewID();
  78. #if defined(_PS3)
  79. #define PASS_BUILDLISTS_PS3 (1<<0)
  80. #define PASS_DRAWLISTS_PS3 (1<<1)
  81. #else
  82. #define PASS_BUILDLISTS (1<<0)
  83. #define PASS_DRAWLISTS (1<<1)
  84. #endif
  85. //-----------------------------------------------------------------------------
  86. // Purpose: Stored pitch drifting variables
  87. //-----------------------------------------------------------------------------
  88. class CPitchDrift
  89. {
  90. public:
  91. float pitchvel;
  92. bool nodrift;
  93. float driftmove;
  94. double laststop;
  95. };
  96. //-----------------------------------------------------------------------------
  97. //
  98. //-----------------------------------------------------------------------------
  99. struct ViewCustomVisibility_t
  100. {
  101. ViewCustomVisibility_t()
  102. {
  103. m_nNumVisOrigins = 0;
  104. m_VisData.m_fDistToAreaPortalTolerance = FLT_MAX;
  105. m_iForceViewLeaf = -1;
  106. }
  107. void AddVisOrigin( const Vector& origin )
  108. {
  109. // Don't allow them to write past array length
  110. AssertMsg( m_nNumVisOrigins < MAX_VIS_LEAVES, "Added more origins than will fit in the array!" );
  111. // If the vis origin count is greater than the size of our array, just fail to add this origin
  112. if ( m_nNumVisOrigins >= MAX_VIS_LEAVES )
  113. return;
  114. m_rgVisOrigins[ m_nNumVisOrigins++ ] = origin;
  115. }
  116. void ForceVisOverride( VisOverrideData_t& visData )
  117. {
  118. m_VisData = visData;
  119. }
  120. void ForceViewLeaf ( int iViewLeaf )
  121. {
  122. m_iForceViewLeaf = iViewLeaf;
  123. }
  124. // Set to true if you want to use multiple origins for doing client side map vis culling
  125. // NOTE: In generaly, you won't want to do this, and by default the 3d origin of the camera, as above,
  126. // will be used as the origin for vis, too.
  127. int m_nNumVisOrigins;
  128. // Array of origins
  129. Vector m_rgVisOrigins[ MAX_VIS_LEAVES ];
  130. // The view data overrides for visibility calculations with area portals
  131. VisOverrideData_t m_VisData;
  132. // The starting leaf to determing which area to start in when performing area portal culling on the engine
  133. // Default behavior is to use the leaf the camera position is in.
  134. int m_iForceViewLeaf;
  135. };
  136. //-----------------------------------------------------------------------------
  137. //
  138. //-----------------------------------------------------------------------------
  139. struct WaterRenderInfo_t
  140. {
  141. bool m_bCheapWater : 1;
  142. bool m_bReflect : 1;
  143. bool m_bRefract : 1;
  144. bool m_bReflectEntities : 1;
  145. bool m_bReflectOnlyMarkedEntities : 1;
  146. bool m_bDrawWaterSurface : 1;
  147. bool m_bOpaqueWater : 1;
  148. bool m_bPseudoTranslucentWater : 1;
  149. bool m_bReflect2DSkybox : 1;
  150. };
  151. //-----------------------------------------------------------------------------
  152. //
  153. //-----------------------------------------------------------------------------
  154. class CBase3dView : public CRefCounted<>,
  155. protected CViewSetup
  156. {
  157. DECLARE_CLASS_NOBASE( CBase3dView );
  158. public:
  159. explicit CBase3dView( CViewRender *pMainView );
  160. VPlane * GetFrustum();
  161. virtual int GetDrawFlags() { return 0; }
  162. #ifdef PORTAL
  163. virtual void EnableWorldFog() {};
  164. #endif
  165. protected:
  166. // @MULTICORE (toml 8/11/2006): need to have per-view frustum. Change when move view stack to client
  167. VPlane *m_Frustum;
  168. CViewRender *m_pMainView;
  169. int m_nSlot;
  170. };
  171. // Frustum cache.
  172. struct FrustumCache_t
  173. {
  174. int m_nFrameCount;
  175. Frustum_t m_Frustums[MAX_SPLITSCREEN_PLAYERS];
  176. FrustumCache_t() { m_nFrameCount = 0; }
  177. bool IsValid( void ) { return ( m_nFrameCount == gpGlobals->framecount ); }
  178. void SetUpdated( void ) { m_nFrameCount = gpGlobals->framecount; }
  179. void Add( const CViewSetup *pView, int iSlot );
  180. };
  181. FrustumCache_t *FrustumCache( void );
  182. //-----------------------------------------------------------------------------
  183. // Base class for 3d views
  184. //-----------------------------------------------------------------------------
  185. class CRendering3dView : public CBase3dView
  186. {
  187. DECLARE_CLASS( CRendering3dView, CBase3dView );
  188. public:
  189. explicit CRendering3dView( CViewRender *pMainView );
  190. virtual ~CRendering3dView() { ReleaseLists(); }
  191. void Setup( const CViewSetup &setup );
  192. // What are we currently rendering? Returns a combination of DF_ flags.
  193. virtual int GetDrawFlags();
  194. virtual void Draw() {};
  195. protected:
  196. // Fog setup
  197. void EnableWorldFog( void );
  198. void SetFogVolumeState( const VisibleFogVolumeInfo_t &fogInfo, bool bUseHeightFog );
  199. // Draw setup
  200. void SetupRenderablesList( int viewID, bool bFastEntityRendering = false, bool bDrawDepthViewNonCachedObjectsOnly = false );
  201. // If iForceViewLeaf is not -1, then it uses the specified leaf as your starting area for setting up area portal culling.
  202. // This is used by water since your reflected view origin is often in solid space, but we still want to treat it as though
  203. // the first portal we're looking out of is a water portal, so our view effectively originates under the water.
  204. void BuildWorldRenderLists( bool bDrawEntities, int iForceViewLeaf = -1, bool bUseCacheIfEnabled = true, bool bShadowDepth = false, float *pReflectionWaterHeight = NULL );
  205. #if defined(_PS3)
  206. void SetupRenderablesList_PS3_Epilogue( void );
  207. void BuildWorldRenderLists_PS3_Epilogue( bool bShadowDepth );
  208. void BuildRenderableRenderLists_PS3_Epilogue( void );
  209. #else
  210. void BuildWorldRenderLists_Epilogue( bool bShadowDepth );
  211. void BuildRenderableRenderLists_Epilogue( int viewID );
  212. #endif
  213. // Purpose: Builds render lists for renderables. Called once for refraction, once for over water
  214. void BuildRenderableRenderLists( int viewID, bool bFastEntityRendering = false, bool bDrawDepthViewNonCachedObjectsOnly = false );
  215. // More concise version of the above BuildRenderableRenderLists(). Called for shadow depth map rendering
  216. void BuildShadowDepthRenderableRenderLists();
  217. void DrawWorld( IMatRenderContext *pRenderContext, float waterZAdjust );
  218. // Draws all opaque/translucent renderables in leaves that were rendered
  219. enum RenderablesRenderPath_t
  220. {
  221. RENDERABLES_RENDER_PATH_NORMAL = 0,
  222. RENDERABLES_RENDER_PATH_SHADOWDEPTH_DEFAULT = ( 1 << 0 ),
  223. RENDERABLES_RENDER_PATH_SHADOWDEPTH_BUILD_GEOCACHE = ( 1 << 1 ),
  224. RENDERABLES_RENDER_PATH_SHADOWDEPTH_USE_GEOCACHE = ( 1 << 2 ),
  225. };
  226. void DrawOpaqueRenderables( IMatRenderContext *pRenderContext, RenderablesRenderPath_t eRenderPath, ERenderDepthMode_t DepthMode, CUtlVector< CClientRenderablesList::CEntry * > *pDeferClippedOpaqueRenderables_Out, RenderGroup_t nGroup = RENDER_GROUP_OPAQUE );
  227. void DrawDeferredClippedOpaqueRenderables( IMatRenderContext *pRenderContext, RenderablesRenderPath_t eRenderPath, ERenderDepthMode_t DepthMode, CUtlVector< CClientRenderablesList::CEntry * > *pDeferClippedOpaqueRenderables );
  228. void DrawTranslucentRenderables( bool bInSkybox, bool bShadowDepth );
  229. #if defined( PORTAL )
  230. void DrawRecursivePortalViews( void );
  231. #endif
  232. // Renders all translucent entities in the render list
  233. void DrawTranslucentRenderablesNoWorld( bool bInSkybox );
  234. // Renders all translucent entities in the render list that ignore the z-buffer
  235. void DrawNoZBufferTranslucentRenderables( void );
  236. // Renders all translucent world surfaces in a particular set of leaves
  237. void DrawTranslucentWorldInLeaves( IMatRenderContext *pRenderContext, bool bShadowDepth );
  238. // Renders all translucent world + detail objects in a particular set of leaves
  239. void DrawTranslucentWorldAndDetailPropsInLeaves( IMatRenderContext *pRenderContext, int iCurLeaf, int iFinalLeaf, int nEngineDrawFlags, int &nDetailLeafCount, LeafIndex_t* pDetailLeafList, bool bShadowDepth );
  240. // Purpose: Computes the actual world list info based on the render flags
  241. void PruneWorldListInfo();
  242. // Sets up automatic z-prepass on the 360 and PS/3. No-op on PC.
  243. void BeginConsoleZPass();
  244. void EndConsoleZPass();
  245. #ifdef PORTAL
  246. virtual bool ShouldDrawPortals() { return true; }
  247. #endif
  248. void ReleaseLists();
  249. //-----------------------------------------------
  250. // Combination of DF_ flags.
  251. int m_DrawFlags;
  252. int m_ClearFlags;
  253. IWorldRenderList *m_pWorldRenderList;
  254. #if defined( CSTRIKE15 ) && defined(_PS3)
  255. CClientRenderablesList *m_pRenderablesList[ MAX_CONCURRENT_BUILDVIEWS ];
  256. ClientWorldListInfo_t *m_pWorldListInfo[ MAX_CONCURRENT_BUILDVIEWS ];
  257. #else
  258. CClientRenderablesList *m_pRenderables;
  259. ClientWorldListInfo_t *m_pWorldListInfo;
  260. #endif
  261. ViewCustomVisibility_t *m_pCustomVisibility;
  262. };
  263. //-----------------------------------------------------------------------------
  264. //
  265. //-----------------------------------------------------------------------------
  266. class CRenderExecutor
  267. {
  268. DECLARE_CLASS_NOBASE( CRenderExecutor );
  269. public:
  270. virtual void AddView( CRendering3dView *pView ) = 0;
  271. virtual void Execute() = 0;
  272. protected:
  273. explicit CRenderExecutor( CViewRender *pMainView ) : m_pMainView( pMainView ) {}
  274. CViewRender *m_pMainView;
  275. };
  276. //-----------------------------------------------------------------------------
  277. //
  278. //-----------------------------------------------------------------------------
  279. class CSimpleRenderExecutor : public CRenderExecutor
  280. {
  281. DECLARE_CLASS( CSimpleRenderExecutor, CRenderExecutor );
  282. public:
  283. explicit CSimpleRenderExecutor( CViewRender *pMainView ) : CRenderExecutor( pMainView ) {}
  284. void AddView( CRendering3dView *pView );
  285. void Execute() {}
  286. };
  287. #if defined(_PS3)
  288. //-----------------------------------------------------------------------------
  289. // For the support of parallel view building jobs (BuildWorldLists, BuildRenderables, etc)
  290. // only current true implementation on PS3 to support SPU BuildWorld/BuildRenderables jobs
  291. //-----------------------------------------------------------------------------
  292. class CConcurrentViewBuilderPS3
  293. {
  294. public:
  295. CConcurrentViewBuilderPS3();
  296. ~CConcurrentViewBuilderPS3() { Purge(); };
  297. void Init( void );
  298. void Purge( void );
  299. // for supporting concurrent view building (BuildWorldLists, BuildRenderables, etc)
  300. void ResetBuildViewID( void );
  301. // get current view index
  302. int GetBuildViewID( void );
  303. // call at the start of each view
  304. void PushBuildView( void );
  305. void PopBuildView( void );
  306. void SyncViewBuilderJobs( void );
  307. void SPUBuildRWJobsOn( bool jobOn ) { m_bSPUBuildRWJobsOn = jobOn; };
  308. bool IsSPUBuildRWJobsOn( void ) { return m_bSPUBuildRWJobsOn; };
  309. int GetPassFlags( void ) { return m_passFlags; };
  310. void SetPassFlags( int flags ) { m_passFlags = flags; };
  311. IWorldRenderList *GetWorldRenderListElement( void );
  312. void SetWorldRenderListElement( IWorldRenderList *pRenderList );
  313. int GetDrawFlags( void ) { return m_drawFlags; };
  314. void SetDrawFlags( int drawFlags ) { m_drawFlags = drawFlags; };
  315. unsigned int GetVisFlags( void );
  316. void SetVisFlags( unsigned int visFlags );
  317. void CacheFrustumData( Frustum_t *pFrustum, Frustum_t *pAreaFrustum, void *pRenderAreaBits, int numArea, bool bViewerInSolidSpace );
  318. void CacheBuildViewVolumeCuller( void *pVC );
  319. void* GetBuildViewVolumeCuller( void );
  320. Frustum_t *GetBuildViewFrustum( void );
  321. Frustum_t *GetBuildViewAreaFrustum( void );
  322. unsigned char *GetBuildViewRenderAreaBits( void );
  323. int GetNumAreaFrustum( void );
  324. Frustum_t *GetBuildViewAreaFrustumID( int frustumID );
  325. void PushBuildRenderableJobs( void );
  326. private:
  327. int m_buildViewID;
  328. int m_nextFreeBuildViewID;
  329. int* m_pBuildViewStack;
  330. int m_buildViewStack[ MAX_CONCURRENT_BUILDVIEWS ];
  331. int m_passFlags;
  332. int m_drawFlags;
  333. unsigned int m_visFlags[ MAX_CONCURRENT_BUILDVIEWS ];
  334. IWorldRenderList *m_pWorldRenderListCache[ MAX_CONCURRENT_BUILDVIEWS ] ALIGN16;
  335. // Frustum cache for Jobs
  336. Frustum_t m_gFrustum[MAX_CONCURRENT_BUILDVIEWS] ALIGN16;
  337. CUtlVector<Frustum_t> m_gAreaFrustum[MAX_CONCURRENT_BUILDVIEWS] ALIGN16;
  338. unsigned char m_gRenderAreaBits[MAX_CONCURRENT_BUILDVIEWS][32] ALIGN16;
  339. bool m_bViewerInSolidSpace[ MAX_CONCURRENT_BUILDVIEWS ] ALIGN16;
  340. CVolumeCuller m_volumeCullerCache[MAX_CONCURRENT_BUILDVIEWS] ALIGN16;
  341. bool m_bSPUBuildRWJobsOn;
  342. };
  343. extern CConcurrentViewBuilderPS3 g_viewBuilder;
  344. #else
  345. //-----------------------------------------------------------------------------
  346. // Cache all the data needed for a single view so that "BuildWorldList" and
  347. // "BuildRenderablesList" jobs are thread safe
  348. // Also holds word/renderables lists and world/renderables jobs
  349. //-----------------------------------------------------------------------------
  350. class CConcurrentViewData
  351. {
  352. public:
  353. void Init( void );
  354. void Purge( void );
  355. CVolumeCuller m_volumeCuller;
  356. Frustum_t m_Frustum;
  357. CUtlVector< Frustum_t, CUtlMemoryAligned< Frustum_t,16 > > m_AreaFrustums;
  358. Frustum_t * m_frustumList[MAX_MAP_AREAS];
  359. // Lists
  360. IWorldRenderList* m_pWorldRenderList;
  361. ClientWorldListInfo_t* m_pWorldListInfo;
  362. CClientRenderablesList* m_pRenderablesList;
  363. // Jobs
  364. CJob* m_pBuildWorldListJob;
  365. CJob* m_pBuildRenderablesListJob;
  366. bool m_bWaitForWorldList;
  367. };
  368. //-----------------------------------------------------------------------------
  369. // For the support of parallel view building jobs (BuildWorldLists, BuildRenderables, etc)
  370. //-----------------------------------------------------------------------------
  371. class CConcurrentViewBuilder
  372. {
  373. public:
  374. CConcurrentViewBuilder();
  375. ~CConcurrentViewBuilder();
  376. void Init( void );
  377. void Purge( void );
  378. void SetBuildWRThreaded( bool bThreaded ) { m_bThreaded = bThreaded; }
  379. bool GetBuildWRThreaded( void ) { return m_bThreaded; }
  380. // BuildViewID methods for supporting concurrent view building (BuildWorldLists, BuildRenderables, etc)
  381. void ResetBuildViewID( void );
  382. // get current view index
  383. int GetBuildViewID( void );
  384. // call at the start of each view
  385. void PushBuildView( void );
  386. void PopBuildView( void );
  387. int GetPassFlags( void ) { return m_passFlags; };
  388. void SetPassFlags( int flags ) { m_passFlags = flags; };
  389. // Volume cullers
  390. void CacheBuildViewVolumeCuller( const CVolumeCuller *pVC );
  391. const CVolumeCuller* GetBuildViewVolumeCuller( int buildViewID = -1 ) const ;
  392. // Frustum data
  393. void CacheFrustumData( const Frustum_t& frustum, const CUtlVector< Frustum_t, CUtlMemoryAligned< Frustum_t,16 > >& aeraFrustums );
  394. void CacheFrustumData( void );
  395. const Frustum_t* GetBuildViewFrustum( int buildViewID = -1 ) const;
  396. const CUtlVector< Frustum_t, CUtlMemoryAligned< Frustum_t,16 > >* GetBuildViewAeraFrustums( int buildViewID = -1 ) const;
  397. Frustum_t** GetBuildViewFrustumList( int buildViewID = -1 );
  398. // Lists
  399. // Note that the "Getter" will not increment the ref count of the list but the "Setter" will increment it
  400. IWorldRenderList * GetWorldRenderListElement( void );
  401. void SetWorldRenderListElement( IWorldRenderList *pRenderList );
  402. // Use the active view if buildViewID is set to -1
  403. ClientWorldListInfo_t* GetClientWorldListInfoElement( int buildViewID = -1 );
  404. WorldListInfo_t* GetWorldListInfoElement( int buildViewID );
  405. void SetWorldListInfoElement( ClientWorldListInfo_t* pWorldListInfo, int buildViewID = -1 );
  406. CClientRenderablesList* GetRenderablesListElement( int buildViewID = -1 );
  407. void SetRenderablesListElement( CClientRenderablesList* pRenderables );
  408. // Queue jobs
  409. void QueueBuildWorldListJob( CJob* pJob );
  410. void WaitForBuildWorldListJob( void );
  411. void FlushBuildWorldListJob( void );
  412. void QueueBuildRenderablesListJob( CJob* pJob );
  413. void WaitForBuildRenderablesListJob( void );
  414. void FlushBuildRenderablesListJob( void );
  415. void AddDependencyToWorldList( void );
  416. private:
  417. void AddJobToThreadPool( CJob* pJob );
  418. void AddToSequentialJobs( CJob* pJob );
  419. void TryRunSequentialJobs( void );
  420. void WaitForCurrentSequentialJobAndRunPending();
  421. void InternalWaitForBuildWorldListJob( int buildViewID );
  422. // Jobs that will run sequentially
  423. class SequentialJobs : public CJob
  424. {
  425. public:
  426. explicit SequentialJobs( CJob* pJob = NULL );
  427. ~SequentialJobs();
  428. void AddJob( CJob* pJob );
  429. virtual JobStatus_t DoExecute();
  430. private:
  431. CUtlVectorFixed<CJob *, 16> m_jobs;
  432. };
  433. bool m_bThreaded;
  434. // View stack & current view ID
  435. int m_buildViewID;
  436. int m_nextFreeBuildViewID;
  437. int* m_pBuildViewStack;
  438. int m_buildViewStack[ MAX_CONCURRENT_BUILDVIEWS ];
  439. // Flags
  440. int m_passFlags;
  441. // Cached data for each view
  442. CConcurrentViewData m_viewData[ MAX_CONCURRENT_BUILDVIEWS ];
  443. // Sequential jobs currently being executed
  444. SequentialJobs* m_pCurrentSeqJobs;
  445. // Pending sequential job - need to wait for the current one to be done before executing
  446. SequentialJobs* m_pPendingSeqJobs;
  447. // Keeps track of all jobs added to the global threadpool
  448. // We can then wait for them in Purge in case a job has been added in the build pass
  449. // but we didn't wait for it in the draw pass (because the list wasn't actually drawn)
  450. CUtlVector<CJob*> mJobsAddedToThreadPool;
  451. };
  452. extern CConcurrentViewBuilder g_viewBuilder;
  453. #endif
  454. //-----------------------------------------------------------------------------
  455. // Purpose: Implements the interface to view rendering for the client .dll
  456. //-----------------------------------------------------------------------------
  457. class CViewRender : public IViewRender
  458. {
  459. DECLARE_CLASS_NOBASE( CViewRender );
  460. public:
  461. virtual void Init( void );
  462. virtual void Shutdown( void );
  463. const CViewSetup *GetPlayerViewSetup( int nSlot = -1 ) const;
  464. virtual void StartPitchDrift( void );
  465. virtual void StopPitchDrift( void );
  466. virtual float GetZNear();
  467. virtual float GetZFar();
  468. virtual void OnRenderStart();
  469. void DriftPitch (void);
  470. static CViewRender * GetMainView() { return assert_cast<CViewRender *>( view ); }
  471. void AddViewToScene( CRendering3dView *pView ) { m_SimpleExecutor.AddView( pView ); }
  472. CMaterialReference &GetWhite();
  473. virtual void InitFadeData( void );
  474. protected:
  475. // Sets up the view parameters
  476. void SetUpView();
  477. // Sets up the view parameters of map overview mode (cl_leveloverview)
  478. void SetUpOverView();
  479. // renders the third person overview spectator mode
  480. void SetUpChaseOverview();
  481. // generates a low-res screenshot for save games
  482. virtual void WriteSaveGameScreenshotOfSize( const char *pFilename, int width, int height );
  483. void WriteSaveGameScreenshot( const char *filename );
  484. // This stores all of the view setup parameters that the engine needs to know about
  485. CViewSetup &GetView( int nSlot = -1 );
  486. const CViewSetup &GetView( int nSlot = -1 ) const;
  487. CViewSetup m_UserView[ MAX_SPLITSCREEN_PLAYERS ];
  488. bool m_bAllowViewAccess;
  489. // Pitch drifting data
  490. CPitchDrift m_PitchDrift;
  491. virtual void RenderPreScene( const CViewSetup &view ) { }
  492. virtual void PreViewDrawScene( const CViewSetup &view ) {}
  493. virtual void PostViewDrawScene( const CViewSetup &view ) {}
  494. float m_flOldChaseOverviewScale;
  495. float m_flIdealChaseOverviewScale;
  496. float m_flNextIdealOverviewScaleUpdate;
  497. public:
  498. CViewRender();
  499. virtual ~CViewRender( void ) {}
  500. // static bool IsThirdPersonOverview( void );
  501. // Implementation of IViewRender interface
  502. public:
  503. void SetupVis( const CViewSetup& view, unsigned int &visFlags, ViewCustomVisibility_t *pCustomVisibility = NULL );
  504. // Render functions
  505. virtual void Render( vrect_t *rect );
  506. virtual void RenderView( const CViewSetup &view, const CViewSetup &hudViewSetup, int nClearFlags, int whatToDraw );
  507. virtual void RenderPlayerSprites();
  508. virtual void Render2DEffectsPreHUD( const CViewSetup &view );
  509. virtual void Render2DEffectsPostHUD( const CViewSetup &view );
  510. virtual void RenderSmokeOverlay( bool bPreViewModel = true ) {};
  511. float GetLastRenderSmokeOverlayAmount() const { return m_flSmokeOverlayAmount; }
  512. void DisableFog( void );
  513. // Called once per level change
  514. void LevelInit( void );
  515. void LevelShutdown( void );
  516. // Add entity to transparent entity queue
  517. bool ShouldDrawEntities( void );
  518. bool ShouldDrawBrushModels( void );
  519. const CViewSetup *GetViewSetup( ) const;
  520. void DisableVis( void );
  521. // Sets up the view model position relative to the local player
  522. void MoveViewModels( );
  523. // Gets the abs origin + angles of the view models
  524. void GetViewModelPosition( int nIndex, Vector *pPos, QAngle *pAngle );
  525. void SetCheapWaterStartDistance( float flCheapWaterStartDistance );
  526. void SetCheapWaterEndDistance( float flCheapWaterEndDistance );
  527. void GetWaterLODParams( float &flCheapWaterStartDistance, float &flCheapWaterEndDistance );
  528. virtual void QueueOverlayRenderView( const CViewSetup &view, int nClearFlags, int whatToDraw );
  529. virtual void GetScreenFadeDistances( float *pMin, float *pMax, float *pScale );
  530. virtual C_BaseEntity *GetCurrentlyDrawingEntity();
  531. virtual void SetCurrentlyDrawingEntity( C_BaseEntity *pEnt );
  532. virtual bool UpdateShadowDepthTexture( ITexture *pRenderTarget, ITexture *pDepthTexture, const CViewSetup &shadowView, bool bRenderWorldAndObjects = true, bool bRenderViewModels = false );
  533. int GetBaseDrawFlags() { return m_BaseDrawFlags; }
  534. virtual bool ShouldForceNoVis() { return m_bForceNoVis; }
  535. int BuildRenderablesListsNumber() const { return m_BuildRenderableListsNumber; }
  536. int IncRenderablesListsNumber() { return ++m_BuildRenderableListsNumber; }
  537. int BuildWorldListsNumber() const;
  538. int IncWorldListsNumber() { return ++m_BuildWorldListsNumber; }
  539. virtual VPlane* GetFrustum() { return ( m_pActiveRenderer ) ? m_pActiveRenderer->GetFrustum() : m_Frustum; }
  540. // What are we currently rendering? Returns a combination of DF_ flags.
  541. virtual int GetDrawFlags() { return ( m_pActiveRenderer ) ? m_pActiveRenderer->GetDrawFlags() : 0; }
  542. CBase3dView * GetActiveRenderer() { return m_pActiveRenderer; }
  543. CBase3dView * SetActiveRenderer( CBase3dView *pActiveRenderer ) { CBase3dView *pPrevious = m_pActiveRenderer; m_pActiveRenderer = pActiveRenderer; return pPrevious; }
  544. void FreezeFrame( float flFreezeTime );
  545. void SetWaterOverlayMaterial( IMaterial *pMaterial )
  546. {
  547. m_UnderWaterOverlayMaterial.Init( pMaterial );
  548. }
  549. void DrawViewModelsShadowDepth( const CViewSetup &view );
  550. protected:
  551. int m_BuildWorldListsNumber;
  552. // General draw methods
  553. // baseDrawFlags is a combination of DF_ defines. DF_MONITOR is passed into here while drawing a monitor.
  554. void ViewDrawScene( bool bDrew3dSkybox, SkyboxVisibility_t nSkyboxVisible, const CViewSetup &view, int nClearFlags, view_id_t viewID, bool bDrawViewModel = false, int baseDrawFlags = 0, ViewCustomVisibility_t *pCustomVisibility = NULL );
  555. void DrawMonitors( const CViewSetup &cameraView );
  556. bool DrawOneMonitor( ITexture *pRenderTarget, int cameraNum, C_PointCamera *pCameraEnt, const CViewSetup &cameraView, C_BasePlayer *localPlayer,
  557. int x, int y, int width, int height );
  558. // Drawing primitives
  559. bool ShouldDrawViewModel( bool drawViewmodel );
  560. #ifdef IRONSIGHT
  561. void DrawViewModels( const CViewSetup &view, bool drawViewmodel, bool bDrawScopeLensMask = false );
  562. #else
  563. void DrawViewModels( const CViewSetup &view, bool drawViewmodel );
  564. #endif
  565. void PerformScreenSpaceEffects( int x, int y, int w, int h );
  566. // Overlays
  567. void SetScreenOverlayMaterial( IMaterial *pMaterial );
  568. IMaterial *GetScreenOverlayMaterial( );
  569. void PerformScreenOverlay( int x, int y, int w, int h );
  570. void DrawUnderwaterOverlay( void );
  571. // Water-related methods
  572. void DrawWorldAndEntities( bool drawSkybox, const CViewSetup &view, int nClearFlags, ViewCustomVisibility_t *pCustomVisibility = NULL );
  573. virtual void ViewDrawScene_Intro( const CViewSetup &view, int nClearFlags, const IntroData_t &introData );
  574. #ifdef PORTAL
  575. // Intended for use in the middle of another ViewDrawScene call, this allows stencils to be drawn after opaques but before translucents are drawn in the main view.
  576. void ViewDrawScene_PortalStencil( const CViewSetup &view, ViewCustomVisibility_t *pCustomVisibility );
  577. void Draw3dSkyboxworld_Portal( const CViewSetup &view, int &nClearFlags, bool &bDrew3dSkybox, SkyboxVisibility_t &nSkyboxVisible, ITexture *pRenderTarget = NULL );
  578. #endif // PORTAL
  579. #ifdef PORTAL2
  580. void ViewDrawPhoto( ITexture *pRenderTarget, C_BaseEntity *pEnt ); //need a photo of an entity
  581. #endif
  582. // Determines what kind of water we're going to use
  583. void DetermineWaterRenderInfo( const VisibleFogVolumeInfo_t &fogVolumeInfo, WaterRenderInfo_t &info );
  584. bool UpdateRefractIfNeededByList( CViewModelRenderablesList::RenderGroups_t &list );
  585. void DrawRenderablesInList( CViewModelRenderablesList::RenderGroups_t &list, int flags = 0 );
  586. // Sets up, cleans up the main 3D view
  587. void SetupMain3DView( int nSlot, const CViewSetup &view, const CViewSetup &hudViewSetup, int &nClearFlags, ITexture *pRenderTarget );
  588. void CleanupMain3DView( const CViewSetup &view );
  589. void GetLetterBoxRectangles( int nSlot, const CViewSetup &view, CUtlVector< vrect_t >& vecLetterBoxRectangles );
  590. void DrawLetterBoxRectangles( int nSlot, const CUtlVector< vrect_t >& vecLetterBoxRectangles );
  591. void EnableWaterDepthFeathing( IMaterial *pWaterMaterial, bool bEnable );
  592. #if defined(_PS3)
  593. void InitSPUBuildRenderingJobs( void );
  594. #endif
  595. // This stores the current view
  596. CViewSetup m_CurrentView;
  597. // VIS Overrides
  598. // Set to true to turn off client side vis ( !!!! rendering will be slow since everything will draw )
  599. bool m_bForceNoVis;
  600. // Some cvars needed by this system
  601. const ConVar *m_pDrawEntities;
  602. const ConVar *m_pDrawBrushModels;
  603. // Some materials used...
  604. CMaterialReference m_TranslucentSingleColor;
  605. CMaterialReference m_ModulateSingleColor;
  606. CMaterialReference m_ScreenOverlayMaterial;
  607. CMaterialReference m_UnderWaterOverlayMaterial;
  608. Vector m_vecLastFacing;
  609. float m_flCheapWaterStartDistance;
  610. float m_flCheapWaterEndDistance;
  611. CViewSetup m_OverlayViewSetup;
  612. int m_OverlayClearFlags;
  613. int m_OverlayDrawFlags;
  614. bool m_bDrawOverlay;
  615. int m_BaseDrawFlags; // Set in ViewDrawScene and OR'd into m_DrawFlags as it goes.
  616. C_BaseEntity *m_pCurrentlyDrawingEntity;
  617. #ifdef PORTAL
  618. friend class CPortalRender; //portal drawing needs muck with views in weird ways
  619. friend class CPortalRenderable;
  620. #endif
  621. int m_BuildRenderableListsNumber;
  622. friend class CBase3dView;
  623. Frustum m_Frustum;
  624. CBase3dView *m_pActiveRenderer;
  625. CSimpleRenderExecutor m_SimpleExecutor;
  626. struct FreezeParams_t
  627. {
  628. FreezeParams_t() : m_bTakeFreezeFrame( false ), m_flFreezeFrameUntil( 0.0f ) {}
  629. bool m_bTakeFreezeFrame;
  630. float m_flFreezeFrameUntil;
  631. };
  632. FreezeParams_t m_FreezeParams[ MAX_SPLITSCREEN_PLAYERS ];
  633. FadeData_t m_FadeData;
  634. CMaterialReference m_WhiteMaterial;
  635. CON_COMMAND_MEMBER_F( CViewRender, "screenfademinsize", OnScreenFadeMinSize, "Modify global screen fade min size in pixels", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
  636. CON_COMMAND_MEMBER_F( CViewRender, "screenfademaxsize", OnScreenFadeMaxSize, "Modify global screen fade max size in pixels", FCVAR_CHEAT | FCVAR_DEVELOPMENTONLY );
  637. float m_flSmokeOverlayAmount;
  638. };
  639. #endif // VIEWRENDER_H