minecraftvulkan/engine/xe_renderer.hpp

57 lines
1.5 KiB
C++
Raw Normal View History

2022-09-19 01:20:51 +00:00
#pragma once
#include "xe_device.hpp"
2022-09-19 01:20:51 +00:00
#include "xe_swap_chain.hpp"
#include "xe_descriptors.hpp"
2022-09-19 01:20:51 +00:00
#include "xe_window.hpp"
#include <array>
2022-09-19 01:20:51 +00:00
#include <cassert>
#include <stdexcept>
#include <memory>
#include <vulkan/vulkan_core.h>
2022-09-19 01:20:51 +00:00
namespace xe {
2022-09-25 01:16:13 +00:00
class Renderer {
2022-09-19 01:20:51 +00:00
public:
2022-09-25 01:16:13 +00:00
Renderer(Window &window, Device &device);
~Renderer();
2022-09-19 01:20:51 +00:00
2022-09-25 01:16:13 +00:00
Renderer(const Renderer &) = delete;
Renderer operator=(const Renderer &) = delete;
2022-09-19 01:20:51 +00:00
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();
2022-09-25 01:16:13 +00:00
Window& xeWindow;
Device& xeDevice;
std::unique_ptr<SwapChain> xeSwapChain;
2022-09-19 01:20:51 +00:00
std::vector<VkCommandBuffer> commandBuffers;
uint32_t currentImageIndex;
int currentFrameIndex{0};
bool isFrameStarted{false};
};
}