PixelBullet  0.0.1
A C++ game engine
Loading...
Searching...
No Matches
Image2D.hpp
1#pragma once
2
3#include "PixelBullet/Filesystem/Resources/Resource.hpp"
4#include "PixelBullet/Filesystem/VirtualPath.hpp"
5#include "PixelBullet/Graphics/Images/Image.hpp"
6
7#include <filesystem>
8#include <typeindex>
9
10namespace PixelBullet
11{
12 class Node;
13
17 class Image2D : public Image, public Resource
18 {
19 public:
25 static std::shared_ptr<Image2D> Create(const Node& node);
26
36 static std::shared_ptr<Image2D> Create(const VirtualPath& filename, VkFilter filter = VK_FILTER_LINEAR,
37 VkSamplerAddressMode addressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT,
38 bool anisotropic = true, bool mipmap = true);
39
49 explicit Image2D(const VirtualPath& filename, VkFilter filter = VK_FILTER_LINEAR,
50 VkSamplerAddressMode addressMode = VK_SAMPLER_ADDRESS_MODE_REPEAT, bool anisotropic = true,
51 bool mipmap = true, bool load = true);
52
65 explicit Image2D(const glm::uvec2& extent, VkFormat format = VK_FORMAT_R8G8B8A8_UNORM,
66 VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
67 VkImageUsageFlags usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_STORAGE_BIT,
68 VkFilter filter = VK_FILTER_LINEAR,
69 VkSamplerAddressMode addressMode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
70 VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT, bool anisotropic = false,
71 bool mipmap = false);
72
85 explicit Image2D(std::unique_ptr<Bitmap>&& bitmap, VkFormat format = VK_FORMAT_R8G8B8A8_UNORM,
86 VkImageLayout layout = VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
87 VkImageUsageFlags usage = VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT | VK_IMAGE_USAGE_STORAGE_BIT,
88 VkFilter filter = VK_FILTER_LINEAR,
89 VkSamplerAddressMode addressMode = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE,
90 VkSampleCountFlagBits samples = VK_SAMPLE_COUNT_1_BIT, bool anisotropic = false,
91 bool mipmap = false);
92
99 void SetPixels(const uint8_t* pixels, uint32_t layerCount, uint32_t baseArrayLayer);
100
101 std::type_index GetTypeIndex() const override
102 {
103 return typeid(Image2D);
104 }
105
106 const VirtualPath& GetFilename() const
107 {
108 return m_Filename;
109 }
110 bool IsAnisotropic() const
111 {
112 return m_Anisotropic;
113 }
114 bool IsMipmap() const
115 {
116 return m_Mipmap;
117 }
118 uint32_t GetComponents() const
119 {
120 return m_Components;
121 }
122
123 friend const Node& operator>>(const Node& node, Image2D& image);
124 friend Node& operator<<(Node& node, const Image2D& image);
125
126 private:
127 void Load(std::unique_ptr<Bitmap> loadBitmap = nullptr);
128
129 private:
130 VirtualPath m_Filename;
131
132 bool m_Anisotropic;
133 bool m_Mipmap;
134 uint32_t m_Components = 0;
135 };
136} // namespace PixelBullet
Resource that represents a 2D image.
Definition Image2D.hpp:18
Image2D(const VirtualPath &filename, VkFilter filter=VK_FILTER_LINEAR, VkSamplerAddressMode addressMode=VK_SAMPLER_ADDRESS_MODE_REPEAT, bool anisotropic=true, bool mipmap=true, bool load=true)
Definition Image2D.cpp:38
std::type_index GetTypeIndex() const override
Returns the type index of the resource.
Definition Image2D.hpp:101
static std::shared_ptr< Image2D > Create(const Node &node)
Definition Image2D.cpp:14
void SetPixels(const uint8_t *pixels, uint32_t layerCount, uint32_t baseArrayLayer)
Definition Image2D.cpp:81
A representation of a Vulkan image, sampler, and view.
Definition Image.hpp:18
Represents a hierarchical node capable of storing various data types and supporting YAML serializatio...
Definition Node.hpp:51
Base class for managed resources.
Definition Resource.hpp:11
Definition VirtualPath.hpp:11