This commit is contained in:
2026-09-06 23:40:49 -07:00
parent 9b1e7d56a3
commit b6a2d5bf11
6 changed files with 423 additions and 119 deletions
+68
View File
@@ -0,0 +1,68 @@
#pragma once
#include <array>
#include <memory>
#include <sophia/types.hpp>
#include <vector>
#include <vulkan/vulkan.hpp>
#include "device.hpp"
#include "swapchain.hpp"
#include "window.hpp"
namespace sophia {
struct FrameData {
vk::CommandBuffer commandBuffer;
vk::UniqueSemaphore imageAvailable;
vk::UniqueFence inFlight;
};
class RenderContext {
public:
static constexpr u32 MAX_FRAMES_IN_FLIGHT = 2;
RenderContext(const RenderContext&) = delete;
RenderContext& operator=(const RenderContext&) = delete;
RenderContext(Window& window, Device& device);
~RenderContext();
vk::CommandBuffer beginFrame();
void endFrame();
void transitionCurrentImage(vk::CommandBuffer commandBuffer,
vk::ImageLayout newLayout) const {
this->swapchain->getImage(static_cast<int>(this->currentImageIndex))
.transitionLayout(commandBuffer, newLayout);
}
vk::ImageView getCurrentImageView() const {
return this->swapchain->getImageView(
static_cast<int>(this->currentImageIndex));
}
vk::Extent2D getExtent() const { return this->swapchain->getExtent(); }
vk::Format getImageFormat() const {
return this->swapchain->getImageFormat();
}
private:
void recreateSwapchain();
void createFrames();
Window& window;
Device& device;
std::unique_ptr<Swapchain> swapchain;
std::array<FrameData, MAX_FRAMES_IN_FLIGHT> frames;
std::vector<vk::UniqueSemaphore> renderFinishedSemaphores;
std::vector<vk::Fence> imagesInFlight;
u32 currentFrameIndex = 0;
u32 currentImageIndex = 0;
bool isFrameStarted = false;
};
} // namespace sophia