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.

75 lines
2.0 KiB

  1. //========= Copyright � 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #include "cbase.h"
  8. #include "materialsystem/imaterialproxy.h"
  9. #include "materialsystem/imaterial.h"
  10. #include "materialsystem/imaterialvar.h"
  11. #include "iviewrender.h"
  12. #include "imaterialproxydict.h"
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. // no inputs, assumes that the results go into $CHEAPWATERSTARTDISTANCE and $CHEAPWATERENDDISTANCE
  16. class CWaterLODMaterialProxy : public IMaterialProxy
  17. {
  18. public:
  19. CWaterLODMaterialProxy();
  20. virtual ~CWaterLODMaterialProxy();
  21. virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
  22. virtual void OnBind( void *pC_BaseEntity );
  23. virtual void Release( void ) { delete this; }
  24. virtual IMaterial *GetMaterial();
  25. private:
  26. IMaterialVar *m_pCheapWaterStartDistanceVar;
  27. IMaterialVar *m_pCheapWaterEndDistanceVar;
  28. };
  29. CWaterLODMaterialProxy::CWaterLODMaterialProxy()
  30. {
  31. m_pCheapWaterStartDistanceVar = NULL;
  32. m_pCheapWaterEndDistanceVar = NULL;
  33. }
  34. CWaterLODMaterialProxy::~CWaterLODMaterialProxy()
  35. {
  36. }
  37. bool CWaterLODMaterialProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
  38. {
  39. bool foundVar;
  40. m_pCheapWaterStartDistanceVar = pMaterial->FindVar( "$CHEAPWATERSTARTDISTANCE", &foundVar, false );
  41. if( !foundVar )
  42. return false;
  43. m_pCheapWaterEndDistanceVar = pMaterial->FindVar( "$CHEAPWATERENDDISTANCE", &foundVar, false );
  44. if( !foundVar )
  45. return false;
  46. return true;
  47. }
  48. void CWaterLODMaterialProxy::OnBind( void *pC_BaseEntity )
  49. {
  50. if( !m_pCheapWaterStartDistanceVar || !m_pCheapWaterEndDistanceVar )
  51. {
  52. return;
  53. }
  54. float start, end;
  55. view->GetWaterLODParams( start, end );
  56. m_pCheapWaterStartDistanceVar->SetFloatValue( start );
  57. m_pCheapWaterEndDistanceVar->SetFloatValue( end );
  58. }
  59. IMaterial *CWaterLODMaterialProxy::GetMaterial()
  60. {
  61. return m_pCheapWaterStartDistanceVar->GetOwningMaterial();
  62. }
  63. EXPOSE_MATERIAL_PROXY( CWaterLODMaterialProxy, WaterLOD );