|
evan 2026.1.4
Evan
|
GPUTexture class. More...
#include <headers/evan/GPUTexture.hpp>


Classes | |
| struct | GenerateMipmapsProperties |
| Holds properties required for generating mipmaps for a Vulkan image. More... | |
| struct | SamplerSettings |
| Consumer-overridable sampler parameters. More... | |
Public Types | |
| enum class | TextureType { Albedo , Normal , Roughness , FontAtlas } |
| Enum class representing different types of textures that can be associated with a material, such as albedo, normal, and roughness textures. More... | |
Public Member Functions | |
| GPUTexture (std::shared_ptr< DeviceContext > deviceContext, const utility::graphic::Texture &texture, TextureType type=TextureType::Albedo, const SamplerSettings &settings=SamplerSettings {}) | |
| Constructs a GPUTexture object by creating a Vulkan image, image view, and sampler based on the provided texture data and type. | |
| ~GPUTexture () | |
| Destructs the GPUTexture object by cleaning up Vulkan resources such as the image, image view, and sampler. | |
| void | destroy (VkDevice device) |
| Destroys the Vulkan resources associated with this GPUTexture, including the image, image view, and sampler. | |
| uint32_t | getMipLevels () const |
| Retrieves the number of mipmap levels generated for this texture. | |
Static Public Member Functions | |
| static uint32_t | computeMipLevels (uint32_t width, uint32_t height) |
| Computes the number of mipmap levels for a texture of the given dimensions. | |
| static float | computeMaxLod (uint32_t mipLevels) |
| Computes the maximum sampleable LOD for a texture with the given number of mipmap levels. | |
Public Attributes | |
| VkImageView | view = VK_NULL_HANDLE |
| The Vulkan image view associated with this GPUTexture. | |
| VkSampler | sampler = VK_NULL_HANDLE |
| The Vulkan sampler associated with this GPUTexture, which defines how the texture is sampled in shader programs. | |
| TextureType | type |
| The type of texture represented by this GPUTexture instance, such as albedo, normal, or roughness. This property is used to categorize the texture based on its intended use in the rendering pipeline, allowing for organized management of texture resources and their bindings in shader programs. | |
Protected Member Functions | |
| void | cleanup () |
| Releases every Vulkan resource owned by this texture. | |
| void | createImage (const ADeviceBackend &deviceBackend, const utility::graphic::Texture &texture, VkCommandPool commandPool, VkQueue graphicsQueue) |
| Creates a Vulkan image based on the provided texture data and type, and allocates memory for it. | |
| void | createImageView (const ADeviceBackend &deviceBackend) |
| Creates a Vulkan image view for the Vulkan image associated with this GPUTexture, allowing shader access to the texture data. | |
| void | createSampler (const ADeviceBackend &deviceBackend, VkSamplerCreateInfo samplerInfo, const SamplerSettings &settings=SamplerSettings {}) |
| Creates a Vulkan sampler for the Vulkan image associated with this GPUTexture, defining how the texture is sampled in shader programs. | |
Protected Attributes | |
| VkImage | _image = VK_NULL_HANDLE |
| The Vulkan image associated with this GPUTexture, which holds the texture data in GPU memory for use in rendering operations. | |
| VkDeviceMemory | _memory = VK_NULL_HANDLE |
| The Vulkan device memory allocated for the image associated with this GPUTexture, which is used to store the texture data in GPU memory. | |
| uint32_t | _mipLevel = 1 |
| The number of mipmap levels generated for the Vulkan image associated with this GPUTexture, which is used to determine the level of detail for texture sampling in shader programs. This property is important for optimizing rendering performance and visual quality by allowing shaders to sample from different mipmap levels based on the distance and angle of the textured surface relative to the camera. | |
| std::shared_ptr< DeviceContext > | _deviceContext |
| The device context used to create this texture, kept alive for the lifetime of the texture so that cleanup can safely destroy its Vulkan resources. | |
GPUTexture class.
This class represents a texture that can be used in the GPU for rendering. It encapsulates the Vulkan image, image view, and sampler associated with the texture, as well as the type of texture (e.g., albedo, normal, roughness) for categorization in the rendering pipeline. The GPUTexture class provides functionality for creating and managing Vulkan resources related to textures, including image creation, memory allocation, image view setup, sampler creation, and mipmap generation. It also includes a method for destroying the Vulkan resources when they are no longer needed.
Definition at line 44 of file GPUTexture.hpp.
Enum class representing different types of textures that can be associated with a material, such as albedo, normal, and roughness textures.
This enum class is used to categorize textures based on their intended use in the rendering pipeline. Each texture type corresponds to a specific role in defining the visual properties of a material, allowing for organized management of texture resources and their bindings in shader programs.
Definition at line 60 of file GPUTexture.hpp.
| evan::GPUTexture::GPUTexture | ( | std::shared_ptr< DeviceContext > | deviceContext, |
| const utility::graphic::Texture & | texture, | ||
| TextureType | type = TextureType::Albedo, |
||
| const SamplerSettings & | settings = SamplerSettings {} |
||
| ) |
Constructs a GPUTexture object by creating a Vulkan image, image view, and sampler based on the provided texture data and type.
This constructor initializes a GPUTexture instance by creating a Vulkan image using the provided texture data, setting up the corresponding image view and sampler for use in shader programs. The constructor takes into account the type of texture being created (e.g., albedo, normal, roughness) to determine the appropriate format and usage flags for the Vulkan image, ensuring that the texture is correctly configured for its intended role in the rendering pipeline.
| deviceContext | A reference to the DeviceContext instance, which provides access to the Vulkan device and related resources needed for creating the image, image view, and sampler. |
| texture | A reference to a utility::graphic::Texture object containing the pixel data and dimensions of the texture to be created. |
| type | The type of texture being created (e.g., albedo, normal, roughness), which determines the format and usage flags for the Vulkan image. |
| settings | Optional sampler settings (min/max LOD, anisotropy, address modes) used to override the default sampler configuration. |
|
protected |
Releases every Vulkan resource owned by this texture.
This method is idempotent: each handle is checked against VK_NULL_HANDLE before being destroyed and is reset afterwards, so it is safe to call more than once or after a partially failed construction.
Computes the maximum sampleable LOD for a texture with the given number of mipmap levels.
LOD is zero-based: a texture with mipLevels levels has valid LODs in the range [0, mipLevels - 1].
| mipLevels | The number of mipmap levels. |
Computes the number of mipmap levels for a texture of the given dimensions.
| width | The width of the texture in pixels. |
| height | The height of the texture in pixels. |
|
protected |
Creates a Vulkan image based on the provided texture data and type, and allocates memory for it.
This method is responsible for creating a Vulkan image object using the pixel data and dimensions from the provided utility::graphic::Texture, as well as determining the appropriate format and usage flags based on the specified TextureType. It also allocates memory for the Vulkan image and binds it to the image object, ensuring that the texture data is properly stored in GPU memory for use in rendering operations.
| deviceBackend | A reference to the ADeviceBackend instance, which provides access to the Vulkan device and related resources needed for creating the image and allocating memory. |
| texture | A reference to a utility::graphic::Texture object containing the pixel data and dimensions of the texture to be created. |
| commandPool | The Vulkan command pool used to allocate command buffers for any necessary staging operations during image creation. |
| graphicsQueue | The Vulkan graphics queue used to submit command buffers for execution during image creation and any necessary staging operations. |
|
protected |
Creates a Vulkan image view for the Vulkan image associated with this GPUTexture, allowing shader access to the texture data.
This method sets up the image view for the Vulkan image, which is necessary for shaders to access the texture data correctly. The image view defines how the image data is interpreted and accessed in shader programs, including aspects such as format and subresource range. Properly creating the image view ensures that the texture can be sampled correctly in rendering operations.
| deviceBackend | A reference to the ADeviceBackend instance, which provides access to the Vulkan device and related resources needed for creating the image view. |
|
protected |
Creates a Vulkan sampler for the Vulkan image associated with this GPUTexture, defining how the texture is sampled in shader programs.
This method sets up the sampler for the Vulkan image, which specifies how the texture is sampled in shader programs, including filtering modes, addressing modes, and mipmapping behavior. Properly creating the sampler ensures that the texture is sampled correctly in rendering operations, allowing for effects such as smooth filtering and proper handling of texture coordinates outside the [0, 1] range.
| deviceBackend | A reference to the ADeviceBackend instance, which provides access to the Vulkan device and related resources needed for creating the sampler. |
| samplerInfo | A VkSamplerCreateInfo structure containing the parameters for creating the Vulkan sampler, such as filtering modes, addressing modes, and mipmapping behavior. This information is used to |
Destroys the Vulkan resources associated with this GPUTexture, including the image, image view, and sampler.
| device | The Vulkan logical device used to destroy the associated resources. This parameter is required to ensure that the correct device context is used for resource cleanup, preventing potential issues with resource management and ensuring proper deallocation of Vulkan objects. |
|
inline |
Retrieves the number of mipmap levels generated for this texture.
Definition at line 282 of file GPUTexture.hpp.
|
protected |
The device context used to create this texture, kept alive for the lifetime of the texture so that cleanup can safely destroy its Vulkan resources.
Definition at line 416 of file GPUTexture.hpp.
|
protected |
The Vulkan image associated with this GPUTexture, which holds the texture data in GPU memory for use in rendering operations.
Definition at line 392 of file GPUTexture.hpp.
|
protected |
The Vulkan device memory allocated for the image associated with this GPUTexture, which is used to store the texture data in GPU memory.
Definition at line 399 of file GPUTexture.hpp.
|
protected |
The number of mipmap levels generated for the Vulkan image associated with this GPUTexture, which is used to determine the level of detail for texture sampling in shader programs. This property is important for optimizing rendering performance and visual quality by allowing shaders to sample from different mipmap levels based on the distance and angle of the textured surface relative to the camera.
Definition at line 409 of file GPUTexture.hpp.
| VkSampler evan::GPUTexture::sampler = VK_NULL_HANDLE |
The Vulkan sampler associated with this GPUTexture, which defines how the texture is sampled in shader programs.
Definition at line 296 of file GPUTexture.hpp.
| TextureType evan::GPUTexture::type |
The type of texture represented by this GPUTexture instance, such as albedo, normal, or roughness. This property is used to categorize the texture based on its intended use in the rendering pipeline, allowing for organized management of texture resources and their bindings in shader programs.
Definition at line 305 of file GPUTexture.hpp.
| VkImageView evan::GPUTexture::view = VK_NULL_HANDLE |
The Vulkan image view associated with this GPUTexture.
Definition at line 290 of file GPUTexture.hpp.