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.

175 lines
7.1 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Implementation for CBaseClientRenderTargets class.
  4. // Provides Init functions for common render textures used by the engine.
  5. // Mod makers can inherit from this class, and call the Create functions for
  6. // only the render textures the want for their mod.
  7. //=============================================================================//
  8. #include "cbase.h"
  9. #include "baseclientrendertargets.h" // header
  10. #include "materialsystem/imaterialsystemhardwareconfig.h" // Hardware config checks
  11. #include "materialsystem/itexture.h" // Hardware config checks
  12. #include "tier0/icommandline.h"
  13. #ifdef GAMEUI_UISYSTEM2_ENABLED
  14. #include "gameui.h"
  15. #endif
  16. #include "c_env_cascade_light.h"
  17. // NOTE: This has to be the last file included!
  18. #include "tier0/memdbgon.h"
  19. ConVar cl_disable_water_render_targets( "cl_disable_water_render_targets", "0" );
  20. ITexture* CBaseClientRenderTargets::CreateWaterReflectionTexture( IMaterialSystem* pMaterialSystem, int iSize )
  21. {
  22. iSize = CommandLine()->ParmValue( "-reflectionTextureSize", iSize );
  23. #if defined( PORTAL )
  24. return pMaterialSystem->CreateNamedMultiRenderTargetTexture(
  25. "_rt_WaterReflection",
  26. iSize, iSize, RT_SIZE_NO_CHANGE,
  27. pMaterialSystem->GetBackBufferFormat(),
  28. // Force separate depth buffer for recursive water reflection views, since using the default depth buffer
  29. // will clear depth in the upper left hand <512,512> corner of the screen causing translucent renderables to
  30. // render on top of closer geometry.
  31. MATERIAL_RT_DEPTH_SEPARATE,
  32. TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  33. CREATERENDERTARGETFLAGS_HDR );
  34. #else
  35. return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
  36. "_rt_WaterReflection",
  37. iSize, iSize, RT_SIZE_PICMIP,
  38. pMaterialSystem->GetBackBufferFormat(),
  39. MATERIAL_RT_DEPTH_SHARED,
  40. TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  41. CREATERENDERTARGETFLAGS_HDR );
  42. #endif
  43. }
  44. ITexture* CBaseClientRenderTargets::CreateWaterRefractionTexture( IMaterialSystem* pMaterialSystem, int iSize )
  45. {
  46. iSize = CommandLine()->ParmValue( "-reflectionTextureSize", iSize );
  47. #if defined( PORTAL )
  48. return pMaterialSystem->CreateNamedMultiRenderTargetTexture(
  49. "_rt_WaterRefraction",
  50. iSize, iSize, RT_SIZE_NO_CHANGE,
  51. // This is different than reflection because it has to have alpha for fog factor.
  52. IMAGE_FORMAT_RGBA8888,
  53. // Force separate depth buffer for recursive water reflection views, since using the default depth buffer
  54. // will clear depth in the upper left hand <512,512> corner of the screen causing translucent renderables to
  55. // render on top of closer geometry.
  56. //
  57. // EDIT: on consoles it doesn't matter for Portal 2 because we never use refraction anyways...we always opt for cheaper translucent water. Save memory instead.
  58. // @TODO: get rid of this buffer entirely on consoles
  59. IsGameConsole() ? MATERIAL_RT_DEPTH_SHARED : MATERIAL_RT_DEPTH_SEPARATE,
  60. TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  61. CREATERENDERTARGETFLAGS_HDR );
  62. #else
  63. return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
  64. "_rt_WaterRefraction",
  65. iSize, iSize, RT_SIZE_PICMIP,
  66. // This is different than reflection because it has to have alpha for fog factor.
  67. IMAGE_FORMAT_RGBA8888,
  68. MATERIAL_RT_DEPTH_SHARED,
  69. TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  70. CREATERENDERTARGETFLAGS_HDR );
  71. #endif
  72. }
  73. ITexture* CBaseClientRenderTargets::CreateCameraTexture( IMaterialSystem* pMaterialSystem, int iSize )
  74. {
  75. iSize = CommandLine()->ParmValue( "-monitorTextureSize", iSize );
  76. return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
  77. "_rt_Camera",
  78. iSize, iSize, RT_SIZE_DEFAULT,
  79. pMaterialSystem->GetBackBufferFormat(),
  80. MATERIAL_RT_DEPTH_SHARED,
  81. 0,
  82. CREATERENDERTARGETFLAGS_HDR );
  83. }
  84. //-----------------------------------------------------------------------------
  85. // Purpose: Called by the engine in material system init and shutdown.
  86. // Clients should override this in their inherited version, but the base
  87. // is to init all standard render targets for use.
  88. // Input : pMaterialSystem - the engine's material system (our singleton is not yet inited at the time this is called)
  89. // pHardwareConfig - the user hardware config, useful for conditional render target setup
  90. //-----------------------------------------------------------------------------
  91. void CBaseClientRenderTargets::SetupClientRenderTargets( IMaterialSystem* pMaterialSystem, IMaterialSystemHardwareConfig* pHardwareConfig, int iWaterTextureSize, int iCameraTextureSize )
  92. {
  93. IMaterialSystem *pSave = materials;
  94. // Make sure our config is loaded before we try to init rendertargets
  95. ConfigureCurrentSystemLevel();
  96. // Water effects
  97. materials = pMaterialSystem; // in case not initted yet for mat system util
  98. g_pMaterialSystem = pMaterialSystem;
  99. g_pMaterialSystemHardwareConfig = pHardwareConfig;
  100. if ( iWaterTextureSize && !cl_disable_water_render_targets.GetBool() )
  101. {
  102. m_WaterReflectionTexture.Init( CreateWaterReflectionTexture( pMaterialSystem, iWaterTextureSize ) );
  103. m_WaterRefractionTexture.Init( CreateWaterRefractionTexture( pMaterialSystem, iWaterTextureSize ) );
  104. }
  105. // mdonofrio - Don't need monitors or flashlight shadows for CS15.
  106. // Still need to initrendertargets for shadowmgr (blob/rtt shadows) - it will skip depth textures if convars set appropriately??
  107. #if !( defined( CSTRIKE15 ) && defined( _PS3 ) )
  108. // Monitors
  109. if ( iCameraTextureSize )
  110. m_CameraTexture.Init( CreateCameraTexture( pMaterialSystem, iCameraTextureSize ) );
  111. #endif
  112. ITexture *pGlintTexture = pMaterialSystem->CreateNamedRenderTargetTextureEx2(
  113. "_rt_eyeglint", 32, 32, RT_SIZE_NO_CHANGE, IMAGE_FORMAT_BGRA8888, MATERIAL_RT_DEPTH_NONE );
  114. pGlintTexture->IncrementReferenceCount();
  115. g_CascadeLightManager.InitRenderTargets();
  116. g_pClientShadowMgr->InitRenderTargets();
  117. #ifdef GAMEUI_UISYSTEM2_ENABLED
  118. g_pGameUIGameSystem->InitRenderTargets();
  119. #endif
  120. m_RenderToRTHelperTexture.Init( pMaterialSystem->CreateNamedRenderTargetTextureEx2( "render_to_rt_helper", 512, 512, RT_SIZE_DEFAULT, IMAGE_FORMAT_RGBA8888, MATERIAL_RT_DEPTH_SHARED, TEXTUREFLAGS_SINGLECOPY ) );
  121. materials = pSave;
  122. }
  123. void CBaseClientRenderTargets::InitClientRenderTargets( IMaterialSystem* pMaterialSystem, IMaterialSystemHardwareConfig* pHardwareConfig )
  124. {
  125. SetupClientRenderTargets( pMaterialSystem, pHardwareConfig );
  126. }
  127. //-----------------------------------------------------------------------------
  128. // Purpose: Shut down each CTextureReference we created in InitClientRenderTargets.
  129. // Called by the engine in material system shutdown.
  130. // Input : -
  131. //-----------------------------------------------------------------------------
  132. void CBaseClientRenderTargets::ShutdownClientRenderTargets()
  133. {
  134. // Water effects
  135. m_WaterReflectionTexture.Shutdown();
  136. m_WaterRefractionTexture.Shutdown();
  137. // Monitors
  138. m_CameraTexture.Shutdown();
  139. g_pClientShadowMgr->ShutdownRenderTargets();
  140. g_CascadeLightManager.ShutdownRenderTargets();
  141. m_RenderToRTHelperTexture.Shutdown();
  142. }
  143. static CBaseClientRenderTargets g_BaseClientRenderTargets;
  144. EXPOSE_SINGLE_INTERFACE_GLOBALVAR( CBaseClientRenderTargets, IClientRenderTargets,
  145. CLIENTRENDERTARGETS_INTERFACE_VERSION, g_BaseClientRenderTargets );