KarmaEngine
Game Engine for practical learning and research purposes
Loading...
Searching...
No Matches
Karma::VulkanTexture Class Reference

Vulkan specific implementation of Texture class. More...

#include <VulkanTexture.h>

Inheritance diagram for Karma::VulkanTexture:
Karma::Texture

Public Member Functions

 VulkanTexture ()
 A constructor.
 VulkanTexture (FVulkanDevice *InDevice, const char *filename)
 Constructor with VulkanRHI support.
 ~VulkanTexture ()
 A destructor.
void CreateTextureImage (VulkanImageBuffer *vImageBuffer)
 Creates Vulkan image for the texture and allocates device memory appropriately.
void CreateTextureImageView ()
 Creates the image view for the texture.
void CreateTextureSampler ()
 Creates the texture sampler.
void GenerateVulkanTexture (VulkanImageBuffer *vImageBuffer)
 Generates the Vulkan texture by creating the image, image view, and sampler.
VkImageView GetImageView () const
VkSampler GetImageSampler () const
Public Member Functions inherited from Karma::Texture
 Texture ()
 A constructor.
 Texture (TextureType tType, const char *filename, std::string textureName, std::string textureShaderName)
 Another constructor.
 ~Texture ()
 A destructor.
const std::string & GetTextureName () const
 Getter for texture name.
const std::string & GetTextureShaderName () const
 Getter for Texture Shader name.
std::shared_ptr< VulkanTextureGetVulkanTexture () const
 Getter for VulkanTexture.

Detailed Description

Vulkan specific implementation of Texture class.

This class handles the creation and management of Vulkan textures, including image views and samplers.

A sampler in Vulkan is an object that defines how to sample textures in shaders. It encapsulates sampling parameters such as filtering modes, addressing modes, and mipmapping settings.

Since
Karma 1.0.0

Constructor & Destructor Documentation

◆ VulkanTexture() [1/2]

Karma::VulkanTexture::VulkanTexture ( )

A constructor.

Since
Karma 1.0.0

◆ VulkanTexture() [2/2]

Karma::VulkanTexture::VulkanTexture ( FVulkanDevice * InDevice,
const char * filename )

Constructor with VulkanRHI support.

InDevice The FVulkanDevice object

filename The location of the texture file along with location

See also
FVulkanDevice::InitGPU()
Since
Karma 1.0.0

◆ ~VulkanTexture()

Karma::VulkanTexture::~VulkanTexture ( )

A destructor.

Cleans up vulkan resources associated with the texture which includes destroying the image sampler, image view, image, and freeing the image memory.

Since
Karma 1.0.0

Member Function Documentation

◆ CreateTextureImage()

void Karma::VulkanTexture::CreateTextureImage ( VulkanImageBuffer * vImageBuffer)

Creates Vulkan image for the texture and allocates device memory appropriately.

There are also transitions of (m_TextureImage) image layouts (from VK_IMAGE_LAYOUT_UNDEFINED -> VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL then copying of vImageBuffer to m_TextureImage followed by transition VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL -> VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL) and vkBindImageMemory call to bind the allocated memory to the image.

Layout transitions are done because different operations in Vulkan require images to be in specific layouts for optimal performance and correctness. https://vulkan-tutorial.com/Texture_mapping/Images

VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL: Optimal as destination in a transfer operation, like vkCmdCopyBufferToImage VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL: Optimal for reading in shaders, used when sampling the texture in a shader.

Parameters
vImageBufferThe VulkanImageBuffer containing the image data to be used for the texture VulkanImageBuffer is expected to have been created and populated with image data prior to this call. See ImageBuffer::Create()
See also
VulkanTexture::GenerateVulkanTexture(), Texture::Texture()

◆ CreateTextureImageView()

void Karma::VulkanTexture::CreateTextureImageView ( )

Creates the image view for the texture.

Since
Karma 1.0.0

◆ CreateTextureSampler()

void Karma::VulkanTexture::CreateTextureSampler ( )

Creates the texture sampler.

A sampler in Vulkan defines how to sample textures in shaders, including filtering modes, addressing modes, and mipmapping settings.

Since
Karma 1.0.0

◆ GenerateVulkanTexture()

void Karma::VulkanTexture::GenerateVulkanTexture ( VulkanImageBuffer * vImageBuffer)

Generates the Vulkan texture by creating the image, image view, and sampler.

This function orchestrates the creation of the Vulkan texture by calling CreateTextureImage, CreateTextureImageView, and CreateTextureSampler in sequence.

Parameters
vImageBufferThe VulkanImageBuffer containing the image data to be used for the texture
See also
VulkanTexture::CreateTextureImage(), VulkanTexture::CreateTextureImageView(), VulkanTexture::CreateTextureSampler()
Since
Karma 1.0.0

The documentation for this class was generated from the following files: