Rendering Engine 0.2.17
Modular Graphics Rendering Engine | v0.2.17
Loading...
Searching...
No Matches
vulkan_render_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) 2026 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5
6#pragma once
7
10
11#include <vector>
12#include <vulkan/vulkan.h>
13
14namespace rendering_engine
15{
16class VulkanRenderer;
17class Material;
18class MeshDataGpu;
19class TextureCache;
20
21/**
22 * @brief Vulkan implementation of IRenderResources for the Rendering Engine.
23 *
24 * Aggregates and manages Vulkan GPU-side resources (buffers, descriptor sets, pipelines)
25 * required to render a drawable object. Responds to renderer events (release/rebuild)
26 * and can be safely reused with shared caches for materials, meshes, and textures.
27 */
29{
30public:
31 /**
32 * @brief Constructor.
33 * @param renderer Pointer to the owning VulkanRenderer instance.
34 *
35 * Registers itself as an observer for resource (re)creation events.
36 */
38
39 /**
40 * @brief Destructor.
41 *
42 * Unregisters from the renderer and calls Shutdown() to release all resources.
43 */
45
46 /**
47 * @copydoc IRenderResources::Initialize
48 */
49 void Initialize(Material* material, MeshDataGpu* meshData, TextureCache* textureCache) override;
50
51 /**
52 * @copydoc IRenderResources::SubmitResources(Transformations2D&, const PackedMaterialData&)
53 */
54 void SubmitResources(Transformations2D& transformations, const PackedMaterialData& materialParameters) override;
55
56 /**
57 * @copydoc IRenderResources::SubmitResources(Transformations3D&, const PackedMaterialData&)
58 */
59 void SubmitResources(Transformations3D& transformations, const PackedMaterialData& materialParameters) override;
60
61 /**
62 * @copydoc IRenderResources::Shutdown
63 */
64 void Shutdown() override;
65
66protected:
67 /**
68 * @copydoc IRendererObserver::OnRenderResourcesRelease
69 */
70 void OnRenderResourcesRelease() override;
71 /**
72 * @copydoc IRendererObserver::OnRenderResourcesRebuild
73 */
74 void OnRenderResourcesRebuild() override;
75 /**
76 * @brief Allocates and initializes all GPU buffers, descriptor sets, and pipelines for this drawable.
77 */
78 void AcquireResources();
82
83 void UpdateTransformations(Transformations2D& transformations);
84 void UpdateTransformations(Transformations3D& transformations);
85 void UpdateMaterialParameters(const PackedMaterialData& materialParameters);
86 /**
87 * @brief Issues a Vulkan draw command for the currently bound indexed mesh.
88 */
89 void DrawIndexed();
90
91private:
92 VulkanRenderer* mRenderer;
93
94 Material* mMaterial;
95 MeshDataGpu* mMeshData;
96 TextureCache* mTextureCache;
97
98 VkBuffer mVertexBuffer;
99 VkBuffer mIndexBuffer;
100
101 VkPipeline mGraphicsPipeline;
102 VkPipelineLayout mPipelineLayout;
103
104 std::vector<VkBuffer> mTransformationBuffers;
105 std::vector<VkDeviceMemory> mTransformationBuffersMemory;
106
107 std::vector<VkBuffer> mMaterialParametersBuffers;
108 std::vector<VkDeviceMemory> mMaterialParametersMemory;
109
110 VkDescriptorPool mDescriptorPool;
111 std::vector<VkDescriptorSet> mDescriptorSets;
112};
113
114} // namespace rendering_engine
Interface for rendering backend resource aggregation and submission.
Interface for observing renderer resource lifecycle events.
Represents a material instance with parameter values, texture bindings, and rendering configuration.
Definition material.hpp:30
Manages mesh data in RAM and GPU, including upload and release operations.
Manages texture loading, GPU uploading, and caching for reuse.
Vulkan implementation of IRenderResources for the Rendering Engine.
void AcquireResources()
Allocates and initializes all GPU buffers, descriptor sets, and pipelines for this drawable.
void OnRenderResourcesRebuild() override
Renderer callback: re-upload or recreate all GPU resources (used after device reset/rebuild).
void OnRenderResourcesRelease() override
Renderer callback: release all GPU resources (used during device loss/reset).
void DrawIndexed()
Issues a Vulkan draw command for the currently bound indexed mesh.
void Shutdown() override
Releases all allocated GPU resources for this object.
void UpdateTransformations(Transformations2D &transformations)
void Initialize(Material *material, MeshDataGpu *meshData, TextureCache *textureCache) override
Initializes GPU-side resources using provided material, mesh, and texture cache.
void SubmitResources(Transformations2D &transformations, const PackedMaterialData &materialParameters) override
Updates GPU resources and issues a draw call for a 2D object.
void UpdateMaterialParameters(const PackedMaterialData &materialParameters)
Vulkan-based implementation of the IRenderer interface.
Contains the raw buffer data and layout metadata of packed material parameters.
Contains transformation matrices for 2D rendering.
Contains model, view, and projection matrices for 3D rendering.