2018-09-27 20:09:42 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vulkan/vulkan.h>
|
|
|
|
|
2018-10-15 19:52:16 -04:00
|
|
|
#include "worldpass.h"
|
|
|
|
|
2018-09-29 21:03:06 -04:00
|
|
|
struct RenderTarget {
|
|
|
|
VkSurfaceKHR surface = nullptr;
|
|
|
|
VkSwapchainKHR swapchain = nullptr;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-01 19:39:26 -04:00
|
|
|
VkExtent2D extent = {};
|
2018-10-01 20:20:16 -04:00
|
|
|
uint32_t numImages = 0;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-01 19:39:26 -04:00
|
|
|
VkImage* images = nullptr;
|
|
|
|
VkImageView* imageViews = nullptr;
|
|
|
|
VkFramebuffer* framebuffers = nullptr;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-01 19:14:44 -04:00
|
|
|
VkCommandBuffer* commandBuffers = nullptr;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-01 19:14:44 -04:00
|
|
|
VkSemaphore imageAvailableSemaphore = nullptr;
|
|
|
|
VkSemaphore renderFinishedSemaphore = nullptr;
|
|
|
|
VkFence* fences = nullptr;
|
2018-09-29 21:03:06 -04:00
|
|
|
};
|
|
|
|
|
2018-10-16 08:49:25 -04:00
|
|
|
class World;
|
|
|
|
class Mesh;
|
|
|
|
|
2018-09-27 20:09:42 -04:00
|
|
|
class Renderer {
|
|
|
|
public:
|
|
|
|
Renderer();
|
|
|
|
~Renderer();
|
2018-10-16 08:49:25 -04:00
|
|
|
|
|
|
|
void render(World& world, RenderTarget* target);
|
|
|
|
|
2018-10-01 21:02:27 -04:00
|
|
|
RenderTarget* createSurfaceRenderTarget(VkSurfaceKHR surface, RenderTarget* oldRenderTarget = nullptr);
|
2018-09-29 21:03:06 -04:00
|
|
|
void destroyRenderTarget(RenderTarget* target);
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-15 19:52:16 -04:00
|
|
|
VkShaderModule createShader(const char* path);
|
2018-10-16 08:49:25 -04:00
|
|
|
|
|
|
|
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
|
|
|
|
|
|
|
|
void fillMeshBuffers(Mesh* mesh);
|
|
|
|
|
2018-09-29 21:03:06 -04:00
|
|
|
VkInstance getInstance() const {
|
|
|
|
return instance_;
|
|
|
|
}
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-15 19:52:16 -04:00
|
|
|
VkDevice getDevice() const {
|
|
|
|
return device_;
|
|
|
|
}
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-15 19:52:16 -04:00
|
|
|
VkRenderPass getRenderPass() const {
|
|
|
|
return presentationRenderPass_;
|
|
|
|
}
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-09-27 20:09:42 -04:00
|
|
|
private:
|
2018-09-27 20:33:45 -04:00
|
|
|
void createInstance();
|
2018-09-28 18:10:33 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
void createDebugMessenger();
|
|
|
|
#endif
|
2018-09-27 20:33:45 -04:00
|
|
|
void createLogicalDevice();
|
2018-10-01 19:14:44 -04:00
|
|
|
void createCommandPool();
|
2018-10-01 19:39:26 -04:00
|
|
|
void createPresentationRenderPass();
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-09-27 20:09:42 -04:00
|
|
|
VkInstance instance_ = nullptr;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-09-28 18:10:33 -04:00
|
|
|
#ifdef DEBUG
|
|
|
|
bool enableDebug = false;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-09-28 18:10:33 -04:00
|
|
|
PFN_vkCreateDebugUtilsMessengerEXT createMessenger_ = nullptr;
|
2018-09-28 20:41:48 -04:00
|
|
|
PFN_vkDestroyDebugUtilsMessengerEXT destroyMessenger_ = nullptr;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-09-28 18:10:33 -04:00
|
|
|
VkDebugUtilsMessengerEXT messenger_ = nullptr;
|
|
|
|
#endif
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-09-29 21:03:06 -04:00
|
|
|
VkPhysicalDevice physicalDevice_ = nullptr;
|
2018-09-27 20:33:45 -04:00
|
|
|
VkDevice device_ = nullptr;
|
2018-09-29 21:03:06 -04:00
|
|
|
|
|
|
|
struct {
|
|
|
|
uint32_t graphics = 0, presentation = 0;
|
|
|
|
} queueIndices;
|
|
|
|
|
2018-09-27 22:47:56 -04:00
|
|
|
VkQueue graphicsQueue_ = nullptr;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-01 19:14:44 -04:00
|
|
|
VkCommandPool commandPool_ = nullptr;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-01 19:39:26 -04:00
|
|
|
VkRenderPass presentationRenderPass_ = nullptr;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-15 19:52:16 -04:00
|
|
|
WorldPass* worldPass_ = nullptr;
|
2018-09-27 20:09:42 -04:00
|
|
|
};
|