2022-04-11 23:11:33 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <array>
|
|
|
|
|
2022-04-12 01:57:37 -04:00
|
|
|
#include "mdlparser.h"
|
2022-04-12 00:54:11 -04:00
|
|
|
|
2022-04-12 08:55:38 -04:00
|
|
|
struct RenderPart {
|
2022-04-12 01:57:37 -04:00
|
|
|
size_t numIndices;
|
2022-04-12 00:54:11 -04:00
|
|
|
|
2022-04-12 01:57:37 -04:00
|
|
|
VkBuffer vertexBuffer, indexBuffer;
|
|
|
|
VkDeviceMemory vertexMemory, indexMemory;
|
2022-04-12 00:54:11 -04:00
|
|
|
};
|
|
|
|
|
2022-04-12 08:55:38 -04:00
|
|
|
struct RenderModel {
|
2022-04-12 20:18:22 -04:00
|
|
|
Model model;
|
2022-04-12 08:55:38 -04:00
|
|
|
std::vector<RenderPart> parts;
|
|
|
|
};
|
|
|
|
|
2022-04-11 23:11:33 -04:00
|
|
|
class Renderer {
|
|
|
|
public:
|
|
|
|
Renderer();
|
|
|
|
|
2022-04-12 00:54:11 -04:00
|
|
|
void initPipeline();
|
2022-04-12 12:19:46 -04:00
|
|
|
bool initSwapchain(VkSurfaceKHR surface, int width, int height);
|
2022-04-12 00:30:17 -04:00
|
|
|
void resize(VkSurfaceKHR surface, int width, int height);
|
2022-04-11 23:11:33 -04:00
|
|
|
|
2022-04-14 10:32:41 -04:00
|
|
|
RenderModel addModel(const Model& model, int lod);
|
2022-04-12 00:54:11 -04:00
|
|
|
|
2022-04-12 01:57:37 -04:00
|
|
|
void render(std::vector<RenderModel> models);
|
2022-04-11 23:11:33 -04:00
|
|
|
|
|
|
|
VkInstance instance = VK_NULL_HANDLE;
|
|
|
|
VkPhysicalDevice physicalDevice = VK_NULL_HANDLE;
|
|
|
|
VkDevice device = VK_NULL_HANDLE;
|
|
|
|
VkQueue graphicsQueue = VK_NULL_HANDLE, presentQueue = VK_NULL_HANDLE;
|
|
|
|
VkCommandPool commandPool = VK_NULL_HANDLE;
|
|
|
|
VkSwapchainKHR swapchain = VK_NULL_HANDLE;
|
|
|
|
VkExtent2D swapchainExtent;
|
|
|
|
std::vector<VkImage> swapchainImages;
|
|
|
|
std::vector<VkImageView> swapchainViews;
|
|
|
|
std::vector<VkFramebuffer> swapchainFramebuffers;
|
|
|
|
VkRenderPass renderPass;
|
|
|
|
std::array<VkCommandBuffer, 3> commandBuffers;
|
|
|
|
std::array<VkFence, 3> inFlightFences;
|
|
|
|
std::array<VkSemaphore, 3> imageAvailableSemaphores, renderFinishedSemaphores;
|
|
|
|
uint32_t currentFrame = 0;
|
2022-04-12 01:57:37 -04:00
|
|
|
VkPipeline pipeline;
|
|
|
|
VkPipelineLayout pipelineLayout;
|
2022-04-12 00:54:11 -04:00
|
|
|
|
|
|
|
std::tuple<VkBuffer, VkDeviceMemory> createBuffer(size_t size, VkBufferUsageFlags usageFlags);
|
|
|
|
|
|
|
|
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
|
|
|
|
|
|
|
|
VkShaderModule createShaderModule(const uint32_t *code, const int length);
|
|
|
|
|
|
|
|
VkShaderModule loadShaderFromDisk(const std::string_view path);
|
2022-04-11 23:11:33 -04:00
|
|
|
};
|