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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
pub mod os;
pub mod gfx;
pub mod av;
pub mod image;
pub mod imgui;
pub mod imdraw;
pub mod pmfx;
pub mod primitives;
#[macro_use]
extern crate bitflags;
pub struct Error {
pub msg: String,
}
impl std::fmt::Debug for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.msg)
}
}
#[cfg(target_os = "windows")]
impl From<windows::core::Error> for Error {
fn from(err: windows::core::Error) -> Error {
Error {
msg: err.message().to_string_lossy(),
}
}
}
impl From<std::io::Error> for Error {
fn from(err: std::io::Error) -> Error {
Error {
msg: err.to_string()
}
}
}
pub struct HotlineInfo {
pub name: String,
pub window_rect: os::Rect<i32>,
pub dpi_aware: bool,
pub clear_colour: Option<gfx::ClearColour>,
pub adapter_name: Option<String>,
pub num_buffers: u32,
pub shader_heap_size: usize,
pub render_target_heap_size: usize,
pub depth_stencil_heap_size: usize
}
impl Default for HotlineInfo {
fn default() -> Self {
HotlineInfo {
name: "hotline".to_string(),
window_rect: os::Rect {
x: 100,
y: 100,
width: 1280,
height: 720
},
dpi_aware: true,
clear_colour: Some(gfx::ClearColour {
r: 0.45,
g: 0.55,
b: 0.60,
a: 1.00,
}),
num_buffers: 2,
adapter_name: None,
shader_heap_size: 1024,
render_target_heap_size: 128,
depth_stencil_heap_size: 64
}
}
}
pub struct Context<D: gfx::Device, A: os::App> {
pub app: A,
pub device: D,
pub main_window: A::Window,
pub swap_chain: D::SwapChain,
pub pmfx: pmfx::Pmfx<D>,
pub cmd_buf: D::CmdBuf,
pub imdraw: imdraw::ImDraw<D>
}
impl<D, A> Context<D, A> where D: gfx::Device, A: os::App {
pub fn create(info: HotlineInfo) -> Result<Self, Error> {
let mut app = A::create(os::AppInfo {
name: info.name.to_string(),
num_buffers: info.num_buffers,
dpi_aware: info.dpi_aware,
window: false,
});
let mut device = D::create(&gfx::DeviceInfo {
adapter_name: info.adapter_name,
shader_heap_size: info.shader_heap_size,
render_target_heap_size: info.render_target_heap_size,
depth_stencil_heap_size: info.depth_stencil_heap_size,
});
let window = app.create_window(os::WindowInfo {
title: info.name.to_string(),
rect: info.window_rect,
style: os::WindowStyleFlags::NONE,
parent_handle: None,
});
let swap_chain_info = gfx::SwapChainInfo {
num_buffers: info.num_buffers as u32,
format: gfx::Format::RGBA8n,
clear_colour: info.clear_colour
};
let swap_chain = device.create_swap_chain::<A>(&swap_chain_info, &window)?;
let cmd_buf = device.create_cmd_buf(info.num_buffers );
let imdraw_info = imdraw::ImDrawInfo {
initial_buffer_size_2d: 1024,
initial_buffer_size_3d: 1024
};
let imdraw : imdraw::ImDraw<D> = imdraw::ImDraw::create(&imdraw_info).unwrap();
Ok(Context {
app,
device,
main_window: window,
swap_chain,
cmd_buf,
pmfx: pmfx::Pmfx::create(),
imdraw
})
}
pub fn new_frame(&mut self) {
}
pub fn swap_buffers(&mut self) {
}
}