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