From 667a23ecb2ab2a992f38ba8c1a2eedbc6fa181d5 Mon Sep 17 00:00:00 2001 From: lachrymaLF Date: Sun, 9 Jun 2024 21:01:19 -0400 Subject: [PATCH] resource manager init --- Keishiki/CMakeLists.txt | 6 +- Keishiki/Graphics.cpp | 106 +++++------------------------------ Keishiki/Keishiki.cpp | 6 +- Keishiki/Resource.cpp | 107 ++++++++++++++++++++++++++++++++++++ Keishiki/ShaderGraph.cpp | 18 +++--- Keishiki/UI.cpp | 35 +++++++++--- Keishiki/VisualTrack.cpp | 6 +- Keishiki/include/Common.h | 6 +- Keishiki/include/Graphics.h | 17 ++---- Keishiki/include/Resource.h | 74 +++++++++++++++++++++++++ README.md | 4 ++ TODO.md | 16 +++--- 12 files changed, 263 insertions(+), 138 deletions(-) create mode 100644 Keishiki/Resource.cpp create mode 100644 Keishiki/include/Resource.h diff --git a/Keishiki/CMakeLists.txt b/Keishiki/CMakeLists.txt index 6682fd6..a0c5f0c 100644 --- a/Keishiki/CMakeLists.txt +++ b/Keishiki/CMakeLists.txt @@ -23,14 +23,16 @@ add_subdirectory("ext/bgfx") add_compile_definitions(IMGUI_DEFINE_MATH_OPERATORS) -# Disable RTTI +# Disable RTTI and exceptions if(MSVC) string(REGEX REPLACE "/GR" "/GR-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") + string(REGEX REPLACE "/EHsc" "/EHs-c-" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}") else() - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fno-rtti -fno-exceptions") endif() + if (WIN32) include_directories("include/windows") target_link_libraries (Keishiki PRIVATE freetype bgfx bx ${PROJECT_SOURCE_DIR}/lib/x64/SDL2.lib ${PROJECT_SOURCE_DIR}/lib/x64/SDL2main.lib) diff --git a/Keishiki/Graphics.cpp b/Keishiki/Graphics.cpp index 3ad0ca1..0ae6224 100644 --- a/Keishiki/Graphics.cpp +++ b/Keishiki/Graphics.cpp @@ -1,4 +1,5 @@ #include "Graphics.h" +#include #include #include FT_FREETYPE_H @@ -12,37 +13,6 @@ #include namespace { - bgfx::ShaderHandle LoadShader(const std::string& FILENAME) { - std::string shaderPath{}; - - switch (bgfx::getRendererType()) { - case bgfx::RendererType::Noop: - case bgfx::RendererType::Direct3D11: - case bgfx::RendererType::Direct3D12: shaderPath = "shaders/dx11/"; break; - case bgfx::RendererType::Gnm: shaderPath = "shaders/pssl/"; break; - case bgfx::RendererType::Metal: shaderPath = "shaders/metal/"; break; - case bgfx::RendererType::OpenGL: shaderPath = "shaders/glsl/"; break; - case bgfx::RendererType::OpenGLES: shaderPath = "shaders/essl/"; break; - case bgfx::RendererType::Vulkan: shaderPath = "shaders/spirv/"; break; - default: K::LogError("Unsupported renderer"); break; - } - - - std::string filePath = shaderPath + FILENAME; - - FILE *file = fopen(filePath.c_str(), "rb"); - fseek(file, 0, SEEK_END); - long fileSize = ftell(file); - fseek(file, 0, SEEK_SET); - - const bgfx::Memory *mem = bgfx::alloc(fileSize + 1); - fread(mem->data, 1, fileSize, file); - mem->data[mem->size - 1] = '\0'; - fclose(file); - - return bgfx::createShader(mem); - } - struct PosUVVertex { f32 x; f32 y; @@ -150,34 +120,9 @@ namespace { } } - std::optional GetImageTexture(const std::string& file) { - K::Graphics::ImageTexture i; - i.buffer = stbi_load(file.c_str(), &i.w, &i.h, &i.channels, 0); - if (i.buffer == NULL) { - K::LogError("ADV: STB IMAGE loading failed for " + file); - return std::nullopt; - } - const bgfx::Memory *buf = bgfx::makeRef(i.buffer, i.w * i.h * i.channels * sizeof(u8)); - i.tx = bgfx::createTexture2D( - i.w, - i.h, - false, - 1, - i.channels == 4 ? bgfx::TextureFormat::RGBA8 : bgfx::TextureFormat::RGB8, - BGFX_TEXTURE_NONE | BGFX_SAMPLER_UVW_CLAMP, - buf - ); - return i; - } - - void DestroyImageTexture(K::Graphics::ImageTexture& i) { - stbi_image_free(i.buffer); - bgfx::destroy(i.tx); - } - Font regular, bold; - bgfx::ProgramHandle imga_program; - bgfx::ProgramHandle a_program; + const K::Resource::Resource *imga_program; + const K::Resource::Resource *a_program; bgfx::UniformHandle s_texColor; bgfx::UniformHandle imga_opacity; @@ -186,19 +131,13 @@ namespace { bgfx::VertexBufferHandle vbh; bgfx::VertexLayout pcvDecl; - K::Dict imgs; - f32 composite_view[16]; bgfx::UniformHandle composite_A, composite_B, composite_mode; - bgfx::ProgramHandle composite_pg; + const K::Resource::Resource *composite_pg; } namespace K::Graphics { - Graphics::ImageTexture *mmaker; - - bgfx::ProgramHandle load_shader_program(const std::string& FILENAME) { - return bgfx::createProgram(LoadShader(FILENAME + ".vert.bin"), LoadShader(FILENAME + ".frag.bin"), true); - }; + const Resource::Resource *mmaker; bool Init(u16 width, u16 height) { error = FT_Init_FreeType(&library); @@ -217,17 +156,17 @@ namespace K::Graphics { ibh = bgfx::createIndexBuffer(bgfx::makeRef(quad_indices, sizeof(quad_indices))); vbh = bgfx::createVertexBuffer(bgfx::makeRef(quad_vert, sizeof(quad_vert)), pcvDecl); - imga_program = load_shader_program("ImageAlpha"); // RGBA + Opacity - a_program = load_shader_program("AlphaStencil"); // A -> FFFA + imga_program = Resource::LoadShaderProgram("ImageAlpha"); // RGBA + Opacity + a_program = Resource::LoadShaderProgram("AlphaStencil"); // A -> FFFA imga_opacity = bgfx::createUniform("f_opacity", bgfx::UniformType::Vec4); // x -> alpha, yzw are dummies s_texColor = bgfx::createUniform("s_texColor", bgfx::UniformType::Sampler); - mmaker = Graphics::GetImageTextureFromFile("mmaker.png"); + mmaker = Resource::LoadStill("mmaker.png"); bx::mtxTranslate(composite_view, 0.f, 0.f, 1.0f); composite_A = bgfx::createUniform("s_A", bgfx::UniformType::Sampler); composite_B = bgfx::createUniform("s_B", bgfx::UniformType::Sampler); - composite_pg = load_shader_program("BinaryComposite"); + composite_pg = Resource::LoadShaderProgram("BinaryComposite"); composite_mode = bgfx::createUniform("u_mode", bgfx::UniformType::Vec4); return true; @@ -238,12 +177,6 @@ namespace K::Graphics { DestroyFont(bold); FT_Done_FreeType(library); - for (auto& img : imgs) { - DestroyImageTexture(img.second); - } - - bgfx::destroy(a_program); - bgfx::destroy(imga_program); bgfx::destroy(ibh); bgfx::destroy(vbh); @@ -253,7 +186,6 @@ namespace K::Graphics { bgfx::destroy(composite_A); bgfx::destroy(composite_B); - bgfx::destroy(composite_pg); bgfx::destroy(composite_mode); } @@ -279,27 +211,15 @@ namespace K::Graphics { DrawTextureWithTransform(view_id, tex, mtx3, state, pg); } - void DrawTextureImageAlpha(u32 view_id, const ImageTexture& img, i32 pos_x, i32 pos_y, f32 alpha) { + void DrawTextureImageAlpha(u32 view_id, const Resource::Resource& img, i32 pos_x, i32 pos_y, f32 alpha) { static f32 pack[4]{}; pack[0] = alpha; bgfx::setUniform(imga_opacity, pack); - DrawTexture(view_id, img.tx, pos_x, pos_y, img.w, img.h, (BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), imga_program); - } - - ImageTexture *GetImageTextureFromFile(const std::string& file) { - if (imgs.find(file) == imgs.end()) { - if (auto i = GetImageTexture(file)) { - imgs[file] = *i; - return &imgs[file]; - } - else return nullptr; - } - else - return &imgs[file]; + DrawTexture(view_id, img.tex, pos_x, pos_y, img.w, img.h, (BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), imga_program->pg); } void DrawTextureStencilAlpha(u32 view_id, const bgfx::TextureHandle& tex, i32 pos_x, i32 pos_y, u32 w, u32 h) { - DrawTexture(view_id, tex, pos_x, pos_y, w, h, (BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), a_program); + DrawTexture(view_id, tex, pos_x, pos_y, w, h, (BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), a_program->pg); } void WalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y) { @@ -444,7 +364,7 @@ namespace K::Graphics { bgfx::setTexture(1, composite_B, composite); // B bgfx::setUniform(composite_mode, pack); // A over B bgfx::setState(BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A); - bgfx::submit(view_id, composite_pg); + bgfx::submit(view_id, composite_pg->pg); } f64 GetCubicUniqueReal(f64 a, f64 b, f64 c, f64 d) { diff --git a/Keishiki/Keishiki.cpp b/Keishiki/Keishiki.cpp index 5c69be6..27b9168 100644 --- a/Keishiki/Keishiki.cpp +++ b/Keishiki/Keishiki.cpp @@ -14,7 +14,7 @@ namespace { K::CompState state; - K::Graphics::ImageTexture *logo; + const K::Resource::Resource *logo; } namespace K { @@ -86,6 +86,7 @@ namespace K { bx::mtxOrtho(proj, 0.0f, app_state.window_width, 0.0f, app_state.window_height, 0.1f, 100.0f, 0.f, bgfx::getCaps()->homogeneousDepth); bgfx::setViewTransform(K::Graphics::K_VIEW_LOGO, view, proj); + K::Resource::Init(); K::UI::Init(app_state.window); if (!K::Graphics::Init(app_state.window_width, app_state.window_height)) { @@ -93,7 +94,7 @@ namespace K { return false; } - logo = K::Graphics::GetImageTextureFromFile("Keishiki.png"); + logo = K::Resource::LoadStill("Keishiki.png"); state.width = 1280; state.height = 550; @@ -169,6 +170,7 @@ namespace K { void Shutdown() { K::Graphics::Shutdown(); K::UI::Shutdown(state); + K::Resource::Shutdown(); bgfx::shutdown(); SDL_DestroyWindow(app_state.window); SDL_Quit(); diff --git a/Keishiki/Resource.cpp b/Keishiki/Resource.cpp new file mode 100644 index 0000000..a49dd5d --- /dev/null +++ b/Keishiki/Resource.cpp @@ -0,0 +1,107 @@ +#include +#include + +namespace { + std::filesystem::path shader_path{}; +} + +namespace K::Resource { + Dict, + Resource, + Resource, + Resource, + Resource + >> resources{}; + + std::filesystem::path ffmpeg_path = "ffmpeg"; + + Resource *LoadStill(const std::filesystem::path& file) { + Resource res{}; + res.buf = stbi_load(file.c_str(), &res.w, &res.h, &res.channels, 0); + if (res.buf == nullptr) { + K::LogError("Image loading failed for " + file.string()); + return nullptr; + } + const bgfx::Memory *ref = bgfx::makeRef(res.buf, res.w * res.h * res.channels * sizeof(u8)); + res.format = res.channels == 4 ? bgfx::TextureFormat::RGBA8 : bgfx::TextureFormat::RGB8; + res.tex = bgfx::createTexture2D( + res.w, + res.h, + false, + 1, + res.format, + BGFX_TEXTURE_NONE | BGFX_SAMPLER_UVW_CLAMP, + ref); + auto [it, check] = resources.emplace(file, res); + return &std::get>(it->second); + } + + bgfx::ShaderHandle LoadShader(const std::filesystem::path& file_path) { + FILE *file = fopen(file_path.c_str(), "rb"); + fseek(file, 0, SEEK_END); + long fileSize = ftell(file); + fseek(file, 0, SEEK_SET); + + const bgfx::Memory *mem = bgfx::alloc(fileSize + 1); + fread(mem->data, 1, fileSize, file); + mem->data[mem->size - 1] = '\0'; + fclose(file); + + return bgfx::createShader(mem); + } + + Resource *LoadShaderProgram(const String& shader_name) { + const auto frag = shader_path / (shader_name + ".frag.bin"), + vert = shader_path / (shader_name + ".vert.bin"); + auto [iter, check] = resources.emplace(shader_name, Resource{ + .frag_last_updated = std::filesystem::last_write_time(frag), + .pg = bgfx::createProgram(LoadShader(vert), LoadShader(frag), true) + }); + return &std::get>(iter->second); + } + + /* Leave caller responsible for managing the returned handle */ + bgfx::ProgramHandle FetchUnmanagedShaderProgram(const String& shader_name) { + const auto frag = shader_path / (shader_name + ".frag.bin"), + vert = shader_path / (shader_name + ".vert.bin"); + return bgfx::createProgram(LoadShader(vert), LoadShader(frag), true); + } + + void Init() { + switch (bgfx::getRendererType()) { + case bgfx::RendererType::Noop: + case bgfx::RendererType::Direct3D11: + case bgfx::RendererType::Direct3D12: shader_path = "shaders/dx11/"; break; + case bgfx::RendererType::Gnm: shader_path = "shaders/pssl/"; break; + case bgfx::RendererType::Metal: shader_path = "shaders/metal/"; break; + case bgfx::RendererType::OpenGL: shader_path = "shaders/glsl/"; break; + case bgfx::RendererType::OpenGLES: shader_path = "shaders/essl/"; break; + case bgfx::RendererType::Vulkan: shader_path = "shaders/spirv/"; break; + default: K::LogError("Unsupported renderer"); + } + } + + void Shutdown() { + for (auto& r : resources) + std::visit([](auto&& arg){ + using T = std::decay_t; + if constexpr (std::is_same_v>) { + bgfx::destroy(arg.tex); + stbi_image_free(arg.buf); + } + else if constexpr (std::is_same_v>) { + bgfx::destroy(arg.pg); + } + else if constexpr (std::is_same_v>) { + + } + else if constexpr (std::is_same_v>) { + + } + else if constexpr (std::is_same_v>) { + + } + }, r.second); + } +} \ No newline at end of file diff --git a/Keishiki/ShaderGraph.cpp b/Keishiki/ShaderGraph.cpp index 54e5207..2124069 100644 --- a/Keishiki/ShaderGraph.cpp +++ b/Keishiki/ShaderGraph.cpp @@ -1,17 +1,17 @@ #include -#include "srell.hpp" +//#include "srell.hpp" namespace { K::String BuildNode(const K::ShaderGraph::NodeInstance& n) { K::String r = n.node->shader_template; - for (u32 i = 0; i < n.node->inputs.size(); i++) { - K::String sub{}; - if (n.inputs[i] != nullptr) - sub = BuildNode(*n.inputs[i]); - else - sub = K::ShaderGraph::VarToString(n.values[i]); // should be made into uniform instead !! - r = srell::regex_replace(r, srell::regex("\\{" + std::to_string(i) + "\\}"), sub); - } +// for (u32 i = 0; i < n.node->inputs.size(); i++) { +// K::String sub{}; +// if (n.inputs[i] != nullptr) +// sub = BuildNode(*n.inputs[i]); +// else +// sub = K::ShaderGraph::VarToString(n.values[i]); // should be made into uniform instead !! +// r = srell::regex_replace(r, srell::regex("\\{" + std::to_string(i) + "\\}"), sub); +// } return r; } } diff --git a/Keishiki/UI.cpp b/Keishiki/UI.cpp index c7978ce..2936b4c 100644 --- a/Keishiki/UI.cpp +++ b/Keishiki/UI.cpp @@ -140,8 +140,6 @@ namespace K::UI { save = bgfx::createTexture2D(s.width, s.height, false, 1, bgfx::TextureFormat::RGBA8, BGFX_TEXTURE_READ_BACK | BGFX_TEXTURE_BLIT_DST); save_buffer = static_cast(std::malloc(s.width * s.height * 4)); - bg.pg = K::Graphics::load_shader_program("Checkerboard"); - bg.add_uniform("f_hw", ShaderGraph::Type::T_XYZ); bg.uniforms.begin()->second.val = ShaderGraph::XYZ{ static_cast(s.width), static_cast(s.height), 0.0f }; bx::mtxOrtho(proj, 0.0f, static_cast(s.width), 0.0f, static_cast(s.height), @@ -164,10 +162,6 @@ namespace K::UI { bgfx::destroy(save); std::free(save_buffer); - bgfx::destroy(bg.pg); - bgfx::destroy(bg.uniforms.begin()->second.handle); - bg.uniforms.erase(bg.uniforms.begin()); - for (auto& layer : s.layers) layer.track.clear(); } @@ -1311,7 +1305,28 @@ namespace K::UI { void Assets(CompState& s) { if (ImGui::Begin("Assets", &draw_assets)) { - ImGui::Text("mmoker"); + for (auto& r : Resource::resources) { + std::visit([](auto&& arg){ + using T = std::decay_t; + if constexpr (std::is_same_v>) { + ImGui::Text("Still"); + } + else if constexpr (std::is_same_v>) { + ImGui::Text("Shader"); + } + else if constexpr (std::is_same_v>) { + ImGui::Text("Sequence"); + } + else if constexpr (std::is_same_v>) { + ImGui::Text("Video"); + } + else if constexpr (std::is_same_v>) { + ImGui::Text("Audio"); + } + }, r.second); + ImGui::SameLine(); + ImGui::Text("%s", r.first.c_str()); + } } ImGui::End(); } @@ -1369,9 +1384,15 @@ namespace K::UI { default: LogError("Unsupported Renderer"); } + + bg.pg = Resource::LoadShaderProgram("Checkerboard")->pg; + bg.add_uniform("f_hw", ShaderGraph::Type::T_XYZ); } void Shutdown(CompState& s) { + bgfx::destroy(bg.uniforms.begin()->second.handle); + bg.uniforms.erase(bg.uniforms.begin()); + DestroyViewport(s); ImGui_Implbgfx_Shutdown(); ImGui_ImplSDL2_Shutdown(); diff --git a/Keishiki/VisualTrack.cpp b/Keishiki/VisualTrack.cpp index 4758d39..a17e4ff 100644 --- a/Keishiki/VisualTrack.cpp +++ b/Keishiki/VisualTrack.cpp @@ -85,7 +85,7 @@ namespace K { bgfx::setUniform(u.handle, pack); } - Graphics::DrawTextureWithTransform(view_id, Graphics::mmaker->tx, transform, + Graphics::DrawTextureWithTransform(view_id, Graphics::mmaker->tex, transform, BGFX_STATE_WRITE_RGB | BGFX_STATE_WRITE_A, pg); } @@ -100,7 +100,7 @@ namespace K { } for (auto& u : uniforms) { f << "# define " << u.first << " __" << u.first; - std::visit([&u, &f](auto&& arg) { + std::visit([&f](auto&& arg) { using T = std::decay_t; if constexpr (std::is_same_v::type> || std::is_same_v::type>) f << ".x"; @@ -156,7 +156,7 @@ namespace K { if (std::system(s.c_str()) == 0) { if (isValid(pg)) bgfx::destroy(pg); - pg = Graphics::load_shader_program("temp"); + pg = Resource::FetchUnmanagedShaderProgram("temp"); } else Log("User shader compilation failed"); diff --git a/Keishiki/include/Common.h b/Keishiki/include/Common.h index 69c9e26..c4ef703 100644 --- a/Keishiki/include/Common.h +++ b/Keishiki/include/Common.h @@ -25,7 +25,7 @@ namespace K { template using Vector = std::vector; template using Dict = std::unordered_map; // to be replaced - inline void LogBase(const std::string_view& s, u8 level) { + inline void LogBase(const String& s, u8 level) { static const char *levels[] = { "Info", "Warning", @@ -33,10 +33,10 @@ namespace K { }; level > 1 ? std::cerr : std::cout << "[" << levels[level] << "] Keishiki: " << s << std::endl; } - inline void Log(const std::string_view& s) { + inline void Log(const String& s) { LogBase(s, 0); } - inline void LogError(const std::string_view& s) { + inline void LogError(const String& s) { LogBase(s, 2); } diff --git a/Keishiki/include/Graphics.h b/Keishiki/include/Graphics.h index aaef0aa..618a0a3 100644 --- a/Keishiki/include/Graphics.h +++ b/Keishiki/include/Graphics.h @@ -1,11 +1,14 @@ #pragma once #include "Common.h" +#include #include #include namespace K::Graphics { + extern const Resource::Resource *mmaker; // TEMP + enum VIEW_ID { K_VIEW_UI, K_VIEW_LOGO, @@ -18,18 +21,9 @@ namespace K::Graphics { bool Init(u16 width, u16 height); void Shutdown(); - bgfx::ProgramHandle load_shader_program(const std::string& FILENAME); - - struct ImageTexture { - i32 w, h, channels; - u8 *buffer; - bgfx::TextureHandle tx; - }; - ImageTexture *GetImageTextureFromFile(const std::string& file); // Caller not responsible for freeing - void DrawTextureWithTransform(u32 view_id, const bgfx::TextureHandle& tex, f32 mtx[16], u64 state, const bgfx::ProgramHandle& pg); void DrawTexture(u32 view_id, const bgfx::TextureHandle& tex, i32 pos_x, i32 pos_y, u32 w, u32 h, u64 state, const bgfx::ProgramHandle& pg); - void DrawTextureImageAlpha(u32 view_id, const ImageTexture& img, i32 pos_x, i32 pos_y, f32 alpha); + void DrawTextureImageAlpha(u32 view_id, const Resource::Resource& img, i32 pos_x, i32 pos_y, f32 alpha); void DrawTextureStencilAlpha(u32 view_id, const bgfx::TextureHandle& tex, i32 pos_x, i32 pos_y, u32 w, u32 h); // Text @@ -81,6 +75,7 @@ namespace K::Graphics { K_V_Count }; + static const char *BlendingToString[] = { "Alpha Over", @@ -123,8 +118,6 @@ namespace K::Graphics { void Composite(u32 view_id, bgfx::FrameBufferHandle fb, bgfx::TextureHandle composite, bgfx::TextureHandle from, Blending mode, u16 w, u16 h, f32 proj[16], f32 transform[16]); - extern Graphics::ImageTexture *mmaker; - f64 GetCubicUniqueReal(f64 a, f64 b, f64 c, f64 d); f64 CubicBezier(f64 a, f64 b, f64 c, f64 d, f64 t); f64 InjectingCubicBezierFromX(f64 p2x, f64 p2y, f64 p3x, f64 p3y, f64 x); diff --git a/Keishiki/include/Resource.h b/Keishiki/include/Resource.h new file mode 100644 index 0000000..7b224da --- /dev/null +++ b/Keishiki/include/Resource.h @@ -0,0 +1,74 @@ +#pragma once +#include +#include +#include + +namespace K::Resource { + extern std::filesystem::path ffmpeg_path; + + enum Type { + K_R_Still, + K_R_StillSequence, + K_R_VideoAudio, + K_R_AudioOnly, + K_R_ShaderProgram, + + // todo other data + K_R_Count + }; + + template + struct Resource { + std::filesystem::file_time_type last_updated; + }; + + template<> + struct Resource { + std::filesystem::file_time_type last_updated; + bgfx::TextureHandle tex; + u8 *buf; + i32 h, w, channels; + bgfx::TextureFormat::Enum format; + }; + + template<> + struct Resource { + std::filesystem::file_time_type last_updated; + u32 frames; + Vector tex; + u32 h, w; + bgfx::TextureFormat::Enum format; + }; + + template<> + struct Resource { + std::filesystem::file_time_type last_updated; + u32 frames; + Vector tex; + u32 h, w; + bgfx::TextureFormat::Enum format; + String scratch_dir; + }; + + template<> + struct Resource { + std::filesystem::file_time_type frag_last_updated; + bgfx::ProgramHandle pg; + }; + + extern Dict, + Resource, + Resource, + Resource, + Resource + >> resources; + + void Init(); + void Shutdown(); + + Resource *LoadStill(const std::filesystem::path& file); + Resource *LoadShaderProgram(const String& shader_name); + bgfx::ProgramHandle FetchUnmanagedShaderProgram(const String& shader_name); +} + diff --git a/README.md b/README.md index aa9e6fe..8ede225 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,12 @@ - [FreeType](https://freetype.org/) - [imgui_impl_bgfx](https://gist.github.com/pr0g/aff79b71bf9804ddb03f39ca7c0c3bbb) - [SDL2](https://www.libsdl.org/) +- [stb](https://github.com/nothings/stb) - [SRELL](https://www.akenotsuki.com/misc/srell/en/) +## Runtime Dependency +- [ffmpeg](https://ffmpeg.org/) + ## Inspired by - [Automaton](https://github.com/0b5vr/automaton) - [Blender](https://www.blender.org/) diff --git a/TODO.md b/TODO.md index f3a34a4..f5a05d3 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,9 @@ # NOW -## Chores -- Node groups +## UI +- Key selection in comp panel +- Graph editor +- Node loop detection (separate DFS (extra work) or be smart in recursion) + - detect time-sensitive nodes in tree and display on timeline ## Compositor - Manage Resources @@ -18,11 +21,8 @@ - Non-negotiable - Shapes (idea: embed glisp :mmtroll:, need to inquire -- still a lot of friction for simple shapes if we don't also get the glisp gizmos) - Non-negotiable - External data driving (csv, json or something else?) -- use a node to select source -## UI -- Key selection in comp panel -- Graph editor -- Node loop detection (separate DFS (extra work) or be smart in recursion) - - detect time-sensitive nodes in tree and display on timeline +## Chores +- Node groups # Later ## IO @@ -37,6 +37,8 @@ ## UI - Adapt nodes for shader graph -- code editor will be fine for now + - Shaders were using SRELL, I'm not sure about this anymore because it throws. We are doing dynamic replaces so CTRE can't work. Might be forced to go with PCRE or Re2. + - Viewport gizmos (Layer-specific & nodes -- can separate into different tools?) -- Not sure how to go about this - Baku vec2 drag is good, color drag is not so necessary because imgui has a good picker