new UI system

This commit is contained in:
Jorijn van der Graaf 2026-05-01 23:35:37 +02:00
commit 216972e73a
82 changed files with 4837 additions and 3243 deletions

View file

@ -38,9 +38,7 @@ module;
#include <wayland-client.h>
#include <wayland-client-protocol.h>
#endif
#ifdef CRAFTER_GRAPHICS_RENDERER_VULKAN
#include "vulkan/vulkan.h"
#endif
#ifdef CRAFTER_GRAPHICS_WINDOW_WIN32
#include <windows.h>
#endif
@ -48,23 +46,18 @@ module;
export module Crafter.Graphics:Window;
import std;
import :Types;
import :Rendertarget;
import :Transform2D;
import Crafter.Event;
export namespace Crafter {
#ifdef CRAFTER_GRAPHICS_RENDERER_VULKAN
struct Semaphores {
// Swap chain image presentation
VkSemaphore presentComplete;
// Command buffer submission and execution
VkSemaphore renderComplete;
};
struct PipelineRTVulkan;
struct RenderPass;
struct DescriptorHeapVulkan;
#endif
struct MouseElement;
struct Window {
FrameTime currentFrameTime;
std::uint32_t width;
@ -98,9 +91,6 @@ export namespace Crafter {
Vector<float, 2> mouseDelta;
bool mouseLeftHeld = false;
bool mouseRightHeld = false;
std::vector<MouseElement*> mouseElements;
std::vector<MouseElement*> pendingMouseElements;
Rendertarget<std::uint8_t, 4, 4, 1> cursorRenderer;
Window() = default;
Window(std::uint32_t width, std::uint32_t height);
@ -139,16 +129,11 @@ export namespace Crafter {
#endif
#ifdef CRAFTER_GRAPHICS_WINDOW_WAYLAND
float scale;
#ifdef CRAFTER_GRAPHICS_RENDERER_SOFTWARE
Rendertarget<std::uint8_t, 4, 4, 1> renderer;
#endif
float scale = 1.0f;
bool configured = false;
xdg_toplevel* xdgToplevel = nullptr;
wp_viewport* wpViewport = nullptr;
wl_surface* surface = nullptr;
wl_buffer* buffer = nullptr;
wl_buffer* backBuffer = nullptr;
xdg_surface* xdgSurface = nullptr;
wl_callback* cb = nullptr;
wl_surface* cursorSurface = nullptr;
@ -177,12 +162,17 @@ export namespace Crafter {
inline static wp_fractional_scale_v1* wp_scale = nullptr;
#endif
#ifdef CRAFTER_GRAPHICS_RENDERER_VULKAN
VkCommandBuffer StartInit();
void FinishInit();
VkCommandBuffer GetCmd();
void EndCmd(VkCommandBuffer cmd);
void CreateSwapchain();
// Save the current swapchain image (state after Render() returns) to
// a PNG file. Allocates a one-shot staging buffer + command buffer,
// copies image-to-buffer, waits idle, then writes PNG via stb. Useful
// for visual regression tests and screenshotting from headless code.
void SaveFrame(const std::filesystem::path& path);
static constexpr std::uint8_t numFrames = 3;
VkSurfaceKHR vulkanSurface = VK_NULL_HANDLE;
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
@ -196,8 +186,8 @@ export namespace Crafter {
Semaphores semaphores;
std::uint32_t currentBuffer = 0;
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
PipelineRTVulkan* pipeline;
DescriptorHeapVulkan* descriptorHeap;
#endif
std::vector<RenderPass*> passes;
DescriptorHeapVulkan* descriptorHeap = nullptr;
std::optional<std::array<float, 4>> clearColor;
};
}