From cb848e71090ca44fcf92721b9223d04d42cfb58d Mon Sep 17 00:00:00 2001 From: Jorijn van der Graaf Date: Mon, 5 May 2025 06:00:35 +0200 Subject: [PATCH] update --- Crafter.Graphics-Camera.cpp | 5 +++-- Crafter.Graphics-Camera.cppm | 2 ++ Crafter.Graphics-MeshShader.cppm | 9 +++++++-- Crafter.Graphics-TextureShader.cppm | 7 ------- Crafter.Graphics-VulkanTexture.cppm | 7 ------- Crafter.Graphics-WindowWayland.cpp | 4 +++- Crafter.Graphics-WindowWaylandVulkan.cpp | 1 + 7 files changed, 16 insertions(+), 19 deletions(-) diff --git a/Crafter.Graphics-Camera.cpp b/Crafter.Graphics-Camera.cpp index 504a91d..f3df871 100644 --- a/Crafter.Graphics-Camera.cpp +++ b/Crafter.Graphics-Camera.cpp @@ -8,14 +8,15 @@ module; module Crafter.Graphics; import Crafter.Math; +import Crafter.Event; using namespace Crafter; Camera::Camera(float fov, float aspectRatio, float near, float far) { projection = MatrixRowMajor::Perspective(fov, aspectRatio, near, far); - view = MatrixRowMajor::Rotation(0, 0, ToRadian(180.0f))*MatrixRowMajor::Translation(1.0f, 0.0f, -10.0f); - Update(); + view = MatrixRowMajor::Identity(); } void Camera::Update() { projectionView = projection*view; + onUpdate.Invoke(); } \ No newline at end of file diff --git a/Crafter.Graphics-Camera.cppm b/Crafter.Graphics-Camera.cppm index 104103e..ca1dbc9 100644 --- a/Crafter.Graphics-Camera.cppm +++ b/Crafter.Graphics-Camera.cppm @@ -6,6 +6,7 @@ export module Crafter.Graphics:Camera; import :VulkanBuffer; import Crafter.Component; import Crafter.Math; +import Crafter.Event; namespace Crafter { export class Camera : public Component { @@ -13,6 +14,7 @@ namespace Crafter { MatrixRowMajor projection; MatrixRowMajor view; MatrixRowMajor projectionView; + Event onUpdate; Camera(float fov, float aspectRatio, float near, float far); void Update(); }; diff --git a/Crafter.Graphics-MeshShader.cppm b/Crafter.Graphics-MeshShader.cppm index 079a273..2005b4e 100644 --- a/Crafter.Graphics-MeshShader.cppm +++ b/Crafter.Graphics-MeshShader.cppm @@ -15,14 +15,19 @@ import Crafter.Math; namespace Crafter { export template - class MeshShader { + class MeshShader : public Component { public: MatrixRowMajor transform; ComponentRefOwning> mesh; ComponentRefOwning camera; Buffer> mvp; std::uint32_t threadCount; - MeshShader(Mesh* mesh, Camera* camera) : threadCount(std::ceil(static_cast(mesh->indexCount)/64/3)), mvp(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), mesh(mesh), camera(camera) { + EventListener cameraUpdate; + MeshShader(Mesh* mesh, Camera* camera) : threadCount(std::ceil(static_cast(mesh->indexCount)/64/3)), mvp(VK_BUFFER_USAGE_UNIFORM_BUFFER_BIT, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT), mesh(mesh), camera(camera), cameraUpdate( + &camera->onUpdate, [this](){ + Update(); + } + ) { transform = MatrixRowMajor::Identity(); } void WriteDescriptors(DescriptorSet& set) { diff --git a/Crafter.Graphics-TextureShader.cppm b/Crafter.Graphics-TextureShader.cppm index 22b530f..03f4c83 100644 --- a/Crafter.Graphics-TextureShader.cppm +++ b/Crafter.Graphics-TextureShader.cppm @@ -4,13 +4,6 @@ module; #include #include #include -#define GLM_FORCE_RADIANS -#define GLM_FORCE_DEPTH_ZERO_TO_ONE -#define GLM_ENABLE_EXPERIMENTAL -#include -#include -#include -#include export module Crafter.Graphics:TextureShader; import Crafter.Component; diff --git a/Crafter.Graphics-VulkanTexture.cppm b/Crafter.Graphics-VulkanTexture.cppm index d8ea3ed..0283d5c 100644 --- a/Crafter.Graphics-VulkanTexture.cppm +++ b/Crafter.Graphics-VulkanTexture.cppm @@ -4,13 +4,6 @@ module; #include #include #include -#define GLM_FORCE_RADIANS -#define GLM_FORCE_DEPTH_ZERO_TO_ONE -#define GLM_ENABLE_EXPERIMENTAL -#include -#include -#include -#include export module Crafter.Graphics:VulkanTexture; import Crafter.Component; diff --git a/Crafter.Graphics-WindowWayland.cpp b/Crafter.Graphics-WindowWayland.cpp index daea4ae..f247a75 100644 --- a/Crafter.Graphics-WindowWayland.cpp +++ b/Crafter.Graphics-WindowWayland.cpp @@ -155,9 +155,11 @@ void keyboard_key(void *data, wl_keyboard *keyboard, uint32_t serial, uint32_t t if(window->heldkeys[keypress]) { window->onKeyHold[keypress].Invoke(); } else{ + window->heldkeys[keypress] = true; window->onKeyDown[keypress].Invoke(); } } else{ + window->heldkeys[keypress] = false; window->onKeyUp[keypress].Invoke(); } @@ -196,7 +198,7 @@ void WindowWayland::seat_handle_capabilities(void* data, wl_seat* seat, uint32_t } if (capabilities & WL_SEAT_CAPABILITY_KEYBOARD) { wl_keyboard* keyboard = wl_seat_get_keyboard(seat); - wl_keyboard_add_listener(keyboard, &keyboard_listener, NULL); + wl_keyboard_add_listener(keyboard, &keyboard_listener, window); } } diff --git a/Crafter.Graphics-WindowWaylandVulkan.cpp b/Crafter.Graphics-WindowWaylandVulkan.cpp index 8177da0..8c824ac 100644 --- a/Crafter.Graphics-WindowWaylandVulkan.cpp +++ b/Crafter.Graphics-WindowWaylandVulkan.cpp @@ -439,6 +439,7 @@ void WindowWaylandVulkan::Start() { vkCmdSetScissor(drawCmdBuffers[currentBuffer], 0, 1, &scissor); onDraw.Invoke(drawCmdBuffers[currentBuffer]); + mouseDelta = {0, 0}; VulkanDevice::vkCmdEndRenderingKHRProc(drawCmdBuffers[currentBuffer]);