aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/cl_mat_stub.cpp
blob: a0caec8d4da37769dba2efff3314058ada22bbe3 (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
65
66
67
68
69
70
71
72
73
74
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//===========================================================================//

#include "cbase.h"
#include "bitmap/imageformat.h"
#include "cl_mat_stub.h"
#include "materialsystem/imaterialsystemstub.h"

// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"

// Hook the engine's mat_stub cvar.
ConVar mat_stub( "mat_stub", "0", FCVAR_CHEAT );
extern ConVar gl_clear;


IMaterialSystemStub* GetStubMaterialSystem()
{
	return materials_stub;
}

// ---------------------------------------------------------------------------------------- //
// CMatStubHandler implementation.
// ---------------------------------------------------------------------------------------- //

CMatStubHandler::CMatStubHandler()
{
	if ( mat_stub.GetInt() )
	{
		m_pOldMaterialSystem = materials;

		// Replace all material system pointers with the stub.
		GetStubMaterialSystem()->SetRealMaterialSystem( materials );
		materials->SetInStubMode( true );
		materials = GetStubMaterialSystem();
		engine->Mat_Stub( materials );
	}
	else
	{
		m_pOldMaterialSystem = 0;
	}
}


CMatStubHandler::~CMatStubHandler()
{
	End();
}


void CMatStubHandler::End()
{
	// Put back the original material system pointer.
	if ( m_pOldMaterialSystem )
	{
		materials = m_pOldMaterialSystem;
		materials->SetInStubMode( false );
		engine->Mat_Stub( materials );
		m_pOldMaterialSystem = 0;
//		if( gl_clear.GetBool() )
		{
			materials->ClearBuffers( true, true );
		}
	}
}


bool IsMatStubEnabled()
{
	return mat_stub.GetBool();
}