Update shader bundling to be included in binary

This commit is contained in:
2021-02-16 21:32:27 +01:00
parent b53b4b0ca1
commit 053cc5b391
7 changed files with 274 additions and 331 deletions

View File

@@ -6,6 +6,7 @@
#include "Device.hpp"
#include "Base/Utils.hpp"
#include "Shader/Shaders.h"
namespace openVulkanoCpp::Vulkan
{
@@ -88,8 +89,27 @@ namespace openVulkanoCpp::Vulkan
vk::ShaderModule Device::CreateShaderModule(const std::string& filename) const
{
Array<char> buffer = Utils::ReadFile(filename);
vk::ShaderModuleCreateInfo smci = { {}, buffer.Size(), reinterpret_cast<const uint32_t*>(buffer.Data()) };
Array<char> buffer;
void* data = nullptr;
size_t size = 0;
if (Utils::StartsWith(filename, "Shader/"))
{
for(uint32_t i = 0; i < fileTableSize; i++)
{
if (Utils::EndsWith(filename, fileTable[i].entryName))
{
data = const_cast<unsigned char*>(fileTable[i].data);
size = fileTable[i].size;
}
}
}
if (!data)
{
buffer = Utils::ReadFile(filename);
size = buffer.Size();
data = buffer.Data();
}
vk::ShaderModuleCreateInfo smci = {{}, size, static_cast<const uint32_t*>(data) };
return CreateShaderModule(smci);
}
@@ -217,4 +237,4 @@ namespace openVulkanoCpp::Vulkan
device.destroyCommandPool(graphicsCommandPool);
//TODO fill
}
}
}