35#ifndef TextureManager_h
36#define TextureManager_h
51 const vk::raii::Device& device,
52 const vk::ImageCreateInfo& imageInfo,
53 const vk::raii::Buffer& srcBuf,
57 const std::string& name =
"",
58 bool upsampleLinear =
true
62 const vk::raii::Device& device,
63 const vk::ImageCreateInfo& imageInfo,
65 const std::string& name =
""
70 ImTextureID GetTexture()
73 vk::ImageView GetView()
79 void SetName(
const std::string& name);
82 void LayoutTransition(
83 vk::raii::CommandBuffer& cmdBuf,
93 std::unique_ptr<vk::raii::ImageView>
m_view;
95 ImTextureID m_texture;
111 const std::string& name,
112 const std::string& path);
116 ImTextureID GetTexture(
const std::string& name)
118 auto it = m_textures.find(name);
119 if(it == m_textures.end())
122 "Texture \"%s\" not found. This is probably the result of a developer mistyping a texture ID.\n",
126 return it->second->GetTexture();
129 std::unique_ptr<vk::raii::Sampler>& GetSampler()
132 std::unique_ptr<vk::raii::Sampler>& GetNearestSampler()
133 {
return m_nearestSampler; }
136 { m_textures.clear(); }
138 vk::raii::CommandBuffer& GetCmdBuffer()
139 {
return *m_cmdBuf; }
141 std::shared_ptr<QueueHandle> GetQueue()
144 vk::ImageView GetView(
const std::string& name)
145 {
return m_textures[name]->GetView(); }
150 const std::string& path,
157 std::map<std::string, std::shared_ptr<Texture> > m_textures;
162 std::unique_ptr<vk::raii::Sampler> m_nearestSampler;
164 std::shared_ptr<QueueHandle> m_queue;
165 std::unique_ptr<vk::raii::CommandPool> m_cmdPool;
166 std::unique_ptr<vk::raii::CommandBuffer> m_cmdBuf;
Manages loading and saving texture resources to files.
Definition: TextureManager.h:105
png_structp LoadPNG(const std::string &path, size_t &width, size_t &height, FILE *&fp, png_infop &info, png_infop &end)
Helper function to initialize libpng and get header info.
Definition: TextureManager.cpp:343
std::unique_ptr< vk::raii::Sampler > m_sampler
Sampler for textures.
Definition: TextureManager.h:160
void LoadTexture(const std::string &name, const std::string &path)
Loads a texture from a file into a named resource.
Definition: TextureManager.cpp:467
GLFWimage LoadPNGToGLFWImage(const std::string &path)
Loads a PNG to a GLFWimage.
Definition: TextureManager.cpp:427
Encapsulates the various Vulkan objects we need to represent texture image memory.
Definition: TextureManager.h:48
Texture(const vk::raii::Device &device, const vk::ImageCreateInfo &imageInfo, const vk::raii::Buffer &srcBuf, int width, int height, TextureManager *mgr, const std::string &name="", bool upsampleLinear=true)
Creates a texture from an externally supplied staging buffer.
Definition: TextureManager.cpp:47
std::unique_ptr< vk::raii::ImageView > m_view
View of the image.
Definition: TextureManager.h:93
std::unique_ptr< vk::raii::DeviceMemory > m_deviceMemory
Device memory backing the image.
Definition: TextureManager.h:98
vk::raii::Image m_image
Image object for our texture.
Definition: TextureManager.h:90