2022-09-19 01:20:51 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-09-23 17:20:30 +00:00
|
|
|
#include "xe_device.hpp"
|
|
|
|
#include "xe_game_object.hpp"
|
2022-09-19 01:20:51 +00:00
|
|
|
#include "xe_swap_chain.hpp"
|
2022-09-23 17:20:30 +00:00
|
|
|
#include "xe_descriptors.hpp"
|
2022-09-19 01:20:51 +00:00
|
|
|
#include "xe_window.hpp"
|
|
|
|
|
2022-09-23 17:20:30 +00:00
|
|
|
#include <array>
|
2022-09-19 01:20:51 +00:00
|
|
|
#include <cassert>
|
2022-09-23 17:20:30 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <memory>
|
|
|
|
#include <vulkan/vulkan_core.h>
|
2022-09-19 01:20:51 +00:00
|
|
|
|
|
|
|
namespace xe {
|
|
|
|
class XeRenderer {
|
|
|
|
public:
|
|
|
|
|
|
|
|
XeRenderer(XeWindow &window, XeDevice &device);
|
|
|
|
~XeRenderer();
|
|
|
|
|
|
|
|
XeRenderer(const XeRenderer &) = delete;
|
|
|
|
XeRenderer operator=(const XeRenderer &) = delete;
|
|
|
|
|
|
|
|
VkRenderPass getSwapChainRenderPass() const { return xeSwapChain->getRenderPass(); }
|
|
|
|
float getAspectRatio() const { return xeSwapChain->extentAspectRatio(); }
|
|
|
|
bool isFrameInProgress() const { return isFrameStarted; }
|
|
|
|
|
|
|
|
VkCommandBuffer getCurrentCommandBuffer() const {
|
|
|
|
assert(isFrameStarted && "Cannot get command buffer when frame not in progress");
|
|
|
|
return commandBuffers[currentFrameIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
int getFrameIndex() const {
|
|
|
|
assert(isFrameStarted && "Cannot get frame index when frame not in progress");
|
|
|
|
return currentFrameIndex;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkCommandBuffer beginFrame();
|
|
|
|
void endFrame();
|
|
|
|
void beginSwapChainRenderPass(VkCommandBuffer commandBuffer);
|
|
|
|
void endSwapChainRenderPass(VkCommandBuffer commandBuffer);
|
|
|
|
|
|
|
|
private:
|
|
|
|
void createCommandBuffers();
|
|
|
|
void freeCommandBuffers();
|
|
|
|
void recreateSwapChain();
|
|
|
|
|
|
|
|
XeWindow& xeWindow;
|
|
|
|
XeDevice& xeDevice;
|
|
|
|
std::unique_ptr<XeSwapChain> xeSwapChain;
|
|
|
|
std::vector<VkCommandBuffer> commandBuffers;
|
|
|
|
|
|
|
|
uint32_t currentImageIndex;
|
|
|
|
int currentFrameIndex{0};
|
|
|
|
bool isFrameStarted{false};
|
|
|
|
};
|
|
|
|
}
|