VulkanWrapper.hpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef GAMINGCORE_VULKAN_WRAPPER_HPP
  2. #define GAMINGCORE_VULKAN_WRAPPER_HPP
  3. #include <core/List.hpp>
  4. #include <core/Meta.hpp>
  5. #include <core/Types.hpp>
  6. #include <vulkan/vulkan.h>
  7. #include "core/VulkanBase.hpp"
  8. namespace Core::Vulkan {
  9. bool init();
  10. void render();
  11. void destroy();
  12. template<typename T>
  13. struct BaseWrapper {
  14. VkDevice device = VK_NULL_HANDLE;
  15. T handle = VK_NULL_HANDLE;
  16. BaseWrapper() = default;
  17. BaseWrapper(const BaseWrapper&) = delete;
  18. BaseWrapper(BaseWrapper&& o) : BaseWrapper() {
  19. swap(o);
  20. }
  21. BaseWrapper& operator=(const BaseWrapper&) = delete;
  22. BaseWrapper& operator=(BaseWrapper&& o) {
  23. swap(o);
  24. o = BaseWrapper();
  25. }
  26. void swap(BaseWrapper& o) {
  27. Core::swap(device, o.device);
  28. Core::swap(handle, o.handle);
  29. }
  30. operator T() {
  31. return handle;
  32. }
  33. operator T*() {
  34. return &handle;
  35. }
  36. operator const T*() const {
  37. return &handle;
  38. }
  39. };
  40. struct ImageView : public BaseWrapper<VkImageView> {
  41. ImageView() = default;
  42. ImageView(ImageView&&) = default;
  43. ~ImageView();
  44. bool init(VkDevice d, VkImage image, VkFormat format);
  45. };
  46. struct Framebuffer : public BaseWrapper<VkFramebuffer> {
  47. Framebuffer() = default;
  48. Framebuffer(Framebuffer&&) = default;
  49. ~Framebuffer();
  50. bool init(const ImageView& iv, VkRenderPass rp, u32 width, u32 height);
  51. };
  52. struct Semaphore : public BaseWrapper<VkSemaphore> {
  53. Semaphore() = default;
  54. Semaphore(Semaphore&&) = default;
  55. ~Semaphore();
  56. bool init(VkDevice d);
  57. };
  58. struct Fence : public BaseWrapper<VkFence> {
  59. Fence() = default;
  60. Fence(Fence&&) = default;
  61. ~Fence();
  62. bool init(VkDevice d);
  63. };
  64. struct Swapchain : public BaseWrapper<VkSwapchainKHR> {
  65. Swapchain() = default;
  66. Swapchain(Swapchain&&) = default;
  67. ~Swapchain();
  68. struct Data {
  69. Base& base;
  70. VkExtent2D size{};
  71. VkSurfaceFormatKHR surfaceFormat{};
  72. VkPresentModeKHR presentMode{};
  73. VkSharingMode sharingMode{};
  74. List<u32> queueFamilies{};
  75. };
  76. bool init(Data& d);
  77. };
  78. struct ShaderModule : public BaseWrapper<VkShaderModule> {
  79. ShaderModule() = default;
  80. ShaderModule(ShaderModule&&) = default;
  81. ~ShaderModule();
  82. bool init(VkDevice d, const char* path);
  83. };
  84. struct PipelineLayout : public BaseWrapper<VkPipelineLayout> {
  85. PipelineLayout() = default;
  86. PipelineLayout(PipelineLayout&&) = default;
  87. ~PipelineLayout();
  88. bool init(VkDevice d);
  89. };
  90. struct SwapchainImages {
  91. List<VkImage> images{};
  92. List<ImageView> imageViews{};
  93. bool init(const Swapchain& s, VkFormat format);
  94. };
  95. struct CommandBuffer : public BaseWrapper<VkCommandBuffer> {
  96. CommandBuffer() = default;
  97. CommandBuffer(CommandBuffer&&) = default;
  98. bool init(VkDevice d, VkCommandPool cp);
  99. };
  100. }
  101. #endif