forked from ValveSoftware/source-sdk-2013
-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathbaseclientrendertargets.cpp
More file actions
127 lines (112 loc) · 4.71 KB
/
baseclientrendertargets.cpp
File metadata and controls
127 lines (112 loc) · 4.71 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: Implementation for CBaseClientRenderTargets class.
// Provides Init functions for common render textures used by the engine.
// Mod makers can inherit from this class, and call the Create functions for
// only the render textures the want for their mod.
//=============================================================================//
#include "cbase.h"
#include "baseclientrendertargets.h" // header
#include "materialsystem/imaterialsystemhardwareconfig.h" // Hardware config checks
#include "tier0/icommandline.h"
ITexture* CBaseClientRenderTargets::CreateWaterReflectionTexture( IMaterialSystem* pMaterialSystem, int iSize )
{
return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
"_rt_WaterReflection",
iSize, iSize, RT_SIZE_PICMIP,
pMaterialSystem->GetBackBufferFormat(),
MATERIAL_RT_DEPTH_SHARED,
TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
CREATERENDERTARGETFLAGS_HDR );
}
ITexture* CBaseClientRenderTargets::CreateWaterRefractionTexture( IMaterialSystem* pMaterialSystem, int iSize )
{
return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
"_rt_WaterRefraction",
iSize, iSize, RT_SIZE_PICMIP,
// This is different than reflection because it has to have alpha for fog factor.
IMAGE_FORMAT_RGBA8888,
MATERIAL_RT_DEPTH_SHARED,
TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
CREATERENDERTARGETFLAGS_HDR );
}
ITexture* CBaseClientRenderTargets::CreateCameraTexture( IMaterialSystem* pMaterialSystem, int iSize )
{
return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
"_rt_Camera",
iSize, iSize, RT_SIZE_DEFAULT,
pMaterialSystem->GetBackBufferFormat(),
MATERIAL_RT_DEPTH_SHARED,
0,
CREATERENDERTARGETFLAGS_HDR );
}
#ifdef MAPBASE
ITexture* CBaseClientRenderTargets::CreateCustomCameraTexture( IMaterialSystem* pMaterialSystem, const char *pszTextureName, int iSize )
{
return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
pszTextureName,
iSize, iSize, RT_SIZE_DEFAULT,
pMaterialSystem->GetBackBufferFormat(),
MATERIAL_RT_DEPTH_SHARED,
0,
CREATERENDERTARGETFLAGS_HDR );
}
ITexture* CBaseClientRenderTargets::CreateColCorrectMaskTexture( IMaterialSystem* pMaterialSystem, int iSize )
{
return pMaterialSystem->CreateNamedRenderTargetTextureEx2(
"_rt_ColCorrectMask",
iSize, iSize, RT_SIZE_PICMIP,
pMaterialSystem->GetBackBufferFormat(), //IMAGE_FORMAT_A8
MATERIAL_RT_DEPTH_SHARED,
TEXTUREFLAGS_CLAMPS | TEXTUREFLAGS_CLAMPT,
CREATERENDERTARGETFLAGS_HDR );
}
#endif
//-----------------------------------------------------------------------------
// Purpose: Called by the engine in material system init and shutdown.
// Clients should override this in their inherited version, but the base
// is to init all standard render targets for use.
// Input : pMaterialSystem - the engine's material system (our singleton is not yet inited at the time this is called)
// pHardwareConfig - the user hardware config, useful for conditional render target setup
//-----------------------------------------------------------------------------
void CBaseClientRenderTargets::InitClientRenderTargets( IMaterialSystem* pMaterialSystem, IMaterialSystemHardwareConfig* pHardwareConfig, int iWaterTextureSize, int iCameraTextureSize )
{
// Water effects
m_WaterReflectionTexture.Init( CreateWaterReflectionTexture( pMaterialSystem, iWaterTextureSize ) );
m_WaterRefractionTexture.Init( CreateWaterRefractionTexture( pMaterialSystem, iWaterTextureSize ) );
// Monitors
m_CameraTexture.Init( CreateCameraTexture( pMaterialSystem, iCameraTextureSize ) );
#ifdef MAPBASE
int iNumCameras = CommandLine()->ParmValue( "-numcameratextures", 3 );
for ( int i = 0; i < iNumCameras; i++ )
{
char szName[32];
Q_snprintf( szName, sizeof(szName), "_rt_Camera%i", i );
int iRefIndex = m_CameraTextures.AddToTail();
m_CameraTextures[iRefIndex].Init( CreateCustomCameraTexture( pMaterialSystem, szName, iCameraTextureSize ) );
}
// Miscellaneous
m_ColCorrectMaskTexture.Init( CreateColCorrectMaskTexture( pMaterialSystem ) );
#endif
}
//-----------------------------------------------------------------------------
// Purpose: Shut down each CTextureReference we created in InitClientRenderTargets.
// Called by the engine in material system shutdown.
// Input : -
//-----------------------------------------------------------------------------
void CBaseClientRenderTargets::ShutdownClientRenderTargets()
{
// Water effects
m_WaterReflectionTexture.Shutdown();
m_WaterRefractionTexture.Shutdown();
// Monitors
m_CameraTexture.Shutdown();
#ifdef MAPBASE
for ( int i = 0; i < m_CameraTextures.Count(); i++ )
{
m_CameraTextures[i].Shutdown();
}
// Miscellaneous
m_ColCorrectMaskTexture.Shutdown();
#endif
}