forked from vixorien/D3D11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Material.cpp
73 lines (63 loc) · 1.61 KB
/
Material.cpp
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
#include "Material.h"
Material::Material(
DirectX::XMFLOAT4 colorTint,
std::shared_ptr<SimpleVertexShader> vs,
std::shared_ptr<SimplePixelShader> ps)
:
colorTint(colorTint),
vs(vs),
ps(ps)
{
}
DirectX::XMFLOAT4 Material::GetColorTint()
{
return colorTint;
}
std::shared_ptr<SimpleVertexShader> Material::GetVS()
{
return vs;
}
std::shared_ptr<SimplePixelShader> Material::GetPS()
{
return ps;
}
DirectX::XMFLOAT4 Material::SetColorTint(DirectX::XMFLOAT4 newColorTint)
{
colorTint = newColorTint;
return colorTint;
}
std::shared_ptr<SimpleVertexShader> Material::SetVS(std::shared_ptr<SimpleVertexShader> newVS)
{
vs = newVS;
return vs;
}
std::shared_ptr<SimplePixelShader> Material::SetPS(std::shared_ptr<SimplePixelShader> newPS)
{
ps = newPS;
return ps;
}
/// <summary>
/// Send all of the data we need for this material down to the GPU
/// </summary>
void Material::PrepareMaterial()
{
vs->SetShader();
ps->SetShader();
// Assigning SRVs and sampler state to the pixel shader in a loop, because there can be more than one.
for (auto& t : textureSRVs)
{
ps->SetShaderResourceView(t.first.c_str(), t.second);
}
for (auto& s : textureSamplers)
{
ps->SetSamplerState(s.first.c_str(), s.second);
}
}
void Material::AddTextureSRV(std::string shaderName, Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv)
{
textureSRVs.insert({ shaderName, srv });
}
void Material::AddTextureSampler(std::string shaderName, Microsoft::WRL::ComPtr<ID3D11SamplerState> sampState)
{
textureSamplers.insert({ shaderName, sampState });
}