Class GpuTexture

Class Documentation

class inexor::vulkan_renderer::wrapper::GpuTexture

RAII wrapper class for textures which are stored in GPU memory.

Todo:

Support 3D textures and cube maps (implement new and separate wrappers though).

Note

The code which loads textures from files is wrapped in CpuTexture.

Public Functions

GpuTexture(const wrapper::Device &device, const CpuTexture &cpu_texture)

Construct a texture from a file.

Parameters
  • device – The const reference to a device RAII wrapper instance.

  • file_name – The name of the texture file.

  • name – The internal debug marker name of the texture.

GpuTexture(const wrapper::Device &device, void *data, std::size_t data_size, int texture_width, int texture_height, int texture_channels, int mip_levels, std::string name)

Construct a texture from a block of memory.

Parameters
  • device – The const reference to a device RAII wrapper instance.

  • device – The const reference to a device RAII wrapper instance.

  • texture_data – A pointer to the texture data.

  • texture_width – The width of the texture.

  • texture_height – The height of the texture.

  • texture_size – The size of the texture.

  • name – The internal debug marker name of the texture.

GpuTexture(const GpuTexture&) = delete
GpuTexture(GpuTexture&&) noexcept
~GpuTexture()
GpuTexture &operator=(const GpuTexture&) = delete
GpuTexture &operator=(GpuTexture&&) = delete
inline std::string name() const
inline VkImage image() const
inline VkImageView image_view() const
inline VkSampler sampler() const

Private Functions

void create_texture(void *texture_data, std::size_t texture_size)

Create the texture.

Parameters
  • texture_data – A pointer to the texture data.

  • texture_size – The size of the texture.

void transition_image_layout(VkImage image, VkImageLayout old_layout, VkImageLayout new_layout)

Transform the image layout.

Parameters
  • image – The image.

  • old_layout – The old image layout.

  • new_layout – The new image layout.

void create_texture_sampler()

Create the texture sampler.

Private Members

std::unique_ptr<wrapper::Image> m_texture_image
OnceCommandBuffer m_copy_command_buffer
VkSampler m_sampler = {VK_NULL_HANDLE}
int m_texture_width = {0}
int m_texture_height = {0}
int m_texture_channels = {0}
int m_mip_levels = {0}
std::string m_name
const wrapper::Device &m_device
const VkFormat m_texture_image_format = {VK_FORMAT_R8G8B8A8_UNORM}