Movmenet & duplication!
This commit is contained in:
30
Makefile
30
Makefile
@@ -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
|
LDFLAGS = -lglfw -lvulkan -ldl -lpthread -lX11 -lXxf86vm -lXrandr -lXi
|
||||||
|
|
||||||
SOURCES = $(wildcard *.cpp)
|
SOURCES = $(wildcard *.cpp)
|
||||||
HEADERS = $(wildcard *.hpp)
|
HEADERS = $(wildcard *.hpp)
|
||||||
|
OBJECTS = $(SOURCES:%.cpp=build/%.o)
|
||||||
|
DEPS = $(OBJECTS:.o=.d)
|
||||||
|
|
||||||
VulkanTest: $(SOURCES) $(HEADERS)
|
SHADERS = shaders/simple_shader.vert shaders/simple_shader.frag
|
||||||
./compile.sh
|
SPV = $(SHADERS:=.spv)
|
||||||
g++ $(CFLAGS) -o VulkanTest $(SOURCES) $(LDFLAGS)
|
|
||||||
|
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
|
.PHONY: test clean
|
||||||
|
|
||||||
@@ -15,3 +33,7 @@ test: VulkanTest
|
|||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f VulkanTest
|
rm -f VulkanTest
|
||||||
|
rm -rf build
|
||||||
|
rm -f $(SPV)
|
||||||
|
|
||||||
|
-include $(DEPS)
|
||||||
BIN
VulkanTest
BIN
VulkanTest
Binary file not shown.
3
build/cve_device.d
Normal file
3
build/cve_device.d
Normal 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
BIN
build/cve_device.o
Normal file
Binary file not shown.
5
build/cve_model.d
Normal file
5
build/cve_model.d
Normal 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
BIN
build/cve_model.o
Normal file
Binary file not shown.
6
build/cve_pipeline.d
Normal file
6
build/cve_pipeline.d
Normal 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
BIN
build/cve_pipeline.o
Normal file
Binary file not shown.
5
build/cve_swap_chain.d
Normal file
5
build/cve_swap_chain.d
Normal 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
BIN
build/cve_swap_chain.o
Normal file
Binary file not shown.
2
build/cve_window.d
Normal file
2
build/cve_window.d
Normal 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
BIN
build/cve_window.o
Normal file
Binary file not shown.
8
build/first_app.d
Normal file
8
build/first_app.d
Normal 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
BIN
build/first_app.o
Normal file
Binary file not shown.
8
build/main.d
Normal file
8
build/main.d
Normal 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
BIN
build/main.o
Normal file
Binary file not shown.
@@ -3,7 +3,16 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <array>
|
#include <array>
|
||||||
|
|
||||||
|
#define GLM_FORCE_RADIANS
|
||||||
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
||||||
|
#include <glm/glm.hpp>
|
||||||
|
|
||||||
namespace cve {
|
namespace cve {
|
||||||
|
struct SimplePushConstantData{
|
||||||
|
glm::vec2 offset;
|
||||||
|
alignas(16) glm::vec3 color;
|
||||||
|
};
|
||||||
|
|
||||||
FirstApp::FirstApp() {
|
FirstApp::FirstApp() {
|
||||||
loadModels();
|
loadModels();
|
||||||
createPipelineLayout();
|
createPipelineLayout();
|
||||||
@@ -35,12 +44,17 @@ namespace cve {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FirstApp::createPipelineLayout() {
|
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{};
|
VkPipelineLayoutCreateInfo pipelineLayoutInfo{};
|
||||||
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
pipelineLayoutInfo.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
|
||||||
pipelineLayoutInfo.setLayoutCount = 0;
|
pipelineLayoutInfo.setLayoutCount = 0;
|
||||||
pipelineLayoutInfo.pSetLayouts = nullptr;
|
pipelineLayoutInfo.pSetLayouts = nullptr;
|
||||||
pipelineLayoutInfo.pushConstantRangeCount = 0;
|
pipelineLayoutInfo.pushConstantRangeCount = 1;
|
||||||
pipelineLayoutInfo.pPushConstantRanges = nullptr;
|
pipelineLayoutInfo.pPushConstantRanges = &pushConstantRange;
|
||||||
if (vkCreatePipelineLayout(cveDevice.device(), &pipelineLayoutInfo, nullptr, &pipelineLayout) !=
|
if (vkCreatePipelineLayout(cveDevice.device(), &pipelineLayoutInfo, nullptr, &pipelineLayout) !=
|
||||||
VK_SUCCESS) {
|
VK_SUCCESS) {
|
||||||
throw std::runtime_error("Failed to create pipeline layout");
|
throw std::runtime_error("Failed to create pipeline layout");
|
||||||
@@ -108,6 +122,9 @@ namespace cve {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FirstApp::recordCommandBuffer(int imageIndex) {
|
void FirstApp::recordCommandBuffer(int imageIndex) {
|
||||||
|
static int frame = 30;
|
||||||
|
frame = (frame+1) % 2000;
|
||||||
|
|
||||||
VkCommandBufferBeginInfo beginInfo{};
|
VkCommandBufferBeginInfo beginInfo{};
|
||||||
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
|
||||||
|
|
||||||
@@ -124,7 +141,7 @@ namespace cve {
|
|||||||
renderPassInfo.renderArea.extent = cveSwapChain->getSwapChainExtent();
|
renderPassInfo.renderArea.extent = cveSwapChain->getSwapChainExtent();
|
||||||
|
|
||||||
std::array<VkClearValue, 2> clearValues{};
|
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};
|
clearValues[1].depthStencil = {1.0f, 0};
|
||||||
renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
|
renderPassInfo.clearValueCount = static_cast<uint32_t>(clearValues.size());
|
||||||
renderPassInfo.pClearValues = clearValues.data();
|
renderPassInfo.pClearValues = clearValues.data();
|
||||||
@@ -144,7 +161,24 @@ namespace cve {
|
|||||||
|
|
||||||
cvePipeline->bind(commandBuffers[imageIndex]);
|
cvePipeline->bind(commandBuffers[imageIndex]);
|
||||||
cveModel->bind(commandBuffers[imageIndex]);
|
cveModel->bind(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]);
|
cveModel->draw(commandBuffers[imageIndex]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
vkCmdEndRenderPass(commandBuffers[imageIndex]);
|
vkCmdEndRenderPass(commandBuffers[imageIndex]);
|
||||||
if (vkEndCommandBuffer(commandBuffers[imageIndex]) != VK_SUCCESS) {
|
if (vkEndCommandBuffer(commandBuffers[imageIndex]) != VK_SUCCESS) {
|
||||||
|
|||||||
@@ -1,9 +1,12 @@
|
|||||||
#version 450
|
#version 450
|
||||||
|
|
||||||
layout(location = 0) in vec3 fragColor;
|
|
||||||
|
|
||||||
layout(location = 0) out vec4 outColor;
|
layout(location = 0) out vec4 outColor;
|
||||||
|
|
||||||
|
layout(push_constant) uniform Push {
|
||||||
|
vec2 offset;
|
||||||
|
vec3 color;
|
||||||
|
} push;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
outColor = vec4(fragColor, 1.0);
|
outColor = vec4(push.color, 1.0);
|
||||||
}
|
}
|
||||||
Binary file not shown.
@@ -3,9 +3,11 @@
|
|||||||
layout(location = 0) in vec2 position;
|
layout(location = 0) in vec2 position;
|
||||||
layout(location = 1) in vec3 color;
|
layout(location = 1) in vec3 color;
|
||||||
|
|
||||||
layout(location = 0) out vec3 fragColor;
|
layout(push_constant) uniform Push {
|
||||||
|
vec2 offset;
|
||||||
|
vec3 color;
|
||||||
|
} push;
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
gl_Position = vec4(position, 0.0, 1.0);
|
gl_Position = vec4(position + push.offset, 0.0, 1.0);
|
||||||
fragColor = color;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Reference in New Issue
Block a user