Vertex positions no longer hard coded

This commit is contained in:
2026-02-20 19:01:01 +00:00
parent 9477f686c6
commit b55769bbf2
4 changed files with 26 additions and 5 deletions

Binary file not shown.

View File

@@ -1,5 +1,7 @@
#include "cve_pipeline.hpp"
#include "cve_model.hpp"
#include <fstream>
#include <stdexcept>
#include <iostream>
@@ -63,12 +65,15 @@ namespace cve {
shaderStages[1].pNext = nullptr;
shaderStages[1].pSpecializationInfo = nullptr;
auto bindingDescriptions = CveModel::Vertex::getBindingDescriptions();
auto attributeDescriptions = CveModel::Vertex::getAttributeDescriptions();
VkPipelineVertexInputStateCreateInfo vertexInputInfo{};
vertexInputInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VERTEX_INPUT_STATE_CREATE_INFO;
vertexInputInfo.vertexBindingDescriptionCount = 0;
vertexInputInfo.vertexAttributeDescriptionCount = 0;
vertexInputInfo.pVertexBindingDescriptions = nullptr;
vertexInputInfo.pVertexAttributeDescriptions = nullptr;
vertexInputInfo.vertexAttributeDescriptionCount = static_cast<uint32_t>(attributeDescriptions.size());
vertexInputInfo.vertexBindingDescriptionCount = static_cast<uint32_t>(bindingDescriptions.size());
vertexInputInfo.pVertexBindingDescriptions = bindingDescriptions.data();
vertexInputInfo.pVertexAttributeDescriptions = attributeDescriptions.data();
VkPipelineViewportStateCreateInfo viewportInfo{};
viewportInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_VIEWPORT_STATE_CREATE_INFO;

View File

@@ -5,6 +5,7 @@
namespace cve {
FirstApp::FirstApp() {
loadModels();
createPipelineLayout();
createPipeline();
createCommandBuffers();
@@ -22,6 +23,17 @@ namespace cve {
vkDeviceWaitIdle(cveDevice.device());
}
void FirstApp::loadModels() {
std::vector<CveModel::Vertex> verticies {
{{0.0f, -0.5f}},
{{0.5f, 0.5f}},
{{-0.5f, 0.5f}}
};
cveModel = std::make_unique<CveModel>(cveDevice, verticies);
}
void FirstApp::createPipelineLayout() {
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
@@ -86,7 +98,8 @@ namespace cve {
vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE);
cvePipeline->bind(commandBuffers[i]);
vkCmdDraw(commandBuffers[i], 3, 1, 0, 0);
cveModel->bind(commandBuffers[i]);
cveModel->draw(commandBuffers[i]);
vkCmdEndRenderPass(commandBuffers[i]);
if (vkEndCommandBuffer(commandBuffers[i]) != VK_SUCCESS) {

View File

@@ -4,6 +4,7 @@
#include "cve_pipeline.hpp"
#include "cve_device.hpp"
#include "cve_swap_chain.hpp"
#include "cve_model.hpp"
#include <memory>
#include <vector>
@@ -22,6 +23,7 @@ namespace cve {
void run();
private:
void loadModels();
void createPipelineLayout();
void createPipeline();
void createCommandBuffers();
@@ -33,5 +35,6 @@ namespace cve {
std::unique_ptr<CvePipeline> cvePipeline;
VkPipelineLayout pipelineLayout;
std::vector<VkCommandBuffer> commandBuffers;
std::unique_ptr<CveModel> cveModel;
};
}