Add code to allow for depth buffer query (Fixes #18)

This commit is contained in:
Georg Hagen
2024-08-01 10:29:07 +02:00
parent 579c4bcca1
commit e54404ec61
8 changed files with 171 additions and 16 deletions

View File

@@ -0,0 +1,48 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include "Math/Math.hpp"
#include "Vulkan/Image.hpp"
namespace OpenVulkano::Vulkan
{
class Renderer;
class DepthBufferQuery final
{
Renderer& renderer;
vk::DeviceMemory memory;
vk::Buffer bufferDepth;
float* cpuDepthBuffer = nullptr;
Math::Vector2f depthQueryCoordinates = { 0.5f, 0.5f };
bool copyDepthBuffer = true;
vk::Offset3D GetCopyOffset() const;
public:
DepthBufferQuery(Renderer& renderer): renderer(renderer) {}
~DepthBufferQuery() { if (cpuDepthBuffer != nullptr) Close(); }
void Init();
void Close();
void Encode(vk::CommandBuffer& commandBuffer);
void Resize(uint32_t width, uint32_t height);
float GetQueriedValue() const;
void SetQueryCoordinates(const Math::Vector2f& coords)
{
copyDepthBuffer = true;
depthQueryCoordinates = coords;
}
};
}