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.

795 lines
25 KiB

  1. //========== Copyright (c) 2005, Valve Corporation, All rights reserved. ========
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================
  6. #include "cbase.h"
  7. #include "tier0/vprof.h"
  8. #include "view_scene.h"
  9. #include "viewrender.h"
  10. #include "viewdebug.h"
  11. #include "view.h"
  12. #include "smoke_fog_overlay.h"
  13. #include "materialsystem/imaterialvar.h"
  14. #include "foundryhelpers_client.h"
  15. #include "c_env_cascade_light.h"
  16. #include "materialsystem/icustommaterialmanager.h"
  17. #ifdef PORTAL
  18. //#include "C_Portal_Player.h"
  19. #include "portal_render_targets.h"
  20. #include "portalrender.h"
  21. #endif
  22. // NOTE: This has to be the last file included!
  23. #include "tier0/memdbgon.h"
  24. //-----------------------------------------------------------------------------
  25. // debugging overlays
  26. //-----------------------------------------------------------------------------
  27. static ConVar cl_drawmaterial( "cl_drawmaterial", "", FCVAR_CHEAT, "Draw a particular material over the frame" );
  28. static ConVar mat_showwatertextures( "mat_showwatertextures", "0", FCVAR_CHEAT );
  29. static ConVar mat_wateroverlaysize( "mat_wateroverlaysize", "128" );
  30. static ConVar mat_showframebuffertexture( "mat_showframebuffertexture", "0", FCVAR_CHEAT );
  31. static ConVar mat_framebuffercopyoverlaysize( "mat_framebuffercopyoverlaysize", "128" );
  32. static ConVar mat_showcamerarendertarget( "mat_showcamerarendertarget", "0", FCVAR_CHEAT );
  33. static ConVar mat_camerarendertargetoverlaysize( "mat_camerarendertargetoverlaysize", "128", FCVAR_CHEAT );
  34. static ConVar mat_hsv( "mat_hsv", "0", FCVAR_CHEAT );
  35. static ConVar mat_yuv( "mat_yuv", "0", FCVAR_CHEAT );
  36. static ConVar cl_overdraw_test( "cl_overdraw_test", "0", FCVAR_CHEAT | FCVAR_NEVER_AS_STRING );
  37. static ConVar mat_drawTexture( "mat_drawTexture", "", 0, "Enable debug view texture" );
  38. static ConVar mat_drawTextureScale( "mat_drawTextureScale", "1.0", 0, "Debug view texture scale" );
  39. #ifdef _GAMECONSOLE
  40. static ConVar mat_drawColorRamp( "mat_drawColorRamp", "0", 0, "Draw color test pattern (0=Off, 1=[0..255], 2=[0..127]" );
  41. #endif
  42. //-----------------------------------------------------------------------------
  43. // debugging
  44. //-----------------------------------------------------------------------------
  45. // (the engine owns this cvar).
  46. ConVar mat_wireframe( "mat_wireframe", "0", FCVAR_CHEAT );
  47. const ConVar *sv_cheats = NULL;
  48. ConVar mat_showlightmappage( "mat_showlightmappage", "-1" ); // set this to the lightmap page that you want to see on screen, set to -1 to show nothing.
  49. ConVar cl_drawshadowtexture( "cl_drawshadowtexture", "0", FCVAR_CHEAT );
  50. extern ConVar cl_csm_debug_2d;
  51. extern ConVar cl_csm_debug_3d;
  52. ConVar cl_shadowtextureoverlaysize( "cl_shadowtextureoverlaysize", "256", FCVAR_CHEAT );
  53. static ConVar r_flashlightdrawdepth( "r_flashlightdrawdepth", "0" );
  54. static ConVar cl_custommaterial_debug_graph( "cl_custommaterial_debug_graph", "0", FCVAR_CHEAT );
  55. //-----------------------------------------------------------------------------
  56. // Lightmap debugging mode view
  57. //-----------------------------------------------------------------------------
  58. class CLightmapDebugView : public CRendering3dView
  59. {
  60. public:
  61. explicit CLightmapDebugView(CViewRender *pMainView) : CRendering3dView( pMainView ) {}
  62. void Draw()
  63. {
  64. extern bool s_bCanAccessCurrentView;
  65. AllowCurrentViewAccess( true );
  66. Frustum frustum;
  67. CMatRenderContextPtr pRenderContext( materials );
  68. render->Push3DView( pRenderContext, *this, 0, NULL, frustum );
  69. BuildWorldRenderLists( true, -1, true, true );
  70. render->PopView( pRenderContext, frustum );
  71. AllowCurrentViewAccess( false );
  72. render->DrawLightmaps( m_pWorldRenderList, mat_showlightmappage.GetInt() );
  73. }
  74. };
  75. //-----------------------------------------------------------------------------
  76. // Renders a material orthographically to screen...
  77. //-----------------------------------------------------------------------------
  78. static void RenderMaterial( const char *pMaterialName )
  79. {
  80. // So it's not in the very top left
  81. float x = 100.0f, y = 100.0f;
  82. // float x = 0.0f, y = 0.0f;
  83. IMaterial *pMaterial = materials->FindMaterial( pMaterialName, TEXTURE_GROUP_OTHER, false );
  84. if ( !IsErrorMaterial( pMaterial ) )
  85. {
  86. CMatRenderContextPtr pRenderContext( materials );
  87. pRenderContext->Bind( pMaterial );
  88. IMesh* pMesh = pRenderContext->GetDynamicMesh( true );
  89. CMeshBuilder meshBuilder;
  90. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  91. meshBuilder.Position3f( x, y, 0.0f );
  92. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  93. meshBuilder.Color4ub( 255, 255, 255, 255 );
  94. meshBuilder.AdvanceVertex();
  95. meshBuilder.Position3f( x + pMaterial->GetMappingWidth(), y, 0.0f );
  96. meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
  97. meshBuilder.Color4ub( 255, 255, 255, 255 );
  98. meshBuilder.AdvanceVertex();
  99. meshBuilder.Position3f( x + pMaterial->GetMappingWidth(), y + pMaterial->GetMappingHeight(), 0.0f );
  100. meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
  101. meshBuilder.Color4ub( 255, 255, 255, 255 );
  102. meshBuilder.AdvanceVertex();
  103. meshBuilder.Position3f( x, y + pMaterial->GetMappingHeight(), 0.0f );
  104. meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
  105. meshBuilder.Color4ub( 255, 255, 255, 255 );
  106. meshBuilder.AdvanceVertex();
  107. meshBuilder.End();
  108. pMesh->Draw();
  109. }
  110. }
  111. static void OverlayWaterTexture( IMaterial *pMaterial, int xOffset, int yOffset, bool bFlip )
  112. {
  113. // screen safe
  114. float xBaseOffset = IsPC() ? 0 : 32;
  115. float yBaseOffset = IsPC() ? 0 : 32;
  116. float offsetS = ( 0.5f / 256.0f );
  117. float offsetT = ( 0.5f / 256.0f );
  118. float fFlip0 = bFlip ? 1.0f : 0.0f;
  119. float fFlip1 = bFlip ? 0.0f : 1.0f;
  120. if( !IsErrorMaterial( pMaterial ) )
  121. {
  122. CMatRenderContextPtr pRenderContext( materials );
  123. pRenderContext->Bind( pMaterial );
  124. IMesh* pMesh = pRenderContext->GetDynamicMesh( true );
  125. float w = mat_wateroverlaysize.GetFloat();
  126. float h = mat_wateroverlaysize.GetFloat();
  127. CMeshBuilder meshBuilder;
  128. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  129. meshBuilder.Position3f( xBaseOffset + xOffset * w, yBaseOffset + yOffset * h, 0.0f );
  130. meshBuilder.TexCoord2f( 0, 0.0f + offsetS, fFlip1 + offsetT );
  131. meshBuilder.AdvanceVertex();
  132. meshBuilder.Position3f( xBaseOffset + ( xOffset + 1 ) * w, yBaseOffset + yOffset * h, 0.0f );
  133. meshBuilder.TexCoord2f( 0, 1.0f + offsetS, fFlip1 + offsetT );
  134. meshBuilder.AdvanceVertex();
  135. meshBuilder.Position3f( xBaseOffset + ( xOffset + 1 ) * w, yBaseOffset + ( yOffset + 1 ) * h, 0.0f );
  136. meshBuilder.TexCoord2f( 0, 1.0f + offsetS, fFlip0 + offsetT );
  137. meshBuilder.AdvanceVertex();
  138. meshBuilder.Position3f( xBaseOffset + xOffset * w, yBaseOffset + ( yOffset + 1 ) * h, 0.0f );
  139. meshBuilder.TexCoord2f( 0, 0.0f + offsetS, fFlip0 + offsetT );
  140. meshBuilder.AdvanceVertex();
  141. meshBuilder.End();
  142. pMesh->Draw();
  143. }
  144. }
  145. static void OverlayWaterTextures( void )
  146. {
  147. OverlayWaterTexture( materials->FindMaterial( "debug/debugreflect", NULL ), 0, 0, false );
  148. OverlayWaterTexture( materials->FindMaterial( "debug/debugrefract", NULL ), 0, 1, true );
  149. }
  150. void OverlayCameraRenderTarget( const char *pszMaterialName, float flX, float flY, float w, float h )
  151. {
  152. float offsetS = ( 0.5f / 256.0f );
  153. float offsetT = ( 0.5f / 256.0f );
  154. IMaterial *pMaterial;
  155. pMaterial = materials->FindMaterial( pszMaterialName, TEXTURE_GROUP_OTHER, true );
  156. if( !IsErrorMaterial( pMaterial ) )
  157. {
  158. CMatRenderContextPtr pRenderContext( materials );
  159. pRenderContext->Bind( pMaterial );
  160. IMesh* pMesh = pRenderContext->GetDynamicMesh( true );
  161. CMeshBuilder meshBuilder;
  162. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  163. meshBuilder.Position3f( flX, flY, 0.0f );
  164. meshBuilder.TexCoord2f( 0, 0.0f + offsetS, 0.0f + offsetT );
  165. meshBuilder.AdvanceVertex();
  166. meshBuilder.Position3f( flX+w, flY, 0.0f );
  167. meshBuilder.TexCoord2f( 0, 1.0f + offsetS, 0.0f + offsetT );
  168. meshBuilder.AdvanceVertex();
  169. meshBuilder.Position3f( flX+w, flY+h, 0.0f );
  170. meshBuilder.TexCoord2f( 0, 1.0f + offsetS, 1.0f + offsetT );
  171. meshBuilder.AdvanceVertex();
  172. meshBuilder.Position3f( flX, flY+h, 0.0f );
  173. meshBuilder.TexCoord2f( 0, 0.0f + offsetS, 1.0f + offsetT );
  174. meshBuilder.AdvanceVertex();
  175. meshBuilder.End();
  176. pMesh->Draw();
  177. }
  178. }
  179. static void OverlayFrameBufferTexture( int nFrameBufferIndex )
  180. {
  181. float offsetS = ( 0.5f / 256.0f );
  182. float offsetT = ( 0.5f / 256.0f );
  183. IMaterial *pMaterial;
  184. char buf[MAX_PATH];
  185. Q_snprintf( buf, MAX_PATH, "debug/debugfbtexture%d", nFrameBufferIndex );
  186. pMaterial = materials->FindMaterial( buf, TEXTURE_GROUP_OTHER, true );
  187. if( !IsErrorMaterial( pMaterial ) )
  188. {
  189. CMatRenderContextPtr pRenderContext( materials );
  190. pRenderContext->Bind( pMaterial );
  191. IMesh* pMesh = pRenderContext->GetDynamicMesh( true );
  192. float w = mat_framebuffercopyoverlaysize.GetFloat();
  193. float h = mat_framebuffercopyoverlaysize.GetFloat();
  194. CMeshBuilder meshBuilder;
  195. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  196. meshBuilder.Position3f( w * nFrameBufferIndex, 0.0f, 0.0f );
  197. meshBuilder.TexCoord2f( 0, 0.0f + offsetS, 0.0f + offsetT );
  198. meshBuilder.AdvanceVertex();
  199. meshBuilder.Position3f( w * ( nFrameBufferIndex + 1 ), 0.0f, 0.0f );
  200. meshBuilder.TexCoord2f( 0, 1.0f + offsetS, 0.0f + offsetT );
  201. meshBuilder.AdvanceVertex();
  202. meshBuilder.Position3f( w * ( nFrameBufferIndex + 1 ), h, 0.0f );
  203. meshBuilder.TexCoord2f( 0, 1.0f + offsetS, 1.0f + offsetT );
  204. meshBuilder.AdvanceVertex();
  205. meshBuilder.Position3f( w * nFrameBufferIndex, h, 0.0f );
  206. meshBuilder.TexCoord2f( 0, 0.0f + offsetS, 1.0f + offsetT );
  207. meshBuilder.AdvanceVertex();
  208. meshBuilder.End();
  209. pMesh->Draw();
  210. }
  211. }
  212. //-----------------------------------------------------------------------------
  213. // Debugging aid to display a texture
  214. //-----------------------------------------------------------------------------
  215. static void OverlayShowTexture( const char* textureName, float scale )
  216. {
  217. bool foundVar;
  218. IMaterial *pMaterial;
  219. IMaterialVar *BaseTextureVar;
  220. ITexture *pTex;
  221. float x, y, w, h;
  222. // ___error is created in code in CMaterialSystem::CreateDebugMaterials()
  223. pMaterial = materials->FindMaterial( "___error", TEXTURE_GROUP_OTHER, true );
  224. BaseTextureVar = pMaterial->FindVar( "$basetexture", &foundVar, false );
  225. if (!foundVar)
  226. return;
  227. CMatRenderContextPtr pRenderContext( materials );
  228. if ( textureName && textureName[0] )
  229. {
  230. pTex = materials->FindTexture( textureName, TEXTURE_GROUP_OTHER, false );
  231. BaseTextureVar->SetTextureValue( pTex );
  232. w = pTex->GetActualWidth() * scale;
  233. h = pTex->GetActualHeight() * scale;
  234. }
  235. else
  236. {
  237. w = h = 64.0f * scale;
  238. }
  239. // Center relative to current viewport
  240. int nViewportX, nViewportY, nViewportWidth, nViewportHeight;
  241. pRenderContext->GetViewport( nViewportX, nViewportY, nViewportWidth, nViewportHeight );
  242. x = ( nViewportWidth - w ) * 0.5f;
  243. y = ( nViewportHeight - h ) * 0.5f;
  244. pRenderContext->Bind( pMaterial );
  245. IMesh* pMesh = pRenderContext->GetDynamicMesh( true );
  246. CMeshBuilder meshBuilder;
  247. meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );
  248. meshBuilder.Position3f( x, y, 0.0f );
  249. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  250. meshBuilder.AdvanceVertex();
  251. meshBuilder.Position3f( x+w, y, 0.0f );
  252. meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
  253. meshBuilder.AdvanceVertex();
  254. meshBuilder.Position3f( x+w, y+h, 0.0f );
  255. meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
  256. meshBuilder.AdvanceVertex();
  257. meshBuilder.Position3f( x, y+h, 0.0f );
  258. meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
  259. meshBuilder.AdvanceVertex();
  260. meshBuilder.End();
  261. pMesh->Draw();
  262. }
  263. #define DEBUG_CUSTOM_MATERIAL_COUNT_HISTORY 60
  264. int m_iDebugCustomMaterialCountHistory[60] = {0};
  265. float m_flDebugNextCustomMaterialCheckTime = 0.0f;
  266. static void DebugOverlayNumActiveCustomMaterialsGraph()
  267. {
  268. int iNumMaterials = g_pMaterialSystem->GetCustomMaterialManager()->DebugGetNumActiveCustomMaterials();
  269. IMaterial *pMaterial;
  270. float x, y;
  271. pMaterial = materials->FindMaterial( "vgui/white", TEXTURE_GROUP_OTHER, true );
  272. int backBufferWidth, backBufferHeight;
  273. materials->GetBackBufferDimensions( backBufferWidth, backBufferHeight );
  274. x = 64;
  275. y = (backBufferHeight / 5) * 3;
  276. CMatRenderContextPtr pRenderContext( materials );
  277. pRenderContext->Bind( pMaterial );
  278. IMesh* pMesh = pRenderContext->GetDynamicMesh( true );
  279. CMeshBuilder meshBuilder;
  280. int temp_x = x + ( 4*DEBUG_CUSTOM_MATERIAL_COUNT_HISTORY );
  281. int temp_y = (backBufferHeight / 5);
  282. int iNumPrims = DEBUG_CUSTOM_MATERIAL_COUNT_HISTORY-1;
  283. //draw graph axis
  284. meshBuilder.Begin( pMesh, MATERIAL_LINES, iNumPrims + 2 );
  285. meshBuilder.Position3f( x, y, 0.0f );
  286. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  287. meshBuilder.Color3ub( 0, 0, 0 );
  288. meshBuilder.AdvanceVertex();
  289. meshBuilder.Position3f( temp_x, y, 0.0f );
  290. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  291. meshBuilder.Color3ub( 0, 0, 0 );
  292. meshBuilder.AdvanceVertex();
  293. meshBuilder.Position3f( temp_x, y, 0.0f );
  294. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  295. meshBuilder.Color3ub( 0, 0, 0 );
  296. meshBuilder.AdvanceVertex();
  297. meshBuilder.Position3f( temp_x, temp_y, 0.0f );
  298. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  299. meshBuilder.Color3ub( 0, 0, 0 );
  300. meshBuilder.AdvanceVertex();
  301. //draw graph segments in same batch
  302. for ( int i=0; i<iNumPrims; i++ )
  303. {
  304. temp_x = 4 + x + (i * 4);
  305. temp_y = y - (m_iDebugCustomMaterialCountHistory[i] / 2);
  306. meshBuilder.Position3f( temp_x, temp_y, 0.0f );
  307. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  308. meshBuilder.Color3ub( 255, 255, 255 );
  309. meshBuilder.AdvanceVertex();
  310. temp_y = y - (m_iDebugCustomMaterialCountHistory[i+1] / 2);
  311. meshBuilder.Position3f( temp_x+4, temp_y, 0.0f );
  312. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  313. meshBuilder.Color3ub( 255, 255, 255 );
  314. meshBuilder.AdvanceVertex();
  315. }
  316. meshBuilder.End();
  317. pMesh->Draw();
  318. //update graph once per second
  319. if ( gpGlobals->curtime > m_flDebugNextCustomMaterialCheckTime || gpGlobals->curtime + 1.0f < m_flDebugNextCustomMaterialCheckTime )
  320. {
  321. m_flDebugNextCustomMaterialCheckTime = gpGlobals->curtime + 1.0f;
  322. for ( int i=0; i<iNumPrims; i++ )
  323. m_iDebugCustomMaterialCountHistory[i] = m_iDebugCustomMaterialCountHistory[i+1];
  324. m_iDebugCustomMaterialCountHistory[iNumPrims] = iNumMaterials;
  325. //draw the actual number of active materials at the head of the graph as text
  326. float fl_x = (float)(temp_x+10) / (float)(backBufferWidth);
  327. float fl_y = (float)(temp_y-10) / (float)(backBufferHeight);
  328. char szNumMaterials[32];
  329. V_snprintf( szNumMaterials, sizeof(szNumMaterials), "%i Active", iNumMaterials );
  330. NDebugOverlay::ScreenText( fl_x, fl_y, szNumMaterials, 255, 255, 255, 255, 1.0f );
  331. }
  332. }
  333. //-----------------------------------------------------------------------------
  334. // Debugging aid to display a color ramp
  335. //-----------------------------------------------------------------------------
  336. #if defined( _GAMECONSOLE )
  337. static void OverlayColorRamp( bool bHalfSpace )
  338. {
  339. IMaterial *pMaterial;
  340. float x, y, w, h;
  341. pMaterial = materials->FindMaterial( "vgui/white", TEXTURE_GROUP_OTHER, true );
  342. int backBufferWidth, backBufferHeight;
  343. materials->GetBackBufferDimensions( backBufferWidth, backBufferHeight );
  344. w = ( backBufferWidth == 1280 ) ? 1024 : 512;
  345. h = 80;
  346. x = ( backBufferWidth - w )/2;
  347. y = ( backBufferHeight - 4*h )/2;
  348. int numBands = 32;
  349. int color0 = 0;
  350. int color1 = bHalfSpace ? 127 : 255;
  351. int colorStep = (color1 - color0 + 1)/numBands;
  352. CMatRenderContextPtr pRenderContext( materials );
  353. pRenderContext->Bind( pMaterial );
  354. IMesh* pMesh = pRenderContext->GetDynamicMesh( true );
  355. CMeshBuilder meshBuilder;
  356. // draw ticks
  357. int xx = x;
  358. meshBuilder.Begin( pMesh, MATERIAL_LINES, numBands+1 );
  359. for ( int i=0; i<numBands+1; i++ )
  360. {
  361. meshBuilder.Position3f( xx, y-10, 0.0f );
  362. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  363. meshBuilder.Color3ub( 255, 255, 0 );
  364. meshBuilder.AdvanceVertex();
  365. meshBuilder.Position3f( xx, y, 0.0f );
  366. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  367. meshBuilder.Color3ub( 255, 255, 0 );
  368. meshBuilder.AdvanceVertex();
  369. xx += w/numBands;
  370. }
  371. meshBuilder.End();
  372. pMesh->Draw();
  373. // black to white band
  374. xx = x;
  375. int color = color0;
  376. meshBuilder.Begin( pMesh, MATERIAL_QUADS, numBands );
  377. for ( int i=0; i<numBands+1; i++ )
  378. {
  379. meshBuilder.Position3f( xx, y, 0.0f );
  380. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  381. meshBuilder.Color3ub( color, color, color );
  382. meshBuilder.AdvanceVertex();
  383. meshBuilder.Position3f( xx+w/numBands, y, 0.0f );
  384. meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
  385. meshBuilder.Color3ub( color, color, color );
  386. meshBuilder.AdvanceVertex();
  387. meshBuilder.Position3f( xx+w/numBands, y+h, 0.0f );
  388. meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
  389. meshBuilder.Color3ub( color, color, color );
  390. meshBuilder.AdvanceVertex();
  391. meshBuilder.Position3f( xx, y+h, 0.0f );
  392. meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
  393. meshBuilder.Color3ub( color, color, color );
  394. meshBuilder.AdvanceVertex();
  395. color += colorStep;
  396. if ( color > 255 )
  397. color = 255;
  398. xx += w/numBands;
  399. }
  400. meshBuilder.End();
  401. pMesh->Draw();
  402. // white to black band
  403. color = color1;
  404. y += h;
  405. xx = x;
  406. meshBuilder.Begin( pMesh, MATERIAL_QUADS, numBands );
  407. for ( int i=0; i<numBands+1; i++ )
  408. {
  409. meshBuilder.Position3f( xx, y, 0.0f );
  410. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  411. meshBuilder.Color3ub( color, color, color );
  412. meshBuilder.AdvanceVertex();
  413. meshBuilder.Position3f( xx+w/numBands, y, 0.0f );
  414. meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
  415. meshBuilder.Color3ub( color, color, color );
  416. meshBuilder.AdvanceVertex();
  417. meshBuilder.Position3f( xx+w/numBands, y+h, 0.0f );
  418. meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
  419. meshBuilder.Color3ub( color, color, color );
  420. meshBuilder.AdvanceVertex();
  421. meshBuilder.Position3f( xx, y+h, 0.0f );
  422. meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
  423. meshBuilder.Color3ub( color, color, color );
  424. meshBuilder.AdvanceVertex();
  425. color -= colorStep;
  426. if ( color < 0 )
  427. color = 0;
  428. xx += w/numBands;
  429. }
  430. meshBuilder.End();
  431. pMesh->Draw();
  432. // red band
  433. color = color1;
  434. y += h;
  435. xx = x;
  436. meshBuilder.Begin( pMesh, MATERIAL_QUADS, numBands );
  437. for ( int i=0; i<numBands+1; i++ )
  438. {
  439. meshBuilder.Position3f( xx, y, 0.0f );
  440. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  441. meshBuilder.Color3ub( color, 0, 0 );
  442. meshBuilder.AdvanceVertex();
  443. meshBuilder.Position3f( xx+w/numBands, y, 0.0f );
  444. meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
  445. meshBuilder.Color3ub( color, 0, 0 );
  446. meshBuilder.AdvanceVertex();
  447. meshBuilder.Position3f( xx+w/numBands, y+h, 0.0f );
  448. meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
  449. meshBuilder.Color3ub( color, 0, 0 );
  450. meshBuilder.AdvanceVertex();
  451. meshBuilder.Position3f( xx, y+h, 0.0f );
  452. meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
  453. meshBuilder.Color3ub( color, 0, 0 );
  454. meshBuilder.AdvanceVertex();
  455. color -= colorStep;
  456. if ( color < 0 )
  457. color = 0;
  458. xx += w/numBands;
  459. }
  460. meshBuilder.End();
  461. pMesh->Draw();
  462. // green band
  463. color = color1;
  464. y += h;
  465. xx = x;
  466. meshBuilder.Begin( pMesh, MATERIAL_QUADS, numBands );
  467. for ( int i=0; i<numBands+1; i++ )
  468. {
  469. meshBuilder.Position3f( xx, y, 0.0f );
  470. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  471. meshBuilder.Color3ub( 0, color, 0 );
  472. meshBuilder.AdvanceVertex();
  473. meshBuilder.Position3f( xx+w/numBands, y, 0.0f );
  474. meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
  475. meshBuilder.Color3ub( 0, color, 0 );
  476. meshBuilder.AdvanceVertex();
  477. meshBuilder.Position3f( xx+w/numBands, y+h, 0.0f );
  478. meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
  479. meshBuilder.Color3ub( 0, color, 0 );
  480. meshBuilder.AdvanceVertex();
  481. meshBuilder.Position3f( xx, y+h, 0.0f );
  482. meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
  483. meshBuilder.Color3ub( 0, color, 0 );
  484. meshBuilder.AdvanceVertex();
  485. color -= colorStep;
  486. if ( color < 0 )
  487. color = 0;
  488. xx += w/numBands;
  489. }
  490. meshBuilder.End();
  491. pMesh->Draw();
  492. // blue band
  493. color = color1;
  494. y += h;
  495. xx = x;
  496. meshBuilder.Begin( pMesh, MATERIAL_QUADS, numBands );
  497. for ( int i=0; i<numBands+1; i++ )
  498. {
  499. meshBuilder.Position3f( xx, y, 0.0f );
  500. meshBuilder.TexCoord2f( 0, 0.0f, 0.0f );
  501. meshBuilder.Color3ub( 0, 0, color );
  502. meshBuilder.AdvanceVertex();
  503. meshBuilder.Position3f( xx+w/numBands, y, 0.0f );
  504. meshBuilder.TexCoord2f( 0, 1.0f, 0.0f );
  505. meshBuilder.Color3ub( 0, 0, color );
  506. meshBuilder.AdvanceVertex();
  507. meshBuilder.Position3f( xx+w/numBands, y+h, 0.0f );
  508. meshBuilder.TexCoord2f( 0, 1.0f, 1.0f );
  509. meshBuilder.Color3ub( 0, 0, color );
  510. meshBuilder.AdvanceVertex();
  511. meshBuilder.Position3f( xx, y+h, 0.0f );
  512. meshBuilder.TexCoord2f( 0, 0.0f, 1.0f );
  513. meshBuilder.Color3ub( 0, 0, color );
  514. meshBuilder.AdvanceVertex();
  515. color -= colorStep;
  516. if ( color < 0 )
  517. color = 0;
  518. xx += w/numBands;
  519. }
  520. meshBuilder.End();
  521. pMesh->Draw();
  522. }
  523. #endif
  524. #if defined( PORTAL )
  525. ConVar cl_debugoverlaysthroughportals( "cl_debugoverlaysthroughportals", "0" );
  526. #endif
  527. //-----------------------------------------------------------------------------
  528. // Draws all the debugging info
  529. //-----------------------------------------------------------------------------
  530. void CDebugViewRender::Draw3DDebuggingInfo( const CViewSetup &view )
  531. {
  532. VPROF("CViewRender::Draw3DDebuggingInfo");
  533. // Draw anything Foundry wants to.
  534. FoundryHelpers_DrawAll();
  535. if ( cl_csm_debug_3d.GetInt() )
  536. {
  537. g_CascadeLightManager.Draw3DDebugInfo();
  538. }
  539. // Draw 3d overlays
  540. #if defined( PORTAL )
  541. if( (g_pPortalRender->GetViewRecursionLevel() == 0) || cl_debugoverlaysthroughportals.GetBool() )
  542. {
  543. render->Draw3DDebugOverlays();
  544. }
  545. #else
  546. render->Draw3DDebugOverlays();
  547. #endif
  548. // Draw the line file used for debugging leaks
  549. render->DrawLineFile();
  550. }
  551. //-----------------------------------------------------------------------------
  552. // Draws all the debugging info
  553. //-----------------------------------------------------------------------------
  554. void CDebugViewRender::Draw2DDebuggingInfo( const CViewSetup &view )
  555. {
  556. // HDRFIXME: Assert NULL rendertarget
  557. if ( mat_yuv.GetInt() )
  558. {
  559. IMaterial *pMaterial;
  560. pMaterial = materials->FindMaterial( "debug/yuv", TEXTURE_GROUP_OTHER, true );
  561. if( !IsErrorMaterial( pMaterial ) )
  562. {
  563. DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width, view.height );
  564. }
  565. }
  566. if ( mat_hsv.GetInt() )
  567. {
  568. IMaterial *pMaterial;
  569. pMaterial = materials->FindMaterial( "debug/hsv", TEXTURE_GROUP_OTHER, true );
  570. if( !IsErrorMaterial( pMaterial ) )
  571. {
  572. DrawScreenEffectMaterial( pMaterial, view.x, view.y, view.width, view.height );
  573. }
  574. }
  575. // Draw debugging lightmaps
  576. if ( mat_showlightmappage.GetInt() != -1 )
  577. {
  578. CLightmapDebugView clientView( assert_cast<CViewRender *>( ::view ) );
  579. clientView.Setup( view );
  580. clientView.Draw();
  581. }
  582. if ( cl_drawshadowtexture.GetInt() )
  583. {
  584. int nSize = cl_shadowtextureoverlaysize.GetInt();
  585. g_pClientShadowMgr->RenderShadowTexture( nSize, nSize );
  586. }
  587. if ( cl_csm_debug_2d.GetInt() )
  588. {
  589. g_CascadeLightManager.Draw2DDebugInfo();
  590. }
  591. if ( cl_custommaterial_debug_graph.GetInt() )
  592. {
  593. DebugOverlayNumActiveCustomMaterialsGraph();
  594. }
  595. const char *pDrawMaterial = cl_drawmaterial.GetString();
  596. if ( pDrawMaterial && pDrawMaterial[0] )
  597. {
  598. RenderMaterial( pDrawMaterial );
  599. }
  600. if ( mat_showwatertextures.GetBool() )
  601. {
  602. OverlayWaterTextures();
  603. }
  604. if ( mat_showcamerarendertarget.GetBool() )
  605. {
  606. float w = mat_wateroverlaysize.GetFloat();
  607. float h = mat_wateroverlaysize.GetFloat();
  608. #ifdef PORTAL
  609. g_pPortalRender->OverlayPortalRenderTargets( w, h );
  610. #else
  611. OverlayCameraRenderTarget( "debug/debugcamerarendertarget", 0, 0, w, h );
  612. #endif
  613. }
  614. if ( mat_showframebuffertexture.GetBool() )
  615. {
  616. // HDRFIXME: Get rid of these rendertarget sets assuming that the assert at the top of this function is true.
  617. CMatRenderContextPtr pRenderContext( materials );
  618. pRenderContext->PushRenderTargetAndViewport( NULL );
  619. OverlayFrameBufferTexture( 0 );
  620. OverlayFrameBufferTexture( 1 );
  621. pRenderContext->PopRenderTargetAndViewport( );
  622. }
  623. const char *pDrawTexture = mat_drawTexture.GetString();
  624. if ( pDrawTexture && pDrawTexture[0] )
  625. {
  626. OverlayShowTexture( pDrawTexture, mat_drawTextureScale.GetFloat() );
  627. }
  628. #ifdef _GAMECONSOLE
  629. if ( mat_drawColorRamp.GetBool() )
  630. {
  631. OverlayColorRamp( mat_drawColorRamp.GetInt() == 2 );
  632. }
  633. #endif
  634. if ( r_flashlightdrawdepth.GetBool() )
  635. {
  636. shadowmgr->DrawFlashlightDepthTexture( );
  637. }
  638. }
  639. //-----------------------------------------------------------------------------
  640. // A console command allowing you to draw a material as an overlay
  641. //-----------------------------------------------------------------------------
  642. CON_COMMAND_F( r_screenoverlay, "Draw specified material as an overlay", FCVAR_CHEAT|FCVAR_SERVER_CAN_EXECUTE )
  643. {
  644. if( args.ArgC() == 2 )
  645. {
  646. if ( !Q_stricmp( "off", args[1] ) )
  647. {
  648. view->SetScreenOverlayMaterial( NULL );
  649. }
  650. else
  651. {
  652. IMaterial *pMaterial = materials->FindMaterial( args[1], TEXTURE_GROUP_OTHER, false );
  653. if ( !IsErrorMaterial( pMaterial ) )
  654. {
  655. view->SetScreenOverlayMaterial( pMaterial );
  656. }
  657. else
  658. {
  659. view->SetScreenOverlayMaterial( NULL );
  660. }
  661. }
  662. }
  663. else
  664. {
  665. IMaterial *pMaterial;
  666. pMaterial = view->GetScreenOverlayMaterial();
  667. Warning( "r_screenoverlay: %s\n", pMaterial ? pMaterial->GetName() : "off" );
  668. }
  669. }
  670. // Used to verify frame syncing.
  671. void CDebugViewRender::GenerateOverdrawForTesting()
  672. {
  673. if ( IsGameConsole() )
  674. return;
  675. if ( !cl_overdraw_test.GetInt() )
  676. return;
  677. for ( int i=0; i < 40; i++ )
  678. {
  679. g_SmokeFogOverlayAlpha = 20 / 255.0;
  680. g_SmokeFogOverlayColor.Init( 0.33f, 0.33f, 0.33f );
  681. DrawSmokeFogOverlay();
  682. }
  683. g_SmokeFogOverlayAlpha = 0;
  684. }