forked from AmigurumiShaders/DX11Starter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaterial.cpp
More file actions
71 lines (56 loc) · 1.67 KB
/
Material.cpp
File metadata and controls
71 lines (56 loc) · 1.67 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
#include "Material.h"
#include "DX12Helper.h"
TextureMaterial::TextureMaterial(Microsoft::WRL::ComPtr<ID3D12PipelineState> pipeline, DirectX::XMFLOAT4 colorTint, DirectX::XMFLOAT2 uvScale, DirectX::XMFLOAT2 uvOffset)
:Material(colorTint,1.0f)
{
this->pipelineState = pipeline;
this->uvScale = uvScale;
this->uvOffset = uvOffset;
finalized = false;
highestSRVIndex = -1;
finalGPUHandleForSRVs = {};
ZeroMemory(textureSRVsBySlot, sizeof(D3D12_CPU_DESCRIPTOR_HANDLE) * 128);
}
void TextureMaterial::AddTexture(D3D12_CPU_DESCRIPTOR_HANDLE srv, int slot)
{
// Valid slot?
if (finalized || slot < 0 || slot >= 128)
return;
// Save and check if this was the highest slot
textureSRVsBySlot[slot] = srv;
highestSRVIndex = max(highestSRVIndex, slot);
}
void TextureMaterial::FinalizeMaterial()
{
if (finalized) return; //dont do anything if this is already finalized
DX12Helper& dx12Helper = DX12Helper::GetInstance();
for (int i = 0; i < highestSRVIndex + 1; i++)
{
D3D12_GPU_DESCRIPTOR_HANDLE handle = dx12Helper.CopySRVsToDescriptorHeapAndGetGPUDescriptorHandle(textureSRVsBySlot[i], 1);
if (i == 0) //we just want the first one, to point to the first descriptor in the final heap
{
finalGPUHandleForSRVs = handle;
}
}
finalized = true;
}
Microsoft::WRL::ComPtr<ID3D12PipelineState> TextureMaterial::GetPipelineState()
{
return pipelineState;
}
D3D12_GPU_DESCRIPTOR_HANDLE TextureMaterial::GetFinalGPUHandleForTextures()
{
return finalGPUHandleForSRVs;
}
DirectX::XMFLOAT4 TextureMaterial::GetColorTint()
{
return colorTint;
}
DirectX::XMFLOAT2 TextureMaterial::GetUVScale()
{
return uvScale;
}
DirectX::XMFLOAT2 TextureMaterial::GetUVOffset()
{
return uvOffset;
}