Files
OpenVulkano/openVulkanoCpp/Shader/ShaderRegistry.cpp

48 lines
1.4 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "ShaderRegistry.hpp"
extern "C"
{
#include "GeneratedShaderData/GeneratedShaderData.h"
}
namespace OpenVulkano
{
ShaderRegistry& ShaderRegistry::GetInstance()
{
static ShaderRegistry instance;
return instance;
}
ShaderRegistry::ShaderRegistry()
{
RegisterShaderTable(reinterpret_cast<const ShaderTableEntry*>(fileTableBackground), fileTableBackgroundSize);
RegisterShaderTable(reinterpret_cast<const ShaderTableEntry*>(fileTableBasic), fileTableBasicSize);
RegisterShaderTable(reinterpret_cast<const ShaderTableEntry*>(fileTableGrid), fileTableGridSize);
}
void ShaderRegistry::RegisterShaderTable(const ShaderTableEntry* table, uint32_t size)
{
for (uint32_t i = 0; i < size; i++)
{
RegisterShader(table[i].entryName, { table[i].data, static_cast<size_t>(table[i].size) });
}
}
void ShaderRegistry::RegisterShader(std::string_view name, std::pair<const uint8_t*, size_t> shader)
{
m_shaderMap.emplace(name, shader);
}
std::pair<const uint8_t*, size_t> ShaderRegistry::GetShader(std::string_view shaderName)
{
auto it = m_shaderMap.find(shaderName);
if (it == m_shaderMap.end()) return { 0, 0 };
return it->second;
}
}