Polyphase Game Engine
Loading...
Searching...
No Matches
Image.h
Go to the documentation of this file.
1#pragma once
2
3#if API_VULKAN
4
6#include "Maths.h"
7
8#include <vulkan/vulkan.h>
9
10class DestroyQueue;
11
12struct ImageDesc
13{
14 uint32_t mWidth = 4;
15 uint32_t mHeight = 4;
16 VkFormat mFormat = VK_FORMAT_R8G8B8A8_UNORM;
17 VkImageUsageFlags mUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_SAMPLED_BIT;
18 uint32_t mMipLevels = 1;
19 uint32_t mLayers = 1;
20};
21
22struct SamplerDesc
23{
24 VkFilter mMagFilter = VK_FILTER_LINEAR;
25 VkFilter mMinFilter = VK_FILTER_LINEAR;
26 VkSamplerAddressMode mAddressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT;
27 VkBorderColor mBorderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
28 float mMaxAnisotropy = 1.0;
29 bool mAnisotropyEnable = false;
30};
31
32class Image
33{
34public:
35 Image(ImageDesc imageDesc, SamplerDesc samplerDesc, const char* debugObjectName);
36
37 // External image? Kind of a hack needed for using swapchain images with RenderPassCache
38 Image(VkImage image, VkImageView imageView, VkSampler sampler, VkFormat format, uint32_t width, uint32_t height);
39
40 VkImage Get() const;
41 VkImageView GetView() const;
42 VkSampler GetSampler() const;
43
44 VkFormat GetFormat() const;
45 uint32_t GetWidth() const;
46 uint32_t GetHeight() const;
47
48 void Update(const void* srcData);
49
50 void Transition(VkImageLayout layout, VkCommandBuffer commandBuffer = VK_NULL_HANDLE);
51 void GenerateMips();
52 void Clear(glm::vec4 color);
53
54 uint64_t GetId() const;
55
56private:
57
58 friend class DestroyQueue;
59 ~Image();
60
61 uint64_t mId = 0;
62 VkImage mImage = VK_NULL_HANDLE;
63 VkImageView mImageView = VK_NULL_HANDLE;
64 VkSampler mSampler = VK_NULL_HANDLE;
65 VramAllocation mMemory;
66
67 uint32_t mWidth = 0;
68 uint32_t mHeight = 0;
69 VkFormat mFormat = VK_FORMAT_UNDEFINED;
70 VkImageUsageFlags mUsage = {};
71 uint32_t mMipLevels = 0;
72 uint32_t mLayers = 0;
73
74 VkFilter mMagFilter = VK_FILTER_LINEAR;
75 VkFilter mMinFilter = VK_FILTER_LINEAR;
76 VkSamplerAddressMode mAddressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT;
77 VkBorderColor mBorderColor = VK_BORDER_COLOR_FLOAT_OPAQUE_BLACK;
78 float mMaxAnisotropy = 1.0;
79 bool mAnisotropyEnable = false;
80
81 VkImageLayout mLayout = VK_IMAGE_LAYOUT_PREINITIALIZED;
82
83 bool mExternal = false;
84};
85
86#endif
bool Update()
Definition Engine.cpp:710