it works kinda
This commit is contained in:
parent
6f44df335f
commit
f0db892b6a
22 changed files with 283 additions and 10537 deletions
|
@ -6,8 +6,9 @@ cmake_minimum_required (VERSION 3.8)
|
|||
project("Main")
|
||||
|
||||
add_executable (Keishiki
|
||||
"ext/imgui/imgui.cpp" "ext/imgui_impl_bgfx.cpp" "ext/imgui_impl_sdl2.cpp"
|
||||
"ext/imgui/imgui.cpp" "ext/imgui_impl_bgfx.cpp" "ext/imgui/backends/imgui_impl_sdl2.cpp"
|
||||
"ext/imgui/imgui_demo.cpp" "ext/imgui/imgui_draw.cpp" "ext/imgui/imgui_tables.cpp" "ext/imgui/imgui_widgets.cpp"
|
||||
"ext/imgui/misc/cpp/imgui_stdlib.cpp"
|
||||
|
||||
"Keishiki.cpp" "Graphics.cpp" "UI.cpp" "ShaderGraph.cpp" "include/ShaderGraph.h" "include/ShaderNodes.h")
|
||||
|
||||
|
@ -15,7 +16,7 @@ if (CMAKE_VERSION VERSION_GREATER 3.12)
|
|||
set_property(TARGET Keishiki PROPERTY CXX_STANDARD 20)
|
||||
endif()
|
||||
|
||||
include_directories ("include" "include/ext" "ext/imgui" "ext/imgui/backends")
|
||||
include_directories ("include" "include/ext" "ext/imgui")
|
||||
add_subdirectory("ext/freetype")
|
||||
add_subdirectory("ext/bgfx")
|
||||
if (WIN32)
|
||||
|
|
|
@ -88,7 +88,7 @@ namespace {
|
|||
|
||||
error = FT_Load_Char(face, c, FT_LOAD_RENDER);
|
||||
if (error) {
|
||||
std::cerr << "ADV: Failed to load character" << std::endl;
|
||||
LogError("Failed to load character");
|
||||
}
|
||||
|
||||
if (slot->bitmap.width != 0) {
|
||||
|
@ -160,7 +160,7 @@ namespace {
|
|||
ImageTexture i;
|
||||
i.buffer = stbi_load(file.c_str(), &i.w, &i.h, &i.channels, 0);
|
||||
if (i.buffer == NULL) {
|
||||
std::cerr << "ADV: STB IMAGE loading failed for " << file << std::endl;
|
||||
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));
|
||||
|
@ -204,7 +204,7 @@ namespace K::Graphics {
|
|||
bool Init(u16 width, u16 height) {
|
||||
error = FT_Init_FreeType(&library);
|
||||
if (error) {
|
||||
std::cerr << "ADV: FreeType init error: " << error << std::endl;
|
||||
LogError("FreeType init error: " + std::to_string(error));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -266,12 +266,6 @@ namespace K::Graphics {
|
|||
bgfx::submit(view_id, pg);
|
||||
}
|
||||
|
||||
void TEMP_SetAlpha(f32 alpha) {
|
||||
f32 pack[4]{};
|
||||
pack[0] = alpha;
|
||||
bgfx::setUniform(imga_opacity, pack);
|
||||
}
|
||||
|
||||
void DrawTextureImageAlpha(u32 view_id, const ImageTexture& img, i32 pos_x, i32 pos_y, f32 alpha) {
|
||||
f32 pack[4]{};
|
||||
pack[0] = alpha;
|
||||
|
@ -282,7 +276,7 @@ namespace K::Graphics {
|
|||
ImageTexture* GetImageTextureFromFile(const std::string& file) {
|
||||
if (imgs.find(file) == imgs.end()) {
|
||||
if (auto i = get_image_texture(file)) {
|
||||
imgs[file] = std::move(*i);
|
||||
imgs[file] = *i;
|
||||
return &imgs[file];
|
||||
}
|
||||
else return nullptr;
|
||||
|
|
|
@ -15,13 +15,13 @@
|
|||
|
||||
namespace {
|
||||
SDL_Window* window;
|
||||
u16 window_width = 1600;
|
||||
u16 window_height = 900;
|
||||
u16 window_width = 1920;
|
||||
u16 window_height = 1080;
|
||||
|
||||
u64 init_time, last_time, current_time, delta_t;
|
||||
bool running = false;
|
||||
|
||||
K::State state;
|
||||
K::CompState state;
|
||||
bgfx::FrameBufferHandle fb = BGFX_INVALID_HANDLE;
|
||||
K::Graphics::ImageTexture* mm;
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ namespace K {
|
|||
}
|
||||
|
||||
bgfx::Init bgfxInit;
|
||||
bgfxInit.type = bgfx::RendererType::OpenGLES; // Automatically choose a renderer.
|
||||
bgfxInit.type = bgfx::RendererType::Count; // Automatically choose a renderer.
|
||||
bgfxInit.resolution.width = window_width;
|
||||
bgfxInit.resolution.height = window_height;
|
||||
bgfxInit.resolution.reset = BGFX_RESET_VSYNC;
|
||||
|
@ -76,16 +76,16 @@ namespace K {
|
|||
LogError("bgfx initialization failed");
|
||||
return false;
|
||||
};
|
||||
|
||||
|
||||
ImGui::CreateContext();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard;
|
||||
io.Fonts->AddFontFromFileTTF("SourceHanSans-Regular.ttc", 17);
|
||||
ImGui_Implbgfx_Init(0);
|
||||
// io.Fonts->AddFontFromFileTTF("SourceHanSans-Regular.ttc", 17);
|
||||
ImGui_Implbgfx_Init(K::Graphics::K_VIEW_TOP);
|
||||
|
||||
bgfx::setDebug(BGFX_DEBUG_TEXT);
|
||||
bgfx::setViewClear(0, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x000000ff, 1.0f, 0);
|
||||
bgfx::setViewRect(0, 0, 0, window_width, window_height);
|
||||
bgfx::setViewClear(K::Graphics::K_VIEW_TOP, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x000000ff, 1.0f, 0);
|
||||
bgfx::setViewRect(K::Graphics::K_VIEW_TOP, 0, 0, window_width, window_height);
|
||||
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
ImGui_ImplSDL2_InitForD3D(window);
|
||||
|
@ -100,25 +100,31 @@ namespace K {
|
|||
return false;
|
||||
}
|
||||
|
||||
fb = bgfx::createFrameBuffer(800, 600, bgfx::TextureFormat::RGBA8);
|
||||
state.layers.push_back(Layer(VisualTrack(ShaderGraph::ShaderGraph({
|
||||
|
||||
})), "garfield", true, false, K_V_Normal));
|
||||
state.width = 800;
|
||||
state.height = 600;
|
||||
fb = bgfx::createFrameBuffer(state.width, state.height, bgfx::TextureFormat::RGBA8);
|
||||
state.layers.push_back(Layer{
|
||||
VisualTrack{},
|
||||
"garfield",
|
||||
true,
|
||||
false,
|
||||
K_V_Normal
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Render() {
|
||||
ImGui::ShowDemoWindow();
|
||||
// ImGui::ShowDemoWindow();
|
||||
UI::Draw(state, mm, fb);
|
||||
ImGui::Render();
|
||||
ImGui_Implbgfx_RenderDrawLists(ImGui::GetDrawData());
|
||||
|
||||
const bgfx::Stats* stat = bgfx::getStats();
|
||||
bgfx::dbgTextClear();
|
||||
bgfx::dbgTextPrintf(0, 53, 0xf8, " %u FPS", stat->cpuTimerFreq / stat->cpuTimeFrame);
|
||||
bgfx::dbgTextPrintf(0, 54, 0xf8, " Project Keishiki :: %s :: Build %s %s", BX_COMPILER_NAME, __DATE__, __TIME__);
|
||||
bgfx::dbgTextPrintf(0, 55, 0xf8, " SDL %i.%i.%2i :: bgfx 1.%i :: Dear ImGui %s :: %s", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, BGFX_API_VERSION, ImGui::GetVersion(), bgfx::getRendererName(bgfx::getRendererType()));
|
||||
bgfx::dbgTextPrintf(0, window_height/16 - 3, 0xf8, " %u FPS", stat->cpuTimerFreq / stat->cpuTimeFrame);
|
||||
bgfx::dbgTextPrintf(0, window_height/16 - 2, 0xf8, " Project Keishiki :: %s :: Build %s %s", BX_COMPILER_NAME, __DATE__, __TIME__);
|
||||
bgfx::dbgTextPrintf(0, window_height/16 - 1, 0xf8, " SDL %i.%i.%i :: bgfx 1.%i :: Dear ImGui %s :: %s", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL, BGFX_API_VERSION, ImGui::GetVersion(), bgfx::getRendererName(bgfx::getRendererType()));
|
||||
|
||||
bgfx::frame();
|
||||
}
|
||||
|
|
|
@ -21,18 +21,20 @@ namespace K::ShaderGraph {
|
|||
String var_to_string(const std::variant<i32, f32, String, RGBA, XYZ>& var) {
|
||||
return std::visit([](auto&& arg) -> String {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, i32> || std::is_same_v<T, f32>)
|
||||
if constexpr (std::is_same_v<T, T_Map<T_Int>::type>)
|
||||
return std::to_string(arg);
|
||||
else if constexpr (std::is_same_v<T, String>)
|
||||
else if constexpr (std::is_same_v<T, T_Map<T_Float>::type>)
|
||||
return std::to_string(arg) + "f";
|
||||
else if constexpr (std::is_same_v<T, T_Map<T_String>::type>)
|
||||
return arg;
|
||||
else if constexpr (std::is_same_v<T, RGBA>)
|
||||
else if constexpr (std::is_same_v<T, T_Map<T_RGBA>::type>)
|
||||
return "vec4(" + std::to_string(arg.r) + "," + std::to_string(arg.g) + "," + std::to_string(arg.b) + "," + std::to_string(arg.a) + ")";
|
||||
else if constexpr (std::is_same_v<T, XYZ>)
|
||||
else if constexpr (std::is_same_v<T, T_Map<T_XYZ>::type>)
|
||||
return "vec3(" + std::to_string(arg.x) + "," + std::to_string(arg.y) + "," + std::to_string(arg.z) + ")";
|
||||
}, var);
|
||||
}
|
||||
String ShaderGraph::generate_shader() const {
|
||||
if (RGBA_node->node->out[RGBA_node_out_index].first != Type::T_RGBA) return {};
|
||||
if (RGBA_node->node->out_types[RGBA_node_out_index] != Type::T_RGBA) return {};
|
||||
return build_node(*RGBA_node);
|
||||
}
|
||||
}
|
||||
|
|
155
Keishiki/UI.cpp
155
Keishiki/UI.cpp
|
@ -4,11 +4,13 @@
|
|||
#include "ext/imgui/misc/cpp/imgui_stdlib.h"
|
||||
#include <imgui.h>
|
||||
#include <imgui_internal.h>
|
||||
#include <misc/cpp/imgui_stdlib.h>
|
||||
#include <fstream>
|
||||
|
||||
namespace {
|
||||
static bool draw_viewport = true;
|
||||
static bool draw_sequencer = true;
|
||||
static bool draw_nodes = true;
|
||||
bool draw_viewport = true;
|
||||
bool draw_sequencer = true;
|
||||
bool draw_nodes = true;
|
||||
}
|
||||
|
||||
namespace ImGui {
|
||||
|
@ -23,7 +25,7 @@ namespace ImGui {
|
|||
}
|
||||
|
||||
namespace K::UI {
|
||||
void MainMenuBar(const State& s) {
|
||||
void MainMenuBar(const CompState& s) {
|
||||
if (ImGui::BeginMainMenuBar()) {
|
||||
//if (ImGui::BeginMenu("Edit")) {
|
||||
// if (ImGui::MenuItem("Undo", "CTRL+Z")) {}
|
||||
|
@ -44,21 +46,23 @@ namespace K::UI {
|
|||
}
|
||||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
void Viewport(State& s, Graphics::ImageTexture* mm, bgfx::FrameBufferHandle fb) {
|
||||
void Viewport(CompState& s, Graphics::ImageTexture* mm, bgfx::FrameBufferHandle fb) {
|
||||
if (ImGui::Begin("Viewport", &draw_viewport)) {
|
||||
ImTextureID idx = nullptr;
|
||||
// If we need new frame
|
||||
for (auto& layer : s.layers) {
|
||||
if (!layer.enabled) continue;
|
||||
bgfx::TextureHandle tx = layer.track.get_frame(0, mm, fb);
|
||||
bgfx::TextureHandle tx = layer.track.get_frame(0, mm, fb, s.width, s.height);
|
||||
idx = ImGui::toId(tx, 0, 0);
|
||||
}
|
||||
if (idx != nullptr)
|
||||
ImGui::Image(idx, ImVec2{ 800, 600 });
|
||||
|
||||
ImGui::Text("Comp Size: %ux%u", s.width, s.height);
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
void Sequencer(State& s){
|
||||
void Sequencer(CompState& s){
|
||||
if (ImGui::Begin("Sequencer", &draw_sequencer)) {
|
||||
if (ImGui::BeginTable("Layers", 5, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit)) {
|
||||
ImGui::TableSetupColumn("#", ImGuiTableColumnFlags_NoSort);
|
||||
|
@ -67,38 +71,37 @@ namespace K::UI {
|
|||
ImGui::TableSetupColumn("Enable", ImGuiTableColumnFlags_NoSort);
|
||||
ImGui::TableSetupColumn("##", ImGuiTableColumnFlags_NoSort);
|
||||
ImGui::TableHeadersRow();
|
||||
u32 c = 0;
|
||||
for (auto it = s.layers.begin(); it != s.layers.end(); it++, c++) {
|
||||
for (u32 i = 0; i < s.layers.size(); i++) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%u", c);
|
||||
ImGui::Text("%u", i);
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Selectable(it->name.c_str(), &it->selected)) {
|
||||
if (!ImGui::GetIO().KeyCtrl) // Clear selection when CTRL is not held
|
||||
for (auto jt = s.layers.begin(); jt != s.layers.end(); jt++) jt->selected = jt == it && jt->selected;
|
||||
if (ImGui::Selectable(s.layers[i].name.c_str(), &s.layers[i].selected)) {
|
||||
s.active = s.layers[i].selected ? &s.layers[i] : nullptr;
|
||||
// if (s.active != nullptr && ImGui::GetIO().KeyCtrl) // Clear selection when CTRL is not held
|
||||
// layers[i].selected = !layers[i].selected;
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
static i32 m = 0;
|
||||
ImGui::SetNextItemWidth(100.0f);
|
||||
if (ImGui::BeginCombo(("##Blending" + std::to_string(c)).c_str(), BlendingToString[it->mode])) {
|
||||
if (ImGui::BeginCombo(("##Blending" + std::to_string(i)).c_str(), BlendingToString[s.layers[i].mode])) {
|
||||
for (i32 b = K_V_Normal; b != K_V_Count; b++) {
|
||||
const bool is_selected = ((Blending)b == it->mode);
|
||||
const bool is_selected = ((Blending)b == s.layers[i].mode);
|
||||
if (ImGui::Selectable(BlendingToString[b], is_selected))
|
||||
it->mode = (Blending)b;
|
||||
s.layers[i].mode = (Blending)b;
|
||||
if (is_selected)
|
||||
ImGui::SetItemDefaultFocus();
|
||||
}
|
||||
ImGui::EndCombo();
|
||||
}
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Checkbox(("##Enable" + std::to_string(c)).c_str(), &it->enabled);
|
||||
ImGui::Checkbox(("##Enable" + std::to_string(i)).c_str(), &s.layers[i].enabled);
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
/*void Nodegraph(State& s) {
|
||||
/*void Nodegraph(CompState& s) {
|
||||
Layer* active = nullptr;
|
||||
u32 active_index = 0;
|
||||
while (active_index < s.layers.size()) {
|
||||
|
@ -243,42 +246,108 @@ namespace K::UI {
|
|||
}
|
||||
ImGui::End();
|
||||
}*/
|
||||
void Shader(State& s) {
|
||||
void Shader(CompState& s) {
|
||||
if (ImGui::Begin("Shader", &draw_nodes)) {
|
||||
static char text[1024 * 16] =
|
||||
"";
|
||||
if (s.active == nullptr)
|
||||
ImGui::Text("No active layer.");
|
||||
else {
|
||||
static int type_current = 0;
|
||||
static char text[8] = "";
|
||||
if (ImGui::Button("Add Uniform") && text[0] != '\0') { // todo LEAK!!
|
||||
s.active->track.add_uniform(text, ShaderGraph::expand_type(static_cast<ShaderGraph::Type>(type_current)));
|
||||
}
|
||||
ImGui::SameLine();
|
||||
ImGui::InputText("##UniformName", text, IM_ARRAYSIZE(text));
|
||||
|
||||
static ImGuiInputTextFlags flags = ImGuiInputTextFlags_AllowTabInput;
|
||||
ImGui::InputTextMultiline("##source", text, IM_ARRAYSIZE(text), ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 16), flags);
|
||||
static int clicked = 0;
|
||||
if (ImGui::Button("Submit Shader"))
|
||||
clicked++;
|
||||
if (clicked & 1) {
|
||||
clicked--;
|
||||
// Compile shader and assign
|
||||
auto f = std::fopen("temp.frag", "w");
|
||||
std::fprintf(f, text); // check errors!!
|
||||
std::fclose(f);
|
||||
if (std::system("./ext/bgfx/cmake/bgfx/shaderc "
|
||||
ImGui::SameLine();
|
||||
ImGui::Combo("Type", &type_current, ShaderGraph::Type_To_Str, ShaderGraph::T_Count);
|
||||
|
||||
if (ImGui::BeginTable("Uniforms", 4, ImGuiTableFlags_Borders | ImGuiTableFlags_SizingFixedFit)) {
|
||||
ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_NoSort);
|
||||
ImGui::TableSetupColumn("Type", ImGuiTableColumnFlags_NoSort);
|
||||
ImGui::TableSetupColumn("Value", ImGuiTableColumnFlags_NoSort);
|
||||
ImGui::TableSetupColumn("##del", ImGuiTableColumnFlags_NoSort);
|
||||
ImGui::TableHeadersRow();
|
||||
for (auto it = s.active->track.uniforms.begin(); it != s.active->track.uniforms.end();) {
|
||||
ImGui::TableNextRow();
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", it->first.c_str());
|
||||
ImGui::TableNextColumn();
|
||||
ImGui::Text("%s", ShaderGraph::Type_To_Str[it->second.second.index()]);
|
||||
ImGui::TableNextColumn();
|
||||
std::visit([it](auto&& arg) {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Int>::type>)
|
||||
ImGui::InputInt(("##" + it->first).c_str(), &arg);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Float>::type>)
|
||||
ImGui::DragFloat(("##" + it->first).c_str(), &arg, 0.005f);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_String>::type>)
|
||||
ImGui::InputText(("##" + it->first).c_str(), &arg);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_RGBA>::type>)
|
||||
ImGui::InputFloat4(("##" + it->first).c_str(), &arg.r);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_XYZ>::type>)
|
||||
ImGui::InputFloat3(("##" + it->first).c_str(), &arg.x);;
|
||||
}, it->second.second);
|
||||
ImGui::TableNextColumn();
|
||||
if (ImGui::Button("Delete Uniform")) {
|
||||
bgfx::destroy(it->second.first);
|
||||
it = s.active->track.uniforms.erase(it);
|
||||
}
|
||||
else it++;
|
||||
}
|
||||
ImGui::EndTable();
|
||||
}
|
||||
ImGui::Text("Editing Layer %u: %s", 0, s.active->name.c_str());
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui::InputTextMultiline("##source", &s.active->track.shader, ImVec2(-FLT_MIN, ImGui::GetTextLineHeight() * 24), ImGuiInputTextFlags_AllowTabInput);
|
||||
if (ImGui::Button("Submit Shader")) {
|
||||
// Compile shader and assign
|
||||
std::ofstream f("temp.frag");
|
||||
f << s.active->track.shader;
|
||||
f.close();
|
||||
if (std::system(
|
||||
#if BX_PLATFORM_WINDOWS
|
||||
"./ext/bgfx/cmake/bgfx/shaderc "
|
||||
"-f temp.frag "
|
||||
"--type fragment "
|
||||
"--platform windows "
|
||||
"--profile spirv "
|
||||
"--profile " "ps_5_0" " "
|
||||
"--varyingdef temp.varying.def.sc "
|
||||
"-i ./ "
|
||||
"-o shaders/spirv/temp.frag.bin") == 0) {
|
||||
if (isValid( s.layers[0].track.shader)) bgfx::destroy(s.layers[0].track.shader);
|
||||
s.layers[0].track.shader = Graphics::load_shader_program("temp"); // LEAK!!!
|
||||
"-o shaders/" "dx11" "/temp.frag.bin"
|
||||
#elif BX_PLATFORM_LINUX
|
||||
"./ext/bgfx/cmake/bgfx/shaderc "
|
||||
"-f temp.frag "
|
||||
"--type fragment "
|
||||
"--platform windows "
|
||||
"--profile " "spirv" " "
|
||||
"--varyingdef temp.varying.def.sc "
|
||||
"-i ./ "
|
||||
"-o shaders/" "spirv" "/temp.frag.bin"
|
||||
#elif BX_PLATFORM_OSX
|
||||
"./ext/bgfx/cmake/bgfx/shaderc "
|
||||
"-f temp.frag "
|
||||
"--type fragment "
|
||||
"--platform osx "
|
||||
"--profile " "metal" " "
|
||||
"--varyingdef temp.varying.def.sc "
|
||||
"-i ./ "
|
||||
"-o shaders/" "metal" "/temp.frag.bin"
|
||||
#endif
|
||||
) == 0) {
|
||||
if (isValid( s.layers[0].track.pg)) bgfx::destroy(s.layers[0].track.pg);
|
||||
s.layers[0].track.pg = Graphics::load_shader_program("temp"); // todo LEAK!!!
|
||||
}
|
||||
else
|
||||
Log("User shader compilation failed");
|
||||
}
|
||||
else
|
||||
Log("User shader compilation failed");
|
||||
}
|
||||
}
|
||||
ImGui::End();
|
||||
}
|
||||
void Draw(State& s, Graphics::ImageTexture* mm, bgfx::FrameBufferHandle fb) {
|
||||
//static ImGuiStyle& style = ImGui::GetStyle();
|
||||
//style.GrabRounding = style.FrameRounding = 15.0f;
|
||||
void Draw(CompState& s, Graphics::ImageTexture* mm, bgfx::FrameBufferHandle fb) {
|
||||
static ImGuiStyle& style = ImGui::GetStyle();
|
||||
style.GrabRounding = style.FrameRounding = 15.0f;
|
||||
MainMenuBar(s);
|
||||
if (draw_viewport) Viewport(s, mm, fb);
|
||||
if (draw_nodes) Shader(s);
|
||||
|
|
|
@ -6,6 +6,11 @@
|
|||
#include <bgfx/bgfx.h>
|
||||
|
||||
namespace K::Graphics {
|
||||
enum VIEW_ID {
|
||||
K_VIEW_TOP = 0,
|
||||
K_VIEW_DRAW = 5
|
||||
};
|
||||
|
||||
bool Init(u16 width, u16 height);
|
||||
void Shutdown();
|
||||
|
||||
|
@ -22,8 +27,6 @@ namespace K::Graphics {
|
|||
void DrawTextureImageAlpha(u32 view_id, const ImageTexture& 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);
|
||||
|
||||
void TEMP_SetAlpha(f32 alpha);
|
||||
|
||||
// Text
|
||||
void WalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y);
|
||||
void RenderWalkGlyph(u32 view_id, Char c, i32& pos_x, i32& pos_y, u32 col);
|
||||
|
|
|
@ -24,10 +24,12 @@ namespace K {
|
|||
Blending mode;
|
||||
};
|
||||
|
||||
struct State {
|
||||
u64 frame;
|
||||
struct CompState {
|
||||
u64 current_frame;
|
||||
u64 frame_max;
|
||||
u32 fps;
|
||||
u32 width, height;
|
||||
Vector<Layer> layers;
|
||||
Layer* active = nullptr;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -47,6 +47,11 @@ namespace K::ShaderGraph {
|
|||
};
|
||||
String var_to_string(const std::variant<i32, f32, String, RGBA, XYZ>& var);
|
||||
|
||||
inline T_Map<T_Count>::type expand_type(Type i) {
|
||||
static constexpr T_Map<T_Count>::type table[] = {i32{}, f32{}, String{}, ShaderGraph::RGBA{}, ShaderGraph::XYZ{}};
|
||||
return table[i];
|
||||
}
|
||||
|
||||
struct Node;
|
||||
struct InSlot {
|
||||
String name;
|
||||
|
@ -55,7 +60,8 @@ namespace K::ShaderGraph {
|
|||
struct Node {
|
||||
String name;
|
||||
Vector<InSlot> inputs;
|
||||
Vector<std::pair<Type, String>> out;
|
||||
Vector<String> out;
|
||||
Vector<Type> out_types;
|
||||
String shader_template;
|
||||
Vector<String> extra_uniforms;
|
||||
};
|
||||
|
|
|
@ -4,8 +4,10 @@
|
|||
#include "Graphics.h"
|
||||
#include "VisualTrack.h"
|
||||
|
||||
namespace K::UI {
|
||||
void Draw(State& s, Graphics::ImageTexture* mm, bgfx::FrameBufferHandle fb);
|
||||
#include "backends/imgui_impl_sdl2.h"
|
||||
#include "imgui_impl_bgfx.h"
|
||||
|
||||
namespace K::UI {
|
||||
void Draw(CompState& s, Graphics::ImageTexture* mm, bgfx::FrameBufferHandle fb);
|
||||
|
||||
}
|
||||
|
|
|
@ -18,25 +18,55 @@ namespace K {
|
|||
|
||||
struct VisualTrack {
|
||||
ShaderGraph::ShaderGraph tree;
|
||||
bgfx::ProgramHandle shader = { bgfx::kInvalidHandle };
|
||||
bgfx::TextureHandle get_frame(u64 time, Graphics::ImageTexture* mm, bgfx::FrameBufferHandle fb) {
|
||||
static u32 mmid = 5;
|
||||
bgfx::touch(mmid);
|
||||
bgfx::setViewMode(mmid, bgfx::ViewMode::Sequential);
|
||||
bgfx::setViewClear(mmid, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
|
||||
bgfx::setViewFrameBuffer(mmid, fb);
|
||||
bgfx::ProgramHandle pg = BGFX_INVALID_HANDLE;
|
||||
String shader{};
|
||||
Dict<String, std::pair<bgfx::UniformHandle, ShaderGraph::T_Map<ShaderGraph::T_Count>::type>> uniforms;
|
||||
bgfx::TextureHandle get_frame(u64 time, Graphics::ImageTexture* mm, bgfx::FrameBufferHandle fb, u32 w, u32 h) const {
|
||||
bgfx::touch(K::Graphics::K_VIEW_DRAW);
|
||||
bgfx::setViewMode(K::Graphics::K_VIEW_DRAW, bgfx::ViewMode::Sequential);
|
||||
bgfx::setViewClear(K::Graphics::K_VIEW_DRAW, BGFX_CLEAR_COLOR | BGFX_CLEAR_DEPTH, 0x00000000, 1.0f, 0);
|
||||
bgfx::setViewFrameBuffer(K::Graphics::K_VIEW_DRAW, fb);
|
||||
float view[16];
|
||||
bx::mtxTranslate(view, 0.f, 0.f, 1.0f);
|
||||
float proj[16];
|
||||
bx::mtxOrtho(proj, 0.0f, 800, 0.0f, 600, 0.1f, 100.0f, 0.f, bgfx::getCaps()->homogeneousDepth);
|
||||
bgfx::setViewTransform(mmid, view, proj);
|
||||
bgfx::setViewRect(mmid, 0, 0, 800, 600);
|
||||
// set uniforms
|
||||
Graphics::TEMP_SetAlpha(1.0);
|
||||
Graphics::DrawTexture(mmid, Graphics::mmaker->tx, 0, 0, 800, 600, (BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) & ~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), shader);
|
||||
bx::mtxOrtho(proj, 0.0f, static_cast<f32>(w), 0.0f, static_cast<f32>(h),
|
||||
0.1f, 100.0f, 0.f, bgfx::getCaps()->homogeneousDepth);
|
||||
bgfx::setViewTransform(K::Graphics::K_VIEW_DRAW, view, proj);
|
||||
bgfx::setViewRect(K::Graphics::K_VIEW_DRAW, 0, 0, w, h);
|
||||
// TODO Find a better way to pack...
|
||||
for (auto& [_name, u] : uniforms) {
|
||||
f32 pack[4]{};
|
||||
std::visit([&pack](auto&& arg) {
|
||||
using T = std::decay_t<decltype(arg)>;
|
||||
if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Int>::type> || std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_Float>::type>)
|
||||
pack[0] = static_cast<f32>(arg);
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_String>::type>)
|
||||
LogError("String passed to shader, verify specification."); // ??? damn bro
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_RGBA>::type>) {
|
||||
pack[0] = arg.r;
|
||||
pack[1] = arg.g;
|
||||
pack[2] = arg.b;
|
||||
pack[3] = arg.a;
|
||||
}
|
||||
else if constexpr (std::is_same_v<T, ShaderGraph::T_Map<ShaderGraph::T_XYZ>::type>){
|
||||
pack[0] = arg.x;
|
||||
pack[1] = arg.y;
|
||||
pack[2] = arg.z;
|
||||
}
|
||||
}, u.second);
|
||||
bgfx::setUniform(u.first, pack);
|
||||
}
|
||||
|
||||
Graphics::DrawTexture(K::Graphics::K_VIEW_DRAW, Graphics::mmaker->tx, 0, 0, w, h,
|
||||
(BGFX_STATE_DEFAULT | BGFX_STATE_BLEND_ALPHA) &
|
||||
~(BGFX_STATE_WRITE_Z | BGFX_STATE_DEPTH_TEST_LESS), pg);
|
||||
return bgfx::getTexture(fb);
|
||||
}
|
||||
};
|
||||
void add_uniform(const String& s, ShaderGraph::T_Map<ShaderGraph::T_Count>::type&& val) {
|
||||
if (!uniforms.contains(s))
|
||||
uniforms.emplace(s, std::make_pair(bgfx::createUniform(s.c_str(), bgfx::UniformType::Vec4), std::move(val)));
|
||||
}
|
||||
};
|
||||
|
||||
void Composite();
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -1,627 +0,0 @@
|
|||
// [DEAR IMGUI]
|
||||
// This is a slightly modified version of stb_rect_pack.h 1.01.
|
||||
// Grep for [DEAR IMGUI] to find the changes.
|
||||
//
|
||||
// stb_rect_pack.h - v1.01 - public domain - rectangle packing
|
||||
// Sean Barrett 2014
|
||||
//
|
||||
// Useful for e.g. packing rectangular textures into an atlas.
|
||||
// Does not do rotation.
|
||||
//
|
||||
// Before #including,
|
||||
//
|
||||
// #define STB_RECT_PACK_IMPLEMENTATION
|
||||
//
|
||||
// in the file that you want to have the implementation.
|
||||
//
|
||||
// Not necessarily the awesomest packing method, but better than
|
||||
// the totally naive one in stb_truetype (which is primarily what
|
||||
// this is meant to replace).
|
||||
//
|
||||
// Has only had a few tests run, may have issues.
|
||||
//
|
||||
// More docs to come.
|
||||
//
|
||||
// No memory allocations; uses qsort() and assert() from stdlib.
|
||||
// Can override those by defining STBRP_SORT and STBRP_ASSERT.
|
||||
//
|
||||
// This library currently uses the Skyline Bottom-Left algorithm.
|
||||
//
|
||||
// Please note: better rectangle packers are welcome! Please
|
||||
// implement them to the same API, but with a different init
|
||||
// function.
|
||||
//
|
||||
// Credits
|
||||
//
|
||||
// Library
|
||||
// Sean Barrett
|
||||
// Minor features
|
||||
// Martins Mozeiko
|
||||
// github:IntellectualKitty
|
||||
//
|
||||
// Bugfixes / warning fixes
|
||||
// Jeremy Jaussaud
|
||||
// Fabian Giesen
|
||||
//
|
||||
// Version history:
|
||||
//
|
||||
// 1.01 (2021-07-11) always use large rect mode, expose STBRP__MAXVAL in public section
|
||||
// 1.00 (2019-02-25) avoid small space waste; gracefully fail too-wide rectangles
|
||||
// 0.99 (2019-02-07) warning fixes
|
||||
// 0.11 (2017-03-03) return packing success/fail result
|
||||
// 0.10 (2016-10-25) remove cast-away-const to avoid warnings
|
||||
// 0.09 (2016-08-27) fix compiler warnings
|
||||
// 0.08 (2015-09-13) really fix bug with empty rects (w=0 or h=0)
|
||||
// 0.07 (2015-09-13) fix bug with empty rects (w=0 or h=0)
|
||||
// 0.06 (2015-04-15) added STBRP_SORT to allow replacing qsort
|
||||
// 0.05: added STBRP_ASSERT to allow replacing assert
|
||||
// 0.04: fixed minor bug in STBRP_LARGE_RECTS support
|
||||
// 0.01: initial release
|
||||
//
|
||||
// LICENSE
|
||||
//
|
||||
// See end of file for license information.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// INCLUDE SECTION
|
||||
//
|
||||
|
||||
#ifndef STB_INCLUDE_STB_RECT_PACK_H
|
||||
#define STB_INCLUDE_STB_RECT_PACK_H
|
||||
|
||||
#define STB_RECT_PACK_VERSION 1
|
||||
|
||||
#ifdef STBRP_STATIC
|
||||
#define STBRP_DEF static
|
||||
#else
|
||||
#define STBRP_DEF extern
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct stbrp_context stbrp_context;
|
||||
typedef struct stbrp_node stbrp_node;
|
||||
typedef struct stbrp_rect stbrp_rect;
|
||||
|
||||
typedef int stbrp_coord;
|
||||
|
||||
#define STBRP__MAXVAL 0x7fffffff
|
||||
// Mostly for internal use, but this is the maximum supported coordinate value.
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects (stbrp_context *context, stbrp_rect *rects, int num_rects);
|
||||
// Assign packed locations to rectangles. The rectangles are of type
|
||||
// 'stbrp_rect' defined below, stored in the array 'rects', and there
|
||||
// are 'num_rects' many of them.
|
||||
//
|
||||
// Rectangles which are successfully packed have the 'was_packed' flag
|
||||
// set to a non-zero value and 'x' and 'y' store the minimum location
|
||||
// on each axis (i.e. bottom-left in cartesian coordinates, top-left
|
||||
// if you imagine y increasing downwards). Rectangles which do not fit
|
||||
// have the 'was_packed' flag set to 0.
|
||||
//
|
||||
// You should not try to access the 'rects' array from another thread
|
||||
// while this function is running, as the function temporarily reorders
|
||||
// the array while it executes.
|
||||
//
|
||||
// To pack into another rectangle, you need to call stbrp_init_target
|
||||
// again. To continue packing into the same rectangle, you can call
|
||||
// this function again. Calling this multiple times with multiple rect
|
||||
// arrays will probably produce worse packing results than calling it
|
||||
// a single time with the full rectangle array, but the option is
|
||||
// available.
|
||||
//
|
||||
// The function returns 1 if all of the rectangles were successfully
|
||||
// packed and 0 otherwise.
|
||||
|
||||
struct stbrp_rect
|
||||
{
|
||||
// reserved for your use:
|
||||
int id;
|
||||
|
||||
// input:
|
||||
stbrp_coord w, h;
|
||||
|
||||
// output:
|
||||
stbrp_coord x, y;
|
||||
int was_packed; // non-zero if valid packing
|
||||
|
||||
}; // 16 bytes, nominally
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_init_target (stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes);
|
||||
// Initialize a rectangle packer to:
|
||||
// pack a rectangle that is 'width' by 'height' in dimensions
|
||||
// using temporary storage provided by the array 'nodes', which is 'num_nodes' long
|
||||
//
|
||||
// You must call this function every time you start packing into a new target.
|
||||
//
|
||||
// There is no "shutdown" function. The 'nodes' memory must stay valid for
|
||||
// the following stbrp_pack_rects() call (or calls), but can be freed after
|
||||
// the call (or calls) finish.
|
||||
//
|
||||
// Note: to guarantee best results, either:
|
||||
// 1. make sure 'num_nodes' >= 'width'
|
||||
// or 2. call stbrp_allow_out_of_mem() defined below with 'allow_out_of_mem = 1'
|
||||
//
|
||||
// If you don't do either of the above things, widths will be quantized to multiples
|
||||
// of small integers to guarantee the algorithm doesn't run out of temporary storage.
|
||||
//
|
||||
// If you do #2, then the non-quantized algorithm will be used, but the algorithm
|
||||
// may run out of temporary storage and be unable to pack some rectangles.
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem (stbrp_context *context, int allow_out_of_mem);
|
||||
// Optionally call this function after init but before doing any packing to
|
||||
// change the handling of the out-of-temp-memory scenario, described above.
|
||||
// If you call init again, this will be reset to the default (false).
|
||||
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic (stbrp_context *context, int heuristic);
|
||||
// Optionally select which packing heuristic the library should use. Different
|
||||
// heuristics will produce better/worse results for different data sets.
|
||||
// If you call init again, this will be reset to the default.
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP_HEURISTIC_Skyline_default=0,
|
||||
STBRP_HEURISTIC_Skyline_BL_sortHeight = STBRP_HEURISTIC_Skyline_default,
|
||||
STBRP_HEURISTIC_Skyline_BF_sortHeight
|
||||
};
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// the details of the following structures don't matter to you, but they must
|
||||
// be visible so you can handle the memory allocations for them
|
||||
|
||||
struct stbrp_node
|
||||
{
|
||||
stbrp_coord x,y;
|
||||
stbrp_node *next;
|
||||
};
|
||||
|
||||
struct stbrp_context
|
||||
{
|
||||
int width;
|
||||
int height;
|
||||
int align;
|
||||
int init_mode;
|
||||
int heuristic;
|
||||
int num_nodes;
|
||||
stbrp_node *active_head;
|
||||
stbrp_node *free_head;
|
||||
stbrp_node extra[2]; // we allocate two extra nodes so optimal user-node-count is 'width' not 'width+2'
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPLEMENTATION SECTION
|
||||
//
|
||||
|
||||
#ifdef STB_RECT_PACK_IMPLEMENTATION
|
||||
#ifndef STBRP_SORT
|
||||
#include <stdlib.h>
|
||||
#define STBRP_SORT qsort
|
||||
#endif
|
||||
|
||||
#ifndef STBRP_ASSERT
|
||||
#include <assert.h>
|
||||
#define STBRP_ASSERT assert
|
||||
#endif
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define STBRP__NOTUSED(v) (void)(v)
|
||||
#define STBRP__CDECL __cdecl
|
||||
#else
|
||||
#define STBRP__NOTUSED(v) (void)sizeof(v)
|
||||
#define STBRP__CDECL
|
||||
#endif
|
||||
|
||||
enum
|
||||
{
|
||||
STBRP__INIT_skyline = 1
|
||||
};
|
||||
|
||||
STBRP_DEF void stbrp_setup_heuristic(stbrp_context *context, int heuristic)
|
||||
{
|
||||
switch (context->init_mode) {
|
||||
case STBRP__INIT_skyline:
|
||||
STBRP_ASSERT(heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight || heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight);
|
||||
context->heuristic = heuristic;
|
||||
break;
|
||||
default:
|
||||
STBRP_ASSERT(0);
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_setup_allow_out_of_mem(stbrp_context *context, int allow_out_of_mem)
|
||||
{
|
||||
if (allow_out_of_mem)
|
||||
// if it's ok to run out of memory, then don't bother aligning them;
|
||||
// this gives better packing, but may fail due to OOM (even though
|
||||
// the rectangles easily fit). @TODO a smarter approach would be to only
|
||||
// quantize once we've hit OOM, then we could get rid of this parameter.
|
||||
context->align = 1;
|
||||
else {
|
||||
// if it's not ok to run out of memory, then quantize the widths
|
||||
// so that num_nodes is always enough nodes.
|
||||
//
|
||||
// I.e. num_nodes * align >= width
|
||||
// align >= width / num_nodes
|
||||
// align = ceil(width/num_nodes)
|
||||
|
||||
context->align = (context->width + context->num_nodes-1) / context->num_nodes;
|
||||
}
|
||||
}
|
||||
|
||||
STBRP_DEF void stbrp_init_target(stbrp_context *context, int width, int height, stbrp_node *nodes, int num_nodes)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i < num_nodes-1; ++i)
|
||||
nodes[i].next = &nodes[i+1];
|
||||
nodes[i].next = NULL;
|
||||
context->init_mode = STBRP__INIT_skyline;
|
||||
context->heuristic = STBRP_HEURISTIC_Skyline_default;
|
||||
context->free_head = &nodes[0];
|
||||
context->active_head = &context->extra[0];
|
||||
context->width = width;
|
||||
context->height = height;
|
||||
context->num_nodes = num_nodes;
|
||||
stbrp_setup_allow_out_of_mem(context, 0);
|
||||
|
||||
// node 0 is the full width, node 1 is the sentinel (lets us not store width explicitly)
|
||||
context->extra[0].x = 0;
|
||||
context->extra[0].y = 0;
|
||||
context->extra[0].next = &context->extra[1];
|
||||
context->extra[1].x = (stbrp_coord) width;
|
||||
context->extra[1].y = (1<<30);
|
||||
context->extra[1].next = NULL;
|
||||
}
|
||||
|
||||
// find minimum y position if it starts at x1
|
||||
static int stbrp__skyline_find_min_y(stbrp_context *c, stbrp_node *first, int x0, int width, int *pwaste)
|
||||
{
|
||||
stbrp_node *node = first;
|
||||
int x1 = x0 + width;
|
||||
int min_y, visited_width, waste_area;
|
||||
|
||||
STBRP__NOTUSED(c);
|
||||
|
||||
STBRP_ASSERT(first->x <= x0);
|
||||
|
||||
#if 0
|
||||
// skip in case we're past the node
|
||||
while (node->next->x <= x0)
|
||||
++node;
|
||||
#else
|
||||
STBRP_ASSERT(node->next->x > x0); // we ended up handling this in the caller for efficiency
|
||||
#endif
|
||||
|
||||
STBRP_ASSERT(node->x <= x0);
|
||||
|
||||
min_y = 0;
|
||||
waste_area = 0;
|
||||
visited_width = 0;
|
||||
while (node->x < x1) {
|
||||
if (node->y > min_y) {
|
||||
// raise min_y higher.
|
||||
// we've accounted for all waste up to min_y,
|
||||
// but we'll now add more waste for everything we've visted
|
||||
waste_area += visited_width * (node->y - min_y);
|
||||
min_y = node->y;
|
||||
// the first time through, visited_width might be reduced
|
||||
if (node->x < x0)
|
||||
visited_width += node->next->x - x0;
|
||||
else
|
||||
visited_width += node->next->x - node->x;
|
||||
} else {
|
||||
// add waste area
|
||||
int under_width = node->next->x - node->x;
|
||||
if (under_width + visited_width > width)
|
||||
under_width = width - visited_width;
|
||||
waste_area += under_width * (min_y - node->y);
|
||||
visited_width += under_width;
|
||||
}
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
*pwaste = waste_area;
|
||||
return min_y;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int x,y;
|
||||
stbrp_node **prev_link;
|
||||
} stbrp__findresult;
|
||||
|
||||
static stbrp__findresult stbrp__skyline_find_best_pos(stbrp_context *c, int width, int height)
|
||||
{
|
||||
int best_waste = (1<<30), best_x, best_y = (1 << 30);
|
||||
stbrp__findresult fr;
|
||||
stbrp_node **prev, *node, *tail, **best = NULL;
|
||||
|
||||
// align to multiple of c->align
|
||||
width = (width + c->align - 1);
|
||||
width -= width % c->align;
|
||||
STBRP_ASSERT(width % c->align == 0);
|
||||
|
||||
// if it can't possibly fit, bail immediately
|
||||
if (width > c->width || height > c->height) {
|
||||
fr.prev_link = NULL;
|
||||
fr.x = fr.y = 0;
|
||||
return fr;
|
||||
}
|
||||
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
while (node->x + width <= c->width) {
|
||||
int y,waste;
|
||||
y = stbrp__skyline_find_min_y(c, node, node->x, width, &waste);
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BL_sortHeight) { // actually just want to test BL
|
||||
// bottom left
|
||||
if (y < best_y) {
|
||||
best_y = y;
|
||||
best = prev;
|
||||
}
|
||||
} else {
|
||||
// best-fit
|
||||
if (y + height <= c->height) {
|
||||
// can only use it if it first vertically
|
||||
if (y < best_y || (y == best_y && waste < best_waste)) {
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
|
||||
best_x = (best == NULL) ? 0 : (*best)->x;
|
||||
|
||||
// if doing best-fit (BF), we also have to try aligning right edge to each node position
|
||||
//
|
||||
// e.g, if fitting
|
||||
//
|
||||
// ____________________
|
||||
// |____________________|
|
||||
//
|
||||
// into
|
||||
//
|
||||
// | |
|
||||
// | ____________|
|
||||
// |____________|
|
||||
//
|
||||
// then right-aligned reduces waste, but bottom-left BL is always chooses left-aligned
|
||||
//
|
||||
// This makes BF take about 2x the time
|
||||
|
||||
if (c->heuristic == STBRP_HEURISTIC_Skyline_BF_sortHeight) {
|
||||
tail = c->active_head;
|
||||
node = c->active_head;
|
||||
prev = &c->active_head;
|
||||
// find first node that's admissible
|
||||
while (tail->x < width)
|
||||
tail = tail->next;
|
||||
while (tail) {
|
||||
int xpos = tail->x - width;
|
||||
int y,waste;
|
||||
STBRP_ASSERT(xpos >= 0);
|
||||
// find the left position that matches this
|
||||
while (node->next->x <= xpos) {
|
||||
prev = &node->next;
|
||||
node = node->next;
|
||||
}
|
||||
STBRP_ASSERT(node->next->x > xpos && node->x <= xpos);
|
||||
y = stbrp__skyline_find_min_y(c, node, xpos, width, &waste);
|
||||
if (y + height <= c->height) {
|
||||
if (y <= best_y) {
|
||||
if (y < best_y || waste < best_waste || (waste==best_waste && xpos < best_x)) {
|
||||
best_x = xpos;
|
||||
//STBRP_ASSERT(y <= best_y); [DEAR IMGUI]
|
||||
best_y = y;
|
||||
best_waste = waste;
|
||||
best = prev;
|
||||
}
|
||||
}
|
||||
}
|
||||
tail = tail->next;
|
||||
}
|
||||
}
|
||||
|
||||
fr.prev_link = best;
|
||||
fr.x = best_x;
|
||||
fr.y = best_y;
|
||||
return fr;
|
||||
}
|
||||
|
||||
static stbrp__findresult stbrp__skyline_pack_rectangle(stbrp_context *context, int width, int height)
|
||||
{
|
||||
// find best position according to heuristic
|
||||
stbrp__findresult res = stbrp__skyline_find_best_pos(context, width, height);
|
||||
stbrp_node *node, *cur;
|
||||
|
||||
// bail if:
|
||||
// 1. it failed
|
||||
// 2. the best node doesn't fit (we don't always check this)
|
||||
// 3. we're out of memory
|
||||
if (res.prev_link == NULL || res.y + height > context->height || context->free_head == NULL) {
|
||||
res.prev_link = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
// on success, create new node
|
||||
node = context->free_head;
|
||||
node->x = (stbrp_coord) res.x;
|
||||
node->y = (stbrp_coord) (res.y + height);
|
||||
|
||||
context->free_head = node->next;
|
||||
|
||||
// insert the new node into the right starting point, and
|
||||
// let 'cur' point to the remaining nodes needing to be
|
||||
// stiched back in
|
||||
|
||||
cur = *res.prev_link;
|
||||
if (cur->x < res.x) {
|
||||
// preserve the existing one, so start testing with the next one
|
||||
stbrp_node *next = cur->next;
|
||||
cur->next = node;
|
||||
cur = next;
|
||||
} else {
|
||||
*res.prev_link = node;
|
||||
}
|
||||
|
||||
// from here, traverse cur and free the nodes, until we get to one
|
||||
// that shouldn't be freed
|
||||
while (cur->next && cur->next->x <= res.x + width) {
|
||||
stbrp_node *next = cur->next;
|
||||
// move the current node to the free list
|
||||
cur->next = context->free_head;
|
||||
context->free_head = cur;
|
||||
cur = next;
|
||||
}
|
||||
|
||||
// stitch the list back in
|
||||
node->next = cur;
|
||||
|
||||
if (cur->x < res.x + width)
|
||||
cur->x = (stbrp_coord) (res.x + width);
|
||||
|
||||
#ifdef _DEBUG
|
||||
cur = context->active_head;
|
||||
while (cur->x < context->width) {
|
||||
STBRP_ASSERT(cur->x < cur->next->x);
|
||||
cur = cur->next;
|
||||
}
|
||||
STBRP_ASSERT(cur->next == NULL);
|
||||
|
||||
{
|
||||
int count=0;
|
||||
cur = context->active_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
cur = context->free_head;
|
||||
while (cur) {
|
||||
cur = cur->next;
|
||||
++count;
|
||||
}
|
||||
STBRP_ASSERT(count == context->num_nodes+2);
|
||||
}
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_height_compare(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
if (p->h > q->h)
|
||||
return -1;
|
||||
if (p->h < q->h)
|
||||
return 1;
|
||||
return (p->w > q->w) ? -1 : (p->w < q->w);
|
||||
}
|
||||
|
||||
static int STBRP__CDECL rect_original_order(const void *a, const void *b)
|
||||
{
|
||||
const stbrp_rect *p = (const stbrp_rect *) a;
|
||||
const stbrp_rect *q = (const stbrp_rect *) b;
|
||||
return (p->was_packed < q->was_packed) ? -1 : (p->was_packed > q->was_packed);
|
||||
}
|
||||
|
||||
STBRP_DEF int stbrp_pack_rects(stbrp_context *context, stbrp_rect *rects, int num_rects)
|
||||
{
|
||||
int i, all_rects_packed = 1;
|
||||
|
||||
// we use the 'was_packed' field internally to allow sorting/unsorting
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = i;
|
||||
}
|
||||
|
||||
// sort according to heuristic
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_height_compare);
|
||||
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
if (rects[i].w == 0 || rects[i].h == 0) {
|
||||
rects[i].x = rects[i].y = 0; // empty rect needs no space
|
||||
} else {
|
||||
stbrp__findresult fr = stbrp__skyline_pack_rectangle(context, rects[i].w, rects[i].h);
|
||||
if (fr.prev_link) {
|
||||
rects[i].x = (stbrp_coord) fr.x;
|
||||
rects[i].y = (stbrp_coord) fr.y;
|
||||
} else {
|
||||
rects[i].x = rects[i].y = STBRP__MAXVAL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// unsort
|
||||
STBRP_SORT(rects, num_rects, sizeof(rects[0]), rect_original_order);
|
||||
|
||||
// set was_packed flags and all_rects_packed status
|
||||
for (i=0; i < num_rects; ++i) {
|
||||
rects[i].was_packed = !(rects[i].x == STBRP__MAXVAL && rects[i].y == STBRP__MAXVAL);
|
||||
if (!rects[i].was_packed)
|
||||
all_rects_packed = 0;
|
||||
}
|
||||
|
||||
// return the all_rects_packed status
|
||||
return all_rects_packed;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
------------------------------------------------------------------------------
|
||||
This software is available under 2 licenses -- choose whichever you prefer.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE A - MIT License
|
||||
Copyright (c) 2017 Sean Barrett
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||
of the Software, and to permit persons to whom the Software is furnished to do
|
||||
so, subject to the following conditions:
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
ALTERNATIVE B - Public Domain (www.unlicense.org)
|
||||
This is free and unencumbered software released into the public domain.
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or distribute this
|
||||
software, either in source code form or as a compiled binary, for any purpose,
|
||||
commercial or non-commercial, and by any means.
|
||||
In jurisdictions that recognize copyright laws, the author or authors of this
|
||||
software dedicate any and all copyright interest in the software to the public
|
||||
domain. We make this dedication for the benefit of the public at large and to
|
||||
the detriment of our heirs and successors. We intend this dedication to be an
|
||||
overt act of relinquishment in perpetuity of all present and future rights to
|
||||
this software under copyright law.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||||
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
------------------------------------------------------------------------------
|
||||
*/
|
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
13
Keishiki/shaders/BinaryComposite/BinaryComposite.frag
Normal file
13
Keishiki/shaders/BinaryComposite/BinaryComposite.frag
Normal file
|
@ -0,0 +1,13 @@
|
|||
$input v_texcoord0
|
||||
|
||||
#include <bgfx_shader.sh>
|
||||
#include <shaderlib.sh>
|
||||
|
||||
SAMPLER2D(A, 0);
|
||||
SAMPLER2D(B, 0);
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 uv = vec2(v_texcoord0.x, 1.0f - v_texcoord0.y);
|
||||
gl_FragColor = texture2D(A, uv) + texture2D(B, uv).a;
|
||||
}
|
0
Keishiki/shaders/BinaryComposite/BinaryComposite.vert
Normal file
0
Keishiki/shaders/BinaryComposite/BinaryComposite.vert
Normal file
4
Keishiki/shaders/BinaryComposite/varying.def.sc
Normal file
4
Keishiki/shaders/BinaryComposite/varying.def.sc
Normal file
|
@ -0,0 +1,4 @@
|
|||
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||
|
||||
vec3 a_position : POSITION;
|
||||
vec2 a_texcoord0 : TEXCOORD0;
|
10
Keishiki/shaders/Checkerboard/Checkerboard.frag
Normal file
10
Keishiki/shaders/Checkerboard/Checkerboard.frag
Normal file
|
@ -0,0 +1,10 @@
|
|||
$input v_texcoord0
|
||||
|
||||
#include <bgfx_shader.sh>
|
||||
#include <shaderlib.sh>
|
||||
|
||||
void main()
|
||||
{
|
||||
vec2 uv = vec2(v_texcoord0.x, 1.0f - v_texcoord0.y) * 100.0f;
|
||||
gl_FragColor = ceil((uv - floor(uv)) - 0.5f);
|
||||
}
|
11
Keishiki/shaders/Checkerboard/Checkerboard.vert
Normal file
11
Keishiki/shaders/Checkerboard/Checkerboard.vert
Normal file
|
@ -0,0 +1,11 @@
|
|||
$input a_position, a_texcoord0
|
||||
$output v_texcoord0
|
||||
|
||||
#include <bgfx_shader.sh>
|
||||
#include <shaderlib.sh>
|
||||
|
||||
void main()
|
||||
{
|
||||
gl_Position = mul(u_modelViewProj, vec4(a_position, 1.0));
|
||||
v_texcoord0 = a_texcoord0;
|
||||
}
|
4
Keishiki/shaders/Checkerboard/varying.def.sc
Normal file
4
Keishiki/shaders/Checkerboard/varying.def.sc
Normal file
|
@ -0,0 +1,4 @@
|
|||
vec2 v_texcoord0 : TEXCOORD0 = vec2(0.0, 0.0);
|
||||
|
||||
vec3 a_position : POSITION;
|
||||
vec2 a_texcoord0 : TEXCOORD0;
|
12
README.md
12
README.md
|
@ -1,2 +1,10 @@
|
|||
# Keishiki
|
||||

|
||||
<img src="Keishiki.webp" alt="Logo" width="300"/>
|
||||
|
||||
# Keishiki Compositor-Sequencer
|
||||
|
||||
## Libraries
|
||||
- [SDL2](https://www.libsdl.org/)
|
||||
- [bgfx](https://github.com/bkaradzic/bgfx)
|
||||
- [Dear ImGui](https://github.com/ocornut/imgui)
|
||||
- [imgui_impl_bgfx](https://gist.github.com/pr0g/aff79b71bf9804ddb03f39ca7c0c3bbb)
|
||||
- [SRELL](https://www.akenotsuki.com/misc/srell/en/)
|
||||
|
|
18
TODO.md
Normal file
18
TODO.md
Normal file
|
@ -0,0 +1,18 @@
|
|||
## Compositor
|
||||
- BinaryComposite
|
||||
- Manage Samplers
|
||||
- Data model for comps
|
||||
- Dump state, non-POD needs serialization!!!
|
||||
|
||||
## UI
|
||||
- Sequencer timeline init
|
||||
- Node editor
|
||||
- Viewport Gizmos (https://github.com/CedricGuillemet/ImGuizmo)
|
||||
- Shader nodes (https://github.com/CedricGuillemet/ImGuizmo)
|
||||
|
||||
## Audio
|
||||
- init (SDL_Mixer?)
|
||||
|
||||
## IO
|
||||
- PNG Export
|
||||
- Video import (research opencv libavcodec etc)
|
Loading…
Add table
Reference in a new issue