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.

237 lines
8.2 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. #ifndef GL_RSURF_H
  10. #define GL_RSURF_H
  11. #ifdef _WIN32
  12. #pragma once
  13. #endif
  14. #include "mathlib/vector.h"
  15. #include "bsptreedata.h"
  16. #include "materialsystem/imesh.h"
  17. class Vector;
  18. struct WorldListInfo_t;
  19. class IMaterial;
  20. class IClientRenderable;
  21. class IBrushRenderer;
  22. class IClientEntity;
  23. struct model_t;
  24. struct cplane_t;
  25. struct VisibleFogVolumeInfo_t;
  26. struct LightmapUpdateInfo_t
  27. {
  28. SurfaceHandle_t m_SurfHandle;
  29. int transformIndex;
  30. };
  31. struct LightmapTransformInfo_t
  32. {
  33. model_t *pModel;
  34. matrix3x4_t xform;
  35. };
  36. extern CUtlVector<LightmapUpdateInfo_t> g_LightmapUpdateList;
  37. extern CUtlVector<LightmapTransformInfo_t> g_LightmapTransformList;
  38. //-----------------------------------------------------------------------------
  39. // Helper class to iterate over leaves
  40. //-----------------------------------------------------------------------------
  41. class IEngineSpatialQuery : public ISpatialQuery
  42. {
  43. public:
  44. };
  45. extern IEngineSpatialQuery* g_pToolBSPTree;
  46. class IWorldRenderList;
  47. IWorldRenderList *AllocWorldRenderList();
  48. void R_Surface_LevelInit();
  49. void R_Surface_LevelShutdown();
  50. void R_SceneBegin( void );
  51. void R_SceneEnd( void );
  52. void R_BuildWorldLists( IWorldRenderList *pRenderList, WorldListInfo_t* pInfo, int iForceViewLeaf, const struct VisOverrideData_t* pVisData, bool bShadowDepth = false, float *pWaterReflectionHeight = NULL );
  53. void R_DrawWorldLists( IWorldRenderList *pRenderList, unsigned long flags, float waterZAdjust );
  54. void R_GetVisibleFogVolume( const Vector& vEyePoint, VisibleFogVolumeInfo_t *pInfo );
  55. void R_SetFogVolumeState( int fogVolume, bool useHeightFog );
  56. IMaterial *R_GetFogVolumeMaterial( int fogVolume, bool bEyeInFogVolume );
  57. void R_SetupSkyTexture( model_t *pWorld );
  58. void Shader_DrawLightmapPageChains( IWorldRenderList *pRenderList, int pageId );
  59. void Shader_DrawLightmapPageSurface( SurfaceHandle_t surfID, float red, float green, float blue );
  60. void Shader_DrawTranslucentSurfaces( IWorldRenderList *pRenderList, int sortIndex, unsigned long flags, bool bShadowDepth );
  61. bool Shader_LeafContainsTranslucentSurfaces( IWorldRenderList *pRenderList, int sortIndex, unsigned long flags );
  62. void R_DrawTopView( bool enable );
  63. void R_TopViewBounds( const Vector2D & mins, const Vector2D & maxs );
  64. // Resets a world render list
  65. void ResetWorldRenderList( IWorldRenderList *pRenderList );
  66. // Computes the centroid of a surface
  67. void Surf_ComputeCentroid( SurfaceHandle_t surfID, Vector *pVecCentroid );
  68. // Installs a client-side renderer for brush models
  69. void R_InstallBrushRenderOverride( IBrushRenderer* pBrushRenderer );
  70. // update dlight status on a brush model
  71. extern int R_MarkDlightsOnBrushModel( model_t *model, IClientRenderable *pRenderable );
  72. void R_DrawBrushModel(
  73. IClientEntity *baseentity,
  74. model_t *model,
  75. const Vector& origin,
  76. const QAngle& angles,
  77. ERenderDepthMode DepthMode, bool bDrawOpaque, bool bDrawTranslucent );
  78. void R_DrawBrushModelShadow( IClientRenderable* pRender );
  79. void R_BrushBatchInit( void );
  80. int R_GetBrushModelPlaneCount( const model_t *model );
  81. const cplane_t &R_GetBrushModelPlane( const model_t *model, int nIndex, Vector *pOrigin );
  82. bool TangentSpaceSurfaceSetup( SurfaceHandle_t surfID, Vector &tVect );
  83. void TangentSpaceComputeBasis( Vector& tangentS, Vector& tangentT, const Vector& normal, const Vector& tVect, bool negateTangent );
  84. #ifndef NEWMESH
  85. inline void BuildIndicesForSurface( CMeshBuilder &meshBuilder, SurfaceHandle_t surfID )
  86. {
  87. int nSurfTriangleCount = MSurf_VertCount( surfID ) - 2;
  88. unsigned short startVert = MSurf_VertBufferIndex( surfID );
  89. Assert(startVert!=0xFFFF);
  90. // NOTE: This switch appears to help performance
  91. // add surface to this batch
  92. switch (nSurfTriangleCount)
  93. {
  94. case 1:
  95. meshBuilder.FastIndex( startVert );
  96. meshBuilder.FastIndex( startVert + 1 );
  97. meshBuilder.FastIndex( startVert + 2 );
  98. break;
  99. case 2:
  100. meshBuilder.FastIndex( startVert );
  101. meshBuilder.FastIndex( startVert + 1 );
  102. meshBuilder.FastIndex( startVert + 2 );
  103. meshBuilder.FastIndex( startVert );
  104. meshBuilder.FastIndex( startVert + 2 );
  105. meshBuilder.FastIndex( startVert + 3 );
  106. break;
  107. default:
  108. {
  109. for ( unsigned short v = 0; v < nSurfTriangleCount; ++v )
  110. {
  111. meshBuilder.FastIndex( startVert );
  112. meshBuilder.FastIndex( startVert + v + 1 );
  113. meshBuilder.FastIndex( startVert + v + 2 );
  114. }
  115. }
  116. break;
  117. }
  118. }
  119. inline void BuildIndicesForWorldSurface( CMeshBuilder &meshBuilder, SurfaceHandle_t surfID, worldbrushdata_t *pData )
  120. {
  121. if ( SurfaceHasPrims(surfID) )
  122. {
  123. mprimitive_t *pPrim = &pData->primitives[MSurf_FirstPrimID( surfID, pData )];
  124. Assert(pPrim->vertCount==0);
  125. unsigned short startVert = MSurf_VertBufferIndex( surfID );
  126. Assert( pPrim->indexCount == ((MSurf_VertCount( surfID ) - 2)*3));
  127. for ( int primIndex = 0; primIndex < pPrim->indexCount; primIndex++ )
  128. {
  129. meshBuilder.FastIndex( pData->primindices[pPrim->firstIndex + primIndex] + startVert );
  130. }
  131. }
  132. else
  133. {
  134. BuildIndicesForSurface( meshBuilder, surfID );
  135. }
  136. }
  137. #else
  138. inline void BuildIndicesForSurface( CIndexBufferBuilder &indexBufferBuilder, SurfaceHandle_t surfID )
  139. {
  140. int nSurfTriangleCount = MSurf_VertCount( surfID ) - 2;
  141. unsigned short startVert = MSurf_VertBufferIndex( surfID );
  142. Assert(startVert!=0xFFFF);
  143. // NOTE: This switch appears to help performance
  144. // add surface to this batch
  145. switch (nSurfTriangleCount)
  146. {
  147. case 1:
  148. indexBufferBuilder.FastIndex( startVert );
  149. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert ) );
  150. indexBufferBuilder.FastIndex( startVert + 1 );
  151. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert + 1 ) );
  152. indexBufferBuilder.FastIndex( startVert + 2 );
  153. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert + 2 ) );
  154. break;
  155. case 2:
  156. indexBufferBuilder.FastIndex( startVert );
  157. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert ) );
  158. indexBufferBuilder.FastIndex( startVert + 1 );
  159. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert + 1 ) );
  160. indexBufferBuilder.FastIndex( startVert + 2 );
  161. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert + 2 ) );
  162. indexBufferBuilder.FastIndex( startVert );
  163. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert ) );
  164. indexBufferBuilder.FastIndex( startVert + 2 );
  165. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert + 2 ) );
  166. indexBufferBuilder.FastIndex( startVert + 3 );
  167. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert + 3 ) );
  168. break;
  169. default:
  170. {
  171. for ( unsigned short v = 0; v < nSurfTriangleCount; ++v )
  172. {
  173. indexBufferBuilder.FastIndex( startVert );
  174. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert ) );
  175. indexBufferBuilder.FastIndex( startVert + v + 1 );
  176. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert + v + 1 ) );
  177. indexBufferBuilder.FastIndex( startVert + v + 2 );
  178. Warning( "BuildIndicesForSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( startVert + v + 2 ) );
  179. }
  180. }
  181. break;
  182. }
  183. }
  184. inline void BuildIndicesForWorldSurface( CIndexBufferBuilder &indexBufferBuilder, SurfaceHandle_t surfID, worldbrushdata_t *pData )
  185. {
  186. if ( SurfaceHasPrims(surfID) )
  187. {
  188. mprimitive_t *pPrim = &pData->primitives[MSurf_FirstPrimID( surfID, pData )];
  189. Assert(pPrim->vertCount==0);
  190. unsigned short startVert = MSurf_VertBufferIndex( surfID );
  191. Assert( pPrim->indexCount == ((MSurf_VertCount( surfID ) - 2)*3));
  192. for ( int primIndex = 0; primIndex < pPrim->indexCount; primIndex++ )
  193. {
  194. indexBufferBuilder.FastIndex( pData->primindices[pPrim->firstIndex + primIndex] + startVert );
  195. Warning( "BuildIndicesForWorldSurface: indexBufferBuilder.FastIndex( %d )\n", ( int )( pData->primindices[pPrim->firstIndex + primIndex] + startVert ) );
  196. }
  197. }
  198. else
  199. {
  200. BuildIndicesForSurface( indexBufferBuilder, surfID );
  201. }
  202. }
  203. #endif
  204. #endif // GL_RSURF_H