diff options
author | tylermurphy534 <tylermurphy534@gmail.com> | 2022-09-27 21:40:20 -0400 |
---|---|---|
committer | tylermurphy534 <tylermurphy534@gmail.com> | 2022-09-27 21:40:20 -0400 |
commit | 269263d88629c48027d71275dd778f7b01a569f1 (patch) | |
tree | 147f63e68d3941751b7bc4778a4bb745b8d88eba /engine | |
parent | procedural chunk loading (diff) | |
download | minecraftvulkan-269263d88629c48027d71275dd778f7b01a569f1.tar.gz minecraftvulkan-269263d88629c48027d71275dd778f7b01a569f1.tar.bz2 minecraftvulkan-269263d88629c48027d71275dd778f7b01a569f1.zip |
destroy buffers on fence
Diffstat (limited to 'engine')
-rw-r--r-- | engine/xe_engine.cpp | 1 | ||||
-rw-r--r-- | engine/xe_model.cpp | 17 | ||||
-rw-r--r-- | engine/xe_model.hpp | 2 | ||||
-rwxr-xr-x | engine/xe_swap_chain.cpp | 5 | ||||
-rwxr-xr-x | engine/xe_swap_chain.hpp | 1 |
5 files changed, 26 insertions, 0 deletions
diff --git a/engine/xe_engine.cpp b/engine/xe_engine.cpp index 201ea81..eabbdb1 100644 --- a/engine/xe_engine.cpp +++ b/engine/xe_engine.cpp @@ -20,6 +20,7 @@ Engine::Engine(int width, int height, std::string name, const char *icon) : xeWi }; Engine::~Engine() { + xe::Model::submitDeleteQueue(); alutExit(); }; diff --git a/engine/xe_model.cpp b/engine/xe_model.cpp index dc39584..f8001fd 100644 --- a/engine/xe_model.cpp +++ b/engine/xe_model.cpp @@ -155,4 +155,21 @@ void Model::Builder::loadModel(const std::string &filepath) { } +static std::vector<Model*> deleteQueue{}; + +void Model::deleteModel(Model* model) { + deleteQueue.push_back(model); +} + +void Model::submitDeleteQueue() { + for(Model* model : deleteQueue) { + if(model == nullptr) return; + try { + delete model; + } catch (int err) {} + } + deleteQueue.clear(); +} + + }
\ No newline at end of file diff --git a/engine/xe_model.hpp b/engine/xe_model.hpp index b75576e..e331ed1 100644 --- a/engine/xe_model.hpp +++ b/engine/xe_model.hpp @@ -41,6 +41,8 @@ class Model { Model operator=(const Model &) = delete; static Model* createModelFromFile(const std::string &filepath); + static void deleteModel(Model* model); + static void submitDeleteQueue(); void bind(VkCommandBuffer commandBuffer); void draw(VkCommandBuffer commandBuffer); diff --git a/engine/xe_swap_chain.cpp b/engine/xe_swap_chain.cpp index 67248f4..c631209 100755 --- a/engine/xe_swap_chain.cpp +++ b/engine/xe_swap_chain.cpp @@ -87,6 +87,9 @@ VkResult SwapChain::submitCommandBuffers( if (imagesInFlight[*imageIndex] != VK_NULL_HANDLE) { vkWaitForFences(device.device(), 1, &imagesInFlight[*imageIndex], VK_TRUE, UINT64_MAX); } + + Model::submitDeleteQueue(); + imagesInFlight[*imageIndex] = inFlightFences[currentFrame]; VkSubmitInfo submitInfo = {}; @@ -105,6 +108,8 @@ VkResult SwapChain::submitCommandBuffers( submitInfo.signalSemaphoreCount = 1; submitInfo.pSignalSemaphores = signalSemaphores; + + vkResetFences(device.device(), 1, &inFlightFences[currentFrame]); if (vkQueueSubmit(device.graphicsQueue(), 1, &submitInfo, inFlightFences[currentFrame]) != VK_SUCCESS) { diff --git a/engine/xe_swap_chain.hpp b/engine/xe_swap_chain.hpp index 380bd6e..d85345b 100755 --- a/engine/xe_swap_chain.hpp +++ b/engine/xe_swap_chain.hpp @@ -2,6 +2,7 @@ #include "xe_device.hpp" #include "xe_image.hpp" +#include "xe_model.hpp" #include <vulkan/vulkan.h> |