vsg  1.1.0
VulkanSceneGraph library
ImageView.h
1 #pragma once
2 
3 /* <editor-fold desc="MIT License">
4 
5 Copyright(c) 2018 Robert Osfield
6 
7 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 
9 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10 
11 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12 
13 </editor-fold> */
14 
15 #include <vsg/state/Image.h>
16 
17 namespace vsg
18 {
19  class Context;
20 
21  extern VSG_DECLSPEC VkImageAspectFlags computeAspectFlagsForFormat(VkFormat format);
22 
24  class VSG_DECLSPEC ImageView : public Inherit<Object, ImageView>
25  {
26  public:
27  ImageView(ref_ptr<Image> in_image = {});
28  ImageView(ref_ptr<Image> in_image, VkImageAspectFlags aspectFlags);
29 
31  VkImageViewCreateFlags flags = 0;
32  ref_ptr<Image> image;
33  VkImageViewType viewType = VK_IMAGE_VIEW_TYPE_2D;
34  VkFormat format = VK_FORMAT_UNDEFINED;
35  VkComponentMapping components = {VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY, VK_COMPONENT_SWIZZLE_IDENTITY};
36  VkImageSubresourceRange subresourceRange;
37 
39  VkImageView vk(uint32_t deviceID) const { return _vulkanData[deviceID].imageView; }
40 
41  int compare(const Object& rhs_object) const override;
42 
43  virtual void compile(Device* device);
44  virtual void compile(Context& context);
45 
46  protected:
47  virtual ~ImageView();
48 
49  struct VulkanData
50  {
51  VkImageView imageView = VK_NULL_HANDLE;
52  ref_ptr<Device> device;
53 
54  ~VulkanData() { release(); }
55  void release();
56  };
57 
58  vk_buffer<VulkanData> _vulkanData;
59  };
60  VSG_type_name(vsg::ImageView);
61 
62  using ImageViews = std::vector<ref_ptr<ImageView>>;
63 
65  extern VSG_DECLSPEC ref_ptr<ImageView> createImageView(Context& context, ref_ptr<Image> image, VkImageAspectFlags aspectFlags);
66 
68  extern VSG_DECLSPEC ref_ptr<ImageView> createImageView(Device* device, ref_ptr<Image> image, VkImageAspectFlags aspectFlags);
69 
71  extern VSG_DECLSPEC void transferImageData(ref_ptr<ImageView> imageView, VkImageLayout targetImageLayout, Data::Properties properties, uint32_t width, uint32_t height, uint32_t depth, uint32_t mipLevels, const Data::MipmapOffsets& mipmapOffsets, ref_ptr<Buffer> stagingBuffer, VkDeviceSize stagingBufferOffset, VkCommandBuffer vk_commandBuffer, vsg::Device* device);
72 
73 } // namespace vsg
Definition: Context.h:67
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition: Device.h:37
ImageView class encapsulates VkImageView and VkImageViewCreateInfo settings used to set it up.
Definition: ImageView.h:25
VkImageView vk(uint32_t deviceID) const
Vulkan VkImageView handle.
Definition: ImageView.h:39
int compare(const Object &rhs_object) const override
compare two objects, return -1 if this object is less than rhs, return 0 if it's equal,...
Definition: Inherit.h:28
Definition: Object.h:42
Definition: ref_ptr.h:22
Definition: Data.h:116
Definition: ImageView.h:50
vk_buffer that manages a single logical device supported.
Definition: vk_buffer.h:28