summaryrefslogtreecommitdiff
path: root/editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor.cpp')
-rw-r--r--editor.cpp66
1 files changed, 54 insertions, 12 deletions
diff --git a/editor.cpp b/editor.cpp
index a06c4a9..455b194 100644
--- a/editor.cpp
+++ b/editor.cpp
@@ -10,10 +10,30 @@
extern "C" {
#include "memory.h"
#include "plat.h"
+#include "str.h"
}
#include <stdio.h>
#include <vector>
+#include <unordered_map>
+
+template<>
+struct std::hash<Pipeline> {
+ size_t operator()(const Pipeline& k) const {
+ return (size_t)fnv1a64_2(
+ k.pipeline_hash,
+ (uint8_t*)&k.descriptor_resource_hash,
+ sizeof k.descriptor_resource_hash
+ );
+ }
+};
+
+static bool operator==(const Pipeline& a, const Pipeline& b) {
+ return
+ a.pipeline_eq(b) &&
+ a.desc_layout_eq(b) &&
+ a.desc_resources_eq(b);
+}
struct Editor_PD : Physics_Debughook {
void shrinkwrap(
@@ -32,6 +52,8 @@ struct Editor_PD : Physics_Debughook {
};
struct Editor_DD : Device_Debug_Hooks {
+ void on_pso_create(const Pipeline& pso) override;
+ void on_pso_destroy(const Pipeline& pso) override;
};
static struct {
@@ -58,7 +80,8 @@ static struct {
v3f gf, gu, gr;
std::vector<v2f> shrinkwrap_points;
std::vector<v2f> projection_points;
- std::vector<Pipeline> psos;
+ std::unordered_map<Pipeline, UI::Element*> psos;
+ UI::Element* pso_tree;
v3f projection_start, projection_end;
} editor;
@@ -71,8 +94,10 @@ static int dev_win_handler(UI::Element* e, const UI::Message& m) {
return 0;
}
-static void create_pso_view(UI::Element* p, const Pipeline* pso) {
+static void init_pso_view(UI::Element* content, const Pipeline* pso) {
auto ui = editor.ui;
+ int rows[] = { 300, 300, 0 };
+ UI::Table* p = ui->create_element<UI::Table>(content, rows);
auto disp_val = [&](UI::Element* parent, const char* name, const char* fmt, auto... vals) {
char buf[64];
sprintf(buf, fmt, vals...);
@@ -185,6 +210,17 @@ static void create_pso_view(UI::Element* p, const Pipeline* pso) {
}
}
+static void create_pso_view(const Pipeline& pso) {
+ UI::Tree* tree;
+ char buf[32];
+ UI* ui = editor.ui;
+ sprintf(buf, "0x%lx", pso.pipeline_hash);
+ tree = ui->create_element<UI::Tree>(editor.pso_tree, buf);
+ init_pso_view(tree, &pso);
+ tree->collapse();
+ editor.psos[pso] = tree;
+}
+
static int dev_btn_handler(UI::Element* e, const UI::Message& m) {
(void)e;
if (m.type == UI::Message::Type::click) {
@@ -195,25 +231,19 @@ static int dev_btn_handler(UI::Element* e, const UI::Message& m) {
);
editor.dev_win->handler = dev_win_handler;
auto ui = editor.ui;
- auto& psov = editor.psos;
+ std::vector<Pipeline> psov;
auto& hook = editor.device_debughook;
auto content = ui->create_element<UI::Tree>(
editor.dev_win->contents,
"Pipeline State Objects"
);
+ editor.pso_tree = content;
psov.clear();
psov.resize(hook.query_psos(0));
hook.query_psos(&psov[0]);
+ editor.psos.clear();
for (auto& pso : psov) {
- UI::Tree* tree;
- UI::Table* table;
- int rows[] = { 300, 300, 0 };
- char buf[32];
- sprintf(buf, "0x%lx", pso.pipeline_hash);
- tree = ui->create_element<UI::Tree>(content, buf);
- table = ui->create_element<UI::Table>(tree, rows);
- create_pso_view(table, &pso);
- tree->collapse();
+ create_pso_view(pso);
}
}
return 0;
@@ -681,3 +711,15 @@ void Editor_PD::projection(
editor.projection_end = editor.projection_start + n;
}
}
+
+void Editor_DD::on_pso_create(const Pipeline& pso) {
+ if (!editor.dev_win) return;
+ create_pso_view(pso);
+}
+
+void Editor_DD::on_pso_destroy(const Pipeline& pso) {
+ if (!editor.dev_win) return;
+ UI::Element* t = editor.psos[pso];
+ t->destroy();
+ editor.psos.erase(pso);
+}