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.

247 lines
5.5 KiB

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