Movmenet & duplication!

This commit is contained in:
2026-02-21 15:23:14 +00:00
parent 11783743de
commit 13063ad289
21 changed files with 113 additions and 15 deletions

View File

@@ -3,7 +3,16 @@
#include <stdexcept>
#include <array>
#define GLM_FORCE_RADIANS
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
#include <glm/glm.hpp>
namespace cve {
struct SimplePushConstantData{
glm::vec2 offset;
alignas(16) glm::vec3 color;
};
FirstApp::FirstApp() {
loadModels();
createPipelineLayout();
@@ -35,12 +44,17 @@ namespace cve {
}
void FirstApp::createPipelineLayout() {
VkPushConstantRange pushConstantRange{};
pushConstantRange.stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT;
pushConstantRange.offset = 0;
pushConstantRange.size = sizeof(SimplePushConstantData);
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
pipelineLayoutInfo.setLayoutCount = 0;
pipelineLayoutInfo.pSetLayouts = nullptr;
pipelineLayoutInfo.pushConstantRangeCount = 0;
pipelineLayoutInfo.pPushConstantRanges = nullptr;
pipelineLayoutInfo.pushConstantRangeCount = 1;
pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange;
if (vkCreatePipelineLayout(cveDevice.device(), &pipelineLayoutInfo, nullptr, &pipelineLayout) !=
VK_SUCCESS) {
throw std::runtime_error("Failed to create pipeline layout");
@@ -108,6 +122,9 @@ namespace cve {
}
void FirstApp::recordCommandBuffer(int imageIndex) {
static int frame = 30;
frame = (frame+1) % 2000;
VkCommandBufferBeginInfo beginInfo{};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@@ -124,7 +141,7 @@ namespace cve {
renderPassInfo.renderArea.extent = cveSwapChain->getSwapChainExtent();
std::array<VkClearValue, 2> clearValues{};
clearValues[0].color = {0.1f, 0.1f, 0.1f, 1.0f};
clearValues[0].color = {0.01f, 0.01f, 0.01f, 1.0f};
clearValues[1].depthStencil = {1.0f, 0};
renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
renderPassInfo.pClearValues = clearValues.data();
@@ -144,7 +161,24 @@ namespace cve {
cvePipeline->bind(commandBuffers[imageIndex]);
cveModel->bind(commandBuffers[imageIndex]);
cveModel->draw(commandBuffers[imageIndex]);
for (int j = 0; j < 4; j++) {
SimplePushConstantData push{};
push.offset = {-0.5f + frame * 0.0005f, -0.4f + j * 0.25f};
push.color = {0.0f, 0.0f, 0.2f + 0.2f * j};
vkCmdPushConstants(
commandBuffers[imageIndex],
pipelineLayout,
VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_FRAGMENT_BIT,
0,
sizeof(SimplePushConstantData),
&push
);
cveModel->draw(commandBuffers[imageIndex]);
}
vkCmdEndRenderPass(commandBuffers[imageIndex]);
if (vkEndCommandBuffer(commandBuffers[imageIndex]) != VK_SUCCESS) {