Files
Destrum/destrum/include/destrum/Graphics/Managers/FrameManager.h
T

57 lines
1.4 KiB
C++

#ifndef FRAMEMANAGER_H
#define FRAMEMANAGER_H
#include <array>
#include <cstdint>
#include <vulkan/vulkan.h>
class FrameManager {
public:
struct FrameData {
VkCommandPool commandPool{VK_NULL_HANDLE};
VkCommandBuffer commandBuffer{VK_NULL_HANDLE};
};
FrameManager() = default;
~FrameManager();
FrameManager(const FrameManager&) = delete;
FrameManager& operator=(const FrameManager&) = delete;
FrameManager(FrameManager&&) = delete;
FrameManager& operator=(FrameManager&&) = delete;
void init(VkDevice device, std::uint32_t queueFamily);
void cleanup(VkDevice device);
[[nodiscard]] VkCommandBuffer beginFrame();
void endFrame(VkCommandBuffer cmd);
void waitIdle() const;
[[nodiscard]] std::uint32_t getCurrentFrameIndex() const {
return frameNumber % 2;
}
[[nodiscard]] FrameData& getCurrentFrame() {
return frames[getCurrentFrameIndex()];
}
[[nodiscard]] const FrameData& getCurrentFrame() const {
return frames[getCurrentFrameIndex()];
}
[[nodiscard]] VkCommandBuffer getCurrentCommandBuffer() {
return frames[getCurrentFrameIndex()].commandBuffer;
}
void nextFrame();
private:
static constexpr std::size_t FRAMES_IN_FLIGHT = 2;
std::array<FrameData, FRAMES_IN_FLIGHT> frames{};
std::uint32_t frameNumber{0};
VkDevice device{VK_NULL_HANDLE};
};
#endif