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.

174 lines
4.7 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef R_DECAL_H
  7. #define R_DECAL_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "decal_private.h"
  12. #include "decal_clip.h"
  13. #include "utllinkedlist.h"
  14. #include "utlrbtree.h"
  15. #include "tier0/platform.h"
  16. #include "tier0/memdbgon.h"
  17. // Initialize and shutdown the decal stuff.
  18. // R_DecalTerm unlinks all the active decals (which frees their counterparts in displacements).
  19. void R_DecalInit();
  20. void R_DecalTerm( worldbrushdata_t *pBrushData, bool term_permanent_decals, bool term_player_decals );
  21. void R_DecalTermNew( worldbrushdata_t *pBrushData, int nTick );
  22. void R_DecalTermAll();
  23. float ComputeDecalLightmapOffset( SurfaceHandle_t surfID );
  24. // --------------------------------------------------------------- //
  25. // Decal functions used for displacements.
  26. // --------------------------------------------------------------- //
  27. // Figure out where the decal maps onto the surface.
  28. void R_SetupDecalClip(
  29. CDecalVert* &pOutVerts,
  30. decal_t *pDecal,
  31. Vector &vSurfNormal,
  32. IMaterial *pMaterial,
  33. Vector textureSpaceBasis[3],
  34. float decalWorldScale[2] );
  35. //-----------------------------------------------------------------------------
  36. // Gets the decal material and radius based on the decal index
  37. //-----------------------------------------------------------------------------
  38. void R_DecalGetMaterialAndSize( int decalIndex, IMaterial*& pDecalMaterial, float& w, float& h );
  39. //=============================================================================
  40. //
  41. // Decal Sort Structures.
  42. //
  43. #define DECALSORT_RBTREE_SIZE 16
  44. enum
  45. {
  46. PERMANENT_LIGHTMAP = 0,
  47. LIGHTMAP,
  48. NONLIGHTMAP,
  49. DECALSORT_TYPE_COUNT,
  50. };
  51. struct DecalSortVertexFormat_t
  52. {
  53. VertexFormat_t m_VertexFormat;
  54. int m_iSortTree; // Sort tree index.
  55. };
  56. struct DecalMaterialSortData_t
  57. {
  58. IMaterial *m_pMaterial;
  59. int m_iLightmapPage;
  60. int m_iBucket; // Index into the s_aDecalMaterialHead list.
  61. };
  62. struct DecalMaterialBucket_t
  63. {
  64. intp m_iHead;
  65. intp m_iTail;
  66. int m_nCheckCount;
  67. };
  68. inline bool DecalSortTreeSortLessFunc( const DecalMaterialSortData_t &decal1, const DecalMaterialSortData_t &decal2 )
  69. {
  70. if ( ( decal1.m_iLightmapPage == -1 ) || ( decal2.m_iLightmapPage == -1 ) )
  71. {
  72. return ( ( intp )decal1.m_pMaterial < ( intp )decal2.m_pMaterial );
  73. }
  74. if ( ( intp )decal1.m_pMaterial == ( intp )decal2.m_pMaterial )
  75. {
  76. return ( decal1.m_iLightmapPage < decal2.m_iLightmapPage );
  77. }
  78. else
  79. {
  80. return ( ( intp )decal1.m_pMaterial < ( intp )decal2.m_pMaterial );
  81. }
  82. }
  83. struct DecalSortTrees_t
  84. {
  85. CUtlRBTree<DecalMaterialSortData_t, int> *m_pTrees[DECALSORT_TYPE_COUNT];
  86. CUtlVector<DecalMaterialBucket_t> m_aDecalSortBuckets[MAX_MAT_SORT_GROUPS+1][DECALSORT_TYPE_COUNT];
  87. DecalSortTrees_t()
  88. {
  89. for ( int iSort = 0; iSort < DECALSORT_TYPE_COUNT; ++iSort )
  90. {
  91. m_pTrees[iSort] = new CUtlRBTree<DecalMaterialSortData_t, int>( DECALSORT_RBTREE_SIZE, DECALSORT_RBTREE_SIZE, DecalSortTreeSortLessFunc );
  92. }
  93. }
  94. ~DecalSortTrees_t()
  95. {
  96. for ( int iSort = 0; iSort < DECALSORT_TYPE_COUNT; ++iSort )
  97. {
  98. if ( m_pTrees[iSort] )
  99. {
  100. m_pTrees[iSort]->RemoveAll();
  101. delete m_pTrees[iSort];
  102. m_pTrees[iSort] = NULL;
  103. }
  104. }
  105. for ( int iGroup = 0; iGroup < ( MAX_MAT_SORT_GROUPS + 1 ); ++iGroup )
  106. {
  107. for ( int iSort = 0; iSort < DECALSORT_TYPE_COUNT; ++iSort )
  108. {
  109. m_aDecalSortBuckets[iGroup][iSort].Purge();
  110. }
  111. }
  112. }
  113. };
  114. extern CUtlVector<DecalSortVertexFormat_t> g_aDecalFormats;
  115. // Surface decals.
  116. extern CUtlFixedLinkedList<decal_t*> g_aDecalSortPool;
  117. extern CUtlVector<DecalSortTrees_t> g_aDecalSortTrees;
  118. extern int g_nDecalSortCheckCount;
  119. extern int g_nBrushModelDecalSortCheckCount;
  120. // Displacement decals.
  121. extern CUtlFixedLinkedList<decal_t*> g_aDispDecalSortPool;
  122. extern CUtlVector<DecalSortTrees_t> g_aDispDecalSortTrees;
  123. extern int g_nDispDecalSortCheckCount;
  124. struct DecalBatchList_t
  125. {
  126. IMaterial *m_pMaterial;
  127. void *m_pProxy;
  128. int m_iLightmapPage;
  129. unsigned short m_iStartIndex;
  130. unsigned short m_nIndexCount;
  131. };
  132. struct DecalMeshList_t
  133. {
  134. IMesh *m_pMesh;
  135. CUtlVectorFixed<DecalBatchList_t, 128> m_aBatches;
  136. };
  137. void DecalSurfacesInit( bool bBrushModel );
  138. void DecalSurfaceAdd( SurfaceHandle_t surfID, int renderGroup );
  139. void DecalSurfaceDraw( IMatRenderContext *pRenderContext, int renderGroup, float flFade = 1.0f );
  140. void DrawDecalsOnSingleSurface( IMatRenderContext *pRenderContext, SurfaceHandle_t surfID );
  141. void R_DecalReSortMaterials( void );
  142. void R_DecalFlushDestroyList( bool bImmediateCleanup = false );
  143. extern VMatrix g_BrushToWorldMatrix;
  144. #include "tier0/memdbgoff.h"
  145. #endif // R_DECAL_H