Archived
1
Fork 0
This repository has been archived on 2025-04-12. You can view files and clone it, but cannot push or open issues or pull requests.
graph/include/renderer.h

197 lines
4.8 KiB
C
Raw Normal View History

#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-11-05 20:51:23 -05:00
#include "imguipass.h"
2018-11-07 07:20:52 -05:00
#include "skypass.h"
2018-11-08 08:57:41 -05:00
#include "shadowpass.h"
2018-10-15 19:52:16 -04:00
constexpr int numFrameResources = 2;
2018-09-29 21:03:06 -04:00
struct RenderTarget {
VkSurfaceKHR surface = nullptr;
VkSwapchainKHR swapchain = nullptr;
2018-10-16 08:49:25 -04:00
VkExtent2D extent = {};
uint32_t numImages = 0, imageIndex = 0, currentResource = 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-06 09:08:55 -05:00
2018-11-03 07:24:32 -04:00
// near field
VkImage* nearFieldImages = nullptr;
VkDeviceMemory* nearFieldMemory = nullptr;
VkImageView* nearFieldImageViews = nullptr;
2018-11-06 09:08:55 -05:00
2018-11-03 07:24:32 -04:00
VkFramebuffer* nearFieldFramebuffers = nullptr;
2018-11-06 09:08:55 -05:00
2018-11-03 07:24:32 -04:00
// far field
VkImage* farFieldImages = nullptr;
VkDeviceMemory* farFieldMemory = nullptr;
VkImageView* farFieldImageViews = nullptr;
2018-11-06 09:08:55 -05:00
2018-11-03 07:24:32 -04:00
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-11-06 09:08:55 -05:00
2018-11-05 20:51:23 -05:00
// imgui
VkBuffer* imguiVertexBuffers = nullptr;
VkDeviceMemory* imguiVertexMemorys = nullptr;
size_t* imguiVertexBufferSizes = nullptr;
2018-11-06 09:08:55 -05:00
2018-11-05 20:51:23 -05:00
VkBuffer* imguiIndexBuffers = nullptr;
VkDeviceMemory* imguiIndexMemorys = nullptr;
size_t* imguiIndexBufferSizes = 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-11-08 12:51:32 -05:00
struct GraphicsConfig {
int shadowResolution, dofDownscale;
bool vsync = true, filterPCF;
2018-11-08 12:51:32 -05:00
};
2018-10-16 08:49:25 -04:00
class World;
class Mesh;
2018-10-25 08:57:36 -04:00
class Camera;
2018-11-06 09:08:55 -05:00
class Material;
2018-10-16 08:49:25 -04:00
class Renderer {
public:
2018-11-08 12:51:32 -05:00
Renderer(GraphicsConfig config);
~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-11-05 20:51:23 -05:00
void uploadImageData(VkImage image, int width, int height, VkDeviceSize size, void* src);
2018-11-06 09:08:55 -05: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-11-06 09:08:55 -05:00
void fillMaterialBuffers(Material* material);
void destroyMaterialBuffers(Material* material);
2018-11-08 12:51:32 -05:00
GraphicsConfig getConfig() const {
return config_;
}
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-06 09:08:55 -05:00
2018-11-03 07:24:32 -04:00
VkQueue getGraphicsQueue() const {
return graphicsQueue_;
}
2018-11-06 09:08:55 -05:00
2018-11-03 07:24:32 -04:00
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-11-06 09:08:55 -05:00
VkDescriptorSetLayout getMaterialSetLayout() const {
return materialSetLayout_;
}
2018-11-07 07:20:52 -05:00
WorldPass& getWorldPass() const {
return *worldPass_;
}
2018-11-08 08:57:41 -05:00
ShadowPass& getShadowPass() const {
return *shadowPass_;
}
private:
2018-09-27 20:33:45 -04:00
void createInstance();
#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();
void createPresentationRenderPass();
2018-10-17 10:06:38 -04:00
void createDescriptorPool();
2018-11-06 09:08:55 -05:00
void createMaterialSetLayout();
2018-10-16 08:49:25 -04:00
2018-11-08 12:51:32 -05:00
GraphicsConfig config_;
VkInstance instance_ = nullptr;
2018-10-16 08:49:25 -04:00
#ifdef DEBUG
bool enableDebug = false;
2018-10-16 08:49:25 -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
VkDebugUtilsMessengerEXT messenger_ = nullptr;
#endif
2018-10-16 08:49:25 -04:00
2018-09-29 21:03:06 -04:00
VkPhysicalDevice physicalDevice_ = nullptr;
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
VkRenderPass presentationRenderPass_ = nullptr;
2018-10-16 08:49:25 -04:00
2018-10-17 10:06:38 -04:00
VkDescriptorPool descriptorPool_ = nullptr;
2018-11-06 09:08:55 -05:00
VkDescriptorSetLayout materialSetLayout_ = 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-11-11 05:41:03 -05:00
#ifdef DEBUG
2018-11-05 20:51:23 -05:00
ImGuiPass* imguiPass_ = nullptr;
2018-11-11 05:41:03 -05:00
#endif
2018-11-07 07:20:52 -05:00
SkyPass* skyPass_ = nullptr;
2018-11-08 08:57:41 -05:00
ShadowPass* shadowPass_ = nullptr;
};