browser DOM support
This commit is contained in:
parent
3859c43ce3
commit
5352ef69a2
37 changed files with 2637 additions and 59 deletions
|
|
@ -17,8 +17,11 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:ComputeShader;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :Device;
|
||||
|
||||
|
|
@ -54,3 +57,4 @@ export namespace Crafter {
|
|||
std::uint32_t gz = 1) const;
|
||||
};
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -18,9 +18,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:Decompress;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import :Device;
|
||||
import std;
|
||||
|
||||
|
|
@ -131,3 +134,4 @@ export namespace Crafter::Decompress {
|
|||
vkCmdPipelineBarrier2(cmd, &dep);
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:DescriptorHeapVulkan;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :Device;
|
||||
import :Window;
|
||||
|
|
@ -326,4 +329,5 @@ export namespace Crafter {
|
|||
DescriptorHeapVulkan* heap_ = nullptr;
|
||||
std::uint16_t raw_ = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
|
|
@ -53,6 +55,7 @@ export namespace Crafter {
|
|||
struct Device {
|
||||
static void Initialize();
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
inline static wl_display* display = nullptr;
|
||||
inline static wl_seat* seat = nullptr;
|
||||
|
|
@ -178,5 +181,13 @@ export namespace Crafter {
|
|||
#else
|
||||
static void TickKeyRepeats() {}
|
||||
#endif
|
||||
#else // CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
// DOM mode: Device collapses to just `Initialize()` (currently a
|
||||
// no-op since the JS runtime initializes itself). The function is
|
||||
// kept so user code calling `Device::Initialize()` still compiles
|
||||
// cross-platform. Browser key repeat is delivered through the
|
||||
// KeyboardEvent.repeat flag directly — no manual synthesis.
|
||||
static void TickKeyRepeats() {}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
217
interfaces/Crafter.Graphics-Dom.cppm
Normal file
217
interfaces/Crafter.Graphics-Dom.cppm
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
/*
|
||||
Crafter®.Graphics
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// Browser DOM bindings — absorbed from Crafter.CppDOM. Only meaningful
|
||||
// when the build defined CRAFTER_GRAPHICS_WINDOW_DOM (i.e. a wasm32-*
|
||||
// target paired with additional/dom-env.js); on native platforms the
|
||||
// partition still parses but every method links to nothing because the
|
||||
// build excludes the impl. project.cpp's per-target module set is what
|
||||
// makes the partition disappear from the native libs.
|
||||
//
|
||||
// Two-class hierarchy (simplified from CppDOM's three-class design):
|
||||
// HtmlElementPtr — non-owning element reference. Tracks every handler
|
||||
// it registered and clears them on destruction, so
|
||||
// the silent-leak bug from CppDOM's bare-pointer
|
||||
// flavour can't happen. Releases the JS handle on
|
||||
// destruction.
|
||||
// HtmlElement — `HtmlElementPtr` plus element ownership: removes
|
||||
// the element from the DOM on destruction. The new
|
||||
// `Create` factory builds a fresh element under a
|
||||
// parent and returns one of these.
|
||||
//
|
||||
// Move-only throughout. The JS handle (`ptr`) of a moved-from instance
|
||||
// is zeroed so the destructor of the moved-from carcass is a no-op.
|
||||
|
||||
export module Crafter.Graphics:Dom;
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :DomEvents;
|
||||
|
||||
export namespace Crafter::Dom {
|
||||
|
||||
class HtmlElementPtr {
|
||||
public:
|
||||
// Opaque JS-side element cookie. 0 = "no element"; the destructor
|
||||
// treats 0 as "moved-from, nothing to release".
|
||||
std::int32_t ptr;
|
||||
|
||||
// Look up an existing element by its DOM id.
|
||||
HtmlElementPtr(const std::string_view id);
|
||||
// Look up + replace innerHTML in one step (matches CppDOM).
|
||||
HtmlElementPtr(const std::string_view id, const std::string_view html);
|
||||
|
||||
protected:
|
||||
// Adopt a JS handle directly (used by HtmlElement::Create — the
|
||||
// JS side has already minted the handle, no second lookup needed).
|
||||
// Tagged-type ctor so the public id-based overloads stay
|
||||
// unambiguous from the call site.
|
||||
struct FromHandle { std::int32_t handle; };
|
||||
explicit HtmlElementPtr(FromHandle h) noexcept : ptr(h.handle) {}
|
||||
|
||||
public:
|
||||
|
||||
// Move-only — copying would silently double-free the JS handle.
|
||||
HtmlElementPtr(HtmlElementPtr&&) noexcept;
|
||||
HtmlElementPtr& operator=(HtmlElementPtr&&) noexcept;
|
||||
HtmlElementPtr(const HtmlElementPtr&) = delete;
|
||||
HtmlElementPtr& operator=(const HtmlElementPtr&) = delete;
|
||||
|
||||
~HtmlElementPtr();
|
||||
|
||||
// DOM ops ─────────────────────────────────────────────────────
|
||||
void SetInnerHTML(const std::string_view html);
|
||||
void SetStyle(const std::string_view style);
|
||||
void SetProperty(const std::string_view property, const std::string_view value);
|
||||
void AddClass(const std::string_view className);
|
||||
void RemoveClass(const std::string_view className);
|
||||
void ToggleClass(const std::string_view className);
|
||||
bool HasClass(const std::string_view className);
|
||||
std::string GetValue();
|
||||
void SetValue(const std::string_view value);
|
||||
|
||||
// Listener API — each Add* returns an opaque id that can be
|
||||
// passed to the matching Remove*. The destructor automatically
|
||||
// removes every handler still registered, so manual removal is
|
||||
// optional. Returns 0 only if registration failed at the JS
|
||||
// boundary (the element was already collected). The 23 event
|
||||
// types are 1:1 with CppDOM's surface.
|
||||
std::int32_t AddClickListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveClickListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddMouseOverListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveMouseOverListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddMouseOutListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveMouseOutListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddMouseMoveListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveMouseMoveListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddMouseDownListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveMouseDownListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddMouseUpListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveMouseUpListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddFocusListener(std::function<void(Crafter::Dom::FocusEvent)> callback);
|
||||
void RemoveFocusListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddBlurListener(std::function<void(Crafter::Dom::FocusEvent)> callback);
|
||||
void RemoveBlurListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddKeyDownListener(std::function<void(Crafter::Dom::KeyboardEvent)> callback);
|
||||
void RemoveKeyDownListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddKeyUpListener(std::function<void(Crafter::Dom::KeyboardEvent)> callback);
|
||||
void RemoveKeyUpListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddKeyPressListener(std::function<void(Crafter::Dom::KeyboardEvent)> callback);
|
||||
void RemoveKeyPressListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddChangeListener(std::function<void(Crafter::Dom::ChangeEvent)> callback);
|
||||
void RemoveChangeListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddSubmitListener(std::function<void()> callback);
|
||||
void RemoveSubmitListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddInputListener(std::function<void(Crafter::Dom::InputEvent)> callback);
|
||||
void RemoveInputListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddResizeListener(std::function<void(Crafter::Dom::ResizeEvent)> callback);
|
||||
void RemoveResizeListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddScrollListener(std::function<void(Crafter::Dom::ScrollEvent)> callback);
|
||||
void RemoveScrollListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddContextMenuListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveContextMenuListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddDragStartListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveDragStartListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddDragEndListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveDragEndListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddDropListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveDropListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddDragOverListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveDragOverListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddDragEnterListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveDragEnterListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddDragLeaveListener(std::function<void(Crafter::Dom::MouseEvent)> callback);
|
||||
void RemoveDragLeaveListener(std::int32_t id);
|
||||
|
||||
std::int32_t AddWheelListener(std::function<void(Crafter::Dom::WheelEvent)> callback);
|
||||
void RemoveWheelListener(std::int32_t id);
|
||||
|
||||
protected:
|
||||
// Per-event-kind handler-id lists. Each `Add*Listener` push_backs
|
||||
// the id it returns; `RemoveAllHandlers` walks every list and
|
||||
// calls the matching JS Remove on each id. The lists are indexed
|
||||
// by event kind so a single handler-id collision across kinds
|
||||
// (allowed by the JS bridge — counters are per-event-kind)
|
||||
// doesn't cause a wrong-kind remove.
|
||||
std::vector<std::int32_t> handlerIds_[24];
|
||||
|
||||
// Shared cleanup used by the destructor AND by move-assignment.
|
||||
// Removes every registered handler from both the C++ map and
|
||||
// the JS side, then frees the JS handle. Leaves `ptr == 0` on
|
||||
// return so a second call is a no-op.
|
||||
void RemoveAllHandlersAndFree();
|
||||
};
|
||||
|
||||
class HtmlElement : public HtmlElementPtr {
|
||||
public:
|
||||
// Adopt an existing element by id; the dtor will remove it from
|
||||
// the DOM. Useful when the caller created the element in markup
|
||||
// and wants C++ to own its lifetime from now on.
|
||||
HtmlElement(const std::string_view id);
|
||||
HtmlElement(const std::string_view id, const std::string_view html);
|
||||
|
||||
HtmlElement(HtmlElement&&) noexcept;
|
||||
HtmlElement& operator=(HtmlElement&&) noexcept;
|
||||
|
||||
~HtmlElement();
|
||||
|
||||
// Create a new element and append it to `parent`. Optional `id`
|
||||
// sets the new element's DOM id (use it when you want to look the
|
||||
// element up from non-C++ code later); empty leaves the element
|
||||
// unnamed. Returns an owning handle — the element is removed from
|
||||
// the DOM when this `HtmlElement` is destroyed.
|
||||
static HtmlElement Create(const HtmlElementPtr& parent,
|
||||
std::string_view tagName,
|
||||
std::string_view id = {});
|
||||
|
||||
// Convenience: create a top-level element under document.body.
|
||||
static HtmlElement CreateInBody(std::string_view tagName,
|
||||
std::string_view id = {});
|
||||
|
||||
private:
|
||||
// Hidden ctor used by Create/CreateInBody — takes an already
|
||||
// allocated JS handle via the base class FromHandle tag. Kept
|
||||
// private so user code doesn't construct an HtmlElement from a
|
||||
// raw handle by accident.
|
||||
explicit HtmlElement(HtmlElementPtr::FromHandle h) noexcept
|
||||
: HtmlElementPtr(h) {}
|
||||
};
|
||||
}
|
||||
#endif // CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
119
interfaces/Crafter.Graphics-DomEvents.cppm
Normal file
119
interfaces/Crafter.Graphics-DomEvents.cppm
Normal file
|
|
@ -0,0 +1,119 @@
|
|||
/*
|
||||
Crafter®.Graphics
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// DOM event POD structs delivered by dom-env.js into the per-listener
|
||||
// callback set in :Dom. The set of fields and their semantics mirror the
|
||||
// equivalent W3C event interfaces — the JS bridge marshals each field
|
||||
// individually as a primitive over the wasm boundary (no struct passing,
|
||||
// no JSON), so the layouts here are merely what the C++ side reconstructs
|
||||
// before invoking the user's std::function.
|
||||
|
||||
export module Crafter.Graphics:DomEvents;
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
|
||||
// The Dom* namespace mirrors CppDOM's flat `Crafter::*` event types but is
|
||||
// re-homed under Crafter::Dom to avoid clashing with anything :Types or
|
||||
// :Input may later add at the bare Crafter:: scope.
|
||||
export namespace Crafter::Dom {
|
||||
struct KeyboardEvent {
|
||||
std::string key;
|
||||
std::uint_fast8_t keyCode;
|
||||
bool altKey;
|
||||
bool ctrlKey;
|
||||
bool shiftKey;
|
||||
bool metaKey;
|
||||
KeyboardEvent(const char* key, std::int32_t keyCode,
|
||||
bool altKey, bool ctrlKey, bool shiftKey, bool metaKey)
|
||||
: key(key), keyCode(keyCode),
|
||||
altKey(altKey), ctrlKey(ctrlKey),
|
||||
shiftKey(shiftKey), metaKey(metaKey) {}
|
||||
};
|
||||
|
||||
struct FocusEvent {
|
||||
// Opaque JS handle cookies — round-trip back into env.js as the
|
||||
// identity of the related element. No C++ API attaches semantics
|
||||
// to them today; held for forward-compat with later helpers.
|
||||
void* target;
|
||||
void* relatedTarget;
|
||||
FocusEvent(void* target, void* relatedTarget)
|
||||
: target(target), relatedTarget(relatedTarget) {}
|
||||
};
|
||||
|
||||
struct MouseEvent {
|
||||
double clientX;
|
||||
double clientY;
|
||||
double screenX;
|
||||
double screenY;
|
||||
std::uint_fast32_t button;
|
||||
std::uint_fast32_t buttons;
|
||||
bool altKey;
|
||||
bool ctrlKey;
|
||||
bool shiftKey;
|
||||
bool metaKey;
|
||||
MouseEvent(double clientX, double clientY, double screenX, double screenY,
|
||||
std::int32_t button, std::int32_t buttons,
|
||||
bool altKey, bool ctrlKey, bool shiftKey, bool metaKey)
|
||||
: clientX(clientX), clientY(clientY),
|
||||
screenX(screenX), screenY(screenY),
|
||||
button(button), buttons(buttons),
|
||||
altKey(altKey), ctrlKey(ctrlKey),
|
||||
shiftKey(shiftKey), metaKey(metaKey) {}
|
||||
};
|
||||
|
||||
struct InputEvent {
|
||||
std::string data;
|
||||
bool isComposing;
|
||||
InputEvent(const char* data, bool isComposing)
|
||||
: data(data), isComposing(isComposing) {}
|
||||
};
|
||||
|
||||
struct WheelEvent : public MouseEvent {
|
||||
double deltaX;
|
||||
double deltaY;
|
||||
double deltaZ;
|
||||
WheelEvent(double clientX, double clientY, double screenX, double screenY,
|
||||
std::int32_t button, std::int32_t buttons,
|
||||
bool altKey, bool ctrlKey, bool shiftKey, bool metaKey,
|
||||
double deltaX, double deltaY, double deltaZ)
|
||||
: MouseEvent(clientX, clientY, screenX, screenY,
|
||||
button, buttons, altKey, ctrlKey, shiftKey, metaKey),
|
||||
deltaX(deltaX), deltaY(deltaY), deltaZ(deltaZ) {}
|
||||
};
|
||||
|
||||
struct ResizeEvent {
|
||||
std::uint_fast32_t width;
|
||||
std::uint_fast32_t height;
|
||||
ResizeEvent(std::uint_fast32_t width, std::uint_fast32_t height)
|
||||
: width(width), height(height) {}
|
||||
};
|
||||
|
||||
struct ScrollEvent {
|
||||
double scrollX;
|
||||
double scrollY;
|
||||
ScrollEvent(double scrollX, double scrollY)
|
||||
: scrollX(scrollX), scrollY(scrollY) {}
|
||||
};
|
||||
|
||||
struct ChangeEvent {
|
||||
std::string value;
|
||||
ChangeEvent(const char* value) : value(value) {}
|
||||
};
|
||||
}
|
||||
#endif // CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
@ -20,9 +20,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
module;
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "../lib/stb_truetype.h"
|
||||
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:Font;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
|
||||
namespace Crafter {
|
||||
|
|
@ -67,4 +70,5 @@ namespace Crafter {
|
|||
float AscentPx(float size); // baseline offset from line-top
|
||||
float ScaleForSize(float size); // stb's pixel-units-per-em factor
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:FontAtlas;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :Font;
|
||||
import :ImageVulkan;
|
||||
|
|
@ -98,3 +101,4 @@ export namespace Crafter {
|
|||
bool ShelfPlace(int w, int h, int& outX, int& outY);
|
||||
};
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -19,9 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 0215-1301 USA
|
|||
|
||||
module;
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:ImageVulkan;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import Crafter.Asset;
|
||||
import :Decompress;
|
||||
|
|
@ -293,4 +296,5 @@ export namespace Crafter {
|
|||
vkCmdPipelineBarrier(cmd, sourceStage, destinationStage, 0, 0, nullptr, 0, nullptr, 1, &barrier);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -17,7 +17,11 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
module;
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:InputField;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :Types;
|
||||
import :Keys;
|
||||
|
|
@ -106,3 +110,4 @@ export namespace Crafter {
|
|||
const InputFieldColors& colors,
|
||||
bool caretVisible);
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -189,6 +189,153 @@ export namespace Crafter {
|
|||
case CrafterKeys::CrafterKeysMax: return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
// DOM mode: `KeyboardEvent.code` (a layout-independent physical-key
|
||||
// string like "KeyA" or "Space") is hashed to a 32-bit KeyCode in
|
||||
// dom-env.js and again here at compile time. FNV-1a was picked for
|
||||
// its trivial implementation — collision chance over the ~110-entry
|
||||
// key set is negligible.
|
||||
constexpr auto fnv = [](const char* s) constexpr -> KeyCode {
|
||||
std::uint32_t h = 2166136261u;
|
||||
while (*s) {
|
||||
h ^= static_cast<std::uint8_t>(*s++);
|
||||
h *= 16777619u;
|
||||
}
|
||||
return h;
|
||||
};
|
||||
switch (k) {
|
||||
// Alphabetic — KeyboardEvent.code uses "Key" prefix.
|
||||
case CrafterKeys::A: return fnv("KeyA");
|
||||
case CrafterKeys::B: return fnv("KeyB");
|
||||
case CrafterKeys::C: return fnv("KeyC");
|
||||
case CrafterKeys::D: return fnv("KeyD");
|
||||
case CrafterKeys::E: return fnv("KeyE");
|
||||
case CrafterKeys::F: return fnv("KeyF");
|
||||
case CrafterKeys::G: return fnv("KeyG");
|
||||
case CrafterKeys::H: return fnv("KeyH");
|
||||
case CrafterKeys::I: return fnv("KeyI");
|
||||
case CrafterKeys::J: return fnv("KeyJ");
|
||||
case CrafterKeys::K: return fnv("KeyK");
|
||||
case CrafterKeys::L: return fnv("KeyL");
|
||||
case CrafterKeys::M: return fnv("KeyM");
|
||||
case CrafterKeys::N: return fnv("KeyN");
|
||||
case CrafterKeys::O: return fnv("KeyO");
|
||||
case CrafterKeys::P: return fnv("KeyP");
|
||||
case CrafterKeys::Q: return fnv("KeyQ");
|
||||
case CrafterKeys::R: return fnv("KeyR");
|
||||
case CrafterKeys::S: return fnv("KeyS");
|
||||
case CrafterKeys::T: return fnv("KeyT");
|
||||
case CrafterKeys::U: return fnv("KeyU");
|
||||
case CrafterKeys::V: return fnv("KeyV");
|
||||
case CrafterKeys::W: return fnv("KeyW");
|
||||
case CrafterKeys::X: return fnv("KeyX");
|
||||
case CrafterKeys::Y: return fnv("KeyY");
|
||||
case CrafterKeys::Z: return fnv("KeyZ");
|
||||
// Numeric (top row) — DigitN.
|
||||
case CrafterKeys::_0: return fnv("Digit0");
|
||||
case CrafterKeys::_1: return fnv("Digit1");
|
||||
case CrafterKeys::_2: return fnv("Digit2");
|
||||
case CrafterKeys::_3: return fnv("Digit3");
|
||||
case CrafterKeys::_4: return fnv("Digit4");
|
||||
case CrafterKeys::_5: return fnv("Digit5");
|
||||
case CrafterKeys::_6: return fnv("Digit6");
|
||||
case CrafterKeys::_7: return fnv("Digit7");
|
||||
case CrafterKeys::_8: return fnv("Digit8");
|
||||
case CrafterKeys::_9: return fnv("Digit9");
|
||||
// Function keys.
|
||||
case CrafterKeys::F1: return fnv("F1");
|
||||
case CrafterKeys::F2: return fnv("F2");
|
||||
case CrafterKeys::F3: return fnv("F3");
|
||||
case CrafterKeys::F4: return fnv("F4");
|
||||
case CrafterKeys::F5: return fnv("F5");
|
||||
case CrafterKeys::F6: return fnv("F6");
|
||||
case CrafterKeys::F7: return fnv("F7");
|
||||
case CrafterKeys::F8: return fnv("F8");
|
||||
case CrafterKeys::F9: return fnv("F9");
|
||||
case CrafterKeys::F10: return fnv("F10");
|
||||
case CrafterKeys::F11: return fnv("F11");
|
||||
case CrafterKeys::F12: return fnv("F12");
|
||||
// Control keys.
|
||||
case CrafterKeys::Escape: return fnv("Escape");
|
||||
case CrafterKeys::Tab: return fnv("Tab");
|
||||
case CrafterKeys::Enter: return fnv("Enter");
|
||||
case CrafterKeys::Space: return fnv("Space");
|
||||
case CrafterKeys::Backspace: return fnv("Backspace");
|
||||
case CrafterKeys::Delete: return fnv("Delete");
|
||||
case CrafterKeys::Insert: return fnv("Insert");
|
||||
case CrafterKeys::Home: return fnv("Home");
|
||||
case CrafterKeys::End: return fnv("End");
|
||||
case CrafterKeys::PageUp: return fnv("PageUp");
|
||||
case CrafterKeys::PageDown: return fnv("PageDown");
|
||||
case CrafterKeys::CapsLock: return fnv("CapsLock");
|
||||
case CrafterKeys::NumLock: return fnv("NumLock");
|
||||
case CrafterKeys::ScrollLock: return fnv("ScrollLock");
|
||||
// Modifiers.
|
||||
case CrafterKeys::LeftShift: return fnv("ShiftLeft");
|
||||
case CrafterKeys::RightShift: return fnv("ShiftRight");
|
||||
case CrafterKeys::LeftCtrl: return fnv("ControlLeft");
|
||||
case CrafterKeys::RightCtrl: return fnv("ControlRight");
|
||||
case CrafterKeys::LeftAlt: return fnv("AltLeft");
|
||||
case CrafterKeys::RightAlt: return fnv("AltRight");
|
||||
case CrafterKeys::LeftSuper: return fnv("MetaLeft");
|
||||
case CrafterKeys::RightSuper: return fnv("MetaRight");
|
||||
// Arrows.
|
||||
case CrafterKeys::Up: return fnv("ArrowUp");
|
||||
case CrafterKeys::Down: return fnv("ArrowDown");
|
||||
case CrafterKeys::Left: return fnv("ArrowLeft");
|
||||
case CrafterKeys::Right: return fnv("ArrowRight");
|
||||
// Keypad.
|
||||
case CrafterKeys::keypad_0: return fnv("Numpad0");
|
||||
case CrafterKeys::keypad_1: return fnv("Numpad1");
|
||||
case CrafterKeys::keypad_2: return fnv("Numpad2");
|
||||
case CrafterKeys::keypad_3: return fnv("Numpad3");
|
||||
case CrafterKeys::keypad_4: return fnv("Numpad4");
|
||||
case CrafterKeys::keypad_5: return fnv("Numpad5");
|
||||
case CrafterKeys::keypad_6: return fnv("Numpad6");
|
||||
case CrafterKeys::keypad_7: return fnv("Numpad7");
|
||||
case CrafterKeys::keypad_8: return fnv("Numpad8");
|
||||
case CrafterKeys::keypad_9: return fnv("Numpad9");
|
||||
case CrafterKeys::keypad_enter: return fnv("NumpadEnter");
|
||||
case CrafterKeys::keypad_plus: return fnv("NumpadAdd");
|
||||
case CrafterKeys::keypad_minus: return fnv("NumpadSubtract");
|
||||
case CrafterKeys::keypad_multiply: return fnv("NumpadMultiply");
|
||||
case CrafterKeys::keypad_divide: return fnv("NumpadDivide");
|
||||
case CrafterKeys::keypad_decimal: return fnv("NumpadDecimal");
|
||||
// Punctuation.
|
||||
case CrafterKeys::grave: return fnv("Backquote");
|
||||
case CrafterKeys::minus: return fnv("Minus");
|
||||
case CrafterKeys::equal: return fnv("Equal");
|
||||
case CrafterKeys::bracket_left: return fnv("BracketLeft");
|
||||
case CrafterKeys::bracket_right: return fnv("BracketRight");
|
||||
case CrafterKeys::backslash: return fnv("Backslash");
|
||||
case CrafterKeys::semicolon: return fnv("Semicolon");
|
||||
case CrafterKeys::quote: return fnv("Quote");
|
||||
case CrafterKeys::comma: return fnv("Comma");
|
||||
case CrafterKeys::period: return fnv("Period");
|
||||
case CrafterKeys::slash: return fnv("Slash");
|
||||
case CrafterKeys::print_screen: return fnv("PrintScreen");
|
||||
case CrafterKeys::pause: return fnv("Pause");
|
||||
case CrafterKeys::menu: return fnv("ContextMenu");
|
||||
// Multimedia / browser / launch.
|
||||
case CrafterKeys::volume_up: return fnv("AudioVolumeUp");
|
||||
case CrafterKeys::volume_down: return fnv("AudioVolumeDown");
|
||||
case CrafterKeys::volume_mute: return fnv("AudioVolumeMute");
|
||||
case CrafterKeys::media_play: return fnv("MediaPlayPause");
|
||||
case CrafterKeys::media_stop: return fnv("MediaStop");
|
||||
case CrafterKeys::media_prev: return fnv("MediaTrackPrevious");
|
||||
case CrafterKeys::media_next: return fnv("MediaTrackNext");
|
||||
case CrafterKeys::browser_back: return fnv("BrowserBack");
|
||||
case CrafterKeys::browser_forward: return fnv("BrowserForward");
|
||||
case CrafterKeys::browser_refresh: return fnv("BrowserRefresh");
|
||||
case CrafterKeys::browser_stop: return fnv("BrowserStop");
|
||||
case CrafterKeys::browser_search: return fnv("BrowserSearch");
|
||||
case CrafterKeys::browser_home: return fnv("BrowserHome");
|
||||
case CrafterKeys::launch_mail: return fnv("LaunchMail");
|
||||
case CrafterKeys::launch_calculator: return fnv("LaunchApp2");
|
||||
case CrafterKeys::launch_media_player: return fnv("LaunchApp1");
|
||||
case CrafterKeys::CrafterKeysMax: return 0;
|
||||
}
|
||||
#endif
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
// Linux kernel input-event-codes. The Wayland keyboard handler strips
|
||||
// the +8 X11 offset before delivery so these match wl_keyboard.key
|
||||
|
|
|
|||
|
|
@ -19,9 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
module;
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:Mesh;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import Crafter.Math;
|
||||
import Crafter.Asset;
|
||||
|
|
@ -55,4 +58,5 @@ export namespace Crafter {
|
|||
// into their own buffer if needed (or uses Compression::DecompressCPU).
|
||||
void Build(const ::Crafter::CompressedMeshAsset& asset, VkCommandBuffer cmd);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:PipelineRTVulkan;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :Device;
|
||||
import :VulkanBuffer;
|
||||
|
|
@ -112,4 +115,5 @@ export namespace Crafter {
|
|||
vkDestroyPipeline(Device::device, pipeline, nullptr);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:RTPass;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :RenderPass;
|
||||
import :Window;
|
||||
|
|
@ -42,3 +45,4 @@ export namespace Crafter {
|
|||
}
|
||||
};
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:RenderPass;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
|
||||
export namespace Crafter {
|
||||
|
|
@ -29,3 +32,4 @@ export namespace Crafter {
|
|||
virtual ~RenderPass() = default;
|
||||
};
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:RenderingElement3D;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :Mesh;
|
||||
import :VulkanBuffer;
|
||||
|
|
@ -82,4 +85,5 @@ export namespace Crafter {
|
|||
static void Add(RenderingElement3D* e);
|
||||
static void Remove(RenderingElement3D* e);
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
50
interfaces/Crafter.Graphics-Router.cppm
Normal file
50
interfaces/Crafter.Graphics-Router.cppm
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
Crafter®.Graphics
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License version 3.0 as published by the Free Software Foundation;
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
// History / SPA routing. Thin C++ wrapper over the browser's
|
||||
// `history.pushState` / `popstate` and `window.location.pathname` —
|
||||
// exists so a single-page app written against this library can manage
|
||||
// its own URL without going through the DOM partition. Re-homed under
|
||||
// the `Crafter::Router` namespace (cleaner than CppDOM's bare free
|
||||
// functions; symmetric with `Crafter::Gamepad`).
|
||||
|
||||
export module Crafter.Graphics:Router;
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
|
||||
export namespace Crafter::Router {
|
||||
|
||||
// Push a new history entry. `data` is a JSON string serialized by
|
||||
// the caller — the browser stores it on the entry but the popstate
|
||||
// listener in V1 receives no payload (matches CppDOM's surface).
|
||||
// `url` is browser-relative, e.g. "/blog/post-1".
|
||||
void PushState(std::string_view data, std::string_view title, std::string_view url);
|
||||
|
||||
// Subscribe to the browser's `popstate` event (back/forward button,
|
||||
// programmatic history.go). Returns an opaque id usable with
|
||||
// `RemovePopStateListener`. Multiple subscribers OK.
|
||||
std::int32_t AddPopStateListener(std::function<void()> callback);
|
||||
void RemovePopStateListener(std::int32_t id);
|
||||
|
||||
// Current `window.location.pathname` as a freshly-allocated string.
|
||||
// Allocates per call — cache the result in the caller if used in
|
||||
// hot paths.
|
||||
std::string GetPath();
|
||||
}
|
||||
#endif // CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
@ -19,9 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
module;
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:SamplerVulkan;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :VulkanBuffer;
|
||||
import :ImageVulkan;
|
||||
|
|
@ -57,4 +60,5 @@ export namespace Crafter {
|
|||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:ShaderBindingTableVulkan;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :Device;
|
||||
import :VulkanBuffer;
|
||||
|
|
@ -37,4 +40,5 @@ export namespace Crafter {
|
|||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -18,8 +18,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:ShaderVulkan;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :Device;
|
||||
import :Types;
|
||||
|
|
@ -59,4 +62,5 @@ export namespace Crafter {
|
|||
Device::CheckVkResult(vkCreateShaderModule(Device::device, &module_info, nullptr, &shader));
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -18,7 +18,11 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
module;
|
||||
// DOM builds drop the Vulkan header — DescriptorBinding (the only
|
||||
// Vk-typed entity here) compiles out under the same guard below.
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif
|
||||
export module Crafter.Graphics:Types;
|
||||
import std;
|
||||
import Crafter.Math;
|
||||
|
|
@ -245,8 +249,10 @@ export namespace Crafter {
|
|||
return std::tan(fov * std::numbers::pi / 360.0);
|
||||
}
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
struct DescriptorBinding {
|
||||
VkDescriptorType type;
|
||||
std::uint32_t slot;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:UI;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import Crafter.Event;
|
||||
import :Device;
|
||||
|
|
@ -336,3 +339,4 @@ export namespace Crafter {
|
|||
return ImageSlot{heap_, range.firstElement};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -17,8 +17,11 @@ License along with this library; if not, write to the Free Software
|
|||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:UIComponents;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :UI;
|
||||
import :Font;
|
||||
|
|
@ -140,3 +143,4 @@ export namespace Crafter {
|
|||
std::array<float, 4> tint = {1, 1, 1, 1},
|
||||
std::array<float, 4> uv = {0, 0, 1, 1});
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -19,9 +19,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
module;
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:VulkanBuffer;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
import :Device;
|
||||
|
||||
|
|
@ -218,4 +221,5 @@ namespace Crafter {
|
|||
VulkanBuffer(VulkanBuffer&) = delete;
|
||||
VulkanBuffer& operator=(const VulkanBuffer&) = delete;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -18,9 +18,12 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
|
||||
module;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#include <assert.h>
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
export module Crafter.Graphics:VulkanTransition;
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
import std;
|
||||
|
||||
export namespace Crafter {
|
||||
|
|
@ -186,4 +189,5 @@ export namespace Crafter {
|
|||
static_cast<uint32_t>(image_memory_barriers.size()),
|
||||
image_memory_barriers.data());
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // !CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@ module;
|
|||
#include <wayland-client.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
#endif
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
|
@ -50,6 +52,7 @@ import :Keys;
|
|||
import Crafter.Event;
|
||||
|
||||
export namespace Crafter {
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
struct Semaphores {
|
||||
// Swap chain image presentation
|
||||
VkSemaphore presentComplete;
|
||||
|
|
@ -58,6 +61,7 @@ export namespace Crafter {
|
|||
};
|
||||
struct RenderPass;
|
||||
struct DescriptorHeapVulkan;
|
||||
#endif
|
||||
|
||||
struct Window {
|
||||
FrameTime currentFrameTime;
|
||||
|
|
@ -105,6 +109,16 @@ export namespace Crafter {
|
|||
Window(Window&) = delete;
|
||||
Window(Window&&) = delete;
|
||||
Window& operator=(const Window&) = delete;
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
// DOM mode keeps a process-global pointer to the live Window so
|
||||
// the JS bridge can deliver document/window events back. If the
|
||||
// Window is destroyed (e.g. it was stack-allocated in main and
|
||||
// main returned), the global must be cleared so subsequent
|
||||
// browser callbacks become no-ops instead of dereferencing
|
||||
// freed memory. Native builds have nothing to clean up at the
|
||||
// Window level (Vulkan resources teardown is the user's job).
|
||||
~Window();
|
||||
#endif
|
||||
|
||||
void StartSync();
|
||||
void StartUpdate();
|
||||
|
|
@ -193,6 +207,7 @@ export namespace Crafter {
|
|||
inline static wp_fractional_scale_v1* wp_scale = nullptr;
|
||||
#endif
|
||||
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOW_DOM
|
||||
VkCommandBuffer StartInit();
|
||||
void FinishInit();
|
||||
VkCommandBuffer GetCmd();
|
||||
|
|
@ -226,5 +241,13 @@ export namespace Crafter {
|
|||
std::vector<RenderPass*> passes;
|
||||
DescriptorHeapVulkan* descriptorHeap = nullptr;
|
||||
std::optional<std::array<float, 4>> clearColor;
|
||||
#else
|
||||
// DOM mode: the page IS the window. `numFrames` stays as a public
|
||||
// constant so cross-platform code can refer to Window::numFrames
|
||||
// without #ifdef'ing the reference; nothing else lives here yet.
|
||||
// V2 (WebGPU compute) will hang its GPUContext / swapchain texture
|
||||
// members off this branch.
|
||||
static constexpr std::uint8_t numFrames = 1;
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
|
@ -20,16 +20,25 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
|
||||
export module Crafter.Graphics;
|
||||
|
||||
// Every partition is `export import`'d unconditionally. Crafter.Build's
|
||||
// dependency scanner doesn't respect `#ifdef` on `import :X`, so the
|
||||
// partition file must always exist. Vulkan-typed partitions stub to
|
||||
// empty modules under CRAFTER_GRAPHICS_WINDOW_DOM, and the new Dom /
|
||||
// DomEvents / Router partitions stub to empty modules in native
|
||||
// builds — see project.cpp for the master list.
|
||||
export import :Types;
|
||||
export import :Keys;
|
||||
export import :Gamepad;
|
||||
export import :Window;
|
||||
export import :Input;
|
||||
export import :Device;
|
||||
export import :Font;
|
||||
export import :Animation;
|
||||
export import :Mesh;
|
||||
export import :ForwardDeclarations;
|
||||
export import :Clipboard;
|
||||
|
||||
// Vulkan-backed partitions — empty under DOM.
|
||||
export import :Font;
|
||||
export import :Mesh;
|
||||
export import :VulkanTransition;
|
||||
export import :VulkanBuffer;
|
||||
export import :ShaderVulkan;
|
||||
|
|
@ -46,5 +55,9 @@ export import :ComputeShader;
|
|||
export import :UI;
|
||||
export import :UIComponents;
|
||||
export import :InputField;
|
||||
export import :Clipboard;
|
||||
export import :Decompress;
|
||||
export import :Decompress;
|
||||
|
||||
// DOM-only partitions — empty under native.
|
||||
export import :Dom;
|
||||
export import :DomEvents;
|
||||
export import :Router;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue