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.

332 lines
8.5 KiB

  1. //===== Copyright � 1996-2005, Valve Corporation, All rights reserved. ======//
  2. //
  3. // Purpose:
  4. //
  5. // $Workfile: $
  6. // $Date: $
  7. // $NoKeywords: $
  8. //===========================================================================//
  9. // HDRFIXME: reduce the number of include files here.
  10. #include "render_pch.h"
  11. #include "cdll_int.h"
  12. #include "client_class.h"
  13. #include "icliententitylist.h"
  14. #include "traceinit.h"
  15. #include "server.h"
  16. #include "r_decal.h"
  17. #include "r_areaportal.h"
  18. #include "ispatialpartitioninternal.h"
  19. #include "cdll_engine_int.h"
  20. #include "ivtex.h"
  21. #include "materialsystem/itexture.h"
  22. #include "view.h"
  23. #include "tier0/dbg.h"
  24. #include "staticpropmgr.h"
  25. #include "icliententity.h"
  26. #include "gl_drawlights.h"
  27. #include "Overlay.h"
  28. #include "vmodes.h"
  29. #include "tier1/utlbuffer.h"
  30. #include "vtf/vtf.h"
  31. #include "bitmap/imageformat.h"
  32. #include "cbenchmark.h"
  33. #include "ivideomode.h"
  34. #include "materialsystem/imaterialsystemhardwareconfig.h"
  35. #include "../utils/common/bsplib.h"
  36. #include "ibsppack.h"
  37. #include "vprof.h"
  38. #include "paint.h"
  39. #if defined(_PS3)
  40. #include "buildindices_PS3.h"
  41. #include "buildworldlists_PS3.h"
  42. #endif
  43. // memdbgon must be the last include file in a .cpp file!!!
  44. #include "tier0/memdbgon.h"
  45. bool g_RendererInLevel = false;
  46. void Linefile_Read_f(void);
  47. /*
  48. ====================
  49. // if( r_drawtranslucentworld )
  50. // {
  51. // bSaveDrawTranslucentWorld = r_drawtranslucentworld->GetBool();
  52. // NOTE! : We use to set this to 0 for HDR.
  53. // r_drawtranslucentworld->SetValue( 0 );
  54. // }
  55. // if( r_drawtranslucentrenderables )
  56. R_TimeRefresh_f
  57. For program optimization
  58. ====================
  59. */
  60. void R_TimeRefresh_f (void)
  61. {
  62. int i;
  63. float start, stop, time;
  64. CViewSetup view;
  65. materials->Flush( true );
  66. Q_memset(&view, 0, sizeof(view));
  67. view.origin = MainViewOrigin();
  68. view.angles[0] = 0;
  69. view.angles[1] = 0;
  70. view.angles[2] = 0;
  71. view.x = 0;
  72. view.y = 0;
  73. view.width = videomode->GetModeWidth();
  74. view.height = videomode->GetModeHeight();
  75. view.fov = 75;
  76. view.fovViewmodel = 75;
  77. view.m_flAspectRatio = 1.0f;
  78. view.zNear = 4;
  79. view.zFar = MAX_COORD_FLOAT;
  80. view.zNearViewmodel = 4;
  81. view.zFarViewmodel = MAX_COORD_FLOAT;
  82. int savedeveloper = developer.GetInt();
  83. developer.SetValue( 0 );
  84. start = Sys_FloatTime ();
  85. for (i=0 ; i<128 ; i++)
  86. {
  87. view.angles[1] = i/128.0*360.0;
  88. g_ClientDLL->RenderView( view, VIEW_CLEAR_COLOR, RENDERVIEW_DRAWVIEWMODEL | RENDERVIEW_DRAWHUD );
  89. Shader_SwapBuffers();
  90. }
  91. materials->Flush( true );
  92. Shader_SwapBuffers();
  93. stop = Sys_FloatTime ();
  94. time = stop-start;
  95. developer.SetValue( savedeveloper );
  96. ConMsg ("%f seconds (%f fps)\n", time, 128/time);
  97. }
  98. ConCommand timerefresh("timerefresh", R_TimeRefresh_f, "Profile the renderer.", FCVAR_CHEAT );
  99. ConCommand linefile("linefile", Linefile_Read_f, "Parses map leak data from .lin file", FCVAR_CHEAT );
  100. //-----------------------------------------------------------------------------
  101. // Purpose:
  102. //-----------------------------------------------------------------------------
  103. void R_Init (void)
  104. {
  105. extern byte *hunk_base;
  106. extern void InitMathlib( void );
  107. InitMathlib();
  108. UpdateMaterialSystemConfig();
  109. #if defined( _PS3 )
  110. g_pBuildIndicesJob->Init();
  111. g_pBuildWorldListsJob->Init();
  112. #endif
  113. }
  114. //-----------------------------------------------------------------------------
  115. // Purpose:
  116. //-----------------------------------------------------------------------------
  117. void R_Shutdown( void )
  118. {
  119. }
  120. //-----------------------------------------------------------------------------
  121. // Purpose:
  122. //-----------------------------------------------------------------------------
  123. void R_ResetLightStyles( void )
  124. {
  125. for ( int i=0 ; i<256 ; i++ )
  126. {
  127. // normal light value
  128. d_lightstylevalue[i] = 264;
  129. d_lightstyleframe[i] = r_framecount;
  130. }
  131. }
  132. void R_RemoveAllDecalsFromAllModels();
  133. //-----------------------------------------------------------------------------
  134. // Purpose:
  135. //-----------------------------------------------------------------------------
  136. CON_COMMAND_F( r_cleardecals, "Usage r_cleardecals <permanent>.", FCVAR_CLIENTCMD_CAN_EXECUTE )
  137. {
  138. if ( host_state.worldmodel )
  139. {
  140. bool bPermanent = false;
  141. if ( args.ArgC() == 2 )
  142. {
  143. if ( !Q_stricmp( args[1], "permanent" ) )
  144. {
  145. bPermanent = true;
  146. }
  147. }
  148. R_DecalTerm( host_state.worldmodel->brush.pShared, bPermanent, false );
  149. }
  150. R_RemoveAllDecalsFromAllModels();
  151. }
  152. //-----------------------------------------------------------------------------
  153. // Loads world geometry. Called when map changes or dx level changes
  154. //-----------------------------------------------------------------------------
  155. void R_LoadWorldGeometry( bool bDXChange )
  156. {
  157. CUtlVector< uint32 > paintData;
  158. if ( g_PaintManager.m_bShouldRegister )
  159. {
  160. g_PaintManager.GetPaintmapDataRLE( paintData );
  161. }
  162. // Recreate the sortinfo arrays ( ack, uses new/delete right now ) because doing it with Hunk_AllocName will
  163. // leak through every connect that doesn't wipe the hunk ( "reconnect" )
  164. MaterialSystem_DestroySortinfo();
  165. //register paint maps
  166. MaterialSystem_RegisterPaintSurfaces();
  167. MaterialSystem_RegisterLightmapSurfaces();
  168. MaterialSystem_CreateSortinfo();
  169. // UNDONE: This is a really crappy place to do this - shouldn't this stuff be in the modelloader?
  170. // If this is the first time we've tried to render this map, create a few one-time data structures
  171. // These all get cleared out if Map_UnloadModel is ever called by the modelloader interface ( and that happens
  172. // any time we free the Hunk down to the low mark since these things all use the Hunk for their data ).
  173. if ( !bDXChange )
  174. {
  175. if ( !modelloader->Map_GetRenderInfoAllocated() )
  176. {
  177. // create the displacement surfaces for the map
  178. modelloader->Map_LoadDisplacements( host_state.worldmodel, false );
  179. //if( !DispInfo_CreateStaticBuffers( host_state.worldmodel, materialSortInfoArray, false ) )
  180. // Sys_Error( "Can't create static meshes for displacements" );
  181. modelloader->Map_SetRenderInfoAllocated( true );
  182. }
  183. }
  184. else
  185. {
  186. // create the displacement surfaces for the map
  187. modelloader->Map_LoadDisplacements( host_state.worldmodel, true );
  188. }
  189. if ( bDXChange )
  190. {
  191. // Must be done before MarkWaterSurfaces
  192. modelloader->RecomputeSurfaceFlags( host_state.worldmodel );
  193. }
  194. Mod_MarkWaterSurfaces( host_state.worldmodel );
  195. // make sure and rebuild lightmaps when the level gets started.
  196. GL_RebuildLightmaps();
  197. if ( bDXChange )
  198. {
  199. R_BrushBatchInit();
  200. R_DecalReSortMaterials();
  201. OverlayMgr()->ReSortMaterials();
  202. }
  203. if ( g_PaintManager.m_bShouldRegister )
  204. {
  205. g_PaintManager.LoadPaintmapDataRLE( paintData );
  206. paintData.Purge();
  207. }
  208. }
  209. /*
  210. ===============
  211. R_LevelInit
  212. ===============
  213. */
  214. void R_LevelInit( void )
  215. {
  216. ConDMsg( "Initializing renderer...\n" );
  217. COM_TimestampedLog( "R_LevelInit: Start" );
  218. VPROF_BUDGET( "R_LevelInit", VPROF_BUDGETGROUP_OTHER_NETWORKING );
  219. Assert( g_ClientDLL );
  220. r_framecount = 1;
  221. R_ResetLightStyles();
  222. R_DecalInit();
  223. R_LoadSkys();
  224. R_InitStudio();
  225. // FIXME: Is this the best place to initialize the kd tree when we're client-only?
  226. if ( !sv.IsActive() )
  227. {
  228. g_pShadowMgr->LevelShutdown();
  229. StaticPropMgr()->LevelShutdown();
  230. SpatialPartition()->Init( host_state.worldmodel->mins, host_state.worldmodel->maxs );
  231. StaticPropMgr()->LevelInit();
  232. g_pShadowMgr->LevelInit( host_state.worldbrush->numsurfaces );
  233. }
  234. // We've fully loaded the new level, unload any models that we don't care about any more
  235. modelloader->UnloadUnreferencedModels();
  236. // INFESTED_DLL - Alien Swarm doesn't want fullbright turned on when there are no lights (since it uses dynamic lights and skips vrad)
  237. static char gamedir[MAX_OSPATH];
  238. Q_FileBase( com_gamedir, gamedir, sizeof( gamedir ) );
  239. if ( host_state.worldmodel->brush.pShared->numworldlights == 0 && Q_stricmp( gamedir, "infested" ) )
  240. {
  241. ConDMsg( "Level unlit, setting 'mat_fullbright 1'\n" );
  242. mat_fullbright.SetValue( 1 );
  243. }
  244. UpdateMaterialSystemConfig();
  245. // FIXME: E3 2003 HACK
  246. if ( IsPC() && mat_levelflush.GetBool() )
  247. {
  248. bool bOnLevelShutdown = false;
  249. materials->ResetTempHWMemory( bOnLevelShutdown );
  250. }
  251. // precache any textures that are used in this map.
  252. // this is a no-op for textures that are already cached from the previous map.
  253. materials->CacheUsedMaterials();
  254. // Loads the world geometry
  255. R_LoadWorldGeometry();
  256. R_Surface_LevelInit();
  257. R_Areaportal_LevelInit();
  258. // Build the overlay fragments.
  259. OverlayMgr()->CreateFragments();
  260. COM_TimestampedLog( "R_LevelInit: Finish" );
  261. g_RendererInLevel = true;
  262. }
  263. void R_LevelShutdown()
  264. {
  265. R_Surface_LevelShutdown();
  266. R_Areaportal_LevelShutdown();
  267. g_DispLightmapSamplePositions.Purge();
  268. g_RendererInLevel = false;
  269. }