Cache transcoded textures

This commit is contained in:
Guillaume Meunier
2025-10-25 10:30:29 +02:00
parent 7d76367d2c
commit a9ad5195b7
13 changed files with 421 additions and 59 deletions
+19 -6
View File
@@ -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>