refactoring everything into multiple classes

main
Benjamin Kraft 2 weeks ago
parent 1c91e836d0
commit 3caf9e9a4e
  1. 32
      src/vulkan/application.cpp
  2. 14
      src/vulkan/application.hpp
  3. 1
      src/vulkan/buffer.cpp
  4. 3
      src/vulkan/buffer.hpp
  5. 1
      src/vulkan/command_pool.cpp
  6. 4
      src/vulkan/command_pool.hpp
  7. 1
      src/vulkan/pipeline.cpp
  8. 3
      src/vulkan/pipeline.hpp
  9. 1
      src/vulkan/swapchain.cpp
  10. 2
      src/vulkan/swapchain.hpp

@ -1,4 +1,10 @@
#include "application.hpp" #include "application.hpp"
#include "vertex.hpp"
#include "swapchain.hpp"
#include "pipeline.hpp"
#include "instance.hpp"
#include "buffer.hpp"
#include "command_pool.hpp"
Application::Application() { Application::Application() {
instance = new Instance; instance = new Instance;
@ -89,19 +95,6 @@ void Application::createSyncObjects() {
} }
} }
Application::~Application() {
delete swapchain;
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++){
vkDestroySemaphore(instance->device, imageAvailableSemaphores[i], nullptr);
vkDestroySemaphore(instance->device, renderFinishedSemaphores[i], nullptr);
vkDestroyFence(instance->device, inFlightFences[i], nullptr);
}
delete commandPool;
delete buffer;
delete pipeline;
delete instance;
}
void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) { void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
VkCommandBufferBeginInfo beginInfo {}; VkCommandBufferBeginInfo beginInfo {};
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@ -146,6 +139,19 @@ void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t im
vkEndCommandBuffer(commandBuffer); vkEndCommandBuffer(commandBuffer);
} }
Application::~Application() {
delete swapchain;
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++){
vkDestroySemaphore(instance->device, imageAvailableSemaphores[i], nullptr);
vkDestroySemaphore(instance->device, renderFinishedSemaphores[i], nullptr);
vkDestroyFence(instance->device, inFlightFences[i], nullptr);
}
delete commandPool;
delete buffer;
delete pipeline;
delete instance;
}

@ -13,12 +13,14 @@
#include <numeric> #include <numeric>
#include <chrono> #include <chrono>
#include <array> #include <array>
#include "vertex.hpp" #include <memory>
#include "swapchain.hpp" #include <vulkan/vulkan_core.h>
#include "pipeline.hpp"
#include "instance.hpp" class Instance;
#include "buffer.hpp" class Swapchain;
#include "command_pool.hpp" class Pipeline;
class Buffer;
class CommandPool;
constexpr int MAX_FRAMES_IN_FLIGHT = 2; constexpr int MAX_FRAMES_IN_FLIGHT = 2;

@ -2,6 +2,7 @@
#include <cstring> #include <cstring>
#include "buffer.hpp" #include "buffer.hpp"
#include "vertex.hpp" #include "vertex.hpp"
#include "instance.hpp"
const std::vector<Vertex> vertices = { const std::vector<Vertex> vertices = {
{{0.0, -0.5}, {1, 0, 0}}, {{0.0, -0.5}, {1, 0, 0}},

@ -2,7 +2,8 @@
#include <vulkan/vulkan_core.h> #include <vulkan/vulkan_core.h>
#include <stdexcept> #include <stdexcept>
#include "instance.hpp"
class Instance;
class Buffer { class Buffer {

@ -1,5 +1,6 @@
#include "command_pool.hpp" #include "command_pool.hpp"
#include "application.hpp" #include "application.hpp"
#include "instance.hpp"
CommandPool::CommandPool(Instance *instance) : instance(instance) { CommandPool::CommandPool(Instance *instance) : instance(instance) {
Instance::QueueFamilyIndices indices = Instance::findQueueFamilies(instance->physicalDevice, instance->surface); Instance::QueueFamilyIndices indices = Instance::findQueueFamilies(instance->physicalDevice, instance->surface);

@ -1,7 +1,9 @@
#pragma once #pragma once
#include <vector> #include <vector>
#include "instance.hpp" #include <vulkan/vulkan_core.h>
class Instance;
class CommandPool { class CommandPool {
public: public:

@ -2,6 +2,7 @@
#include <fstream> #include <fstream>
#include "pipeline.hpp" #include "pipeline.hpp"
#include "vertex.hpp" #include "vertex.hpp"
#include "instance.hpp"
std::vector<char> readFile(const std::string& fileName){ std::vector<char> readFile(const std::string& fileName){
std::ifstream file(fileName, std::ios::ate | std::ios::binary); std::ifstream file(fileName, std::ios::ate | std::ios::binary);

@ -1,7 +1,8 @@
#pragma once #pragma once
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "instance.hpp"
class Instance;
class Pipeline { class Pipeline {
public: public:

@ -1,6 +1,7 @@
#include <limits> #include <limits>
#include <stdexcept> #include <stdexcept>
#include "swapchain.hpp" #include "swapchain.hpp"
#include "instance.hpp"
SwapchainSupportDetails querySwapchainSupport(VkPhysicalDevice device, VkSurfaceKHR surface){ SwapchainSupportDetails querySwapchainSupport(VkPhysicalDevice device, VkSurfaceKHR surface){
SwapchainSupportDetails details; SwapchainSupportDetails details;

@ -3,7 +3,7 @@
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include <vector> #include <vector>
#include "instance.hpp" class Instance;
struct SwapchainSupportDetails { struct SwapchainSupportDetails {
VkSurfaceCapabilitiesKHR capabilities {}; VkSurfaceCapabilitiesKHR capabilities {};

Loading…
Cancel
Save