File include/jen/settings.h changed (mode: 100644) (index c24770b..7523f3f) |
1 |
1 |
#pragma once |
#pragma once |
2 |
2 |
#include "controls.h" |
#include "controls.h" |
3 |
|
#include <memory> |
|
|
3 |
|
#include "result.h" |
|
4 |
|
#include "configuration.h" |
4 |
5 |
|
|
5 |
6 |
namespace jen { |
namespace jen { |
6 |
7 |
struct ApplicationSettings; |
struct ApplicationSettings; |
7 |
8 |
struct ThreadPoolSettings; |
struct ThreadPoolSettings; |
8 |
9 |
struct WindowSettings; |
struct WindowSettings; |
|
10 |
|
#if JEN_MODULE_GRAPHICS |
9 |
11 |
struct GraphicsSettings; |
struct GraphicsSettings; |
|
12 |
|
#endif |
|
13 |
|
struct Window; |
10 |
14 |
|
|
11 |
15 |
namespace ModulesFlag { enum T : uint32_t { |
namespace ModulesFlag { enum T : uint32_t { |
12 |
16 |
COMPUTE = 1, |
COMPUTE = 1, |
|
... |
... |
struct jen::WindowSettings { |
45 |
49 |
const char *p_title_str; |
const char *p_title_str; |
46 |
50 |
}; |
}; |
47 |
51 |
|
|
|
52 |
|
#if JEN_MODULE_GRAPHICS |
48 |
53 |
struct jen::GraphicsSettings |
struct jen::GraphicsSettings |
49 |
54 |
{ |
{ |
50 |
|
struct DebugOverlay { |
|
51 |
|
bool is_enabled; |
|
52 |
|
bool is_visible; |
|
53 |
|
Key::Board toggle_key; |
|
54 |
|
const char *font_path; |
|
55 |
|
}; |
|
56 |
|
|
|
57 |
55 |
enum class Shading : uint32_t { |
enum class Shading : uint32_t { |
58 |
56 |
DEFAULT, |
DEFAULT, |
59 |
57 |
NO_LIGHTING, |
NO_LIGHTING, |
|
... |
... |
struct jen::GraphicsSettings |
62 |
60 |
DEBUG_CLUSTERS_NUM_LIGHTS, |
DEBUG_CLUSTERS_NUM_LIGHTS, |
63 |
61 |
COUNT |
COUNT |
64 |
62 |
}; |
}; |
65 |
|
|
|
66 |
|
enum class Filter : uint32_t { _1, _16, _25, _32, _64, _100, _128 }; |
|
67 |
|
struct Shadow { |
|
68 |
|
float bias = 0.05f; |
|
69 |
|
Filter pcss_search = Filter::_16; |
|
70 |
|
Filter pcf = Filter::_32; |
|
71 |
|
uint32_t extent = 512; |
|
|
63 |
|
enum class Filter : uint32_t { |
|
64 |
|
_1, _16, _25, _32, _64, _100, _128 |
72 |
65 |
}; |
}; |
73 |
|
|
|
74 |
66 |
enum class DrawMode : uint8_t { |
enum class DrawMode : uint8_t { |
75 |
67 |
DEFAULT, WIREFRAME, POINTS |
DEFAULT, WIREFRAME, POINTS |
76 |
68 |
}; |
}; |
|
... |
... |
struct jen::GraphicsSettings |
81 |
73 |
FRONT_AND_BACK = FRONT | BACK |
FRONT_AND_BACK = FRONT | BACK |
82 |
74 |
}; |
}; |
83 |
75 |
|
|
|
76 |
|
[[nodiscard]] bool update_from_input(Window *p_window); |
|
77 |
|
|
|
78 |
|
[[nodiscard]] bool operator ==(const GraphicsSettings& settings) const { |
|
79 |
|
return memcmp(this, &settings, sizeof(*this)) == 0; |
|
80 |
|
} |
|
81 |
|
[[nodiscard]] bool operator !=(const GraphicsSettings& settings) const { |
|
82 |
|
return not operator==(settings); |
|
83 |
|
} |
|
84 |
|
|
|
85 |
|
struct DebugOverlay { |
|
86 |
|
bool is_enabled; |
|
87 |
|
bool is_visible; |
|
88 |
|
Key::Board toggle_key; |
|
89 |
|
const char *font_path; |
|
90 |
|
}; |
|
91 |
|
struct Shadow { |
|
92 |
|
float bias = 0.05f; |
|
93 |
|
Filter pcss_search = Filter::_16; |
|
94 |
|
Filter pcf = Filter::_32; |
|
95 |
|
uint32_t extent = 512; |
|
96 |
|
}; |
|
97 |
|
|
84 |
98 |
Shading shading = Shading::DEFAULT; |
Shading shading = Shading::DEFAULT; |
85 |
99 |
Shadow shadows; |
Shadow shadows; |
86 |
100 |
DrawMode draw_mode; |
DrawMode draw_mode; |
|
... |
... |
struct jen::GraphicsSettings |
92 |
106 |
bool is_debug_normals_visible; |
bool is_debug_normals_visible; |
93 |
107 |
bool is_debug_depth_cube_visible; |
bool is_debug_depth_cube_visible; |
94 |
108 |
DebugOverlay debug_overlay; |
DebugOverlay debug_overlay; |
95 |
|
|
|
96 |
|
[[nodiscard]] bool operator ==(const GraphicsSettings& settings) const { |
|
97 |
|
return memcmp(this, &settings, sizeof(*this)) == 0; |
|
98 |
|
} |
|
99 |
|
[[nodiscard]] bool operator !=(const GraphicsSettings& settings) const { |
|
100 |
|
return not operator==(settings); |
|
101 |
|
} |
|
102 |
109 |
}; |
}; |
|
110 |
|
#endif |
103 |
111 |
|
|
104 |
112 |
struct jen::Settings { |
struct jen::Settings { |
105 |
113 |
constexpr void |
constexpr void |
|
... |
... |
struct jen::Settings { |
111 |
119 |
thread_pool.queue_indices.drawFrame = 0; |
thread_pool.queue_indices.drawFrame = 0; |
112 |
120 |
|
|
113 |
121 |
window.p_title_str = ""; |
window.p_title_str = ""; |
114 |
|
|
|
|
122 |
|
#if JEN_MODULE_GRAPHICS |
115 |
123 |
graphics.draw_mode = GraphicsSettings::DrawMode::DEFAULT; |
graphics.draw_mode = GraphicsSettings::DrawMode::DEFAULT; |
116 |
124 |
graphics.cull_mode = GraphicsSettings::CullMode::BACK; |
graphics.cull_mode = GraphicsSettings::CullMode::BACK; |
117 |
125 |
graphics.shading = GraphicsSettings::Shading::DEFAULT; |
graphics.shading = GraphicsSettings::Shading::DEFAULT; |
|
... |
... |
struct jen::Settings { |
130 |
138 |
graphics.debug_overlay.is_visible = false; |
graphics.debug_overlay.is_visible = false; |
131 |
139 |
graphics.debug_overlay.toggle_key = Key::Board::f1; |
graphics.debug_overlay.toggle_key = Key::Board::f1; |
132 |
140 |
graphics.debug_overlay.font_path = "fonts//IBMPlexMono.ttf"; |
graphics.debug_overlay.font_path = "fonts//IBMPlexMono.ttf"; |
|
141 |
|
#endif |
133 |
142 |
} |
} |
134 |
143 |
[[nodiscard]] constexpr static Settings |
[[nodiscard]] constexpr static Settings |
135 |
144 |
get_default(const ApplicationSettings &app_settings) { |
get_default(const ApplicationSettings &app_settings) { |
|
... |
... |
struct jen::Settings { |
141 |
150 |
ApplicationSettings application; |
ApplicationSettings application; |
142 |
151 |
ThreadPoolSettings thread_pool; |
ThreadPoolSettings thread_pool; |
143 |
152 |
WindowSettings window; |
WindowSettings window; |
|
153 |
|
#if JEN_MODULE_GRAPHICS |
144 |
154 |
GraphicsSettings graphics; |
GraphicsSettings graphics; |
|
155 |
|
#endif |
145 |
156 |
}; |
}; |
File src/graphics/graphics_interface.cpp changed (mode: 100644) (index f563e8e..3edca38) |
... |
... |
destroy(GpuTexture* p_gpuTexture, bool destroy_src) { |
142 |
142 |
p->destroyer << p_gpuTexture; |
p->destroyer << p_gpuTexture; |
143 |
143 |
} |
} |
144 |
144 |
|
|
145 |
|
[[nodiscard]] Result ModuleGraphics:: apply_settings() { |
|
146 |
|
return p->update_stages(); |
|
|
145 |
|
[[nodiscard]] Result ModuleGraphics:: |
|
146 |
|
apply_settings(const GraphicsSettings &settings) { |
|
147 |
|
if (p->settings != settings) { |
|
148 |
|
p->settings = settings; |
|
149 |
|
return p->update_stages(); |
|
150 |
|
} |
|
151 |
|
return VK_SUCCESS; |
147 |
152 |
} |
} |
148 |
153 |
|
|
149 |
154 |
jen::ResourceState jen::resource_state(const jen::GpuData * const p) { |
jen::ResourceState jen::resource_state(const jen::GpuData * const p) { |
|
... |
... |
bool call_key(Key::Board key, bool *p_pressed, const Window &input, Foo foo, |
198 |
203 |
return false; |
return false; |
199 |
204 |
} |
} |
200 |
205 |
|
|
201 |
|
[[nodiscard]] Result ModuleGraphics::update_settings_from_input() |
|
|
206 |
|
[[nodiscard]] bool GraphicsSettings:: |
|
207 |
|
update_from_input(Window *p_window) |
202 |
208 |
{ |
{ |
203 |
209 |
static bool is_f_pressed[Key::f12 - Key::f1 + 1]; |
static bool is_f_pressed[Key::f12 - Key::f1 + 1]; |
204 |
210 |
|
|
|
... |
... |
bool call_key(Key::Board key, bool *p_pressed, const Window &input, Foo foo, |
208 |
214 |
: Window::CursorMode::DISABLED); |
: Window::CursorMode::DISABLED); |
209 |
215 |
}; |
}; |
210 |
216 |
|
|
211 |
|
auto p_settings = &p->settings; |
|
212 |
|
|
|
213 |
|
auto polygon_mode = [p_settings]() { |
|
214 |
|
auto &pm = p_settings->draw_mode; |
|
|
217 |
|
auto polygon_mode = [this]() { |
|
218 |
|
auto &pm = draw_mode; |
215 |
219 |
pm = GraphicsSettings::DrawMode(int(pm) + 1); |
pm = GraphicsSettings::DrawMode(int(pm) + 1); |
216 |
220 |
if (pm > GraphicsSettings::DrawMode::POINTS) |
if (pm > GraphicsSettings::DrawMode::POINTS) |
217 |
221 |
pm = GraphicsSettings::DrawMode::DEFAULT; |
pm = GraphicsSettings::DrawMode::DEFAULT; |
218 |
222 |
}; |
}; |
219 |
|
auto cull_mode = [p_settings]() { |
|
|
223 |
|
auto cull_mode = [this]() { |
220 |
224 |
using CM = GraphicsSettings::CullMode; |
using CM = GraphicsSettings::CullMode; |
221 |
|
p_settings->cull_mode = p_settings->cull_mode == CM::NONE |
|
222 |
|
? CM::BACK : CM::NONE; |
|
|
225 |
|
this->cull_mode = this->cull_mode == CM::NONE ? CM::BACK : CM::NONE; |
223 |
226 |
}; |
}; |
224 |
|
auto light_mode = [p_settings]() { |
|
|
227 |
|
auto light_mode = [this]() { |
225 |
228 |
using Shading = jen::GraphicsSettings::Shading; |
using Shading = jen::GraphicsSettings::Shading; |
226 |
|
auto &s = p_settings->shading; |
|
|
229 |
|
auto &s = this->shading; |
227 |
230 |
s = Shading(int(s) + 1); |
s = Shading(int(s) + 1); |
228 |
231 |
if (s == Shading::COUNT) |
if (s == Shading::COUNT) |
229 |
232 |
s = Shading::DEFAULT; |
s = Shading::DEFAULT; |
230 |
233 |
}; |
}; |
231 |
|
auto multisampling_mode = [p_settings]() { |
|
232 |
|
auto &m = p_settings->multisampling; |
|
|
234 |
|
auto multisampling_mode = [this]() { |
|
235 |
|
auto &m = this->multisampling; |
233 |
236 |
m += m; |
m += m; |
234 |
237 |
if (m > 8) // TODO set as hardware limits |
if (m > 8) // TODO set as hardware limits |
235 |
238 |
m = 1; |
m = 1; |
|
... |
... |
bool call_key(Key::Board key, bool *p_pressed, const Window &input, Foo foo, |
243 |
246 |
}; |
}; |
244 |
247 |
auto toggle = [](bool *p_d) { *p_d = not *p_d; }; |
auto toggle = [](bool *p_d) { *p_d = not *p_d; }; |
245 |
248 |
|
|
246 |
|
auto &w = p->p_instance->window; |
|
|
249 |
|
auto &w = *p_window; |
247 |
250 |
bool changed = false; |
bool changed = false; |
248 |
|
call_key(p_settings->debug_overlay.toggle_key, |
|
249 |
|
is_f_pressed, w, toggle, |
|
250 |
|
&p_settings->debug_overlay.is_visible); |
|
|
251 |
|
call_key(debug_overlay.toggle_key, is_f_pressed, w, toggle, |
|
252 |
|
&debug_overlay.is_visible); |
251 |
253 |
call_key(Key::f2, is_f_pressed, w, cursor_mode, &w); |
call_key(Key::f2, is_f_pressed, w, cursor_mode, &w); |
252 |
254 |
changed |= call_key(Key::f3, is_f_pressed, w, toggle, |
changed |= call_key(Key::f3, is_f_pressed, w, toggle, |
253 |
|
&p_settings->is_debug_depth_cube_visible); |
|
|
255 |
|
&is_debug_depth_cube_visible); |
254 |
256 |
changed |= call_key(Key::f4, is_f_pressed, w, polygon_mode); |
changed |= call_key(Key::f4, is_f_pressed, w, polygon_mode); |
255 |
257 |
changed |= call_key(Key::f5, is_f_pressed, w, cull_mode); |
changed |= call_key(Key::f5, is_f_pressed, w, cull_mode); |
256 |
258 |
changed |= call_key(Key::f6, is_f_pressed, w, light_mode); |
changed |= call_key(Key::f6, is_f_pressed, w, light_mode); |
257 |
259 |
changed |= call_key(Key::f7, is_f_pressed, w, multisampling_mode); |
changed |= call_key(Key::f7, is_f_pressed, w, multisampling_mode); |
258 |
260 |
changed |= call_key(Key::f8, is_f_pressed, w, toggle, |
changed |= call_key(Key::f8, is_f_pressed, w, toggle, |
259 |
|
&p_settings->is_debug_normals_visible); |
|
|
261 |
|
&is_debug_normals_visible); |
260 |
262 |
changed |= call_key(Key::f9, is_f_pressed, w, toggle, |
changed |= call_key(Key::f9, is_f_pressed, w, toggle, |
261 |
|
&p_settings->wait_for_monitor); |
|
|
263 |
|
&wait_for_monitor); |
262 |
264 |
call_key(Key::f11, is_f_pressed, w, monitor_mode, &w); |
call_key(Key::f11, is_f_pressed, w, monitor_mode, &w); |
263 |
265 |
|
|
264 |
|
return changed ? apply_settings() : VK_SUCCESS; |
|
|
266 |
|
return changed; |
265 |
267 |
} |
} |
266 |
268 |
|
|
267 |
269 |
void ModuleGraphics::Loop:: |
void ModuleGraphics::Loop:: |