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

View File

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

View File

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