evan 2026.1.4
Evan
Loading...
Searching...
No Matches
GPUMesh.hpp
1/*
2** ETIB PROJECT, 2026
3** evan
4** File description:
5** GPUMesh
6*/
7
8#pragma once
9
10#include "evan/EvanPlatform.hpp"
11
12#include "evan/DeviceContext.hpp"
13
14#include "evan/GPUVertex.hpp"
15
16#include <glm/glm.hpp>
17
18#include <utility/math/aabb.hpp>
19
20#include <utility/logging/loggable.hpp>
21#include <utility/logging/default_logger.hpp>
22
23namespace evan
24{
41 class GPUMesh:
42 protected utility::logging::Loggable<GPUMesh,
43 utility::logging::DefaultLogger>
44 {
45 public:
75 GPUMesh(std::shared_ptr<DeviceContext> deviceContext,
76 std::vector<GPUVertex> vertices, std::vector<uint32_t> indices,
77 uint32_t materialID);
78
79 ~GPUMesh();
80
101 void destroy(VkDevice device);
102
115 VkBuffer getVertexBuffer() const;
116
129 VkBuffer getIndexBuffer() const;
130
142 uint32_t getIndexCount() const;
143
153 size_t getVertexCount() const;
154
169 uint32_t getMaterialID() const;
170
181 [[nodiscard]] const utility::math::AabbF &getBounds() const;
182
193 void setTransform(const glm::mat4 &transform);
194
200 [[nodiscard]] const glm::mat4 &getTransform() const;
201
220 void updateVertices(const std::vector<GPUVertex> &vertices);
221
222 protected:
246 void createIndexBuffer(std::shared_ptr<DeviceContext> deviceContext,
247 std::vector<uint32_t> indices);
248
256 void cleanup();
257
263 VkBuffer _vertexBuffer = VK_NULL_HANDLE;
264
271 VkDeviceMemory _vertexBufferMemory = VK_NULL_HANDLE;
272
278 VkBuffer _indexBuffer = VK_NULL_HANDLE;
279
286 VkDeviceMemory _indexBufferMemory = VK_NULL_HANDLE;
287
294 uint32_t _indexCount = 0;
295
301 size_t _vertexCount = 0;
302
308 uint32_t _materialID = 0;
309
314 glm::mat4 _transform = glm::mat4(1.0f);
315
320 utility::math::AabbF _bounds;
321
327 std::shared_ptr<DeviceContext> _deviceContext;
328 };
329} // namespace evan
A class representing a mesh stored on the GPU, containing vertex and index buffers,...
Definition GPUMesh.hpp:44
VkBuffer _vertexBuffer
Definition GPUMesh.hpp:263
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.
uint32_t getIndexCount() const
Retrieves the count of indices in the index buffer associated with this GPUMesh instance.
uint32_t _indexCount
Definition GPUMesh.hpp:294
void destroy(VkDevice device)
Destroys the GPUMesh instance by cleaning up GPU resources associated with the vertex and index buffe...
VkBuffer getVertexBuffer() const
Retrieves the Vulkan vertex buffer associated with this GPUMesh instance.
VkDeviceMemory _vertexBufferMemory
Definition GPUMesh.hpp:271
utility::math::AabbF _bounds
Definition GPUMesh.hpp:320
size_t getVertexCount() const
Retrieves the number of vertices the vertex buffer was allocated for.
std::shared_ptr< DeviceContext > _deviceContext
Definition GPUMesh.hpp:327
size_t _vertexCount
Definition GPUMesh.hpp:301
VkDeviceMemory _indexBufferMemory
Definition GPUMesh.hpp:286
void updateVertices(const std::vector< GPUVertex > &vertices)
Updates the vertex data of the mesh in place.
void setTransform(const glm::mat4 &transform)
Sets the model transform of this mesh.
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.
glm::mat4 _transform
Definition GPUMesh.hpp:314
VkBuffer getIndexBuffer() const
Retrieves the Vulkan index buffer associated with this GPUMesh instance.
VkBuffer _indexBuffer
Definition GPUMesh.hpp:278
uint32_t _materialID
Definition GPUMesh.hpp:308
const glm::mat4 & getTransform() const
Retrieves the per-instance model transform of this mesh.
void cleanup()
Releases the vertex and index buffers owned by this mesh.
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 devi...