forked from vixorien/D3D11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterial.cpp
More file actions
97 lines (79 loc) · 1.93 KB
/
Copy pathMaterial.cpp
File metadata and controls
97 lines (79 loc) · 1.93 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
#include "Material.h"
#include "Graphics.h"
Material::Material(
std::string name,
DirectX::XMFLOAT4 colorTint,
Microsoft::WRL::ComPtr<ID3D11PixelShader> ps,
Microsoft::WRL::ComPtr<ID3D11VertexShader> vs) :
name(name),
colorTint(colorTint),
scale(DirectX::XMFLOAT2(1.0f, 1.0f)),
offset(DirectX::XMFLOAT2(0.0f, 0.0f)),
ps(ps),
vs(vs)
{
}
std::string Material::GetName()
{
return name;
}
DirectX::XMFLOAT4 Material::GetColorTint()
{
return colorTint;
}
DirectX::XMFLOAT2 Material::GetScale()
{
return scale;
}
DirectX::XMFLOAT2 Material::GetOffset()
{
return offset;
}
Microsoft::WRL::ComPtr<ID3D11PixelShader> Material::GetPixelShader()
{
return ps;
}
Microsoft::WRL::ComPtr<ID3D11VertexShader> Material::GetVertexShader()
{
return vs;
}
std::unordered_map<unsigned int, Microsoft::WRL::ComPtr<ID3D11ShaderResourceView>>& Material::GetTextureSRVMap()
{
return textureSRVs;
}
void Material::SetColorTint(DirectX::XMFLOAT4 colorTint)
{
this->colorTint = colorTint;
}
void Material::SetScale(DirectX::XMFLOAT2 scale)
{
this->scale = scale;
}
void Material::SetOffset(DirectX::XMFLOAT2 offset)
{
this->offset = offset;
}
void Material::SetPixelShader(Microsoft::WRL::ComPtr<ID3D11PixelShader> ps)
{
this->ps = ps;
}
void Material::SetVertexShader(Microsoft::WRL::ComPtr<ID3D11VertexShader> vs)
{
this->vs = vs;
}
void Material::AddTextureSRV(unsigned int i, Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> srv)
{
textureSRVs.insert({ i, srv });
}
void Material::AddSampler(unsigned int i, Microsoft::WRL::ComPtr<ID3D11SamplerState> sampler)
{
samplers.insert({ i, sampler });
}
void Material::BindTexturesAndSamplers()
{
// Binding SRVs and Samplers in C++ (the first param is the index from the shader)
for (auto& srv : textureSRVs)
Graphics::Context->PSSetShaderResources(srv.first, 1, srv.second.GetAddressOf());
for (auto& s : samplers)
Graphics::Context->PSSetSamplers(s.first, 1, s.second.GetAddressOf());
}