Better structure again (whoohoo)!
This commit is contained in:
BIN
VulkanTest
BIN
VulkanTest
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -25,10 +25,11 @@ namespace cve {
|
||||
if (cveSwapChain == nullptr) {
|
||||
cveSwapChain = std::make_unique<CveSwapChain>(cveDevice, extent);
|
||||
} else {
|
||||
cveSwapChain = std::make_unique<CveSwapChain>(cveDevice, extent, std::move(cveSwapChain));
|
||||
if (cveSwapChain->imageCount() != commandBuffers.size()) {
|
||||
freeCommandBuffers();
|
||||
createCommandBuffers();
|
||||
std::shared_ptr<CveSwapChain> oldSwapChain = std::move(cveSwapChain);
|
||||
cveSwapChain = std::make_unique<CveSwapChain>(cveDevice, extent, oldSwapChain);
|
||||
|
||||
if (!oldSwapChain->compareSwapFormats(*cveSwapChain.get())) {
|
||||
throw std::runtime_error("Swap chain image format/depth has changed.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +37,7 @@ namespace cve {
|
||||
}
|
||||
|
||||
void CveRenderer::createCommandBuffers() {
|
||||
commandBuffers.resize(cveSwapChain->imageCount());
|
||||
commandBuffers.resize(CveSwapChain::MAX_FRAMES_IN_FLIGHT);
|
||||
|
||||
VkCommandBufferAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
@@ -99,6 +100,8 @@ namespace cve {
|
||||
}
|
||||
|
||||
isFrameStarted = false;
|
||||
|
||||
currentFrameIndex = (currentFrameIndex + 1) % CveSwapChain::MAX_FRAMES_IN_FLIGHT;
|
||||
}
|
||||
|
||||
void CveRenderer::beginSwapChainRenderPass(VkCommandBuffer commandBuffer) {
|
||||
|
||||
@@ -23,7 +23,12 @@ namespace cve {
|
||||
|
||||
VkCommandBuffer getCurrentCommandBuffer() const {
|
||||
assert(isFrameStarted && "Cannot get command buffer when frame is not in progress");
|
||||
return commandBuffers[currentImageIndex];
|
||||
return commandBuffers[currentFrameIndex];
|
||||
}
|
||||
|
||||
int getFrameIndex() const {
|
||||
assert(isFrameStarted && "Cannot get frame index when frame is not started");
|
||||
return currentFrameIndex;
|
||||
}
|
||||
|
||||
VkCommandBuffer beginFrame();
|
||||
@@ -41,7 +46,8 @@ namespace cve {
|
||||
std::unique_ptr<CveSwapChain> cveSwapChain;
|
||||
std::vector<VkCommandBuffer> commandBuffers;
|
||||
|
||||
uint32_t currentImageIndex;
|
||||
uint32_t currentImageIndex = 0;
|
||||
int currentFrameIndex = 0;
|
||||
bool isFrameStarted = false;
|
||||
};
|
||||
}
|
||||
|
||||
@@ -301,6 +301,7 @@ void CveSwapChain::createFramebuffers() {
|
||||
|
||||
void CveSwapChain::createDepthResources() {
|
||||
VkFormat depthFormat = findDepthFormat();
|
||||
swapChainDepthFormat = depthFormat;
|
||||
VkExtent2D swapChainExtent = getSwapChainExtent();
|
||||
|
||||
depthImages.resize(imageCount());
|
||||
|
||||
@@ -40,6 +40,11 @@ class CveSwapChain {
|
||||
VkResult acquireNextImage(uint32_t *imageIndex);
|
||||
VkResult submitCommandBuffers(const VkCommandBuffer *buffers, uint32_t *imageIndex);
|
||||
|
||||
bool compareSwapFormats(const CveSwapChain& swapChain) const {
|
||||
return swapChain.swapChainDepthFormat == swapChainDepthFormat &&
|
||||
swapChain.swapChainImageFormat == swapChainImageFormat;
|
||||
};
|
||||
|
||||
private:
|
||||
void init();
|
||||
void createSwapChain();
|
||||
@@ -57,6 +62,7 @@ class CveSwapChain {
|
||||
VkExtent2D chooseSwapExtent(const VkSurfaceCapabilitiesKHR &capabilities);
|
||||
|
||||
VkFormat swapChainImageFormat;
|
||||
VkFormat swapChainDepthFormat;
|
||||
VkExtent2D swapChainExtent;
|
||||
|
||||
std::vector<VkFramebuffer> swapChainFramebuffers;
|
||||
|
||||
Reference in New Issue
Block a user