Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
vulkan_material_resources.cpp
Go to the documentation of this file.
2#include "vulkan_renderer.hpp"
3#include "material.hpp"
4#include "utility.hpp"
5
6namespace rendering_engine
7{
8
10 :
11 mRenderer(renderer)
12{}
13
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}
44
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}
53
55{
56 return mDescriptorSetLayout;
57}
58
60{
61 return mPipelinePair.first;
62}
63
65{
66 return mPipelinePair.second;
67}
68
69} // namespace rendering_engine
Represents a material instance with parameter values, texture bindings, and rendering configuration.
Definition material.hpp:30
const MaterialSettings GetMaterialSettings() const
Returns the material's static settings (domain, blend mode, shading model, etc.).
Definition material.cpp:16
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
VkPipeline GetPipeline() const
Gets the Vulkan graphics pipeline used by the material.
void Shutdown() override
Releases all Vulkan GPU resources associated with this material.
void Initialize(Material *material) override
Initializes Vulkan-specific GPU resources for the material.
VkPipelineLayout GetPipelineLayout() const
Gets the Vulkan pipeline layout used by the material.
VulkanMaterialResources(VulkanRenderer *renderer)
Constructs a VulkanMaterialResources instance.
VkDescriptorSetLayout GetDescriptorSetLayout() const
Gets the Vulkan descriptor set layout for the material.
Vulkan-based implementation of the IRenderer interface.