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-10-17 10:06:38 -04:00
|
|
|
#include "postpass.h"
|
2018-11-03 07:24:32 -04:00
|
|
|
#include "dofpass.h"
|
2018-10-15 19:52:16 -04:00
|
|
|
|
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-17 09:28:47 -04:00
|
|
|
uint32_t numImages = 0, currentImage = 0;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-11-03 07:24:32 -04:00
|
|
|
// swapwchain
|
2018-10-17 09:28:47 -04:00
|
|
|
VkImage* swapchainImages = nullptr;
|
|
|
|
VkImageView* swapchainImageViews = nullptr;
|
|
|
|
VkFramebuffer* swapchainFramebuffers = nullptr;
|
|
|
|
|
2018-11-03 07:24:32 -04:00
|
|
|
// offscreen color
|
2018-10-24 19:20:23 -04:00
|
|
|
VkImage* offscreenColorImages = nullptr;
|
|
|
|
VkDeviceMemory* offscreenColorMemory = nullptr;
|
|
|
|
VkImageView* offscreenColorImageViews = nullptr;
|
2018-10-25 08:57:36 -04:00
|
|
|
|
2018-11-03 07:24:32 -04:00
|
|
|
// offscreen depth
|
2018-10-24 19:20:23 -04:00
|
|
|
VkImage* offscreenDepthImages = nullptr;
|
|
|
|
VkDeviceMemory* offscreenDepthMemory = nullptr;
|
|
|
|
VkImageView* offscreenDepthImageViews = nullptr;
|
2018-10-25 08:57:36 -04:00
|
|
|
|
2018-10-17 09:28:47 -04:00
|
|
|
VkFramebuffer* offscreenFramebuffers = nullptr;
|
2018-11-03 07:24:32 -04:00
|
|
|
|
|
|
|
// near field
|
|
|
|
VkImage* nearFieldImages = nullptr;
|
|
|
|
VkDeviceMemory* nearFieldMemory = nullptr;
|
|
|
|
VkImageView* nearFieldImageViews = nullptr;
|
|
|
|
|
|
|
|
VkFramebuffer* nearFieldFramebuffers = nullptr;
|
|
|
|
|
|
|
|
// far field
|
|
|
|
VkImage* farFieldImages = nullptr;
|
|
|
|
VkDeviceMemory* farFieldMemory = nullptr;
|
|
|
|
VkImageView* farFieldImageViews = nullptr;
|
|
|
|
|
|
|
|
VkFramebuffer* farFieldFramebuffers = 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-10-17 10:06:38 -04:00
|
|
|
|
|
|
|
VkDescriptorSet* postSets = nullptr;
|
2018-11-03 07:24:32 -04:00
|
|
|
VkDescriptorSet* dofSets = nullptr;
|
2018-09-29 21:03:06 -04:00
|
|
|
};
|
|
|
|
|
2018-10-16 08:49:25 -04:00
|
|
|
class World;
|
|
|
|
class Mesh;
|
2018-10-25 08:57:36 -04:00
|
|
|
class Camera;
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-09-27 20:09:42 -04:00
|
|
|
class Renderer {
|
|
|
|
public:
|
|
|
|
Renderer();
|
|
|
|
~Renderer();
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-25 08:57:36 -04:00
|
|
|
void render(World& world, Camera& camera, RenderTarget* target);
|
2018-10-16 08:49:25 -04:00
|
|
|
|
2018-10-26 20:56:06 -04:00
|
|
|
RenderTarget* createSurfaceRenderTarget(VkSurfaceKHR surface, RenderTarget* oldTarget = nullptr);
|
2018-09-29 21:03:06 -04:00
|
|
|
void destroyRenderTarget(RenderTarget* target);
|
2018-10-25 08:57:36 -04:00
|
|
|
|
2018-10-30 21:13:36 -04:00
|
|
|
void takeScreenshot(const char* path, 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
|
|
|
|
2018-10-26 20:56:06 -04:00
|
|
|
uint32_t findMemoryType(uint32_t typeFilter, VkMemoryPropertyFlags properties);
|
2018-10-16 08:49:25 -04:00
|
|
|
|
|
|
|
void fillMeshBuffers(Mesh* mesh);
|
2018-10-16 09:01:14 -04:00
|
|
|
void destroyMeshBuffers(Mesh* mesh);
|
2018-10-16 08:49:25 -04:00
|
|
|
|
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-11-03 07:24:32 -04:00
|
|
|
|
|
|
|
VkQueue getGraphicsQueue() const {
|
|
|
|
return graphicsQueue_;
|
|
|
|
}
|
|
|
|
|
|
|
|
VkCommandPool getCommandPool() const {
|
|
|
|
return commandPool_;
|
|
|
|
}
|
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-10-17 10:06:38 -04:00
|
|
|
VkDescriptorPool getDescriptorPool() const {
|
|
|
|
return descriptorPool_;
|
|
|
|
}
|
|
|
|
|
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-17 10:06:38 -04:00
|
|
|
void createDescriptorPool();
|
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-10-16 09:04:57 -04:00
|
|
|
VkPhysicalDeviceMemoryProperties deviceMemoryProperties_ = {};
|
|
|
|
|
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-17 10:06:38 -04:00
|
|
|
VkDescriptorPool descriptorPool_ = nullptr;
|
|
|
|
|
2018-10-15 19:52:16 -04:00
|
|
|
WorldPass* worldPass_ = nullptr;
|
2018-10-17 10:06:38 -04:00
|
|
|
PostPass* postPass_ = nullptr;
|
2018-11-03 07:24:32 -04:00
|
|
|
DoFPass* dofPass_ = nullptr;
|
2018-09-27 20:09:42 -04:00
|
|
|
};
|