-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModuleD3D12.h
More file actions
82 lines (68 loc) · 2.52 KB
/
Copy pathModuleD3D12.h
File metadata and controls
82 lines (68 loc) · 2.52 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
#pragma once
#include "Module.h"
#include <wrl/client.h>
#include <dxgi1_6.h>
#include <cstdint>
class ModuleD3D12 : public Module
{
private:
bool m_commandListOpen = false;
HWND hWnd = NULL;
uint32_t windowWidth = 0;
uint32_t windowHeight = 0;
// Core DX12
Microsoft::WRL::ComPtr<IDXGIFactory6> factory;
Microsoft::WRL::ComPtr<ID3D12Device5> device;
Microsoft::WRL::ComPtr<ID3D12CommandQueue> commandQueue;
Microsoft::WRL::ComPtr<ID3D12GraphicsCommandList> commandList;
Microsoft::WRL::ComPtr<ID3D12CommandAllocator> commandAllocator;
// Swap chain y render targets
static constexpr uint32_t BACK_BUFFER_COUNT = 2;
Microsoft::WRL::ComPtr<IDXGISwapChain4> swapChain;
uint32_t currentFrame = 0;
Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> rtvHeap;
uint32_t rtvDescriptorSize = 0;
Microsoft::WRL::ComPtr<ID3D12Resource> renderTargets[BACK_BUFFER_COUNT];
// Depth stencil
Microsoft::WRL::ComPtr<ID3D12Resource> depthStencilBuffer;
Microsoft::WRL::ComPtr<ID3D12DescriptorHeap> dsvHeap;
UINT dsvDescriptorSize = 0;
// Fence
Microsoft::WRL::ComPtr<ID3D12Fence> fence;
uint64_t fenceValue = 0;
HANDLE fenceEvent = nullptr;
//Render to Texture
std::vector<bool> rtvAllocations;
UINT allocatedRTVs = 0;
public:
ModuleD3D12(HWND hWnd);
~ModuleD3D12();
uint32_t getWindowWidth() const { return windowWidth; }
uint32_t getWindowHeight() const { return windowHeight; }
bool init() override;
void preRender() override;
void postRender() override;
void resize(uint32_t width, uint32_t height);
bool flush();
bool isCommandListOpen() const { return m_commandListOpen; }
// Getters para otros módulos
ID3D12Device5* getDevice() const;
uint32_t getCurrentFrame() const;
UINT getLastCompletedFrame() const;
ID3D12GraphicsCommandList* getCommandList() const;
ID3D12CommandAllocator* getCommandAllocator() const;
ID3D12CommandQueue* getDrawCommandQueue() const;
ID3D12Resource* getBackBuffer() const;
D3D12_CPU_DESCRIPTOR_HANDLE getRenderTargetDescriptor() const;
D3D12_CPU_DESCRIPTOR_HANDLE getDepthStencilDescriptor() const {
return dsvHeap->GetCPUDescriptorHandleForHeapStart();
}
//Render to Texture
D3D12_CPU_DESCRIPTOR_HANDLE allocateRTV();
void freeRTV(D3D12_CPU_DESCRIPTOR_HANDLE handle);
ID3D12DescriptorHeap* getRTVHeap() const { return rtvHeap.Get(); }
private:
void enableDebugLayer();
bool createFactory();
bool createDevice(bool useWarp);
};