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.

186 lines
4.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef BSPLIGHTING_H
  8. #define BSPLIGHTING_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include "stdafx.h"
  13. #include "ibsplighting.h"
  14. #include "utlvector.h"
  15. #include "utllinkedlist.h"
  16. #include "bspfile.h"
  17. #include "interface.h"
  18. #include "ivraddll.h"
  19. #include "ibsplightingthread.h"
  20. class CBSPLighting : public IBSPLighting
  21. {
  22. public:
  23. CBSPLighting();
  24. virtual ~CBSPLighting();
  25. virtual void Release();
  26. virtual bool Load( char const *pFilename );
  27. virtual void Term();
  28. virtual bool Serialize();
  29. virtual void StartLighting( char const *pVMFFileWithEnts );
  30. virtual float GetPercentComplete();
  31. virtual void Interrupt();
  32. virtual bool CheckForNewLightmaps();
  33. virtual void Draw();
  34. private:
  35. class CVert
  36. {
  37. public:
  38. Vector m_vPos;
  39. Vector2D m_vTexCoords;
  40. Vector2D m_vLightCoords;
  41. };
  42. // This is the face data we store for each face. Just enough to
  43. // let us update the lightmaps in memory.
  44. class CFaceMaterial;
  45. class CFace;
  46. class CStoredFace
  47. {
  48. public:
  49. int m_iMapFace; // index into dfaces.
  50. int m_LightmapPageID;
  51. int m_OffsetIntoLightmapPage[2];
  52. int m_LightmapSize[2]; // This already has 1 added to it (unlike dface).
  53. CFaceMaterial *m_pMaterial;
  54. CFace *m_pFace; // only valid inside of Load
  55. float m_BumpSTexCoordOffset;
  56. // Indices into CFaceMaterial::m_pMesh
  57. int m_iFirstIndex;
  58. int m_nIndices;
  59. };
  60. class CDrawCommand
  61. {
  62. public:
  63. CUtlVector<CPrimList> m_PrimLists;
  64. int m_LightmapPageID;
  65. };
  66. friend bool FindDrawCommand( CUtlVector<CDrawCommand*> &drawCommands, int lmPageID, int &index );
  67. class CMaterialBuf
  68. {
  69. public:
  70. CMaterialBuf();
  71. ~CMaterialBuf();
  72. CUtlLinkedList<CStoredFace*, unsigned short> m_Faces;
  73. // Commands to draw everything in this material as fast as possible.
  74. CUtlVector<CDrawCommand*> m_DrawCommands;
  75. int m_nVerts;
  76. int m_nIndices;
  77. IMesh *m_pMesh;
  78. };
  79. class CFaceMaterial
  80. {
  81. public:
  82. ~CFaceMaterial();
  83. IMaterial *m_pMaterial;
  84. // Faces using this material.
  85. CUtlLinkedList<CStoredFace*, unsigned short> m_Faces;
  86. // Static buffers to hold all the verts.
  87. CUtlLinkedList<CMaterialBuf*, unsigned short> m_MaterialBufs;
  88. };
  89. class CFace
  90. {
  91. public:
  92. int m_iDispInfo;
  93. dface_t *m_pDFace; // used while loading..
  94. CStoredFace *m_pStoredFace;
  95. int m_LightmapSortID;
  96. float m_LightmapVecs[2][4];
  97. int m_LightmapTextureMinsInLuxels[2];
  98. int m_iVertStart; // Indexes CBSPLighting::m_Verts.
  99. int m_nVerts;
  100. };
  101. class CDispInfoFaces
  102. {
  103. public:
  104. CUtlVector<CVert> m_Verts;
  105. int m_Power;
  106. };
  107. private:
  108. void AssignFaceMaterialCounts(
  109. CBSPInfo &file,
  110. CUtlVector<CFace> &faces );
  111. VertexFormat_t ComputeLMGroupVertexFormat( IMaterial * pMaterial );
  112. void BuildLMGroups(
  113. CBSPInfo &file,
  114. CUtlVector<CFace> &faces,
  115. CUtlVector<CVert> &verts,
  116. CUtlVector<CDispInfoFaces> &dispInfos
  117. );
  118. void BuildDrawCommands();
  119. void ReloadLightmaps();
  120. bool LoadVRADDLL( char const *pFilename );
  121. void CreateDisplacements( CBSPInfo &file, CUtlVector<CFace> &faces, CUtlVector<CDispInfoFaces> &dispInfos );
  122. // Fast material ID to CFaceMaterial lookups..
  123. void InitMaterialLUT( CBSPInfo &file );
  124. CFaceMaterial* FindOrAddMaterial( CBSPInfo &file, int stringTableID );
  125. private:
  126. CUtlVector<CStoredFace> m_StoredFaces;
  127. CUtlLinkedList<CFaceMaterial*, unsigned short> m_FaceMaterials;
  128. int m_nTotalTris;
  129. // The VRAD DLL. This holds the level file.
  130. CSysModule *m_hVRadDLL;
  131. IVRadDLL *m_pVRadDLL;
  132. // The lighting thread.
  133. IBSPLightingThread *m_pBSPLightingThread;
  134. // Used to detect when lighting is finished so it can update the lightmaps
  135. // in the material system.
  136. bool m_bLightingInProgress;
  137. // Maps string table IDs to materials.
  138. CUtlVector<CFaceMaterial*> m_StringTableIDToMaterial;
  139. };
  140. #endif // BSPLIGHTING_H