Skip to content

Commit 8a1d4e1

Browse files
committed
Misc fixups
1 parent 2ab6165 commit 8a1d4e1

File tree

6 files changed

+75
-27
lines changed

6 files changed

+75
-27
lines changed

lib/engine/include/facade/engine/editor/common.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TreeNode : public Openable {
5050
explicit TreeNode(char const* label, int flags = {});
5151
~TreeNode();
5252

53-
static void leaf(char const* label, int flags = {});
53+
static bool leaf(char const* label, int flags = {});
5454
};
5555

5656
///

lib/engine/include/facade/engine/editor/scene_tree.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace editor {
1111
///
1212
/// \brief Target Node to inspect (driven by SceneTree)
1313
///
14-
struct Inspectee {
14+
struct InspectNode {
1515
FixedString<128> name{"[Node]###Node"};
1616
Id<Node> id{};
1717

@@ -30,7 +30,7 @@ class SceneTree : public Pinned {
3030
/// \param inout Used to highlight matching Node, and set to clicked Node, if any
3131
/// \returns true if inout changed during tree walk
3232
///
33-
bool render(NotClosed<Window>, Inspectee& inout) const;
33+
bool render(NotClosed<Window>, InspectNode& inout) const;
3434

3535
private:
3636
Scene& m_scene;

lib/engine/src/editor/common.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ TreeNode::~TreeNode() {
2525
if (m_open) { ImGui::TreePop(); }
2626
}
2727

28-
void TreeNode::leaf(char const* label, int flags) {
29-
if (auto tn = TreeNode{label, flags | ImGuiTreeNodeFlags_Leaf}) {}
28+
bool TreeNode::leaf(char const* label, int flags) {
29+
if (TreeNode{label, flags | ImGuiTreeNodeFlags_Leaf}) { return true; }
30+
return false;
3031
}
3132

3233
Window::Menu::Menu(NotClosed<Window>) : MenuBar(ImGui::BeginMenuBar()) {}

lib/engine/src/editor/scene_tree.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ FixedString<128> node_name(Node const& node) {
1111
return ret;
1212
}
1313

14-
Inspectee inspect(Node const& node) {
15-
auto ret = Inspectee{};
14+
InspectNode inspect(Node const& node) {
15+
auto ret = InspectNode{};
1616
ret.id = node.id();
1717
ret.name = node_name(node);
1818
ret.name += FixedString{"###Node"};
1919
return ret;
2020
}
2121

22-
void walk(Node& node, Inspectee& inout) {
22+
void walk(Node& node, InspectNode& inout) {
2323
auto flags = ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanAvailWidth;
2424
if (node.id() == inout.id) { flags |= ImGuiTreeNodeFlags_Selected; }
2525
if (node.children().empty()) { flags |= ImGuiTreeNodeFlags_Leaf; }
@@ -35,7 +35,7 @@ void walk(Node& node, Inspectee& inout) {
3535
}
3636
} // namespace
3737

38-
bool SceneTree::render(NotClosed<Window>, Inspectee& inout) const {
38+
bool SceneTree::render(NotClosed<Window>, InspectNode& inout) const {
3939
auto const in = inout.id;
4040
if (!m_scene.find(in)) { inout = {}; }
4141
for (auto& root : m_scene.roots()) { walk(root, inout); }

lib/util/include/facade/util/rgb.hpp

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,66 @@
33
#include <glm/vec4.hpp>
44

55
namespace facade {
6+
///
7+
/// \brief 3-channel colour with HDR support
8+
///
69
struct Rgb {
10+
///
11+
/// \brief 8-bit channels.
12+
///
713
glm::tvec3<std::uint8_t> channels{0xff, 0xff, 0xff};
14+
///
15+
/// \brief Intensity (> 1.0 == HDR).
16+
///
817
float intensity{1.0f};
918

19+
///
20+
/// \brief Convert an 8-bit channels to a normalized float.
21+
/// \param channel 8-bit channel
22+
/// \returns Normalized float
23+
///
1024
static constexpr float to_f32(std::uint8_t channel) { return static_cast<float>(channel) / static_cast<float>(0xff); }
11-
static constexpr float to_u8(float normalized) { return static_cast<std::uint8_t>(normalized * static_cast<float>(0xff)); }
25+
///
26+
/// \brief Convert a normalized float into an 8-bit channel.
27+
/// \param normalized Normalized float
28+
/// \returns 8-bit channel
29+
///
30+
static constexpr std::uint8_t to_u8(float normalized) { return static_cast<std::uint8_t>(normalized * static_cast<float>(0xff)); }
31+
///
32+
/// \brief Convert linear input to sRGB.
33+
/// \param linear 4 normalized floats encoded as linear
34+
/// \returns 4 normalized floats encoded as sRGB
35+
///
1236
static glm::vec4 to_srgb(glm::vec4 const& linear);
37+
///
38+
/// \brief Convert sRGB input to linear.
39+
/// \param srgb 4 normalized floats encoded as sRGB
40+
/// \returns 4 normalized floats encoded as linear
41+
///
1342
static glm::vec4 to_linear(glm::vec4 const& srgb);
1443

15-
static constexpr Rgb make(glm::vec3 const& serialized, float intensity = 1.0f) {
44+
///
45+
/// \brief Construct an Rgb instance using normalized input and intensity.
46+
/// \param normalized 3 channels of normalized [0-1] floats
47+
/// \param intensity Intensity of returned Rgb
48+
/// \returns Rgb instance
49+
///
50+
static constexpr Rgb make(glm::vec3 const& normalized, float intensity = 1.0f) {
1651
return {
17-
.channels = {to_u8(serialized.x), to_u8(serialized.y), to_u8(serialized.z)},
52+
.channels = {to_u8(normalized.x), to_u8(normalized.y), to_u8(normalized.z)},
1853
.intensity = intensity,
1954
};
2055
}
2156

57+
///
58+
/// \brief Convert instance to 3 channel normalized output.
59+
/// \returns 3 normalized floats
60+
///
2261
constexpr glm::vec3 to_vec3() const { return intensity * glm::vec3{to_f32(channels.x), to_f32(channels.y), to_f32(channels.z)}; }
62+
///
63+
/// \brief Convert instance to 4 channel normalized output.
64+
/// \returns 4 normalized floats
65+
///
2366
constexpr glm::vec4 to_vec4(float alpha = 1.0f) const { return {to_vec3(), alpha}; }
2467
};
2568
} // namespace facade

src/main.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ struct MainMenu {
123123

124124
struct {
125125
editor::Log log{};
126-
editor::Inspectee inspectee{};
126+
editor::InspectNode inspect{};
127127
Bool unified_scaling{true};
128128
} data{};
129129

@@ -146,15 +146,15 @@ struct MainMenu {
146146

147147
void inspector(Scene& scene) {
148148
bool show = true;
149-
ImGui::SetNextWindowSize({400.0f, 400.0f}, ImGuiCond_Once);
150-
if (auto window = editor::Window{data.inspectee.name.c_str(), &show}) {
151-
editor::SceneInspector{window, scene}.inspect(data.inspectee.id, data.unified_scaling);
149+
ImGui::SetNextWindowSize({400.0f, 400.0f}, ImGuiCond_FirstUseEver);
150+
if (auto window = editor::Window{data.inspect.name.c_str(), &show}) {
151+
editor::SceneInspector{window, scene}.inspect(data.inspect.id, data.unified_scaling);
152152
}
153-
if (!show) { data.inspectee = {}; }
153+
if (!show) { data.inspect = {}; }
154154
}
155155

156156
void stats(Engine const& engine, float const dt) {
157-
ImGui::SetNextWindowSize({250.0f, 200.0f}, ImGuiCond_Once);
157+
ImGui::SetNextWindowSize({250.0f, 200.0f}, ImGuiCond_FirstUseEver);
158158
if (auto window = editor::Window{"Frame Stats", &windows.stats}) {
159159
auto const& stats = engine.renderer().frame_stats();
160160
ImGui::Text("%s", FixedString{"Counter: {}", stats.frame_counter}.c_str());
@@ -171,17 +171,21 @@ struct MainMenu {
171171
}
172172

173173
void tree(Scene& scene) {
174-
ImGui::SetNextWindowSize({250.0f, 350.0f}, ImGuiCond_Once);
175-
if (auto window = editor::Window{"Scene", &windows.tree}) { editor::SceneTree{scene}.render(window, data.inspectee); }
174+
ImGui::SetNextWindowSize({250.0f, 350.0f}, ImGuiCond_FirstUseEver);
175+
if (auto window = editor::Window{"Scene", &windows.tree}) {
176+
if (ImGui::Button("Lights")) { windows.lights = true; }
177+
ImGui::Separator();
178+
editor::SceneTree{scene}.render(window, data.inspect);
179+
}
176180
}
177181

178-
void lights(Scene& scene) {
179-
ImGui::SetNextWindowSize({400.0f, 400.0f}, ImGuiCond_Once);
180-
if (auto window = editor::Window{"Lights", &windows.lights}) { editor::Inspector{window}.inspect(scene.lights); }
182+
void lights(Lights& lights) {
183+
ImGui::SetNextWindowSize({400.0f, 400.0f}, ImGuiCond_FirstUseEver);
184+
if (auto window = editor::Window{"Lights", &windows.lights}) { editor::Inspector{window}.inspect(lights); }
181185
}
182186

183187
void log() {
184-
ImGui::SetNextWindowSize({600.0f, 200.0f}, ImGuiCond_Once);
188+
ImGui::SetNextWindowSize({600.0f, 200.0f}, ImGuiCond_FirstUseEver);
185189
if (auto window = editor::Window{"Log", &windows.log}) { data.log.render(window); }
186190
}
187191

@@ -205,8 +209,8 @@ struct MainMenu {
205209
}
206210

207211
if (windows.tree) { tree(engine.scene()); }
208-
if (windows.lights) { lights(engine.scene()); }
209-
if (data.inspectee) { inspector(engine.scene()); }
212+
if (windows.lights) { lights(engine.scene().lights); }
213+
if (data.inspect) { inspector(engine.scene()); }
210214
if (windows.stats) { stats(engine, dt); }
211215
if (windows.log) { log(); }
212216
if (windows.imgui_demo) { ImGui::ShowDemoWindow(&windows.imgui_demo); }
@@ -248,7 +252,7 @@ void run() {
248252
auto material = std::make_unique<LitMaterial>();
249253
material->albedo = {1.0f, 0.0f, 0.0f};
250254
material_id = scene.add(std::move(material));
251-
auto static_mesh_id = scene.add(make_manipulator(0.125f, 1.0f, 16));
255+
auto static_mesh_id = scene.add(make_cubed_sphere(1.0f, 32));
252256
auto mesh_id = scene.add(Mesh{.primitives = {Mesh::Primitive{static_mesh_id, material_id}}});
253257

254258
auto node = Node{};

0 commit comments

Comments
 (0)