VulkanWrapper.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #ifndef GAMINGCORE_VULKAN_WRAPPER_HPP
  2. #define GAMINGCORE_VULKAN_WRAPPER_HPP
  3. #include <core/Meta.hpp>
  4. #include <vulkan/vulkan.h>
  5. namespace Core::Vulkan {
  6. bool init();
  7. void render();
  8. void destroy();
  9. template<typename T>
  10. struct BaseWrapper {
  11. VkDevice device = VK_NULL_HANDLE;
  12. T handle = VK_NULL_HANDLE;
  13. BaseWrapper() = default;
  14. BaseWrapper(const BaseWrapper&) = delete;
  15. BaseWrapper(BaseWrapper&& o) : BaseWrapper() {
  16. swap(o);
  17. }
  18. BaseWrapper& operator=(const BaseWrapper&) = delete;
  19. BaseWrapper& operator=(BaseWrapper&& o) {
  20. swap(o);
  21. o = BaseWrapper();
  22. }
  23. void swap(BaseWrapper& o) {
  24. Core::swap(device, o.device);
  25. Core::swap(handle, o.handle);
  26. }
  27. operator T() {
  28. return handle;
  29. }
  30. operator T*() {
  31. return &handle;
  32. }
  33. operator const T*() const {
  34. return &handle;
  35. }
  36. };
  37. struct ImageView : public BaseWrapper<VkImageView> {
  38. ImageView() = default;
  39. ImageView(ImageView&&) = default;
  40. ~ImageView();
  41. };
  42. struct Framebuffer : public BaseWrapper<VkFramebuffer> {
  43. Framebuffer() = default;
  44. Framebuffer(Framebuffer&&) = default;
  45. ~Framebuffer();
  46. };
  47. struct Semaphore : public BaseWrapper<VkSemaphore> {
  48. Semaphore() = default;
  49. Semaphore(Semaphore&&) = default;
  50. ~Semaphore();
  51. bool init(VkDevice d);
  52. };
  53. struct Fence : public BaseWrapper<VkFence> {
  54. Fence() = default;
  55. Fence(Fence&&) = default;
  56. ~Fence();
  57. bool init(VkDevice d);
  58. };
  59. struct Swapchain : public BaseWrapper<VkSwapchainKHR> {
  60. Swapchain() = default;
  61. Swapchain(Swapchain&&) = default;
  62. ~Swapchain();
  63. };
  64. struct ShaderModule : public BaseWrapper<VkShaderModule> {
  65. ShaderModule() = default;
  66. ShaderModule(ShaderModule&&) = default;
  67. ~ShaderModule();
  68. bool init(VkDevice d, const char* path);
  69. };
  70. struct PipelineLayout : public BaseWrapper<VkPipelineLayout> {
  71. PipelineLayout() = default;
  72. PipelineLayout(PipelineLayout&&) = default;
  73. ~PipelineLayout();
  74. bool init(VkDevice d);
  75. };
  76. }
  77. #endif