vsg: include/vsg/state/ImageInfo.h Source File

vsg 1.1.13 VulkanSceneGraph library

Loading...
Searching...
No Matches
ImageInfo.h
1#pragma once
2
3/* <editor-fold desc="MIT License">
4
5Copyright(c) 2018 Robert Osfield
6
7Permission 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
9The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
11THE 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/ImageView.h>
16#include <vsg/state/Sampler.h>
17
18namespace vsg
19{
20
22 class VSG_DECLSPEC ImageInfo : public Inherit<Object, ImageInfo>
23 {
24 public:
25 ImageInfo() :
26 imageLayout(VK_IMAGE_LAYOUT_UNDEFINED) {}
27
28 ImageInfo(ref_ptr<Sampler> in_sampler, ref_ptr<ImageView> in_imageView, VkImageLayout in_imageLayout = VK_IMAGE_LAYOUT_UNDEFINED);
29
30 // Convenience constructor that creates a vsg::ImageView and vsg::Image to represent the data on the GPU.
31 template<typename T>
32 ImageInfo(ref_ptr<Sampler> in_sampler, ref_ptr<T> in_data, VkImageLayout in_imageLayout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) :
33 ImageInfo(in_sampler, ImageView::create(Image::create(in_data)), in_imageLayout)
34 {
35 }
36
37 ImageInfo(const ImageInfo&) = delete;
38 ImageInfo& operator=(const ImageInfo&) = delete;
39
40 explicit operator bool() const { return sampler.valid() && imageView.valid(); }
41
42 int compare(const Object& rhs_object) const override;
43
44 void computeNumMipMapLevels();
45
46 ref_ptr<Sampler> sampler;
47 ref_ptr<ImageView> imageView;
48 VkImageLayout imageLayout = VK_IMAGE_LAYOUT_UNDEFINED;
49
51 bool requiresCopy(uint32_t deviceID) const
52 {
53 if (!imageView || !imageView->image) return false;
54 auto& data = imageView->image->data;
55 return data && data->differentModifiedCount(copiedModifiedCounts[deviceID]);
56 }
57
59 bool syncModifiedCounts(uint32_t deviceID)
60 {
61 if (!imageView || !imageView->image) return false;
62 auto& data = imageView->image->data;
63 return data && data->getModifiedCount(copiedModifiedCounts[deviceID]);
64 }
65
66 vk_buffer<ModifiedCount> copiedModifiedCounts;
67
68 protected:
69 virtual ~ImageInfo();
70 };
71 VSG_type_name(vsg::ImageInfo);
72
73 using ImageInfoList = std::vector<ref_ptr<ImageInfo>>;
74
76 struct FormatTraits
77 {
78 int size = 0;
79 int numBitsPerComponent = 0;
80 int numComponents = 0;
81 bool packed = false;
82 int blockWidth = 1;
83 int blockHeight = 1;
84 int blockDepth = 1;
85 uint8_t defaultValue[32];
86
87 template<typename T>
88 void assign4(T value)
89 {
90 T* ptr = reinterpret_cast<T*>(defaultValue);
91 (*ptr++) = value;
92 (*ptr++) = value;
93 (*ptr++) = value;
94 (*ptr++) = value;
95 }
96 };
97
99 extern VSG_DECLSPEC FormatTraits getFormatTraits(VkFormat format, bool default_one = true);
100
102 extern VSG_DECLSPEC uint32_t computeNumMipMapLevels(const Data* data, const Sampler* sampler);
103
104} // namespace vsg
vsg::Data
Definition Data.h:115
vsg::ImageInfo
ImageInfo class provides the VkDescriptorImageInfo settings used when setting up vsg::/vkDescriptorIm...
Definition ImageInfo.h:23
vsg::ImageInfo::compare
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,...
vsg::ImageInfo::syncModifiedCounts
bool syncModifiedCounts(uint32_t deviceID)
return true if the ImageInfo's data has been modified and should be copied to the buffer,...
Definition ImageInfo.h:59
vsg::ImageInfo::requiresCopy
bool requiresCopy(uint32_t deviceID) const
return true if the ImageInfo's data has been modified and should be copied to the buffer
Definition ImageInfo.h:51
vsg::Object
Definition Object.h:60
vsg::Sampler
Sampler encapsulates the VkSampler and the VkSamplerCreateInfo settings used to set it up.
Definition Sampler.h:25
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::FormatTraits
format traits hints that can be used when initializing image data
Definition ImageInfo.h:77
vsg::vk_buffer
vk_buffer that manages a single logical device supported.
Definition vk_buffer.h:29