mirror of https://github.com/AxioDL/metaforce.git
CCubeRenderer: Add Drawable logic implemented
This commit is contained in:
parent
594921789c
commit
805065b6f2
|
@ -5,6 +5,7 @@
|
|||
#include "Runtime/Graphics/CDrawablePlaneObject.hpp"
|
||||
#include "Runtime/Graphics/CLight.hpp"
|
||||
#include "Runtime/Graphics/CModel.hpp"
|
||||
#include "Runtime/Particle/CParticleGen.hpp"
|
||||
|
||||
namespace metaforce {
|
||||
static logvisor::Module Log("CCubeRenderer");
|
||||
|
@ -166,6 +167,16 @@ void Buckets::Init() {
|
|||
sMinMaxDistance = skWorstMinMaxDistance;
|
||||
}
|
||||
|
||||
CCubeRenderer::CAreaListItem::CAreaListItem(const std::vector<CMetroidModelInstance>* geom,
|
||||
const CAreaRenderOctTree* octTree,
|
||||
std::unordered_map<CAssetId, TCachedToken<CTexture>>&& textures,
|
||||
std::vector<CCubeModel*>&& models, int areaIdx)
|
||||
: x0_geometry(geom)
|
||||
, x4_octTree(octTree)
|
||||
, x8_textures(std::move(textures))
|
||||
, x10_models(std::move(models))
|
||||
, x18_areaIdx(areaIdx) {}
|
||||
|
||||
CCubeRenderer::CCubeRenderer(IObjectStore& store, IFactory& resFac) : x8_factory(resFac), xc_store(store) {
|
||||
// void* data = xe4_blackTex.GetBitMapData();
|
||||
// memset(data, 0, 32);
|
||||
|
@ -179,9 +190,7 @@ CCubeRenderer::CCubeRenderer(IObjectStore& store, IFactory& resFac) : x8_factory
|
|||
// GX draw sync
|
||||
}
|
||||
|
||||
CCubeRenderer::~CCubeRenderer() {
|
||||
g_Renderer = nullptr;
|
||||
}
|
||||
CCubeRenderer::~CCubeRenderer() { g_Renderer = nullptr; }
|
||||
|
||||
void CCubeRenderer::GenerateReflectionTex() {}
|
||||
void CCubeRenderer::GenerateFogVolumeRampTex() {}
|
||||
|
@ -194,8 +203,17 @@ void CCubeRenderer::ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor, con
|
|||
void CCubeRenderer::DoPhazonSuitIndirectAlphaBlur(float blurRadius, float f2, const TLockedToken<CTexture>& indTex) {}
|
||||
void CCubeRenderer::AddStaticGeometry(const std::vector<CMetroidModelInstance>* geometry,
|
||||
const CAreaRenderOctTree* octTree, int areaIdx) {}
|
||||
void CCubeRenderer::EnablePVS(const CPVSVisSet& set, u32 areaIdx) {}
|
||||
void CCubeRenderer::DisablePVS() {}
|
||||
void CCubeRenderer::EnablePVS(const CPVSVisSet& set, u32 areaIdx) {
|
||||
if (!xdc_) {
|
||||
xc8_pvs.emplace(set);
|
||||
xdc_ = true;
|
||||
} else {
|
||||
xc8_pvs.emplace(set);
|
||||
}
|
||||
|
||||
xe0_pvsAreaIdx = areaIdx;
|
||||
}
|
||||
void CCubeRenderer::DisablePVS() { xc8_pvs.reset(); }
|
||||
void CCubeRenderer::RemoveStaticGeometry(const std::vector<CMetroidModelInstance>* geometry) {}
|
||||
void CCubeRenderer::DrawUnsortedGeometry(int areaIdx, int mask, int targetMask, bool shadowRender) {}
|
||||
void CCubeRenderer::DrawSortedGeometry(int areaIdx, int mask, int targetMask) {}
|
||||
|
@ -203,11 +221,50 @@ void CCubeRenderer::DrawStaticGeometry(int areaIdx, int mask, int targetMask) {}
|
|||
void CCubeRenderer::DrawAreaGeometry(int areaIdx, int mask, int targetMask) {}
|
||||
void CCubeRenderer::PostRenderFogs() {}
|
||||
void CCubeRenderer::SetModelMatrix(const zeus::CTransform& xf) {}
|
||||
void CCubeRenderer::AddParticleGen(CParticleGen& gen) {}
|
||||
void CCubeRenderer::AddParticleGen(CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) {}
|
||||
void CCubeRenderer::AddPlaneObject(void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, int type) {}
|
||||
void CCubeRenderer::AddParticleGen(CParticleGen& gen) {
|
||||
auto bounds = gen.GetBounds();
|
||||
|
||||
if (bounds) {
|
||||
auto closestPoint = bounds->closestPointAlongVector(xb0_viewPlane.normal());
|
||||
Buckets::Insert(closestPoint, *bounds, EDrawableType::Particle, reinterpret_cast<void*>(&gen), xb0_viewPlane, 0);
|
||||
}
|
||||
}
|
||||
void CCubeRenderer::AddParticleGen(CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) {
|
||||
Buckets::Insert(pos, bounds, EDrawableType::Particle, reinterpret_cast<void*>(&gen), xb0_viewPlane, 0);
|
||||
}
|
||||
void CCubeRenderer::AddPlaneObject(void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, int type) {
|
||||
|
||||
auto closestPoint = aabb.closestPointAlongVector(xb0_viewPlane.normal());
|
||||
auto closestDist = xb0_viewPlane.pointToPlaneDist(closestPoint);
|
||||
auto furthestPoint = aabb.furthestPointAlongVector(xb0_viewPlane.normal());
|
||||
auto furthestDist = xb0_viewPlane.pointToPlaneDist(furthestPoint);
|
||||
|
||||
if (closestDist >= 0.f || furthestDist >= 0.f) {
|
||||
bool zOnly = false;
|
||||
if (plane.normal() == zeus::skUp) {
|
||||
zOnly = true;
|
||||
}
|
||||
|
||||
bool invertTest = false;
|
||||
if (zOnly) {
|
||||
invertTest = CGraphics::g_GXModelView.origin.z() >= plane.d();
|
||||
} else if (plane.pointToPlaneDist(CGraphics::g_GXModelView.origin) < 0.f) {
|
||||
invertTest = false;
|
||||
} else {
|
||||
invertTest = true;
|
||||
}
|
||||
|
||||
Buckets::InsertPlaneObject(closestDist, furthestDist, aabb, invertTest, plane, zOnly, EDrawableType(type + 2), obj);
|
||||
}
|
||||
}
|
||||
void CCubeRenderer::AddDrawable(void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, int mode,
|
||||
IRenderer::EDrawableSorting sorting) {}
|
||||
IRenderer::EDrawableSorting sorting) {
|
||||
if (sorting == EDrawableSorting::UnsortedCallback) {
|
||||
xa8_drawableCallback(obj, xac_drawableCallbackUserData, mode);
|
||||
} else {
|
||||
Buckets::Insert(pos, aabb, EDrawableType(mode + 2), obj, xb0_viewPlane, 0);
|
||||
}
|
||||
}
|
||||
void CCubeRenderer::SetDrawableCallback(IRenderer::TDrawableCallback cb, void* ctx) {}
|
||||
void CCubeRenderer::SetWorldViewpoint(const zeus::CTransform& xf) {}
|
||||
void CCubeRenderer::SetPerspective(float fovy, float aspect, float znear, float zfar) {}
|
||||
|
@ -232,9 +289,7 @@ void CCubeRenderer::PrimColor(float, float, float, float) {}
|
|||
void CCubeRenderer::PrimColor(const zeus::CColor&) {}
|
||||
void CCubeRenderer::EndPrimitive() {}
|
||||
void CCubeRenderer::SetAmbientColor(const zeus::CColor& color) {}
|
||||
void CCubeRenderer::DrawString(const char* string, int x, int y) {
|
||||
x10_font.DrawString(string, x, y, zeus::skWhite);
|
||||
}
|
||||
void CCubeRenderer::DrawString(const char* string, int x, int y) { x10_font.DrawString(string, x, y, zeus::skWhite); }
|
||||
|
||||
u32 CCubeRenderer::GetFPS() { return CGraphics::GetFPS(); }
|
||||
void CCubeRenderer::CacheReflection(IRenderer::TReflectionCallback cb, void* ctx, bool clearAfter) {}
|
||||
|
|
|
@ -62,7 +62,7 @@ private:
|
|||
zeus::CPlane xb0_viewPlane{0.f, 1.f, 0.f, 0.f};
|
||||
enum class EPVSMode : u8 { Mask, PVS, PVSAndMask } xc0_pvsMode = EPVSMode::Mask;
|
||||
std::optional<CPVSVisSet> xc8_pvs;
|
||||
// bool xdc_;
|
||||
bool xdc_{};
|
||||
u32 xe0_pvsAreaIdx = UINT32_MAX;
|
||||
CTexture xe4_blackTex{ETexelFormat::RGB565, 4, 4, 1};
|
||||
u32 x14c_ = 0;
|
||||
|
|
|
@ -43,24 +43,27 @@ public:
|
|||
};
|
||||
|
||||
private:
|
||||
static u32 sCurrentFrameCount;
|
||||
ETexelFormat x0_fmt;
|
||||
u16 x4_w;
|
||||
u16 x6_h;
|
||||
u8 x8_mips;
|
||||
u8 x9_bitsPerPixel;
|
||||
u32 xc_memoryAllocated;
|
||||
u32 xc_memoryAllocated{};
|
||||
std::unique_ptr<CGraphicsPalette> x10_graphicsPalette;
|
||||
std::unique_ptr<CDumpedBitmapDataReloader> x14_bitmapReloader;
|
||||
u32 x18_gxFormat;
|
||||
u32 x1c_gxCIFormat;
|
||||
u32 x18_gxFormat{};
|
||||
u32 x1c_gxCIFormat{};
|
||||
/* GXTexObj x20_texObj */
|
||||
EClampMode x40_clampMode;
|
||||
EClampMode x40_clampMode = EClampMode::Repeat;
|
||||
/* CARAMToken x44_aramToken */
|
||||
u32 x64_frameAllocated{};
|
||||
|
||||
aurora::gfx::TextureHandle m_tex;
|
||||
aurora::gfx::TextureHandle m_paletteTex;
|
||||
std::unique_ptr<u8[]> m_otex;
|
||||
EFontType m_ftype = EFontType::None;
|
||||
const CTextureInfo* m_textureInfo;
|
||||
const CTextureInfo* m_textureInfo{};
|
||||
|
||||
size_t ComputeMippedTexelCount() const;
|
||||
size_t ComputeMippedBlockCountDXT1() const;
|
||||
|
@ -82,26 +85,26 @@ private:
|
|||
void BuildDXT3(const void* data, size_t length, aurora::zstring_view label);
|
||||
|
||||
void InitBitmapBuffers(ETexelFormat fmt, s16 width, s16 height, s32 mips);
|
||||
void InitTextureObjs();
|
||||
|
||||
public:
|
||||
CTexture(ETexelFormat, s16, s16, s32);
|
||||
CTexture(std::unique_ptr<u8[]>&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id);
|
||||
ETexelFormat GetTexelFormat() const { return x0_fmt; }
|
||||
ETexelFormat GetMemoryCardTexelFormat() const {
|
||||
[[nodiscard]] ETexelFormat GetTexelFormat() const { return x0_fmt; }
|
||||
[[nodiscard]] ETexelFormat GetMemoryCardTexelFormat() const {
|
||||
return x0_fmt == ETexelFormat::C8PC ? ETexelFormat::C8 : ETexelFormat::RGB5A3;
|
||||
}
|
||||
u16 GetWidth() const { return x4_w; }
|
||||
u16 GetHeight() const { return x6_h; }
|
||||
u32 GetNumMips() const { return x8_mips; }
|
||||
u8 GetBitsPerPixel() const { return x9_bitsPerPixel; }
|
||||
[[nodiscard]] u16 GetWidth() const { return x4_w; }
|
||||
[[nodiscard]] u16 GetHeight() const { return x6_h; }
|
||||
[[nodiscard]] u8 GetNumMips() const { return x8_mips; }
|
||||
[[nodiscard]] u8 GetBitsPerPixel() const { return x9_bitsPerPixel; }
|
||||
void Load(int slot, EClampMode clamp) const;
|
||||
const aurora::gfx::TextureHandle& GetTexture() const { return m_tex; }
|
||||
// const boo::ObjToken<boo::ITexture>& GetBooTexture() const { return m_booTex; }
|
||||
const aurora::gfx::TextureHandle& GetPaletteTexture() const { return m_paletteTex; }
|
||||
[[nodiscard]] const aurora::gfx::TextureHandle& GetTexture() const { return m_tex; }
|
||||
[[nodiscard]] const aurora::gfx::TextureHandle& GetPaletteTexture() const { return m_paletteTex; }
|
||||
std::unique_ptr<u8[]> BuildMemoryCardTex(u32& sizeOut, ETexelFormat& fmtOut, std::unique_ptr<u8[]>& paletteOut) const;
|
||||
const aurora::gfx::TextureHandle& GetFontTexture(EFontType tp);
|
||||
|
||||
const CTextureInfo* GetTextureInfo() const { return m_textureInfo; }
|
||||
[[nodiscard]] const CTextureInfo* GetTextureInfo() const { return m_textureInfo; }
|
||||
|
||||
static u32 TexelFormatBitsPerPixel(ETexelFormat fmt);
|
||||
};
|
||||
|
|
|
@ -708,7 +708,7 @@ static std::string_view TextureFormatString(ETexelFormat format) {
|
|||
}
|
||||
|
||||
u32 CTexture::TexelFormatBitsPerPixel(ETexelFormat fmt) {
|
||||
switch(fmt) {
|
||||
switch (fmt) {
|
||||
case ETexelFormat::I4:
|
||||
case ETexelFormat::C4:
|
||||
case ETexelFormat::CMPR:
|
||||
|
@ -729,18 +729,24 @@ u32 CTexture::TexelFormatBitsPerPixel(ETexelFormat fmt) {
|
|||
}
|
||||
}
|
||||
|
||||
u32 CTexture::sCurrentFrameCount = 0;
|
||||
|
||||
void CTexture::InitBitmapBuffers(ETexelFormat fmt, s16 width, s16 height, s32 mips) {}
|
||||
void CTexture::InitTextureObjs() {}
|
||||
|
||||
CTexture::CTexture(ETexelFormat fmt, s16 w, s16 h, s32 mips)
|
||||
: x0_fmt(fmt), x4_w(w), x6_h(h), x8_mips(mips), x9_bitsPerPixel(TexelFormatBitsPerPixel(fmt)) {
|
||||
#if 0
|
||||
x64_ = sCurrentFrameCount;
|
||||
: x0_fmt(fmt)
|
||||
, x4_w(w)
|
||||
, x6_h(h)
|
||||
, x8_mips(mips)
|
||||
, x9_bitsPerPixel(TexelFormatBitsPerPixel(fmt))
|
||||
, x64_frameAllocated(sCurrentFrameCount) {
|
||||
|
||||
InitBitmapBuffers(fmt, w, h, mips);
|
||||
InitTextureObjs();
|
||||
#endif
|
||||
}
|
||||
|
||||
CTexture::CTexture(std::unique_ptr<u8[]>&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id)
|
||||
: m_textureInfo(inf) {
|
||||
CTexture::CTexture(std::unique_ptr<u8[]>&& in, u32 length, bool otex, const CTextureInfo* inf, CAssetId id) {
|
||||
std::unique_ptr<u8[]> owned = std::move(in);
|
||||
CMemoryInStream r(owned.get(), length, CMemoryInStream::EOwnerShip::NotOwned);
|
||||
x0_fmt = ETexelFormat(r.ReadLong());
|
||||
|
@ -748,6 +754,7 @@ CTexture::CTexture(std::unique_ptr<u8[]>&& in, u32 length, bool otex, const CTex
|
|||
x6_h = r.ReadShort();
|
||||
x8_mips = r.ReadLong();
|
||||
x9_bitsPerPixel = TexelFormatBitsPerPixel(x0_fmt);
|
||||
m_textureInfo = inf;
|
||||
|
||||
auto label = fmt::format(FMT_STRING("TXTR {:08X} ({})"), id.Value(), TextureFormatString(x0_fmt));
|
||||
switch (x0_fmt) {
|
||||
|
|
Loading…
Reference in New Issue