Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
vulkan_mesh_resources.hpp
Go to the documentation of this file.
1// This file is part of the Rendering Engine project.
2// Author: Alexander Obzherin <alexanderobzherin@gmail.com>
3// Copyright (c) 2025 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5
6#pragma once
7
9#include <vulkan/vulkan.h>
10#include <string>
11
12namespace rendering_engine
13{
14class VulkanRenderer;
15
16/**
17 * @brief Vulkan implementation of the mesh GPU resource interface.
18 *
19 * Manages Vulkan buffers and device memory for mesh vertex and index data.
20 * Supports multiple vertex types and provides direct access to underlying VkBuffer handles.
21 */
23{
24public:
25 /**
26 * @brief Construct Vulkan mesh resources.
27 * @param renderer Pointer to the owning VulkanRenderer.
28 */
30
31 /**
32 * @brief Create a GPU vertex buffer from 2D vertex data.
33 * @param vertices Vector of 2D vertex data.
34 */
35 void CreateVertexBuffer(std::vector<Vertex2D> vertices) override;
36
37 /**
38 * @brief Create a GPU vertex buffer from 3D unlit vertex data.
39 * @param vertices Vector of VertexPositionColorTexture data.
40 */
41 void CreateVertexBuffer(std::vector<VertexPositionColorTexture> vertices) override;
42
43 /**
44 * @brief Create a GPU vertex buffer from 3D lit vertex data.
45 * @param vertices Vector of VertexPositionColorTextureNormalTangent data.
46 */
47 void CreateVertexBuffer(std::vector<VertexPositionColorTextureNormalTangent> vertices) override;
48
49 /**
50 * @brief Create a GPU index buffer.
51 * @param indices Vector of indices.
52 */
53 void CreateIndexBuffer(std::vector<uint32_t> indices) override;
54
55 /**
56 * @brief Query whether buffers are currently resident on the GPU.
57 * @return True if buffers are allocated and uploaded, false otherwise.
58 */
59 inline bool IsOnGPU() const override;
60
61 /**
62 * @brief Release all GPU resources associated with this mesh.
63 */
64 void Shutdown() override;
65
66 /**
67 * @brief Get the Vulkan vertex buffer handle.
68 * @return VkBuffer handle for the vertex buffer.
69 */
70 VkBuffer GetVertexBuffer() const;
71
72 /**
73 * @brief Get the Vulkan index buffer handle.
74 * @return VkBuffer handle for the index buffer.
75 */
76 VkBuffer GetIndexBuffer() const;
77
78 /**
79 * @brief Get the size (in bytes) of the GPU vertex buffer.
80 * @return Size in bytes of the vertex buffer.
81 */
82 inline size_t GetVertexBufferSize() const override;
83
84 /**
85 * @brief Get the size (in bytes) of the GPU index buffer.
86 * @return Size in bytes of the index buffer.
87 */
88 inline size_t GetIndexBufferSize() const override;
89
90private:
91 VulkanRenderer* mRenderer;
92 bool bIsOnGPU;
93
94 VkBuffer mVertexBuffer;
95 VkDeviceMemory mVertexBufferMemory;
96 size_t mVertexBufferSize;
97
98 VkBuffer mIndexBuffer;
99 VkDeviceMemory mIndexBufferMemory;
100 size_t mIndexBufferSize;
101};
102
103} // namespace rendering_engine
Interface for GPU mesh resource management.
bool IsOnGPU() const override
Query whether buffers are currently resident on the GPU.
void Shutdown() override
Release all GPU resources associated with this mesh.
void CreateIndexBuffer(std::vector< uint32_t > indices) override
Create a GPU index buffer.
VulkanMeshResources(VulkanRenderer *renderer)
Construct Vulkan mesh resources.
size_t GetVertexBufferSize() const override
Get the size (in bytes) of the GPU vertex buffer.
size_t GetIndexBufferSize() const override
Get the size (in bytes) of the GPU index buffer.
VkBuffer GetIndexBuffer() const
Get the Vulkan index buffer handle.
void CreateVertexBuffer(std::vector< Vertex2D > vertices) override
Create a GPU vertex buffer from 2D vertex data.
VkBuffer GetVertexBuffer() const
Get the Vulkan vertex buffer handle.
Vulkan-based implementation of the IRenderer interface.