From 0d02ece4c1f88272bb5b135a7cafccceaeacb38c Mon Sep 17 00:00:00 2001 From: Brandon Mak Date: Sun, 16 Oct 2022 16:28:29 +0800 Subject: [PATCH] Wrote handle resize for mouse picking objects --- .../MiddleEnd/Interface/SHGraphicsSystem.cpp | 2 ++ .../MiddleEnd/Interface/SHMousePickSystem.cpp | 29 ++++++++++++++----- .../MiddleEnd/Interface/SHMousePickSystem.h | 5 +++- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp index 247c58fd..cd99648c 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHGraphicsSystem.cpp @@ -559,6 +559,8 @@ namespace SHADE worldRenderGraph->HandleResize(windowDims.first, windowDims.second); + mousePickSystem->HandleResize(); + defaultViewport->SetWidth(static_cast(windowDims.first)); defaultViewport->SetHeight(static_cast(windowDims.second)); diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp index ee8665d5..e4ac92e5 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.cpp @@ -9,8 +9,10 @@ namespace SHADE { - void SHMousePickSystem::Init(Handle logicalDevice, std::span> cmdPools, Handle eidAttachment) noexcept + void SHMousePickSystem::Init(Handle device, std::span> cmdPools, Handle eidAttachment) noexcept { + logicalDevice = device; + pickedEID = 0; // Create command buffers @@ -22,13 +24,7 @@ namespace SHADE // assign the attachment entityIDAttachment = eidAttachment; - // Create the fence - afterCopyFence = logicalDevice->CreateFence(); - - uint32_t bufferSize = entityIDAttachment->GetWidth() * eidAttachment->GetHeight() * SHVkUtil::GetBytesPerPixelFromFormat(entityIDAttachment->GetResourceFormat()); - - // Create the buffer - imageDataDstBuffer = logicalDevice->CreateBuffer(bufferSize, nullptr, bufferSize, vk::BufferUsageFlagBits::eTransferDst, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); + HandleResize(); } void SHMousePickSystem::Run(Handle queue, uint32_t frameIndex) noexcept @@ -63,6 +59,23 @@ namespace SHADE } } + void SHMousePickSystem::HandleResize(void) noexcept + { + if (afterCopyFence) + afterCopyFence.Free(); + + if (imageDataDstBuffer) + imageDataDstBuffer.Free(); + + // Create the fence + afterCopyFence = logicalDevice->CreateFence(); + + uint32_t bufferSize = entityIDAttachment->GetWidth() * entityIDAttachment->GetHeight() * SHVkUtil::GetBytesPerPixelFromFormat(entityIDAttachment->GetResourceFormat()); + + // Create the buffer + imageDataDstBuffer = logicalDevice->CreateBuffer(bufferSize, nullptr, bufferSize, vk::BufferUsageFlagBits::eTransferDst, VMA_MEMORY_USAGE_AUTO, VMA_ALLOCATION_CREATE_MAPPED_BIT | VMA_ALLOCATION_CREATE_HOST_ACCESS_SEQUENTIAL_WRITE_BIT); + } + EntityID SHMousePickSystem::GetPickedEntity(void) const noexcept { return pickedEID; diff --git a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h index 080a192c..4b84c1df 100644 --- a/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h +++ b/SHADE_Engine/src/Graphics/MiddleEnd/Interface/SHMousePickSystem.h @@ -17,6 +17,8 @@ namespace SHADE class SHMousePickSystem { private: + Handle logicalDevice; + //! Handle to the render graph resource that will contain the entity IDs Handle entityIDAttachment; @@ -35,8 +37,9 @@ namespace SHADE /*-----------------------------------------------------------------------*/ /* PUBLIC MEMBER FUNCTIONS */ /*-----------------------------------------------------------------------*/ - void Init(Handle logicalDevice, std::span> cmdPools, Handle eidAttachment) noexcept; + void Init(Handle device, std::span> cmdPools, Handle eidAttachment) noexcept; void Run (Handle queue, uint32_t frameIndex) noexcept; + void HandleResize (void) noexcept; /*-----------------------------------------------------------------------*/ /* SETTERS AND GETTERS */