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
+6
View File
@@ -62,5 +62,11 @@ public:
auto _ = entries.lock();
_->clear();
}
void remove(const Key & key)
{
auto _ = entries.lock();
_->erase(key);
}
};
} // namespace utils
+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>
+70
View File
@@ -0,0 +1,70 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "json_string.h"
std::string json_string(const std::string & in)
{
std::string out;
out.reserve(in.size() + 2);
out += '"';
for (char c: in)
{
switch (c)
{
case '\b':
out += "\\b";
break;
case '\f':
out += "\\f";
break;
case '\n':
out += "\\n";
break;
case '\r':
out += "\\r";
break;
case '\t':
out += "\\t";
break;
case '"':
out += "\\\"";
break;
case '\\':
out += "\\\\";
break;
default:
out += c;
break;
}
}
out += '"';
return out;
}
+24
View File
@@ -0,0 +1,24 @@
/*
* WiVRn VR streaming
* Copyright (C) 2024 Guillaume Meunier <guillaume.meunier@centraliens.net>
* Copyright (C) 2024 Patrick Nicolas <patricknicolas@laposte.net>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#pragma once
#include <string>
std::string json_string(const std::string & in);