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.

829 lines
23 KiB

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