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

@@ -1,12 +1,30 @@
CFLAGS = -std=c++17 -O2
CXX ?= g++
CCACHE := $(shell command -v ccache 2>/dev/null)
ifneq ($(CCACHE),)
CXX := ccache $(CXX)
endif
CXXFLAGS = -std=c++17 -O2 -MMD -MP
LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi
SOURCES = $(wildcard *.cpp)
HEADERS = $(wildcard *.hpp)
OBJECTS = $(SOURCES:%.cpp=build/%.o)
DEPS = $(OBJECTS:.o=.d)
VulkanTest: $(SOURCES) $(HEADERS)
./compile.sh
g++ $(CFLAGS) -o VulkanTest $(SOURCES) $(LDFLAGS)
SHADERS = shaders/simple_shader.vert shaders/simple_shader.frag
SPV = $(SHADERS:=.spv)
VulkanTest: $(SPV) $(OBJECTS)
$(CXX) $(CXXFLAGS) -o VulkanTest $(OBJECTS) $(LDFLAGS)
build/%.o: %.cpp $(HEADERS) | build
$(CXX) $(CXXFLAGS) -c $< -o $@
shaders/%.spv: shaders/%
/usr/local/bin/glslc $< -o $@
build:
mkdir -p build
.PHONY: test clean
@@ -15,3 +33,7 @@ test: VulkanTest
clean:
rm -f VulkanTest
rm -rf build
rm -f $(SPV)
-include $(DEPS)

Binary file not shown.

3
build/cve_device.d Normal file
View File

@@ -0,0 +1,3 @@
build/cve_device.o: cve_device.cpp cve_device.hpp cve_window.hpp
cve_device.hpp:
cve_window.hpp:

BIN
build/cve_device.o Normal file

Binary file not shown.

5
build/cve_model.d Normal file
View File

@@ -0,0 +1,5 @@
build/cve_model.o: cve_model.cpp cve_model.hpp cve_device.hpp \
cve_window.hpp
cve_model.hpp:
cve_device.hpp:
cve_window.hpp:

BIN
build/cve_model.o Normal file

Binary file not shown.

6
build/cve_pipeline.d Normal file
View File

@@ -0,0 +1,6 @@
build/cve_pipeline.o: cve_pipeline.cpp cve_pipeline.hpp cve_device.hpp \
cve_window.hpp cve_model.hpp
cve_pipeline.hpp:
cve_device.hpp:
cve_window.hpp:
cve_model.hpp:

BIN
build/cve_pipeline.o Normal file

Binary file not shown.

5
build/cve_swap_chain.d Normal file
View File

@@ -0,0 +1,5 @@
build/cve_swap_chain.o: cve_swap_chain.cpp cve_swap_chain.hpp \
cve_device.hpp cve_window.hpp
cve_swap_chain.hpp:
cve_device.hpp:
cve_window.hpp:

BIN
build/cve_swap_chain.o Normal file

Binary file not shown.

2
build/cve_window.d Normal file
View File

@@ -0,0 +1,2 @@
build/cve_window.o: cve_window.cpp cve_window.hpp
cve_window.hpp:

BIN
build/cve_window.o Normal file

Binary file not shown.

8
build/first_app.d Normal file
View File

@@ -0,0 +1,8 @@
build/first_app.o: first_app.cpp first_app.hpp cve_window.hpp \
cve_pipeline.hpp cve_device.hpp cve_swap_chain.hpp cve_model.hpp
first_app.hpp:
cve_window.hpp:
cve_pipeline.hpp:
cve_device.hpp:
cve_swap_chain.hpp:
cve_model.hpp:

BIN
build/first_app.o Normal file

Binary file not shown.

8
build/main.d Normal file
View File

@@ -0,0 +1,8 @@
build/main.o: main.cpp first_app.hpp cve_window.hpp cve_pipeline.hpp \
cve_device.hpp cve_swap_chain.hpp cve_model.hpp
first_app.hpp:
cve_window.hpp:
cve_pipeline.hpp:
cve_device.hpp:
cve_swap_chain.hpp:
cve_model.hpp:

BIN
build/main.o Normal file

Binary file not shown.

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) {

View File

@@ -1,9 +1,12 @@
#version 450
layout(location = 0) in vec3 fragColor;
layout(location = 0) out vec4 outColor;
layout(push_constant) uniform Push {
vec2 offset;
vec3 color;
} push;
void main() {
outColor = vec4(fragColor, 1.0);
outColor = vec4(push.color, 1.0);
}

Binary file not shown.

View File

@@ -3,9 +3,11 @@
layout(location = 0) in vec2 position;
layout(location = 1) in vec3 color;
layout(location = 0) out vec3 fragColor;
layout(push_constant) uniform Push {
vec2 offset;
vec3 color;
} push;
void main() {
gl_Position = vec4(position, 0.0, 1.0);
fragColor = color;
gl_Position = vec4(position + push.offset, 0.0, 1.0);
}

Binary file not shown.