-
Notifications
You must be signed in to change notification settings - Fork 1
/
gdi.h
107 lines (94 loc) · 2.39 KB
/
gdi.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
#pragma once
#include "general_headers.h"
namespace deleters
{
void bitmap_deleter(HBITMAP* pbitmap);
void dc_deleter(HDC* hdc);
using pbmp_deleter_type = decltype(bitmap_deleter)*;
using pdc_deleter_type = decltype(dc_deleter)*;
}
struct coords
{
double x{ 0 }, y{ 0 }, z{ 0 };
};
struct point
{
double x{ 0 }, y{ 0 };
};
class safe_bitmap
{
public:
safe_bitmap(const HBITMAP bmp);
safe_bitmap() = default;
safe_bitmap(const safe_bitmap& rhs);
~safe_bitmap();
void reset(const HBITMAP bmp = NULL);
void release();
operator HBITMAP()const;
HBITMAP get()const;
operator bool() const;
private:
HBITMAP _bitmap{ NULL };
int* _ref{ nullptr };
};
//cannot be used with GetDC
class safe_dc
{
public:
safe_dc(const HDC hdc);
safe_dc() = default;
safe_dc(safe_dc& rhs);
~safe_dc();
void reset(const HDC hdc = NULL);
void release();
operator HDC()const;
HDC get()const;
operator bool()const;
private:
HDC _dc{ NULL };
int* _ref{ nullptr };
};
class bitmap_guard
{
public:
bitmap_guard(HBITMAP* pbitmap);
private:
std::unique_ptr<HBITMAP, deleters::pbmp_deleter_type> _manager;
};
class created_dc_guard
{
public:
created_dc_guard(HDC* hdc);
private:
std::unique_ptr<HDC, deleters::pdc_deleter_type> _manager;
};
struct scene_states
{
DirectX::XMMATRIX world{ DirectX::XMMatrixIdentity() };
DirectX::XMVECTOR light{ 0.2013022f,0.9101138f,-0.3621709f,0.0f };
};
class vxl_gdi_renderer
{
public:
constexpr static const size_t bitmap_width = 256;
constexpr static const size_t bitmap_height = 256;
constexpr static const size_t bitmap_bpp = 32;
constexpr static const size_t bitmap_pitch = ((bitmap_width * bitmap_bpp + 31) & ~31) / 8;
vxl_gdi_renderer() = default;
~vxl_gdi_renderer() = default;
bool initialize(HWND hwnd_for_dc);
bool valid()const;
bool clear_vxl_canvas(const RGBQUAD& fill_color);
bool render_vxl(const class vxl& vxl, const class hva& hva, const class palette& palette, const class vpl& vpl,const size_t frame);
bool copy_result(HDC target);
void set_world(const DirectX::XMMATRIX& world);
void set_light_dir(const DirectX::XMVECTOR& dir);
DirectX::XMMATRIX get_world()const;
DirectX::XMVECTOR get_light_dir()const;
private:
safe_bitmap _canvas;
safe_dc _hdc;
void* _surface_buffer{ 0 };
std::unique_ptr<double[][bitmap_width]> _zbuffer;
scene_states _states;
};