Update shader loading
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
#include <Windows.h>
|
||||
#else
|
||||
#include <pthread.h>
|
||||
#include <fstream>
|
||||
|
||||
#endif
|
||||
|
||||
namespace openVulkanoCpp
|
||||
@@ -24,4 +26,16 @@ namespace openVulkanoCpp
|
||||
pthread_setname_np(pthread_self(), name.c_str());
|
||||
#endif
|
||||
}
|
||||
|
||||
Array<char> Utils::ReadFile(const std::string& filePath)
|
||||
{
|
||||
std::ifstream file(filePath, std::ios::ate | std::ios::binary);
|
||||
if (!file.is_open()) throw std::runtime_error("Failed to open file '" + filePath + "'!");
|
||||
const size_t fileSize = static_cast<size_t>(file.tellg());
|
||||
Array<char> data(fileSize);
|
||||
file.seekg(0);
|
||||
file.read(data.Data(), fileSize);
|
||||
file.close();
|
||||
return data;
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include "Data/Containers/Array.hpp"
|
||||
|
||||
namespace openVulkanoCpp
|
||||
{
|
||||
@@ -124,5 +125,7 @@ namespace openVulkanoCpp
|
||||
{
|
||||
return str.size() >= suffix.size() && 0 == str.compare(str.size()-suffix.size(), suffix.size(), suffix);
|
||||
}
|
||||
|
||||
static Array<char> ReadFile(const std::string& filePath);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ namespace openVulkanoCpp
|
||||
|
||||
void ExecuteNow(const std::function<void(const vk::CommandBuffer& commandBuffer)>& function) const;
|
||||
|
||||
vk::ShaderModule CreateShaderModule(const std::string& filename);
|
||||
vk::ShaderModule CreateShaderModule(const std::string& filename) const;
|
||||
|
||||
vk::ShaderModule CreateShaderModule(vk::ShaderModuleCreateInfo& createInfo) const;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user