mirror of https://github.com/AxioDL/metaforce.git
Minor fixes, more CModel RE
This commit is contained in:
parent
e48435f11e
commit
3ba2c4bfff
|
@ -39,11 +39,8 @@ pub(crate) fn initialize_imgui(window: &winit::window::Window, gpu: &DeviceHolde
|
|||
ffi::ImGuiEngine_Initialize(hidpi_factor as f32);
|
||||
}
|
||||
|
||||
let renderer_config = if gpu.backend == wgpu::Backend::Vulkan {
|
||||
imgui_backend::RendererConfig::new_spv_srgb()
|
||||
} else {
|
||||
imgui_backend::RendererConfig::new_srgb()
|
||||
};
|
||||
let renderer_config = imgui_backend::RendererConfig::new_srgb();
|
||||
|
||||
let imgui_backend = imgui_backend::Renderer::new(
|
||||
&mut imgui,
|
||||
&gpu.device,
|
||||
|
|
|
@ -272,28 +272,6 @@ impl RendererConfig<'_> {
|
|||
pub fn new_srgb() -> Self {
|
||||
Self::with_combined_shaders(include_wgsl!("imgui.wgsl"), FS_ENTRY_POINT_SRGB)
|
||||
}
|
||||
|
||||
/// Create a new renderer config with precompiled default shaders outputting linear color.
|
||||
///
|
||||
/// If you write to a Bgra8UnormSrgb framebuffer, this is what you want.
|
||||
pub fn new_spv() -> Self {
|
||||
Self::with_separate_shaders(
|
||||
include_spirv_raw!("imgui_vs_main.spv"),
|
||||
include_spirv_raw!("imgui_fs_main_linear.spv"),
|
||||
FS_ENTRY_POINT_LINEAR,
|
||||
)
|
||||
}
|
||||
|
||||
/// Create a new renderer config with precompiled default shaders outputting srgb color.
|
||||
///
|
||||
/// If you write to a Bgra8Unorm framebuffer, this is what you want.
|
||||
pub fn new_spv_srgb() -> Self {
|
||||
Self::with_separate_shaders(
|
||||
include_spirv_raw!("imgui_vs_main.spv"),
|
||||
include_spirv_raw!("imgui_fs_main_srgb.spv"),
|
||||
FS_ENTRY_POINT_SRGB,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Renderer {
|
||||
|
|
|
@ -3,6 +3,12 @@
|
|||
#include "CGraphics.hpp"
|
||||
|
||||
namespace metaforce {
|
||||
u32 CModel::sFrameCounter = 0;
|
||||
bool CModel::sIsTextureTimeoutEnabled = true;
|
||||
CModel* CModel::sThisFrameList = nullptr;
|
||||
CModel* CModel::sOneFrameList = nullptr;
|
||||
CModel* CModel::sTwoFrameList = nullptr;
|
||||
|
||||
static const u8* MemoryFromPartData(const u8*& dataCur, const u32*& secSizeCur) {
|
||||
const u8* ret = nullptr;
|
||||
if (*secSizeCur != 0) {
|
||||
|
@ -14,23 +20,85 @@ static const u8* MemoryFromPartData(const u8*& dataCur, const u32*& secSizeCur)
|
|||
}
|
||||
|
||||
CModel::CModel(std::unique_ptr<u8[]> in, u32 dataLen, IObjectStore* store)
|
||||
: x0_data(std::move(in)), x4_dataLen(dataLen), x38_lastFrame(CGraphics::GetFrameCounter() - 2) {
|
||||
: x0_data(std::move(in)), x4_dataLen(dataLen), x34_next(sThisFrameList), x38_lastFrame(CGraphics::GetFrameCounter() - 2) {
|
||||
const u8* data = reinterpret_cast<const u8*>(x0_data.get());
|
||||
u32 uVar1 = *reinterpret_cast<const u32*>(data + 8);
|
||||
u32 sectionSizeStart = 0x2c;
|
||||
if (*reinterpret_cast<const u32*>(data + 4) == 1) {
|
||||
if (hecl::SBig(*reinterpret_cast<const u32*>(data + 4)) == 1) {
|
||||
sectionSizeStart = 0x28;
|
||||
}
|
||||
const u32* secSizeCur = reinterpret_cast<const u32*>(data + sectionSizeStart);
|
||||
s32 numMatSets = 1;
|
||||
if (*reinterpret_cast<const u32*>(data + 4) > 1) {
|
||||
numMatSets = *reinterpret_cast<const s32*>(data + 0x28);
|
||||
if (hecl::SBig(*reinterpret_cast<const u32*>(data + 4)) > 1) {
|
||||
numMatSets = hecl::SBig(*reinterpret_cast<const s32*>(data + 0x28));
|
||||
}
|
||||
const auto* dataCur = data + (sectionSizeStart + *reinterpret_cast<const s32*>(data + 0x24) * 4 + 0x1f & 0xffffffe0);
|
||||
const auto* dataCur = data + ROUND_UP_32(sectionSizeStart + hecl::SBig(*reinterpret_cast<const s32*>(data + 0x24)) * 4);
|
||||
x18_matSets.reserve(numMatSets);
|
||||
for (int i = 0; i < numMatSets; i += 1) {
|
||||
x18_matSets.emplace_back(
|
||||
const_cast<CCubeModel*>(reinterpret_cast<const CCubeModel*>(MemoryFromPartData(dataCur, secSizeCur))));
|
||||
for (s32 i = 0; i < numMatSets; ++i) {
|
||||
x18_matSets.emplace_back(static_cast<const u8*>(MemoryFromPartData(dataCur, secSizeCur)));
|
||||
auto shader = x18_matSets.back();
|
||||
CCubeModel::MakeTexturesFromMats(shader.x10_data, shader.x0_textures, true);
|
||||
}
|
||||
}
|
||||
|
||||
void CModel::UpdateLastFrame() { x38_lastFrame = CGraphics::GetFrameCounter(); }
|
||||
void CModel::MoveToThisFrameList() {
|
||||
UpdateLastFrame();
|
||||
CModel* ptr = sThisFrameList;
|
||||
if (sThisFrameList != this) {
|
||||
RemoveFromList();
|
||||
if (sThisFrameList != nullptr) {
|
||||
x34_next = sThisFrameList;
|
||||
x34_next->x30_prev = this;
|
||||
}
|
||||
ptr = this;
|
||||
}
|
||||
|
||||
sThisFrameList = ptr;
|
||||
}
|
||||
|
||||
void CModel::RemoveFromList() {
|
||||
if (x30_prev == nullptr) {
|
||||
if (sThisFrameList == this) {
|
||||
sThisFrameList = x34_next;
|
||||
} else if (sOneFrameList == this) {
|
||||
sOneFrameList = x34_next;
|
||||
} else if (sTwoFrameList == this) {
|
||||
sTwoFrameList = x34_next;
|
||||
}
|
||||
} else {
|
||||
x30_prev->x34_next = x34_next;
|
||||
}
|
||||
if (x34_next != nullptr) {
|
||||
x34_next->x30_prev = x30_prev;
|
||||
}
|
||||
x30_prev = nullptr;
|
||||
x34_next = nullptr;
|
||||
}
|
||||
|
||||
void CModel::FrameDone() {
|
||||
++sFrameCounter;
|
||||
auto* iter = sTwoFrameList;
|
||||
if (sIsTextureTimeoutEnabled) {
|
||||
while (iter != nullptr) {
|
||||
auto* next = iter->x34_next;
|
||||
iter->VerifyCurrentShader(0);
|
||||
for (auto& shader : iter->x18_matSets) {
|
||||
shader.UnlockTextures();
|
||||
}
|
||||
|
||||
iter->x28_modelInst->UnlockTextures();
|
||||
iter->x34_next = nullptr;
|
||||
iter->x30_prev = nullptr;
|
||||
iter = next;
|
||||
}
|
||||
|
||||
sTwoFrameList = sOneFrameList;
|
||||
sOneFrameList = sThisFrameList;
|
||||
sThisFrameList = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void CModel::EnableTextureTimeout() { sIsTextureTimeoutEnabled = true; }
|
||||
void CModel::DisableTextureTimeout() { sIsTextureTimeoutEnabled = false; }
|
||||
} // namespace metaforce
|
||||
|
|
|
@ -10,28 +10,51 @@
|
|||
|
||||
namespace metaforce {
|
||||
class CCubeSurface;
|
||||
class CCubeModel;
|
||||
class CCubeModel {
|
||||
public:
|
||||
void UnlockTextures() {}
|
||||
|
||||
struct SShader {
|
||||
std::vector<TCachedToken<CTexture>> x0_textures;
|
||||
CCubeModel* x10_model;
|
||||
|
||||
SShader(CCubeModel* model) : x10_model(model) {}
|
||||
static void MakeTexturesFromMats(const u8* ptr, std::vector<TCachedToken<CTexture>>& texture, bool b1) {}
|
||||
};
|
||||
|
||||
class CModel {
|
||||
public:
|
||||
struct SShader {
|
||||
std::vector<TCachedToken<CTexture>> x0_textures;
|
||||
const u8* x10_data;
|
||||
|
||||
SShader(const u8* data) : x10_data(data) {}
|
||||
|
||||
void UnlockTextures() {};
|
||||
};
|
||||
|
||||
private:
|
||||
static u32 sFrameCounter;
|
||||
static bool sIsTextureTimeoutEnabled;
|
||||
static CModel* sThisFrameList;
|
||||
static CModel* sOneFrameList;
|
||||
static CModel* sTwoFrameList;
|
||||
|
||||
std::unique_ptr<u8[]> x0_data;
|
||||
u32 x4_dataLen;
|
||||
std::vector<CCubeSurface*> x8_surfaces;
|
||||
std::vector<SShader> x18_matSets;
|
||||
CCubeModel* x28_modelInst;
|
||||
u16 x2c_;
|
||||
u16 x2e_;
|
||||
CModel* x30_next;
|
||||
CModel* x34_prev;
|
||||
CCubeModel* x28_modelInst = nullptr;
|
||||
u16 x2c_ = 0;
|
||||
u16 x2e_ = 0;
|
||||
CModel* x30_prev = nullptr;
|
||||
CModel* x34_next;
|
||||
u32 x38_lastFrame;
|
||||
|
||||
public:
|
||||
CModel(std::unique_ptr<u8[]> in, u32 dataLen, IObjectStore* store);
|
||||
|
||||
void UpdateLastFrame();
|
||||
void MoveToThisFrameList();
|
||||
void RemoveFromList();
|
||||
void VerifyCurrentShader(s32 idx) {};
|
||||
static void FrameDone();
|
||||
static void EnableTextureTimeout();
|
||||
static void DisableTextureTimeout();
|
||||
};
|
||||
} // namespace metaforce
|
||||
|
|
Loading…
Reference in New Issue