Team Fortress 2 Source Code as on 22/4/2020
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.

330 lines
12 KiB

  1. //========= Copyright 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 "tier1/refcount.h"
  19. //-----------------------------------------------------------------------------
  20. // Forward declarations
  21. //-----------------------------------------------------------------------------
  22. class CViewSetup;
  23. class CEngineSprite;
  24. class IClientEntity;
  25. class IMaterial;
  26. struct model_t;
  27. class IClientRenderable;
  28. //-----------------------------------------------------------------------------
  29. // Flags used by DrawWorldLists
  30. //-----------------------------------------------------------------------------
  31. enum
  32. {
  33. DRAWWORLDLISTS_DRAW_STRICTLYABOVEWATER = 0x001,
  34. DRAWWORLDLISTS_DRAW_STRICTLYUNDERWATER = 0x002,
  35. DRAWWORLDLISTS_DRAW_INTERSECTSWATER = 0x004,
  36. DRAWWORLDLISTS_DRAW_WATERSURFACE = 0x008,
  37. DRAWWORLDLISTS_DRAW_SKYBOX = 0x010,
  38. DRAWWORLDLISTS_DRAW_CLIPSKYBOX = 0x020,
  39. DRAWWORLDLISTS_DRAW_SHADOWDEPTH = 0x040,
  40. DRAWWORLDLISTS_DRAW_REFRACTION = 0x080,
  41. DRAWWORLDLISTS_DRAW_REFLECTION = 0x100,
  42. DRAWWORLDLISTS_DRAW_SSAO = 0x800,
  43. };
  44. enum
  45. {
  46. MAT_SORT_GROUP_STRICTLY_ABOVEWATER = 0,
  47. MAT_SORT_GROUP_STRICTLY_UNDERWATER,
  48. MAT_SORT_GROUP_INTERSECTS_WATER_SURFACE,
  49. MAT_SORT_GROUP_WATERSURFACE,
  50. MAX_MAT_SORT_GROUPS
  51. };
  52. enum ERenderDepthMode
  53. {
  54. DEPTH_MODE_NORMAL = 0,
  55. DEPTH_MODE_SHADOW = 1,
  56. DEPTH_MODE_SSA0 = 2,
  57. DEPTH_MODE_OVERRIDE = 3,
  58. DEPTH_MODE_MAX
  59. };
  60. typedef VPlane Frustum[FRUSTUM_NUMPLANES];
  61. //-----------------------------------------------------------------------------
  62. // Leaf index
  63. //-----------------------------------------------------------------------------
  64. typedef unsigned short LeafIndex_t;
  65. typedef short LeafFogVolume_t;
  66. enum
  67. {
  68. INVALID_LEAF_INDEX = (LeafIndex_t)~0
  69. };
  70. //-----------------------------------------------------------------------------
  71. // Describes the leaves to be rendered this view, set by BuildWorldLists
  72. //-----------------------------------------------------------------------------
  73. struct WorldListInfo_t
  74. {
  75. int m_ViewFogVolume;
  76. int m_LeafCount;
  77. LeafIndex_t* m_pLeafList;
  78. LeafFogVolume_t* m_pLeafFogVolume;
  79. };
  80. class IWorldRenderList : public IRefCounted
  81. {
  82. };
  83. //-----------------------------------------------------------------------------
  84. // Describes the fog volume for a particular point
  85. //-----------------------------------------------------------------------------
  86. struct VisibleFogVolumeInfo_t
  87. {
  88. int m_nVisibleFogVolume;
  89. int m_nVisibleFogVolumeLeaf;
  90. bool m_bEyeInFogVolume;
  91. float m_flDistanceToWater;
  92. float m_flWaterHeight;
  93. IMaterial *m_pFogVolumeMaterial;
  94. };
  95. //-----------------------------------------------------------------------------
  96. // Vertex format for brush models
  97. //-----------------------------------------------------------------------------
  98. struct BrushVertex_t
  99. {
  100. Vector m_Pos;
  101. Vector m_Normal;
  102. Vector m_TangentS;
  103. Vector m_TangentT;
  104. Vector2D m_TexCoord;
  105. Vector2D m_LightmapCoord;
  106. private:
  107. BrushVertex_t( const BrushVertex_t& src );
  108. };
  109. //-----------------------------------------------------------------------------
  110. // Visibility data for area portal culling
  111. //-----------------------------------------------------------------------------
  112. struct VisOverrideData_t
  113. {
  114. Vector m_vecVisOrigin; // The point to to use as the viewpoint for area portal backface cull checks.
  115. float m_fDistToAreaPortalTolerance; // The distance from an area portal before using the full screen as the viewable portion.
  116. };
  117. //-----------------------------------------------------------------------------
  118. // interface for asking about the Brush surfaces from the client DLL
  119. //-----------------------------------------------------------------------------
  120. class IBrushSurface
  121. {
  122. public:
  123. // Computes texture coordinates + lightmap coordinates given a world position
  124. virtual void ComputeTextureCoordinate( Vector const& worldPos, Vector2D& texCoord ) = 0;
  125. virtual void ComputeLightmapCoordinate( Vector const& worldPos, Vector2D& lightmapCoord ) = 0;
  126. // Gets the vertex data for this surface
  127. virtual int GetVertexCount() const = 0;
  128. virtual void GetVertexData( BrushVertex_t* pVerts ) = 0;
  129. // Gets at the material properties for this surface
  130. virtual IMaterial* GetMaterial() = 0;
  131. };
  132. //-----------------------------------------------------------------------------
  133. // interface for installing a new renderer for brush surfaces
  134. //-----------------------------------------------------------------------------
  135. class IBrushRenderer
  136. {
  137. public:
  138. // Draws the surface; returns true if decals should be rendered on this surface
  139. virtual bool RenderBrushModelSurface( IClientEntity* pBaseEntity, IBrushSurface* pBrushSurface ) = 0;
  140. };
  141. #define MAX_VIS_LEAVES 32
  142. //-----------------------------------------------------------------------------
  143. // Purpose: Interface to client .dll to set up a rendering pass over world
  144. // The client .dll can call Render multiple times to overlay one or more world
  145. // views on top of one another
  146. //-----------------------------------------------------------------------------
  147. enum DrawBrushModelMode_t
  148. {
  149. DBM_DRAW_ALL = 0,
  150. DBM_DRAW_OPAQUE_ONLY,
  151. DBM_DRAW_TRANSLUCENT_ONLY,
  152. };
  153. class IVRenderView
  154. {
  155. public:
  156. // Draw normal brush model.
  157. // If pMaterialOverride is non-null, then all the faces of the bmodel will
  158. // set this material rather than their regular material.
  159. virtual void DrawBrushModel(
  160. IClientEntity *baseentity,
  161. model_t *model,
  162. const Vector& origin,
  163. const QAngle& angles,
  164. bool bUnused ) = 0;
  165. // Draw brush model that has no origin/angles change ( uses identity transform )
  166. // FIXME, Material proxy IClientEntity *baseentity is unused right now, use DrawBrushModel for brushes with
  167. // proxies for now.
  168. virtual void DrawIdentityBrushModel( IWorldRenderList *pList, model_t *model ) = 0;
  169. // Mark this dynamic light as having changed this frame ( so light maps affected will be recomputed )
  170. virtual void TouchLight( struct dlight_t *light ) = 0;
  171. // Draw 3D Overlays
  172. virtual void Draw3DDebugOverlays( void ) = 0;
  173. // Sets global blending fraction
  174. virtual void SetBlend( float blend ) = 0;
  175. virtual float GetBlend( void ) = 0;
  176. // Sets global color modulation
  177. virtual void SetColorModulation( float const* blend ) = 0;
  178. virtual void GetColorModulation( float* blend ) = 0;
  179. // Wrap entire scene drawing
  180. virtual void SceneBegin( void ) = 0;
  181. virtual void SceneEnd( void ) = 0;
  182. // Gets the fog volume for a particular point
  183. virtual void GetVisibleFogVolume( const Vector& eyePoint, VisibleFogVolumeInfo_t *pInfo ) = 0;
  184. // Wraps world drawing
  185. // If iForceViewLeaf is not -1, then it uses the specified leaf as your starting area for setting up area portal culling.
  186. // This is used by water since your reflected view origin is often in solid space, but we still want to treat it as though
  187. // the first portal we're looking out of is a water portal, so our view effectively originates under the water.
  188. virtual IWorldRenderList * CreateWorldList() = 0;
  189. virtual void BuildWorldLists( IWorldRenderList *pList, WorldListInfo_t* pInfo, int iForceFViewLeaf, const VisOverrideData_t* pVisData = NULL, bool bShadowDepth = false, float *pReflectionWaterHeight = NULL ) = 0;
  190. virtual void DrawWorldLists( IWorldRenderList *pList, unsigned long flags, float waterZAdjust ) = 0;
  191. // Optimization for top view
  192. virtual void DrawTopView( bool enable ) = 0;
  193. virtual void TopViewBounds( Vector2D const& mins, Vector2D const& maxs ) = 0;
  194. // Draw lights
  195. virtual void DrawLights( void ) = 0;
  196. // FIXME: This function is a stub, doesn't do anything in the engine right now
  197. virtual void DrawMaskEntities( void ) = 0;
  198. // Draw surfaces with alpha
  199. virtual void DrawTranslucentSurfaces( IWorldRenderList *pList, int sortIndex, unsigned long flags, bool bShadowDepth ) = 0;
  200. // Draw Particles ( just draws the linefine for debugging map leaks )
  201. virtual void DrawLineFile( void ) = 0;
  202. // Draw lightmaps
  203. virtual void DrawLightmaps( IWorldRenderList *pList, int pageId ) = 0;
  204. // Wraps view render sequence, sets up a view
  205. virtual void ViewSetupVis( bool novis, int numorigins, const Vector origin[] ) = 0;
  206. // Return true if any of these leaves are visible in the current PVS.
  207. virtual bool AreAnyLeavesVisible( int *leafList, int nLeaves ) = 0;
  208. virtual void VguiPaint( void ) = 0;
  209. // Sets up view fade parameters
  210. virtual void ViewDrawFade( byte *color, IMaterial *pMaterial ) = 0;
  211. // Sets up the projection matrix for the specified field of view
  212. virtual void OLD_SetProjectionMatrix( float fov, float zNear, float zFar ) = 0;
  213. // Determine lighting at specified position
  214. virtual colorVec GetLightAtPoint( Vector& pos ) = 0;
  215. // Whose eyes are we looking through?
  216. virtual int GetViewEntity( void ) = 0;
  217. // Get engine field of view setting
  218. virtual float GetFieldOfView( void ) = 0;
  219. // 1 == ducking, 0 == not
  220. virtual unsigned char **GetAreaBits( void ) = 0;
  221. // Set up fog for a particular leaf
  222. virtual void SetFogVolumeState( int nVisibleFogVolume, bool bUseHeightFog ) = 0;
  223. // Installs a brush surface draw override method, null means use normal renderer
  224. virtual void InstallBrushSurfaceRenderer( IBrushRenderer* pBrushRenderer ) = 0;
  225. // Draw brush model shadow
  226. virtual void DrawBrushModelShadow( IClientRenderable *pRenderable ) = 0;
  227. // Does the leaf contain translucent surfaces?
  228. virtual bool LeafContainsTranslucentSurfaces( IWorldRenderList *pList, int sortIndex, unsigned long flags ) = 0;
  229. virtual bool DoesBoxIntersectWaterVolume( const Vector &mins, const Vector &maxs, int leafWaterDataID ) = 0;
  230. virtual void SetAreaState(
  231. unsigned char chAreaBits[MAX_AREA_STATE_BYTES],
  232. unsigned char chAreaPortalBits[MAX_AREA_PORTAL_STATE_BYTES] ) = 0;
  233. // See i
  234. virtual void VGui_Paint( int mode ) = 0;
  235. // Push, pop views (see PushViewFlags_t above for flags)
  236. virtual void Push3DView( const CViewSetup &view, int nFlags, ITexture* pRenderTarget, Frustum frustumPlanes ) = 0;
  237. virtual void Push2DView( const CViewSetup &view, int nFlags, ITexture* pRenderTarget, Frustum frustumPlanes ) = 0;
  238. virtual void PopView( Frustum frustumPlanes ) = 0;
  239. // Sets the main view
  240. virtual void SetMainView( const Vector &vecOrigin, const QAngle &angles ) = 0;
  241. enum
  242. {
  243. VIEW_SETUP_VIS_EX_RETURN_FLAGS_USES_RADIAL_VIS = 0x00000001
  244. };
  245. // Wraps view render sequence, sets up a view
  246. virtual void ViewSetupVisEx( bool novis, int numorigins, const Vector origin[], unsigned int &returnFlags ) = 0;
  247. //replaces the current view frustum with a rhyming replacement of your choice
  248. virtual void OverrideViewFrustum( Frustum custom ) = 0;
  249. virtual void DrawBrushModelShadowDepth( IClientEntity *baseentity, model_t *model, const Vector& origin, const QAngle& angles, ERenderDepthMode DepthMode ) = 0;
  250. virtual void UpdateBrushModelLightmap( model_t *model, IClientRenderable *pRenderable ) = 0;
  251. virtual void BeginUpdateLightmaps( void ) = 0;
  252. virtual void EndUpdateLightmaps( void ) = 0;
  253. virtual void OLD_SetOffCenterProjectionMatrix( float fov, float zNear, float zFar, float flAspectRatio, float flBottom, float flTop, float flLeft, float flRight ) = 0;
  254. virtual void OLD_SetProjectionMatrixOrtho( float left, float top, float right, float bottom, float zNear, float zFar ) = 0;
  255. virtual void Push3DView( const CViewSetup &view, int nFlags, ITexture* pRenderTarget, Frustum frustumPlanes, ITexture* pDepthTexture ) = 0;
  256. virtual void GetMatricesForView( const CViewSetup &view, VMatrix *pWorldToView, VMatrix *pViewToProjection, VMatrix *pWorldToProjection, VMatrix *pWorldToPixels ) = 0;
  257. virtual void DrawBrushModelEx( IClientEntity *baseentity, model_t *model, const Vector& origin, const QAngle& angles, DrawBrushModelMode_t mode ) = 0;
  258. };
  259. // change this when the new version is incompatable with the old
  260. #define VENGINE_RENDERVIEW_INTERFACE_VERSION "VEngineRenderView014"
  261. #if defined(_STATIC_LINKED) && defined(CLIENT_DLL)
  262. namespace Client
  263. {
  264. extern IVRenderView *render;
  265. }
  266. #else
  267. extern IVRenderView *render;
  268. #endif
  269. #endif // IVRENDERVIEW_H