-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderTargetTexture.cpp
More file actions
109 lines (89 loc) · 3.33 KB
/
Copy pathRenderTargetTexture.cpp
File metadata and controls
109 lines (89 loc) · 3.33 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
#include "Globals.h"
#include "RenderTargetTexture.h"
#include "ModuleD3D12.h"
#include "Application.h"
#include "ModuleShaderDescriptors.h"
#include "ModuleResource.h"
/*
RenderTargetTexture::RenderTargetTexture() {
}
RenderTargetTexture::~RenderTargetTexture() {
Release();
}
void RenderTargetTexture::Release() {
texture.Reset();
}
bool RenderTargetTexture::Create(ID3D12Device* device, UINT width, UINT height, DXGI_FORMAT format, const DirectX::SimpleMath::Vector4& clearColor)
{
this->width = width;
this->height = height;
this->clearColor = clearColor;
D3D12_RESOURCE_DESC texDesc = {};
texDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
texDesc.Alignment = 0;
texDesc.Width = width;
texDesc.Height = height;
texDesc.DepthOrArraySize = 1;
texDesc.MipLevels = 1;
texDesc.Format = format;
texDesc.SampleDesc.Count = 1;
texDesc.SampleDesc.Quality = 0;
texDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
texDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
D3D12_HEAP_PROPERTIES heapProps = {};
heapProps.Type = D3D12_HEAP_TYPE_DEFAULT;
heapProps.CPUPageProperty = D3D12_CPU_PAGE_PROPERTY_UNKNOWN;
heapProps.MemoryPoolPreference = D3D12_MEMORY_POOL_UNKNOWN;
heapProps.CreationNodeMask = 1;
heapProps.VisibleNodeMask = 1;
D3D12_CLEAR_VALUE clearValue = {};
clearValue.Format = format;
memcpy(clearValue.Color, &clearColor.x, sizeof(float) * 4);
if (FAILED(device->CreateCommittedResource(
&heapProps,
D3D12_HEAP_FLAG_NONE,
&texDesc,
D3D12_RESOURCE_STATE_COMMON,
&clearValue,
IID_PPV_ARGS(&texture)))) {
LOG("Failed to create render target texture");
return false;
}
// Get ModuleShaderDescriptors
auto shaderDescriptors = app->getShaderDescriptors();
if (!shaderDescriptors) {
LOG("Shader descriptors module not found");
return false;
}
// Create RTV descriptor (in RTV heap from ModuleD3D12)
auto d3d12 = app->getD3D12();
auto rtvHeap = d3d12->getRTVHeap(); // You'll need to add this getter
rtvHandle = rtvHeap->GetCPUDescriptorHandleForHeapStart();
D3D12_RENDER_TARGET_VIEW_DESC rtvDesc = {};
rtvDesc.Format = format;
rtvDesc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
rtvDesc.Texture2D.MipSlice = 0;
rtvDesc.Texture2D.PlaneSlice = 0;
device->CreateRenderTargetView(texture.Get(), &rtvDesc, rtvHandle);
// Create SRV descriptor (in shader-visible heap)
srvHandle = shaderDescriptors->allocate(); // You'll need to implement allocation
D3D12_SHADER_RESOURCE_VIEW_DESC srvDesc = {};
srvDesc.Format = format;
srvDesc.ViewDimension = D3D12_SRV_DIMENSION_TEXTURE2D;
srvDesc.Shader4ComponentMapping = D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING;
srvDesc.Texture2D.MostDetailedMip = 0;
srvDesc.Texture2D.MipLevels = 1;
srvDesc.Texture2D.PlaneSlice = 0;
srvDesc.Texture2D.ResourceMinLODClamp = 0.0f;
device->CreateShaderResourceView(texture.Get(), &srvDesc, srvHandle.cpu);
LOG("Created render target texture: %dx%d", width, height);
return true;
}
bool RenderTargetTexture::Resize(ID3D12Device* device, UINT newWidth, UINT newHeight) {
if (width == newWidth && height == newHeight) {
return true;
}
Release();
return Create(device, newWidth, newHeight);
}
*/