summaryrefslogtreecommitdiff
path: root/editor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'editor.cpp')
-rw-r--r--editor.cpp177
1 files changed, 174 insertions, 3 deletions
diff --git a/editor.cpp b/editor.cpp
index 32e4498..a06c4a9 100644
--- a/editor.cpp
+++ b/editor.cpp
@@ -12,6 +12,7 @@ extern "C" {
#include "plat.h"
}
+#include <stdio.h>
#include <vector>
struct Editor_PD : Physics_Debughook {
@@ -30,13 +31,17 @@ struct Editor_PD : Physics_Debughook {
) override;
};
+struct Editor_DD : Device_Debug_Hooks {
+};
+
static struct {
Editor_Settings settings;
Editor_PD physics_debughook;
+ Editor_DD device_debughook;
UI* ui;
UI::Toolbar* toolbar;
- UI::Button* mat_btn, * ent_btn, * phy_btn;
- UI::Modal* mat_win, * ent_win, * phy_win;
+ UI::Button* mat_btn, * ent_btn, * phy_btn, * dev_btn;
+ UI::Modal* mat_win, * ent_win, * phy_win, * dev_win;
UI::Label* mat_name, * spl;
UI::Slider* metalness_input;
UI::Slider* roughness_input;
@@ -53,9 +58,167 @@ static struct {
v3f gf, gu, gr;
std::vector<v2f> shrinkwrap_points;
std::vector<v2f> projection_points;
+ std::vector<Pipeline> psos;
v3f projection_start, projection_end;
} editor;
+static int dev_win_handler(UI::Element* e, const UI::Message& m) {
+ (void)e;
+ if (m.type == UI::Message::Type::destroy) {
+ editor.dev_btn->enable();
+ editor.dev_win = 0;
+ }
+ return 0;
+}
+
+static void create_pso_view(UI::Element* p, const Pipeline* pso) {
+ auto ui = editor.ui;
+ auto disp_val = [&](UI::Element* parent, const char* name, const char* fmt, auto... vals) {
+ char buf[64];
+ sprintf(buf, fmt, vals...);
+ ui->create_element<UI::Label>(parent, name);
+ ui->create_element<UI::Label>(parent, buf);
+ };
+ auto disp_bool = [&](UI::Element* parent, const char* name, bool v) {
+ disp_val(parent, name, v? "Yes": "No");
+ };
+ auto disp_enum = [&](UI::Element* parent, const char* name, int v, auto... s) {
+ const char* arr[] = { s... };
+ disp_val(parent, name, "%s", arr[v]);
+ };
+ disp_val(p, "PSO Hash", "%llx", pso->pipeline_hash);
+ disp_val(p, "Descriptor Resource Hash", "%llx", pso->descriptor_resource_hash);
+ disp_val(
+ p,
+ "Viewport",
+ "%d %d %d %d",
+ pso->viewport[0],
+ pso->viewport[1],
+ pso->viewport[2],
+ pso->viewport[3]
+ );
+ disp_val(
+ p,
+ "Scissor",
+ "%d %d %d %d",
+ pso->scissor[0],
+ pso->scissor[1],
+ pso->scissor[2],
+ pso->scissor[3]
+ );
+ disp_bool(p, "Depth Test", pso->depth_test);
+ disp_bool(p, "Depth Write", pso->depth_write);
+ disp_bool(p, "Blend Enable", pso->blend_enable);
+ disp_enum(p, "Depth Mode", (int)pso->depth_mode,
+ "Less",
+ "Less Equal",
+ "Equal",
+ "Greater",
+ "Greater Equal",
+ "Always",
+ "Never"
+ );
+ disp_enum(p, "Geometry Type", (int)pso->geo,
+ "Triangles",
+ "Lines",
+ "Points"
+ );
+ auto disp_blend = [&](const char* n, int v) {
+ disp_enum(p, n, v,
+ "Zero",
+ "One",
+ "Src Colour",
+ "Inv_src_colour",
+ "Dst_colour",
+ "Inv_dst_colour",
+ "Src_alpha",
+ "Inv_src_alpha",
+ "Dst_alpha",
+ "Inv_dst_alpha"
+ );
+ };
+ auto disp_blend_mode = [&](const char* n, int v) {
+ disp_enum(p, n, v,
+ "Add",
+ "Subtract",
+ "Reverse Subtract",
+ "Min",
+ "Max"
+ );
+ };
+ disp_blend("Colour Blend Source", (int)pso->blend_src);
+ disp_blend("Colour Blend Destination", (int)pso->blend_dst);
+ disp_blend_mode("Colour Blend Mode", (int)pso->blend_mode);
+ disp_blend("Alpha Blend Source", (int)pso->blend_src_alpha);
+ disp_blend("Alpha Blend Destination", (int)pso->blend_dst_alpha);
+ disp_blend_mode("Alpha Blend Mode", (int)pso->blend_mode_alpha);
+ disp_val(p, "Vertex Format ID", "%d", (int)pso->vertex_format.index);
+ disp_val(p, "Shader ID", "%d", (int)pso->shader.index);
+ auto dt = ui->create_element<UI::Tree>(p, "Descriptors");
+ for (int i = 0; i < pso->descriptor_count; i++) {
+ int rows[] = { 300, 300, 0 };
+ const Descriptor& d = pso->descriptors[i];
+ char buf[32];
+ sprintf(buf, "%d", d.slot);
+ auto tree = ui->create_element<UI::Tree>(dt, buf);
+ auto table = ui->create_element<UI::Table>(tree, rows);
+ disp_enum(table, "Type", (int)d.type,
+ "Texture",
+ "Constant Buffer"
+ );
+ switch (d.type) {
+ case Descriptor::Type::texture: {
+ Texture_Descriptor& tex =
+ *(Texture_Descriptor*)d.payload;
+ disp_val(table, "Texture ID", "%d", (int)tex.texture.index);
+ disp_val(table, "Sampler ID", "%d", (int)tex.sampler.index);
+ } break;
+ case Descriptor::Type::constant_buffer: {
+ Constant_Buffer_Descriptor& cb =
+ *(Constant_Buffer_Descriptor*)d.payload;
+ disp_val(table, "Offset", "%d", cb.offset);
+ disp_val(table, "Size", "%d", cb.size);
+ disp_val(table, "Buffer ID", "%d", (int)cb.buffer.index);
+ } break;
+ }
+ tree->collapse();
+ }
+}
+
+static int dev_btn_handler(UI::Element* e, const UI::Message& m) {
+ (void)e;
+ if (m.type == UI::Message::Type::click) {
+ editor.dev_btn->disable();
+ editor.dev_win = editor.ui->create_element<UI::Modal>(
+ editor.ui->root,
+ "Device Debugger"
+ );
+ editor.dev_win->handler = dev_win_handler;
+ auto ui = editor.ui;
+ auto& psov = editor.psos;
+ auto& hook = editor.device_debughook;
+ auto content = ui->create_element<UI::Tree>(
+ editor.dev_win->contents,
+ "Pipeline State Objects"
+ );
+ psov.clear();
+ psov.resize(hook.query_psos(0));
+ hook.query_psos(&psov[0]);
+ 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();
+ }
+ }
+ return 0;
+}
+
static int mat_win_handler(UI::Element* e, const UI::Message& m) {
(void)e;
if (m.type == UI::Message::Type::destroy) {
@@ -266,7 +429,9 @@ static int phy_btn_handler(UI::Element* e, const UI::Message& m) {
return 0;
}
-void init_editor(UI* ui, World* world) {
+void init_editor(Device* d, UI* ui, World* world) {
+ editor.device_debughook.dev = d;
+ d->hooks = &editor.device_debughook;
editor.ui = ui;
editor.toolbar = ui->create_element<UI::Toolbar>(ui->root);
editor.mat_btn = ui->create_element<UI::Button>(
@@ -284,9 +449,15 @@ void init_editor(UI* ui, World* world) {
"Physics Debugger"
);
editor.phy_btn->handler = phy_btn_handler;
+ editor.dev_btn = ui->create_element<UI::Button>(
+ editor.toolbar,
+ "Device Debugger"
+ );
+ editor.dev_btn->handler = dev_btn_handler;
editor.mat_win = 0;
editor.ent_win = 0;
editor.phy_win = 0;
+ editor.dev_win = 0;
editor.debug_sat_axis = 0;
editor.world = world;
editor.dragging_gizmo = 0;