destroy buffers on fence

This commit is contained in:
tylermurphy534 2022-09-27 21:40:20 -04:00
parent 9b60b862e5
commit 269263d886
9 changed files with 35 additions and 8 deletions

View file

@ -20,6 +20,7 @@ Engine::Engine(int width, int height, std::string name, const char *icon) : xeWi
};
Engine::~Engine() {
xe::Model::submitDeleteQueue();
alutExit();
};

View file

@ -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();
}
}

View file

@ -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);

View file

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

View file

@ -2,6 +2,7 @@
#include "xe_device.hpp"
#include "xe_image.hpp"
#include "xe_model.hpp"
#include <vulkan/vulkan.h>

View file

@ -18,8 +18,7 @@ Chunk::Chunk(int32_t gridX, int32_t gridZ, uint32_t world_seed)
Chunk::~Chunk() {
if(worker.joinable())
worker.join();
if(chunkMesh != nullptr)
delete chunkMesh;
xe::Model::deleteModel(chunkMesh);
}
//
@ -155,8 +154,10 @@ void Chunk::addVerticies(Chunk* c, uint8_t side, int32_t x, int32_t y, int32_t z
xe::Model* Chunk::getMesh() {
if(reloadRequired) {
if(chunkMesh != nullptr)
delete chunkMesh;
if(chunkMesh != nullptr) {
xe::Model::deleteModel(chunkMesh);
chunkMesh = nullptr;
}
if(worker.joinable())
worker.join();
xe::Model::Builder builder{};

View file

@ -73,8 +73,8 @@ void FirstApp::reloadLoadedChunks(xe::GameObject& viewer) {
int gridZ = static_cast<int>(floor(gameObject.transform.translation.z / 16.f));
int newGridX = minX + x;
int newGridZ = minZ + z;
if(gridX < minX || gridZ < minZ || gridX > maxX || gridZ > maxZ)
Chunk::deleteChunk(gridX, gridZ);
// if(gridX < minX || gridZ < minZ || gridX > maxX || gridZ > maxZ)
// Chunk::deleteChunk(gridX, gridZ);
Chunk* chunk = Chunk::getChunk(newGridX, newGridZ);
if(chunk == nullptr) {
chunk = Chunk::newChunk(newGridX, newGridZ, 12345);

View file

@ -32,7 +32,7 @@ class FirstApp {
static constexpr int WIDTH = 800;
static constexpr int HEIGHT = 600;
static constexpr int RENDER_DISTANCE = 10;
static constexpr int RENDER_DISTANCE = 32;
void createGameObjects(xe::GameObject& viewer);
void reloadLoadedChunks(xe::GameObject& viewer);

View file

@ -36,7 +36,7 @@ namespace app {
xe::GameObject &viewerObject;
KeyMappings keys{};
float moveSpeed{10.f};
float moveSpeed{30.f};
float lookSpeed{1.5f};
};