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.

283 lines
8.9 KiB

  1. //===== Copyright � 1996-2005, 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. class CVolumeCuller;
  27. struct LightmapUpdateInfo_t
  28. {
  29. SurfaceHandle_t m_SurfHandle;
  30. int m_nDlightMask;
  31. short m_nTransformIndex;
  32. bool m_bNeedsLightmap;
  33. bool m_bNeedsBumpmap;
  34. };
  35. struct LightmapTransformInfo_t
  36. {
  37. model_t *pModel;
  38. matrix3x4_t xform;
  39. };
  40. extern CUtlVector<LightmapUpdateInfo_t> g_LightmapUpdateList;
  41. extern CUtlVector<LightmapTransformInfo_t> g_LightmapTransformList;
  42. //-----------------------------------------------------------------------------
  43. // Helper class to iterate over leaves
  44. //-----------------------------------------------------------------------------
  45. class IEngineSpatialQuery : public ISpatialQuery
  46. {
  47. public:
  48. };
  49. extern IEngineSpatialQuery* g_pToolBSPTree;
  50. class IWorldRenderList;
  51. IWorldRenderList *AllocWorldRenderList();
  52. #if defined(_PS3)
  53. IWorldRenderList *AllocWorldRenderList_PS3( int viewID );
  54. #endif
  55. void R_Surface_LevelInit();
  56. void R_Surface_LevelShutdown();
  57. void R_SceneBegin( void );
  58. void R_SceneEnd( void );
  59. void R_BuildWorldLists( IWorldRenderList *pRenderList, WorldListInfo_t* pInfo, int iForceViewLeaf, const struct VisOverrideData_t* pVisData, bool bShadowDepth = false, float *pWaterReflectionHeight = NULL );
  60. void R_DrawWorldLists( IMatRenderContext *pRenderContext, IWorldRenderList *pRenderList, unsigned long flags, float waterZAdjust );
  61. #if defined(_PS3)
  62. void R_BuildWorldLists_PS3_Epilogue( IWorldRenderList *pRenderListIn, WorldListInfo_t* pInfo, bool bShadowDepth );
  63. void R_FrameEndSPURSSync( int flags );
  64. #else
  65. void R_BuildWorldLists_Epilogue( IWorldRenderList *pRenderListIn, WorldListInfo_t* pInfo, bool bShadowDepth );
  66. #endif
  67. void R_GetWorldListIndicesInfo( WorldListIndicesInfo_t * pInfoOut, IWorldRenderList *pRenderList, unsigned long nFlags );
  68. int R_GetNumIndicesForWorldList( IWorldRenderList *pRenderList, unsigned long nFlags );
  69. void R_GetVisibleFogVolume( const Vector& vEyePoint, const VisOverrideData_t *pVisOverrideData, VisibleFogVolumeInfo_t *pInfo );
  70. void R_SetFogVolumeState( int fogVolume, bool useHeightFog );
  71. IMaterial *R_GetFogVolumeMaterial( int fogVolume, bool bEyeInFogVolume );
  72. void R_SetupSkyTexture( model_t *pWorld );
  73. void Shader_DrawLightmapPageChains( IWorldRenderList *pRenderList, int pageId );
  74. void Shader_DrawLightmapPageSurface( SurfaceHandle_t surfID, float red, float green, float blue );
  75. void Shader_DrawTranslucentSurfaces( IMatRenderContext *pRenderContext, IWorldRenderList *pRenderList, int *pSortList, int sortCount, unsigned long flags );
  76. bool Shader_LeafContainsTranslucentSurfaces( IWorldRenderList *pRenderList, int sortIndex, unsigned long flags );
  77. void R_DrawTopView( bool enable );
  78. void R_TopViewNoBackfaceCulling( bool bDisable );
  79. void R_TopViewNoVisCheck( bool bDisable );
  80. void R_TopViewBounds( const Vector2D & mins, const Vector2D & maxs );
  81. void R_SetTopViewVolumeCuller( const CVolumeCuller *pTopViewVolumeCuller );
  82. // Resets a world render list
  83. void ResetWorldRenderList( IWorldRenderList *pRenderList );
  84. // Computes the centroid of a surface
  85. void Surf_ComputeCentroid( SurfaceHandle_t surfID, Vector *pVecCentroid );
  86. // Installs a client-side renderer for brush models
  87. void R_InstallBrushRenderOverride( IBrushRenderer* pBrushRenderer );
  88. // update dlight status on a brush model
  89. extern int R_MarkDlightsOnBrushModel( model_t *model, IClientRenderable *pRenderable );
  90. void R_DrawBrushModel(
  91. IClientEntity *baseentity,
  92. model_t *model,
  93. const Vector& origin,
  94. const QAngle& angles,
  95. ERenderDepthMode_t DepthMode, bool bDrawOpaque, bool bDrawTranslucent );
  96. void R_DrawBrushModel(
  97. IClientEntity *baseentity,
  98. model_t *model,
  99. const matrix3x4a_t& brushModelToWorld,
  100. bool bShadowDepth, bool bDrawOpaque, bool bDrawTranslucent );
  101. // Draws arrays of brush models
  102. void R_DrawBrushModelArray( IMatRenderContext* pRenderContext, int nCount,
  103. const BrushArrayInstanceData_t *pInstanceData, int nModelTypeFlags );
  104. // Draws arrays of brush models( this version is used by queued render contexts)
  105. inline void R_DrawBrushModelArray( int nCount,
  106. const BrushArrayInstanceData_t *pInstanceData, int nModelTypeFlags )
  107. {
  108. CMatRenderContextPtr pRenderContext( g_pMaterialSystem );
  109. R_DrawBrushModelArray( pRenderContext, nCount, pInstanceData, nModelTypeFlags );
  110. }
  111. void R_DrawBrushModelShadow( IClientRenderable* pRender );
  112. void R_BrushBatchInit( void );
  113. int R_GetBrushModelPlaneCount( const model_t *model );
  114. const cplane_t &R_GetBrushModelPlane( const model_t *model, int nIndex, Vector *pOrigin );
  115. bool TangentSpaceSurfaceSetup( SurfaceHandle_t surfID, Vector &tVect );
  116. void TangentSpaceComputeBasis( Vector& tangentS, Vector& tangentT, const Vector& normal, const Vector& tVect, bool negateTangent );
  117. inline int BuildIndicesForSurface( CIndexBuilder &meshBuilder, SurfaceHandle_t surfID )
  118. {
  119. int nSurfTriangleCount = MSurf_VertCount( surfID ) - 2;
  120. int startVert = MSurf_VertBufferIndex( surfID );
  121. Assert(startVert!=0xFFFF);
  122. // NOTE: This switch appears to help performance
  123. // add surface to this batch
  124. switch (nSurfTriangleCount)
  125. {
  126. case 1:
  127. meshBuilder.FastTriangle(startVert);
  128. break;
  129. case 2:
  130. meshBuilder.FastQuad(startVert);
  131. break;
  132. default:
  133. meshBuilder.FastPolygon(startVert, nSurfTriangleCount);
  134. break;
  135. }
  136. return nSurfTriangleCount;
  137. }
  138. inline void BuildIndicesForWorldSurface( CIndexBuilder &meshBuilder, SurfaceHandle_t surfID, worldbrushdata_t *pData )
  139. {
  140. if ( SurfaceHasPrims(surfID) )
  141. {
  142. mprimitive_t *pPrim = &pData->primitives[MSurf_FirstPrimID( surfID, pData )];
  143. Assert(pPrim->vertCount==0);
  144. unsigned short startVert = MSurf_VertBufferIndex( surfID );
  145. Assert( pPrim->indexCount == ((MSurf_VertCount( surfID ) - 2)*3));
  146. CIndexBuilder &indexBuilder = meshBuilder;
  147. indexBuilder.FastIndexList( &pData->primindices[pPrim->firstIndex], startVert, pPrim->indexCount );
  148. }
  149. else
  150. {
  151. BuildIndicesForSurface( meshBuilder, surfID );
  152. }
  153. }
  154. // each surface has an index to the first vertex in the depth fill VB
  155. extern CUtlVector<uint16> g_DepthFillVBFirstVertexForSurface;
  156. inline int BuildDepthFillIndicesForSurface( CIndexBuilder &meshBuilder, SurfaceHandle_t surfID )
  157. {
  158. int nSurfTriangleCount = MSurf_VertCount( surfID ) - 2;
  159. int startVert = g_DepthFillVBFirstVertexForSurface[ MSurf_Index(surfID )];
  160. Assert(startVert!=0xFFFF);
  161. // NOTE: This switch appears to help performance
  162. // add surface to this batch
  163. switch (nSurfTriangleCount)
  164. {
  165. case 1:
  166. meshBuilder.FastTriangle(startVert);
  167. break;
  168. case 2:
  169. meshBuilder.FastQuad(startVert);
  170. break;
  171. default:
  172. meshBuilder.FastPolygon(startVert, nSurfTriangleCount);
  173. break;
  174. }
  175. return nSurfTriangleCount;
  176. }
  177. inline void BuildDepthFillIndicesForWorldSurface( CIndexBuilder &meshBuilder, SurfaceHandle_t surfID, worldbrushdata_t *pData )
  178. {
  179. if ( SurfaceHasPrims(surfID) )
  180. {
  181. mprimitive_t *pPrim = &pData->primitives[MSurf_FirstPrimID( surfID, pData )];
  182. Assert(pPrim->vertCount==0);
  183. unsigned short startVert = g_DepthFillVBFirstVertexForSurface[ MSurf_Index(surfID )];
  184. Assert( pPrim->indexCount == ((MSurf_VertCount( surfID ) - 2)*3));
  185. CIndexBuilder &indexBuilder = meshBuilder;
  186. indexBuilder.FastIndexList( &pData->primindices[pPrim->firstIndex], startVert, pPrim->indexCount );
  187. }
  188. else
  189. {
  190. BuildDepthFillIndicesForSurface( meshBuilder, surfID );
  191. }
  192. }
  193. inline int GetIndexCountForWorldSurface( SurfaceHandle_t surfID )
  194. {
  195. return ( MSurf_VertCount( surfID ) - 2 ) * 3;
  196. }
  197. struct CShaderDebug
  198. {
  199. bool wireframe;
  200. bool normals;
  201. bool luxels;
  202. bool bumpBasis;
  203. bool surfacematerials;
  204. bool anydebug;
  205. int surfaceid;
  206. void TestAnyDebug()
  207. {
  208. anydebug = wireframe || normals || luxels || bumpBasis || ( surfaceid != 0 ) || surfacematerials;
  209. }
  210. };
  211. extern CShaderDebug g_ShaderDebug;
  212. #define BRUSHMODEL_DECAL_SORT_GROUP MAX_MAT_SORT_GROUPS
  213. const int MAX_VERTEX_FORMAT_CHANGES = 128;
  214. #define BACKFACE_EPSILON -0.01f
  215. void Shader_GetSurfVertexAndIndexCount( SurfaceHandle_t surfaceHandle, int *pVertexCount, int *pIndexCount );
  216. // Draw debugging information
  217. void DrawDebugInformation( IMatRenderContext *pRenderContext, SurfaceHandle_t *pList, int listCount );
  218. void DrawDebugInformation( IMatRenderContext *pRenderContext, const matrix3x4a_t &brushToWorld, SurfaceHandle_t *pList, int listCount );
  219. class CBrushModelTransform
  220. {
  221. public:
  222. CBrushModelTransform( const Vector &origin, const QAngle &angles, IMatRenderContext *pRenderContext );
  223. CBrushModelTransform( const matrix3x4a_t &matrix, IMatRenderContext *pRenderContext );
  224. ~CBrushModelTransform();
  225. VMatrix *GetNonIdentityMatrix();
  226. inline bool IsIdentity() { return m_bIdentity; }
  227. Vector m_savedModelorg;
  228. bool m_bIdentity;
  229. };
  230. #endif // GL_RSURF_H