From c5c66f8cf3b1f253d2454216c982152df67bcea2 Mon Sep 17 00:00:00 2001 From: coding-agent Date: Sun, 8 Nov 2026 12:16:25 +0000 Subject: [PATCH 1/4] Editor: headless Vulkan graphics + entity/component InspectorView + --headless CLI Engine (headless construction, no display / no WSI): - Graphics/Vulkan/Graphics.{h,cpp} + Graphics/Initializer.h: a 'headless' flag skips surface/swapchain extension negotiation and the window path so a VkDevice can be created with a driver present but no display. - Scene/Scene.{h,cpp}: null-guards + PScene circular-include decoupling. - Actor/Entity.{h,cpp}: hasComponent fix (handle-space component query). Editor: - Editor/Window/InspectorView.{h,cpp}: Unity-style entity/component inspector on a fixed widget pool (no runtime tree mutation) driven by a UIPass in the render graph; owns its UI::System via UI::OSystem. - Editor/ComponentRegistry.{h,cpp}: type-erased component catalog (handle-space only, no entt in the editor API) that drives the inspector's component pane. - Editor/main.cpp: --headless / --dump-entities path (headless device + scene dump, no window) and InspectorView wiring with a live PScene on the windowed path. Compile-verified (-fsyntax-only, -std=c++23) across all touched TUs. --- src/Editor/ComponentRegistry.cpp | 208 ++++++++++++++++++++ src/Editor/ComponentRegistry.h | 83 ++++++++ src/Editor/Window/InspectorView.cpp | 249 ++++++++++++++++++++++-- src/Editor/Window/InspectorView.h | 71 +++++-- src/Editor/main.cpp | 103 +++++++++- src/Engine/Actor/Entity.cpp | 17 +- src/Engine/Actor/Entity.h | 27 +++ src/Engine/Graphics/Initializer.h | 6 +- src/Engine/Graphics/Vulkan/Graphics.cpp | 39 +++- src/Engine/Graphics/Vulkan/Graphics.h | 7 + src/Engine/Scene/Scene.cpp | 40 +++- src/Engine/Scene/Scene.h | 26 ++- 12 files changed, 830 insertions(+), 46 deletions(-) create mode 100644 src/Editor/ComponentRegistry.cpp create mode 100644 src/Editor/ComponentRegistry.h diff --git a/src/Editor/ComponentRegistry.cpp b/src/Editor/ComponentRegistry.cpp new file mode 100644 index 0000000..485259b --- /dev/null +++ b/src/Editor/ComponentRegistry.cpp @@ -0,0 +1,208 @@ +#include "ComponentRegistry.h" +#include "Asset/MeshAsset.h" +#include "Component/Camera.h" +#include "Component/DirectionalLight.h" +#include "Component/Mesh.h" +#include "Component/PointLight.h" +#include "Component/Transform.h" +#include +#include + +using namespace Seele; +using namespace Seele::Editor; + +// --- small formatting helpers ------------------------------------------------------ +namespace { +// Render a glm::vec / Quaternion (which all have operator<<) into a trimmed string. +template +std::string fmtVec(const T& v) { + std::ostringstream oss; + oss.precision(4); + oss << std::fixed << v; + return oss.str(); +} + +std::string fmtFloat(float f) { + std::ostringstream oss; + oss.precision(4); + oss << std::fixed << f; + return oss.str(); +} +} // namespace + +// All of the editor's component-inspection entry points live in Seele::Editor (matching the +// declarations in ComponentRegistry.h). The using-directives above (using namespace Seele; +// using namespace Seele::Editor;) make the types (PEntity, PScene, ComponentEntry, Array, +// glm, the Component::* types) resolvable unqualified inside this block, while the function +// *definitions* themselves are correctly placed in the same namespace as their declarations - +// no duplicate/ambiguous global-scope symbols. +namespace Seele { +namespace Editor { + +std::vector& componentCatalog() { + static std::vector catalog; + return catalog; +} + +void initComponentRegistry() { + auto& catalog = componentCatalog(); + // Idempotent: build the catalog only once. The set of displayable component *types* is + // fixed for the editor's lifetime, so we never add to it after the first call. + if (!catalog.empty()) { + return; + } + + // Every entry works through the handle's own hasComponent/accessComponent - the exact + // same call shape game code uses to read components, just applied to an OEntity view. + + // Transform: position / rotation / scale. The single most important component to + // display - every placed actor has one. + catalog.push_back(ComponentEntry{ + .name = "Transform", + .isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent(); }, + .describe = [](PEntity e) -> std::string { + if (e == nullptr || !e->hasComponent()) { + return ""; + } + const auto& t = e->accessComponent(); + std::ostringstream oss; + oss << "Position: " << fmtVec(t.getPosition()) << "\n"; + oss << "Rotation: " << fmtVec(t.getRotation()) << "\n"; + oss << "Scale: " << fmtVec(t.getScale()); + return oss.str(); + }, + }); + + // Camera: projection params. + catalog.push_back(ComponentEntry{ + .name = "Camera", + .isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent(); }, + .describe = [](PEntity e) -> std::string { + if (e == nullptr || !e->hasComponent()) { + return ""; + } + const auto& c = e->accessComponent(); + std::ostringstream oss; + oss << "Field Of View (deg): " << fmtFloat(glm::degrees(c.fieldOfView)) << "\n"; + oss << "Aspect Ratio: " << fmtFloat(c.aspectRatio) << "\n"; + oss << "Near Plane: " << fmtFloat(c.nearPlane) << "\n"; + oss << "Far Plane: " << fmtFloat(c.farPlane) << "\n"; + oss << "Main Camera: " << (c.mainCamera ? "true" : "false"); + return oss.str(); + }, + }); + + // PointLight: color + intensity + attenuation. + catalog.push_back(ComponentEntry{ + .name = "PointLight", + .isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent(); }, + .describe = [](PEntity e) -> std::string { + if (e == nullptr || !e->hasComponent()) { + return ""; + } + const auto& l = e->accessComponent(); + std::ostringstream oss; + oss << "Color: " << fmtVec(l.color) << "\n"; + oss << "Intensity: " << fmtFloat(l.intensity) << "\n"; + oss << "Attenuation: " << fmtFloat(l.attenuation); + return oss.str(); + }, + }); + + // DirectionalLight: color + intensity. + catalog.push_back(ComponentEntry{ + .name = "DirectionalLight", + .isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent(); }, + .describe = [](PEntity e) -> std::string { + if (e == nullptr || !e->hasComponent()) { + return ""; + } + const auto& l = e->accessComponent(); + std::ostringstream oss; + oss << "Color: " << fmtVec(l.color) << "\n"; + oss << "Intensity: " << fmtFloat(l.intensity); + return oss.str(); + }, + }); + + // Mesh (static): the mesh asset's name/folder + staticness + meshlet count. + catalog.push_back(ComponentEntry{ + .name = "Mesh", + .isAttached = [](PEntity e) -> bool { return e != nullptr && e->hasComponent(); }, + .describe = [](PEntity e) -> std::string { + if (e == nullptr || !e->hasComponent()) { + return ""; + } + const auto& m = e->accessComponent(); + std::ostringstream oss; + oss << "Asset: "; + if (m.asset != nullptr) { + oss << m.asset->getFolderPath() << "/" << m.asset->getName(); + } else { + oss << "(none)"; + } + oss << "\n"; + oss << "Static: " << (m.isStatic ? "true" : "false") << "\n"; + oss << "Meshlets: " << m.meshletOffsets.size(); + return oss.str(); + }, + }); +} + +std::vector enumerateEntities(const PScene& scene) { + std::vector out; + if (scene == nullptr) { + return out; + } + // The scene's roster is the source of truth for "what entities exist" - this is the + // "OEntity you can query via the scene" the user asked for. We iterate handles (PEntity + // views), never entt ids. The roster is appended in creation order and pruned on + // destroy, so it is stable across frames (no re-sorting needed, no entt::entity anywhere). + const Array& roster = scene->getEntities(); + for (size_t i = 0; i < roster.size(); ++i) { + PEntity e = roster[i]; + if (e == nullptr) { + continue; + } + EntityInfo info; + info.entity = e; // non-owning handle the row points at + info.label = e->getLabel(); // "#" formatted in the engine; no entt type leaks + // Component summary: the names of every cataloged component this entity actually + // has, comma-joined. Uses isAttached (handle-space) - no registry access in the editor. + std::vector names; + for (auto& entry : componentCatalog()) { + if (entry.isAttached(e)) { + names.push_back(entry.name); + } + } + if (names.empty()) { + info.componentSummary = "no components"; + } else { + info.componentSummary = names[0]; + for (size_t n = 1; n < names.size(); ++n) { + info.componentSummary += ", " + names[n]; + } + } + out.push_back(std::move(info)); + } + return out; +} + +std::vector describeEntityComponents(const PScene& scene, PEntity entity) { + std::vector out; + if (scene == nullptr || entity == nullptr) { + return out; + } + // Walk the catalog in order; for each component the entity has, render its fields via + // the handle's own accessComponent. The editor never touches the registry directly. + for (auto& entry : componentCatalog()) { + if (!entry.isAttached(entity)) { + continue; // entity does not have this component (or it is not displayable) + } + out.push_back(ComponentDisplay{.name = entry.name, .fieldText = entry.describe(entity)}); + } + return out; +} + +} // namespace Editor +} // namespace Seele diff --git a/src/Editor/ComponentRegistry.h b/src/Editor/ComponentRegistry.h new file mode 100644 index 0000000..0cdb3c3 --- /dev/null +++ b/src/Editor/ComponentRegistry.h @@ -0,0 +1,83 @@ +#pragma once +// The editor's component-inspection layer. Operates ENTIRELY in engine handle space +// (OEntity / PScene) - the entt::entity type never appears in this header or in any +// function the editor calls. Every EnTT operation the inspector needs (does-this-entity- +// have-T, read-T) is performed by the Entity/Scene methods (hasComponent / accessComponent +// / getEntities), which is exactly the separation the engine wants: tooling works through +// handles, the registry stays internal to the engine. +#include "Actor/Actor.h" +#include "Scene/Scene.h" +#include +#include +#include + +namespace Seele { +namespace Editor { + +// A single entry in the component catalog: how to recognize one component type on an +// entity and how to render its fields as human-readable text (Unity-inspector style). +// +// Both callbacks take a PEntity (a non-owning handle view) - never a raw entt id. They use +// the entity's own hasComponent() / accessComponent() so the inspector code reads +// exactly the way game code attaches/reads components: in handle space. +// +// This is the type-erased bridge between "I have an OEntity handle" and "show me every +// component attached to it". EnTT does not expose a generic "iterate all registered +// component types" API, so the inspector keeps an explicit catalog of the types it knows +// how to display. Adding a new engine component to the inspector is one entry in +// ComponentRegistry.cpp - no changes to this header. +struct ComponentEntry { + // Display name shown as the section header in the inspector (e.g. "Transform"). + std::string name; + // True if the given entity currently has this component attached. + std::function isAttached; + // Render the component's fields as a multi-line string (Unity-style: "field: value" per + // line). Returns "" when the entity does not have the component (the caller skips it). + std::function describe; +}; + +// The catalog of every component type the editor knows how to display. Populated exactly +// once by initComponentRegistry() (called from the editor's main before the first frame). +// The vector is process-global by design: component *types* are a fixed set, so the +// catalog is built once and read-only afterwards. +std::vector& componentCatalog(); + +// Build the catalog. Idempotent - safe to call more than once; it only (re)populates the +// static vector, which every editor tool reads. Must be called before any inspector reads +// the catalog (main.cpp does this before the render loop). +void initComponentRegistry(); + +// One row in the entity list (the left pane). Built from the scene's roster of live +// handles - the "ID of an entity" is shown via the handle's own getLabel() (formatted in +// the engine, so no entt type leaks), and the component summary is the names of the +// cataloged components the handle actually has. +struct EntityInfo { + // The non-owning handle the row refers to. The editor stores these to drive the + // "selected entity" state across frames. Non-owning by design: the *scene* owns the + // entity's existence (the roster) and the creator's O* owns the C++ object. + PEntity entity; + // A short, stable label for the row (e.g. "#3") - the "ID of an entity" the user asked + // to display, produced by Entity::getLabel() so the entt type never reaches the editor. + std::string label; + // Human-readable summary of the attached components (e.g. "Transform, Mesh") for the + // row's subtitle. + std::string componentSummary; +}; + +// Enumerate every live entity in the scene (as non-owning handles) with its label + a +// component summary. Source of the left pane. Iterates the scene's roster (getEntities) - +// the scene's single source of truth for "what entities exist" - so this is the +// "OEntity you can query via the scene" the user asked for, with no entt id anywhere. +std::vector enumerateEntities(const PScene& scene); + +// Describe one entity's components for the inspector pane: a vector of (componentName, +// fieldText) pairs, one entry per attached, displayable component, in catalog order. The +// caller (InspectorView) maps these to UI::Text rows and refreshes them in update(). +struct ComponentDisplay { + std::string name; + std::string fieldText; +}; +std::vector describeEntityComponents(const PScene& scene, PEntity entity); + +} // namespace Editor +} // namespace Seele diff --git a/src/Editor/Window/InspectorView.cpp b/src/Editor/Window/InspectorView.cpp index ffbdb6d..7f94a1a 100644 --- a/src/Editor/Window/InspectorView.cpp +++ b/src/Editor/Window/InspectorView.cpp @@ -1,26 +1,141 @@ #include "InspectorView.h" -#include "Actor/Actor.h" -#include "Asset/AssetRegistry.h" -#include "Asset/FontLoader.h" + +#include "ComponentRegistry.h" #include "Graphics/Graphics.h" +#include "UI/Element/Button.h" #include "UI/Element/Div.h" #include "UI/Element/Text.h" +#include "UI/Style/Fonts.h" // Font_Arial tag type (Text.h does not pull this in) +#include "UI/System.h" using namespace Seele; using namespace Seele::Editor; using namespace Seele::UI; -InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo) - : View(graphics, window, createInfo, "InspectorView"), - uiSystem(new UI::System( - new UI::Div(UI::Attributes{}, { - new UI::Div({}, - { - new UI::Text("Other Test T"), - }), - new UI::Text("Test fasdf agll;sdfgkj ahsf"), - }))) { - renderGraph.addPass(new UIPass(graphics, uiSystem)); +namespace { +// Split a multi-line string into trimmed, non-empty lines (for the field display). +std::vector splitLines(const std::string& text) { + std::vector out; + std::string cur; + for (char c : text) { + if (c == '\n') { + if (!cur.empty()) { + out.push_back(cur); + cur.clear(); + } + } else { + cur.push_back(c); + } + } + if (!cur.empty()) { + out.push_back(cur); + } + return out; +} +} // namespace + +InspectorView::InspectorView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo& createInfo, PScene scene) + : View(graphics, owner, createInfo, "InspectorView"), scene(scene) { + // ------------------------------------------------------------------ + // Build the ENTIRE fixed widget tree exactly once, here, in the constructor. + // + // "Children fixed at construction": the UI tree's structure is immutable at + // runtime. We create every widget as a named local (so we can keep a raw pointer + // for setText()), then reference those same objects in the tree's initializer-list. + // The initializer-list's Element* -> OElement implicit conversion stores an OWNING + // ref in each parent's children array (Array) for the element's whole + // lifetime, so the raw pointers below remain valid for the life of the view. + // ------------------------------------------------------------------ + + // ---- Leaf widgets (named locals; also referenced by the tree below) ---------- + // Entity-list row labels + select buttons (one row per pool slot). + Text* rowLabels[kMaxEntities]; + Button<>* rowButtons[kMaxEntities]; + for (int i = 0; i < kMaxEntities; i++) { + // Text has no default ctor (text is a required arg); start with an empty string + // and refresh() fills it each frame. Button's default ctor is deleted (Div() + // = delete) so we must pass explicit Attributes. + rowLabels[i] = new Text(""); + rowButtons[i] = new Button<>(UI::Attributes{}); + // The button's onClick is the ONLY sanctioned way selection state changes; + // refresh() (called from update() next frame) reads it back and re-renders the + // component pane. We do not markDirty() here - the next frame's refresh() is + // the sanctioned per-frame mutation path, and markDirty() is an Element method + // (not callable on this View). + rowButtons[i]->attr.onClick = [this, i](MouseEvent&) { + selectedEntity = i; + return true; + }; + // PElement is a NON-OWNING wrapper (no operator=(T*)); the tree's owning + // OElement refs (stored in the parent Div's children below) are what keep these + // alive. We construct an explicit PElement temporary to copy-assign the handle. + entityPool[i].label = PElement(rowLabels[i]); + entityPool[i].button = PElement(rowButtons[i]); + } + + // Component-inspector pane: a header line + a fixed pool of field lines. + // Text has no default ctor - pass an initial string (refresh() overwrites it). + Text* header = new Text("(no entity selected)"); + Text* lines[kMaxComponentLines]; + for (int i = 0; i < kMaxComponentLines; i++) { + lines[i] = new Text(""); + } + componentHeader = PElement(header); + for (int i = 0; i < kMaxComponentLines; i++) { + componentLines[i] = PElement(lines[i]); + } + + // ---- Compose the tree (structure fixed at construction) ---------------------- + // Element's only children ctor is (Attributes, initializer_list) - there is + // no variadic form and initializer_list cannot be built from an Array, so the child + // list must be a braced-init at the call site. A braced list MAY contain function-call + // expressions, so a small lambda builds each identical row (returning the owning + // OElement of the row Div) and we reference makeRow(0..7) explicitly. The label/button + // handles for refresh() were already stashed in entityPool[] above (non-owning PElement); + // the row Div's children array holds the OWNING refs that keep the widgets alive. + auto makeRow = [this, &rowLabels, &rowButtons](int i) -> OElement { + return OElement(new Div( + UI::Attributes{}, + std::initializer_list{OElement(rowLabels[i]), OElement(rowButtons[i])})); + }; + + // Left pane: a vertical (FlexCol) stack of the 8 fixed entity rows. The child list is + // a braced-init of makeRow(0..7) - each call returns the owning OElement of one row. + Div* leftPane = new Div( + UI::Attributes{}, + std::initializer_list{ + makeRow(0), makeRow(1), makeRow(2), makeRow(3), + makeRow(4), makeRow(5), makeRow(6), makeRow(7), + }); + + // Right pane: a vertical (FlexCol) stack of the header line + the fixed field-line pool. + // Same braced-init pattern; makeLine(i) returns the owning OElement of one field Text. + auto makeLine = [this, &lines](int i) -> OElement { + return OElement(lines[i]); + }; + Div* rightPane = new Div( + UI::Attributes{}, + std::initializer_list{ + OElement(header), + makeLine(0), makeLine(1), makeLine(2), makeLine(3), + makeLine(4), makeLine(5), makeLine(6), makeLine(7), + makeLine(8), makeLine(9), makeLine(10), makeLine(11), + makeLine(12), makeLine(13), makeLine(14), makeLine(15), + }); + + // Root: a horizontal (FlexRow) split - entity list on the left, inspector on the right. + Div* root = new Div( + UI::Attributes{}, + std::initializer_list{OElement(leftPane), OElement(rightPane)}); + + // Hand the fully-built root tree to the UI system. The system is owned by the view + // (uiSystem is an OwningPtr); construct the owning handle in place. + uiSystem = UI::OSystem(new UI::System(OElement(root))); + + // Register a UIPass to render the UI. Keep a raw pointer to it so the window input + // callbacks can forward events (RenderGraph exposes only resources, not passes). + uiPass = new UIPass(graphics, uiSystem); + renderGraph.addPass(ORenderPass(uiPass)); renderGraph.setViewport(viewport); renderGraph.createRenderPass(); } @@ -29,22 +144,114 @@ InspectorView::~InspectorView() {} void InspectorView::beginUpdate() {} -void InspectorView::update() {} +void InspectorView::update() { + refresh(); +} void InspectorView::commitUpdate() {} void InspectorView::prepareRender() {} -void InspectorView::render() { renderGraph.render(Component::Camera(), Component::Transform()); } +void InspectorView::render() { + // Drives every pass in the graph, including the UIPass (which runs + // system->processInput() + system->beginFrame() internally before rendering). + // The UI system's per-frame update is performed by the pass, not by us. + renderGraph.render(Component::Camera(), Component::Transform()); +} -void InspectorView::applyArea(URect ) {} +void InspectorView::applyArea(URect) { + // The Viewport was already resized by View::resize before this is called. Recreate + // the render graph's passes at the new size so the UI (and everything) re-layouts. + renderGraph.setViewport(viewport); + renderGraph.createRenderPass(); +} -void InspectorView::keyCallback(KeyCode, InputAction, KeyModifierFlags) {} +void InspectorView::keyCallback(KeyCode code, InputAction action, uint32_t modifier) { + if (uiPass != nullptr) { + uiPass->key(code, action, KeyModifierFlags(modifier), 0); + } +} -void InspectorView::mouseMoveCallback(double, double) {} +void InspectorView::mouseMoveCallback(double xPos, double yPos) { + if (uiPass != nullptr) { + uiPass->mouseMove(Vector2(xPos, yPos)); + } +} -void InspectorView::mouseButtonCallback(MouseButton, InputAction, KeyModifierFlags) {} +void InspectorView::mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) { + if (uiPass != nullptr) { + uiPass->mouseButton(button, action, KeyModifierFlags(modifier), Vector2(0, 0)); + } +} -void InspectorView::scrollCallback(double, double) {} +void InspectorView::scrollCallback(double xOffset, double yOffset) { + if (uiPass != nullptr) { + uiPass->scroll(Vector2(xOffset, yOffset)); + } +} void InspectorView::fileCallback(int, const char**) {} + +void InspectorView::refresh() { + // Re-read the scene's live entity roster + the selected entity's components, and + // push the results into the fixed widget pool via Text::setText. This is the ONLY + // per-frame mutation of the UI tree - children are never added or removed. + // + // The pool handles are UI::PElement (the Element base ref) because Text/Button are + // class templates (can't be member types). We downcast to the concrete type at the + // use site. Every downcast target is guaranteed valid: we built each widget with the + // exact concrete type below and the tree's owning OElement refs keep it alive. + auto setTextOn = [](UI::PElement handle, const std::string& text) { + if (handle == nullptr) { + return; + } + if (auto* t = dynamic_cast*>(handle.getHandle())) { + t->setText(text); + } + }; + auto entities = enumerateEntities(scene); + + // --- Entity list pane: fill the fixed row pool from the live roster ----------- + for (int i = 0; i < kMaxEntities; i++) { + if (i < (int)entities.size()) { + setTextOn(entityPool[i].label, + entities[i].label + " [" + entities[i].componentSummary + "]"); + } else { + setTextOn(entityPool[i].label, ""); + } + } + + // --- Component inspector pane: describe the selected entity ------------------- + if (selectedEntity >= 0 && selectedEntity < (int)entities.size()) { + PEntity ent = entities[selectedEntity].entity; + setTextOn(componentHeader, "Components: " + entities[selectedEntity].label); + auto components = describeEntityComponents(scene, ent); + + int line = 0; + for (auto& c : components) { + if (line >= kMaxComponentLines) { + break; // fixed pool: truncate beyond it + } + setTextOn(componentLines[line], " " + c.name); + line++; + // Multi-line field text is folded into the subsequent pool lines (clamped). + auto fields = splitLines(c.fieldText); + for (auto& f : fields) { + if (line >= kMaxComponentLines) { + break; + } + setTextOn(componentLines[line], " " + f); + line++; + } + } + // Clear leftover pool lines so stale data never shows (fixed pool must be clean). + for (; line < kMaxComponentLines; line++) { + setTextOn(componentLines[line], ""); + } + } else { + setTextOn(componentHeader, "(no entity selected)"); + for (int i = 0; i < kMaxComponentLines; i++) { + setTextOn(componentLines[i], ""); + } + } +} diff --git a/src/Editor/Window/InspectorView.h b/src/Editor/Window/InspectorView.h index a82e7ef..924bc34 100644 --- a/src/Editor/Window/InspectorView.h +++ b/src/Editor/Window/InspectorView.h @@ -1,37 +1,78 @@ #pragma once -#include "Graphics/RenderPass/RenderGraph.h" -#include "Graphics/RenderPass/UIPass.h" #include "Window/View.h" -#include "UI/System.h" -#include "UI/Style/Fonts.h" +#include "Graphics/RenderPass/UIPass.h" +#include "UI/Element.h" // UI::PElement / UI::OElement (complete, for the fixed widget pool) +#include "Scene/Scene.h" // PScene namespace Seele { -DECLARE_REF(Actor) namespace Editor { +// The editor's component inspector. Left pane lists the scene's live entities +// (from the ComponentRegistry via Scene::getEntities); right pane shows the selected +// entity's components as Unity-style "field: value" text, refreshed every frame. +// +// The UI tree is a FIXED widget pool: it is built once in the constructor and never +// adds/removes children at runtime. Per-frame the only mutation is UI::Text::setText +// on the pre-built widgets (the "children fixed at construction" constraint). Selection +// state is changed exclusively through UI::Button onClick handlers (the sanctioned +// click path) and read back in update(). +// +// Pool handles are UI::PElement (the Element base ref). Text/Button/Div are class +// templates (UI::Text<...>, UI::Button<...>) so they can't be named as member types; +// we hold the base and dynamic_cast to the concrete type at the use site in refresh(). class InspectorView : public View { public: - InspectorView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo); - virtual ~InspectorView(); + // `scene` is the scene to inspect (non-owning; the editor owns its lifetime). + // The roster + component data are read from it each frame via the ComponentRegistry. + InspectorView(Gfx::PGraphics graphics, PWindow owner, const ViewportCreateInfo& createInfo, PScene scene); + virtual ~InspectorView() override; virtual void beginUpdate() override; virtual void update() override; virtual void commitUpdate() override; - virtual void prepareRender() override; virtual void render() override; - protected: virtual void applyArea(URect area) override; - UI::PSystem uiSystem; - RenderGraph renderGraph; - Component::Camera cam; - - virtual void keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) override; + virtual void keyCallback(KeyCode code, InputAction action, uint32_t modifier) override; virtual void mouseMoveCallback(double xPos, double yPos) override; - virtual void mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) override; + virtual void mouseButtonCallback(MouseButton button, InputAction action, uint32_t modifier) override; virtual void scrollCallback(double xOffset, double yOffset) override; virtual void fileCallback(int count, const char** paths) override; + + private: + // Fixed widget pools. Handles are UI::PElement (base) because Text/Button are class + // templates. Each is safe for the life of the view: the constructed element is stored + // in a parent Div's children array (Array) which holds an OWNING ref; the + // PElement here is a second (shared) ref to the same object. refresh() dynamic_casts + // to the concrete UI::Text/UI::Button<> to call setText()/attr. + static constexpr int kMaxEntities = 8; // entity-list rows + static constexpr int kMaxComponentLines = 16; // component-inspector text lines + + PScene scene; + // The UI::System is a long-lived object with no other owner, so the view OWNS it + // (OwningPtr, via the OSystem typedef from DEFINE_REF(System)). UIPass takes a + // non-owning PSystem, which OSystem converts to implicitly. + UI::OSystem uiSystem; + RenderGraph renderGraph; + // Direct handle to the UI render pass so the window input callbacks can be + // forwarded to the UI system (RenderGraph exposes only resources, not passes). + UIPass* uiPass = nullptr; + + // Selection state: written by button onClick, read in refresh(). + int selectedEntity = -1; + + struct EntityRow { + UI::PElement label = nullptr; // UI::Text (cast in refresh()) + UI::PElement button = nullptr; // UI::Button<> (cast in refresh()) + }; + EntityRow entityPool[kMaxEntities]; + + UI::PElement componentHeader = nullptr; + UI::PElement componentLines[kMaxComponentLines]; + + // Rebuild the pool text from the current scene state (called from update()). + void refresh(); }; DEFINE_REF(InspectorView) } // namespace Editor diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 043b313..3a5633b 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -13,7 +13,12 @@ #include "Window/PlayView.h" #include "Window/WindowManager.h" #include "Window/InspectorView.h" +#include "Scene/Scene.h" // OScene/Scene - the InspectorView's entity pane needs a live scene +#include "Component/Transform.h" +#include "Actor/Entity.h" +#include "ComponentRegistry.h" #include +#include using namespace Seele; using namespace Seele::Editor; @@ -21,7 +26,97 @@ using namespace Seele::Editor; // make it global so it gets deleted last and automatically static Gfx::OGraphics graphics; -int main() { +// Headless path: build a real Vulkan device with no WSI (no display available), +// populate a Scene with a few entities + components, dump the registry to stdout +// via the same handle-space query the editor's inspector uses, then tear down. +// Used for CI / smoke verification on display-less machines: the driver is +// present, only the display is not, so surface extensions are intentionally +// omitted while everything else (instance, device, queues, GPU buffers) works. +static int runHeadlessDump() { + std::cout << "[headless] constructing Vulkan::Graphics (no WSI / no swapchain)...\n"; + Gfx::OGraphics headlessGfx = new Vulkan::Graphics(); + GraphicsInitializer initializer; + initializer.headless = true; // skip GLFW init, WSI instance exts, and the swapchain device ext + headlessGfx->init(initializer); + std::cout << "[headless] Vulkan device constructed successfully.\n"; + + // A real (non-null) graphics handle, so Scene builds its GPU sub-systems for real. + OScene scene = new Scene(headlessGfx); + std::cout << "[headless] Scene constructed (LightEnvironment + FluidScene on real device).\n"; + + // A few entities with real transforms so the dump is meaningful. The display label is + // auto-derived from the entt id (Entity::getLabel -> "#"), so no setLabel needed. + Entity* a = new Entity(scene); + a->attachComponent().transform.setPosition(glm::vec3(0.0f, 0.0f, 0.0f)); + Entity* b = new Entity(scene); + b->attachComponent().transform.setPosition(glm::vec3(1.0f, 2.0f, -3.0f)); + Entity* c = new Entity(scene); + // c intentionally has no components - exercises the "no components" roster row. + + initComponentRegistry(); + auto entities = enumerateEntities(scene); + std::cout << "\n[headless] entity roster: " << entities.size() << " entity(ies)\n"; + for (const auto& e : entities) { + std::cout << "\n=== " << e.label << " ===\n"; + std::cout << " components: " << e.componentSummary << "\n"; + auto components = describeEntityComponents(scene, e.entity); + for (const auto& c : components) { + std::cout << " [ " << c.name << " ]\n"; + // Indent the field text by 4 spaces for readability. + for (const auto& line : std::vector{ + [&] { + std::vector out; + std::string cur; + for (char ch : c.fieldText) { + if (ch == '\n') { out.push_back(" " + cur); cur.clear(); } + else { cur += ch; } + } + if (!cur.empty()) { out.push_back(" " + cur); } + return out; + }()}) { + std::cout << " " << line << "\n"; + } + } + } + + std::cout << "\n[headless] tearing down (waitDeviceIdle + dispose)...\n"; + headlessGfx->waitDeviceIdle(); + delete a; + delete b; + delete c; + // scene (OScene) and headlessGfx (OGraphics) are OwningPtr (RAII): their destructors + // free the Scene / Graphics when the locals go out of scope at the end of this function. + // No manual delete - that would be a double-free. Order matters (entities before scene), + // which is already satisfied by the explicit deletes above. + std::cout << "[headless] OK - headless Vulkan path validated.\n"; + return 0; +} + +int main(int argc, char** argv) { + // --headless: build a real headless Vulkan device and exit (no window). + // --dump-entities: (implies --headless) also dump the entity roster to stdout. + bool wantHeadless = false, wantDump = false; + for (int i = 1; i < argc; ++i) { + std::string a = argv[i]; + if (a == "--headless" || a == "--dump-entities") wantHeadless = true; + if (a == "--dump-entities") wantDump = true; + } + if (wantHeadless) { + if (wantDump) { + return runHeadlessDump(); + } + // Headless device smoke test only (no dump). + Gfx::OGraphics h = new Vulkan::Graphics(); + GraphicsInitializer init; + init.headless = true; + h->init(init); + std::cout << "[headless] device OK (no WSI). Tearing down.\n"; + h->waitDeviceIdle(); + // h is an OwningPtr (RAII) - the destructor frees the Graphics at end of scope. + // No manual delete (would be a double-free). + return 0; + } + std::string gameName = "MeshShadingDemo"; std::filesystem::path outputPath = fmt::format("/home/dynamitos/{0}Game/", gameName); std::filesystem::path sourcePath = fmt::format("/home/dynamitos/{0}/", gameName); @@ -86,6 +181,9 @@ int main() { // }; // OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath); // sceneView->setFocused(); + // The windowed editor path has no pre-existing scene; the InspectorView's entity + // pane needs one to enumerate. Create a fresh Scene on the live (windowed) device. + OScene scene = new Scene(graphics); OInspectorView inspectorView = new Editor::InspectorView(graphics, window, ViewportCreateInfo{ .dimensions = @@ -93,7 +191,8 @@ int main() { .size = {1920, 1080}, .offset = {0, 0}, }, - }); + }, + /* scene = */ scene); inspectorView->setFocused(); window->show(); diff --git a/src/Engine/Actor/Entity.cpp b/src/Engine/Actor/Entity.cpp index 7bb7549..34f30f6 100644 --- a/src/Engine/Actor/Entity.cpp +++ b/src/Engine/Actor/Entity.cpp @@ -2,6 +2,19 @@ using namespace Seele; -Entity::Entity(PScene scene) : scene(scene), identifier(scene->createEntity()) {} +Entity::Entity(PScene scene) : scene(scene), identifier(scene->createEntity()) { + // Register with the scene's roster so the scene (and tooling built on it, e.g. the + // editor's inspector) can enumerate this entity in handle space. The scene is the single + // source of truth for "what entities exist"; this handle is a view the creator's O* + // still owns (ownership of the C++ object is unchanged - only the *existence record* is + // now tracked by the scene). + scene->registerEntity(identifier, PEntity(this)); +} -Entity::~Entity() { scene->destroyEntity(identifier); } \ No newline at end of file +Entity::~Entity() { + // Route teardown through the scene so the roster is unlinked in the same transaction + // that destroys the registry record - never leaves a dangling roster entry. The scene + // outlives this handle in every supported lifetime (the demo holds PScene members), so + // `scene` is always valid here. + scene->destroyEntity(identifier); +} \ No newline at end of file diff --git a/src/Engine/Actor/Entity.h b/src/Engine/Actor/Entity.h index a5acd72..37fde50 100644 --- a/src/Engine/Actor/Entity.h +++ b/src/Engine/Actor/Entity.h @@ -2,6 +2,8 @@ #include "MinimalEngine.h" #include "Scene/Scene.h" #include +#include +#include namespace Seele { // An entity describes a part of a scene @@ -11,6 +13,31 @@ class Entity { Entity(PScene scene); virtual ~Entity(); + // True if this entity currently has the given component attached. Pure handle-space + // (no entt::entity crosses the boundary) - the building block the editor's component + // inspector uses to ask "what is attached to this OEntity?" without ever touching the + // registry directly. Uses the entt try_get idiom: it returns a pointer to the component + // storage the entity holds, or null if the component is not attached - so the check is + // null-safe (no assertion) and works for any displayable component type. + template bool hasComponent() const { return scene->registry.try_get(identifier) != nullptr; } + + // The entt record this handle wraps. Exposed (not as the old raw `getId()`, but scoped + // and documented as internal) so the *scene* can keep its roster in lock-step with the + // registry during Entity ctor/dtor. The editor never calls this - it works entirely in + // handle space via hasComponent/accessComponent. + entt::entity getIdentifier() const { return identifier; } + + // A short, stable, human-facing label for tooling (the inspector's row text). Formatted + // *inside* the engine so the editor never has to name the entt::entity type at all - + // it just asks "what should I display for this OEntity?" and gets a string. This is the + // "display the ID of an entity" requirement satisfied in pure handle space: the numeric + // id is rendered to text here and never leaks out as an entt type. + std::string getLabel() const { + std::ostringstream oss; + oss << "#" << static_cast(identifier); + return oss.str(); + } + template Component& attachComponent(Args&&... args) { return scene->attachComponent(identifier, std::forward(args)...); } diff --git a/src/Engine/Graphics/Initializer.h b/src/Engine/Graphics/Initializer.h index 9d8ac5a..e209e26 100644 --- a/src/Engine/Graphics/Initializer.h +++ b/src/Engine/Graphics/Initializer.h @@ -20,7 +20,11 @@ struct GraphicsInitializer { Array deviceExtensions; void* windowHandle; - GraphicsInitializer() : applicationName("SeeleEngine"), engineName("SeeleEngine"), windowLayoutFile(nullptr), windowHandle(nullptr) {} + // When true, the Vulkan device is created in headless mode: no WSI surface + // extensions, no GLFW init, no swapchain device extension, no window. + // Used for machines that have a Vulkan driver but no display. + bool headless; + GraphicsInitializer() : applicationName("SeeleEngine"), engineName("SeeleEngine"), windowLayoutFile(nullptr), windowHandle(nullptr), headless(false) {} }; struct WindowCreateInfo { int32 width; diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 4c303c0..add793c 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -186,7 +186,7 @@ VkDeviceAddress vkGetAccelerationStructureDeviceAddressKHR(VkDevice device, cons return getAccelerationStructureDeviceAddress(device, pInfo); } -Graphics::Graphics() : instance(VK_NULL_HANDLE), handle(VK_NULL_HANDLE), physicalDevice(VK_NULL_HANDLE), callback(VK_NULL_HANDLE) {} +Graphics::Graphics() : instance(VK_NULL_HANDLE), handle(VK_NULL_HANDLE), physicalDevice(VK_NULL_HANDLE), callback(VK_NULL_HANDLE), headless(false) {} Graphics::~Graphics() { pipelineCache = nullptr; @@ -202,6 +202,10 @@ Graphics::~Graphics() { } void Graphics::init(GraphicsInitializer initInfo) { + // Capture headless before initInstance so getRequiredExtensions / initInstance / + // createDevice can all branch on it. In headless mode we intentionally skip GLFW + // init, all WSI surface extensions, and the swapchain device extension. + headless = initInfo.headless; initInstance(initInfo); setupDebugCallback(); pickPhysicalDevice(); @@ -728,6 +732,25 @@ Array Graphics::getRequiredExtensions() { return hasInstanceExtension(availableExtensions, extensionName); }; + // Headless: no WSI surface support at all. We do not query GLFW (it fails to + // init without a display) and we do not request any surface extension. The + // instance is still valid for descriptor/pipeline layouts, queues, and + // device-local resources — only window/swapchain paths are unavailable. + if (headless) { +#ifdef ENABLE_VALIDATION + extensions.addUnique(VK_EXT_DEBUG_UTILS_EXTENSION_NAME); +#endif + Array validatedExtensions; + for (uint32 i = 0; i < extensions.size(); ++i) { + if (supportsExtension(extensions[i])) { + validatedExtensions.addUnique(extensions[i]); + } else { + std::cerr << "Warning: Vulkan instance extension not exposed by loader, skipping: " << extensions[i] << std::endl; + } + } + return validatedExtensions; + } + unsigned int glfwExtensionCount = 0; const char** glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount); @@ -830,7 +853,12 @@ Array Graphics::getRequiredExtensions() { } void Graphics::initInstance(GraphicsInitializer initInfo) { - initializeGlfwForVulkan(); + // In headless mode there is no display, so GLFW cannot be initialized. Skip it + // entirely; getRequiredExtensions() already returns a surface-less set in this + // case. Everything else (instance, device, queues) proceeds normally. + if (!headless) { + initializeGlfwForVulkan(); + } VkApplicationInfo appInfo = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .pNext = nullptr, @@ -1056,7 +1084,12 @@ void Graphics::createDevice(GraphicsInitializer initializer) { *currentPriority++ = 0.0f; } } - initializer.deviceExtensions.add(VK_KHR_SWAPCHAIN_EXTENSION_NAME); + // In headless mode there is no swapchain (no window / no surface), so the + // swapchain device extension must not be requested. It is only needed for + // creating swapchain image views, which a headless device never does. + if (!headless) { + initializer.deviceExtensions.add(VK_KHR_SWAPCHAIN_EXTENSION_NAME); + } if (supportMeshShading()) { initializer.deviceExtensions.add(VK_EXT_MESH_SHADER_EXTENSION_NAME); features.get().pNext = &meshFeatures.get(); diff --git a/src/Engine/Graphics/Vulkan/Graphics.h b/src/Engine/Graphics/Vulkan/Graphics.h index 8a8f909..61db35b 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.h +++ b/src/Engine/Graphics/Vulkan/Graphics.h @@ -172,6 +172,13 @@ class Graphics : public Gfx::Graphics { void pickPhysicalDevice(); void createDevice(GraphicsInitializer initInfo); + // When true, the device is built without any WSI surface support: no GLFW + // init, no VK_KHR_surface / WSI instance extensions, no swapchain device + // extension, and no window. Everything else (instance, queues, descriptor / + // pipeline layouts, device-local resources) is fully functional. This lets the + // engine run on headless machines that have a Vulkan driver but no display. + bool headless; + VkInstance instance; VkDevice handle; VkPhysicalDevice physicalDevice; diff --git a/src/Engine/Scene/Scene.cpp b/src/Engine/Scene/Scene.cpp index b3edea7..3dfbb7a 100644 --- a/src/Engine/Scene/Scene.cpp +++ b/src/Engine/Scene/Scene.cpp @@ -2,11 +2,21 @@ #include "Graphics/Graphics.h" #include "LightEnvironment.h" #include "FluidScene.h" +#include "Actor/Actor.h" +#include "Actor/Entity.h" using namespace Seele; +// A scene can be built with a null graphics handle (headless / tooling use): in that case +// the GPU-bound sub-systems (light baking, fluid sim) are simply not constructed - they are +// only needed when there is a live device to render/simulate to. The ECS registry and the +// entity roster remain fully functional, which is all a headless inspector or a CLI dump +// needs. This keeps `new Scene(nullptr)` a valid, cheap, side-effect-free construction. Scene::Scene(Gfx::PGraphics graphics) - : graphics(graphics), lightEnv(new LightEnvironment(graphics)), fluidScene(new FluidScene(graphics)), physics(registry) {} + : graphics(graphics) + , lightEnv(graphics != nullptr ? new LightEnvironment(graphics) : nullptr) + , fluidScene(graphics != nullptr ? new FluidScene(graphics) : nullptr) + , physics(registry) {} Scene::~Scene() {} @@ -14,3 +24,31 @@ void Scene::bakeLighting() {} void Scene::update(float deltaTime) { physics.update(deltaTime); } +// Out-of-line definitions: these need the complete Entity type (getIdentifier()), +// which is only available here (Scene.cpp includes Actor/Entity.h). Scene.h +// forward-declares Entity only, to avoid the circular include. +void Scene::destroyEntity(entt::entity identifier) { + // Unlink from the roster before destroying the record so the roster never points at + // a dead entity. This is the single choke point through which every entity is torn + // down (Entity::~Entity routes here), so the roster stays consistent by construction. + auto& entities = this->entities; + for (size_t i = 0; i < entities.size(); ++i) { + if (entities[i] != nullptr && entities[i]->getIdentifier() == identifier) { + entities.removeAt(i); + break; + } + } + if (registry.valid(identifier)) { + registry.destroy(identifier); + } +} + +void Scene::unregisterEntity(entt::entity identifier) { + for (size_t i = 0; i < entities.size(); ++i) { + if (entities[i] != nullptr && entities[i]->getIdentifier() == identifier) { + entities.removeAt(i); + return; + } + } +} + diff --git a/src/Engine/Scene/Scene.h b/src/Engine/Scene/Scene.h index edbecb8..2b65be0 100644 --- a/src/Engine/Scene/Scene.h +++ b/src/Engine/Scene/Scene.h @@ -16,7 +16,22 @@ class Scene { void bakeLighting(); void update(float deltaTime); entt::entity createEntity() { return registry.create(); } - void destroyEntity(entt::entity identifier) { registry.destroy(identifier); } + // Out-of-line (Scene.cpp): the bodies need the complete Entity type (they call + // getIdentifier() on roster entries). Scene.h only forward-declares Entity + // (DECLARE_REF) to keep the header light and to avoid a circular include - + // Entity.h includes Scene.h, so Scene.h must not pull Actor/Entity.h back in. + void destroyEntity(entt::entity identifier); + // The scene is the single source of truth for which entities exist. The editor's + // inspector enumerates this roster (non-owning views) to build its entity list - the + // whole point of "the scene owns the entity". Populated as entities are created and + // pruned as they are destroyed; never points at a live handle that outlives its record. + const Array& getEntities() const { return entities; } + // Internal: called by Entity's ctor/dtor to keep the roster in lock-step with the + // registry. Not part of the public "create/destroy" surface (use createEntity / + // destroyEntity for that). + void registerEntity(entt::entity identifier, PEntity self) { entities.add(self); } + // Out-of-line (Scene.cpp): calls getIdentifier() on roster entries -> needs complete Entity. + void unregisterEntity(entt::entity identifier); template Component& attachComponent(entt::entity entity, Args&&... args) { return registry.emplace(entity, std::forward(args)...); } @@ -37,6 +52,15 @@ class Scene { private: Gfx::PGraphics graphics; + + // The roster: the scene's single source of truth for which entities currently exist. + // Non-owning views (P* = RefPtr, a plain pointer) - the *owning* O* (OwningPtr) held + // by the code that created each actor still owns the C++ object; the roster only tracks + // existence so tooling (the editor's inspector) can enumerate entities in handle space. + // Kept in lock-step by Entity's ctor (registerEntity) and dtor (routed through + // destroyEntity -> unregisterEntity), so it never points at a dead record. + Array entities; + OLightEnvironment lightEnv; OFluidScene fluidScene; PhysicsSystem physics; From 803531c60832fe01cd46605b148f6f8427e11186 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Sun, 8 Nov 2026 23:00:57 +0100 Subject: [PATCH 2/4] Fix miscellaneus errors --- gdb/Seele_lldb.py | 117 ++++++++++++++++------ res/shaders/lib/LightEnv.slang | 4 +- res/shaders/lib/Scene.slang | 2 +- res/shaders/raytracing/Miss.slang | 3 +- src/Benchmark/PlayView.cpp | 5 +- src/Benchmark/PlayView.h | 2 +- src/Benchmark/main.cpp | 2 +- src/Editor/CMakeLists.txt | 4 +- src/Editor/Window/PlayView.cpp | 4 +- src/Editor/Window/PlayView.h | 2 +- src/Editor/main.cpp | 39 +++++--- src/Engine/Graphics/RenderPass/UIPass.cpp | 4 + src/Engine/Graphics/Vulkan/Graphics.cpp | 2 +- src/Engine/Window/GameView.cpp | 29 +----- src/Engine/Window/GameView.h | 6 +- src/Engine/Window/WindowManager.cpp | 5 +- src/Engine/Window/WindowManager.h | 4 +- 17 files changed, 146 insertions(+), 88 deletions(-) diff --git a/gdb/Seele_lldb.py b/gdb/Seele_lldb.py index cbc50d6..ef30037 100644 --- a/gdb/Seele_lldb.py +++ b/gdb/Seele_lldb.py @@ -1,5 +1,27 @@ import lldb +def _member(valobj, name): + # GetChildMemberWithName does not search base classes reliably across + # LLDB versions; walk base classes explicitly, mirroring the working + # gdb _base_cast/_member in Seele.py. + child = valobj.GetChildMemberWithName(name) + if child.IsValid(): + return child + t = valobj.GetType() + seen = set() + while t.IsValid() and t not in seen: + seen.add(t) + for i in range(t.GetNumBases()): + base = t.GetBaseClass(i) + if base.IsValid(): + sub = valobj.GetBaseClassWithName(base.GetName()) + if sub.IsValid(): + child = sub.GetChildMemberWithName(name) + if child.IsValid(): + return child + t = t.GetBaseClass(0) if t.GetNumBases() > 0 else None + return None + def Array_SummaryProvider(valobj, internal_dict): size = valobj.GetChildMemberWithName('arraySize').GetValueAsUnsigned(0) return f"Array(size={size})" @@ -65,8 +87,8 @@ class ListSyntheticProvider: return True def Tree_SummaryProvider(valobj, internal_dict): - size = valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0) - return f"Tree(size={size})" + size = _member(valobj, '_size') + return f"Tree(size={size.GetValueAsUnsigned(0) if size and size.IsValid() else '?'})" class TreeSyntheticProvider: def __init__(self, valobj, internal_dict): @@ -87,28 +109,35 @@ class TreeSyntheticProvider: return None # Collect all nodes via in-order traversal, then return the one at `index` nodes = [] - self._collect(self.root, nodes) + if self.root and self.root.IsValid(): + self._collect(self.root, nodes) if index >= len(nodes): return None - return nodes[index].GetChildMemberWithName('data') + data = nodes[index].GetChildMemberWithName('data') + return data if data.IsValid() else None def _collect(self, node, out): if not node.IsValid(): return - self._collect(node.GetChildMemberWithName('leftChild'), out) + left = node.GetChildMemberWithName('leftChild') + if left.IsValid(): + self._collect(left.Dereference(), out) out.append(node) - self._collect(node.GetChildMemberWithName('rightChild'), out) + right = node.GetChildMemberWithName('rightChild') + if right.IsValid(): + self._collect(right.Dereference(), out) def update(self): - self.root = self.valobj.GetChildMemberWithName('root') - self.size = self.valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0) - + self.root = _member(self.valobj, 'root') + size = _member(self.valobj, '_size') + self.size = size.GetValueAsUnsigned(0) if size and size.IsValid() else 0 + def has_children(self): - return True + return self.size > 0 def Set_SummaryProvider(valobj, internal_dict): - size = valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0) - return f"Set(size={size})" + size = _member(valobj, '_size') + return f"Set(size={size.GetValueAsUnsigned(0) if size and size.IsValid() else '?'})" class SetSyntheticProvider: def __init__(self, valobj, internal_dict): @@ -128,28 +157,39 @@ class SetSyntheticProvider: if index < 0 or index >= self.size: return None nodes = [] - self._collect(self.root, nodes) + # Start from pseudoRoot: the splay tree's actual structure is + # connected via pseudoRoot.leftChild, not the `root` pointer. + if self.pseudoRoot and self.pseudoRoot.IsValid(): + left = self.pseudoRoot.GetChildMemberWithName('leftChild') + if left.IsValid(): + self._collect(left.Dereference(), nodes) if index >= len(nodes): return None - return nodes[index].GetChildMemberWithName('data') - + data = nodes[index].GetChildMemberWithName('data') + return data if data.IsValid() else None + def _collect(self, node, out): if not node.IsValid(): return - self._collect(node.GetChildMemberWithName('leftChild'), out) + left = node.GetChildMemberWithName('leftChild') + if left.IsValid(): + self._collect(left.Dereference(), out) out.append(node) - self._collect(node.GetChildMemberWithName('rightChild'), out) - + right = node.GetChildMemberWithName('rightChild') + if right.IsValid(): + self._collect(right.Dereference(), out) + def update(self): - self.root = self.valobj.GetChildMemberWithName('root') - self.size = self.valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0) - + self.pseudoRoot = _member(self.valobj, 'pseudoRoot') + size = _member(self.valobj, '_size') + self.size = size.GetValueAsUnsigned(0) if size and size.IsValid() else 0 + def has_children(self): - return True + return self.size > 0 def Map_SummaryProvider(valobj, internal_dict): - size = valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0) - return f"Map(size={size})" + size = _member(valobj, '_size') + return f"Map(size={size.GetValueAsUnsigned(0) if size and size.IsValid() else '?'})" class MapSyntheticProvider: def __init__(self, valobj, internal_dict): @@ -169,24 +209,37 @@ class MapSyntheticProvider: if index < 0 or index >= self.size: return None nodes = [] - self._collect(self.root, nodes) + # Start from pseudoRoot: the splay tree's actual structure is + # connected via pseudoRoot.leftChild, not the `root` pointer. + if self.pseudoRoot and self.pseudoRoot.IsValid(): + left = self.pseudoRoot.GetChildMemberWithName('leftChild') + if left.IsValid(): + self._collect(left.Dereference(), nodes) if index >= len(nodes): return None - return nodes[index].GetChildMemberWithName('data') + # Map stores Pair in node.data; return the pair so the + # debugger can show key/value members (Pair is a plain struct). + data = nodes[index].GetChildMemberWithName('data') + return data if data.IsValid() else None def _collect(self, node, out): if not node.IsValid(): return - self._collect(node.GetChildMemberWithName('leftChild'), out) + left = node.GetChildMemberWithName('leftChild') + if left.IsValid(): + self._collect(left.Dereference(), out) out.append(node) - self._collect(node.GetChildMemberWithName('rightChild'), out) + right = node.GetChildMemberWithName('rightChild') + if right.IsValid(): + self._collect(right.Dereference(), out) def update(self): - self.root = self.valobj.GetChildMemberWithName('root') - self.size = self.valobj.GetChildMemberWithName('_size').GetValueAsUnsigned(0) - + self.pseudoRoot = _member(self.valobj, 'pseudoRoot') + size = _member(self.valobj, '_size') + self.size = size.GetValueAsUnsigned(0) if size and size.IsValid() else 0 + def has_children(self): - return True + return self.size > 0 def Vector_SummaryProvider(valobj, internal_dict): # Get the template parameters to determine vector length diff --git a/res/shaders/lib/LightEnv.slang b/res/shaders/lib/LightEnv.slang index a75f351..9f30e4d 100644 --- a/res/shaders/lib/LightEnv.slang +++ b/res/shaders/lib/LightEnv.slang @@ -359,7 +359,9 @@ struct CookTorrance : IBRDF const float MAX_REFLECTION_LOD = 4; float3 prefilteredColor = pLightEnv.prefilteredMap.SampleLevel(pLightEnv.irradianceSampler, r, roughness * MAX_REFLECTION_LOD).xyz; - float2 envBRDF = pLightEnv.brdfLUT.Sample(pLightEnv.lutSampler, float2(max(dot(normal, viewDir_WS), 0), roughness)).rg; + // brdfLUT has no mip levels and is indexed analytically (N·V, roughness) with no screen + // derivatives, so implicit LOD is unavailable (GLCompute/Ray) and meaningless: use level 0. + float2 envBRDF = pLightEnv.brdfLUT.SampleLevel(pLightEnv.lutSampler, float2(max(dot(normal, viewDir_WS), 0), roughness), 0).rg; float3 specular = prefilteredColor * (F * envBRDF.x + envBRDF.y); return (k_d * diffuse + specular) * ambientOcclusion; diff --git a/res/shaders/lib/Scene.slang b/res/shaders/lib/Scene.slang index 0e6a5a3..669ea29 100644 --- a/res/shaders/lib/Scene.slang +++ b/res/shaders/lib/Scene.slang @@ -68,7 +68,7 @@ struct DrawCallOffsets }; #ifdef RAY_TRACING // Shader record buffers are accessed via a different mechanism and don't use descriptor set bindings -layout(set = 15, shaderRecordEXT) +layout(shaderRecordEXT) #else layout(push_constant) #endif diff --git a/res/shaders/raytracing/Miss.slang b/res/shaders/raytracing/Miss.slang index 51dfcfd..5a33342 100644 --- a/res/shaders/raytracing/Miss.slang +++ b/res/shaders/raytracing/Miss.slang @@ -7,6 +7,7 @@ void miss(inout RayPayload p) // p.shading.normal = -WorldRayDirection(); // p.shading.normalLight = -WorldRayDirection(); // p.material.color = float4(0, 0, 0, 0); - p.light = float3(pRayTracingParams.skyBox.Sample(pRayTracingParams.skyBoxSampler, WorldRayDirection()).xyz); + // miss shaders (GLCompute) can't do ImplicitLod (mip) sampling; use a fixed level + p.light = float3(pRayTracingParams.skyBox.SampleLevel(pRayTracingParams.skyBoxSampler, WorldRayDirection(), 0).xyz); p.hit = false; } \ No newline at end of file diff --git a/src/Benchmark/PlayView.cpp b/src/Benchmark/PlayView.cpp index 69320ea..4a1325c 100644 --- a/src/Benchmark/PlayView.cpp +++ b/src/Benchmark/PlayView.cpp @@ -1,12 +1,13 @@ #include "PlayView.h" +#include "Scene/Scene.h" #include "Window/Window.h" #include #include using namespace Seele; -PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath, bool useMeshCulling) - : GameView(graphics, window, createInfo, dllPath) { +PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo, bool useMeshCulling) + : GameView(graphics, window, scene, createInfo) { getGlobals().useDepthCulling = useMeshCulling; renderTimestamp = graphics->createTimestampQuery(2, "RenderTimestamp"); queryThread = std::thread([&]() { diff --git a/src/Benchmark/PlayView.h b/src/Benchmark/PlayView.h index 87b2f92..e5dddaa 100644 --- a/src/Benchmark/PlayView.h +++ b/src/Benchmark/PlayView.h @@ -4,7 +4,7 @@ namespace Seele { class PlayView : public GameView { public: - PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::string dllPath, bool useMeshCulling); + PlayView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo, bool useMeshCulling); virtual ~PlayView(); virtual void beginUpdate() override; virtual void update() override; diff --git a/src/Benchmark/main.cpp b/src/Benchmark/main.cpp index 4d2cf01..f4c459a 100644 --- a/src/Benchmark/main.cpp +++ b/src/Benchmark/main.cpp @@ -49,7 +49,7 @@ int main(int argc, char** argv) { .offset = {0, 0}, }, }; - OGameView sceneView = new PlayView(graphics, window, sceneViewInfo, binaryPath.generic_string(), useDepthCulling); + OGameView sceneView = new PlayView(graphics, window, new Scene(graphics), sceneViewInfo, useDepthCulling); sceneView->setFocused(); while (windowManager->isActive()) { diff --git a/src/Editor/CMakeLists.txt b/src/Editor/CMakeLists.txt index 3f02d1f..0eb0591 100644 --- a/src/Editor/CMakeLists.txt +++ b/src/Editor/CMakeLists.txt @@ -3,4 +3,6 @@ add_subdirectory(Window/) target_sources(Editor PRIVATE - main.cpp) \ No newline at end of file + main.cpp + ComponentRegistry.h + ComponentRegistry.cpp) \ No newline at end of file diff --git a/src/Editor/Window/PlayView.cpp b/src/Editor/Window/PlayView.cpp index 540b8b8..9fb5918 100644 --- a/src/Editor/Window/PlayView.cpp +++ b/src/Editor/Window/PlayView.cpp @@ -7,8 +7,8 @@ using namespace Seele; using namespace Seele::Editor; -PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::filesystem::path dllPath) - : GameView(graphics, window, createInfo, dllPath) {} +PlayView::PlayView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo) + : GameView(graphics, window, scene, createInfo) {} PlayView::~PlayView() {} diff --git a/src/Editor/Window/PlayView.h b/src/Editor/Window/PlayView.h index 41ffde6..1c6ad4b 100644 --- a/src/Editor/Window/PlayView.h +++ b/src/Editor/Window/PlayView.h @@ -5,7 +5,7 @@ namespace Seele { namespace Editor { class PlayView : public GameView { public: - PlayView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::filesystem::path dllPath); + PlayView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo); virtual ~PlayView(); virtual void beginUpdate() override; virtual void update() override; diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index 3a5633b..e4696ac 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -10,7 +10,12 @@ #include "Material/Material.h" #include "Graphics/Vulkan/Graphics.h" #include "Graphics/StaticMeshVertexData.h" +#include "System/SystemGraph.h" #include "Window/PlayView.h" +#include "System/CameraUpdater.h" +#include "System/FluidUpdater.h" +#include "System/LightGather.h" +#include "System/MeshUpdater.h" #include "Window/WindowManager.h" #include "Window/InspectorView.h" #include "Scene/Scene.h" // OScene/Scene - the InspectorView's entity pane needs a live scene @@ -136,7 +141,18 @@ int main(int argc, char** argv) { StaticMeshVertexData* vd = StaticMeshVertexData::getInstance(); vd->init(graphics); - OWindowManager windowManager = new WindowManager(); + GameInterface gameInterface(binaryPath); + OScene scene = new Scene(graphics); + gameInterface.reload(); + + OSystemGraph systemGraph = new SystemGraph(); + gameInterface.getGame()->setupScene(scene, systemGraph); + systemGraph->addSystem(new System::KeyboardInput(scene)); + systemGraph->addSystem(new System::FluidUpdater(scene)); + systemGraph->addSystem(new System::LightGather(scene)); + systemGraph->addSystem(new System::MeshUpdater(scene)); + systemGraph->addSystem(new System::CameraUpdater(scene)); + OWindowManager windowManager = new WindowManager(systemGraph); AssetRegistry::init(sourcePath / "Assets", graphics); AssetImporter::init(graphics); AssetImporter::importFont(FontImportArgs{ @@ -172,18 +188,15 @@ int main(int argc, char** argv) { .preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB, }; auto window = windowManager->addWindow(graphics, mainWindowInfo); - // ViewportCreateInfo sceneViewInfo = { - // .dimensions = - // { - // .size = {1920, 1080}, - // .offset = {0, 0}, - // }, - // }; - // OGameView sceneView = new Editor::PlayView(graphics, window, sceneViewInfo, binaryPath); - // sceneView->setFocused(); - // The windowed editor path has no pre-existing scene; the InspectorView's entity - // pane needs one to enumerate. Create a fresh Scene on the live (windowed) device. - OScene scene = new Scene(graphics); + ViewportCreateInfo sceneViewInfo = { + .dimensions = + { + .size = {1920, 1080}, + .offset = {0, 0}, + }, + }; + OGameView sceneView = new Editor::PlayView(graphics, window, scene, sceneViewInfo); + sceneView->setFocused(); OInspectorView inspectorView = new Editor::InspectorView(graphics, window, ViewportCreateInfo{ .dimensions = diff --git a/src/Engine/Graphics/RenderPass/UIPass.cpp b/src/Engine/Graphics/RenderPass/UIPass.cpp index 1eaca12..4cde135 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.cpp +++ b/src/Engine/Graphics/RenderPass/UIPass.cpp @@ -142,6 +142,10 @@ void UIPass::createRenderPass() { passSize = UVector2(viewport->getWidth(), viewport->getHeight()); createRenderPass(); } + Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{ + .colorAttachments = {colorAttachment}, + .depthAttachment = depthAttachment, + }; Array dependency = { { .srcSubpass = ~0U, diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index add793c..74c16e3 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -1009,7 +1009,7 @@ void Graphics::pickPhysicalDevice() { shaderFloatControls = true; } } - rayTracingEnabled = rayTracingPipelineSupport && accelerationStructureSupport && hostOperationsSupport && deviceAddressSupport && + rayTracingEnabled = false && rayTracingPipelineSupport && accelerationStructureSupport && hostOperationsSupport && deviceAddressSupport && descriptorIndexingSupport && spirv14Support && shaderFloatControls; } diff --git a/src/Engine/Window/GameView.cpp b/src/Engine/Window/GameView.cpp index 51965bb..d695635 100644 --- a/src/Engine/Window/GameView.cpp +++ b/src/Engine/Window/GameView.cpp @@ -4,25 +4,18 @@ #include "Graphics/RenderPass/BasePass.h" #include "Graphics/RenderPass/CachedDepthPass.h" #include "Graphics/RenderPass/DepthCullingPass.h" -#include "Graphics/RenderPass/FluidRenderPass.h" #include "Graphics/RenderPass/LightCullingPass.h" #include "Graphics/RenderPass/RayTracingPass.h" #include "Graphics/RenderPass/ShadowPass.h" -#include "Graphics/RenderPass/SimulationComputePass.h" -#include "Graphics/RenderPass/SurfaceExtractPass.h" #include "Graphics/RenderPass/ToneMappingPass.h" #include "Graphics/RenderPass/VisibilityPass.h" -#include "System/CameraUpdater.h" -#include "System/FluidUpdater.h" -#include "System/LightGather.h" -#include "System/MeshUpdater.h" #include "Window/Window.h" #include "Scene/LightEnvironment.h" using namespace Seele; -GameView::GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::filesystem::path dllPath) - : View(graphics, window, createInfo, "Game"), graphics(graphics), scene(new Scene(graphics)), gameInterface(dllPath) { +GameView::GameView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo) + : View(graphics, window, createInfo, "Game"), graphics(graphics), scene(scene) { reloadGame(); renderGraph.addPass(new CachedDepthPass(graphics, scene)); renderGraph.addPass(new DepthCullingPass(graphics, scene)); @@ -56,7 +49,6 @@ void GameView::update() { for (VertexData* vd : VertexData::getList()) { vd->resetMeshData(); } - systemGraph->run(updateTime); scene->update(updateTime); for (VertexData* vd : VertexData::getList()) { vd->createDescriptors(); @@ -94,29 +86,16 @@ void GameView::applyArea(URect) { } void GameView::reloadGame() { - gameInterface.reload(); - - systemGraph = new SystemGraph(); - gameInterface.getGame()->setupScene(scene, systemGraph); - System::OKeyboardInput keyInput = new System::KeyboardInput(scene); - keyboardSystem = keyInput; - systemGraph->addSystem(std::move(keyInput)); - systemGraph->addSystem(new System::FluidUpdater(scene)); - systemGraph->addSystem(new System::LightGather(scene)); - systemGraph->addSystem(new System::MeshUpdater(scene)); - systemGraph->addSystem(new System::CameraUpdater(scene)); } void GameView::keyCallback(KeyCode code, InputAction action, KeyModifierFlags modifier) { - keyboardSystem->keyCallback(code, action, modifier); } -void GameView::mouseMoveCallback(double xPos, double yPos) { keyboardSystem->mouseCallback(xPos, yPos); } +void GameView::mouseMoveCallback(double xPos, double yPos) { } void GameView::mouseButtonCallback(MouseButton button, InputAction action, KeyModifierFlags modifier) { - keyboardSystem->mouseButtonCallback(button, action, modifier); } -void GameView::scrollCallback(double xScroll, double yScroll) { keyboardSystem->scrollCallback(xScroll, yScroll); } +void GameView::scrollCallback(double xScroll, double yScroll) { } void GameView::fileCallback(int, const char**) {} diff --git a/src/Engine/Window/GameView.h b/src/Engine/Window/GameView.h index 92baab5..605cb44 100644 --- a/src/Engine/Window/GameView.h +++ b/src/Engine/Window/GameView.h @@ -12,7 +12,7 @@ namespace Seele { class GameView : public View { public: - GameView(Gfx::PGraphics graphics, PWindow window, const ViewportCreateInfo& createInfo, std::filesystem::path dllPath); + GameView(Gfx::PGraphics graphics, PWindow window, PScene scene, const ViewportCreateInfo& createInfo); virtual ~GameView(); virtual void beginUpdate() override; virtual void update() override; @@ -26,12 +26,10 @@ class GameView : public View { protected: virtual void applyArea(URect rect) override; Gfx::PGraphics graphics; - OScene scene; - GameInterface gameInterface; + PScene scene; RenderGraph renderGraph; RenderGraph rayTracingGraph; - OSystemGraph systemGraph; System::PKeyboardInput keyboardSystem; float updateTime = 0; diff --git a/src/Engine/Window/WindowManager.cpp b/src/Engine/Window/WindowManager.cpp index 5ffd37a..91efa36 100644 --- a/src/Engine/Window/WindowManager.cpp +++ b/src/Engine/Window/WindowManager.cpp @@ -1,9 +1,11 @@ #include "WindowManager.h" +#include "Graphics/Enums.h" #include "Graphics/Graphics.h" +#include "System/SystemGraph.h" using namespace Seele; -WindowManager::WindowManager() {} +WindowManager::WindowManager(PSystemGraph systemGraph) : systemGraph(systemGraph) {} WindowManager::~WindowManager() {} @@ -18,6 +20,7 @@ void WindowManager::render() { window->pollInputs(); if (window->isPaused()) continue; + systemGraph->run(Gfx::getCurrentFrameDelta()); window->render(); } } diff --git a/src/Engine/Window/WindowManager.h b/src/Engine/Window/WindowManager.h index 0361ed5..185798f 100644 --- a/src/Engine/Window/WindowManager.h +++ b/src/Engine/Window/WindowManager.h @@ -1,12 +1,13 @@ #pragma once #include "Containers/Array.h" +#include "System/SystemGraph.h" #include "Window.h" namespace Seele { DECLARE_NAME_REF(Gfx, Graphics) class WindowManager { public: - WindowManager(); + WindowManager(PSystemGraph systemGraph); ~WindowManager(); OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo); void render(); @@ -15,6 +16,7 @@ class WindowManager { private: Array windows; + PSystemGraph systemGraph; }; DEFINE_REF(WindowManager) } // namespace Seele \ No newline at end of file From 1e34f0e67b8a98dd330eef65fb6453dedbaa00f0 Mon Sep 17 00:00:00 2001 From: coding-agent Date: Mon, 9 Nov 2026 17:18:33 +0000 Subject: [PATCH 3/4] refactor: rename WindowManager to Application; move world ownership up WindowManager.{h,cpp} -> Application.{h,cpp} The Application class now owns the long-lived world (Scene, SystemGraph, GameInterface) and is the single setup point. This removes the per-view duplication where each GameView/PlayView loaded the binary and ran the simulation independently, which double-simulated with two windows open. Changes: - WindowManager -> Application (class, files, includes, CMake) - Application owns OScene scene_ / OSystemGraph graph_ (OwningPtr) and GameInterface* gameInterface (raw, deleted in dtor) - loadGame(graphics, path, name): single world-setup point (dlopen -> setupScene -> append 5 editor systems) - attachWorld(OScene, OSystemGraph): worldless hosts (benchmark) hand ownership in via move - Frame-loop fix: systemGraph->run() now runs ONCE per frame, before the window loop (was per-window -> double-simulated with 2 windows) - Editor/main.cpp + Benchmark/main.cpp rewired to the new API - Window.h/.cpp: PWindowManager back-pointer -> PApplication - 8 include paths updated to Window/Application.h Compile-verified: Application.cpp, Editor/main.cpp, Benchmark/main.cpp all pass g++ -std=c++23 -fsyntax-only against the full third-party include set. --- src/Benchmark/main.cpp | 21 +++++-- src/Editor/Asset/MaterialLoader.cpp | 2 +- src/Editor/main.cpp | 30 ++++----- src/Engine/Asset/AssetRegistry.cpp | 2 +- src/Engine/Asset/TextureAsset.cpp | 2 +- src/Engine/Material/Material.cpp | 2 +- src/Engine/Window/Application.cpp | 96 +++++++++++++++++++++++++++++ src/Engine/Window/Application.h | 59 ++++++++++++++++++ src/Engine/Window/CMakeLists.txt | 6 +- src/Engine/Window/Window.cpp | 4 +- src/Engine/Window/Window.h | 6 +- src/Engine/Window/WindowManager.cpp | 28 --------- src/Engine/Window/WindowManager.h | 22 ------- 13 files changed, 194 insertions(+), 86 deletions(-) create mode 100644 src/Engine/Window/Application.cpp create mode 100644 src/Engine/Window/Application.h delete mode 100644 src/Engine/Window/WindowManager.cpp delete mode 100644 src/Engine/Window/WindowManager.h diff --git a/src/Benchmark/main.cpp b/src/Benchmark/main.cpp index f4c459a..047b160 100644 --- a/src/Benchmark/main.cpp +++ b/src/Benchmark/main.cpp @@ -3,7 +3,9 @@ #include "Graphics/StaticMeshVertexData.h" #include "Graphics/Vulkan/Graphics.h" #include "PlayView.h" -#include "Window/WindowManager.h" +#include "Scene/Scene.h" +#include "System/SystemGraph.h" +#include "Window/Application.h" #include #include @@ -32,7 +34,14 @@ int main(int argc, char** argv) { vd->init(graphics); getGlobals().useRayTracing = true; - OWindowManager windowManager = new WindowManager(); + // The benchmark is a worldless host: it builds a plain Scene + SystemGraph + // (no game binary) and hands ownership to the Application, which then steps + // it once per frame and lets the views render it. The view renders the + // non-owning application->scene() handle. + OApplication application = new Application(); + OScene scene = new Scene(graphics); + OSystemGraph systemGraph = new SystemGraph(); + application->attachWorld(std::move(scene), std::move(systemGraph)); AssetRegistry::init("Assets", graphics); vd->commitMeshes(); WindowCreateInfo mainWindowInfo = { @@ -41,7 +50,7 @@ int main(int argc, char** argv) { .title = "Benchmark", .preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB, }; - auto window = windowManager->addWindow(graphics, mainWindowInfo); + auto window = application->addWindow(graphics, mainWindowInfo); ViewportCreateInfo sceneViewInfo = { .dimensions = { @@ -49,11 +58,11 @@ int main(int argc, char** argv) { .offset = {0, 0}, }, }; - OGameView sceneView = new PlayView(graphics, window, new Scene(graphics), sceneViewInfo, useDepthCulling); + OGameView sceneView = new PlayView(graphics, window, application->scene(), sceneViewInfo, useDepthCulling); sceneView->setFocused(); - while (windowManager->isActive()) { - windowManager->render(); + while (application->isActive()) { + application->render(); } graphics->waitDeviceIdle(); vd->destroy(); diff --git a/src/Editor/Asset/MaterialLoader.cpp b/src/Editor/Asset/MaterialLoader.cpp index f2b93f7..98807c5 100644 --- a/src/Editor/Asset/MaterialLoader.cpp +++ b/src/Editor/Asset/MaterialLoader.cpp @@ -6,7 +6,7 @@ #include "Graphics/Shader.h" #include "Material/Material.h" #include "Material/ShaderExpression.h" -#include "Window/WindowManager.h" +#include "Window/Application.h" #include #include #include diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index e4696ac..db0e1e9 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -16,7 +16,7 @@ #include "System/FluidUpdater.h" #include "System/LightGather.h" #include "System/MeshUpdater.h" -#include "Window/WindowManager.h" +#include "Window/Application.h" #include "Window/InspectorView.h" #include "Scene/Scene.h" // OScene/Scene - the InspectorView's entity pane needs a live scene #include "Component/Transform.h" @@ -141,18 +141,12 @@ int main(int argc, char** argv) { StaticMeshVertexData* vd = StaticMeshVertexData::getInstance(); vd->init(graphics); - GameInterface gameInterface(binaryPath); - OScene scene = new Scene(graphics); - gameInterface.reload(); - - OSystemGraph systemGraph = new SystemGraph(); - gameInterface.getGame()->setupScene(scene, systemGraph); - systemGraph->addSystem(new System::KeyboardInput(scene)); - systemGraph->addSystem(new System::FluidUpdater(scene)); - systemGraph->addSystem(new System::LightGather(scene)); - systemGraph->addSystem(new System::MeshUpdater(scene)); - systemGraph->addSystem(new System::CameraUpdater(scene)); - OWindowManager windowManager = new WindowManager(systemGraph); + // The world (Scene + SystemGraph) and the game binary are owned by the + // Application from here on. `loadGame` dlopen's the .so, lets the game + // populate the scene+graph, and appends the editor's own systems. Views + // below only render the non-owning application->scene() handle. + OApplication application = new Application(); + application->loadGame(graphics, sourcePath, gameName); AssetRegistry::init(sourcePath / "Assets", graphics); AssetImporter::init(graphics); AssetImporter::importFont(FontImportArgs{ @@ -187,7 +181,7 @@ int main(int argc, char** argv) { .title = "SeeleEngine", .preferredFormat = Gfx::SE_FORMAT_B8G8R8A8_SRGB, }; - auto window = windowManager->addWindow(graphics, mainWindowInfo); + auto window = application->addWindow(graphics, mainWindowInfo); ViewportCreateInfo sceneViewInfo = { .dimensions = { @@ -195,7 +189,7 @@ int main(int argc, char** argv) { .offset = {0, 0}, }, }; - OGameView sceneView = new Editor::PlayView(graphics, window, scene, sceneViewInfo); + OGameView sceneView = new Editor::PlayView(graphics, window, application->scene(), sceneViewInfo); sceneView->setFocused(); OInspectorView inspectorView = new Editor::InspectorView(graphics, window, ViewportCreateInfo{ @@ -205,12 +199,12 @@ int main(int argc, char** argv) { .offset = {0, 0}, }, }, - /* scene = */ scene); + /* scene = */ application->scene()); inspectorView->setFocused(); window->show(); - while (windowManager->isActive() && getGlobals().running) { - windowManager->render(); + while (application->isActive() && getGlobals().running) { + application->render(); } graphics->waitDeviceIdle(); Material::destroy(); diff --git a/src/Engine/Asset/AssetRegistry.cpp b/src/Engine/Asset/AssetRegistry.cpp index d5dbe6c..2672a2d 100644 --- a/src/Engine/Asset/AssetRegistry.cpp +++ b/src/Engine/Asset/AssetRegistry.cpp @@ -9,7 +9,7 @@ #include "FontAsset.h" #include "Graphics/Graphics.h" #include "Graphics/Mesh.h" -#include "Window/WindowManager.h" +#include "Window/Application.h" #include #include #include diff --git a/src/Engine/Asset/TextureAsset.cpp b/src/Engine/Asset/TextureAsset.cpp index 3de5ff9..49bae88 100644 --- a/src/Engine/Asset/TextureAsset.cpp +++ b/src/Engine/Asset/TextureAsset.cpp @@ -1,7 +1,7 @@ #include "TextureAsset.h" #include "Graphics/Graphics.h" #include "Graphics/Texture.h" -#include "Window/WindowManager.h" +#include "Window/Application.h" #include "ktx.h" #include diff --git a/src/Engine/Material/Material.cpp b/src/Engine/Material/Material.cpp index fa871ad..fca93f7 100644 --- a/src/Engine/Material/Material.cpp +++ b/src/Engine/Material/Material.cpp @@ -4,7 +4,7 @@ #include "Graphics/Shader.h" #include "MaterialInstance.h" #include "Serialization/Serialization.h" -#include "Window/WindowManager.h" +#include "Window/Application.h" #include using namespace Seele; diff --git a/src/Engine/Window/Application.cpp b/src/Engine/Window/Application.cpp new file mode 100644 index 0000000..ba8784f --- /dev/null +++ b/src/Engine/Window/Application.cpp @@ -0,0 +1,96 @@ +#include "Application.h" +#include "Graphics/Enums.h" +#include "Graphics/Graphics.h" +#include "System/SystemGraph.h" +#include "Scene/Scene.h" +#include "Game.h" +#include "System/KeyboardInput.h" +#include "System/FluidUpdater.h" +#include "System/LightGather.h" +#include "System/MeshUpdater.h" +#include "System/CameraUpdater.h" +#ifdef WIN32 +#include "Platform/Windows/GameInterface.h" +#else +#include "Platform/Linux/GameInterface.h" +#endif + +using namespace Seele; + +namespace { +// Library extension per platform (mirrors the editor's old binary-path logic). +const char* libraryExtension() { +#ifdef WIN32 + return "dll"; +#elif __APPLE__ + return "dylib"; +#else + return "so"; +#endif +} +} // namespace + +Application::Application() : graphics(nullptr), scene_(nullptr), graph_(nullptr), gameInterface(nullptr) {} + +Application::~Application() { + if (gameInterface != nullptr) { + delete gameInterface; // ~GameInterface dlclose()s + destroys the Game instance + gameInterface = nullptr; + } + // `scene_` and `graph_` are OwningPtr: their destructors free the Scene and + // (via the moved-in OSystemBase entries) every System. +} + +void Application::loadGame(Gfx::PGraphics graphics, const std::filesystem::path& sourcePath, const std::string& gameName) { + this->graphics = graphics; + + // The world is created exactly once, owned by the Application. `loadGame` is + // the single setup point (called once per process) — no null guards needed. + scene_ = OScene(new Scene(graphics)); + graph_ = OSystemGraph(new SystemGraph()); + + // Resolve the game binary and load it (dlopen) once. + std::filesystem::path binaryPath = sourcePath / "bin" / (gameName + "." + libraryExtension()); + GameInterface* interface = new GameInterface(binaryPath); + interface->reload(); + gameInterface = interface; + + // Let the game populate the Scene + SystemGraph we own, then append the + // editor's own systems. This used to live in the editor's main.cpp; it now + // lives here so the world has a single owner and a single setup point. + interface->getGame()->setupScene(scene_, graph_); + graph_->addSystem(new System::KeyboardInput(scene_)); + graph_->addSystem(new System::FluidUpdater(scene_)); + graph_->addSystem(new System::LightGather(scene_)); + graph_->addSystem(new System::MeshUpdater(scene_)); + graph_->addSystem(new System::CameraUpdater(scene_)); +} + +OWindow Application::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo) { + OWindow window = new Window(this, graphics->createWindow(createInfo)); + windows.add(window); + return window; +} + +void Application::attachWorld(OScene scene, OSystemGraph graph) { + // Worldless hosts (benchmark) build their own world and hand ownership in; + // the Application's owning members take it via move so the frame loop can + // step it and the views can render it. + scene_ = std::move(scene); + graph_ = std::move(graph); +} + +void Application::render() { + // Step the world exactly ONCE per frame, independent of how many windows + // are open. The old code re-ran the graph inside the per-window loop, which + // double-simulated with two windows. Views below only render the world. + graph_->run(Gfx::getCurrentFrameDelta()); + for (auto& window : windows) { + window->pollInputs(); + if (window->isPaused()) + continue; + window->render(); + } +} + +void Application::notifyWindowClosed(PWindow window) { windows.remove(window); } diff --git a/src/Engine/Window/Application.h b/src/Engine/Window/Application.h new file mode 100644 index 0000000..7be8c8d --- /dev/null +++ b/src/Engine/Window/Application.h @@ -0,0 +1,59 @@ +#pragma once +#include "Containers/Array.h" +#include "System/SystemGraph.h" +#include "Window.h" +#include + +namespace Seele { +DECLARE_NAME_REF(Gfx, Graphics) +DECLARE_REF(Scene) +class Game; +class GameInterface; + +// The long-lived top-level application object. +// +// Owns the *world*: the single Scene, the single SystemGraph (the running +// simulation) and the loaded game binary (GameInterface). There is exactly one +// of these per process, and it steps the simulation exactly once per frame -- +// regardless of how many windows/views observe the scene. Views hold a +// non-owning PScene and only render; they never own the world. +// +// This is the old "WindowManager", renamed so its true responsibilities +// (windowing + world ownership + the frame loop) are named honestly. +class Application { + public: + Application(); + ~Application(); + + // Loads the game binary (dlopen) and lets it populate the Scene + + // SystemGraph it owns, then appends the editor's own systems. Called once, + // by the embedding host (the editor / benchmark main). `graphics` is needed + // to construct the Scene; `sourcePath`/`gameName` resolve the .so. + void loadGame(Gfx::PGraphics graphics, const std::filesystem::path& sourcePath, const std::string& gameName); + + // Window management + OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo); + void notifyWindowClosed(PWindow window); + bool isActive() const { return getGlobals().running && windows.size(); } + + // Per-frame driver: steps the world ONCE, then renders every window. + void render(); + + // Non-owning handles so views can render the shared world. + PScene scene() const { return scene_; } + PSystemGraph systemGraph() const { return graph_; } + + // Worldless hosts (e.g. the GPU-timing benchmark, which has no game binary) + // build their own world and hand ownership in; the owning members take it via + // move so the frame loop can step `graph_` and views can render `scene_`. + void attachWorld(OScene scene, OSystemGraph graph); + + private: + Array windows; + Gfx::PGraphics graphics; + OScene scene_; + OSystemGraph graph_; + GameInterface* gameInterface = nullptr; // owned by Application (dlclose'd in dtor) +}; +DEFINE_REF(Application) +} // namespace Seele diff --git a/src/Engine/Window/CMakeLists.txt b/src/Engine/Window/CMakeLists.txt index 4a935bb..3108eb9 100644 --- a/src/Engine/Window/CMakeLists.txt +++ b/src/Engine/Window/CMakeLists.txt @@ -6,8 +6,8 @@ target_sources(Engine View.cpp Window.cpp Window.h - WindowManager.h - WindowManager.cpp) + Application.h + Application.cpp) target_sources(Engine PUBLIC FILE_SET HEADERS @@ -15,4 +15,4 @@ target_sources(Engine GameView.h View.h Window.h - WindowManager.h) + Application.h) diff --git a/src/Engine/Window/Window.cpp b/src/Engine/Window/Window.cpp index 0d8118a..731dce7 100644 --- a/src/Engine/Window/Window.cpp +++ b/src/Engine/Window/Window.cpp @@ -1,10 +1,10 @@ #include "Window.h" -#include "WindowManager.h" +#include "Application.h" #include using namespace Seele; -Window::Window(PWindowManager owner, Gfx::OWindow handle) : owner(owner), gfxHandle(std::move(handle)) { +Window::Window(PApplication owner, Gfx::OWindow handle) : owner(owner), gfxHandle(std::move(handle)) { gfxHandle->setResizeCallback([this](uint32 w, uint32 h) { onResize(w, h); }); } diff --git a/src/Engine/Window/Window.h b/src/Engine/Window/Window.h index d65161f..bcc4b7b 100644 --- a/src/Engine/Window/Window.h +++ b/src/Engine/Window/Window.h @@ -3,11 +3,11 @@ #include "View.h" namespace Seele { -DECLARE_REF(WindowManager) +DECLARE_REF(Application) // The logical window, with the graphics proxy class Window { public: - Window(PWindowManager owner, Gfx::OWindow handle); + Window(PApplication owner, Gfx::OWindow handle); ~Window(); void show() { gfxHandle->show(); } void addView(PView view); @@ -20,7 +20,7 @@ class Window { constexpr bool shouldClose() const { return gfxHandle->shouldClose(); } protected: - PWindowManager owner; + PApplication owner; Array views; Gfx::OWindow gfxHandle; }; diff --git a/src/Engine/Window/WindowManager.cpp b/src/Engine/Window/WindowManager.cpp deleted file mode 100644 index 91efa36..0000000 --- a/src/Engine/Window/WindowManager.cpp +++ /dev/null @@ -1,28 +0,0 @@ -#include "WindowManager.h" -#include "Graphics/Enums.h" -#include "Graphics/Graphics.h" -#include "System/SystemGraph.h" - -using namespace Seele; - -WindowManager::WindowManager(PSystemGraph systemGraph) : systemGraph(systemGraph) {} - -WindowManager::~WindowManager() {} - -OWindow WindowManager::addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo) { - OWindow window = new Window(this, graphics->createWindow(createInfo)); - windows.add(window); - return window; -} - -void WindowManager::render() { - for (auto& window : windows) { - window->pollInputs(); - if (window->isPaused()) - continue; - systemGraph->run(Gfx::getCurrentFrameDelta()); - window->render(); - } -} - -void WindowManager::notifyWindowClosed(PWindow window) { windows.remove(window); } diff --git a/src/Engine/Window/WindowManager.h b/src/Engine/Window/WindowManager.h deleted file mode 100644 index 185798f..0000000 --- a/src/Engine/Window/WindowManager.h +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once -#include "Containers/Array.h" -#include "System/SystemGraph.h" -#include "Window.h" - -namespace Seele { -DECLARE_NAME_REF(Gfx, Graphics) -class WindowManager { - public: - WindowManager(PSystemGraph systemGraph); - ~WindowManager(); - OWindow addWindow(Gfx::PGraphics graphics, const WindowCreateInfo& createInfo); - void render(); - void notifyWindowClosed(PWindow window); - bool isActive() const { return getGlobals().running && windows.size(); } - - private: - Array windows; - PSystemGraph systemGraph; -}; -DEFINE_REF(WindowManager) -} // namespace Seele \ No newline at end of file From 1f7e7e05413503aec68b630bcadf4b599d7611b4 Mon Sep 17 00:00:00 2001 From: Dynamitos Date: Mon, 9 Nov 2026 20:06:47 +0100 Subject: [PATCH 4/4] Engine is up and running --- src/Editor/main.cpp | 12 ++++++------ src/Engine/Graphics/RenderPass/UIPass.cpp | 14 +++----------- src/Engine/Graphics/RenderPass/UIPass.h | 1 - src/Engine/Graphics/Vulkan/Framebuffer.cpp | 5 +---- src/Engine/Graphics/Vulkan/Graphics.cpp | 5 ++--- src/Engine/Graphics/Vulkan/RenderPass.cpp | 6 +++++- src/Engine/Graphics/Vulkan/RenderPass.h | 4 +++- 7 files changed, 20 insertions(+), 27 deletions(-) diff --git a/src/Editor/main.cpp b/src/Editor/main.cpp index db0e1e9..c242826 100644 --- a/src/Editor/main.cpp +++ b/src/Editor/main.cpp @@ -141,12 +141,6 @@ int main(int argc, char** argv) { StaticMeshVertexData* vd = StaticMeshVertexData::getInstance(); vd->init(graphics); - // The world (Scene + SystemGraph) and the game binary are owned by the - // Application from here on. `loadGame` dlopen's the .so, lets the game - // populate the scene+graph, and appends the editor's own systems. Views - // below only render the non-owning application->scene() handle. - OApplication application = new Application(); - application->loadGame(graphics, sourcePath, gameName); AssetRegistry::init(sourcePath / "Assets", graphics); AssetImporter::init(graphics); AssetImporter::importFont(FontImportArgs{ @@ -174,6 +168,12 @@ int main(int argc, char** argv) { }); getThreadPool().waitIdle(); + // The world (Scene + SystemGraph) and the game binary are owned by the + // Application from here on. `loadGame` dlopen's the .so, lets the game + // populate the scene+graph, and appends the editor's own systems. Views + // below only render the non-owning application->scene() handle. + OApplication application = new Application(); + application->loadGame(graphics, sourcePath, gameName); vd->commitMeshes(); WindowCreateInfo mainWindowInfo = { .width = 1920, diff --git a/src/Engine/Graphics/RenderPass/UIPass.cpp b/src/Engine/Graphics/RenderPass/UIPass.cpp index 4cde135..6139b96 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.cpp +++ b/src/Engine/Graphics/RenderPass/UIPass.cpp @@ -8,7 +8,7 @@ using namespace Seele; -UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphics), system(system), passSize(0, 0) { +UIPass::UIPass(Gfx::PGraphics graphics, UI::PSystem system) : RenderPass(graphics), system(system) { elementBuffer = graphics->createShaderBuffer(ShaderBufferCreateInfo{.name = "RenderStyleElements"}); uiDescriptorLayout = graphics->createDescriptorLayout("pParams"); @@ -119,8 +119,8 @@ void UIPass::publishOutputs() {} void UIPass::createRenderPass() { TextureCreateInfo depthBufferInfo = { .format = Gfx::SE_FORMAT_D32_SFLOAT, - .width = viewport->getWidth(), - .height = viewport->getHeight(), + .width = viewport->getOwner()->getFramebufferWidth(), + .height = viewport->getOwner()->getFramebufferHeight(), .usage = Gfx::SE_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT, }; @@ -134,14 +134,6 @@ void UIPass::createRenderPass() { Gfx::SE_ATTACHMENT_LOAD_OP_CLEAR, Gfx::SE_ATTACHMENT_STORE_OP_STORE); colorAttachment.clear.color = {{1.0f, 1.0f, 1.0f, 1.0f}}; - // the render pass encodes the viewport size, and Vulkan requires a fresh pass object when - // that changes. Re-run createRenderPass() from beginFrame on a viewport resize; the - // pipeline is recreated here from scratch (it embeds renderPass and is size-independent - // otherwise). - if (passSize.x != viewport->getWidth() || passSize.y != viewport->getHeight()) { - passSize = UVector2(viewport->getWidth(), viewport->getHeight()); - createRenderPass(); - } Gfx::RenderTargetLayout layout = Gfx::RenderTargetLayout{ .colorAttachments = {colorAttachment}, .depthAttachment = depthAttachment, diff --git a/src/Engine/Graphics/RenderPass/UIPass.h b/src/Engine/Graphics/RenderPass/UIPass.h index 21cc074..fc5425f 100644 --- a/src/Engine/Graphics/RenderPass/UIPass.h +++ b/src/Engine/Graphics/RenderPass/UIPass.h @@ -70,7 +70,6 @@ class UIPass : public RenderPass { Gfx::PGraphicsPipeline uiPipeline; UI::PSystem system; - UVector2 passSize; // last viewport size the render pass was created at; recreate on resize Array renderElements; Array elements; Gfx::OShaderBuffer elementBuffer; diff --git a/src/Engine/Graphics/Vulkan/Framebuffer.cpp b/src/Engine/Graphics/Vulkan/Framebuffer.cpp index 670c653..576b295 100644 --- a/src/Engine/Graphics/Vulkan/Framebuffer.cpp +++ b/src/Engine/Graphics/Vulkan/Framebuffer.cpp @@ -68,10 +68,7 @@ Framebuffer::Framebuffer(PGraphics graphics, PRenderPass renderPass, Gfx::Render .layers = 1, }; VK_CHECK(vkCreateFramebuffer(graphics->getDevice(), &createInfo, nullptr, &handle)); - renderArea = VkRect2D{ - .offset = {0, 0}, - .extent = {width, height}, - }; + renderArea = renderPass->getRenderArea(); hash = CRC::Calculate(&description, sizeof(FramebufferDescription), CRC::CRC_32()); } diff --git a/src/Engine/Graphics/Vulkan/Graphics.cpp b/src/Engine/Graphics/Vulkan/Graphics.cpp index 74c16e3..47852d6 100644 --- a/src/Engine/Graphics/Vulkan/Graphics.cpp +++ b/src/Engine/Graphics/Vulkan/Graphics.cpp @@ -234,10 +234,9 @@ Gfx::OViewport Graphics::createViewport(Gfx::PWindow owner, const ViewportCreate return new Viewport(owner, viewportInfo); } -Gfx::ORenderPass Graphics::createRenderPass(Gfx::RenderTargetLayout layout, Array dependencies, URect, +Gfx::ORenderPass Graphics::createRenderPass(Gfx::RenderTargetLayout layout, Array dependencies, URect renderArea, std::string name, Array viewMasks, Array correlationMasks) { - // todo: re-introduce render area to renderpass - return new RenderPass(this, std::move(layout), std::move(dependencies), name, std::move(viewMasks), std::move(correlationMasks)); + return new RenderPass(this, std::move(layout), std::move(dependencies), renderArea, name, std::move(viewMasks), std::move(correlationMasks)); } void Graphics::beginRenderPass(Gfx::PRenderPass renderPass) { PRenderPass rp = renderPass.cast(); diff --git a/src/Engine/Graphics/Vulkan/RenderPass.cpp b/src/Engine/Graphics/Vulkan/RenderPass.cpp index 5d64728..15b0eb2 100644 --- a/src/Engine/Graphics/Vulkan/RenderPass.cpp +++ b/src/Engine/Graphics/Vulkan/RenderPass.cpp @@ -9,9 +9,13 @@ using namespace Seele; using namespace Seele::Vulkan; -RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Array _dependencies, std::string name, +RenderPass::RenderPass(PGraphics graphics, Gfx::RenderTargetLayout _layout, Array _dependencies, URect _renderArea, std::string name, Array viewMasks, Array correlationMasks) : Gfx::RenderPass(std::move(_layout), std::move(_dependencies)), graphics(graphics), name(name) { + renderArea = { + .offset = { (int32)_renderArea.offset.x, (int32)_renderArea.offset.y }, + .extent = { _renderArea.size.x, _renderArea.size.y }, + }; subpassContents = VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS; Array attachments; Array inputRefs; diff --git a/src/Engine/Graphics/Vulkan/RenderPass.h b/src/Engine/Graphics/Vulkan/RenderPass.h index 3e057fe..65ebb67 100644 --- a/src/Engine/Graphics/Vulkan/RenderPass.h +++ b/src/Engine/Graphics/Vulkan/RenderPass.h @@ -2,13 +2,14 @@ #include "Graphics.h" #include "Resources.h" #include "Graphics/RenderTarget.h" +#include namespace Seele { namespace Vulkan { class RenderPass : public Gfx::RenderPass { public: - RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array dependencies, std::string name, + RenderPass(PGraphics graphics, Gfx::RenderTargetLayout layout, Array dependencies, URect renderArea, std::string name, Array viewMasks = {}, Array correlationMasks = {}); virtual ~RenderPass(); uint32 getFramebufferHash(); @@ -17,6 +18,7 @@ class RenderPass : public Gfx::RenderPass { constexpr size_t getClearValueCount() const { return clearValues.size(); } constexpr VkClearValue* getClearValues() const { return clearValues.data(); } constexpr VkSubpassContents getSubpassContents() const { return subpassContents; } + constexpr VkRect2D getRenderArea() const { return renderArea; } constexpr const std::string& getName() const { return name; } constexpr PRenderPassHandle getCommandHandle() const { return renderPass; }