Skip to content

Commit d08aea1

Browse files
authored
Add support for cubemaps and skybox (#72)
* Add support for cubemaps and skybox Currently not set up to be used in a Scene: will need external resources first. * Add editor::FileBrowser - Rename `BrowseGltf` to `FileBrowser`. - Incorporate "*.skybox" into browsers and drops. - Use `string_view` for events. * Add operator""_B, FixedBitmap - Use `u` instead of `U` for unsigned literals. * Integrate Skybox and enable async loads - Remove increment logic from `MaybeFuture` and expose class in thread_pool.hpp. - Add `LoadFuture` with increment logic to gltf_loader.hpp. * Add zip_ranges - Use `zip_ranges()` instead of `enumerate()` for loading skybox data. - Remove enumerate.hpp from TUs where it's unused.
1 parent 581287a commit d08aea1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+674
-251
lines changed

CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,18 @@ if(FACADE_BUILD_EXE AND FACADE_BUILD_SHADERS)
3737
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/default.vert
3838
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/unlit.frag
3939
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/lit.frag
40+
${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/skybox.frag
4041

4142
OUTPUT
4243
${CMAKE_CURRENT_SOURCE_DIR}/src/bin/default_vert.spv.hpp
4344
${CMAKE_CURRENT_SOURCE_DIR}/src/bin/unlit_frag.spv.hpp
4445
${CMAKE_CURRENT_SOURCE_DIR}/src/bin/lit_frag.spv.hpp
46+
${CMAKE_CURRENT_SOURCE_DIR}/src/bin/skybox_frag.spv.hpp
4547

4648
COMMAND embed-shader ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/default.vert > ${CMAKE_CURRENT_SOURCE_DIR}/src/bin/default_vert.spv.hpp
4749
COMMAND embed-shader ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/unlit.frag > ${CMAKE_CURRENT_SOURCE_DIR}/src/bin/unlit_frag.spv.hpp
4850
COMMAND embed-shader ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/lit.frag > ${CMAKE_CURRENT_SOURCE_DIR}/src/bin/lit_frag.spv.hpp
51+
COMMAND embed-shader ${CMAKE_CURRENT_SOURCE_DIR}/src/shaders/skybox.frag > ${CMAKE_CURRENT_SOURCE_DIR}/src/bin/skybox_frag.spv.hpp
4952
)
5053
endif()
5154

lib/engine/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ target_sources(${PROJECT_NAME} PRIVATE
4343
include/${target_prefix}/engine/editor/browse_file.hpp
4444
include/${target_prefix}/engine/editor/common.hpp
4545
include/${target_prefix}/engine/editor/drag_drop_id.hpp
46+
include/${target_prefix}/engine/editor/file_browser.hpp
4647
include/${target_prefix}/engine/editor/inspector.hpp
4748
include/${target_prefix}/engine/editor/log.hpp
4849
include/${target_prefix}/engine/editor/reflector.hpp
@@ -54,6 +55,7 @@ target_sources(${PROJECT_NAME} PRIVATE
5455

5556
src/editor/browse_file.cpp
5657
src/editor/common.cpp
58+
src/editor/file_browser.cpp
5759
src/editor/inspector.cpp
5860
src/editor/log.cpp
5961
src/editor/reflector.cpp
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#pragma once
2+
#include <facade/engine/editor/browse_file.hpp>
3+
4+
namespace facade::editor {
5+
///
6+
/// \brief Persistent modal pop up to browse for a file given a list of extensions.
7+
///
8+
/// Uses Modal and BrowseFile.
9+
///
10+
class FileBrowser {
11+
public:
12+
struct Result {
13+
std::string selected{};
14+
std::string_view browse_path{};
15+
bool path_changed{};
16+
};
17+
18+
FileBrowser(std::string label, std::vector<std::string> extensions, std::string browse_path);
19+
20+
Result update(bool& out_trigger);
21+
22+
std::vector<std::string> extensions;
23+
24+
private:
25+
std::string m_browse_path;
26+
std::string m_label;
27+
std::vector<std::string_view> m_extensions_view{};
28+
env::DirEntries m_dir_entries{};
29+
bool m_trigger{};
30+
};
31+
} // namespace facade::editor

lib/engine/include/facade/engine/engine.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ class Engine {
8383
void request_stop();
8484

8585
///
86-
/// \brief Load a GLTF scene asynchronously.
86+
/// \brief Load a GLTF scene / Skybox asynchronously.
8787
///
8888
/// Subsequent requests will be rejected if one is in flight
8989
///
90-
bool load_async(std::string gltf_json_path, UniqueTask<void()> on_loaded = {});
90+
bool load_async(std::string json_path, UniqueTask<void()> on_loaded = {});
9191
///
9292
/// \brief Obtain status of in-flight async load request (if active).
9393
///

lib/engine/include/facade/engine/scene_renderer.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
#include <facade/vk/buffer.hpp>
55

66
namespace facade {
7+
class Skybox;
8+
79
class SceneRenderer {
810
public:
911
explicit SceneRenderer(Gfx const& gfx);
1012

11-
void render(Scene const& scene, Renderer& renderer, vk::CommandBuffer cb);
13+
void render(Scene const& scene, Ptr<Skybox const> skybox, Renderer& renderer, vk::CommandBuffer cb);
1214

1315
private:
1416
void write_view(glm::vec2 const extent);
1517
void update_view(Pipeline& out_pipeline) const;
16-
std::span<glm::mat4x4 const> make_instances(Node const& node, glm::mat4x4 const& parent);
18+
std::span<glm::mat4x4 const> make_instances(Node const& node, glm::mat4x4 const& parent) const;
1719

18-
void render(Renderer& renderer, vk::CommandBuffer cb, Node const& node, glm::mat4 const& parent = matrix_identity_v);
20+
void render(Renderer& renderer, vk::CommandBuffer cb, Skybox const& skybox) const;
21+
void render(Renderer& renderer, vk::CommandBuffer cb, Node const& node, glm::mat4 const& parent = matrix_identity_v) const;
1922

2023
Gfx m_gfx;
2124
Sampler m_sampler;
@@ -24,7 +27,7 @@ class SceneRenderer {
2427
Texture m_white;
2528
Texture m_black;
2629

27-
std::vector<glm::mat4x4> m_instance_mats{};
30+
mutable std::vector<glm::mat4x4> m_instance_mats{};
2831
Scene const* m_scene{};
2932
};
3033
} // namespace facade

lib/engine/src/editor/browse_file.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <imgui.h>
33
#include <facade/engine/editor/browse_file.hpp>
44
#include <facade/util/env.hpp>
5+
#include <facade/util/fixed_string.hpp>
56
#include <filesystem>
67

78
namespace facade::editor {
@@ -75,6 +76,16 @@ auto BrowseFile::operator()(NotClosed<Popup> popup, std::string& out_path) -> Re
7576
if (ImGui::Button("Downloads")) { cd(std::move(downloads)); }
7677
}
7778

79+
ImGui::Separator();
80+
auto exts = FixedString{};
81+
if (extensions.empty()) {
82+
exts = "*.*";
83+
} else {
84+
exts = FixedString{"*{}", extensions[0]};
85+
for (auto it = std::next(extensions.begin()); it != extensions.end(); ++it) { exts += FixedString{", *{}", *it}; }
86+
}
87+
ImGui::Text("%s", exts.c_str());
88+
7889
ImGui::Separator();
7990
if (auto window = editor::Window{popup, "File Tree"}) {
8091
env::GetDirEntries{.extensions = extensions}(out_entries, out_path.c_str());
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include <imgui.h>
2+
#include <facade/engine/editor/file_browser.hpp>
3+
4+
namespace facade::editor {
5+
FileBrowser::FileBrowser(std::string label, std::vector<std::string> extensions, std::string browse_path)
6+
: extensions(std::move(extensions)), m_browse_path(std::move(browse_path)), m_label(std::move(label)) {
7+
if (m_label.empty()) { m_label = "Browse..."; }
8+
}
9+
10+
auto FileBrowser::update(bool& out_trigger) -> Result {
11+
auto ret = Result{};
12+
if (out_trigger && !ImGui::IsPopupOpen(m_label.c_str())) { Modal::open(m_label.c_str()); }
13+
out_trigger = false;
14+
if (ImGui::IsPopupOpen(m_label.c_str())) { ImGui::SetNextWindowSize({400.0f, 250.0f}, ImGuiCond_FirstUseEver); }
15+
if (auto popup = Modal{m_label.c_str()}) {
16+
m_extensions_view.clear();
17+
m_extensions_view.reserve(extensions.size());
18+
for (auto const& extension : extensions) { m_extensions_view.push_back(extension); }
19+
auto [selected, changed] = BrowseFile{.out_entries = m_dir_entries, .extensions = m_extensions_view}(popup, m_browse_path);
20+
ret.path_changed = changed;
21+
ret.browse_path = m_browse_path;
22+
if (!selected.empty()) {
23+
popup.close_current();
24+
ret.selected = std::move(selected);
25+
}
26+
}
27+
return ret;
28+
}
29+
} // namespace facade::editor

lib/engine/src/editor/reflector.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
#include <imgui.h>
22
#include <facade/engine/editor/reflector.hpp>
3-
#include <facade/util/enumerate.hpp>
43
#include <facade/util/fixed_string.hpp>
54
#include <optional>
65

0 commit comments

Comments
 (0)