Update shader loading

This commit is contained in:
2021-01-10 23:39:13 +01:00
parent 5afb752fca
commit e90c043c6b
4 changed files with 22 additions and 10 deletions

View File

@@ -5,6 +5,7 @@
*/
#include "Device.hpp"
#include "Base/Utils.hpp"
namespace openVulkanoCpp::Vulkan
{
@@ -85,16 +86,10 @@ namespace openVulkanoCpp::Vulkan
device.freeCommandBuffers(graphicsCommandPool, commandBuffer);
}
vk::ShaderModule Device::CreateShaderModule(const std::string& filename)
vk::ShaderModule Device::CreateShaderModule(const std::string& filename) const
{
std::ifstream file(filename, std::ios::ate | std::ios::binary);
if (!file.is_open()) throw std::runtime_error("Failed to open shader file!");
const size_t fileSize = static_cast<size_t>(file.tellg());
std::vector<char> buffer(fileSize);
file.seekg(0);
file.read(buffer.data(), fileSize);
file.close();
vk::ShaderModuleCreateInfo smci = { {}, buffer.size(), reinterpret_cast<const uint32_t*>(buffer.data()) };
Array<char> buffer = Utils::ReadFile(filename);
vk::ShaderModuleCreateInfo smci = { {}, buffer.Size(), reinterpret_cast<const uint32_t*>(buffer.Data()) };
return CreateShaderModule(smci);
}