|
evan 2026.1.4
Evan
|
A class representing a mesh stored on the GPU, containing vertex and index buffers, as well as material information. More...
#include <headers/evan/GPUMesh.hpp>


Public Member Functions | |
| GPUMesh (std::shared_ptr< DeviceContext > deviceContext, std::vector< GPUVertex > vertices, std::vector< uint32_t > indices, uint32_t materialID) | |
| Constructs a GPUMesh instance by creating vertex and index buffers on the GPU using the provided device context, vertex data, index data, and material ID. | |
| void | destroy (VkDevice device) |
| Destroys the GPUMesh instance by cleaning up GPU resources associated with the vertex and index buffers. | |
| VkBuffer | getVertexBuffer () const |
| Retrieves the Vulkan vertex buffer associated with this GPUMesh instance. | |
| VkBuffer | getIndexBuffer () const |
| Retrieves the Vulkan index buffer associated with this GPUMesh instance. | |
| uint32_t | getIndexCount () const |
| Retrieves the count of indices in the index buffer associated with this GPUMesh instance. | |
| size_t | getVertexCount () const |
| Retrieves the number of vertices the vertex buffer was allocated for. | |
| uint32_t | getMaterialID () const |
| Retrieves the material ID associated with this GPUMesh instance. | |
| const utility::math::AabbF & | getBounds () const |
| Retrieves the axis-aligned bounding box of this mesh. | |
| void | setTransform (const glm::mat4 &transform) |
| Sets the model transform of this mesh. | |
| const glm::mat4 & | getTransform () const |
| Retrieves the per-instance model transform of this mesh. | |
| void | updateVertices (const std::vector< GPUVertex > &vertices) |
| Updates the vertex data of the mesh in place. | |
Protected Member Functions | |
| void | createIndexBuffer (std::shared_ptr< DeviceContext > deviceContext, std::vector< uint32_t > indices) |
| Creates the vertex buffer on the GPU using the provided device context and vertex data. | |
| void | cleanup () |
| Releases the vertex and index buffers owned by this mesh. | |
Protected Attributes | |
| VkBuffer | _vertexBuffer = VK_NULL_HANDLE |
| VkDeviceMemory | _vertexBufferMemory = VK_NULL_HANDLE |
| VkBuffer | _indexBuffer = VK_NULL_HANDLE |
| VkDeviceMemory | _indexBufferMemory = VK_NULL_HANDLE |
| uint32_t | _indexCount = 0 |
| size_t | _vertexCount = 0 |
| uint32_t | _materialID = 0 |
| glm::mat4 | _transform = glm::mat4(1.0f) |
| utility::math::AabbF | _bounds |
| std::shared_ptr< DeviceContext > | _deviceContext |
A class representing a mesh stored on the GPU, containing vertex and index buffers, as well as material information.
The GPUMesh class encapsulates the creation and management of vertex and index buffers on the GPU, allowing for efficient rendering of 3D models. It provides methods to retrieve the vertex and index buffers, as well as the count of indices and the material ID associated with the mesh. The class also includes a destructor to clean up GPU resources when the mesh is no longer needed.
Definition at line 41 of file GPUMesh.hpp.
| evan::GPUMesh::GPUMesh | ( | std::shared_ptr< DeviceContext > | deviceContext, |
| std::vector< GPUVertex > | vertices, | ||
| std::vector< uint32_t > | indices, | ||
| uint32_t | materialID | ||
| ) |
Constructs a GPUMesh instance by creating vertex and index buffers on the GPU using the provided device context, vertex data, index data, and material ID.
This constructor initializes the GPUMesh by creating vertex and index buffers on the GPU using the provided device context. It takes in a vector of GPUVertex structures representing the vertex data, a vector of uint32_t representing the index data, and a uint32_t representing the material ID associated with the mesh. The constructor is responsible for allocating GPU resources and uploading the vertex and index data to the GPU for efficient rendering.
| deviceContext | A reference to the DeviceContext instance used for Vulkan device management and resource creation. |
| vertices | A vector of GPUVertex structures containing the vertex data for the mesh. |
| indices | A vector of uint32_t containing the index data for the mesh. |
| materialID | A uint32_t representing the material ID associated with the mesh, which can be used to reference material properties for rendering. |
|
protected |
Releases the vertex and index buffers owned by this mesh.
Idempotent: every handle is null-checked and reset after being destroyed, making it safe to call from both the destructor and the public destroy() method.
|
protected |
Creates the vertex buffer on the GPU using the provided device context and vertex data.
This method is responsible for creating the Vulkan vertex buffer and allocating memory for it on the GPU. It takes in a reference to the DeviceContext for Vulkan device management and a vector of GPUVertex structures containing the vertex data to be uploaded to the GPU. The method handles the creation of the vertex buffer, allocation of memory, and uploading of vertex data to ensure that the vertex buffer is properly set up for rendering operations.
| deviceContext | A reference to the DeviceContext instance used for Vulkan device management and resource creation. |
| indices | A vector of uint32_t values containing the index data for the index buffer. |
Destroys the GPUMesh instance by cleaning up GPU resources associated with the vertex and index buffers.
This method is responsible for releasing GPU resources allocated for the vertex and index buffers when the GPUMesh instance is destroyed. It takes in a VkDevice representing the Vulkan device used for resource management and ensures that all GPU resources are properly cleaned up to prevent memory leaks and ensure efficient resource usage.
| device | The Vulkan device used for resource management, which is required to clean up GPU resources associated with the vertex and index buffers. |
| const utility::math::AabbF & evan::GPUMesh::getBounds | ( | ) | const |
Retrieves the axis-aligned bounding box of this mesh.
The box is computed from the vertex positions at creation time and refreshed whenever updateVertices() is called. An empty box (isEmpty()) means the mesh has no vertices and must be treated as always visible by culling code.
| VkBuffer evan::GPUMesh::getIndexBuffer | ( | ) | const |
Retrieves the Vulkan index buffer associated with this GPUMesh instance.
This method returns the Vulkan buffer handle for the index buffer, which can be used for rendering operations. The index buffer contains the index data for the mesh and is created during the initialization of the GPUMesh instance.
| uint32_t evan::GPUMesh::getIndexCount | ( | ) | const |
Retrieves the count of indices in the index buffer associated with this GPUMesh instance.
This method returns the number of indices stored in the index buffer, which is used for rendering operations to determine how many vertices to draw based on the index data.
| uint32_t evan::GPUMesh::getMaterialID | ( | ) | const |
Retrieves the material ID associated with this GPUMesh instance.
This method returns the material ID, which can be used to reference material properties for rendering. The material ID is set during the initialization of the GPUMesh instance and can be used to determine how the mesh should be rendered based on its associated material properties.
| const glm::mat4 & evan::GPUMesh::getTransform | ( | ) | const |
Retrieves the per-instance model transform of this mesh.
| VkBuffer evan::GPUMesh::getVertexBuffer | ( | ) | const |
Retrieves the Vulkan vertex buffer associated with this GPUMesh instance.
This method returns the Vulkan buffer handle for the vertex buffer, which can be used for rendering operations. The vertex buffer contains the vertex data for the mesh and is created during the initialization of the GPUMesh instance.
| size_t evan::GPUMesh::getVertexCount | ( | ) | const |
Retrieves the number of vertices the vertex buffer was allocated for.
Used by RenderObject::updateMeshes() to decide whether an incoming mesh can be re-uploaded in place or requires a buffer rebuild.
Sets the model transform of this mesh.
This is the single source of truth for the pose of the mesh: the transform is written into the frame's instance buffer and applied by the vertex shader, so moving or scaling the mesh never touches its vertex data. The stored vertices are local-space.
| transform | The 4x4 model matrix of this mesh. |
Updates the vertex data of the mesh in place.
This method re-uploads vertex data to the already-allocated vertex buffer, reusing the existing buffer and memory instead of creating and destroying Vulkan resources. It is intended for meshes whose topology is static but whose vertex positions change over time (for example a debug ray that follows the cursor).
| vertices | A vector of GPUVertex structures containing the new vertex data. The number of vertices must match the count the mesh was created with. |
|
protected |
The mesh bounding box, computed from vertex positions and refreshed by updateVertices(). Empty when the mesh has no vertices.
Definition at line 320 of file GPUMesh.hpp.
|
protected |
The device context used to create this mesh, kept alive for the lifetime of the mesh so that cleanup can safely destroy its Vulkan resources.
Definition at line 327 of file GPUMesh.hpp.
|
protected |
Vulkan buffer handle for the index buffer associated with this GPUMesh instance, which contains the index data for rendering operations.
Definition at line 278 of file GPUMesh.hpp.
|
protected |
Vulkan device memory handle for the index buffer associated with this GPUMesh instance, which is used to manage the memory allocated for the index buffer on the GPU.
Definition at line 286 of file GPUMesh.hpp.
|
protected |
The count of indices stored in the index buffer associated with this GPUMesh instance, which is used for rendering operations to determine how many vertices to draw based on the index data.
Definition at line 294 of file GPUMesh.hpp.
|
protected |
The material ID associated with this GPUMesh instance, which can be used for rendering purposes to reference material properties.
Definition at line 308 of file GPUMesh.hpp.
|
protected |
Per-instance model transform. Identity by default; only consumed when renderer instancing is enabled.
Definition at line 314 of file GPUMesh.hpp.
|
protected |
Vulkan buffer handle for the vertex buffer associated with this GPUMesh instance, which contains the vertex data for rendering operations.
Definition at line 263 of file GPUMesh.hpp.
|
protected |
Vulkan device memory handle for the vertex buffer associated with this GPUMesh instance, which is used to manage the memory allocated for the vertex buffer on the GPU.
Definition at line 271 of file GPUMesh.hpp.
|
protected |
The number of vertices the vertex buffer was allocated for. Used to validate updateVertices() calls and prevent writing past the end of the allocated buffer.
Definition at line 301 of file GPUMesh.hpp.