comps
This commit is contained in:
parent
12281ce6f4
commit
10b506152f
8 changed files with 109 additions and 82 deletions
|
@ -137,7 +137,7 @@ namespace {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace K::Graphics {
|
namespace K::Graphics {
|
||||||
bool Init(u16 width, u16 height) {
|
bool Init() {
|
||||||
error = FT_Init_FreeType(&library);
|
error = FT_Init_FreeType(&library);
|
||||||
if (error) {
|
if (error) {
|
||||||
LogError("FreeType init error: " + std::to_string(error));
|
LogError("FreeType init error: " + std::to_string(error));
|
||||||
|
|
|
@ -15,11 +15,6 @@
|
||||||
#include "backends/imgui_impl_sdl3.h"
|
#include "backends/imgui_impl_sdl3.h"
|
||||||
#include <imgui.h>
|
#include <imgui.h>
|
||||||
|
|
||||||
namespace {
|
|
||||||
K::CompState state;
|
|
||||||
const K::Resource::Resource<K::Resource::Type::K_R_Still> *logo;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace K {
|
namespace K {
|
||||||
K::AppState app_state;
|
K::AppState app_state;
|
||||||
|
|
||||||
|
@ -31,7 +26,7 @@ namespace K {
|
||||||
|
|
||||||
app_state.window = SDL_CreateWindow("Keishiki",
|
app_state.window = SDL_CreateWindow("Keishiki",
|
||||||
app_state.window_width, app_state.window_height,
|
app_state.window_width, app_state.window_height,
|
||||||
0);
|
SDL_WINDOW_RESIZABLE);
|
||||||
|
|
||||||
if (app_state.window == nullptr) {
|
if (app_state.window == nullptr) {
|
||||||
LogError(SDL_GetError());
|
LogError(SDL_GetError());
|
||||||
|
@ -54,6 +49,7 @@ namespace K {
|
||||||
bgfxInit.platformData.ndt = SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
|
bgfxInit.platformData.ndt = SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_X11_DISPLAY_POINTER, NULL);
|
||||||
bgfxInit.platformData.nwh = (void*)SDL_GetNumberProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
|
bgfxInit.platformData.nwh = (void*)SDL_GetNumberProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_X11_WINDOW_NUMBER, 0);
|
||||||
}
|
}
|
||||||
|
#if WL_EGL_PLATFORM
|
||||||
else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) {
|
else if (SDL_strcmp(SDL_GetCurrentVideoDriver(), "wayland") == 0) {
|
||||||
bgfxInit.platformData.type = bgfx::NativeWindowHandleType::Wayland;
|
bgfxInit.platformData.type = bgfx::NativeWindowHandleType::Wayland;
|
||||||
bgfxInit.platformData.ndt = SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
|
bgfxInit.platformData.ndt = SDL_GetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_WAYLAND_DISPLAY_POINTER, NULL);
|
||||||
|
@ -63,6 +59,7 @@ namespace K {
|
||||||
SDL_SetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_WAYLAND_EGL_WINDOW_POINTER, (void*)(uintptr_t)bgfxInit.platformData.nwh);
|
SDL_SetProperty(SDL_GetWindowProperties(app_state.window), SDL_PROP_WINDOW_WAYLAND_EGL_WINDOW_POINTER, (void*)(uintptr_t)bgfxInit.platformData.nwh);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
#elif BX_PLATFORM_EMSCRIPTEN
|
#elif BX_PLATFORM_EMSCRIPTEN
|
||||||
bgfxInit.platformData.nwh = (void*)"#canvas";
|
bgfxInit.platformData.nwh = (void*)"#canvas";
|
||||||
#endif
|
#endif
|
||||||
|
@ -72,58 +69,21 @@ namespace K {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bgfx::setDebug(BGFX_DEBUG_TEXT);
|
|
||||||
bgfx::setViewRect(K::Graphics::K_VIEW_LOGO, 0, 0, app_state.window_width, app_state.window_height);
|
|
||||||
float view[16];
|
|
||||||
bx::mtxTranslate(view, 0.f, 0.f, 1.0f);
|
|
||||||
float proj[16];
|
|
||||||
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::Resource::Init();
|
||||||
K::UI::Init(app_state.window);
|
K::UI::Init(app_state.window);
|
||||||
|
|
||||||
if (!K::Graphics::Init(app_state.window_width, app_state.window_height)) {
|
if (!K::Graphics::Init()) {
|
||||||
LogError("Graphics init failed");
|
LogError("Graphics init failed");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
logo = Resource::Load<Resource::K_R_Still>("Keishiki.png");
|
app_state.compositions.emplace_back("default project", 0, 100, 30.0f, 1280, 550);
|
||||||
|
app_state.inspecting_composition = 0;
|
||||||
state.width = 1280;
|
K::UI::SetupViewport(app_state.compositions[0]);
|
||||||
state.height = 550;
|
|
||||||
state.current_frame = 0;
|
|
||||||
state.fps = 30.0f;
|
|
||||||
state.frame_max = 200;
|
|
||||||
|
|
||||||
K::UI::SetupViewport(state);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render() {
|
|
||||||
K::Graphics::DrawTextureImageAlpha(K::Graphics::K_VIEW_LOGO, logo, app_state.window_width - logo->w + 10, 0, .4f);
|
|
||||||
|
|
||||||
UI::Draw(app_state.bgfx_frame, state);
|
|
||||||
|
|
||||||
const bgfx::Stats *stat = bgfx::getStats();
|
|
||||||
const bgfx::Caps *caps = bgfx::getCaps();
|
|
||||||
bgfx::dbgTextClear();
|
|
||||||
bgfx::dbgTextPrintf(0, app_state.window_height/16 - 8, 0xf8,
|
|
||||||
" lachrymal.net :: %s Renderer :: %u/%u Views :: %u FBs :: %u Samplers :: Blit %s :: %s :: %u FPS",
|
|
||||||
caps->supported & BGFX_CAPS_RENDERER_MULTITHREADED ? "Multithreaded" : "Singlethreaded",
|
|
||||||
app_state.n_views, caps->limits.maxViews, caps->limits.maxFrameBuffers,
|
|
||||||
caps->limits.maxTextureSamplers, caps->supported & BGFX_CAPS_TEXTURE_BLIT ? "OK" : "NO",
|
|
||||||
SDL_GetCurrentVideoDriver(),
|
|
||||||
stat->cpuTimerFreq / stat->cpuTimeFrame);
|
|
||||||
bgfx::dbgTextPrintf(0, app_state.window_height/16 - 7, 0xf8,
|
|
||||||
" Project Keishiki :: %s :: Build %s %s :: SDL %i.%i.%i :: bgfx 1.%i :: Dear ImGui %s :: %s",
|
|
||||||
BX_COMPILER_NAME, __DATE__, __TIME__, SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION,
|
|
||||||
BGFX_API_VERSION, ImGui::GetVersion(), bgfx::getRendererName(bgfx::getRendererType()));
|
|
||||||
|
|
||||||
app_state.bgfx_frame = bgfx::frame();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Run() {
|
void Run() {
|
||||||
app_state.init_time = SDL_GetTicks();
|
app_state.init_time = SDL_GetTicks();
|
||||||
app_state.last_time = app_state.init_time;
|
app_state.last_time = app_state.init_time;
|
||||||
|
@ -138,9 +98,14 @@ namespace K {
|
||||||
app_state.running.store(false);
|
app_state.running.store(false);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if (current_event.type == SDL_EVENT_WINDOW_PIXEL_SIZE_CHANGED) {
|
||||||
|
SDL_GetWindowSize(app_state.window, &app_state.window_width, &app_state.window_height);
|
||||||
|
bgfx::reset(app_state.window_width, app_state.window_height);
|
||||||
|
UI::SetLogoView();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Render();
|
UI::Draw();
|
||||||
|
|
||||||
app_state.last_time = app_state.current_time;
|
app_state.last_time = app_state.current_time;
|
||||||
}
|
}
|
||||||
|
@ -148,7 +113,7 @@ namespace K {
|
||||||
|
|
||||||
void Shutdown() {
|
void Shutdown() {
|
||||||
K::Graphics::Shutdown();
|
K::Graphics::Shutdown();
|
||||||
K::UI::Shutdown(state);
|
K::UI::Shutdown();
|
||||||
K::Resource::Shutdown();
|
K::Resource::Shutdown();
|
||||||
bgfx::shutdown();
|
bgfx::shutdown();
|
||||||
|
|
||||||
|
|
104
Keishiki/UI.cpp
104
Keishiki/UI.cpp
|
@ -19,12 +19,13 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
const K::Resource::Resource<K::Resource::Type::K_R_Still> *logo;
|
||||||
|
|
||||||
// Panels
|
// Panels
|
||||||
bool draw_viewport = true,
|
bool draw_viewport = true,
|
||||||
draw_layer = true,
|
draw_layer = true,
|
||||||
draw_comp = true,
|
draw_comp = true,
|
||||||
draw_interpolation = true,
|
draw_interpolation = true,
|
||||||
// draw_properties = true,
|
|
||||||
draw_assets = true;
|
draw_assets = true;
|
||||||
|
|
||||||
const f32 row_height = 20.0f;
|
const f32 row_height = 20.0f;
|
||||||
|
@ -37,10 +38,11 @@ namespace {
|
||||||
save = BGFX_INVALID_HANDLE;
|
save = BGFX_INVALID_HANDLE;
|
||||||
bgfx::FrameBufferHandle composite_fb[2] = { BGFX_INVALID_HANDLE, BGFX_INVALID_HANDLE },
|
bgfx::FrameBufferHandle composite_fb[2] = { BGFX_INVALID_HANDLE, BGFX_INVALID_HANDLE },
|
||||||
render_fb = BGFX_INVALID_HANDLE;
|
render_fb = BGFX_INVALID_HANDLE;
|
||||||
K::VisualTrack bg{};
|
|
||||||
f32 proj[16], transform[16], view[16];
|
f32 proj[16], transform[16], view[16];
|
||||||
|
|
||||||
|
K::VisualTrack bg{};
|
||||||
K::Byte *save_buffer;
|
K::Byte *save_buffer;
|
||||||
bool save_called = false;
|
K::CompState *comp_save_called = nullptr;
|
||||||
u32 ready_frame;
|
u32 ready_frame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,6 +59,14 @@ namespace ImGui {
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace K::UI {
|
namespace K::UI {
|
||||||
|
void SetLogoView() {
|
||||||
|
bgfx::setViewRect(Graphics::K_VIEW_LOGO, 0, 0, app_state.window_width, app_state.window_height);
|
||||||
|
float view[16];
|
||||||
|
bx::mtxTranslate(view, 0.f, 0.f, 1.0f);
|
||||||
|
float proj[16];
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
void AddTransformLayer(CompState& s, const String& name) {
|
void AddTransformLayer(CompState& s, const String& name) {
|
||||||
auto l = Layer{
|
auto l = Layer{
|
||||||
|
@ -107,7 +117,7 @@ namespace K::UI {
|
||||||
s.layers.push_back(std::move(l));
|
s.layers.push_back(std::move(l));
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenuBar(const CompState& s) {
|
void MainMenuBar() {
|
||||||
if (ImGui::BeginMainMenuBar()) {
|
if (ImGui::BeginMainMenuBar()) {
|
||||||
if (ImGui::BeginMenu("Edit")) {
|
if (ImGui::BeginMenu("Edit")) {
|
||||||
// if (ImGui::MenuItem("Undo", "CTRL+Z")) {}
|
// if (ImGui::MenuItem("Undo", "CTRL+Z")) {}
|
||||||
|
@ -393,11 +403,11 @@ namespace K::UI {
|
||||||
ImGui::Text("%ux%u", s.width, s.height);
|
ImGui::Text("%ux%u", s.width, s.height);
|
||||||
ImGui::SameLine();
|
ImGui::SameLine();
|
||||||
|
|
||||||
ImGui::BeginDisabled(save_called);
|
ImGui::BeginDisabled(comp_save_called == nullptr);
|
||||||
if (ImGui::Button("Save to frame.png")) {
|
if (ImGui::Button("Save to frame.png")) {
|
||||||
bgfx::blit(Graphics::K_VIEW_COMP_COMPOSITE + view_count, save, 0, 0, composite[layers_done % 2]);
|
bgfx::blit(Graphics::K_VIEW_COMP_COMPOSITE + view_count, save, 0, 0, composite[layers_done % 2]);
|
||||||
ready_frame = bgfx::readTexture(save, save_buffer);
|
ready_frame = bgfx::readTexture(save, save_buffer);
|
||||||
save_called = true;
|
comp_save_called = &s;
|
||||||
}
|
}
|
||||||
ImGui::EndDisabled();
|
ImGui::EndDisabled();
|
||||||
|
|
||||||
|
@ -476,7 +486,7 @@ namespace K::UI {
|
||||||
node_delete_requested = false;
|
node_delete_requested = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ImGui::Begin("Composition", &draw_comp, ImGuiWindowFlags_NoScrollbar)) {
|
if (!ImGui::Begin(("Composition: " + s.name).c_str(), &draw_comp, ImGuiWindowFlags_NoScrollbar)) {
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -485,7 +495,7 @@ namespace K::UI {
|
||||||
if (ImGui::Shortcut(ImGuiKey_Space))
|
if (ImGui::Shortcut(ImGuiKey_Space))
|
||||||
TogglePlay();
|
TogglePlay();
|
||||||
|
|
||||||
static u32 node_current{};
|
static u32 node_current = 0;
|
||||||
if (ImGui::Button("Add")) {
|
if (ImGui::Button("Add")) {
|
||||||
s.plugboard.nodes.Store(static_cast<Plugboard::K_P_Nodes>(node_current));
|
s.plugboard.nodes.Store(static_cast<Plugboard::K_P_Nodes>(node_current));
|
||||||
}
|
}
|
||||||
|
@ -1383,15 +1393,20 @@ namespace K::UI {
|
||||||
ImPlot::Annotation(p3x, p3y, {1.0f, 1.0f, 1.0f, 1.0f}, {15.0f, 0.0f}, true);
|
ImPlot::Annotation(p3x, p3y, {1.0f, 1.0f, 1.0f, 1.0f}, {15.0f, 0.0f}, true);
|
||||||
|
|
||||||
static f32 x_tmp, y_tmp;
|
static f32 x_tmp, y_tmp;
|
||||||
|
static f32 cap_l, cap_r;
|
||||||
|
|
||||||
ImGui::SetCursorScreenPos(ImPlot::PlotToPixels(p2x, p2y) - ImVec2{10.0f / 2.0f, 10.0f / 2.0f});
|
ImGui::SetCursorScreenPos(ImPlot::PlotToPixels(p2x, p2y) - ImVec2{10.0f / 2.0f, 10.0f / 2.0f});
|
||||||
ImGui::Button("##p2", {10.0f, 10.0f});
|
ImGui::Button("##p2", {10.0f, 10.0f});
|
||||||
if (ImGui::IsItemClicked()) {
|
if (ImGui::IsItemClicked()) {
|
||||||
x_tmp = segment.v[0];
|
x_tmp = segment.v[0];
|
||||||
y_tmp = segment.v[1];
|
y_tmp = segment.v[1];
|
||||||
|
auto cp1 = segment.v[2] + 1.0f;
|
||||||
|
auto d_sqrt = std::sqrt(cp1 * cp1 - 4.0f * segment.v[2] * segment.v[2]);
|
||||||
|
cap_l = (cp1 - d_sqrt) / 2.0f;
|
||||||
|
cap_r = (cp1 + d_sqrt) / 2.0f;
|
||||||
}
|
}
|
||||||
if (ImGui::IsItemActive()) {
|
if (ImGui::IsItemActive()) {
|
||||||
segment.v[0] = std::clamp(x_tmp + static_cast<f32>(drag_off_x) / (static_cast<f32>(frame_nxt) - static_cast<f32>(frame)), 0.0f, 1.0f);
|
segment.v[0] = std::clamp(x_tmp + static_cast<f32>(drag_off_x) / (static_cast<f32>(frame_nxt) - static_cast<f32>(frame)), segment.v[2] >= 0.0f ? 0.0f : cap_l, cap_r);
|
||||||
segment.v[1] = y_tmp + static_cast<f32>(drag_off_y / (v_nxt - v));
|
segment.v[1] = y_tmp + static_cast<f32>(drag_off_y / (v_nxt - v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1400,9 +1415,12 @@ namespace K::UI {
|
||||||
if (ImGui::IsItemClicked()) {
|
if (ImGui::IsItemClicked()) {
|
||||||
x_tmp = segment.v[2];
|
x_tmp = segment.v[2];
|
||||||
y_tmp = segment.v[3];
|
y_tmp = segment.v[3];
|
||||||
|
auto d_sqrt = std::sqrt(4.0f * segment.v[0] - 3.0f * segment.v[0] * segment.v[0]);
|
||||||
|
cap_l = (segment.v[0] - d_sqrt) / 2.0f;
|
||||||
|
cap_r = (segment.v[0] + d_sqrt) / 2.0f;
|
||||||
}
|
}
|
||||||
if (ImGui::IsItemActive()) {
|
if (ImGui::IsItemActive()) {
|
||||||
segment.v[2] = std::clamp(x_tmp + static_cast<f32>(drag_off_x) / (static_cast<f32>(frame_nxt) - static_cast<f32>(frame)), 0.0f, 1.0f);
|
segment.v[2] = std::clamp(x_tmp + static_cast<f32>(drag_off_x) / (static_cast<f32>(frame_nxt) - static_cast<f32>(frame)), cap_l, segment.v[0] <= 1.0f ? 1.0f : cap_r);
|
||||||
segment.v[3] = y_tmp + static_cast<f32>(drag_off_y / (v_nxt - v));
|
segment.v[3] = y_tmp + static_cast<f32>(drag_off_y / (v_nxt - v));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1764,9 +1782,8 @@ namespace K::UI {
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Assets(CompState& s) {
|
void Assets() {
|
||||||
if (ImGui::Begin("Assets", &draw_assets)) {
|
if (ImGui::Begin("Assets", &draw_assets)) {
|
||||||
ImGui::TextUnformatted("Loaded assets:");
|
|
||||||
if (ImGui::BeginTable("Assets", 3, ImGuiTableFlags_Borders)) {
|
if (ImGui::BeginTable("Assets", 3, ImGuiTableFlags_Borders)) {
|
||||||
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
|
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthStretch);
|
||||||
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed);
|
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_WidthFixed);
|
||||||
|
@ -1774,6 +1791,16 @@ namespace K::UI {
|
||||||
ImGui::TableHeadersRow();
|
ImGui::TableHeadersRow();
|
||||||
|
|
||||||
i32 i = 0;
|
i32 i = 0;
|
||||||
|
for (auto& comp : app_state.compositions) {
|
||||||
|
ImGui::TableNextRow();
|
||||||
|
ImGui::PushID(i++);
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text("%s", comp.name.c_str());
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::Text("Composition");
|
||||||
|
ImGui::TableNextColumn();
|
||||||
|
ImGui::PopID();
|
||||||
|
}
|
||||||
for (auto& [name, res] : Resource::resources) {
|
for (auto& [name, res] : Resource::resources) {
|
||||||
ImGui::TableNextRow();
|
ImGui::TableNextRow();
|
||||||
ImGui::PushID(i++);
|
ImGui::PushID(i++);
|
||||||
|
@ -1813,31 +1840,55 @@ namespace K::UI {
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Draw(u32 frame, CompState& s) {
|
void Draw() {
|
||||||
ImGui_ImplSDL3_NewFrame();
|
ImGui_ImplSDL3_NewFrame();
|
||||||
ImGui_Implbgfx_NewFrame();
|
ImGui_Implbgfx_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
|
Graphics::DrawTextureImageAlpha(K::Graphics::K_VIEW_LOGO, logo, app_state.window_width - logo->w + 10, 0, .4f);
|
||||||
|
|
||||||
ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(), ImGuiDockNodeFlags_PassthruCentralNode);
|
ImGui::DockSpaceOverViewport(0, ImGui::GetMainViewport(), ImGuiDockNodeFlags_PassthruCentralNode);
|
||||||
|
|
||||||
ImGui::ShowDemoWindow();
|
ImGui::ShowDemoWindow();
|
||||||
MainMenuBar(s);
|
MainMenuBar();
|
||||||
if (draw_viewport) Viewport(s); // Must go before comp!
|
|
||||||
if (draw_layer) Layer(s);
|
|
||||||
if (draw_comp) Composition(s);
|
|
||||||
if (draw_interpolation) Interpolation(s);
|
|
||||||
if (draw_assets) Assets(s);
|
|
||||||
|
|
||||||
if (save_called && ready_frame <= frame) {
|
if (draw_assets) Assets();
|
||||||
stbi_write_png("frame.png", static_cast<i32>(s.width), static_cast<i32>(s.height), 4, save_buffer, static_cast<i32>(s.width) * 4);
|
|
||||||
save_called = false;
|
auto& comp = app_state.compositions[app_state.inspecting_composition];
|
||||||
|
if (draw_viewport) Viewport(comp);
|
||||||
|
if (draw_layer) Layer(comp);
|
||||||
|
if (draw_comp) Composition(comp);
|
||||||
|
if (draw_interpolation) Interpolation(comp);
|
||||||
|
|
||||||
|
if (comp_save_called != nullptr && ready_frame <= app_state.bgfx_frame) {
|
||||||
|
stbi_write_png("frame.png", static_cast<i32>(comp_save_called->width), static_cast<i32>(comp_save_called->height), 4, save_buffer, static_cast<i32>(comp_save_called->width) * 4);
|
||||||
|
comp_save_called = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImGui_Implbgfx_RenderDrawLists(ImGui::GetDrawData());
|
ImGui_Implbgfx_RenderDrawLists(ImGui::GetDrawData());
|
||||||
|
|
||||||
|
const bgfx::Stats *stat = bgfx::getStats();
|
||||||
|
const bgfx::Caps *caps = bgfx::getCaps();
|
||||||
|
bgfx::dbgTextClear();
|
||||||
|
bgfx::dbgTextPrintf(0, app_state.window_height/16 - 8, 0xf8,
|
||||||
|
" lachrymal.net :: %s Renderer :: %u/%u Views :: %u FBs :: %u Samplers :: Blit %s :: %s :: %u FPS",
|
||||||
|
caps->supported & BGFX_CAPS_RENDERER_MULTITHREADED ? "Multithreaded" : "Singlethreaded",
|
||||||
|
app_state.n_views, caps->limits.maxViews, caps->limits.maxFrameBuffers,
|
||||||
|
caps->limits.maxTextureSamplers, caps->supported & BGFX_CAPS_TEXTURE_BLIT ? "OK" : "NO",
|
||||||
|
SDL_GetCurrentVideoDriver(),
|
||||||
|
stat->cpuTimerFreq / stat->cpuTimeFrame);
|
||||||
|
bgfx::dbgTextPrintf(0, app_state.window_height/16 - 7, 0xf8,
|
||||||
|
" Project Keishiki :: %s :: Build %s %s :: SDL %i.%i.%i :: bgfx 1.%i :: Dear ImGui %s :: %s",
|
||||||
|
BX_COMPILER_NAME, __DATE__, __TIME__, SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_MICRO_VERSION,
|
||||||
|
BGFX_API_VERSION, ImGui::GetVersion(), bgfx::getRendererName(bgfx::getRendererType()));
|
||||||
|
|
||||||
|
app_state.bgfx_frame = bgfx::frame();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init(SDL_Window *window) {
|
void Init(SDL_Window *window) {
|
||||||
|
bgfx::setDebug(BGFX_DEBUG_TEXT);
|
||||||
|
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImPlot::CreateContext();
|
ImPlot::CreateContext();
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
@ -1845,6 +1896,7 @@ namespace K::UI {
|
||||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
ImGui_Implbgfx_Init(Graphics::K_VIEW_UI);
|
ImGui_Implbgfx_Init(Graphics::K_VIEW_UI);
|
||||||
bgfx::setViewClear(Graphics::K_VIEW_UI, BGFX_CLEAR_COLOR);
|
bgfx::setViewClear(Graphics::K_VIEW_UI, BGFX_CLEAR_COLOR);
|
||||||
|
SetLogoView();
|
||||||
|
|
||||||
switch (bgfx::getRendererType()) {
|
switch (bgfx::getRendererType()) {
|
||||||
case bgfx::RendererType::Noop:
|
case bgfx::RendererType::Noop:
|
||||||
|
@ -1867,13 +1919,17 @@ namespace K::UI {
|
||||||
|
|
||||||
bg.pg = Resource::Load<Resource::K_R_ShaderProgram>("Checkerboard")->pg;
|
bg.pg = Resource::Load<Resource::K_R_ShaderProgram>("Checkerboard")->pg;
|
||||||
bg.AddUniform("f_hw", ShaderGraph::Type::T_XYZ);
|
bg.AddUniform("f_hw", ShaderGraph::Type::T_XYZ);
|
||||||
|
|
||||||
|
logo = Resource::Load<Resource::K_R_Still>("Keishiki.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Shutdown(CompState& s) {
|
void Shutdown() {
|
||||||
bgfx::destroy(bg.uniforms[0].handle);
|
bgfx::destroy(bg.uniforms[0].handle);
|
||||||
bg.uniforms.erase(bg.uniforms.begin());
|
bg.uniforms.erase(bg.uniforms.begin());
|
||||||
|
|
||||||
DestroyViewport(s);
|
for (auto& comp : app_state.compositions)
|
||||||
|
DestroyViewport(comp);
|
||||||
|
|
||||||
ImGui_Implbgfx_Shutdown();
|
ImGui_Implbgfx_Shutdown();
|
||||||
ImGui_ImplSDL3_Shutdown();
|
ImGui_ImplSDL3_Shutdown();
|
||||||
ImPlot::DestroyContext();
|
ImPlot::DestroyContext();
|
||||||
|
|
|
@ -18,7 +18,7 @@ namespace K::Graphics {
|
||||||
K_VIEW_COMP_COMPOSITE
|
K_VIEW_COMP_COMPOSITE
|
||||||
};
|
};
|
||||||
|
|
||||||
bool Init(u16 width, u16 height);
|
bool Init();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
void DrawQuad(u32 view_id, f32 mtx[16], u64 state, const bgfx::ProgramHandle& pg);
|
void DrawQuad(u32 view_id, f32 mtx[16], u64 state, const bgfx::ProgramHandle& pg);
|
||||||
|
|
|
@ -9,8 +9,6 @@ namespace K {
|
||||||
void Run();
|
void Run();
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
|
|
||||||
void Render();
|
|
||||||
|
|
||||||
struct Layer {
|
struct Layer {
|
||||||
VisualTrack track;
|
VisualTrack track;
|
||||||
String name;
|
String name;
|
||||||
|
@ -19,6 +17,7 @@ namespace K {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct CompState {
|
struct CompState {
|
||||||
|
String name;
|
||||||
// Time
|
// Time
|
||||||
u64 current_frame;
|
u64 current_frame;
|
||||||
u64 frame_max;
|
u64 frame_max;
|
||||||
|
@ -36,12 +35,16 @@ namespace K {
|
||||||
|
|
||||||
extern struct AppState {
|
extern struct AppState {
|
||||||
SDL_Window *window = nullptr;
|
SDL_Window *window = nullptr;
|
||||||
u16 window_width = 2300,
|
i32 window_width = 2300,
|
||||||
window_height = 1300;
|
window_height = 1300;
|
||||||
|
|
||||||
|
std::atomic_bool running {true};
|
||||||
|
|
||||||
u64 init_time{}, last_time{}, current_time{}, delta_t{};
|
u64 init_time{}, last_time{}, current_time{}, delta_t{};
|
||||||
u32 bgfx_frame{};
|
u32 bgfx_frame{};
|
||||||
u32 n_views{};
|
u32 n_views{};
|
||||||
std::atomic_bool running {true};
|
|
||||||
|
i32 inspecting_composition = -1;
|
||||||
|
Vector<CompState> compositions{};
|
||||||
} app_state; // global !
|
} app_state; // global !
|
||||||
}
|
}
|
||||||
|
|
|
@ -373,7 +373,7 @@ namespace K::Plugboard {
|
||||||
|
|
||||||
T_Map<T_Count>::type FetchNegate(const CompState& s, const Negate& n);
|
T_Map<T_Count>::type FetchNegate(const CompState& s, const Negate& n);
|
||||||
struct Negate {
|
struct Negate {
|
||||||
const static char constexpr *name = static_cast<const char*>("Add");
|
const static char constexpr *name = static_cast<const char*>("Negate");
|
||||||
std::array<InSocket, 2> in = { InSocket{"a", T_Float } };
|
std::array<InSocket, 2> in = { InSocket{"a", T_Float } };
|
||||||
std::array<OutSocket, 1> out = { OutSocket{ "-a", T_Float } };
|
std::array<OutSocket, 1> out = { OutSocket{ "-a", T_Float } };
|
||||||
std::array<T_Map<T_Count>::type (*)(const CompState&, const Negate&), 1> fetch = { FetchNegate };
|
std::array<T_Map<T_Count>::type (*)(const CompState&, const Negate&), 1> fetch = { FetchNegate };
|
||||||
|
|
|
@ -4,7 +4,9 @@
|
||||||
|
|
||||||
namespace K::UI {
|
namespace K::UI {
|
||||||
void Init(SDL_Window *window);
|
void Init(SDL_Window *window);
|
||||||
void Draw(u32 frame, CompState& s);
|
void Draw();
|
||||||
void Shutdown(CompState& s);
|
void Shutdown();
|
||||||
void SetupViewport(CompState& s);
|
void SetupViewport(CompState& s);
|
||||||
|
void DestroyViewport(CompState& s);
|
||||||
|
void SetLogoView();
|
||||||
}
|
}
|
||||||
|
|
1
TODO.md
1
TODO.md
|
@ -10,6 +10,7 @@
|
||||||
- Pre-compose/Layer Groups
|
- Pre-compose/Layer Groups
|
||||||
- Undo's
|
- Undo's
|
||||||
- Node groups
|
- Node groups
|
||||||
|
|
||||||
- Motion blur
|
- Motion blur
|
||||||
|
|
||||||
- Text (idea: index-based evaluation in plugboard)
|
- Text (idea: index-based evaluation in plugboard)
|
||||||
|
|
Loading…
Add table
Reference in a new issue