-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathrendertarget.h
More file actions
105 lines (84 loc) · 2.7 KB
/
rendertarget.h
File metadata and controls
105 lines (84 loc) · 2.7 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
#pragma once
namespace Framework
{
int BitsPerPixel(DXGI_FORMAT format);
enum RTFLAG
{
RTFLAG_EnableUAV = 0x01,
RTFLAG_Default = 0x00,
};
class RenderTarget
{
public:
RenderTarget();
void Init(
ID3D11Device * pDevice,
int2 dims,
DXGI_FORMAT format,
int sampleCount = 1,
int flags = RTFLAG_Default);
void Reset();
void Bind(ID3D11DeviceContext * pCtx);
void Bind(ID3D11DeviceContext * pCtx, box2 viewport);
void Bind(ID3D11DeviceContext * pCtx, box3 viewport);
int SizeInBytes() const
{ return m_dims.x * m_dims.y * m_sampleCount * BitsPerPixel(m_format) / 8; }
// Read back the data to main memory - you're responsible for allocing enough
void Readback(
ID3D11DeviceContext * pCtx,
void * pDataOut);
comptr<ID3D11Texture2D> m_pTex;
comptr<ID3D11RenderTargetView> m_pRtv;
comptr<ID3D11ShaderResourceView> m_pSrv;
comptr<ID3D11UnorderedAccessView> m_pUav;
int2 m_dims;
int m_sampleCount;
DXGI_FORMAT m_format;
};
enum DSFLAG
{
DSFLAG_EnableUAV = 0x01,
DSFLAG_Default = 0x00,
};
class DepthStencilTarget
{
public:
DepthStencilTarget();
void Init(
ID3D11Device * pDevice,
int2 dims,
DXGI_FORMAT format,
int sampleCount = 1,
int flags = DSFLAG_Default);
void Reset();
void Bind(ID3D11DeviceContext * pCtx);
void Bind(ID3D11DeviceContext * pCtx, box2 viewport);
void Bind(ID3D11DeviceContext * pCtx, box3 viewport);
int SizeInBytes() const
{ return m_dims.x * m_dims.y * m_sampleCount * BitsPerPixel(m_formatDsv) / 8; }
// Read back the data to main memory - you're responsible for allocing enough
void Readback(
ID3D11DeviceContext * pCtx,
void * pDataOut);
comptr<ID3D11Texture2D> m_pTex;
comptr<ID3D11DepthStencilView> m_pDsv;
comptr<ID3D11ShaderResourceView> m_pSrvDepth;
comptr<ID3D11ShaderResourceView> m_pSrvStencil;
comptr<ID3D11UnorderedAccessView> m_pUavDepth;
comptr<ID3D11UnorderedAccessView> m_pUavStencil;
int2 m_dims;
int m_sampleCount;
DXGI_FORMAT m_formatDsv;
DXGI_FORMAT m_formatSrvDepth;
DXGI_FORMAT m_formatSrvStencil;
};
// Utility functions for binding multiple render targets
void BindRenderTargets(ID3D11DeviceContext * pCtx, RenderTarget * pRt, DepthStencilTarget * pDst);
void BindRenderTargets(ID3D11DeviceContext * pCtx, RenderTarget * pRt, DepthStencilTarget * pDst, box2 viewport);
void BindRenderTargets(ID3D11DeviceContext * pCtx, RenderTarget * pRt, DepthStencilTarget * pDst, box3 viewport);
// Helper functions for saving out screenshots of render targets
bool WriteRenderTargetToBMP(
ID3D11DeviceContext * pCtx,
RenderTarget * pRt,
const char * path);
}