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.

251 lines
5.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef DISPINFO_DEFS_H
  8. #define DISPINFO_DEFS_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "utlvector.h"
  13. #include "materialsystem/imesh.h"
  14. #include "convar.h"
  15. #include "bspfile.h"
  16. #include "filesystem.h"
  17. #include "decal_private.h"
  18. #include "mempool.h"
  19. #include "decal_clip.h"
  20. #include "bitvec.h"
  21. #include "Overlay.h"
  22. #include "zone.h"
  23. extern ConVar r_DrawDisp;
  24. class CDispInfo;
  25. class CDispGroup;
  26. // The texture stage that displacement lightmap coordinates go in.
  27. #define DISP_LMCOORDS_STAGE 1
  28. #define MAX_STATIC_BUFFER_VERTS (8*1024)
  29. #define MAX_STATIC_BUFFER_INDICES (8*1024)
  30. #define MAX_DISP_DECALS 32
  31. #define MAX_EXTRA_DEPENDENCIES 8
  32. #define MAX_RETESSELATE MAX_MAP_DISPINFO // Max number of displacements that can be retesselated per frame.
  33. #define MAX_TOTAL_DISP_DEPENDENCIES (4*2 + 4*MAX_DISP_CORNER_NEIGHBORS + MAX_EXTRA_DEPENDENCIES)
  34. // These hold the HDISPINFOARRAYs.
  35. class CDispArray
  36. {
  37. public:
  38. unsigned short m_CurTag;
  39. CDispInfo *m_pDispInfos;
  40. int m_nDispInfos;
  41. };
  42. // These classes store groups of meshes which can be drawn with one IMesh::Draw() call.
  43. class CGroupMesh
  44. {
  45. public:
  46. IMesh *m_pMesh;
  47. CUtlVector<CDispInfo*> m_DispInfos;
  48. // This list is updated each frame to point at the visible LODs.
  49. CUtlVector<CDispInfo*> m_VisibleDisps;
  50. CUtlVector<CPrimList> m_Visible;
  51. int m_nVisible;
  52. CDispGroup *m_pGroup;
  53. };
  54. class CDispGroup
  55. {
  56. public:
  57. int m_LightmapPageID;
  58. IMaterial *m_pMaterial;
  59. CUtlVector<CGroupMesh*> m_Meshes;
  60. CUtlVector<int> m_DispInfos;
  61. int m_nVisible;
  62. };
  63. // This represents the two neighboring verts that are used to calculate the
  64. // error when removing a side vert of a node.
  65. class CSideVertCorners
  66. {
  67. public:
  68. CFourVerts m_Corners[2];
  69. };
  70. class CDispDecalBase
  71. {
  72. public:
  73. CDispDecalBase( int flags ) : m_Flags(flags) {}
  74. enum
  75. {
  76. NODE_BITFIELD_COMPUTED = 0x1,
  77. DECAL_SHADOW = 0x2,
  78. NO_INTERSECTION = 0x4,
  79. FRAGMENTS_COMPUTED = 0x8, // *non-shadow* fragments
  80. };
  81. // Precalculated flags on the nodes telling which nodes this decal can intersect.
  82. // See CPowerInfo::m_NodeIndexIncrements for a description of how the node tree is
  83. // walked using this bit vector.
  84. CBitVec<85> m_NodeIntersect; // The number of nodes on a 17x17 is 85.
  85. // Note: this must be larger if MAX_MAP_DISP_POWER gets larger.
  86. // Number of triangles + verts that got generated for this decal.
  87. unsigned char m_Flags;
  88. unsigned short m_nVerts;
  89. unsigned short m_nTris;
  90. };
  91. //-----------------------------------------------------------------------------
  92. // Types associated with normal decals
  93. //-----------------------------------------------------------------------------
  94. typedef unsigned short DispDecalFragmentHandle_t;
  95. enum
  96. {
  97. DISP_DECAL_FRAGMENT_HANDLE_INVALID = (DispDecalFragmentHandle_t)~0
  98. };
  99. class CDispDecal : public CDispDecalBase
  100. {
  101. public:
  102. CDispDecal() : CDispDecalBase(0) {}
  103. decal_t *m_pDecal;
  104. float m_DecalWorldScale[2];
  105. Vector m_TextureSpaceBasis[3];
  106. float m_flSize;
  107. DispDecalFragmentHandle_t m_FirstFragment;
  108. };
  109. #pragma pack(1)
  110. class CDispDecalFragment
  111. {
  112. public:
  113. enum { MAX_VERTS = 6 }; // 3 decal verts clipped by 4 planes results in a maximum of 6 (not 8) verts
  114. decal_t *m_pDecal; // Owning Decal
  115. unsigned char m_nVerts; //
  116. CDecalVert* m_pVerts; // m_pVerts[MAX_VERTS];
  117. ~CDispDecalFragment()
  118. {
  119. delete[] m_pVerts;
  120. m_pVerts = NULL;
  121. }
  122. };
  123. #pragma pack()
  124. typedef unsigned short DispShadowFragmentHandle_t;
  125. enum
  126. {
  127. DISP_SHADOW_FRAGMENT_HANDLE_INVALID = (DispShadowFragmentHandle_t)~0
  128. };
  129. class CDispShadowDecal : public CDispDecalBase
  130. {
  131. public:
  132. CDispShadowDecal() : CDispDecalBase(DECAL_SHADOW) {}
  133. ShadowHandle_t m_Shadow;
  134. DispShadowFragmentHandle_t m_FirstFragment;
  135. };
  136. class CDispShadowFragment
  137. {
  138. public:
  139. // NOTE: This # is >8 because we have 6 clip planes, it overflowed..
  140. enum { MAX_VERTS = 12 };
  141. int m_nVerts;
  142. ShadowVertex_t* m_ShadowVerts;
  143. ~CDispShadowFragment()
  144. {
  145. delete[] m_ShadowVerts;
  146. m_ShadowVerts = NULL;
  147. }
  148. };
  149. class CDispRenderVert
  150. {
  151. public:
  152. Vector m_vPos;
  153. // These are necessary for mat_normals to work
  154. Vector m_vNormal;
  155. Vector m_vSVector;
  156. Vector m_vTVector;
  157. Vector2D m_vTexCoord;
  158. Vector2D m_LMCoords;
  159. };
  160. // This position is about OVERLAY_AVOID_FLICKER_NORMAL_OFFSET inches off the surface
  161. // and is used by overlays and shadows to avoid z-fighting.
  162. inline Vector GetOverlayPos( CMeshReader *pReader, int iVertIndex )
  163. {
  164. Vector vNormal;
  165. pReader->Normal( iVertIndex, vNormal );
  166. return pReader->Position( iVertIndex ) + vNormal * OVERLAY_AVOID_FLICKER_NORMAL_OFFSET;
  167. }
  168. // --------------------------------------------------------------------------------- //
  169. // Global tables.
  170. // --------------------------------------------------------------------------------- //
  171. extern int g_CoreDispNeighborOrientationMap[4][4];
  172. // --------------------------------------------------------------------------------- //
  173. // Global variables.
  174. // --------------------------------------------------------------------------------- //
  175. extern CUtlVector<unsigned char> g_DispLMAlpha;
  176. extern CUtlVector<unsigned char, CHunkMemory<unsigned char> > g_DispLightmapSamplePositions;
  177. extern CUtlVector<CDispGroup*> g_DispGroups;
  178. // CVars.
  179. extern ConVar r_DispWalkable;
  180. extern ConVar r_DispBuildable;
  181. // If this is true, then no backface removal is done.
  182. extern bool g_bDispOrthoRender;
  183. #endif // DISPINFO_DEFS_H