vulkan-project/texture_manager.hpp
2022-10-14 20:58:20 +02:00

66 lines
2.2 KiB
C++

#pragma once
#include "texture_atlas.hpp"
#include "stb_image.h"
#include <gz-util/util/string.hpp>
#include <glm/fwd.hpp>
#include <unordered_map>
namespace gz::vk {
struct TextureInfo {
uint32_t atlas;
glm::vec2 texCoordTopLeft;
glm::vec2 texCoordBottomRight;
};
/// Defined in vulkan_instance.hpp
class VulkanInstance;
class TextureManager {
public:
/**
* @brief Create a texture manager
* @details
* -# @ref VulkanInstance::registerCleanupCallback "register" @ref cleanup() "cleanup callback"
* -# @ref createDescriptor "create descriptor set layout, pool and set
*/
TextureManager(VulkanInstance& instance);
void getTexCoords(const std::string& textureName, glm::vec2& texCoords);
const VkDescriptorSet& getDescriptorSet() const { return descriptorSet; }
const VkDescriptorSetLayout& getDescriptorSetLayout() const { return descriptorSetLayout; }
private:
void cleanup();
void loadTextureFromFile(const std::string& textureName);
std::unordered_map<uint32_t, TextureAtlas> atlases;
util::unordered_string_map<TextureInfo> textureInfos;
VulkanInstance& vk;
/**
* @name Create desciptors
* @details These functions create a desciptor with bindings for
* -# Combined Image Sampler (DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER) at binding 0
* @{
*/
VkDescriptorSetLayout descriptorSetLayout;
VkDescriptorPool descriptorPool;
VkDescriptorSet descriptorSet;
/* std::vector<VkDescriptorSet> descriptorSets; */
/**
* @brief Create a descriptor set layout
* @details
* Bindings:
* -0 COMBINED_IMAGE_SAMPLER
*/
void createDescriptorSetLayout();
void createDescriptorPool();
void createDescriptorSet();
/* const uint32_t bindingCombinedImageSampler = 1; */
/**
* @}
*/
};
} // namespace gz::vk