mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-12-09 21:07:42 +00:00
Async resource build fixes
This commit is contained in:
@@ -156,6 +156,7 @@ zeus::CMatrix4f CGraphics::CalculatePerspectiveMatrix(float fovy, float aspect,
|
||||
|
||||
zeus::CMatrix4f CGraphics::GetPerspectiveProjectionMatrix()
|
||||
{
|
||||
CProjectionState& ref = g_Proj;
|
||||
float rml = g_Proj.x8_right - g_Proj.x4_left;
|
||||
float rpl = g_Proj.x8_right + g_Proj.x4_left;
|
||||
float tmb = g_Proj.xc_top - g_Proj.x10_bottom;
|
||||
|
||||
@@ -117,36 +117,26 @@ void CBooModel::UnlockTextures() const
|
||||
|
||||
void CBooModel::DrawAlphaSurfaces(const CModelFlags& flags) const
|
||||
{
|
||||
if (TryLockTextures())
|
||||
const CBooSurface* surf = x3c_firstSortedSurface;
|
||||
while (surf)
|
||||
{
|
||||
const CBooSurface* surf = x3c_firstSortedSurface;
|
||||
while (surf)
|
||||
{
|
||||
DrawSurface(*surf, flags);
|
||||
surf = surf->m_next;
|
||||
}
|
||||
DrawSurface(*surf, flags);
|
||||
surf = surf->m_next;
|
||||
}
|
||||
}
|
||||
|
||||
void CBooModel::DrawNormalSurfaces(const CModelFlags& flags) const
|
||||
{
|
||||
if (TryLockTextures())
|
||||
const CBooSurface* surf = x38_firstUnsortedSurface;
|
||||
while (surf)
|
||||
{
|
||||
const CBooSurface* surf = x38_firstUnsortedSurface;
|
||||
while (surf)
|
||||
{
|
||||
DrawSurface(*surf, flags);
|
||||
surf = surf->m_next;
|
||||
}
|
||||
DrawSurface(*surf, flags);
|
||||
surf = surf->m_next;
|
||||
}
|
||||
}
|
||||
|
||||
void CBooModel::DrawSurfaces(const CModelFlags& flags) const
|
||||
{
|
||||
if (!(flags.m_flags & 0x4))
|
||||
if (!TryLockTextures())
|
||||
return;
|
||||
|
||||
const CBooSurface* surf = x38_firstUnsortedSurface;
|
||||
while (surf)
|
||||
{
|
||||
@@ -300,20 +290,29 @@ void CBooModel::UpdateUniformData() const
|
||||
|
||||
void CBooModel::DrawAlpha(const CModelFlags& flags) const
|
||||
{
|
||||
UpdateUniformData();
|
||||
DrawAlphaSurfaces(flags);
|
||||
if (TryLockTextures())
|
||||
{
|
||||
UpdateUniformData();
|
||||
DrawAlphaSurfaces(flags);
|
||||
}
|
||||
}
|
||||
|
||||
void CBooModel::DrawNormal(const CModelFlags& flags) const
|
||||
{
|
||||
UpdateUniformData();
|
||||
DrawNormalSurfaces(flags);
|
||||
if (TryLockTextures())
|
||||
{
|
||||
UpdateUniformData();
|
||||
DrawNormalSurfaces(flags);
|
||||
}
|
||||
}
|
||||
|
||||
void CBooModel::Draw(const CModelFlags& flags) const
|
||||
{
|
||||
UpdateUniformData();
|
||||
DrawSurfaces(flags);
|
||||
if (TryLockTextures())
|
||||
{
|
||||
UpdateUniformData();
|
||||
DrawSurfaces(flags);
|
||||
}
|
||||
}
|
||||
|
||||
static const u8* MemoryFromPartData(const u8*& dataCur, const s32*& secSizeCur)
|
||||
@@ -378,7 +377,7 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store)
|
||||
{
|
||||
hecl::Runtime::ShaderTag tag(mat.heclIr,
|
||||
hmdlMeta.colorCount, hmdlMeta.uvCount, hmdlMeta.weightCount,
|
||||
0, mat.uvAnims.size(), true, true, true);
|
||||
0, mat.uvAnims.size(), false, false, true);
|
||||
matSet.m_shaders.push_back(CGraphics::g_ShaderCacheMgr->buildShader(tag, mat.heclIr, "CMDL", ctx));
|
||||
}
|
||||
}
|
||||
@@ -403,7 +402,7 @@ CModel::CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store)
|
||||
hecl::SBig(aabbPtr[3]), hecl::SBig(aabbPtr[4]), hecl::SBig(aabbPtr[5]));
|
||||
x28_modelInst = std::make_unique<CBooModel>(&x8_surfaces, x18_matSets[0],
|
||||
m_vtxFmt, m_vbo, m_ibo,
|
||||
aabb, flags & 0x2, true);
|
||||
aabb, flags & 0x2, false);
|
||||
}
|
||||
|
||||
void CBooModel::SShader::UnlockTextures()
|
||||
@@ -465,7 +464,8 @@ CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag,
|
||||
const urde::CVParamTransfer& vparms)
|
||||
{
|
||||
IObjectStore* store = static_cast<TObjOwnerParam<IObjectStore*>*>(vparms.GetObj())->GetParam();
|
||||
return TToken<CModel>::GetIObjObjectFor(std::make_unique<CModel>(std::move(in), len, store));
|
||||
CFactoryFnReturn ret = TToken<CModel>::GetIObjObjectFor(std::make_unique<CModel>(std::move(in), len, store));
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,10 +34,10 @@ class CTexture
|
||||
void BuildRGB5A3FromGCN(CInputStream& in);
|
||||
void BuildRGBA8FromGCN(CInputStream& in);
|
||||
void BuildDXT1FromGCN(CInputStream& in);
|
||||
void BuildRGBA8(CInputStream& in);
|
||||
void BuildRGBA8(const void* data);
|
||||
|
||||
public:
|
||||
CTexture(CInputStream& in);
|
||||
CTexture(std::unique_ptr<u8[]>&& in, u32 length);
|
||||
enum class EClampMode
|
||||
{
|
||||
None,
|
||||
@@ -50,7 +50,9 @@ public:
|
||||
boo::ITexture* GetBooTexture() {return m_booTex;}
|
||||
};
|
||||
|
||||
CFactoryFnReturn FTextureFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms);
|
||||
CFactoryFnReturn FTextureFactory(const urde::SObjectTag& tag,
|
||||
std::unique_ptr<u8[]>&& in, u32 len,
|
||||
const urde::CVParamTransfer& vparms);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -648,63 +648,64 @@ void CTexture::BuildDXT1FromGCN(CInputStream& in)
|
||||
});
|
||||
}
|
||||
|
||||
void CTexture::BuildRGBA8(CInputStream& in)
|
||||
void CTexture::BuildRGBA8(const void* data)
|
||||
{
|
||||
size_t texelCount = ComputeMippedTexelCount();
|
||||
std::unique_ptr<atInt8[]> buf = in.readBytes(texelCount * 4);
|
||||
|
||||
m_booToken = CGraphics::CommitResources([&](boo::IGraphicsDataFactory::Context& ctx) -> bool
|
||||
{
|
||||
m_booTex = ctx.newStaticTexture(x4_w, x6_h, x8_mips, boo::TextureFormat::RGBA8,
|
||||
buf.get(), texelCount * 4);
|
||||
data, texelCount * 4);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
CTexture::CTexture(CInputStream& in)
|
||||
CTexture::CTexture(std::unique_ptr<u8[]>&& in, u32 length)
|
||||
{
|
||||
x0_fmt = ETexelFormat(in.readUint32Big());
|
||||
x4_w = in.readUint16Big();
|
||||
x6_h = in.readUint16Big();
|
||||
x8_mips = in.readUint32Big();
|
||||
std::unique_ptr<u8[]> owned = std::move(in);
|
||||
athena::io::MemoryReader r(owned.get(), length);
|
||||
x0_fmt = ETexelFormat(r.readUint32Big());
|
||||
x4_w = r.readUint16Big();
|
||||
x6_h = r.readUint16Big();
|
||||
x8_mips = r.readUint32Big();
|
||||
|
||||
switch (x0_fmt)
|
||||
{
|
||||
case ETexelFormat::I4:
|
||||
BuildI4FromGCN(in);
|
||||
BuildI4FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::I8:
|
||||
BuildI8FromGCN(in);
|
||||
BuildI8FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::IA4:
|
||||
BuildIA4FromGCN(in);
|
||||
BuildIA4FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::IA8:
|
||||
BuildIA8FromGCN(in);
|
||||
BuildIA8FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::C4:
|
||||
BuildC4FromGCN(in);
|
||||
BuildC4FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::C8:
|
||||
BuildC8FromGCN(in);
|
||||
BuildC8FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::C14X2:
|
||||
BuildC14X2FromGCN(in);
|
||||
BuildC14X2FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::RGB565:
|
||||
BuildRGB565FromGCN(in);
|
||||
BuildRGB565FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::RGB5A3:
|
||||
BuildRGB5A3FromGCN(in);
|
||||
BuildRGB5A3FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::RGBA8:
|
||||
BuildRGBA8FromGCN(in);
|
||||
BuildRGBA8FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::CMPR:
|
||||
BuildDXT1FromGCN(in);
|
||||
BuildDXT1FromGCN(r);
|
||||
break;
|
||||
case ETexelFormat::RGBA8PC:
|
||||
BuildRGBA8(in);
|
||||
BuildRGBA8(owned.get() + 12);
|
||||
break;
|
||||
default:
|
||||
Log.report(logvisor::Fatal, "invalid texture type %d for boo", int(x0_fmt));
|
||||
@@ -716,9 +717,11 @@ void CTexture::Load(int slot, EClampMode clamp) const
|
||||
|
||||
}
|
||||
|
||||
CFactoryFnReturn FTextureFactory(const SObjectTag& tag, CInputStream& in, const CVParamTransfer& vparms)
|
||||
CFactoryFnReturn FTextureFactory(const urde::SObjectTag& tag,
|
||||
std::unique_ptr<u8[]>&& in, u32 len,
|
||||
const urde::CVParamTransfer& vparms)
|
||||
{
|
||||
return TToken<CTexture>::GetIObjObjectFor(std::make_unique<CTexture>(in));
|
||||
return TToken<CTexture>::GetIObjObjectFor(std::make_unique<CTexture>(std::move(in), len));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user