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.

172 lines
4.6 KiB

  1. //========= Copyright 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/memdbgon.h"
  16. // Initialize and shutdown the decal stuff.
  17. // R_DecalTerm unlinks all the active decals (which frees their counterparts in displacements).
  18. void R_DecalInit();
  19. void R_DecalTerm( worldbrushdata_t *pBrushData, bool term_permanent_decals );
  20. void R_DecalTermAll();
  21. float ComputeDecalLightmapOffset( SurfaceHandle_t surfID );
  22. // get the max vertex/index to lock in a dynamic VB
  23. void R_DecalsGetMaxMesh( IMatRenderContext *pRenderContext, int &nDecalSortMaxVerts, int &nDecalSortMaxIndices );
  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. int m_iHead;
  65. int m_nCheckCount;
  66. };
  67. inline bool DecalSortTreeSortLessFunc( const DecalMaterialSortData_t &decal1, const DecalMaterialSortData_t &decal2 )
  68. {
  69. if ( ( decal1.m_iLightmapPage == -1 ) || ( decal2.m_iLightmapPage == -1 ) )
  70. {
  71. return ( ( int )decal1.m_pMaterial < ( int )decal2.m_pMaterial );
  72. }
  73. if ( ( int )decal1.m_pMaterial == ( int )decal2.m_pMaterial )
  74. {
  75. return ( decal1.m_iLightmapPage < decal2.m_iLightmapPage );
  76. }
  77. else
  78. {
  79. return ( ( int )decal1.m_pMaterial < ( int )decal2.m_pMaterial );
  80. }
  81. }
  82. struct DecalSortTrees_t
  83. {
  84. CUtlRBTree<DecalMaterialSortData_t, int> *m_pTrees[DECALSORT_TYPE_COUNT];
  85. CUtlVector<DecalMaterialBucket_t> m_aDecalSortBuckets[MAX_MAT_SORT_GROUPS+1][DECALSORT_TYPE_COUNT];
  86. DecalSortTrees_t()
  87. {
  88. for ( int iSort = 0; iSort < DECALSORT_TYPE_COUNT; ++iSort )
  89. {
  90. m_pTrees[iSort] = new CUtlRBTree<DecalMaterialSortData_t, int>( DECALSORT_RBTREE_SIZE, DECALSORT_RBTREE_SIZE, DecalSortTreeSortLessFunc );
  91. }
  92. }
  93. ~DecalSortTrees_t()
  94. {
  95. for ( int iSort = 0; iSort < DECALSORT_TYPE_COUNT; ++iSort )
  96. {
  97. if ( m_pTrees[iSort] )
  98. {
  99. m_pTrees[iSort]->RemoveAll();
  100. delete m_pTrees[iSort];
  101. m_pTrees[iSort] = NULL;
  102. }
  103. }
  104. for ( int iGroup = 0; iGroup < ( MAX_MAT_SORT_GROUPS + 1 ); ++iGroup )
  105. {
  106. for ( int iSort = 0; iSort < DECALSORT_TYPE_COUNT; ++iSort )
  107. {
  108. m_aDecalSortBuckets[iGroup][iSort].Purge();
  109. }
  110. }
  111. }
  112. };
  113. extern CUtlVector<DecalSortVertexFormat_t> g_aDecalFormats;
  114. // Surface decals.
  115. extern CUtlFixedLinkedList<decal_t*> g_aDecalSortPool;
  116. extern CUtlVector<DecalSortTrees_t> g_aDecalSortTrees;
  117. extern int g_nDecalSortCheckCount;
  118. extern int g_nBrushModelDecalSortCheckCount;
  119. // Displacement decals.
  120. extern CUtlFixedLinkedList<decal_t*> g_aDispDecalSortPool;
  121. extern CUtlVector<DecalSortTrees_t> g_aDispDecalSortTrees;
  122. extern int g_nDispDecalSortCheckCount;
  123. struct DecalBatchList_t
  124. {
  125. IMaterial *m_pMaterial;
  126. void *m_pProxy;
  127. int m_iLightmapPage;
  128. unsigned short m_iStartIndex;
  129. unsigned short m_nIndexCount;
  130. };
  131. struct DecalMeshList_t
  132. {
  133. IMesh *m_pMesh;
  134. CUtlVectorFixed<DecalBatchList_t, 128> m_aBatches;
  135. };
  136. void DecalSurfacesInit( bool bBrushModel );
  137. void DecalSurfaceAdd( SurfaceHandle_t surfID, int renderGroup );
  138. void DecalSurfaceDraw( IMatRenderContext *pRenderContext, int renderGroup, float flFade = 1.0f );
  139. void DrawDecalsOnSingleSurface( IMatRenderContext *pRenderContext, SurfaceHandle_t surfID );
  140. void R_DecalReSortMaterials( void );
  141. void R_DecalFlushDestroyList( void );
  142. extern VMatrix g_BrushToWorldMatrix;
  143. #include "tier0/memdbgoff.h"
  144. #endif // R_DECAL_H