diff --git a/src/ifcviewer/ViewportCore.h b/src/ifcviewer/ViewportCore.h index c526512149..37b517b4cd 100644 --- a/src/ifcviewer/ViewportCore.h +++ b/src/ifcviewer/ViewportCore.h @@ -20,17 +20,20 @@ #ifndef VIEWPORTCORE_H #define VIEWPORTCORE_H -// Platform-agnostic render core. Owns the wgpu state + scene state + -// per-frame render path. Talks to its embedder through ViewportHost -// (window/canvas surface, scheduling, notifications) — has no Qt or -// browser dependencies of its own. +// Platform-agnostic render core. Owns the wgpu lifecycle state + +// (eventually) scene state + per-frame render path. Talks to its +// embedder through ViewportHost (window/canvas surface, scheduling, +// notifications) — has no Qt or browser dependencies of its own. // -// Empty for now: this header / TU is the placeholder for the -// incremental Path-A refactor (#77-#86). Each subsequent commit moves -// one subsystem out of ViewportWindow.cpp into here and updates the -// public surface accordingly. Until that work lands, ViewportWindow -// retains its render body; this class is just the target for the -// move. +// First migration target (#84-a): wgpu instance/adapter/device/queue/ +// surface ownership. The next subsystems (pipelines, models, render +// path) move incrementally across subsequent commits — each leaving +// the desktop build green. ViewportWindow currently holds reference +// members pointing back at ViewportCore's storage so its body doesn't +// have to acquire a `core_.` prefix on every wgpu touch. Those +// references shrink as render methods themselves move over. + +#include #include "ViewportHost.h" @@ -44,8 +47,28 @@ public: ViewportHost* host() const { return host_; } + // Friend access for ViewportWindow's reference proxies. As each + // render method moves into ViewportCore it stops needing these + // (it touches the fields directly); once everything has migrated + // the friend declaration goes away. + friend class ViewportWindow; + private: ViewportHost* host_; + + // ---- wgpu lifecycle state ------------------------------------------------ + // + // Plain pointers (wgpu C handles); zero-init means "not yet + // initialised". Owned by ViewportCore now; reference members in + // ViewportWindow alias these so the existing call sites don't + // need to change to use a `core_.` prefix. + WGPUInstance instance_ = nullptr; + WGPUAdapter adapter_ = nullptr; + WGPUDevice device_ = nullptr; + WGPUQueue queue_ = nullptr; + WGPUSurface surface_ = nullptr; + WGPUTextureFormat surface_format_ = WGPUTextureFormat_Undefined; + bool surface_configured_ = false; }; #endif // VIEWPORTCORE_H diff --git a/src/ifcviewer/ViewportWindow.cpp b/src/ifcviewer/ViewportWindow.cpp index 311ffdf51b..ce553fc08b 100644 --- a/src/ifcviewer/ViewportWindow.cpp +++ b/src/ifcviewer/ViewportWindow.cpp @@ -606,7 +606,19 @@ static WGPUStringView svFromCStr(const char* s) { // ----------------------------------------------------------------------------- ViewportWindow::ViewportWindow(QWindow* parent) - : QWindow(parent) { + : QWindow(parent), + core_(this), + // Bind reference aliases to ViewportCore's storage so the + // existing `device_` / `queue_` / … sites in this TU keep + // working unchanged. Each reference goes away as its owning + // render method moves into ViewportCore. + instance_ (core_.instance_), + adapter_ (core_.adapter_), + device_ (core_.device_), + queue_ (core_.queue_), + surface_ (core_.surface_), + surface_format_ (core_.surface_format_), + surface_configured_(core_.surface_configured_) { // wgpu doesn't need a GL context; we just need a real native window // whose backing layer matches the GPU API wgpu will drive. // diff --git a/src/ifcviewer/ViewportWindow.h b/src/ifcviewer/ViewportWindow.h index e55eeef1bd..1df4836043 100644 --- a/src/ifcviewer/ViewportWindow.h +++ b/src/ifcviewer/ViewportWindow.h @@ -634,16 +634,25 @@ private: void recomposeAndUploadModel(uint32_t model_id); bool wgpu_initialized_ = false; - bool surface_configured_ = false; int configured_w_ = 0; int configured_h_ = 0; - WGPUInstance instance_ = nullptr; - WGPUAdapter adapter_ = nullptr; - WGPUDevice device_ = nullptr; - WGPUQueue queue_ = nullptr; - WGPUSurface surface_ = nullptr; - WGPUTextureFormat surface_format_ = WGPUTextureFormat_Undefined; + // ---- wgpu lifecycle state aliases ---------------------------------- + // + // Actual storage lives in core_ (declared below; ViewportWindow is a + // friend of ViewportCore so these references can bind). Existing + // member-access sites in ViewportWindow.cpp keep working unchanged — + // they just resolve to core_.device_ etc. through these references. + // Each one is removed when its owning render method moves into + // ViewportCore (#84-b onwards). + ViewportCore core_; + WGPUInstance& instance_; + WGPUAdapter& adapter_; + WGPUDevice& device_; + WGPUQueue& queue_; + WGPUSurface& surface_; + WGPUTextureFormat& surface_format_; + bool& surface_configured_; // Render pipeline + bind group layouts (built once after init). WGPUShaderModule main_shader_module_ = nullptr;