Removed binary, made program more hardware-independent, and created gitignore
This commit is contained in:
parent
0e5053b5a8
commit
754776687c
3 changed files with 12 additions and 13 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
VulkanTest
|
BIN
VulkanTest
BIN
VulkanTest
Binary file not shown.
24
main.cpp
24
main.cpp
|
@ -246,10 +246,10 @@ class HelloTriangleApplication {
|
||||||
std::random_device rd;
|
std::random_device rd;
|
||||||
std::mt19937 gen(rd());
|
std::mt19937 gen(rd());
|
||||||
std::uniform_real_distribution<float> pos_dist(-0.5, 0.5);
|
std::uniform_real_distribution<float> pos_dist(-0.5, 0.5);
|
||||||
std::uniform_real_distribution<float> speed_dist(0.0f, 0.0001f);
|
std::uniform_real_distribution<float> speed_dist(0.0f, 0.00001f);
|
||||||
std::uniform_real_distribution<float> size_dist;
|
std::uniform_real_distribution<float> size_dist;
|
||||||
if (scenario == 0) {
|
if (scenario == 0) {
|
||||||
size_dist = std::uniform_real_distribution(4.0f, 12.0f);
|
size_dist = std::uniform_real_distribution(4.0f, 40.0f);
|
||||||
} else if (scenario == 1) {
|
} else if (scenario == 1) {
|
||||||
size_dist = std::uniform_real_distribution(-10.0f, 10.0f);
|
size_dist = std::uniform_real_distribution(-10.0f, 10.0f);
|
||||||
}
|
}
|
||||||
|
@ -265,8 +265,9 @@ class HelloTriangleApplication {
|
||||||
|
|
||||||
void mainLoop() {
|
void mainLoop() {
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
|
int64_t startTime = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||||
glfwPollEvents();
|
glfwPollEvents();
|
||||||
drawFrame();
|
drawFrame(startTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
vkDeviceWaitIdle(device);
|
vkDeviceWaitIdle(device);
|
||||||
|
@ -1034,12 +1035,9 @@ class HelloTriangleApplication {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateUniformBuffer(uint32_t currentImage) {
|
void updateUniformBuffer(uint32_t currentImage, uint64_t startTime) {
|
||||||
static auto startTime = std::chrono::high_resolution_clock::now();
|
uint64_t timeNow = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();
|
||||||
|
float dTime = static_cast<float>(startTime - timeNow);
|
||||||
auto currentTime = std::chrono::high_resolution_clock::now();
|
|
||||||
float time = std::chrono::duration<float, std::chrono::seconds::period>(currentTime - startTime).count();
|
|
||||||
|
|
||||||
UniformBufferObject ubo{};
|
UniformBufferObject ubo{};
|
||||||
|
|
||||||
int arrayLen = sizeof(ballsArr) / sizeof(ballsArr[0]);
|
int arrayLen = sizeof(ballsArr) / sizeof(ballsArr[0]);
|
||||||
|
@ -1050,7 +1048,7 @@ class HelloTriangleApplication {
|
||||||
//ballsArr[3] = ballsArr[3] + glm::vec4(0.003f, -0.003f, 0.0f, 0.0f);
|
//ballsArr[3] = ballsArr[3] + glm::vec4(0.003f, -0.003f, 0.0f, 0.0f);
|
||||||
|
|
||||||
for (int i = 0; i < arrayLen; i++) {
|
for (int i = 0; i < arrayLen; i++) {
|
||||||
ballsArr[i] = ballsArr[i] + glm::vec4(speedArr[i].first, speedArr[i].second, 0.0f, 0.0f) * time;
|
ballsArr[i] = ballsArr[i] + glm::vec4(speedArr[i].first, speedArr[i].second, 0.0f, 0.0f) * (dTime/1000000000000000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
//ubo.balls = ballsVec;
|
//ubo.balls = ballsVec;
|
||||||
|
@ -1069,7 +1067,7 @@ class HelloTriangleApplication {
|
||||||
vkUnmapMemory(device, uniformBuffersMemory[currentImage]);
|
vkUnmapMemory(device, uniformBuffersMemory[currentImage]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawFrame() {
|
void drawFrame(int64_t startTime) {
|
||||||
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
|
vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
|
||||||
|
|
||||||
uint32_t imageIndex;
|
uint32_t imageIndex;
|
||||||
|
@ -1082,8 +1080,6 @@ class HelloTriangleApplication {
|
||||||
throw std::runtime_error("failed to acquire swap chain image!");
|
throw std::runtime_error("failed to acquire swap chain image!");
|
||||||
}
|
}
|
||||||
|
|
||||||
updateUniformBuffer(currentFrame);
|
|
||||||
|
|
||||||
vkResetFences(device, 1, &inFlightFences[currentFrame]);
|
vkResetFences(device, 1, &inFlightFences[currentFrame]);
|
||||||
|
|
||||||
vkResetCommandBuffer(commandBuffers[currentFrame], 0);
|
vkResetCommandBuffer(commandBuffers[currentFrame], 0);
|
||||||
|
@ -1128,6 +1124,8 @@ class HelloTriangleApplication {
|
||||||
throw std::runtime_error("failed to present swap chain image!");
|
throw std::runtime_error("failed to present swap chain image!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateUniformBuffer(currentFrame, startTime);
|
||||||
|
|
||||||
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
|
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue