metaforce/Editor/badging/Badging.cpp

46 lines
1.4 KiB
C++
Raw Normal View History

2016-07-16 12:21:12 -07:00
#include "Badging.hpp"
#include "athena/MemoryReader.hpp"
#include <specter/Icon.hpp>
2016-07-16 12:21:12 -07:00
#include <zlib.h>
extern "C" uint8_t URDE_BADGE[];
extern "C" size_t URDE_BADGE_SZ;
2021-04-10 01:42:06 -07:00
namespace metaforce {
2016-07-16 12:21:12 -07:00
static logvisor::Module Log("URDE::badging");
static specter::Icon g_BadgeIcon;
2018-12-07 21:30:43 -08:00
void InitializeBadging(specter::ViewResources& viewRes) {
athena::io::MemoryReader r(URDE_BADGE, URDE_BADGE_SZ);
size_t fmt = r.readUint32Big();
if (fmt != 16)
2020-04-11 15:51:39 -07:00
Log.report(logvisor::Fatal, FMT_STRING("incorrect icon texture format"));
2018-12-07 21:30:43 -08:00
size_t width = r.readUint16Big();
size_t height = r.readUint16Big();
size_t mips = r.readUint32Big();
size_t decompSz = r.readUint32Big();
std::unique_ptr<uint8_t[]> texels(new uint8_t[decompSz]);
uLongf destSz = decompSz;
size_t pos = r.position();
if (uncompress(texels.get(), &destSz, URDE_BADGE + pos, URDE_BADGE_SZ - pos) != Z_OK)
2020-04-11 15:51:39 -07:00
Log.report(logvisor::Fatal, FMT_STRING("unable to decompress badge"));
2018-12-07 21:30:43 -08:00
viewRes.m_factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) {
specter::IconAtlas<1, 1> atlas;
atlas.initializeAtlas(ctx.newStaticTexture(width, height, mips, boo::TextureFormat::RGBA8,
boo::TextureClampMode::Repeat, texels.get(), destSz));
g_BadgeIcon = atlas.getIcon(0, 0);
return true;
} BooTrace);
2016-07-16 12:21:12 -07:00
}
2018-12-07 21:30:43 -08:00
void DestroyBadging() { g_BadgeIcon.m_tex.reset(); }
2018-12-07 21:30:43 -08:00
specter::Icon& GetBadge() { return g_BadgeIcon; }
2016-07-16 12:21:12 -07:00
2021-04-10 01:42:06 -07:00
} // namespace metaforce