-
Notifications
You must be signed in to change notification settings - Fork 1
/
TextureBuffer.h
100 lines (83 loc) · 1.76 KB
/
TextureBuffer.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
#pragma once
#include "globals.h"
#include "half.hpp"
using half_float::half;
#pragma pack(2)
/// <summary>
/// Screenshot header
/// This BMP head comes from
/// https://github.com/philkr/gamehook
/// </summary>
struct BMHead {
char magic[2] = { 'B', 'M' };
int size;
int _reserved = 0;
int offset = 0x36;
int hsize = 40;
int width, height;
short planes = 1;
short depth = 24;
int compression = 0;
int img_size = 0;
int rx = 0x03C3,
ry = 0x03C3;
int ncol = 0,
nimpcol = 0;
BMHead(int W, int H) :width(W), height(-H) {
int E = 4 - ((W * 3) % 4);
img_size = (3 * W + E) * H;
size = img_size + sizeof(BMHead);
}
};
/// <summary>
/// Depth file Header
/// </summary>
struct DEPTHHead {
char magic[2] = { 'D', 'P' };
int size;
int width;
int height;
float min_val;
float max_val;
short depth;
int offset = 28;
DEPTHHead(int W, int H, bool real_depth) : width(W), height(H), min_val(1.0f), max_val(0.0f)
{
int data_size = width * height * (real_depth ? 2 : 3);
size = data_size + sizeof(DEPTHHead);
depth = (real_depth ? 16 : 24);
magic[1] = (real_depth ? 'R' : 'P');
}
};
struct RealDepthData
{
half x;
half y;
half z;
half a;
};
#pragma pack()
class TextureBuffer
{
std::vector<uint8_t> data;
D3D11_TEXTURE2D_DESC desc;
ID3D11Texture2D* texture;
D3D11_MAPPED_SUBRESOURCE mappedRes;
void saveScreenshot(const char* fileName);
void saveDepth(const char* fileName);
void saveRealDepth(const char* fileName);
public:
enum Type
{
Color,
DepthBuffer,
RealDepthTexture,
Invalid
};
TextureBuffer::Type type;
bool valid;
TextureBuffer(ID3D11Device* pDevice, ID3D11DeviceContext* pDeviceContext, ID3D11Texture2D* origTexture, Type textureType);
~TextureBuffer();
void save(const char* fileName);
const size_t GetSize();
};