|
evan 2026.1.4
Evan
|
Represents a material in the rendering engine, encapsulating texture data, image views, samplers, and descriptor sets for use in Vulkan rendering operations. More...
#include <headers/evan/GPUMaterial.hpp>


Public Member Functions | |
| GPUMaterial (std::shared_ptr< DeviceContext > deviceContext, const Renderer &renderer, const utility::graphic::Material &material, uint32_t shaderID) | |
| Constructs a GPUMaterial instance using the provided device context, renderer, and texture path. | |
| void | destroy (VkDevice device) |
| Destroys the Vulkan resources associated with the material. | |
| void | update (std::shared_ptr< DeviceContext > deviceContext, const Renderer &renderer, const utility::graphic::Material &material, uint32_t shaderID) |
| Updates the GPUMaterial with new texture data and resources. | |
| const std::vector< VkDescriptorSet > & | getDescriptorSets () const |
| Retrieves the Vulkan descriptor sets associated with this material. | |
| uint32_t | getShaderID () const |
| Retrieves the unique shader ID associated with this material. | |
| BlendMode | getBlendMode () const |
| Retrieves the blend mode this material has to be drawn with. | |
| uint32_t | getUploadedVersion () const |
| Retrieves the version number of the uploaded material. | |
Protected Member Functions | |
| void | createDescriptorSets (VkDevice logicalDevice, VkDescriptorSetLayout descriptorSetLayout, VkDescriptorPool descriptorPool, const std::vector< VkBuffer > &uniformBuffers) |
| Creates Vulkan descriptor sets for the material, allowing shaders to access the material's texture data and associated resources during rendering operations. | |
| void | cleanup () |
| Releases every Vulkan resource owned by this material. | |
| void | freeDescriptorSets (VkDevice device) |
| Frees the descriptor sets allocated for this material and clears the container. | |
Protected Attributes | |
| std::vector< std::shared_ptr< GPUTexture > > | _textures |
| uint32_t | _shaderID |
| utility::graphic::AlphaMode | _alphaMode |
| std::vector< VkDescriptorSet > | _descriptorSets |
| VkDescriptorPool | _descriptorPool = VK_NULL_HANDLE |
| uint32_t | _uploadedVersion = 0 |
| std::shared_ptr< DeviceContext > | _deviceContext |
Represents a material in the rendering engine, encapsulating texture data, image views, samplers, and descriptor sets for use in Vulkan rendering operations.
The GPUMaterial class is responsible for managing the Vulkan resources associated with a material, including creating images from texture files, generating mipmaps, creating image views and samplers, and setting up descriptor sets for shader access. It provides methods for initializing these resources based on a given texture path and the device context and renderer instances. The class also includes functionality for cleaning up Vulkan resources when they are no longer needed.
Definition at line 42 of file GPUMaterial.hpp.
| evan::GPUMaterial::GPUMaterial | ( | std::shared_ptr< DeviceContext > | deviceContext, |
| const Renderer & | renderer, | ||
| const utility::graphic::Material & | material, | ||
| uint32_t | shaderID | ||
| ) |
Constructs a GPUMaterial instance using the provided device context, renderer, and texture path.
This constructor initializes the material by creating a Vulkan image from the specified texture file, generating mipmaps for the image, creating an image view and sampler, and setting up descriptor sets for shader access. It utilizes the provided device context and renderer to access necessary Vulkan resources and configurations for these operations.
| deviceContext | A reference to the DeviceContext instance, which provides access to Vulkan device resources and configurations needed for creating images, image views, samplers, and descriptor sets. |
| renderer | A reference to the Renderer instance, which may be used to access rendering configurations or resources needed for material initialization. |
| material | A reference to the utility::graphic::Material instance, which contains information about the material's shader and textures, used to initialize the Vulkan resources for this material. |
| shaderID | The unique ID of the shader associated with this material, used to identify which shader program should be used when rendering objects that utilize this material. |
|
protected |
Releases every Vulkan resource owned by this material.
Descriptor sets are freed before the textures they reference are destroyed. This method is idempotent, so it is safe to call from both the destructor and the public destroy() method.
|
protected |
Creates Vulkan descriptor sets for the material, allowing shaders to access the material's texture data and associated resources during rendering operations.
This method sets up descriptor sets for the material, which can be bound to shader stages to provide access to the material's Vulkan image, image view, sampler, and other associated resources. The descriptor sets are configured based on the provided descriptor set layout and uniform buffers.
| logicalDevice | The Vulkan logical device used to create the descriptor sets. This device should be the same one used to create the material's Vulkan resources. |
| descriptorSetLayout | The Vulkan descriptor set layout that defines the structure of the descriptor sets to be created for this material. The layout should match the expected bindings in the shader programs that will access the material's resources. |
| descriptorPool | The Vulkan descriptor pool from which the descriptor sets will be allocated. This pool should have sufficient capacity to allocate the required number of descriptor sets for this material. |
| uniformBuffers | A vector of Vulkan buffer handles representing uniform buffers that may be used in the descriptor sets for shader access to uniform data associated with the material. |
Destroys the Vulkan resources associated with the material.
This method cleans up all Vulkan resources allocated for the material, including the Vulkan image, image view, sampler, and descriptor sets. It should be called when the material is no longer needed to free up GPU resources and prevent memory leaks.
| device | The Vulkan logical device used to destroy the associated resources. This device should be the same one used to create the resources in the first place. |
Frees the descriptor sets allocated for this material and clears the container.
| device | The Vulkan logical device used to free the descriptor sets. When VK_NULL_HANDLE or when no descriptor sets are present, this method only clears the container. |
| BlendMode evan::GPUMaterial::getBlendMode | ( | ) | const |
Retrieves the blend mode this material has to be drawn with.
Derived from the alpha semantics declared by the material (see utility::graphic::Material::getAlphaMode). AlphaMode::Mask is projected onto the alpha pipeline for now: a masked texel whose alpha is close to zero contributes nothing once blended, which keeps alpha-tested content visually correct until shaders can discard below the cutoff.
| const std::vector< VkDescriptorSet > & evan::GPUMaterial::getDescriptorSets | ( | ) | const |
Retrieves the Vulkan descriptor sets associated with this material.
This method returns a vector of Vulkan descriptor sets that have been created for this material. These descriptor sets can be used in shader programs to access the material's texture data and other associated resources during rendering operations.
createDescriptorSets, update) or when the material is destroyed. Callers must not hold it beyond the current bind. | uint32_t evan::GPUMaterial::getShaderID | ( | ) | const |
Retrieves the unique shader ID associated with this material.
This method returns the unique ID of the shader that is associated with this material. The shader ID is used to identify which shader program should be used when rendering objects that utilize this material, allowing for proper rendering of the material's visual properties based on the shader's functionality and characteristics.
| uint32_t evan::GPUMaterial::getUploadedVersion | ( | ) | const |
Retrieves the version number of the uploaded material.
This method returns the version number of the material that was uploaded to the GPU. This is useful for tracking changes and updates to the material's properties and resources.
| void evan::GPUMaterial::update | ( | std::shared_ptr< DeviceContext > | deviceContext, |
| const Renderer & | renderer, | ||
| const utility::graphic::Material & | material, | ||
| uint32_t | shaderID | ||
| ) |
Updates the GPUMaterial with new texture data and resources.
This method updates the GPUMaterial by reinitializing its Vulkan resources based on the provided material's texture data. It creates new Vulkan images, image views, samplers, and descriptor sets as needed to reflect any changes in the material's properties or associated textures.
| deviceContext | A shared pointer to the DeviceContext instance, which provides access to Vulkan device resources and configurations needed for updating images, image views, samplers, and descriptor sets. |
| renderer | A reference to the Renderer instance, which may be used to access rendering configurations or resources needed for material updates. |
| material | A reference to the utility::graphic::Material instance, which contains updated information about the material's shader and textures, used to reinitialize the Vulkan resources for this material. |
| shaderID | The unique ID of the shader associated with this material, used to identify which shader program should be used when rendering objects that utilize this material. |
|
protected |
The alpha semantics declared by the material this object uploads.
Kept so the renderer can pick the opaque or the alpha-blended pipeline variant without reaching back into the CPU-side material.
Definition at line 275 of file GPUMaterial.hpp.
|
protected |
The Vulkan descriptor pool from which the descriptor sets were allocated. Stored so they can be freed when the material is destroyed.
Definition at line 288 of file GPUMaterial.hpp.
|
protected |
Vector of Vulkan descriptor sets associated with the material.
Definition at line 281 of file GPUMaterial.hpp.
|
protected |
The device context used to create this material, kept alive for the lifetime of the material so that cleanup can safely destroy its Vulkan resources.
Definition at line 301 of file GPUMaterial.hpp.
|
protected |
The unique ID associated with the shader used by this material.
Definition at line 267 of file GPUMaterial.hpp.
|
protected |
Textures associated with the material, categorized by their intended use in the rendering pipeline.
Definition at line 262 of file GPUMaterial.hpp.
|
protected |
The version number of the material, used for tracking changes and updates to the material's properties and resources.
Definition at line 294 of file GPUMaterial.hpp.