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.

401 lines
15 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $NoKeywords: $
  7. //===========================================================================//
  8. #if !defined( IVRENDERVIEW_H )
  9. #define IVRENDERVIEW_H
  10. #ifdef _WIN32
  11. #pragma once
  12. #endif
  13. #include "basetypes.h"
  14. #include "mathlib/vplane.h"
  15. #include "interface.h"
  16. #include "materialsystem/imaterialsystem.h"
  17. #include "const.h"
  18. #include "mathlib/vertexcolor.h"
  19. #include "tier1/refcount.h"
  20. //-----------------------------------------------------------------------------
  21. // Forward declarations
  22. //-----------------------------------------------------------------------------
  23. class CViewSetup;
  24. class CEngineSprite;
  25. class IClientEntity;
  26. class IMaterial;
  27. struct model_t;
  28. class IClientRenderable;
  29. class IMatRenderContext;
  30. class CVolumeCuller;
  31. //-----------------------------------------------------------------------------
  32. // Flags used by DrawWorldLists
  33. //-----------------------------------------------------------------------------
  34. enum
  35. {
  36. DRAWWORLDLISTS_DRAW_STRICTLYABOVEWATER = 0x001,
  37. DRAWWORLDLISTS_DRAW_STRICTLYUNDERWATER = 0x002,
  38. DRAWWORLDLISTS_DRAW_INTERSECTSWATER = 0x004,
  39. DRAWWORLDLISTS_DRAW_WATERSURFACE = 0x008,
  40. DRAWWORLDLISTS_DRAW_SKYBOX = 0x010,
  41. DRAWWORLDLISTS_DRAW_CLIPSKYBOX = 0x020,
  42. DRAWWORLDLISTS_DRAW_SHADOWDEPTH = 0x040,
  43. DRAWWORLDLISTS_DRAW_REFRACTION = 0x080,
  44. DRAWWORLDLISTS_DRAW_REFLECTION = 0x100,
  45. DRAWWORLDLISTS_DRAW_WORLD_GEOMETRY = 0x200,
  46. DRAWWORLDLISTS_DRAW_DECALS_AND_OVERLAYS = 0x400,
  47. DRAWWORLDLISTS_DRAW_SIMPLE_WORLD_MODEL = 0x800,
  48. DRAWWORLDLISTS_DRAW_SIMPLE_WORLD_MODEL_WATER= 0x1000,
  49. DRAWWORLDLISTS_DRAW_SKIP_DISPLACEMENTS = 0x2000,
  50. DRAWWORLDLISTS_DRAW_SSAO = 0x4000,
  51. };
  52. enum
  53. {
  54. MAT_SORT_GROUP_STRICTLY_ABOVEWATER = 0,
  55. MAT_SORT_GROUP_STRICTLY_UNDERWATER,
  56. MAT_SORT_GROUP_INTERSECTS_WATER_SURFACE,
  57. MAT_SORT_GROUP_WATERSURFACE,
  58. MAX_MAT_SORT_GROUPS
  59. };
  60. enum ERenderDepthMode_t
  61. {
  62. DEPTH_MODE_NORMAL = 0,
  63. DEPTH_MODE_SHADOW = 1,
  64. DEPTH_MODE_SSA0 = 2,
  65. DEPTH_MODE_MAX
  66. };
  67. static const char* s_pMatSortGroupsString[] =
  68. {
  69. "Sort: Abovewater",
  70. "Sort: Underwater",
  71. "Sort: IntersectsWater",
  72. "Sort: WaterSurface",
  73. };
  74. typedef VPlane Frustum[FRUSTUM_NUMPLANES];
  75. //-----------------------------------------------------------------------------
  76. // Leaf index
  77. //-----------------------------------------------------------------------------
  78. typedef unsigned short LeafIndex_t;
  79. enum
  80. {
  81. INVALID_LEAF_INDEX = (LeafIndex_t)~0
  82. };
  83. //-----------------------------------------------------------------------------
  84. // Describes the leaves to be rendered this view, set by BuildWorldLists
  85. //-----------------------------------------------------------------------------
  86. // NOTE: This is slightly slower on x360 but saves memory
  87. #if 1
  88. struct WorldListLeafData_t
  89. {
  90. LeafIndex_t leafIndex; // 16 bits
  91. int16 waterData;
  92. uint16 firstTranslucentSurface; // engine-internal list index
  93. uint16 translucentSurfaceCount; // count of translucent surfaces+disps
  94. };
  95. #else
  96. struct WorldListLeafData_t
  97. {
  98. uint32 leafIndex;
  99. int32 waterData;
  100. uint32 firstTranslucentSurface; // engine-internal list index
  101. uint32 translucentSurfaceCount; // count of translucent surfaces+disps
  102. };
  103. #endif
  104. struct WorldListInfo_t
  105. {
  106. int m_ViewFogVolume;
  107. int m_LeafCount;
  108. bool m_bHasWater;
  109. WorldListLeafData_t *m_pLeafDataList;
  110. };
  111. class IWorldRenderList : public IRefCounted
  112. {
  113. };
  114. //-----------------------------------------------------------------------------
  115. // Describes the fog volume for a particular point
  116. //-----------------------------------------------------------------------------
  117. struct VisibleFogVolumeInfo_t
  118. {
  119. int m_nVisibleFogVolume;
  120. int m_nVisibleFogVolumeLeaf;
  121. bool m_bEyeInFogVolume;
  122. float m_flDistanceToWater;
  123. float m_flWaterHeight;
  124. IMaterial *m_pFogVolumeMaterial;
  125. };
  126. //-----------------------------------------------------------------------------
  127. // Vertex format for brush models
  128. //-----------------------------------------------------------------------------
  129. struct BrushVertex_t
  130. {
  131. Vector m_Pos;
  132. Vector m_Normal;
  133. Vector m_TangentS;
  134. Vector m_TangentT;
  135. Vector2D m_TexCoord;
  136. Vector2D m_LightmapCoord;
  137. private:
  138. BrushVertex_t( const BrushVertex_t& src );
  139. };
  140. //-----------------------------------------------------------------------------
  141. // Visibility data for area portal culling
  142. //-----------------------------------------------------------------------------
  143. struct VisOverrideData_t
  144. {
  145. Vector m_vecVisOrigin; // The point to to use as the viewpoint for area portal backface cull checks.
  146. float m_fDistToAreaPortalTolerance; // The distance from an area portal before using the full screen as the viewable portion.
  147. // PORTAL2-specific
  148. Vector m_vPortalCorners[4]; // When rendering a portal view, these are the 4 corners of the portal you are looking through (used to shrink the frustum)
  149. bool m_bTrimFrustumToPortalCorners;
  150. Vector m_vPortalOrigin;
  151. Vector m_vPortalForward;
  152. float m_flPortalRadius;
  153. };
  154. //-----------------------------------------------------------------------------
  155. // interface for asking about the Brush surfaces from the client DLL
  156. //-----------------------------------------------------------------------------
  157. class IBrushSurface
  158. {
  159. public:
  160. // Computes texture coordinates + lightmap coordinates given a world position
  161. virtual void ComputeTextureCoordinate( Vector const& worldPos, Vector2D& texCoord ) = 0;
  162. virtual void ComputeLightmapCoordinate( Vector const& worldPos, Vector2D& lightmapCoord ) = 0;
  163. // Gets the vertex data for this surface
  164. virtual int GetVertexCount() const = 0;
  165. virtual void GetVertexData( BrushVertex_t* pVerts ) = 0;
  166. // Gets at the material properties for this surface
  167. virtual IMaterial* GetMaterial() = 0;
  168. };
  169. //-----------------------------------------------------------------------------
  170. // interface for installing a new renderer for brush surfaces
  171. //-----------------------------------------------------------------------------
  172. class IBrushRenderer
  173. {
  174. public:
  175. // Draws the surface; returns true if decals should be rendered on this surface
  176. virtual bool RenderBrushModelSurface( IClientEntity* pBaseEntity, IBrushSurface* pBrushSurface ) = 0;
  177. };
  178. #define MAX_VIS_LEAVES 32
  179. //-----------------------------------------------------------------------------
  180. // Purpose: Interface to client .dll to set up a rendering pass over world
  181. // The client .dll can call Render multiple times to overlay one or more world
  182. // views on top of one another
  183. //-----------------------------------------------------------------------------
  184. enum DrawBrushModelMode_t
  185. {
  186. DBM_DRAW_ALL = 0,
  187. DBM_DRAW_OPAQUE_ONLY,
  188. DBM_DRAW_TRANSLUCENT_ONLY,
  189. };
  190. //-----------------------------------------------------------------------------
  191. // Brush model instance rendering state
  192. //-----------------------------------------------------------------------------
  193. struct BrushArrayInstanceData_t
  194. {
  195. matrix3x4a_t *m_pBrushToWorld; // NOTE: Not inlined because it has alignment restrictions; this way the instance struct size can change without memory penalty
  196. const model_t *m_pBrushModel; // NOTE: Only the first two fields are used when rendering shadows
  197. Vector4D m_DiffuseModulation;
  198. ShaderStencilState_t *m_pStencilState;
  199. };
  200. class IVRenderView
  201. {
  202. public:
  203. // Draw normal brush model.
  204. // If pMaterialOverride is non-null, then all the faces of the bmodel will
  205. // set this material rather than their regular material.
  206. virtual void DrawBrushModel(
  207. IClientEntity *baseentity,
  208. model_t *model,
  209. const Vector& origin,
  210. const QAngle& angles,
  211. bool bUnused ) = 0;
  212. // Draw brush model that has no origin/angles change ( uses identity transform )
  213. // FIXME, Material proxy IClientEntity *baseentity is unused right now, use DrawBrushModel for brushes with
  214. // proxies for now.
  215. virtual void DrawIdentityBrushModel( IWorldRenderList *pList, model_t *model ) = 0;
  216. // Mark this dynamic light as having changed this frame ( so light maps affected will be recomputed )
  217. virtual void TouchLight( struct dlight_t *light ) = 0;
  218. // Draw 3D Overlays
  219. virtual void Draw3DDebugOverlays( void ) = 0;
  220. // Sets global blending fraction
  221. virtual void SetBlend( float blend ) = 0;
  222. virtual float GetBlend( void ) = 0;
  223. // Sets global color modulation
  224. virtual void SetColorModulation( float const* blend ) = 0;
  225. virtual void GetColorModulation( float* blend ) = 0;
  226. // Wrap entire scene drawing
  227. virtual void SceneBegin( void ) = 0;
  228. virtual void SceneEnd( void ) = 0;
  229. // Gets the fog volume for a particular point
  230. virtual void GetVisibleFogVolume( const Vector& eyePoint, const VisOverrideData_t *pVisOverrideData, VisibleFogVolumeInfo_t *pInfo ) = 0;
  231. // Wraps world drawing
  232. // If iForceViewLeaf is not -1, then it uses the specified leaf as your starting area for setting up area portal culling.
  233. // This is used by water since your reflected view origin is often in solid space, but we still want to treat it as though
  234. // the first portal we're looking out of is a water portal, so our view effectively originates under the water.
  235. virtual IWorldRenderList * CreateWorldList() = 0;
  236. #if defined(_PS3)
  237. virtual IWorldRenderList * CreateWorldList_PS3( int viewID ) = 0;
  238. virtual void BuildWorldLists_PS3_Epilogue( IWorldRenderList *pList, WorldListInfo_t* pInfo, bool bShadowDepth ) = 0;
  239. #else
  240. virtual void BuildWorldLists_Epilogue( IWorldRenderList *pList, WorldListInfo_t* pInfo, bool bShadowDepth ) = 0;
  241. #endif
  242. virtual void BuildWorldLists( IWorldRenderList *pList, WorldListInfo_t* pInfo, int iForceFViewLeaf, const VisOverrideData_t* pVisData = NULL, bool bShadowDepth = false, float *pReflectionWaterHeight = NULL ) = 0;
  243. virtual void DrawWorldLists( IMatRenderContext *pRenderContext, IWorldRenderList *pList, unsigned long flags, float waterZAdjust ) = 0;
  244. virtual void GetWorldListIndicesInfo( WorldListIndicesInfo_t * pIndicesInfoOut, IWorldRenderList *pList, unsigned long nFlags ) = 0;
  245. // Optimization for top view
  246. virtual void DrawTopView( bool enable ) = 0;
  247. virtual void TopViewNoBackfaceCulling( bool bDisable ) = 0;
  248. virtual void TopViewNoVisCheck( bool bDisable ) = 0;
  249. virtual void TopViewBounds( Vector2D const& mins, Vector2D const& maxs ) = 0;
  250. virtual void SetTopViewVolumeCuller( const CVolumeCuller *pVolumeCuller ) = 0;
  251. // Draw lights
  252. virtual void DrawLights( void ) = 0;
  253. // FIXME: This function is a stub, doesn't do anything in the engine right now
  254. virtual void DrawMaskEntities( void ) = 0;
  255. // Draw surfaces with alpha, don't call in shadow depth pass
  256. virtual void DrawTranslucentSurfaces( IMatRenderContext *pRenderContext, IWorldRenderList *pList, int *pSortList, int sortCount, unsigned long flags ) = 0;
  257. // Draw Particles ( just draws the linefine for debugging map leaks )
  258. virtual void DrawLineFile( void ) = 0;
  259. // Draw lightmaps
  260. virtual void DrawLightmaps( IWorldRenderList *pList, int pageId ) = 0;
  261. // Wraps view render sequence, sets up a view
  262. virtual void ViewSetupVis( bool novis, int numorigins, const Vector origin[] ) = 0;
  263. // Return true if any of these leaves are visible in the current PVS.
  264. virtual bool AreAnyLeavesVisible( int *leafList, int nLeaves ) = 0;
  265. virtual void VguiPaint( void ) = 0;
  266. // Sets up view fade parameters
  267. virtual void ViewDrawFade( byte *color, IMaterial *pMaterial, bool mapFullTextureToScreen = true ) = 0;
  268. // Sets up the projection matrix for the specified field of view
  269. virtual void OLD_SetProjectionMatrix( float fov, float zNear, float zFar ) = 0;
  270. // Determine lighting at specified position
  271. virtual colorVec GetLightAtPoint( Vector& pos ) = 0;
  272. // Whose eyes are we looking through?
  273. virtual int GetViewEntity( void ) = 0;
  274. virtual bool IsViewEntity( int entindex ) = 0;
  275. // Get engine field of view setting
  276. virtual float GetFieldOfView( void ) = 0;
  277. // 1 == ducking, 0 == not
  278. virtual unsigned char **GetAreaBits( void ) = 0;
  279. // Set up fog for a particular leaf
  280. virtual void SetFogVolumeState( int nVisibleFogVolume, bool bUseHeightFog ) = 0;
  281. // Installs a brush surface draw override method, null means use normal renderer
  282. virtual void InstallBrushSurfaceRenderer( IBrushRenderer* pBrushRenderer ) = 0;
  283. // Draw brush model shadow
  284. virtual void DrawBrushModelShadow( IClientRenderable *pRenderable ) = 0;
  285. // Does the leaf contain translucent surfaces?
  286. virtual bool LeafContainsTranslucentSurfaces( IWorldRenderList *pList, int sortIndex, unsigned long flags ) = 0;
  287. virtual bool DoesBoxIntersectWaterVolume( const Vector &mins, const Vector &maxs, int leafWaterDataID ) = 0;
  288. virtual void SetAreaState(
  289. unsigned char chAreaBits[MAX_AREA_STATE_BYTES],
  290. unsigned char chAreaPortalBits[MAX_AREA_PORTAL_STATE_BYTES] ) = 0;
  291. // See i
  292. virtual void VGui_Paint( int mode ) = 0;
  293. // Push, pop views (see PushViewFlags_t above for flags)
  294. virtual void Push3DView( IMatRenderContext *pRenderContext, const CViewSetup &view, int nFlags, ITexture* pRenderTarget, Frustum frustumPlanes ) = 0;
  295. virtual void Push2DView( IMatRenderContext *pRenderContext, const CViewSetup &view, int nFlags, ITexture* pRenderTarget, Frustum frustumPlanes ) = 0;
  296. virtual void PopView( IMatRenderContext *pRenderContext, Frustum frustumPlanes ) = 0;
  297. // Sets the main view
  298. virtual void SetMainView( const Vector &vecOrigin, const QAngle &angles ) = 0;
  299. enum
  300. {
  301. VIEW_SETUP_VIS_EX_RETURN_FLAGS_USES_RADIAL_VIS = 0x00000001
  302. };
  303. // Wraps view render sequence, sets up a view
  304. virtual void ViewSetupVisEx( bool novis, int numorigins, const Vector origin[], unsigned int &returnFlags ) = 0;
  305. //replaces the current view frustum with a rhyming replacement of your choice
  306. virtual void OverrideViewFrustum( Frustum custom ) = 0;
  307. virtual void DrawBrushModelShadowDepth( IClientEntity *baseentity, model_t *model, const Vector& origin, const QAngle& angles, ERenderDepthMode_t DepthMode ) = 0;
  308. virtual void UpdateBrushModelLightmap( model_t *model, IClientRenderable *pRenderable ) = 0;
  309. virtual void BeginUpdateLightmaps( void ) = 0;
  310. virtual void EndUpdateLightmaps() = 0;
  311. virtual void OLD_SetOffCenterProjectionMatrix( float fov, float zNear, float zFar, float flAspectRatio, float flBottom, float flTop, float flLeft, float flRight ) = 0;
  312. virtual void OLD_SetProjectionMatrixOrtho( float left, float top, float right, float bottom, float zNear, float zFar ) = 0;
  313. virtual void Push3DView( IMatRenderContext *pRenderContext, const CViewSetup &view, int nFlags, ITexture* pRenderTarget, Frustum frustumPlanes, ITexture* pDepthTexture ) = 0;
  314. virtual void GetMatricesForView( const CViewSetup &view, VMatrix *pWorldToView, VMatrix *pViewToProjection, VMatrix *pWorldToProjection, VMatrix *pWorldToPixels ) = 0;
  315. virtual void DrawBrushModelEx( IClientEntity *baseentity, model_t *model, const Vector& origin, const QAngle& angles, DrawBrushModelMode_t mode ) = 0;
  316. virtual bool DoesBrushModelNeedPowerOf2Framebuffer( const model_t *model ) = 0;
  317. // draw an array of brush models (see model_types.h for the model type flags, i.e. STUDIO_SHADOWDEPTHTEXTURE)
  318. virtual void DrawBrushModelArray( IMatRenderContext* pContext, int nCount, const BrushArrayInstanceData_t *pInstanceData, int nModelTypeFlags ) = 0;
  319. };
  320. // change this when the new version is incompatable with the old
  321. #define VENGINE_RENDERVIEW_INTERFACE_VERSION "VEngineRenderView014"
  322. #if defined(_STATIC_LINKED) && defined(CLIENT_DLL)
  323. namespace Client
  324. {
  325. extern IVRenderView *render;
  326. }
  327. #else
  328. extern IVRenderView *render;
  329. #endif
  330. #endif // IVRENDERVIEW_H