From d10f6a6afc401d4d1dad5491413113d4da542956 Mon Sep 17 00:00:00 2001 From: riidefi <34194588+riidefi@users.noreply.github.com> Date: Thu, 21 Jan 2021 00:05:03 -0700 Subject: [PATCH] :bug: TEX0: Automate LOD range calculation --- source/plugins/g3d/io/TEX0.cpp | 7 +++++-- source/plugins/g3d/texture.hpp | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/source/plugins/g3d/io/TEX0.cpp b/source/plugins/g3d/io/TEX0.cpp index 74095b5f9..b10a3c46c 100644 --- a/source/plugins/g3d/io/TEX0.cpp +++ b/source/plugins/g3d/io/TEX0.cpp @@ -19,8 +19,9 @@ void writeTexture(const Texture& data, oishii::Writer& writer, writer.write(data.height); writer.write(static_cast(data.format)); writer.write(data.mipLevel); - writer.write(data.minLod); - writer.write(data.maxLod); + writer.write(data.custom_lod ? data.minLod : 0.0f); + writer.write(data.custom_lod ? data.maxLod + : static_cast(data.mipLevel - 1)); writer.write(0); // src path writer.write(0); // user data writer.alignTo(32); // Assumes already 32b aligned @@ -48,6 +49,8 @@ void readTexture(Texture& data, oishii::BinaryReader& reader) { data.mipLevel = reader.read(); data.minLod = reader.read(); data.maxLod = reader.read(); + data.custom_lod = data.minLod != 0.0f || + data.maxLod != static_cast(data.mipLevel - 1); data.sourcePath = readName(reader, start); // Skip user data reader.seekSet(start + ofsTex); diff --git a/source/plugins/g3d/texture.hpp b/source/plugins/g3d/texture.hpp index d1d5fd259..d097aa919 100644 --- a/source/plugins/g3d/texture.hpp +++ b/source/plugins/g3d/texture.hpp @@ -16,6 +16,7 @@ struct TextureData { u32 height = 32; u32 mipLevel{1}; // 1 - no mipmaps + bool custom_lod = false; f32 minLod{0.0f}; f32 maxLod{1.0f};