Cache transcoded textures
This commit is contained in:
+19
-6
@@ -21,12 +21,13 @@
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iterator>
|
||||
#include <type_traits>
|
||||
#include <vector>
|
||||
|
||||
namespace utils
|
||||
{
|
||||
template <typename T>
|
||||
static std::vector<T> read_whole_file(std::filesystem::path filename)
|
||||
static std::conditional_t<std::is_same_v<T, std::string>, std::string, std::vector<T>> read_whole_file(std::filesystem::path filename)
|
||||
{
|
||||
std::ifstream file(filename, std::ios::binary | std::ios::ate);
|
||||
file.exceptions(std::ios_base::badbit | std::ios_base::failbit);
|
||||
@@ -34,14 +35,26 @@ static std::vector<T> read_whole_file(std::filesystem::path filename)
|
||||
size_t size = file.tellg();
|
||||
file.seekg(0);
|
||||
|
||||
if constexpr (sizeof(T) > 1)
|
||||
size = size - size % sizeof(T);
|
||||
if constexpr (std::is_same_v<T, std::string>)
|
||||
{
|
||||
std::string string;
|
||||
string.resize(size);
|
||||
|
||||
std::vector<T> bytes(size / sizeof(T));
|
||||
file.read(reinterpret_cast<char *>(string.data()), size);
|
||||
|
||||
file.read(reinterpret_cast<char *>(bytes.data()), size);
|
||||
return string;
|
||||
}
|
||||
else
|
||||
{
|
||||
if constexpr (sizeof(T) > 1)
|
||||
size = size - size % sizeof(T);
|
||||
|
||||
return bytes;
|
||||
std::vector<T> bytes(size / sizeof(T));
|
||||
|
||||
file.read(reinterpret_cast<char *>(bytes.data()), size);
|
||||
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
||||
Reference in New Issue
Block a user