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.

796 lines
22 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //=============================================================================//
  9. #ifndef GL_MODEL_PRIVATE_H
  10. #define GL_MODEL_PRIVATE_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "mathlib/vector4d.h"
  15. #include "tier0/dbg.h"
  16. #include "tier1/utlsymbol.h"
  17. #include "idispinfo.h"
  18. #include "shadowmgr.h"
  19. #include "vcollide.h"
  20. #include "studio.h"
  21. #include "qlimits.h"
  22. #include "host.h"
  23. #include "gl_model.h"
  24. #include "cmodel.h"
  25. #include "bspfile.h"
  26. #include "Overlay.h"
  27. //#include "datamap.h"
  28. #include "surfacehandle.h"
  29. #include "mathlib/compressed_light_cube.h"
  30. #include "datacache/imdlcache.h"
  31. #include "bitmap/cubemap.h"
  32. //-----------------------------------------------------------------------------
  33. // forward declarations
  34. //-----------------------------------------------------------------------------
  35. struct studiomeshdata_t;
  36. struct decal_t;
  37. struct msurface1_t;
  38. struct msurfacelighting_t;
  39. struct msurfacenormal_t;
  40. class ITexture;
  41. class CEngineSprite;
  42. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  43. struct mvertex_t
  44. {
  45. Vector position;
  46. };
  47. // !!! if this is changed, it must be changed in asm_draw.h too !!!
  48. struct medge_t
  49. {
  50. unsigned short v[2];
  51. // unsigned int cachededgeoffset;
  52. };
  53. class IMaterial;
  54. class IMaterialVar;
  55. // This is here for b/w compatibility with world surfaces that use
  56. // WorldVertexTransition. We can get rid of it when we rev the engine.
  57. #define TEXINFO_USING_BASETEXTURE2 0x0001
  58. struct mtexinfo_t
  59. {
  60. Vector4D textureVecsTexelsPerWorldUnits[2]; // [s/t] unit vectors in world space.
  61. // [i][3] is the s/t offset relative to the origin.
  62. Vector4D lightmapVecsLuxelsPerWorldUnits[2];
  63. float luxelsPerWorldUnit;
  64. float worldUnitsPerLuxel;
  65. unsigned short flags; // SURF_ flags.
  66. unsigned short texinfoFlags;// TEXINFO_ flags.
  67. IMaterial *material;
  68. mtexinfo_t( mtexinfo_t const& src )
  69. {
  70. // copy constructor needed since Vector4D has no copy constructor
  71. memcpy( this, &src, sizeof(mtexinfo_t) );
  72. }
  73. };
  74. struct mnode_t
  75. {
  76. // common with leaf
  77. int contents; // <0 to differentiate from leafs
  78. // -1 means check the node for visibility
  79. // -2 means don't check the node for visibility
  80. int visframe; // node needs to be traversed if current
  81. mnode_t *parent;
  82. short area; // If all leaves below this node are in the same area, then
  83. // this is the area index. If not, this is -1.
  84. short flags;
  85. VectorAligned m_vecCenter;
  86. VectorAligned m_vecHalfDiagonal;
  87. // node specific
  88. cplane_t *plane;
  89. mnode_t *children[2];
  90. unsigned short firstsurface;
  91. unsigned short numsurfaces;
  92. };
  93. struct mleaf_t
  94. {
  95. public:
  96. // common with node
  97. int contents; // contents mask
  98. int visframe; // node needs to be traversed if current
  99. mnode_t *parent;
  100. short area;
  101. short flags;
  102. VectorAligned m_vecCenter;
  103. VectorAligned m_vecHalfDiagonal;
  104. // leaf specific
  105. short cluster;
  106. short leafWaterDataID;
  107. unsigned short firstmarksurface;
  108. unsigned short nummarksurfaces;
  109. short nummarknodesurfaces;
  110. short unused;
  111. unsigned short dispListStart; // index into displist of first displacement
  112. unsigned short dispCount; // number of displacements in the list for this leaf
  113. };
  114. struct mleafwaterdata_t
  115. {
  116. float surfaceZ;
  117. float minZ;
  118. short surfaceTexInfoID;
  119. short firstLeafIndex;
  120. };
  121. struct mcubemapsample_t
  122. {
  123. Vector origin;
  124. ITexture *pTexture;
  125. unsigned char size; // default (mat_envmaptgasize) if 0, 1<<(size-1) otherwise.
  126. };
  127. typedef struct mportal_s
  128. {
  129. unsigned short *vertList;
  130. int numportalverts;
  131. cplane_t *plane;
  132. unsigned short cluster[2];
  133. // int visframe;
  134. } mportal_t;
  135. typedef struct mcluster_s
  136. {
  137. unsigned short *portalList;
  138. int numportals;
  139. } mcluster_t;
  140. struct mmodel_t
  141. {
  142. Vector mins, maxs;
  143. Vector origin; // for sounds or lights
  144. float radius;
  145. int headnode;
  146. int firstface, numfaces;
  147. };
  148. struct mprimitive_t
  149. {
  150. int type;
  151. unsigned short firstIndex;
  152. unsigned short indexCount;
  153. unsigned short firstVert;
  154. unsigned short vertCount;
  155. };
  156. struct mprimvert_t
  157. {
  158. Vector pos;
  159. float texCoord[2];
  160. float lightCoord[2];
  161. };
  162. typedef dleafambientindex_t mleafambientindex_t;
  163. typedef dleafambientlighting_t mleafambientlighting_t;
  164. struct LightShadowZBufferSample_t
  165. {
  166. float m_flTraceDistance; // how far we traced. 0 = invalid
  167. float m_flHitDistance; // where we hit
  168. };
  169. #define SHADOW_ZBUF_RES 8 // 6 * 64 * 2 * 4 = 3k bytes per light
  170. typedef CCubeMap< LightShadowZBufferSample_t, SHADOW_ZBUF_RES> lightzbuffer_t;
  171. #include "model_types.h"
  172. #define MODELFLAG_MATERIALPROXY 0x0001 // we've got a material proxy
  173. #define MODELFLAG_TRANSLUCENT 0x0002 // we've got a translucent model
  174. #define MODELFLAG_VERTEXLIT 0x0004 // we've got a vertex-lit model
  175. #define MODELFLAG_TRANSLUCENT_TWOPASS 0x0008 // render opaque part in opaque pass
  176. #define MODELFLAG_FRAMEBUFFER_TEXTURE 0x0010 // we need the framebuffer as a texture
  177. #define MODELFLAG_HAS_DLIGHT 0x0020 // need to check dlights
  178. #define MODELFLAG_STUDIOHDR_USES_FB_TEXTURE 0x0100 // persisted from studiohdr
  179. #define MODELFLAG_STUDIOHDR_USES_BUMPMAPPING 0x0200 // persisted from studiohdr
  180. #define MODELFLAG_STUDIOHDR_USES_ENV_CUBEMAP 0x0400 // persisted from studiohdr
  181. #define MODELFLAG_STUDIOHDR_AMBIENT_BOOST 0x0800 // persisted from studiohdr
  182. #define MODELFLAG_STUDIOHDR_DO_NOT_CAST_SHADOWS 0x1000 // persisted from studiohdr
  183. struct worldbrushdata_t
  184. {
  185. int numsubmodels;
  186. int numplanes;
  187. cplane_t *planes;
  188. int numleafs; // number of visible leafs, not counting 0
  189. mleaf_t *leafs;
  190. int numleafwaterdata;
  191. mleafwaterdata_t *leafwaterdata;
  192. int numvertexes;
  193. mvertex_t *vertexes;
  194. int numoccluders;
  195. doccluderdata_t *occluders;
  196. int numoccluderpolys;
  197. doccluderpolydata_t *occluderpolys;
  198. int numoccludervertindices;
  199. int *occludervertindices;
  200. int numvertnormalindices; // These index vertnormals.
  201. unsigned short *vertnormalindices;
  202. int numvertnormals;
  203. Vector *vertnormals;
  204. int numnodes;
  205. mnode_t *nodes;
  206. unsigned short *m_LeafMinDistToWater;
  207. int numtexinfo;
  208. mtexinfo_t *texinfo;
  209. int numtexdata;
  210. csurface_t *texdata;
  211. int numDispInfos;
  212. HDISPINFOARRAY hDispInfos; // Use DispInfo_Index to get IDispInfos..
  213. /*
  214. int numOrigSurfaces;
  215. msurface_t *pOrigSurfaces;
  216. */
  217. int numsurfaces;
  218. msurface1_t *surfaces1;
  219. msurface2_t *surfaces2;
  220. msurfacelighting_t *surfacelighting;
  221. msurfacenormal_t *surfacenormals;
  222. bool unloadedlightmaps;
  223. int numvertindices;
  224. unsigned short *vertindices;
  225. int nummarksurfaces;
  226. SurfaceHandle_t *marksurfaces;
  227. ColorRGBExp32 *lightdata;
  228. int numworldlights;
  229. dworldlight_t *worldlights;
  230. lightzbuffer_t *shadowzbuffers;
  231. // non-polygon primitives (strips and lists)
  232. int numprimitives;
  233. mprimitive_t *primitives;
  234. int numprimverts;
  235. mprimvert_t *primverts;
  236. int numprimindices;
  237. unsigned short *primindices;
  238. int m_nAreas;
  239. darea_t *m_pAreas;
  240. int m_nAreaPortals;
  241. dareaportal_t *m_pAreaPortals;
  242. int m_nClipPortalVerts;
  243. Vector *m_pClipPortalVerts;
  244. mcubemapsample_t *m_pCubemapSamples;
  245. int m_nCubemapSamples;
  246. int m_nDispInfoReferences;
  247. unsigned short *m_pDispInfoReferences;
  248. mleafambientindex_t *m_pLeafAmbient;
  249. mleafambientlighting_t *m_pAmbientSamples;
  250. #if 0
  251. int numportals;
  252. mportal_t *portals;
  253. int numclusters;
  254. mcluster_t *clusters;
  255. int numportalverts;
  256. unsigned short *portalverts;
  257. int numclusterportals;
  258. unsigned short *clusterportals;
  259. #endif
  260. };
  261. // only models with type "mod_brush" have this data
  262. struct brushdata_t
  263. {
  264. worldbrushdata_t *pShared;
  265. int firstmodelsurface, nummodelsurfaces;
  266. unsigned short renderHandle;
  267. unsigned short firstnode;
  268. };
  269. // only models with type "mod_sprite" have this data
  270. struct spritedata_t
  271. {
  272. int numframes;
  273. int width;
  274. int height;
  275. CEngineSprite *sprite;
  276. };
  277. struct model_t
  278. {
  279. FileNameHandle_t fnHandle;
  280. CUtlString strName;
  281. int nLoadFlags; // mark loaded/not loaded
  282. int nServerCount; // marked at load
  283. IMaterial **ppMaterials; // null-terminated runtime material cache; ((intptr_t*)(ppMaterials))[-1] == nMaterials
  284. modtype_t type;
  285. int flags; // MODELFLAG_???
  286. // volume occupied by the model graphics
  287. Vector mins, maxs;
  288. float radius;
  289. union
  290. {
  291. brushdata_t brush;
  292. MDLHandle_t studio;
  293. spritedata_t sprite;
  294. };
  295. };
  296. //-----------------------------------------------------------------------------
  297. // Decals
  298. //-----------------------------------------------------------------------------
  299. struct decallist_t
  300. {
  301. DECLARE_SIMPLE_DATADESC();
  302. Vector position;
  303. char name[ 128 ];
  304. short entityIndex;
  305. byte depth;
  306. byte flags;
  307. // This is the surface plane that we hit so that we can move certain decals across
  308. // transitions if they hit similar geometry
  309. Vector impactPlaneNormal;
  310. };
  311. inline class IDispInfo *MLeaf_Disaplcement( mleaf_t *pLeaf, int index, worldbrushdata_t *pData = host_state.worldbrush )
  312. {
  313. Assert(index<pLeaf->dispCount);
  314. int dispIndex = pData->m_pDispInfoReferences[pLeaf->dispListStart+index];
  315. return DispInfo_IndexArray( pData->hDispInfos, dispIndex );
  316. }
  317. #define MAXLIGHTMAPS 4
  318. // drawing surface flags
  319. #define SURFDRAW_NOLIGHT 0x00000001 // no lightmap
  320. #define SURFDRAW_NODE 0x00000002 // This surface is on a node
  321. #define SURFDRAW_SKY 0x00000004 // portal to sky
  322. #define SURFDRAW_BUMPLIGHT 0x00000008 // Has multiple lightmaps for bump-mapping
  323. #define SURFDRAW_NODRAW 0x00000010 // don't draw this surface, not really visible
  324. #define SURFDRAW_TRANS 0x00000020 // sort this surface from back to front
  325. #define SURFDRAW_PLANEBACK 0x00000040 // faces away from plane of the node that stores this face
  326. #define SURFDRAW_DYNAMIC 0x00000080 // Don't use a static buffer for this face
  327. #define SURFDRAW_TANGENTSPACE 0x00000100 // This surface needs a tangent space
  328. #define SURFDRAW_NOCULL 0x00000200 // Don't bother backface culling these
  329. #define SURFDRAW_HASLIGHTSYTLES 0x00000400 // has a lightstyle other than 0
  330. #define SURFDRAW_HAS_DISP 0x00000800 // has a dispinfo
  331. #define SURFDRAW_ALPHATEST 0x00001000 // Is alphstested
  332. #define SURFDRAW_NOSHADOWS 0x00002000 // No shadows baby
  333. #define SURFDRAW_NODECALS 0x00004000 // No decals baby
  334. #define SURFDRAW_HAS_PRIMS 0x00008000 // has a list of prims
  335. #define SURFDRAW_WATERSURFACE 0x00010000 // This is a water surface
  336. #define SURFDRAW_UNDERWATER 0x00020000
  337. #define SURFDRAW_ABOVEWATER 0x00040000
  338. #define SURFDRAW_HASDLIGHT 0x00080000 // Has some kind of dynamic light that must be checked
  339. #define SURFDRAW_DLIGHTPASS 0x00100000 // Must be drawn in the dlight pass
  340. #define SURFDRAW_UNUSED2 0x00200000 // unused
  341. #define SURFDRAW_VERTCOUNT_MASK 0xFF000000 // 8 bits of vertex count
  342. #define SURFDRAW_SORTGROUP_MASK 0x00C00000 // 2 bits of sortgroup
  343. #define SURFDRAW_VERTCOUNT_SHIFT 24
  344. #define SURFDRAW_SORTGROUP_SHIFT 22
  345. // NOTE: 16-bytes, preserve size/alignment - we index this alot
  346. struct msurface1_t
  347. {
  348. // garymct - are these needed? - used by decal projection code
  349. int textureMins[2]; // smallest unnormalized s/t position on the surface.
  350. short textureExtents[2]; // ?? s/t texture size, 1..512 for all non-sky surfaces
  351. struct
  352. {
  353. unsigned short numPrims;
  354. unsigned short firstPrimID; // index into primitive list if numPrims > 0
  355. } prims;
  356. };
  357. #pragma pack(1)
  358. struct msurfacenormal_t
  359. {
  360. unsigned int firstvertnormal;
  361. // unsigned short firstvertnormal;
  362. // FIXME: Should I just point to the leaf here since it has this data?????????????
  363. // short fogVolumeID; // -1 if not in fog
  364. };
  365. #pragma pack()
  366. // This is a single cache line (32 bytes)
  367. struct msurfacelighting_t
  368. {
  369. // You read that minus sign right. See the comment below.
  370. ColorRGBExp32 *AvgLightColor( int nLightStyleIndex ) { return m_pSamples - (nLightStyleIndex + 1); }
  371. // Lightmap info
  372. short m_LightmapMins[2];
  373. short m_LightmapExtents[2];
  374. short m_OffsetIntoLightmapPage[2];
  375. int m_nLastComputedFrame; // last frame the surface's lightmap was recomputed
  376. int m_fDLightBits; // Indicates which dlights illuminates this surface.
  377. int m_nDLightFrame; // Indicates the last frame in which dlights illuminated this surface
  378. unsigned char m_nStyles[MAXLIGHTMAPS]; // index into d_lightstylevalue[] for animated lights
  379. // no one surface can be effected by more than 4
  380. // animated lights.
  381. // NOTE: This is tricky. To get this to fit in a single cache line,
  382. // and to save the extra memory of not having to store average light colors for
  383. // lightstyles that are not used, I store between 0 and 4 average light colors +before+
  384. // the samples, depending on how many lightstyles there are. Naturally, accessing
  385. // an average color for an undefined lightstyle on the surface results in undefined results.
  386. // 0->4 avg light colors, *in reverse order from m_nStyles* + [numstyles*surfsize]
  387. ColorRGBExp32 *m_pSamples;
  388. };
  389. const int WORLD_DECAL_HANDLE_INVALID = 0xFFFF;
  390. typedef unsigned short WorldDecalHandle_t;
  391. #pragma pack(1)
  392. // NOTE: 32-bytes. Aligned/indexed often
  393. struct msurface2_t
  394. {
  395. unsigned int flags; // see SURFDRAW_ #defines (only 22-bits right now)
  396. // These are packed in to flags now
  397. //unsigned char vertCount; // number of verts for this surface
  398. //unsigned char sortGroup; // only uses 2 bits, subdivide?
  399. cplane_t *plane; // pointer to shared plane
  400. int firstvertindex; // look up in model->vertindices[] (only uses 17-18 bits?)
  401. WorldDecalHandle_t decals;
  402. ShadowDecalHandle_t m_ShadowDecals; // unsigned short
  403. OverlayFragmentHandle_t m_nFirstOverlayFragment; // First overlay fragment on the surface (short)
  404. short materialSortID;
  405. unsigned short vertBufferIndex;
  406. unsigned short m_bDynamicShadowsEnabled : 1; // Can this surface receive dynamic shadows?
  407. unsigned short texinfo : 15;
  408. IDispInfo *pDispInfo; // displacement map information
  409. int visframe; // should be drawn when node is crossed
  410. };
  411. #pragma pack()
  412. inline unsigned short MSurf_AreDynamicShadowsEnabled( SurfaceHandle_t surfID )
  413. {
  414. return surfID->m_bDynamicShadowsEnabled;
  415. }
  416. inline int MSurf_Index( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  417. {
  418. int surfaceIndex = surfID - pData->surfaces2;
  419. Assert(surfaceIndex >= 0 && surfaceIndex < pData->numsurfaces);
  420. return surfaceIndex;
  421. }
  422. inline const SurfaceHandle_t SurfaceHandleFromIndex( int surfaceIndex, const worldbrushdata_t *pData )
  423. {
  424. return &pData->surfaces2[surfaceIndex];
  425. }
  426. inline SurfaceHandle_t SurfaceHandleFromIndex( int surfaceIndex, worldbrushdata_t *pData = host_state.worldbrush )
  427. {
  428. return &pData->surfaces2[surfaceIndex];
  429. }
  430. #if _DEBUG
  431. #define ASSERT_SURF_VALID(surfID) MSurf_Index(surfID)
  432. #else
  433. #define ASSERT_SURF_VALID(surfID)
  434. #endif
  435. inline unsigned int& MSurf_Flags( SurfaceHandle_t surfID )
  436. {
  437. return surfID->flags;
  438. }
  439. inline bool SurfaceHasDispInfo( SurfaceHandle_t surfID )
  440. {
  441. return ( MSurf_Flags( surfID ) & SURFDRAW_HAS_DISP ) ? true : false;
  442. }
  443. inline bool SurfaceHasPrims( SurfaceHandle_t surfID )
  444. {
  445. return ( MSurf_Flags( surfID ) & SURFDRAW_HAS_PRIMS ) ? true : false;
  446. }
  447. inline int& MSurf_VisFrame( SurfaceHandle_t surfID )
  448. {
  449. return surfID->visframe;
  450. }
  451. inline int MSurf_SortGroup( SurfaceHandle_t surfID )
  452. {
  453. return (surfID->flags & SURFDRAW_SORTGROUP_MASK) >> SURFDRAW_SORTGROUP_SHIFT;
  454. }
  455. inline void MSurf_SetSortGroup( SurfaceHandle_t surfID, int sortGroup )
  456. {
  457. unsigned int flags = (sortGroup << SURFDRAW_SORTGROUP_SHIFT) & SURFDRAW_SORTGROUP_MASK;
  458. surfID->flags |= flags;
  459. }
  460. /*
  461. inline int& MSurf_DLightFrame( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  462. {
  463. // ASSERT_SURF_VALID( surfID );
  464. Assert( pData );
  465. return pData->surfacelighting[surfID].dlightframe;
  466. }
  467. */
  468. inline int& MSurf_DLightBits( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  469. {
  470. int surfaceIndex = MSurf_Index(surfID,pData);
  471. // ASSERT_SURF_VALID( surfID );
  472. Assert( pData );
  473. return pData->surfacelighting[surfaceIndex].m_fDLightBits;
  474. }
  475. inline cplane_t& MSurf_Plane( SurfaceHandle_t surfID )
  476. {
  477. return *surfID->plane;
  478. }
  479. inline int& MSurf_FirstVertIndex( SurfaceHandle_t surfID )
  480. {
  481. return surfID->firstvertindex;
  482. }
  483. inline int MSurf_VertCount( SurfaceHandle_t surfID )
  484. {
  485. return (surfID->flags >> SURFDRAW_VERTCOUNT_SHIFT) & 0xFF;
  486. }
  487. inline void MSurf_SetVertCount( SurfaceHandle_t surfID, int vertCount )
  488. {
  489. int flags = (vertCount << SURFDRAW_VERTCOUNT_SHIFT) & SURFDRAW_VERTCOUNT_MASK;
  490. surfID->flags |= flags;
  491. }
  492. inline int *MSurf_TextureMins( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  493. {
  494. int surfaceIndex = MSurf_Index(surfID,pData);
  495. // ASSERT_SURF_VALID( surfID );
  496. Assert( pData );
  497. return pData->surfaces1[surfaceIndex].textureMins;
  498. }
  499. inline short *MSurf_TextureExtents( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  500. {
  501. int surfaceIndex = MSurf_Index(surfID,pData);
  502. // ASSERT_SURF_VALID( surfID );
  503. Assert( pData );
  504. return pData->surfaces1[surfaceIndex].textureExtents;
  505. }
  506. inline short *MSurf_LightmapMins( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  507. {
  508. int surfaceIndex = MSurf_Index(surfID,pData);
  509. // ASSERT_SURF_VALID( surfID );
  510. Assert( pData );
  511. return pData->surfacelighting[surfaceIndex].m_LightmapMins;
  512. }
  513. inline short *MSurf_LightmapExtents( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  514. {
  515. int surfaceIndex = MSurf_Index(surfID,pData);
  516. // ASSERT_SURF_VALID( surfID );
  517. Assert( pData );
  518. return pData->surfacelighting[surfaceIndex].m_LightmapExtents;
  519. }
  520. inline short MSurf_MaxLightmapSizeWithBorder( SurfaceHandle_t surfID )
  521. {
  522. // ASSERT_SURF_VALID( surfID );
  523. return SurfaceHasDispInfo( surfID ) ? MAX_DISP_LIGHTMAP_DIM_INCLUDING_BORDER : MAX_BRUSH_LIGHTMAP_DIM_INCLUDING_BORDER;
  524. }
  525. inline short MSurf_MaxLightmapSizeWithoutBorder( SurfaceHandle_t surfID )
  526. {
  527. // ASSERT_SURF_VALID( surfID );
  528. return SurfaceHasDispInfo( surfID ) ? MAX_DISP_LIGHTMAP_DIM_WITHOUT_BORDER : MAX_BRUSH_LIGHTMAP_DIM_WITHOUT_BORDER;
  529. }
  530. inline mtexinfo_t *MSurf_TexInfo( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  531. {
  532. return &pData->texinfo[surfID->texinfo];
  533. }
  534. inline WorldDecalHandle_t& MSurf_Decals( SurfaceHandle_t surfID )
  535. {
  536. return surfID->decals;
  537. }
  538. inline bool SurfaceHasDecals( SurfaceHandle_t surfID )
  539. {
  540. return ( MSurf_Decals( surfID ) != WORLD_DECAL_HANDLE_INVALID ) ? true : false;
  541. }
  542. inline ShadowDecalHandle_t& MSurf_ShadowDecals( SurfaceHandle_t surfID )
  543. {
  544. return surfID->m_ShadowDecals;
  545. }
  546. inline ColorRGBExp32 *MSurf_AvgLightColor( SurfaceHandle_t surfID, int nIndex, worldbrushdata_t *pData = host_state.worldbrush )
  547. {
  548. int surfaceIndex = MSurf_Index(surfID,pData);
  549. // ASSERT_SURF_VALID( surfID );
  550. Assert( pData );
  551. return pData->surfacelighting[surfaceIndex].AvgLightColor(nIndex);
  552. }
  553. inline byte *MSurf_Styles( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  554. {
  555. int surfaceIndex = MSurf_Index(surfID,pData);
  556. // ASSERT_SURF_VALID( surfID );
  557. Assert( pData );
  558. return pData->surfacelighting[surfaceIndex].m_nStyles;
  559. }
  560. /*
  561. inline int *MSurf_CachedLight( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  562. {
  563. // ASSERT_SURF_VALID( surfID );
  564. Assert( pData );
  565. return pData->surfacelighting[surfID].cached_light;
  566. }
  567. inline short& MSurf_CachedDLight( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  568. {
  569. // ASSERT_SURF_VALID( surfID );
  570. Assert( pData );
  571. return pData->surfacelighting[surfID].cached_dlight;
  572. }
  573. */
  574. inline unsigned short MSurf_NumPrims( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  575. {
  576. if ( SurfaceHasDispInfo( surfID ) || !SurfaceHasPrims( surfID ))
  577. return 0;
  578. int surfaceIndex = MSurf_Index(surfID,pData);
  579. // ASSERT_SURF_VALID( surfID );
  580. Assert( pData );
  581. return pData->surfaces1[surfaceIndex].prims.numPrims;
  582. }
  583. inline unsigned short MSurf_FirstPrimID( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  584. {
  585. if ( SurfaceHasDispInfo( surfID ) )
  586. return 0;
  587. int surfaceIndex = MSurf_Index(surfID,pData);
  588. // ASSERT_SURF_VALID( surfID );
  589. Assert( pData );
  590. return pData->surfaces1[surfaceIndex].prims.firstPrimID;
  591. }
  592. inline ColorRGBExp32 *MSurf_Samples( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  593. {
  594. int surfaceIndex = MSurf_Index(surfID,pData);
  595. // ASSERT_SURF_VALID( surfID );
  596. Assert( pData );
  597. return pData->surfacelighting[surfaceIndex].m_pSamples;
  598. }
  599. inline IDispInfo *MSurf_DispInfo( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  600. {
  601. return surfID->pDispInfo;
  602. }
  603. //inline unsigned short &MSurf_FirstVertNormal( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  604. inline unsigned int &MSurf_FirstVertNormal( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  605. {
  606. int surfaceIndex = MSurf_Index(surfID,pData);
  607. // ASSERT_SURF_VALID( surfID );
  608. Assert( pData );
  609. Assert( pData->surfacenormals[surfaceIndex].firstvertnormal < MAX_MAP_VERTNORMALINDICES );
  610. return pData->surfacenormals[surfaceIndex].firstvertnormal;
  611. }
  612. inline unsigned short &MSurf_VertBufferIndex( SurfaceHandle_t surfID )
  613. {
  614. return surfID->vertBufferIndex;
  615. }
  616. inline short& MSurf_MaterialSortID( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  617. {
  618. return surfID->materialSortID;
  619. }
  620. inline short *MSurf_OffsetIntoLightmapPage( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  621. {
  622. int surfaceIndex = MSurf_Index(surfID,pData);
  623. // ASSERT_SURF_VALID( surfID );
  624. Assert( pData );
  625. return pData->surfacelighting[surfaceIndex].m_OffsetIntoLightmapPage;
  626. }
  627. inline VPlane MSurf_GetForwardFacingPlane( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  628. {
  629. // ASSERT_SURF_VALID( surfID );
  630. Assert( pData );
  631. return VPlane( MSurf_Plane( surfID).normal, MSurf_Plane( surfID ).dist );
  632. }
  633. inline OverlayFragmentHandle_t &MSurf_OverlayFragmentList( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  634. {
  635. return surfID->m_nFirstOverlayFragment;
  636. }
  637. inline msurfacelighting_t *SurfaceLighting( SurfaceHandle_t surfID, worldbrushdata_t *pData = host_state.worldbrush )
  638. {
  639. int surfaceIndex = MSurf_Index(surfID,pData);
  640. Assert( pData );
  641. return &pData->surfacelighting[surfaceIndex];
  642. }
  643. #endif // GL_MODEL_PRIVATE_H