Class Texture#

Class Documentation#

class Texture#

Public Functions

Texture()#
Texture(const Texture&) = delete#
Texture &operator=(const Texture&) = delete#
Texture(Texture &&other) noexcept#
Texture &operator=(Texture &&other) noexcept#
bool createFromFile(const std::shared_ptr<VulkanDevice> &device, vk::CommandPool commandPool, const std::string &fileName, bool srgb = true)#
bool createFromMemory(const std::shared_ptr<VulkanDevice> &device, vk::CommandPool commandPool, const unsigned char *encodedBytes, size_t byteCount, bool srgb = true)#

Decodes an encoded image (PNG/JPG/…) already in memory and uploads it, for glTF’s embedded / data-URI images which never touch the filesystem. Shares the upload path with createFromFile; returns false if the bytes do not decode. srgb selects the colour space the data is uploaded in: true for colour data (base colour, emissive), false for linear data (normal maps) - see the note on uploadRgba’s texture_format.

bool createDefaultTexture(const std::shared_ptr<VulkanDevice> &device, vk::CommandPool commandPool)#

Returns false if the white-default upload itself failed (e.g. a failed submit), in which case the texture is left empty/unwritten.

void setImage(vk::Image image)#
void setImageView(vk::ImageView imageView)#
inline uint32_t getMipLevel() const#
inline VulkanImage &getVulkanImage()#
inline vk::Image &getImage()#
inline vk::ImageView &getImageView()#
inline vk::Sampler &getSampler()#
void createImage(const std::shared_ptr<VulkanDevice> &device, uint32_t width, uint32_t height, uint32_t in_mip_levels, vk::Format format, vk::ImageTiling tiling, vk::ImageUsageFlags use_flags, vk::MemoryPropertyFlags prop_flags, uint32_t array_layers = 1, vk::ImageCreateFlags create_flags = {}, vk::ImageType image_type = vk::ImageType::e2D, uint32_t depth = 1)#
void createImageView(const std::shared_ptr<VulkanDevice> &device, vk::Format format, vk::ImageAspectFlags aspect_flags, uint32_t in_mip_levels, vk::ImageViewType view_type = vk::ImageViewType::e2D, uint32_t array_layers = 1)#
void createTextureSampler(const std::shared_ptr<VulkanDevice> &device, vk::Filter filter = vk::Filter::eLinear, vk::SamplerAddressMode addressMode = vk::SamplerAddressMode::eRepeat, vk::Bool32 compareEnable = VK_FALSE, vk::CompareOp compareOp = vk::CompareOp::eAlways)#
void releaseImageView()#

Releases the current view only, leaving the sampler and image alone. Call before a createImage() that will replace the image the view looks at, so the view is destroyed before its image (VUID-vkDestroyImage-image-01000).

void releaseSampler()#

Releases the current sampler only, leaving the view and image alone. Called first by createTextureSampler() so a second call on an already-created instance releases the previous sampler instead of leaking it.

void cleanUp()#
~Texture()#

Public Static Functions

static unsigned char *loadTextureData(const std::string &file_name, int *width, int *height, vk::DeviceSize *image_size)#