diff options
| author | inspectredc <inspectredc@gmail.com> | 2025-03-04 11:46:25 +0000 |
|---|---|---|
| committer | Lywx <kiritodev01@gmail.com> | 2025-03-09 17:26:40 -0600 |
| commit | c9c479c5c3c3bd3c652c30b4740c85d47a0fc5fa (patch) | |
| tree | 0d4108d5d1378b9004adc278e5e0bae5cdcaaa18 /src/factories/CompressedTextureFactory.cpp | |
| parent | 6ca699d508d2b62ab51d290e6a38a1a24f7d83cf (diff) | |
texture macros
Diffstat (limited to 'src/factories/CompressedTextureFactory.cpp')
| -rw-r--r-- | src/factories/CompressedTextureFactory.cpp | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/src/factories/CompressedTextureFactory.cpp b/src/factories/CompressedTextureFactory.cpp index 4d30bc2..6608afa 100644 --- a/src/factories/CompressedTextureFactory.cpp +++ b/src/factories/CompressedTextureFactory.cpp @@ -38,7 +38,7 @@ ExportResult CompressedTextureHeaderExporter::Export(std::ostream &write, std::s const auto symbol = GetSafeNode(node, "symbol", entryName); const auto offset = GetSafeNode<uint32_t>(node, "offset"); auto format = GetSafeNode<std::string>(node, "format"); - auto texture = std::static_pointer_cast<TextureData>(raw); + auto texture = std::static_pointer_cast<CompressedTextureData>(raw); auto data = texture->mBuffer; auto isOTR = Companion::Instance->IsOTRMode(); size_t byteSize = std::max(1, (int) (texture->mFormat.depth / 8)); @@ -70,6 +70,25 @@ ExportResult CompressedTextureHeaderExporter::Export(std::ostream &write, std::s write << "static const ALIGN_ASSET(2) char " << symbol << "[] = \"__OTR__" << (*replacement) << "\";\n\n"; } else { write << "extern " << "u8 " << symbol << "[];\n"; + // Allocate worse case size + uint8_t* compressedData; + size_t compressedSize; + size_t worstSize; + + switch (texture->mCompressionType) { + case CompressionType::MIO0: + worstSize = MIO0_HEADER_LENGTH + ((data.size()+7)/8) + data.size(); + compressedData = static_cast<uint8_t*>(std::calloc(worstSize, sizeof(uint8_t))); + compressedSize = mio0_encode(data.data(), data.size(), compressedData); + break; + default: + // UNIMPLEMENTED + throw std::runtime_error("Unsupported Compressed Texture Type"); + break; + } + write << "#define _" << symbol << "_COMPRESSED_SIZE 0x" << std::hex << compressedSize << std::dec << "\n"; + write << "#define _" << symbol << "_WIDTH 0x" << std::hex << texture->mWidth << std::dec << "\n"; + write << "#define _" << symbol << "_HEIGHT 0x" << std::hex << texture->mHeight << std::dec << "\n"; } } |
