4#include <vulkan/vulkan.h>
31 const VkImage& operator+() const;
66 const
ImageView& operator[](std::
string tag) const;
86 template<std::same_as<VkMemoryPropertyFlagBits>... P>
87 Image(const
LogicalDevice&
virtualGpu, const
PhysicalDevice& realGpu, VkFormat
format, std::pair<
unsigned int,
unsigned int>
resolution, VkImageTiling tiling, VkImageUsageFlags usage, P... memoryProperties) :
virtualGpu{ &
virtualGpu },
format{
format },
isSwapchainImage{
false },
layout{ VK_IMAGE_LAYOUT_UNDEFINED },
resolution{
resolution }{
88 VkImageCreateInfo imageInfo{};
89 imageInfo.sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO;
90 imageInfo.imageType = VK_IMAGE_TYPE_2D;
93 imageInfo.extent.depth = 1;
94 imageInfo.mipLevels = 1;
95 imageInfo.arrayLayers = 1;
97 imageInfo.tiling = tiling;
98 imageInfo.initialLayout =
layout;
99 imageInfo.usage = usage;
100 imageInfo.samples = VK_SAMPLE_COUNT_1_BIT;
101 imageInfo.sharingMode = VK_SHARING_MODE_EXCLUSIVE;
103 if (VkResult result = vkCreateImage(+
virtualGpu, &imageInfo,
nullptr, &
image); result != VK_SUCCESS) {
104 throw VulkanException(
"Failed to create image!", result);
107 VkMemoryRequirements memRequirements;
110 VkMemoryAllocateInfo allocInfo{};
111 allocInfo.sType = VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO;
112 allocInfo.allocationSize = memRequirements.size;
116 throw VulkanException(
"Failed to allocate image memory!", result);
127 std::map<std::string, ImageView>
views;
static uint32_t findSuitableMemoryIndex(const PhysicalDevice &realGpu, uint32_t suitableTypesBitmask, P... requiredMemoryProperties)
Definition: Buffer.h:61
An Image is an object representing what can be passed to the swapchain: the content of the image is w...
Definition: Image.h:19
VkFormat getFormat() const
Returns the format of the image, which is the same format of all the images in the swapchain of this ...
Definition: Image.cpp:57
std::pair< unsigned int, unsigned int > resolution
Definition: Image.h:126
VkDeviceMemory allocatedMemory
Definition: Image.h:128
LogicalDevice const * virtualGpu
Definition: Image.h:129
Image & operator=(const Image &)=delete
friend void swap(Image &lhs, Image &rhs)
void eliminateImageView(std::string tag)
Eliminates the specified image view.
Definition: Image.cpp:75
bool isSwapchainImage
Definition: Image.h:130
VkFormat format
Definition: Image.h:124
const ImageView & generateImageView(std::string tag, const LogicalDevice &virtualGpu, VkImageAspectFlags type=VK_IMAGE_ASPECT_COLOR_BIT)
Creates a new image view for this image, and adds it to the array of image views of this image,...
Definition: Image.cpp:63
const std::map< std::string, ImageView > & getImageViews() const
Returns all the image views of this image.
Definition: Image.cpp:90
Image(const Image &)=delete
VkImage image
Definition: Image.h:123
std::map< std::string, ImageView > views
Definition: Image.h:127
Image()
Definition: Image.cpp:19
VkImageLayout layout
Definition: Image.h:125
Part of an image where we can actually draw.
Definition: ImageView.h:12
A logical device is an abstraction of the physical GPU which we can mainly use to send commands.
Definition: LogicalDevice.h:15
Represents the GPU (or any other device) that will be used with Vulkan to perform computer graphics.
Definition: PhysicalDevice.h:17
Types of queue families.
Definition: Animations.h:17