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.

148 lines
5.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #ifndef IDISPINFO_H
  10. #define IDISPINFO_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. //=============================================================================
  15. #include <assert.h>
  16. #include "bspfile.h"
  17. #include "mathlib/vmatrix.h"
  18. #include "dispnode.h"
  19. #include "builddisp.h"
  20. #include "utlvector.h"
  21. #include "engine/ishadowmgr.h"
  22. #include "getintersectingsurfaces_struct.h"
  23. #include "surfacehandle.h"
  24. #include "ivrenderview.h"
  25. struct model_t;
  26. struct Ray_t;
  27. struct RayDispOutput_t;
  28. struct decal_t;
  29. class CMeshBuilder;
  30. //-----------------------------------------------------------------------------
  31. // Handle to decals + shadows on displacements
  32. //-----------------------------------------------------------------------------
  33. typedef unsigned short DispDecalHandle_t;
  34. enum
  35. {
  36. DISP_DECAL_HANDLE_INVALID = (DispDecalHandle_t)~0
  37. };
  38. typedef unsigned short DispShadowHandle_t;
  39. enum
  40. {
  41. DISP_SHADOW_HANDLE_INVALID = (DispShadowHandle_t)~0
  42. };
  43. //-----------------------------------------------------------------------------
  44. // Displacement interface to the engine (and WorldCraft?)
  45. //-----------------------------------------------------------------------------
  46. abstract_class IDispInfo
  47. {
  48. public:
  49. virtual ~IDispInfo() {}
  50. // Builds a list of displacement triangles intersecting the sphere.
  51. virtual void GetIntersectingSurfaces( GetIntersectingSurfaces_Struct *pStruct ) = 0;
  52. virtual void RenderWireframeInLightmapPage( int pageId ) = 0;
  53. virtual void GetBoundingBox( Vector &bbMin, Vector &bbMax ) = 0;
  54. // Get and set the parent surfaces.
  55. virtual void SetParent( SurfaceHandle_t surfID ) = 0;
  56. virtual SurfaceHandle_t GetParent() = 0;
  57. // Add dynamic lights to the lightmap for this surface.
  58. virtual void AddDynamicLights( struct dlight_t *pLights, unsigned int lightMask ) = 0;
  59. // Compute the mask for the lights hitting this surface.
  60. virtual unsigned int ComputeDynamicLightMask( struct dlight_t *pLights ) = 0;
  61. // Add and remove decals.
  62. // flSize is like the radius of the decal so the decal isn't put on any disp faces it's too far away from.
  63. virtual DispDecalHandle_t NotifyAddDecal( decal_t *pDecal, float flSize ) = 0;
  64. virtual void NotifyRemoveDecal( DispDecalHandle_t h ) = 0;
  65. virtual DispShadowHandle_t AddShadowDecal( ShadowHandle_t shadowHandle ) = 0;
  66. virtual void RemoveShadowDecal( DispShadowHandle_t handle ) = 0;
  67. // Compute shadow fragments for a particular shadow, return the vertex + index count of all fragments
  68. virtual bool ComputeShadowFragments( DispShadowHandle_t h, int& vertexCount, int& indexCount ) = 0;
  69. // Tag the surface and check if it's tagged. You can untag all the surfaces
  70. // with DispInfo_ClearAllTags. Note: it just uses a frame counter to track the
  71. // tag state so it's really really fast to call ClearAllTags (just increments
  72. // a variable 99.999% of the time).
  73. virtual bool GetTag() = 0;
  74. virtual void SetTag() = 0;
  75. // Cast a ray against this surface
  76. virtual bool TestRay( Ray_t const& ray, float start, float end, float& dist, Vector2D* lightmapUV, Vector2D* textureUV ) = 0;
  77. // Computes the texture + lightmap coordinate given a displacement uv
  78. virtual void ComputeLightmapAndTextureCoordinate( RayDispOutput_t const& uv, Vector2D* luv, Vector2D* tuv ) = 0;
  79. };
  80. // ----------------------------------------------------------------------------- //
  81. // Adds shadow rendering data to a particular mesh builder
  82. // The function will return the new base index
  83. // ----------------------------------------------------------------------------- //
  84. int DispInfo_AddShadowsToMeshBuilder( CMeshBuilder& meshBuilder,
  85. DispShadowHandle_t h, int baseIndex );
  86. typedef void* HDISPINFOARRAY;
  87. // Init and shutdown for the material system (references global, materials).
  88. void DispInfo_InitMaterialSystem();
  89. void DispInfo_ShutdownMaterialSystem();
  90. // Use these to manage a list of IDispInfos.
  91. HDISPINFOARRAY DispInfo_CreateArray( int nElements );
  92. void DispInfo_DeleteArray( HDISPINFOARRAY hArray );
  93. IDispInfo* DispInfo_IndexArray( HDISPINFOARRAY hArray, int iElement );
  94. int DispInfo_ComputeIndex( HDISPINFOARRAY hArray, IDispInfo* pInfo );
  95. // Clear the tags for all displacements in the array.
  96. void DispInfo_ClearAllTags( HDISPINFOARRAY hArray );
  97. // Call this to render a list of displacements.
  98. // If bOrtho is true, then no backface removal is done on dispinfos.
  99. void DispInfo_RenderList( int nSortGroup, SurfaceHandle_t *pList, int listCount, bool bOrtho, unsigned long flags, ERenderDepthMode DepthMode );
  100. // This should be called from Map_LoadDisplacements (while the map file is open).
  101. // It loads the displacement data from the file and prepares the displacements for rendering.
  102. //
  103. // bRestoring is set to true when just restoring the data from the mapfile
  104. // (ie: displacements already are initialized but need new static buffers).
  105. bool DispInfo_LoadDisplacements( model_t *pWorld, bool bRestoring );
  106. // Deletes all the static vertex buffers.
  107. void DispInfo_ReleaseMaterialSystemObjects( model_t *pWorld );
  108. #endif // IDISPINFO_H