2022-02-27 02:18:58 +00:00
|
|
|
#include "Runtime/Graphics/CGraphicsPalette.hpp"
|
|
|
|
#include "Runtime/Streams/CInputStream.hpp"
|
|
|
|
|
|
|
|
namespace metaforce {
|
|
|
|
u32 CGraphicsPalette::sCurrentFrameCount = 0;
|
|
|
|
|
|
|
|
CGraphicsPalette::CGraphicsPalette(EPaletteFormat fmt, int count)
|
2022-05-19 07:57:30 +00:00
|
|
|
: x0_fmt(fmt), x8_entryCount(count), xc_entries(std::make_unique<u16[]>(count)) {
|
2022-05-13 23:40:19 +00:00
|
|
|
GXInitTlutObj(&x10_tlutObj, xc_entries.get(), static_cast<GXTlutFmt>(x0_fmt), x8_entryCount);
|
2022-02-27 02:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CGraphicsPalette::CGraphicsPalette(CInputStream& in) : x0_fmt(EPaletteFormat(in.ReadLong())) {
|
|
|
|
u16 w = in.ReadShort();
|
|
|
|
u16 h = in.ReadShort();
|
|
|
|
x8_entryCount = w * h;
|
2022-05-19 07:57:30 +00:00
|
|
|
xc_entries = std::make_unique<u16[]>(x8_entryCount);
|
|
|
|
in.Get(reinterpret_cast<u8*>(xc_entries.get()), x8_entryCount * sizeof(u16));
|
2022-05-13 23:40:19 +00:00
|
|
|
GXInitTlutObj(&x10_tlutObj, xc_entries.get(), static_cast<GXTlutFmt>(x0_fmt), x8_entryCount);
|
|
|
|
// DCFlushRange(xc_entries.get(), x8_entryCount * 2);
|
2022-02-27 02:18:58 +00:00
|
|
|
}
|
|
|
|
|
2022-03-03 07:51:11 +00:00
|
|
|
void CGraphicsPalette::Load() {
|
2022-05-13 23:40:19 +00:00
|
|
|
GXLoadTlut(&x10_tlutObj, GX_TLUT0);
|
2022-03-03 07:51:11 +00:00
|
|
|
x4_frameLoaded = sCurrentFrameCount;
|
|
|
|
}
|
2022-05-13 23:40:19 +00:00
|
|
|
|
|
|
|
void CGraphicsPalette::UnLock() {
|
|
|
|
// DCStoreRange(xc_lut, x8_numEntries << 1);
|
|
|
|
GXInitTlutObj(&x10_tlutObj, xc_entries.get(), static_cast<GXTlutFmt>(x0_fmt), x8_entryCount);
|
|
|
|
// DCFlushRange(xc_lut, x8_numEntries << 1);
|
|
|
|
x1c_locked = false;
|
|
|
|
}
|
|
|
|
} // namespace metaforce
|