cleaned up renderer
This commit is contained in:
parent
afe23851f0
commit
d661c88ee2
58 changed files with 3030 additions and 4722 deletions
|
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
Crafter®.Graphics
|
||||
Copyright (C) 2025 Catcrafts®
|
||||
Copyright (C) 2026 Catcrafts®
|
||||
catcrafts.net
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
|
|
@ -18,7 +18,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|||
*/
|
||||
module;
|
||||
|
||||
#ifdef CRAFTER_GRAPHICS_WAYLAND
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
|
|
@ -32,95 +32,46 @@ module;
|
|||
#include <linux/input.h>
|
||||
#include <sys/mman.h>
|
||||
#include <wayland-cursor.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <print>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
#endif
|
||||
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOWS
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <linux/input-event-codes.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include "../lib/xdg-shell-client-protocol.h"
|
||||
#include "../lib/wayland-xdg-decoration-unstable-v1-client-protocol.h"
|
||||
#include "../lib/fractional-scale-v1.h"
|
||||
#include "../lib/viewporter.h"
|
||||
#include <string.h>
|
||||
#include <linux/input.h>
|
||||
#include <sys/mman.h>
|
||||
#include <wayland-cursor.h>
|
||||
#include <xkbcommon/xkbcommon.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <print>
|
||||
#include <wayland-client.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
#ifdef CRAFTER_GRAPHICS_RENDERER_VULKAN
|
||||
#include "vulkan/vulkan.h"
|
||||
#include "vulkan/vulkan_wayland.h"
|
||||
#else
|
||||
#include "vulkan/vulkan.h"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
export module Crafter.Graphics:Window;
|
||||
import std;
|
||||
import :Types;
|
||||
import :Rendertarget;
|
||||
import :Transform2D;
|
||||
import Crafter.Event;
|
||||
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||||
#ifdef CRAFTER_GRAPHICS_RENDERER_VULKAN
|
||||
import :PipelineRTVulkan;
|
||||
#endif
|
||||
|
||||
export namespace Crafter {
|
||||
class Transform;
|
||||
class MouseElement;
|
||||
class Window {
|
||||
public:
|
||||
#ifdef CRAFTER_GRAPHICS_RENDERER_VULKAN
|
||||
struct Semaphores {
|
||||
// Swap chain image presentation
|
||||
VkSemaphore presentComplete;
|
||||
// Command buffer submission and execution
|
||||
VkSemaphore renderComplete;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct MouseElement;
|
||||
struct Window {
|
||||
FrameTime currentFrameTime;
|
||||
std::int32_t width;
|
||||
std::int32_t height;
|
||||
std::uint32_t width;
|
||||
std::uint32_t height;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> lastFrameBegin;
|
||||
std::vector<Transform*> elements;
|
||||
Event<void> onClose;
|
||||
Event<FrameTime> onUpdate;
|
||||
bool open = true;
|
||||
bool updating = false;
|
||||
std::vector<ClipRect> dirtyRects;
|
||||
float scale;
|
||||
|
||||
Window() = default;
|
||||
Window(std::int32_t width, std::int32_t height);
|
||||
Window(Window&) = delete;
|
||||
Window(Window&&) = delete;
|
||||
virtual ~Window() = default;
|
||||
Window& operator=(const Window&) = delete;
|
||||
void AddDirtyRect(ScaleData rect);
|
||||
virtual void StartSync() = 0;
|
||||
virtual void StartUpdate() = 0;
|
||||
virtual void StopUpdate() = 0;
|
||||
void ScaleElement(Transform& element, Transform& parent);
|
||||
void ScaleElement(Transform& element);
|
||||
void ScaleMouse(MouseElement& element, Transform& parent);
|
||||
void ScaleMouse(MouseElement& element);
|
||||
#ifdef CRAFTER_TIMING
|
||||
std::chrono::nanoseconds totalUpdate;
|
||||
std::vector<std::pair<const EventListener<FrameTime>*, std::chrono::nanoseconds>> updateTimings;
|
||||
std::chrono::nanoseconds totalRender;
|
||||
std::vector<std::tuple<const Transform*, std::uint32_t, std::uint32_t, std::chrono::nanoseconds>> renderTimings;
|
||||
std::chrono::nanoseconds vblank;
|
||||
std::chrono::nanoseconds totalFrame;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> frameEnd;
|
||||
std::vector<std::chrono::nanoseconds> frameTimes;
|
||||
void LogTiming();
|
||||
#endif
|
||||
};
|
||||
|
||||
class WindowKeyboard {
|
||||
public:
|
||||
bool heldkeys[static_cast<std::uint32_t>(CrafterKeys::CrafterKeysMax)] = {};
|
||||
Event<void> onKeyDown[static_cast<std::uint32_t>(CrafterKeys::CrafterKeysMax)];
|
||||
Event<void> onKeyHold[static_cast<std::uint32_t>(CrafterKeys::CrafterKeysMax)];
|
||||
|
|
@ -128,134 +79,69 @@ export namespace Crafter {
|
|||
Event<CrafterKeys> onAnyKeyDown;
|
||||
Event<CrafterKeys> onAnyKeyHold;
|
||||
Event<CrafterKeys> onAnyKeyUp;
|
||||
};
|
||||
|
||||
class MouseElement;
|
||||
class WindowMouse {
|
||||
public:
|
||||
Event<MousePoint> onMouseRightClick;
|
||||
Event<MousePoint> onMouseLeftClick;
|
||||
Event<MousePoint> onMouseRightHold;
|
||||
Event<MousePoint> onMouseLeftHold;
|
||||
Event<MousePoint> onMouseRightRelease;
|
||||
Event<MousePoint> onMouseLeftRelease;
|
||||
Event<MouseMoveEvent> onMouseMove;
|
||||
Event<MouseMoveEvent> onMouseEnter;
|
||||
Event<MouseMoveEvent> onMouseLeave;
|
||||
Event<void> onMouseRightClick;
|
||||
Event<void> onMouseLeftClick;
|
||||
Event<void> onMouseRightHold;
|
||||
Event<void> onMouseLeftHold;
|
||||
Event<void> onMouseRightRelease;
|
||||
Event<void> onMouseLeftRelease;
|
||||
Event<void> onMouseMove;
|
||||
Event<void> onMouseEnter;
|
||||
Event<void> onMouseLeave;
|
||||
Event<std::uint32_t> onMouseScroll;
|
||||
MousePoint currentMousePos;
|
||||
MousePoint lastMousePos;
|
||||
MouseDelta mouseDelta;
|
||||
Vector<float, 2> currentMousePos;
|
||||
Vector<float, 2> lastMousePos;
|
||||
Vector<float, 2> mouseDelta;
|
||||
bool mouseLeftHeld = false;
|
||||
bool mouseRightHeld = false;
|
||||
std::vector<MouseElement*> mouseElements;
|
||||
std::vector<MouseElement*> pendingMouseElements;
|
||||
};
|
||||
|
||||
class WindowTitle {
|
||||
public:
|
||||
virtual void SetTitle(const std::string_view title) = 0;
|
||||
};
|
||||
Window(std::uint32_t width, std::uint32_t height);
|
||||
Window(std::uint32_t width, std::uint32_t height, const std::string_view title);
|
||||
Window(Window&) = delete;
|
||||
Window(Window&&) = delete;
|
||||
Window& operator=(const Window&) = delete;
|
||||
|
||||
class Transform;
|
||||
class WindowFramebuffer : public Window {
|
||||
public:
|
||||
WindowFramebuffer() = default;
|
||||
WindowFramebuffer(std::uint32_t width, std::uint32_t height);
|
||||
virtual void Resize(std::uint32_t width, std::uint32_t height) = 0;
|
||||
virtual void Write(Pixel_BU8_GU8_RU8_AU8* pixels) = 0;
|
||||
virtual void Write(std::uint32_t x, std::uint32_t y, Pixel_BU8_GU8_RU8_AU8 pixel) = 0;
|
||||
virtual Pixel_BU8_GU8_RU8_AU8 Read(std::uint32_t x, std::uint32_t y) const = 0;
|
||||
virtual const Pixel_BU8_GU8_RU8_AU8* Read() const = 0;
|
||||
virtual Pixel_BU8_GU8_RU8_AU8* Get() = 0;
|
||||
virtual void Store() = 0;
|
||||
virtual void Render() = 0;
|
||||
};
|
||||
void StartSync();
|
||||
void StartUpdate();
|
||||
void StopUpdate();
|
||||
void SetTitle(const std::string_view title);
|
||||
void Resize(std::uint32_t width, std::uint32_t height);
|
||||
void Render();
|
||||
void Update();
|
||||
|
||||
#ifdef CRAFTER_GRAPHICS_WAYLAND
|
||||
class WindowWayland final : public WindowKeyboard, public WindowMouse, public WindowFramebuffer, public WindowTitle {
|
||||
public:
|
||||
Pixel_BU8_GU8_RU8_AU8* framebuffer = nullptr;
|
||||
WindowWayland(std::uint32_t width, std::uint32_t height);
|
||||
WindowWayland(std::uint32_t width, std::uint32_t height, const std::string_view title);
|
||||
~WindowWayland();
|
||||
#ifdef CRAFTER_TIMING
|
||||
std::chrono::nanoseconds totalUpdate;
|
||||
std::vector<std::pair<const EventListener<FrameTime>*, std::chrono::nanoseconds>> updateTimings;
|
||||
std::chrono::nanoseconds totalRender;
|
||||
std::chrono::nanoseconds vblank;
|
||||
std::chrono::nanoseconds totalFrame;
|
||||
std::chrono::time_point<std::chrono::high_resolution_clock> frameEnd;
|
||||
std::vector<std::chrono::nanoseconds> frameTimes;
|
||||
void LogTiming();
|
||||
#endif
|
||||
|
||||
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
|
||||
float scale;
|
||||
#ifdef CRAFTER_GRAPHICS_RENDERER_SOFTWARE
|
||||
Rendertarget renderer;
|
||||
#endif
|
||||
bool configured = false;
|
||||
wl_shm* shm = nullptr;
|
||||
wl_seat* seat = nullptr;
|
||||
wp_fractional_scale_v1* wp_scale = nullptr;
|
||||
xdg_toplevel* xdgToplevel = nullptr;
|
||||
wp_viewport* wpViewport = nullptr;
|
||||
wp_viewporter* wpViewporter = nullptr;
|
||||
xdg_wm_base* xdgWmBase = nullptr;
|
||||
zxdg_decoration_manager_v1* manager = nullptr;
|
||||
wp_fractional_scale_manager_v1* fractionalScaleManager = nullptr;
|
||||
wl_surface* surface = nullptr;
|
||||
wl_buffer* buffer = nullptr;
|
||||
wl_buffer* backBuffer = nullptr;
|
||||
xdg_surface* xdgSurface = nullptr;
|
||||
wl_display* display = nullptr;
|
||||
wl_callback* cb = nullptr;
|
||||
xkb_keymap* xkb_keymap;
|
||||
xkb_context* xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
xkb_state* xkb_state;
|
||||
void RenderElement(Transform* transform);
|
||||
void Render() override;
|
||||
void QueueRender();
|
||||
void StartSync() override;
|
||||
void StartUpdate() override;
|
||||
void StopUpdate() override;
|
||||
void SetTitle(const std::string_view title) override;
|
||||
void Resize(std::uint32_t width, std::uint32_t height) override;
|
||||
void Write(Pixel_BU8_GU8_RU8_AU8* pixels) override;
|
||||
void Write(std::uint32_t x, std::uint32_t y, Pixel_BU8_GU8_RU8_AU8 pixel) override;
|
||||
Pixel_BU8_GU8_RU8_AU8 Read(std::uint32_t x, std::uint32_t y) const override;
|
||||
const Pixel_BU8_GU8_RU8_AU8* Read() const override;
|
||||
Pixel_BU8_GU8_RU8_AU8* Get() override;
|
||||
void Store() override;
|
||||
inline static wl_compositor* compositor = nullptr;
|
||||
static void wl_surface_frame_done(void *data, wl_callback *cb, uint32_t time);
|
||||
static void PointerListenerHandleMotion(void* data, wl_pointer* wl_pointer, uint time, wl_fixed_t surface_x, wl_fixed_t surface_y);
|
||||
static void PointerListenerHandleAxis(void*, wl_pointer*, std::uint32_t, std::uint32_t, wl_fixed_t value);
|
||||
static void PointerListenerHandleEnter(void* data, wl_pointer* wl_pointer, uint serial, wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y);
|
||||
static void PointerListenerHandleLeave(void*, wl_pointer*, std::uint32_t, wl_surface*);
|
||||
static void xdg_toplevel_handle_close(void* data, xdg_toplevel*);
|
||||
static void handle_global(void* data, wl_registry* registry, std::uint32_t name, const char* interface, std::uint32_t version);
|
||||
static void pointer_handle_button(void* data, wl_pointer* pointer, std::uint32_t serial, std::uint32_t time, std::uint32_t button, std::uint32_t state);
|
||||
static void seat_handle_capabilities(void* data, wl_seat* seat, uint32_t capabilities);
|
||||
static void xdg_surface_handle_configure(void* data, xdg_surface* xdg_surface, std::uint32_t serial);
|
||||
|
||||
static void xdg_surface_handle_preferred_scale(void* data, wp_fractional_scale_v1*, std::uint32_t scale);
|
||||
static void xdg_wm_base_handle_ping(void* data, xdg_wm_base* xdg_wm_base, std::uint32_t serial);
|
||||
static void keyboard_keymap(void* data, wl_keyboard* keyboard, uint32_t format, int fd, uint32_t size);
|
||||
static void keyboard_enter(void *data, wl_keyboard *keyboard, uint32_t serial, wl_surface *surface, wl_array *keys);
|
||||
static void keyboard_leave(void *data, wl_keyboard *keyboard, uint32_t serial, wl_surface *surface);
|
||||
static void keyboard_key(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
|
||||
static void keyboard_modifiers(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group);
|
||||
static void keyboard_repeat_info(void *data, wl_keyboard *keyboard, int32_t rate, int32_t delay);
|
||||
static void handle_global_remove(void* data, wl_registry* registry, uint32_t name);
|
||||
static void wl_surface_frame_done(void *data, wl_callback *cb, uint32_t time);
|
||||
static void xdg_toplevel_handle_close(void* data, xdg_toplevel*);
|
||||
static void xdg_surface_handle_configure(void* data, xdg_surface* xdg_surface, std::uint32_t serial);
|
||||
static void xdg_toplevel_configure(void*, xdg_toplevel*, std::int32_t, std::int32_t, wl_array*);
|
||||
|
||||
constexpr static wl_pointer_listener pointer_listener = {
|
||||
.enter = PointerListenerHandleEnter,
|
||||
.leave = PointerListenerHandleLeave,
|
||||
.motion = PointerListenerHandleMotion,
|
||||
.button = pointer_handle_button,
|
||||
.axis = PointerListenerHandleAxis,
|
||||
};
|
||||
constexpr static wl_keyboard_listener keyboard_listener = {
|
||||
.keymap = keyboard_keymap,
|
||||
.enter = keyboard_enter,
|
||||
.leave = keyboard_leave,
|
||||
.key = keyboard_key,
|
||||
.modifiers = keyboard_modifiers,
|
||||
.repeat_info = keyboard_repeat_info,
|
||||
};
|
||||
constexpr static wl_seat_listener seat_listener = {
|
||||
.capabilities = seat_handle_capabilities,
|
||||
};
|
||||
constexpr static wl_registry_listener registry_listener = {
|
||||
.global = handle_global,
|
||||
.global_remove = handle_global_remove,
|
||||
};
|
||||
|
||||
constexpr static xdg_toplevel_listener xdg_toplevel_listener = {
|
||||
.configure = xdg_toplevel_configure,
|
||||
.close = xdg_toplevel_handle_close,
|
||||
|
|
@ -263,60 +149,17 @@ export namespace Crafter {
|
|||
constexpr static wl_callback_listener wl_callback_listener = {
|
||||
.done = wl_surface_frame_done,
|
||||
};
|
||||
constexpr static xdg_wm_base_listener xdgWmBaseListener = {
|
||||
.ping = xdg_wm_base_handle_ping,
|
||||
};
|
||||
constexpr static xdg_surface_listener xdg_surface_listener = {
|
||||
.configure = xdg_surface_handle_configure,
|
||||
};
|
||||
constexpr static wp_fractional_scale_v1_listener wp_fractional_scale_v1_listener = {
|
||||
.preferred_scale = xdg_surface_handle_preferred_scale,
|
||||
};
|
||||
};
|
||||
#endif
|
||||
inline static wp_fractional_scale_v1* wp_scale = nullptr;
|
||||
#endif
|
||||
|
||||
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||||
struct Semaphores {
|
||||
// Swap chain image presentation
|
||||
VkSemaphore presentComplete;
|
||||
// Command buffer submission and execution
|
||||
VkSemaphore renderComplete;
|
||||
};
|
||||
#ifndef CRAFTER_GRAPHICS_WINDOWS
|
||||
class WindowVulkan final : public Window, public WindowKeyboard, public WindowMouse, public WindowTitle {
|
||||
public:
|
||||
WindowVulkan(std::uint32_t width, std::uint32_t height);
|
||||
WindowVulkan(std::uint32_t width, std::uint32_t height, const std::string_view title);
|
||||
~WindowVulkan();
|
||||
bool configured = false;
|
||||
wl_shm* shm = nullptr;
|
||||
wl_seat* seat = nullptr;
|
||||
wp_fractional_scale_v1* wp_scale = nullptr;
|
||||
xdg_toplevel* xdgToplevel = nullptr;
|
||||
wp_viewport* wpViewport = nullptr;
|
||||
wp_viewporter* wpViewporter = nullptr;
|
||||
xdg_wm_base* xdgWmBase = nullptr;
|
||||
zxdg_decoration_manager_v1* manager = nullptr;
|
||||
wp_fractional_scale_manager_v1* fractionalScaleManager = nullptr;
|
||||
wl_surface* surface = nullptr;
|
||||
xdg_surface* xdgSurface = nullptr;
|
||||
wl_display* display = nullptr;
|
||||
wl_callback* cb = nullptr;
|
||||
xkb_keymap* xkb_keymap;
|
||||
xkb_context* xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
||||
xkb_state* xkb_state;
|
||||
Event<void> onRender;
|
||||
#ifdef CRAFTER_GRAPHICS_RENDERER_VULKAN
|
||||
std::vector<VkDescriptorSet> descriptorsRt;
|
||||
void Render();
|
||||
void QueueRender();
|
||||
void Resize(std::uint32_t width, std::uint32_t height);
|
||||
void StartSync() override;
|
||||
void StartUpdate() override;
|
||||
void StopUpdate() override;
|
||||
void SetTitle(const std::string_view title) override;
|
||||
VkCommandBuffer StartInit();
|
||||
void FinishInit();
|
||||
|
||||
template <typename Pipeline>
|
||||
void SetPipelineRT() {
|
||||
rtPipeline = Pipeline::pipeline;
|
||||
|
|
@ -326,77 +169,11 @@ export namespace Crafter {
|
|||
hitRegion = Pipeline::hitRegion;
|
||||
callableRegion = Pipeline::callableRegion;
|
||||
}
|
||||
|
||||
void SetPipelineRT(PipelineRTVulkan& pipeline) {
|
||||
rtPipeline = pipeline.pipeline;
|
||||
rtPipelineLayout = pipeline.pipelineLayout;
|
||||
raygenRegion = pipeline.raygenRegion;
|
||||
missRegion = pipeline.missRegion;
|
||||
hitRegion = pipeline.hitRegion;
|
||||
callableRegion = pipeline.callableRegion;
|
||||
}
|
||||
inline static wl_compositor* compositor = nullptr;
|
||||
static void wl_surface_frame_done(void *data, wl_callback *cb, uint32_t time);
|
||||
static void PointerListenerHandleMotion(void* data, wl_pointer* wl_pointer, uint time, wl_fixed_t surface_x, wl_fixed_t surface_y);
|
||||
static void PointerListenerHandleAxis(void*, wl_pointer*, std::uint32_t, std::uint32_t, wl_fixed_t value);
|
||||
static void PointerListenerHandleEnter(void* data, wl_pointer* wl_pointer, uint serial, wl_surface* surface, wl_fixed_t surface_x, wl_fixed_t surface_y);
|
||||
static void PointerListenerHandleLeave(void*, wl_pointer*, std::uint32_t, wl_surface*);
|
||||
static void xdg_toplevel_handle_close(void* data, xdg_toplevel*);
|
||||
static void handle_global(void* data, wl_registry* registry, std::uint32_t name, const char* interface, std::uint32_t version);
|
||||
static void pointer_handle_button(void* data, wl_pointer* pointer, std::uint32_t serial, std::uint32_t time, std::uint32_t button, std::uint32_t state);
|
||||
static void seat_handle_capabilities(void* data, wl_seat* seat, uint32_t capabilities);
|
||||
static void xdg_surface_handle_configure(void* data, xdg_surface* xdg_surface, std::uint32_t serial);
|
||||
static void xdg_surface_handle_preferred_scale(void* data, wp_fractional_scale_v1*, std::uint32_t scale);
|
||||
static void xdg_wm_base_handle_ping(void* data, xdg_wm_base* xdg_wm_base, std::uint32_t serial);
|
||||
static void keyboard_keymap(void* data, wl_keyboard* keyboard, uint32_t format, int fd, uint32_t size);
|
||||
static void keyboard_enter(void *data, wl_keyboard *keyboard, uint32_t serial, wl_surface *surface, wl_array *keys);
|
||||
static void keyboard_leave(void *data, wl_keyboard *keyboard, uint32_t serial, wl_surface *surface);
|
||||
static void keyboard_key(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t time, uint32_t key, uint32_t state);
|
||||
static void keyboard_modifiers(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t mods_depressed, uint32_t mods_latched, uint32_t mods_locked, uint32_t group);
|
||||
static void keyboard_repeat_info(void *data, wl_keyboard *keyboard, int32_t rate, int32_t delay);
|
||||
static void handle_global_remove(void* data, wl_registry* registry, uint32_t name);
|
||||
static void xdg_toplevel_configure(void*, xdg_toplevel*, std::int32_t, std::int32_t, wl_array*);
|
||||
|
||||
constexpr static wl_pointer_listener pointer_listener = {
|
||||
.enter = PointerListenerHandleEnter,
|
||||
.leave = PointerListenerHandleLeave,
|
||||
.motion = PointerListenerHandleMotion,
|
||||
.button = pointer_handle_button,
|
||||
.axis = PointerListenerHandleAxis,
|
||||
};
|
||||
constexpr static wl_keyboard_listener keyboard_listener = {
|
||||
.keymap = keyboard_keymap,
|
||||
.enter = keyboard_enter,
|
||||
.leave = keyboard_leave,
|
||||
.key = keyboard_key,
|
||||
.modifiers = keyboard_modifiers,
|
||||
.repeat_info = keyboard_repeat_info,
|
||||
};
|
||||
constexpr static wl_seat_listener seat_listener = {
|
||||
.capabilities = seat_handle_capabilities,
|
||||
};
|
||||
constexpr static wl_registry_listener registry_listener = {
|
||||
.global = handle_global,
|
||||
.global_remove = handle_global_remove,
|
||||
};
|
||||
constexpr static xdg_toplevel_listener xdg_toplevel_listener = {
|
||||
.configure = xdg_toplevel_configure,
|
||||
.close = xdg_toplevel_handle_close,
|
||||
};
|
||||
constexpr static wl_callback_listener wl_callback_listener = {
|
||||
.done = wl_surface_frame_done,
|
||||
};
|
||||
constexpr static xdg_wm_base_listener xdgWmBaseListener = {
|
||||
.ping = xdg_wm_base_handle_ping,
|
||||
};
|
||||
constexpr static xdg_surface_listener xdg_surface_listener = {
|
||||
.configure = xdg_surface_handle_configure,
|
||||
};
|
||||
constexpr static wp_fractional_scale_v1_listener wp_fractional_scale_v1_listener = {
|
||||
.preferred_scale = xdg_surface_handle_preferred_scale,
|
||||
};
|
||||
void SetPipelineRT(PipelineRTVulkan& pipeline);
|
||||
VkCommandBuffer StartInit();
|
||||
void FinishInit();
|
||||
void CreateSwapchain();
|
||||
static constexpr std::uint32_t numFrames = 3;
|
||||
static constexpr std::uint8_t numFrames = 3;
|
||||
VkSurfaceKHR vulkanSurface = VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
|
||||
VkFormat colorFormat;
|
||||
|
|
@ -407,7 +184,7 @@ export namespace Crafter {
|
|||
VkCommandBuffer drawCmdBuffers[numFrames];
|
||||
VkSubmitInfo submitInfo;
|
||||
Semaphores semaphores;
|
||||
uint32_t currentBuffer = 0;
|
||||
std::uint32_t currentBuffer = 0;
|
||||
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
VkPipeline rtPipeline;
|
||||
VkPipelineLayout rtPipelineLayout;
|
||||
|
|
@ -415,64 +192,6 @@ export namespace Crafter {
|
|||
VkStridedDeviceAddressRegionKHR missRegion;
|
||||
VkStridedDeviceAddressRegionKHR hitRegion;
|
||||
VkStridedDeviceAddressRegionKHR callableRegion;
|
||||
#endif
|
||||
};
|
||||
#else
|
||||
class WindowVulkan final : public Window, public WindowKeyboard, public WindowMouse, public WindowTitle {
|
||||
public:
|
||||
WindowVulkan(std::uint32_t width, std::uint32_t height);
|
||||
WindowVulkan(std::uint32_t width, std::uint32_t height, const std::string_view title);
|
||||
~WindowVulkan();
|
||||
Event<void> onRender;
|
||||
std::vector<VkDescriptorSet> descriptorsRt;
|
||||
void Render();
|
||||
void QueueRender();
|
||||
void Resize(std::uint32_t width, std::uint32_t height);
|
||||
void StartSync() override;
|
||||
void StartUpdate() override;
|
||||
void StopUpdate() override;
|
||||
void SetTitle(const std::string_view title) override;
|
||||
VkCommandBuffer StartInit();
|
||||
void FinishInit();
|
||||
|
||||
template <typename Pipeline>
|
||||
void SetPipelineRT() {
|
||||
rtPipeline = Pipeline::pipeline;
|
||||
rtPipelineLayout = Pipeline::pipelineLayout;
|
||||
raygenRegion = Pipeline::raygenRegion;
|
||||
missRegion = Pipeline::missRegion;
|
||||
hitRegion = Pipeline::hitRegion;
|
||||
callableRegion = Pipeline::callableRegion;
|
||||
}
|
||||
|
||||
void SetPipelineRT(PipelineRTVulkan& pipeline) {
|
||||
rtPipeline = pipeline.pipeline;
|
||||
rtPipelineLayout = pipeline.pipelineLayout;
|
||||
raygenRegion = pipeline.raygenRegion;
|
||||
missRegion = pipeline.missRegion;
|
||||
hitRegion = pipeline.hitRegion;
|
||||
callableRegion = pipeline.callableRegion;
|
||||
}
|
||||
void CreateSwapchain();
|
||||
static constexpr std::uint32_t numFrames = 3;
|
||||
VkSurfaceKHR vulkanSurface = VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
|
||||
VkFormat colorFormat;
|
||||
VkColorSpaceKHR colorSpace;
|
||||
VkImage images[numFrames];
|
||||
VkImageView imageViews[numFrames];
|
||||
std::thread thread;
|
||||
VkCommandBuffer drawCmdBuffers[numFrames];
|
||||
VkSubmitInfo submitInfo;
|
||||
Semaphores semaphores;
|
||||
uint32_t currentBuffer = 0;
|
||||
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
VkPipeline rtPipeline;
|
||||
VkPipelineLayout rtPipelineLayout;
|
||||
VkStridedDeviceAddressRegionKHR raygenRegion;
|
||||
VkStridedDeviceAddressRegionKHR missRegion;
|
||||
VkStridedDeviceAddressRegionKHR hitRegion;
|
||||
VkStridedDeviceAddressRegionKHR callableRegion;
|
||||
};
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue