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.

675 lines
21 KiB

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