summaryrefslogtreecommitdiff
path: root/game/client/tf2/ztestmaterialproxy.cpp
blob: 102cd34f273c3aefaf37099bb019f4ca432f6c95 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "materialsystem/imaterialproxy.h"
#include "materialsystem/imaterial.h"
#include "materialsystem/imaterialvar.h"

// $sineVar : name of variable that controls the alpha level (float)
class CzTestMaterialProxy : public IMaterialProxy
{
public:
	CzTestMaterialProxy();
	virtual ~CzTestMaterialProxy();
	virtual bool Init( IMaterial *pMaterial, KeyValues *pKeyValues );
	virtual void OnBind( void *pC_BaseEntity );
	virtual void Release( void ) { delete this; }
private:
	C_BaseEntity *BindArgToEntity( void *pArg );

	IMaterialVar *m_AlphaVar;
};

CzTestMaterialProxy::CzTestMaterialProxy()
{
	m_AlphaVar = NULL;
}

CzTestMaterialProxy::~CzTestMaterialProxy()
{
}

C_BaseEntity *CzTestMaterialProxy::BindArgToEntity( void *pArg )
{
	IClientRenderable *pRend = (IClientRenderable *)pArg;
	return pRend->GetIClientUnknown()->GetBaseEntity();
}

bool CzTestMaterialProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
{
	bool foundVar;
	m_AlphaVar = pMaterial->FindVar( "$alpha", &foundVar, false );
	return foundVar;
}

void CzTestMaterialProxy::OnBind( void *pC_BaseEntity )
{
	C_BaseEntity *pEnt = BindArgToEntity( pC_BaseEntity );
	if( !pEnt )
	{
		return;
	}

	if (m_AlphaVar)
	{
		m_AlphaVar->SetFloatValue( pEnt->m_clrRender.a );
	}

}

EXPOSE_INTERFACE( CzTestMaterialProxy, IMaterialProxy, "zTest" IMATERIAL_PROXY_INTERFACE_VERSION );