HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RV_VKSwapchain.h
Go to the documentation of this file.
1 /*
2  * PROPRIETARY INFORMATION. This software is proprietary to
3  * Side Effects Software Inc., and is not to be reproduced,
4  * transmitted, or disclosed in any way without written permission.
5  *
6  * NAME: RV_VKSwapchain.h ( RV Library, C++)
7  *
8  * COMMENTS:
9  * Class to manage Vulkan swapchain object
10  */
11 #ifndef RV_VKSwapchain_h
12 #define RV_VKSwapchain_h
13 
14 #include <VE/VE_VK.h>
15 
16 #ifdef VULKAN_PRESENTATION
17 
18 #include "RV_API.h"
19 #include "RV_TypePtrs.h"
20 
21 #include <VE/VE_VK.h>
22 
23 #include <UT/UT_Array.h>
24 #include <UT/UT_UniquePtr.h>
25 
26 class RV_VKSurface;
27 class RV_Render;
28 
29 class RV_API RV_VKSwapchainCreateInfo
30 {
31 public:
32  exint getWidth() const
33  { return myVkCreateInfo.imageExtent.width; }
34  exint getHeight() const
35  { return myVkCreateInfo.imageExtent.height; }
36  VkFormat getImageFormat() const
37  { return myVkCreateInfo.imageFormat; }
38 
39  void setSurface(RV_VKSurface* surface);
40  void setMinImgCount(exint img_count);
41  void setFormat(VkSurfaceFormatKHR surface_format);
42  void setSize(exint width, exint height);
43  void setQueueFamilies(const UT_Array<uint32_t>* queue_family_indices);
44  void setPresentMode(VkPresentModeKHR mode);
45  void setOldSwapchain(RV_VKSwapchain* old_sc);
46  void setUsage(VkImageUsageFlags usage)
47  { myVkCreateInfo.imageUsage = usage; }
48  void setPreTransform(VkSurfaceTransformFlagBitsKHR transform)
49  { myVkCreateInfo.preTransform = transform; }
50  void setClipped(bool clipped)
51  { myVkCreateInfo.clipped = clipped; }
52 
53  RV_VKSwapchainCreateInfo() = default;
55  {
57  new RV_VKSwapchainCreateInfo(*this));
58  }
59 
60 protected:
61  VkSwapchainCreateInfoKHR myVkCreateInfo = {
63  nullptr,
64  0, /* flags */
65  VK_NULL_HANDLE, /* surface */
66  2, /* minImageCount */
67  VK_FORMAT_B8G8R8A8_SRGB, /* imageFormat */
68  VK_COLOR_SPACE_SRGB_NONLINEAR_KHR, /* imageColorSpace */
69  { 0, 0 }, /* imageExtent */
70  1, /* imageArrayLayers */
71  VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, /* imageUsage */
72  VK_SHARING_MODE_EXCLUSIVE, /* imageSharingMode */
73  0, /* queueFamilyIndexCount */
74  nullptr, /* pQueueFamilyIndices */
75  VK_SURFACE_TRANSFORM_IDENTITY_BIT_KHR, /* preTransform */
76  VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR, /* compositeAlpha */
77  VK_PRESENT_MODE_MAILBOX_KHR, /* presentMode */
78  VK_TRUE, /* clipped */
79  VK_NULL_HANDLE /* oldSwapchain */
80  };
81 
82  RV_VKSurface* mySurface;
83 
84  RV_VKSwapchainCreateInfo(const RV_VKSwapchainCreateInfo&) = default;
85  RV_VKSwapchainCreateInfo &operator=(const RV_VKSwapchainCreateInfo&) = delete;
86 
87  friend class RV_VKSwapchain;
88 };
89 
90 class RV_API RV_VKSwapchain
91 {
92 public:
93  static RV_VKSwapchainPtr create(
94  RV_Instance* inst,
95  const RV_VKSwapchainCreateInfo* info);
96 
97  RV_VKSwapchain(
98  RV_Instance* inst,
99  const RV_VKSwapchainCreateInfo* info,
100  VkSwapchainKHR vk_sc);
101 
102  ~RV_VKSwapchain();
103 
104  void initialize(RV_Render* r);
105  bool isInitialized() const
106  { return myImageCount; }
107 
108  void nextImage();
109  void prepareForPresent(RV_Render* r);
110 
111  VkSwapchainKHR getVkSwapchain() const
112  { return myVkSwapchain; }
113  uint32_t getCurrentImageIndex() const
114  { return myImageIndex; }
115  RV_VKImage* getCurrentImage() const
116  { return myImages(myImageIndex).get(); }
117  RV_Framebuffer* getCurrentFramebuffer() const
118  { return myFramebuffers(myImageIndex).get(); }
119  VkSemaphore getCurrentImageAcquiredSem() const
120  { return myImageAcquiredSems(myFrameIndex); }
121  VkSemaphore getCurrentPresentReadySem() const
122  { return myPresentReadySems(myFrameIndex); }
123 
124  UT_NON_COPYABLE(RV_VKSwapchain);
125 
126 private:
127  RV_Instance* myInst;
128  VkSwapchainKHR myVkSwapchain;
130 
131  UT_Array<RV_VKImagePtr> myImages;
132  UT_Array<RV_VKFramebufferPtr> myFramebuffers;
133  UT_Array<VkSemaphore> myImageAcquiredSems;
134  UT_Array<VkSemaphore> myPresentReadySems;
135  uint32_t myImageCount = 0;
136  uint32_t myFrameIndex = 0;
137  uint32_t myImageIndex = 0;
138 };
139 
140 #endif // VULKAN_PRESENTATION
141 
142 #endif
#define VK_NULL_HANDLE
Definition: vulkan_core.h:45
#define VK_TRUE
Definition: vulkan_core.h:130
int64 exint
Definition: SYS_Types.h:125
VkPresentModeKHR
Definition: vulkan_core.h:7517
VkFlags VkImageUsageFlags
Definition: vulkan_core.h:2311
std::unique_ptr< T, Deleter > UT_UniquePtr
A smart pointer for unique ownership of dynamically allocated objects.
Definition: UT_UniquePtr.h:39
GLint GLsizei GLsizei height
Definition: glcorearb.h:103
#define UT_NON_COPYABLE(CLASS)
Define deleted copy constructor and assignment operator inside a class.
#define RV_API
Definition: RV_API.h:10
OPENVDB_API void initialize()
Global registration of native Grid, Transform, Metadata and Point attribute types. Also initializes blosc (if enabled).
Definition: logging.h:294
GA_API const UT_StringHolder transform
Handle to the main interface of Vulkan.
Definition: RV_Instance.h:44
GLenum mode
Definition: glcorearb.h:99
GLsizeiptr const void GLenum usage
Definition: glcorearb.h:664
LeafData & operator=(const LeafData &)=delete
VkFormat
Definition: vulkan_core.h:1386
GLint GLsizei width
Definition: glcorearb.h:103
GLboolean r
Definition: glcorearb.h:1222
VkSurfaceTransformFlagBitsKHR
Definition: vulkan_core.h:7549