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

vsg 1.1.13 VulkanSceneGraph library

Loading...
Searching...
No Matches
Image.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/vk/DeviceMemory.h>
16#include <vsg/vk/vk_buffer.h>
17
18namespace vsg
19{
20 // forward declare
21 class Context;
22
24 class VSG_DECLSPEC Image : public Inherit<Object, Image>
25 {
26 public:
28 explicit Image(ref_ptr<Data> in_data = {});
29
31 Image(VkImage image, Device* device);
32
34 VkImage vk(uint32_t deviceID) const { return _vulkanData[deviceID].image; }
35
37 ref_ptr<Data> data;
38 VkImageCreateFlags flags = 0;
39 VkImageType imageType = VK_IMAGE_TYPE_2D;
40 VkFormat format = VK_FORMAT_UNDEFINED;
41 VkExtent3D extent = {0, 0, 0};
42 uint32_t mipLevels = 0;
43 uint32_t arrayLayers = 0;
44 VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT;
45 VkImageTiling tiling = VK_IMAGE_TILING_OPTIMAL;
46 VkImageUsageFlags usage = 0;
47 VkSharingMode sharingMode = VK_SHARING_MODE_EXCLUSIVE;
48 std::vector<uint32_t> queueFamilyIndices;
49 VkImageLayout initialLayout = VK_IMAGE_LAYOUT_UNDEFINED;
50
51 int compare(const Object& rhs_object) const override;
52
53 DeviceMemory* getDeviceMemory(uint32_t deviceID) { return _vulkanData[deviceID].deviceMemory; }
54 const DeviceMemory* getDeviceMemory(uint32_t deviceID) const { return _vulkanData[deviceID].deviceMemory; }
55
56 VkDeviceSize getMemoryOffset(uint32_t deviceID) const { return _vulkanData[deviceID].memoryOffset; }
57
58 VkMemoryRequirements getMemoryRequirements(uint32_t deviceID) const;
59
60 VkResult allocateAndBindMemory(Device* device, VkMemoryPropertyFlags memoryProperties = VK_MEMORY_PROPERTY_DEVICE_LOCAL_BIT, void* pNextAllocInfo = nullptr);
61
62 VkResult bind(DeviceMemory* deviceMemory, VkDeviceSize memoryOffset);
63
65 bool requiresCopy(uint32_t deviceID) const { return data && data->differentModifiedCount(_vulkanData[deviceID].copiedModifiedCount); }
66
68 bool syncModifiedCount(uint32_t deviceID) { return data && data->getModifiedCount(_vulkanData[deviceID].copiedModifiedCount); }
69
70 virtual void compile(Device* device);
71 virtual void compile(Context& context);
72
73 protected:
74 virtual ~Image();
75
76 struct VulkanData
77 {
78 VkImage image = VK_NULL_HANDLE;
79 ref_ptr<DeviceMemory> deviceMemory;
80 VkDeviceSize memoryOffset = 0;
81 VkDeviceSize size = 0;
82 ref_ptr<Device> device;
83 bool requiresDataCopy = false;
84 ModifiedCount copiedModifiedCount;
85
86 void release();
87 };
88
89 vk_buffer<VulkanData> _vulkanData;
90 };
91 VSG_type_name(vsg::Image);
92
93} // namespace vsg
vsg::Context
Definition Context.h:67
vsg::Device
Device encapsulates VkDevice, a logical handle to the PhysicalDevice with capabilities specified duri...
Definition Device.h:39
vsg::DeviceMemory
Definition DeviceMemory.h:29
vsg::Image
Image class encapsulates VkImage and VkImageCreateInfo settings used to set it up.
Definition Image.h:25
vsg::Image::Image
Image(VkImage image, Device *device)
create a vsg::Image wrapper for specified VkImage
vsg::Image::vk
VkImage vk(uint32_t deviceID) const
Vulkan VkImage handle.
Definition Image.h:34
vsg::Image::requiresCopy
bool requiresCopy(uint32_t deviceID) const
return true if the Image's data has been modified and should be copied to the buffer.
Definition Image.h:65
vsg::Image::data
ref_ptr< Data > data
VkImageCreateInfo settings.
Definition Image.h:37
vsg::Image::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::Image::syncModifiedCount
bool syncModifiedCount(uint32_t deviceID)
return true if the Image's data has been modified and should be copied to the buffer,...
Definition Image.h:68
vsg::Image::Image
Image(ref_ptr< Data > in_data={})
create a vsg::Image, optional Data is used to initialize createInfo, delay VkImage creation to compil...
vsg::Object
Definition Object.h:60
vsg::ref_ptr
Definition ref_ptr.h:22
vsg::Image::VulkanData
Definition Image.h:77
vsg::ModifiedCount
ModifiedCount provides a count value to keep track of modifications to data.
Definition Data.h:32
vsg::vk_buffer
vk_buffer that manages a single logical device supported.
Definition vk_buffer.h:29