mirror of
https://github.com/open-goal/jak-project
synced 2026-08-07 02:06:59 -04:00
[graphics] Rewrite of texture system (#1212)
* loading cleanup * temp * add texture replacement * fix windows * oops * fix windows * final cleanup
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "third-party/fmt/core.h"
|
||||
#include "common/util/Assert.h"
|
||||
#include "third-party/stb_image.h"
|
||||
#include <filesystem>
|
||||
|
||||
namespace decompiler {
|
||||
|
||||
@@ -11,7 +13,8 @@ void TextureDB::add_texture(u32 tpage,
|
||||
u16 w,
|
||||
u16 h,
|
||||
const std::string& tex_name,
|
||||
const std::string& tpage_name) {
|
||||
const std::string& tpage_name,
|
||||
const std::vector<std::string>& level_names) {
|
||||
auto existing_tpage_name = tpage_names.find(tpage);
|
||||
if (existing_tpage_name == tpage_names.end()) {
|
||||
tpage_names[tpage] = tpage_name;
|
||||
@@ -35,6 +38,30 @@ void TextureDB::add_texture(u32 tpage,
|
||||
new_tex.h = h;
|
||||
new_tex.page = tpage;
|
||||
}
|
||||
for (const auto& level_name : level_names) {
|
||||
texture_ids_per_level[level_name].insert(combo_id);
|
||||
}
|
||||
}
|
||||
|
||||
void TextureDB::replace_textures(const std::string& path) {
|
||||
std::filesystem::path base_path(path);
|
||||
for (auto& tex : textures) {
|
||||
std::filesystem::path full_path =
|
||||
base_path / tpage_names.at(tex.second.page) / (tex.second.name + ".png");
|
||||
if (std::filesystem::exists(full_path)) {
|
||||
fmt::print("Replacing {}\n", full_path.string().c_str());
|
||||
int w, h;
|
||||
auto data = stbi_load(full_path.string().c_str(), &w, &h, 0, 4); // rgba channels
|
||||
if (!data) {
|
||||
fmt::print("failed to load PNG file: {}\n", full_path.string().c_str());
|
||||
continue;
|
||||
}
|
||||
tex.second.rgba_bytes.resize(w * h);
|
||||
memcpy(tex.second.rgba_bytes.data(), data, w * h * 4);
|
||||
tex.second.w = w;
|
||||
tex.second.h = h;
|
||||
stbi_image_free(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace decompiler
|
||||
|
||||
Reference in New Issue
Block a user