summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
Diffstat (limited to 'engine')
-rw-r--r--engine/xe_engine.cpp1
-rw-r--r--engine/xe_model.cpp17
-rw-r--r--engine/xe_model.hpp2
-rwxr-xr-xengine/xe_swap_chain.cpp5
-rwxr-xr-xengine/xe_swap_chain.hpp1
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>