vulkan window
This commit is contained in:
parent
4b34eb3972
commit
cfb43257a0
9 changed files with 1674 additions and 34 deletions
|
|
@ -39,6 +39,29 @@ module;
|
|||
#include <wayland-client.h>
|
||||
#include <wayland-client-protocol.h>
|
||||
#endif
|
||||
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||||
#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>
|
||||
#include <vulkan/vulkan.h>
|
||||
#include <vulkan/vulkan_wayland.h>
|
||||
#endif
|
||||
|
||||
export module Crafter.Graphics:Window;
|
||||
import std;
|
||||
|
|
@ -243,4 +266,122 @@ export namespace Crafter {
|
|||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifdef CRAFTER_GRAPHICS_VULKAN
|
||||
struct Semaphores {
|
||||
// Swap chain image presentation
|
||||
VkSemaphore presentComplete;
|
||||
// Command buffer submission and execution
|
||||
VkSemaphore renderComplete;
|
||||
};
|
||||
|
||||
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;
|
||||
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();
|
||||
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,
|
||||
};
|
||||
private:
|
||||
void CreateSwapchain();
|
||||
VkSurfaceKHR vulkanSurface = VK_NULL_HANDLE;
|
||||
VkSwapchainKHR swapChain = VK_NULL_HANDLE;
|
||||
VkFormat colorFormat;
|
||||
VkColorSpaceKHR colorSpace;
|
||||
std::vector<VkImage> images;
|
||||
std::vector<VkImageView> imageViews;
|
||||
std::thread thread;
|
||||
std::vector<VkCommandBuffer> drawCmdBuffers;
|
||||
std::vector<VkFramebuffer> frameBuffers;
|
||||
VkSubmitInfo submitInfo;
|
||||
Semaphores semaphores;
|
||||
uint32_t currentBuffer = 0;
|
||||
VkPipelineStageFlags submitPipelineStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
VkRenderPass renderPass = VK_NULL_HANDLE;
|
||||
};
|
||||
#endif
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue