Finished command buffers
This commit is contained in:
@@ -114,6 +114,10 @@ namespace cve {
|
||||
}
|
||||
}
|
||||
|
||||
void CvePipeline::bind(VkCommandBuffer commandBuffer){
|
||||
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, graphicsPipeline);
|
||||
}
|
||||
|
||||
PipelineConfigInfo CvePipeline::defaultPipelineConfigInfo(uint32_t width, uint32_t height) {
|
||||
PipelineConfigInfo configInfo{};
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ namespace cve {
|
||||
CvePipeline(const CvePipeline&) = delete;
|
||||
void operator=(const CvePipeline&) = delete;
|
||||
|
||||
void bind(VkCommandBuffer commandBuffer);
|
||||
static PipelineConfigInfo defaultPipelineConfigInfo(uint32_t width, uint32_t height);
|
||||
|
||||
private:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "first_app.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <array>
|
||||
|
||||
namespace cve {
|
||||
FirstApp::FirstApp() {
|
||||
@@ -43,6 +44,52 @@ namespace cve {
|
||||
);
|
||||
}
|
||||
|
||||
void FirstApp::createCommandBuffers() {};
|
||||
void FirstApp::createCommandBuffers() {
|
||||
commandBuffers.resize(cveSwapChain.imageCount());
|
||||
|
||||
VkCommandBufferAllocateInfo allocInfo{};
|
||||
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
|
||||
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
|
||||
allocInfo.commandPool = cveDevice.getCommandPool();
|
||||
allocInfo.commandBufferCount = static_cast<uint32_t>(commandBuffers.size());
|
||||
|
||||
if (vkAllocateCommandBuffers(cveDevice.device(), &allocInfo, commandBuffers.data()) !=
|
||||
VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to allocate command buffers");
|
||||
}
|
||||
|
||||
for (int i=0; i < commandBuffers.size(); i++) {
|
||||
VkCommandBufferBeginInfo beginInfo{};
|
||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||
|
||||
if (vkBeginCommandBuffer(commandBuffers[i], &beginInfo) != VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to begin command buffer recording");
|
||||
}
|
||||
|
||||
VkRenderPassBeginInfo renderPassInfo{};
|
||||
renderPassInfo.sType = VK_STRUCTURE_TYPE_RENDER_PASS_BEGIN_INFO;
|
||||
renderPassInfo.renderPass = cveSwapChain.getRenderPass();
|
||||
renderPassInfo.framebuffer = cveSwapChain.getFrameBuffer(i);
|
||||
|
||||
renderPassInfo.renderArea.offset = {0, 0};
|
||||
renderPassInfo.renderArea.extent = cveSwapChain.getSwapChainExtent();
|
||||
|
||||
std::array<VkClearValue, 2> clearValues{};
|
||||
clearValues[0].color = {0.1f, 0.1f, 0.1f, 1.0f};
|
||||
clearValues[1].depthStencil = {1.0f, 0};
|
||||
renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
|
||||
renderPassInfo.pClearValues = clearValues.data();
|
||||
|
||||
vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
|
||||
|
||||
cvePipeline->bind(commandBuffers[i]);
|
||||
vkCmdDraw(commandBuffers[i], 3, 1, 0, 0);
|
||||
|
||||
vkCmdEndRenderPass(commandBuffers[i]);
|
||||
if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {
|
||||
throw std::runtime_error("Failed to record command buffer!");
|
||||
}
|
||||
}
|
||||
}
|
||||
void FirstApp::drawFrame() {};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user