Elaztek Developer Hub
Blamite Game Engine - blam!  00453.06.08.26.0624.blamite
The core library for the Blamite Game Engine.
bgfx_config.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <bgfx/bgfx.h>
6 
10 
15 {
16 private:
17  bool debug_flag_wireframe = false;
18  bool debug_flag_profiler = false;
19  bool debug_flag_stats = false;
20  bool debug_flag_text = false;
21  bool debug_flag_ifh = false;
22 
23  bool clear_flag_color = true;
24  bool clear_flag_depth = true;
25  bool clear_flag_stencil = false;
26 
27  std::string msaa = "off"; // off, 2x, 4x, 8x, 16x
28  bool reset_vsync = false;
29  bool reset_max_anisotropy = false;
30  bool reset_flush_after_render = false;
31  bool reset_srgb_backbuffer = false;
32  bool reset_hdr10 = false;
33  bool reset_hidpi = false;
34  bool reset_depth_clamp = false;
35  bool reset_transparent_backbuffer = false;
36 
37  BlamVector4 color = BlamVector4();
38  BlamVector4 uv = BlamVector4();
39  BlamVector4 flags = BlamVector4();
40 
41  bool sf_write_r = true;
42  bool sf_write_g = true;
43  bool sf_write_b = true;
44  bool sf_write_a = true;
45  bool sf_write_z = true;
46 
47  std::string sf_cull_direction = "counter-clockwise";
48  std::string sf_blend_mode = "add";
49  std::string sf_depth_test = "less";
50 
51  bool sf_msaa = true;
52  bool sf_line_aa = false;
53  bool sf_conservative_raster = false;
54  bool sf_front_ccw = false;
55  bool sf_blend_independent = false;
56  bool sf_blend_alpha_to_coverage = false;
57 
58 public:
59  void Draw()
60  {
61  if (!show)
62  {
63  return;
64  }
65 
66  if (ImGui::Begin("bgfx Config", &show))
67  {
68  if (ImGui::CollapsingHeader(ENGINE_TEXT("bgfx_test_section_debug_flags_name").c_str()))
69  {
70  ImGui::Checkbox(ENGINE_TEXT("bgfx_debug_flag_wireframe_name").c_str(), &debug_flag_wireframe);
72  Blam::UI::ImGUI::Widgets::ShowHelpMarker(ENGINE_TEXT("bgfx_debug_flag_wireframe_help_text").c_str());
73 
74  ImGui::Checkbox(ENGINE_TEXT("bgfx_debug_flag_profiler_name").c_str(), &debug_flag_profiler);
76  Blam::UI::ImGUI::Widgets::ShowHelpMarker(ENGINE_TEXT("bgfx_debug_flag_profiler_help_text").c_str());
77 
78  ImGui::Checkbox(ENGINE_TEXT("bgfx_debug_flag_stats_name").c_str(), &debug_flag_stats);
80  Blam::UI::ImGUI::Widgets::ShowHelpMarker(ENGINE_TEXT("bgfx_debug_flag_stats_help_text").c_str());
81 
82  ImGui::Checkbox(ENGINE_TEXT("bgfx_debug_flag_text_name").c_str(), &debug_flag_text);
84  Blam::UI::ImGUI::Widgets::ShowHelpMarker(ENGINE_TEXT("bgfx_debug_flag_text_help_text").c_str());
85 
86  ImGui::Checkbox(ENGINE_TEXT("bgfx_debug_flag_ifh_name").c_str(), &debug_flag_ifh);
88  Blam::UI::ImGUI::Widgets::ShowHelpMarker(ENGINE_TEXT("bgfx_debug_flag_ifh_help_text").c_str());
89 
90 
91  uint32_t debug_flags = 0;
92 
93  if (debug_flag_wireframe) debug_flags += BGFX_DEBUG_WIREFRAME;
94  if (debug_flag_profiler) debug_flags += BGFX_DEBUG_PROFILER;
95  if (debug_flag_stats) debug_flags += BGFX_DEBUG_STATS;
96  if (debug_flag_text) debug_flags += BGFX_DEBUG_TEXT;
97  if (debug_flag_ifh) debug_flags += BGFX_DEBUG_IFH;
98 
99  bgfx::setDebug(debug_flags);
100  }
101 
102  if (ImGui::CollapsingHeader(ENGINE_TEXT("bgfx_test_section_view_clearing_flags_name").c_str()))
103  {
104  ImGui::Checkbox("clear color", &clear_flag_color);
105  ImGui::Checkbox("clear stencil", &clear_flag_stencil);
106  ImGui::Checkbox("clear depth", &clear_flag_depth);
107 
108  uint16_t clear_flags = 0;
109 
110  if (clear_flag_color) clear_flags += BGFX_CLEAR_COLOR;
111  if (clear_flag_stencil) clear_flags += BGFX_CLEAR_STENCIL;
112  if (clear_flag_depth) clear_flags += BGFX_CLEAR_DEPTH;
113 
115  }
116 
117  /*if (ImGui::CollapsingHeader(ENGINE_TEXT("bgfx_test_section_projection_name").c_str()))
118  {
119  ImGui::Text(ENGINE_TEXT("bgfx_projection_help_text").c_str());
120  }*/
121 
122  if (ImGui::CollapsingHeader("reset flags"))
123  {
124  ImGui::Text("hey");
125 
126  if (ImGui::BeginCombo("msaa", msaa.c_str()))
127  {
128  if (ImGui::Selectable("off")) msaa = "off";
129  if (ImGui::Selectable("2x")) msaa = "2x";
130  if (ImGui::Selectable("4x")) msaa = "4x";
131  if (ImGui::Selectable("8x")) msaa = "8x";
132  if (ImGui::Selectable("16x")) msaa = "16x";
133  ImGui::EndCombo();
134  }
135 
136  ImGui::Checkbox("vsync", &reset_vsync);
137  ImGui::Checkbox("max anisotropy", &reset_max_anisotropy);
138  ImGui::Checkbox("flush after render", &reset_flush_after_render);
139  ImGui::Checkbox("sRGB backbuffer", &reset_srgb_backbuffer);
140  ImGui::Checkbox("hdr10", &reset_hdr10);
141  ImGui::Checkbox("hidpi", &reset_hidpi);
142  ImGui::Checkbox("depth clamp", &reset_depth_clamp);
143  ImGui::Checkbox("transparent backbuffer", &reset_transparent_backbuffer);
144 
145  uint32_t reset_flags = 0;
146 
147  if (msaa == "2x")
148  {
149  reset_flags += BGFX_RESET_MSAA_X2;
150  }
151  else if (msaa == "4x")
152  {
153  reset_flags += BGFX_RESET_MSAA_X4;
154  }
155  else if (msaa == "8x")
156  {
157  reset_flags += BGFX_RESET_MSAA_X8;
158  }
159  else if (msaa == "16x")
160  {
161  reset_flags += BGFX_RESET_MSAA_X16;
162  }
163 
164  if (reset_vsync) reset_flags += BGFX_RESET_VSYNC;
165  if (reset_max_anisotropy) reset_flags += BGFX_RESET_MAXANISOTROPY;
166  if (reset_flush_after_render) reset_flags += BGFX_RESET_FLUSH_AFTER_RENDER;
167  if (reset_srgb_backbuffer) reset_flags += BGFX_RESET_SRGB_BACKBUFFER;
168  if (reset_hdr10) reset_flags += BGFX_RESET_HDR10;
169  if (reset_hidpi) reset_flags += BGFX_RESET_HIDPI;
170  if (reset_depth_clamp) reset_flags += BGFX_RESET_DEPTH_CLAMP;
171  if (reset_transparent_backbuffer) reset_flags += BGFX_RESET_TRANSPARENT_BACKBUFFER;
172 
174  }
175 
176  if (ImGui::CollapsingHeader("uniforms"))
177  {
178  bgfx::UniformHandle test_color_uniform = bgfx::createUniform("test_color_uniform", bgfx::UniformType::Vec4);
179  bgfx::UniformHandle test_uv_uniform = bgfx::createUniform("test_uv_uniform", bgfx::UniformType::Vec4);
180  bgfx::UniformHandle test_debug_flags = bgfx::createUniform("test_debug_flags", bgfx::UniformType::Vec4);
181 
182  ImGui::ColorEdit4("color", (float*)&color);
183  ImGui::DragFloat2("uv", (float*)&uv);
184 
185  ImGui::DragFloat("debug", (float*)&flags, 0.1f);
186 
187  bgfx::setUniform(test_color_uniform, &color);
188  bgfx::setUniform(test_uv_uniform, &uv);
189  bgfx::setUniform(test_debug_flags, &flags);
190  }
191 
192  if (ImGui::CollapsingHeader("2d state flags"))
193  {
194  ImGui::Checkbox("write r", &sf_write_r);
195  ImGui::Checkbox("write g", &sf_write_g);
196  ImGui::Checkbox("write b", &sf_write_b);
197  ImGui::Checkbox("write a", &sf_write_a);
198  ImGui::Checkbox("write z", &sf_write_z);
199 
200  if (ImGui::BeginCombo("cull direction", sf_cull_direction.c_str()))
201  {
202  if (ImGui::Selectable("clockwise (cw)")) sf_cull_direction = "clockwise";
203  if (ImGui::Selectable("counter-clockwise (ccw)")) sf_cull_direction = "counter-clockwise";
204  if (ImGui::Selectable("off (no culling)")) sf_cull_direction = "off";
205  ImGui::EndCombo();
206  }
207 
208  if (ImGui::BeginCombo("blend mode", sf_blend_mode.c_str()))
209  {
210  if (ImGui::Selectable("add")) sf_blend_mode = "add";
211  if (ImGui::Selectable("alpha")) sf_blend_mode = "alpha";
212  if (ImGui::Selectable("darken")) sf_blend_mode = "darken";
213  if (ImGui::Selectable("lighten")) sf_blend_mode = "lighten";
214  if (ImGui::Selectable("multiply")) sf_blend_mode = "multiply";
215  if (ImGui::Selectable("normal")) sf_blend_mode = "normal";
216  if (ImGui::Selectable("screen")) sf_blend_mode = "screen";
217  if (ImGui::Selectable("linear burn")) sf_blend_mode = "linear burn";
218  ImGui::EndCombo();
219  }
220 
221  if (ImGui::BeginCombo("depth test", sf_depth_test.c_str()))
222  {
223  if (ImGui::Selectable("less")) sf_depth_test = "less";
224  if (ImGui::Selectable("less or equal")) sf_depth_test = "less or equal";
225  if (ImGui::Selectable("equal")) sf_depth_test = "equal";
226  if (ImGui::Selectable("greater or equal")) sf_depth_test = "greater or equal";
227  if (ImGui::Selectable("greater")) sf_depth_test = "greater";
228  if (ImGui::Selectable("not equal")) sf_depth_test = "not equal";
229  if (ImGui::Selectable("never")) sf_depth_test = "never";
230  if (ImGui::Selectable("always")) sf_depth_test = "always";
231  ImGui::EndCombo();
232  }
233 
234  ImGui::Checkbox("msaa", &sf_msaa);
235  ImGui::Checkbox("line anti-aliasing", &sf_line_aa);
236  ImGui::Checkbox("conservative rasterization", &sf_conservative_raster);
237  ImGui::Checkbox("front counter-clockwise", &sf_front_ccw);
238  ImGui::Checkbox("blend independent", &sf_blend_independent);
239  ImGui::Checkbox("blend alpha-to-coverage", &sf_blend_alpha_to_coverage);
240 
241  uint64_t flags = 0;
242 
243  if (sf_cull_direction == "clockwise") flags |= BGFX_STATE_CULL_CW;
244  else if (sf_cull_direction == "counter-clockwise") flags |= BGFX_STATE_CULL_CCW;
245 
246  if (sf_write_r) flags |= BGFX_STATE_WRITE_R;
247  if (sf_write_g) flags |= BGFX_STATE_WRITE_G;
248  if (sf_write_b) flags |= BGFX_STATE_WRITE_B;
249  if (sf_write_a) flags |= BGFX_STATE_WRITE_A;
250  if (sf_write_z) flags |= BGFX_STATE_WRITE_Z;
251 
252  if (sf_blend_mode == "add") flags |= BGFX_STATE_BLEND_ADD;
253  else if (sf_blend_mode == "alpha") flags |= BGFX_STATE_BLEND_ALPHA;
254  else if (sf_blend_mode == "darken") flags |= BGFX_STATE_BLEND_DARKEN;
255  else if (sf_blend_mode == "lighten") flags |= BGFX_STATE_BLEND_LIGHTEN;
256  else if (sf_blend_mode == "multiply") flags |= BGFX_STATE_BLEND_MULTIPLY;
257  else if (sf_blend_mode == "normal") flags |= BGFX_STATE_BLEND_NORMAL;
258  else if (sf_blend_mode == "screen") flags |= BGFX_STATE_BLEND_SCREEN;
259  else if (sf_blend_mode == "linear burn") flags |= BGFX_STATE_BLEND_LINEAR_BURN;
260 
261  if (sf_depth_test == "less") flags |= BGFX_STATE_DEPTH_TEST_LESS;
262  else if (sf_depth_test == "less or equal") flags |= BGFX_STATE_DEPTH_TEST_LEQUAL;
263  else if (sf_depth_test == "equal") flags |= BGFX_STATE_DEPTH_TEST_EQUAL;
264  else if (sf_depth_test == "greater or equal") flags |= BGFX_STATE_DEPTH_TEST_GEQUAL;
265  else if (sf_depth_test == "greater") flags |= BGFX_STATE_DEPTH_TEST_GREATER;
266  else if (sf_depth_test == "not equal") flags |= BGFX_STATE_DEPTH_TEST_NOTEQUAL;
267  else if (sf_depth_test == "never") flags |= BGFX_STATE_DEPTH_TEST_NEVER;
268  else if (sf_depth_test == "always") flags |= BGFX_STATE_DEPTH_TEST_ALWAYS;
269 
270  if (sf_msaa) flags |= BGFX_STATE_MSAA;
271  if (sf_line_aa) flags |= BGFX_STATE_LINEAA;
272  if (sf_conservative_raster) flags |= BGFX_STATE_CONSERVATIVE_RASTER;
273  if (sf_front_ccw) flags |= BGFX_STATE_FRONT_CCW;
274  if (sf_blend_independent) flags |= BGFX_STATE_BLEND_INDEPENDENT;
275  if (sf_blend_alpha_to_coverage) flags |= BGFX_STATE_BLEND_ALPHA_TO_COVERAGE;
276 
278  }
279  }
280  ImGui::End();
281  }
282 };
color
BlamColor color
Typedef for a color field, used in tag definitions.
Definition: tags.h:447
ImGui::Checkbox
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition: imgui_widgets.cpp:974
BlamImGuiWindow::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: imgui.h:34
BlamImGuiWindow_BgfxConfig
Dialog used to configure bgfx debug, clear, and reset flags.
Definition: bgfx_config.hpp:14
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
engine_text.h
rendering.h
ImGui::SameLine
IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f)
Definition: imgui.cpp:7147
BlamImGuiWindow
Class representing an ImGUI window.
Definition: imgui.h:31
Blam::RenderingBGFX::SetViewClearFlags
BLAM void SetViewClearFlags(uint16_t flags)
Definition: bgfx.cpp:406
uint64_t
unsigned long long uint64_t
Definition: stdint.h:18
ImGui::DragFloat
IMGUI_API bool DragFloat(const char *label, float *v, float v_speed=1.0f, float v_min=0.0f, float v_max=0.0f, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2164
Blam::UI::ImGUI::Widgets::ShowHelpMarker
BLAM void ShowHelpMarker(const char *desc)
Shows a help indicator.
Definition: widgets.cpp:7
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
ImGui::DragFloat2
IMGUI_API bool DragFloat2(const char *label, float v[2], float v_speed=1.0f, float v_min=0.0f, float v_max=0.0f, const char *format="%.3f", float power=1.0f)
Definition: imgui_widgets.cpp:2169
ImGui::CollapsingHeader
IMGUI_API bool CollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0)
Definition: imgui_widgets.cpp:5422
widgets.h
ImGui::Text
IMGUI_API void Text(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:238
ImGui::BeginCombo
IMGUI_API bool BeginCombo(const char *label, const char *preview_value, ImGuiComboFlags flags=0)
Definition: imgui_widgets.cpp:1416
ImGui::Selectable
IMGUI_API bool Selectable(const char *label, bool selected=false, ImGuiSelectableFlags flags=0, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:5469
reset_flags
uint32_t reset_flags
Definition: bgfx.cpp:35
uint32_t
unsigned int uint32_t
Definition: stdint.h:17
ImGui::EndCombo
IMGUI_API void EndCombo()
Definition: imgui_widgets.cpp:1522
ImGui::ColorEdit4
IMGUI_API bool ColorEdit4(const char *label, float col[4], ImGuiColorEditFlags flags=0)
Definition: imgui_widgets.cpp:4154
ENGINE_TEXT
#define ENGINE_TEXT(string_id)
Definition: engine_text.h:7
imgui.h
Blam::RenderingBGFX::SetDefault2DStateFlags
BLAM void SetDefault2DStateFlags(uint64_t flags)
Definition: bgfx.cpp:438
Blam::RenderingBGFX::SetResetFlags
BLAM void SetResetFlags(uint32_t flags)
Definition: bgfx.cpp:412
uint16_t
unsigned short uint16_t
Definition: stdint.h:16
BlamImGuiWindow_BgfxConfig::Draw
void Draw()
Draws the contents of the group.
Definition: bgfx_config.hpp:59