forked from megayuchi/D3D12Lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD3D12Renderer.h
135 lines (107 loc) · 5.01 KB
/
D3D12Renderer.h
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#pragma once
#include "Renderer_typedef.h"
class CD3D12ResourceManager;
class CDescriptorPool;
class CSimpleConstantBufferPool;
class CSingleDescriptorAllocator;
class CConstantBufferManager;
class CFontManager;
class CTextureManager;
class CD3D12Renderer
{
static const UINT MAX_DRAW_COUNT_PER_FRAME = 1024;
static const UINT MAX_DESCRIPTOR_COUNT = 4096;
HWND m_hWnd = nullptr;
ID3D12Device5* m_pD3DDevice = nullptr;
ID3D12CommandQueue* m_pCommandQueue = nullptr;
CD3D12ResourceManager* m_pResourceManager = nullptr;
CFontManager* m_pFontManager = nullptr;
CSingleDescriptorAllocator* m_pSingleDescriptorAllocator = nullptr;
ID3D12CommandAllocator* m_ppCommandAllocator[MAX_PENDING_FRAME_COUNT] = {};
ID3D12GraphicsCommandList* m_ppCommandList[MAX_PENDING_FRAME_COUNT] = {};
CDescriptorPool* m_ppDescriptorPool[MAX_PENDING_FRAME_COUNT] = {};
CConstantBufferManager* m_ppConstBufferManager[MAX_PENDING_FRAME_COUNT] = {};
CTextureManager* m_pTextureManager = nullptr;
UINT64 m_pui64LastFenceValue[MAX_PENDING_FRAME_COUNT] = {};
UINT64 m_ui64FenceVaule = 0;
D3D_FEATURE_LEVEL m_FeatureLevel = D3D_FEATURE_LEVEL_11_0;
DXGI_ADAPTER_DESC1 m_AdapterDesc = {};
IDXGISwapChain3* m_pSwapChain = nullptr;
D3D12_VIEWPORT m_Viewport = {};
D3D12_RECT m_ScissorRect = {};
DWORD m_dwWidth = 0;
DWORD m_dwHeight = 0;
float m_fDPI = 96.0f;
ID3D12Resource* m_pRenderTargets[SWAP_CHAIN_FRAME_COUNT] = {};
ID3D12Resource* m_pDepthStencil = nullptr;
ID3D12DescriptorHeap* m_pRTVHeap = nullptr;
ID3D12DescriptorHeap* m_pDSVHeap = nullptr;
ID3D12DescriptorHeap* m_pSRVHeap = nullptr;
UINT m_rtvDescriptorSize = 0;
UINT m_srvDescriptorSize = 0;
UINT m_dsvDescriptorSize = 0;
UINT m_dwSwapChainFlags = 0;
UINT m_uiRenderTargetIndex = 0;
HANDLE m_hFenceEvent = nullptr;
ID3D12Fence* m_pFence = nullptr;
DWORD m_dwCurContextIndex = 0;
XMMATRIX m_matView = {};
XMMATRIX m_matProj = {};
XMVECTOR m_CamPos = {};
XMVECTOR m_CamDir = {};
void InitCamera();
BOOL CreateDepthStencil(UINT Width, UINT Height);
void CreateFence();
void CleanupFence();
void CreateCommandList();
void CleanupCommandList();
BOOL CreateDescriptorHeapForRTV();
BOOL CreateDescriptorHeapForDSV();
void CleanupDescriptorHeapForRTV();
void CleanupDescriptorHeapForDSV();
UINT64 Fence();
void WaitForFenceValue(UINT64 ExpectedFenceValue);
void Cleanup();
public:
BOOL Initialize(HWND hWnd, BOOL bEnableDebugLayer, BOOL bEnableGBV);
void BeginRender();
void EndRender();
void Present();
BOOL UpdateWindowSize(DWORD dwBackBufferWidth, DWORD dwBackBufferHeight);
void* CreateBasicMeshObject();
void DeleteBasicMeshObject(void* pMeshObjHandle);
void* CreateSpriteObject();
void* CreateSpriteObject(const WCHAR* wchTexFileName, int PosX, int PosY, int Width, int Height);
void DeleteSpriteObject(void* pSpriteObjHandle);
BOOL BeginCreateMesh(void* pMeshObjHandle, const BasicVertex* pVertexList, DWORD dwVertexCount, DWORD dwTriGroupCount);
BOOL InsertTriGroup(void* pMeshObjHandle, const WORD* pIndexList, DWORD dwTriCount, const WCHAR* wchTexFileName);
void EndCreateMesh(void* pMeshObjHandle);
void* CreateTiledTexture(UINT TexWidth, UINT TexHeight, DWORD r, DWORD g, DWORD b);
void* CreateDynamicTexture(UINT TexWidth, UINT TexHeight);
void* CreateTextureFromFile(const WCHAR* wchFileName);
void DeleteTexture(void* pTexHandle);
void* CreateFontObject(const WCHAR* wchFontFamilyName, float fFontSize);
void DeleteFontObject(void* pFontHandle);
BOOL WriteTextToBitmap(BYTE* pDestImage, UINT DestWidth, UINT DestHeight, UINT DestPitch, int* piOutWidth, int* piOutHeight, void* pFontObjHandle, const WCHAR* wchString, DWORD dwLen);
void RenderMeshObject(void* pMeshObjHandle, const XMMATRIX* pMatWorld);
void RenderSpriteWithTex(void* pSprObjHandle, int iPosX, int iPosY, float fScaleX, float fScaleY, const RECT* pRect, float Z, void* pTexHandle);
void RenderSprite(void* pSprObjHandle, int iPosX, int iPosY, float fScaleX, float fScaleY, float Z);
void UpdateTextureWithImage(void* pTexHandle, const BYTE* pSrcBits, UINT SrcWidth, UINT SrcHeight);
void SetCameraPos(float x, float y, float z);
void MoveCamera(float x, float y, float z);
void GetCameraPos(float* pfOutX, float* pfOutY, float* pfOutZ);
void SetCamera(const XMVECTOR* pCamPos, const XMVECTOR* pCamDir, const XMVECTOR* pCamUp);
// for internal
ID3D12Device5* INL_GetD3DDevice() const { return m_pD3DDevice; }
CD3D12ResourceManager* INL_GetResourceManager() { return m_pResourceManager; }
CDescriptorPool* INL_GetDescriptorPool() { return m_ppDescriptorPool[m_dwCurContextIndex]; }
CSimpleConstantBufferPool* GetConstantBufferPool(CONSTANT_BUFFER_TYPE type);
UINT INL_GetSrvDescriptorSize() { return m_srvDescriptorSize; }
CSingleDescriptorAllocator* INL_GetSingleDescriptorAllocator() { return m_pSingleDescriptorAllocator; }
void GetViewProjMatrix(XMMATRIX* pOutMatView, XMMATRIX* pOutMatProj);
DWORD INL_GetScreenWidth() const { return m_dwWidth; }
DWORD INL_GetScreenHeigt() const { return m_dwHeight; }
float INL_GetDPI() const { return m_fDPI; }
CD3D12Renderer();
~CD3D12Renderer();
};