|
KarmaEngine
Game Engine for practical learning and research purposes
|
Vulkan specific implementation of Texture class. More...
#include <VulkanTexture.h>
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< VulkanTexture > | GetVulkanTexture () const |
| Getter for VulkanTexture. | |
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.
| Karma::VulkanTexture::VulkanTexture | ( | ) |
A constructor.
| 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
| 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.
| 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.
| vImageBuffer | The 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() |
| void Karma::VulkanTexture::CreateTextureImageView | ( | ) |
Creates the image view for the texture.
| 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.
| 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.
| vImageBuffer | The VulkanImageBuffer containing the image data to be used for the texture |