Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
rendering_engine::VulkanMaterialResources Class Reference

Vulkan-specific implementation of material render resources. More...

#include <vulkan_material_resources.hpp>

Inherits rendering_engine::IMaterialRenderResources.

Public Member Functions

 VulkanMaterialResources (VulkanRenderer *renderer)
 Constructs a VulkanMaterialResources instance.
void Initialize (Material *material) override
 Initializes Vulkan-specific GPU resources for the material.
void Shutdown () override
 Releases all Vulkan GPU resources associated with this material.
VkDescriptorSetLayout GetDescriptorSetLayout () const
 Gets the Vulkan descriptor set layout for the material.
VkPipelineLayout GetPipelineLayout () const
 Gets the Vulkan pipeline layout used by the material.
VkPipeline GetPipeline () const
 Gets the Vulkan graphics pipeline used by the material.
Public Member Functions inherited from rendering_engine::IMaterialRenderResources
virtual ~IMaterialRenderResources ()=default

Detailed Description

Vulkan-specific implementation of material render resources.

This class manages Vulkan GPU resources required to render a specific Material. It provides access to the Vulkan descriptor set layout, pipeline layout, and graphics pipeline associated with a given material. The resource creation is delegated to the owning VulkanRenderer instance.

The Material class calls Initialize and Shutdown to manage the lifecycle of these resources.

Definition at line 28 of file vulkan_material_resources.hpp.

Constructor & Destructor Documentation

◆ VulkanMaterialResources()

rendering_engine::VulkanMaterialResources::VulkanMaterialResources ( VulkanRenderer * renderer)

Constructs a VulkanMaterialResources instance.

Parameters
rendererPointer to the VulkanRenderer that provides creation utilities.

Definition at line 9 of file vulkan_material_resources.cpp.

10 :
11 mRenderer(renderer)
12{}

Member Function Documentation

◆ GetDescriptorSetLayout()

VkDescriptorSetLayout rendering_engine::VulkanMaterialResources::GetDescriptorSetLayout ( ) const

Gets the Vulkan descriptor set layout for the material.

Returns
Vulkan handle to the descriptor set layout.

Definition at line 54 of file vulkan_material_resources.cpp.

55{
56 return mDescriptorSetLayout;
57}

◆ GetPipeline()

VkPipeline rendering_engine::VulkanMaterialResources::GetPipeline ( ) const

Gets the Vulkan graphics pipeline used by the material.

Returns
Vulkan handle to the pipeline.

Definition at line 64 of file vulkan_material_resources.cpp.

65{
66 return mPipelinePair.second;
67}

◆ GetPipelineLayout()

VkPipelineLayout rendering_engine::VulkanMaterialResources::GetPipelineLayout ( ) const

Gets the Vulkan pipeline layout used by the material.

Returns
Vulkan handle to the pipeline layout.

Definition at line 59 of file vulkan_material_resources.cpp.

60{
61 return mPipelinePair.first;
62}

◆ Initialize()

void rendering_engine::VulkanMaterialResources::Initialize ( Material * material)
overridevirtual

Initializes Vulkan-specific GPU resources for the material.

Loads compiled SPIR-V shader binaries and creates descriptor set layout and pipeline.

Parameters
materialPointer to the owning Material instance.

Implements rendering_engine::IMaterialRenderResources.

Definition at line 14 of file vulkan_material_resources.cpp.

15{
16 mDescriptorSetLayout = mRenderer->CreateDescriptorSetLayout(material);
17
18 const auto matName = material->GetMaterialSettings().materialName;
19
20 std::vector<char> spvVert;
21 std::vector<char> spvFrag;
22
24 {
25 const auto& entries = Utility::GetPackEntries();
26 std::string materialEntry = "Shaders/" + matName;
27
28 std::vector<uint8_t> binaryFileDataVert = Utility::ReadPackedFile(materialEntry + "/" + std::string(matName + "_vert.spv"));
29 std::vector<uint8_t> binaryFileDataFrag = Utility::ReadPackedFile(materialEntry + "/" + std::string(matName + "_frag.spv"));
30
31 spvVert.assign(binaryFileDataVert.begin(), binaryFileDataVert.end());
32 spvFrag.assign(binaryFileDataFrag.begin(), binaryFileDataFrag.end());
33 }
34 else
35 {
36 boost::filesystem::path matPath = Utility::GetShadersFolderPath() / matName;
37
38 spvVert = Utility::ReadShaderBinaryFile((matPath / std::string(matName + "_vert.spv")).string());
39 spvFrag = Utility::ReadShaderBinaryFile((matPath / std::string(matName + "_frag.spv")).string());
40 }
41
42 mPipelinePair = mRenderer->CreateGraphicsPipeline(material, mDescriptorSetLayout, spvVert, spvFrag);
43}
static boost::filesystem::path GetShadersFolderPath()
Returns absolute path to Content/Shaders.
Definition utility.cpp:202
static std::vector< char > ReadShaderBinaryFile(std::string const &filename)
Reads a binary shader file from disk.
Definition utility.cpp:66
static const PackEntries & GetPackEntries()
Returns the manifest of packed files.
Definition utility.cpp:219
static std::vector< uint8_t > ReadPackedFile(const std::string &entryPath)
Reads raw bytes of a file stored inside Pack.bin.
Definition utility.cpp:260
static bool IsPackageProvided()
Checks whether packed assets (Pack.bin / Pack.json) exist.
Definition utility.cpp:212

◆ Shutdown()

void rendering_engine::VulkanMaterialResources::Shutdown ( )
overridevirtual

Releases all Vulkan GPU resources associated with this material.

This should be called when the renderer shuts down or resources are rebuilt.

Implements rendering_engine::IMaterialRenderResources.

Definition at line 45 of file vulkan_material_resources.cpp.

46{
47 auto vulkanLogicalDevice = mRenderer->GetLogicalDevice();
48 vkDestroyDescriptorSetLayout(vulkanLogicalDevice, mDescriptorSetLayout, nullptr);
49
50 vkDestroyPipeline(vulkanLogicalDevice, mPipelinePair.second, nullptr);
51 vkDestroyPipelineLayout(vulkanLogicalDevice, mPipelinePair.first, nullptr);
52}

The documentation for this class was generated from the following files: