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.

77 lines
3.3 KiB

  1. //========= Copyright 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 "tier0/icommandline.h"
  12. ITexture* CBaseClientRenderTargets::CreateWaterReflectionTexture( IMaterialSystem* pMaterialSystem, int iSize )
  13. {
  14. return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
  15. "_rt_WaterReflection",
  16. iSize, iSize, RT_SIZE_PICMIP,
  17. pMaterialSystem->GetBackBufferFormat(),
  18. MATERIAL_RT_DEPTH_SHARED,
  19. TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  20. CREATERENDERTARGETFLAGS_HDR );
  21. }
  22. ITexture* CBaseClientRenderTargets::CreateWaterRefractionTexture( IMaterialSystem* pMaterialSystem, int iSize )
  23. {
  24. return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
  25. "_rt_WaterRefraction",
  26. iSize, iSize, RT_SIZE_PICMIP,
  27. // This is different than reflection because it has to have alpha for fog factor.
  28. IMAGE_FORMAT_RGBA8888,
  29. MATERIAL_RT_DEPTH_SHARED,
  30. TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
  31. CREATERENDERTARGETFLAGS_HDR );
  32. }
  33. ITexture* CBaseClientRenderTargets::CreateCameraTexture( IMaterialSystem* pMaterialSystem, int iSize )
  34. {
  35. return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
  36. "_rt_Camera",
  37. iSize, iSize, RT_SIZE_DEFAULT,
  38. pMaterialSystem->GetBackBufferFormat(),
  39. MATERIAL_RT_DEPTH_SHARED,
  40. 0,
  41. CREATERENDERTARGETFLAGS_HDR );
  42. }
  43. //-----------------------------------------------------------------------------
  44. // Purpose: Called by the engine in material system init and shutdown.
  45. // Clients should override this in their inherited version, but the base
  46. // is to init all standard render targets for use.
  47. // Input : pMaterialSystem - the engine's material system (our singleton is not yet inited at the time this is called)
  48. // pHardwareConfig - the user hardware config, useful for conditional render target setup
  49. //-----------------------------------------------------------------------------
  50. void CBaseClientRenderTargets::InitClientRenderTargets( IMaterialSystem* pMaterialSystem, IMaterialSystemHardwareConfig* pHardwareConfig, int iWaterTextureSize, int iCameraTextureSize )
  51. {
  52. // Water effects
  53. m_WaterReflectionTexture.Init( CreateWaterReflectionTexture( pMaterialSystem, iWaterTextureSize ) );
  54. m_WaterRefractionTexture.Init( CreateWaterRefractionTexture( pMaterialSystem, iWaterTextureSize ) );
  55. // Monitors
  56. m_CameraTexture.Init( CreateCameraTexture( pMaterialSystem, iCameraTextureSize ) );
  57. }
  58. //-----------------------------------------------------------------------------
  59. // Purpose: Shut down each CTextureReference we created in InitClientRenderTargets.
  60. // Called by the engine in material system shutdown.
  61. // Input : -
  62. //-----------------------------------------------------------------------------
  63. void CBaseClientRenderTargets::ShutdownClientRenderTargets()
  64. {
  65. // Water effects
  66. m_WaterReflectionTexture.Shutdown();
  67. m_WaterRefractionTexture.Shutdown();
  68. // Monitors
  69. m_CameraTexture.Shutdown();
  70. }