2022-02-25 07:45:25 +00:00
|
|
|
#pragma once
|
|
|
|
|
2022-02-27 02:18:58 +00:00
|
|
|
#include "Runtime/Graphics/CCubeModel.hpp"
|
|
|
|
#include "Runtime/Graphics/CPVSVisSet.hpp"
|
|
|
|
#include "Runtime/Graphics/CTexture.hpp"
|
|
|
|
#include "Runtime/Graphics/IRenderer.hpp"
|
|
|
|
#include "Runtime/CRandom16.hpp"
|
|
|
|
#include "Runtime/Graphics/CFont.hpp"
|
2022-02-25 07:45:25 +00:00
|
|
|
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
namespace metaforce {
|
|
|
|
class IObjectStore;
|
|
|
|
class IFactory;
|
|
|
|
|
|
|
|
class CCubeRenderer final : public IRenderer {
|
|
|
|
// TODO function for controlling x318_26_requestRGBA6
|
|
|
|
// then these can be removed
|
|
|
|
friend class CMorphBallShadow;
|
|
|
|
friend class CWorldTransManager;
|
|
|
|
|
|
|
|
struct CAreaListItem {
|
|
|
|
const std::vector<CMetroidModelInstance>* x0_geometry;
|
|
|
|
const CAreaRenderOctTree* x4_octTree;
|
|
|
|
/* originally auto_ptrs of vectors */
|
2022-03-06 04:50:54 +00:00
|
|
|
std::unique_ptr<std::vector<TCachedToken<CTexture>>> x8_textures;
|
|
|
|
std::unique_ptr<std::vector<std::unique_ptr<CCubeModel>>> x10_models;
|
2022-03-07 03:07:00 +00:00
|
|
|
s32 x18_areaIdx;
|
2022-02-25 07:45:25 +00:00
|
|
|
/* Per-area octree-word major, light bits minor */
|
|
|
|
std::vector<u32> x1c_lightOctreeWords;
|
|
|
|
|
|
|
|
CAreaListItem(const std::vector<CMetroidModelInstance>* geom, const CAreaRenderOctTree* octTree,
|
2022-03-06 04:50:54 +00:00
|
|
|
std::unique_ptr<std::vector<TCachedToken<CTexture>>>&& textures,
|
2022-03-07 03:07:00 +00:00
|
|
|
std::unique_ptr<std::vector<std::unique_ptr<CCubeModel>>>&& models, s32 areaIdx);
|
2022-02-25 07:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct CFogVolumeListItem {
|
|
|
|
zeus::CTransform x0_transform;
|
|
|
|
zeus::CColor x30_color;
|
|
|
|
zeus::CAABox x34_aabb;
|
|
|
|
TLockedToken<CModel> x4c_model;
|
|
|
|
// bool x58_b; Optional for model token
|
|
|
|
const CSkinnedModel* x5c_skinnedModel = nullptr;
|
|
|
|
CFogVolumeListItem(const zeus::CTransform& xf, const zeus::CColor& color, const zeus::CAABox& aabb,
|
|
|
|
const TLockedToken<CModel>* model, const CSkinnedModel* sModel)
|
|
|
|
: x0_transform(xf), x30_color(color), x34_aabb(aabb), x5c_skinnedModel(sModel) {
|
|
|
|
if (model)
|
|
|
|
x4c_model = *model;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
private:
|
|
|
|
IFactory& x8_factory;
|
|
|
|
IObjectStore& xc_store;
|
2022-02-27 02:18:58 +00:00
|
|
|
CFont x10_font{1.f};
|
2022-03-06 04:50:54 +00:00
|
|
|
u32 x18_primVertCount = 0;
|
2022-02-25 07:45:25 +00:00
|
|
|
std::list<CAreaListItem> x1c_areaListItems;
|
|
|
|
// TODO x34...x40
|
|
|
|
zeus::CFrustum x44_frustumPlanes; // {zeus::skIdentityMatrix4f, 1.5707964f, 1.f, 1.f, false, 100.f}
|
|
|
|
TDrawableCallback xa8_drawableCallback = nullptr;
|
|
|
|
void* xac_drawableCallbackUserData = nullptr;
|
|
|
|
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;
|
2022-02-27 20:12:02 +00:00
|
|
|
bool xdc_{};
|
2022-02-25 07:45:25 +00:00
|
|
|
u32 xe0_pvsAreaIdx = UINT32_MAX;
|
2022-03-04 07:47:21 +00:00
|
|
|
CTexture xe4_blackTex{ETexelFormat::RGB565, 4, 4, 1, "Black Texture"};
|
2022-02-27 21:17:44 +00:00
|
|
|
std::unique_ptr<CTexture> x14c_reflectionTex;
|
2022-03-04 07:47:21 +00:00
|
|
|
CTexture x150_reflectionTex{ETexelFormat::IA8, 32, 32, 1, "Reflection Texture"};
|
|
|
|
CTexture x1b8_fogVolumeRamp{ETexelFormat::I8, 256, 256, 1, "Fog Volume Ramp Texture"};
|
|
|
|
CTexture x220_sphereRamp{ETexelFormat::I8, 32, 32, 1, "Sphere Ramp Texture"};
|
2022-05-13 23:40:19 +00:00
|
|
|
CGraphicsPalette x288_thermoPalette{EPaletteFormat::RGB565, 16};
|
2022-02-25 07:45:25 +00:00
|
|
|
CRandom16 x2a8_thermalRand{20};
|
|
|
|
std::list<CFogVolumeListItem> x2ac_fogVolumes;
|
|
|
|
std::list<std::pair<zeus::CVector3f, float>> x2c4_spaceWarps;
|
|
|
|
u32 x2dc_reflectionAge = 2;
|
2022-03-06 04:50:54 +00:00
|
|
|
zeus::CColor x2e0_primColor = zeus::skWhite;
|
|
|
|
zeus::CVector3f x2e4_primNormal = zeus::skForward;
|
2022-02-25 07:45:25 +00:00
|
|
|
float x2f0_thermalVisorLevel = 1.f;
|
|
|
|
zeus::CColor x2f4_thermColor{1.f, 0.f, 1.f, 1.f};
|
|
|
|
float x2f8_thermColdScale = 0.f; // ??? byte in code
|
|
|
|
zeus::CColor x2fc_tevReg1Color{1.f, 0.f, 1.f, 1.f};
|
|
|
|
std::vector<CLight> x300_dynamicLights;
|
|
|
|
u32 x310_phazonSuitMaskCountdown = 0;
|
2022-02-27 21:17:44 +00:00
|
|
|
std::unique_ptr<CTexture> x314_phazonSuitMask;
|
2022-02-25 07:45:25 +00:00
|
|
|
bool x318_24_refectionDirty : 1 = false;
|
|
|
|
bool x318_25_drawWireframe : 1 = false;
|
|
|
|
bool x318_26_requestRGBA6 : 1 = false;
|
|
|
|
bool x318_27_currentRGBA6 : 1 = false;
|
|
|
|
bool x318_28_disableFog : 1 = false;
|
|
|
|
bool x318_29_thermalVisor : 1 = false;
|
|
|
|
bool x318_30_inAreaDraw : 1 = false;
|
|
|
|
bool x318_31_persistRGBA6 : 1 = false;
|
|
|
|
|
2022-05-13 23:40:19 +00:00
|
|
|
CTexture m_thermalRandomStatic{ETexelFormat::IA4, 640, 448, 1, "Thermal Random Static"};
|
|
|
|
|
2022-02-25 07:45:25 +00:00
|
|
|
void GenerateReflectionTex();
|
|
|
|
void GenerateFogVolumeRampTex();
|
|
|
|
void GenerateSphereRampTex();
|
|
|
|
void LoadThermoPalette();
|
|
|
|
|
2022-03-12 15:47:20 +00:00
|
|
|
void ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, CTexture& maskTex, CTexture& indTex,
|
|
|
|
const zeus::CColor& modColor, float scale, float offX, float offY);
|
|
|
|
void ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor, CTexture& maskTex);
|
2022-07-02 00:47:45 +00:00
|
|
|
void DoPhazonSuitIndirectAlphaBlur(float blurRadius, float f2);
|
|
|
|
void ReallyDrawSpaceWarp(const zeus::CVector3f& pt, float strength);
|
|
|
|
void ReallyRenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const CModel* model,
|
|
|
|
const CSkinnedModel* sModel);
|
2022-02-25 07:45:25 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
CCubeRenderer(IObjectStore& store, IFactory& resFac);
|
|
|
|
~CCubeRenderer() override;
|
|
|
|
|
2022-03-06 04:50:54 +00:00
|
|
|
void AddWorldSurfaces(CCubeModel& model);
|
2022-02-25 07:45:25 +00:00
|
|
|
void AddStaticGeometry(const std::vector<CMetroidModelInstance>* geometry, const CAreaRenderOctTree* octTree,
|
2022-03-07 03:07:00 +00:00
|
|
|
s32 areaIdx) override;
|
2022-02-25 07:45:25 +00:00
|
|
|
void EnablePVS(const CPVSVisSet& set, u32 areaIdx) override;
|
|
|
|
void DisablePVS() override;
|
|
|
|
void RemoveStaticGeometry(const std::vector<CMetroidModelInstance>* geometry) override;
|
2022-05-12 05:57:24 +00:00
|
|
|
void DrawUnsortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) override;
|
2022-03-07 03:07:00 +00:00
|
|
|
void DrawSortedGeometry(s32 areaIdx, s32 mask, s32 targetMask) override;
|
|
|
|
void DrawStaticGeometry(s32 areaIdx, s32 mask, s32 targetMask) override;
|
|
|
|
void DrawAreaGeometry(s32 areaIdx, s32 mask, s32 targetMask) override;
|
2022-02-25 07:45:25 +00:00
|
|
|
void PostRenderFogs() override;
|
|
|
|
void SetModelMatrix(const zeus::CTransform& xf) override;
|
|
|
|
void AddParticleGen(CParticleGen& gen) override;
|
|
|
|
void AddParticleGen(CParticleGen& gen, const zeus::CVector3f& pos, const zeus::CAABox& bounds) override;
|
2022-03-07 03:07:00 +00:00
|
|
|
void AddPlaneObject(void* obj, const zeus::CAABox& aabb, const zeus::CPlane& plane, s32 type) override;
|
|
|
|
void AddDrawable(void* obj, const zeus::CVector3f& pos, const zeus::CAABox& aabb, s32 mode,
|
2022-02-25 07:45:25 +00:00
|
|
|
EDrawableSorting sorting) override;
|
|
|
|
void SetDrawableCallback(TDrawableCallback cb, void* ctx) override;
|
|
|
|
void SetWorldViewpoint(const zeus::CTransform& xf) override;
|
|
|
|
void SetPerspective(float fovy, float aspect, float znear, float zfar) override;
|
|
|
|
void SetPerspective(float fovy, float width, float height, float znear, float zfar) override;
|
|
|
|
std::pair<zeus::CVector2f, zeus::CVector2f> SetViewportOrtho(bool centered, float znear, float zfar) override;
|
|
|
|
void SetClippingPlanes(const zeus::CFrustum& frustum) override;
|
2022-03-07 03:07:00 +00:00
|
|
|
void SetViewport(s32 left, s32 right, s32 width, s32 height) override;
|
2022-02-25 07:45:25 +00:00
|
|
|
void SetDepthReadWrite(bool read, bool write) override {
|
|
|
|
CGraphics::SetDepthWriteMode(read, ERglEnum::LEqual, write);
|
|
|
|
}
|
|
|
|
void SetBlendMode_AdditiveAlpha() override {
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::One, ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
void SetBlendMode_AlphaBlended() override {
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcAlpha, ERglBlendFactor::InvSrcAlpha,
|
|
|
|
ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
void SetBlendMode_ColorMultiply() override {
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::Zero, ERglBlendFactor::SrcColor, ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
void SetBlendMode_InvertDst() override {
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::InvSrcColor, ERglBlendFactor::Zero,
|
|
|
|
ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
void SetBlendMode_InvertSrc() override {
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Logic, ERglBlendFactor::One, ERglBlendFactor::Zero, ERglLogicOp::InvCopy);
|
|
|
|
}
|
|
|
|
void SetBlendMode_NoColorWrite() override {
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::Zero, ERglBlendFactor::One, ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
void SetBlendMode_Replace() override {
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::One, ERglBlendFactor::Zero, ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
void SetBlendMode_AdditiveDestColor() override {
|
|
|
|
CGraphics::SetBlendMode(ERglBlendMode::Blend, ERglBlendFactor::SrcColor, ERglBlendFactor::One, ERglLogicOp::Clear);
|
|
|
|
}
|
|
|
|
void BeginScene() override;
|
|
|
|
void EndScene() override;
|
2022-03-07 03:07:00 +00:00
|
|
|
void SetDebugOption(EDebugOption, s32) override;
|
|
|
|
void BeginPrimitive(EPrimitiveType, s32) override;
|
2022-02-25 07:45:25 +00:00
|
|
|
void BeginLines(int) override;
|
|
|
|
void BeginLineStrip(int) override;
|
|
|
|
void BeginTriangles(int) override;
|
|
|
|
void BeginTriangleStrip(int) override;
|
|
|
|
void BeginTriangleFan(int) override;
|
|
|
|
void PrimVertex(const zeus::CVector3f&) override;
|
|
|
|
void PrimNormal(const zeus::CVector3f&) override;
|
|
|
|
void PrimColor(float, float, float, float) override;
|
|
|
|
void PrimColor(const zeus::CColor&) override;
|
|
|
|
void EndPrimitive() override;
|
|
|
|
void SetAmbientColor(const zeus::CColor& color) override;
|
2022-03-07 03:07:00 +00:00
|
|
|
void DrawString(const char* string, s32, s32) override;
|
2022-02-25 07:45:25 +00:00
|
|
|
u32 GetFPS() override;
|
|
|
|
void CacheReflection(TReflectionCallback cb, void* ctx, bool clearAfter) override;
|
|
|
|
void DrawSpaceWarp(const zeus::CVector3f& pt, float strength) override;
|
2022-03-12 15:47:20 +00:00
|
|
|
void DrawThermalModel(CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol,
|
2022-03-10 06:33:17 +00:00
|
|
|
TConstVectorRef positions, TConstVectorRef normals, const CModelFlags& flags) override;
|
2022-03-12 15:47:20 +00:00
|
|
|
void DrawModelDisintegrate(CModel& model, CTexture& tex, const zeus::CColor& color, TConstVectorRef positions,
|
|
|
|
TConstVectorRef normals, float t) override;
|
|
|
|
void DrawModelFlat(CModel& model, const CModelFlags& flags, bool unsortedOnly, TConstVectorRef positions,
|
|
|
|
TConstVectorRef normals) override;
|
2022-03-07 03:07:00 +00:00
|
|
|
void SetWireframeFlags(s32 flags) override;
|
2022-02-25 07:45:25 +00:00
|
|
|
void SetWorldFog(ERglFogMode mode, float startz, float endz, const zeus::CColor& color) override;
|
|
|
|
void RenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb, const TLockedToken<CModel>* model,
|
|
|
|
const CSkinnedModel* sModel) override;
|
|
|
|
void SetThermal(bool thermal, float level, const zeus::CColor& color) override;
|
|
|
|
void SetThermalColdScale(float scale) override;
|
|
|
|
void DoThermalBlendCold() override;
|
|
|
|
void DoThermalBlendHot() override;
|
|
|
|
u32 GetStaticWorldDataSize() override;
|
|
|
|
void SetGXRegister1Color(const zeus::CColor& color) override;
|
|
|
|
void SetWorldLightFadeLevel(float level) override;
|
|
|
|
void PrepareDynamicLights(const std::vector<CLight>& lights) override;
|
|
|
|
|
|
|
|
// Non-virtual functions
|
2022-03-06 07:46:42 +00:00
|
|
|
void SetupRendererStates(bool depthWrite);
|
2022-02-25 07:45:25 +00:00
|
|
|
void AllocatePhazonSuitMaskTexture();
|
|
|
|
void DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod, const TLockedToken<CTexture>& indTex,
|
|
|
|
const zeus::CColor& indirectMod, float blurRadius, float scale, float offX,
|
|
|
|
float offY);
|
|
|
|
void DrawXRayOutline(const zeus::CAABox& aabb);
|
2022-03-06 04:50:54 +00:00
|
|
|
std::list<CAreaListItem>::iterator FindStaticGeometry(const std::vector<CMetroidModelInstance>* geometry);
|
2022-02-25 07:45:25 +00:00
|
|
|
void FindOverlappingWorldModels(std::vector<u32>& modelBits, const zeus::CAABox& aabb) const;
|
2022-03-07 03:07:00 +00:00
|
|
|
s32 DrawOverlappingWorldModelIDs(s32 alphaVal, const std::vector<u32>& modelBits, const zeus::CAABox& aabb);
|
2022-07-26 05:08:14 +00:00
|
|
|
void DrawOverlappingWorldModelShadows(s32 alphaVal, const std::vector<u32>& modelBits, const zeus::CAABox& aabb);
|
2022-03-06 04:50:54 +00:00
|
|
|
void RenderBucketItems(const CAreaListItem* lights);
|
|
|
|
void DrawRenderBucketsDebug() {}
|
2022-02-26 07:05:59 +00:00
|
|
|
|
2022-03-06 21:01:25 +00:00
|
|
|
void HandleUnsortedModel(CAreaListItem* areaItem, CCubeModel& model, const CModelFlags& flags);
|
|
|
|
void HandleUnsortedModelWireframe(CAreaListItem* areaItem, CCubeModel& model);
|
|
|
|
|
2022-03-07 03:07:00 +00:00
|
|
|
void ActivateLightsForModel(const CAreaListItem* areaItem, CCubeModel& model);
|
2022-03-06 21:01:25 +00:00
|
|
|
|
2022-03-12 15:47:20 +00:00
|
|
|
void DoThermalModelDraw(CCubeModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol,
|
|
|
|
TConstVectorRef positions, TConstVectorRef normals, const CModelFlags& flags);
|
|
|
|
|
2022-02-26 07:05:59 +00:00
|
|
|
// Getters
|
|
|
|
[[nodiscard]] bool IsInAreaDraw() const { return x318_30_inAreaDraw; }
|
|
|
|
[[nodiscard]] bool IsReflectionDirty() const { return x318_24_refectionDirty; }
|
|
|
|
void SetReflectionDirty(bool v) { x318_24_refectionDirty = v; }
|
|
|
|
[[nodiscard]] bool IsThermalVisorActive() const { return x318_29_thermalVisor; }
|
2022-03-07 03:07:00 +00:00
|
|
|
CTexture* GetRealReflection() {
|
|
|
|
x2dc_reflectionAge = 0;
|
|
|
|
if (x14c_reflectionTex) {
|
|
|
|
return x14c_reflectionTex.get();
|
|
|
|
}
|
|
|
|
|
|
|
|
return &xe4_blackTex;
|
|
|
|
}
|
2022-03-06 04:50:54 +00:00
|
|
|
|
|
|
|
static void SetupCGraphicsState();
|
2022-02-25 07:45:25 +00:00
|
|
|
};
|
|
|
|
} // namespace metaforce
|