metaforce/Runtime/Graphics/CBooRenderer.hpp

313 lines
13 KiB
C++
Raw Normal View History

2016-04-13 06:07:23 +00:00
#ifndef __URDE_CBOORENDERER_HPP__
#define __URDE_CBOORENDERER_HPP__
2015-08-18 05:54:43 +00:00
2016-07-25 22:52:02 +00:00
#include <functional>
2016-07-21 05:21:45 +00:00
#include "IRenderer.hpp"
#include "CDrawable.hpp"
2016-07-25 22:52:02 +00:00
#include "CDrawablePlaneObject.hpp"
#include "Shaders/CThermalColdFilter.hpp"
2016-08-03 21:53:03 +00:00
#include "Shaders/CThermalHotFilter.hpp"
2016-07-29 17:38:44 +00:00
#include "Shaders/CSpaceWarpFilter.hpp"
#include "Shaders/CFogVolumePlaneShader.hpp"
#include "Shaders/CFogVolumeFilter.hpp"
2017-05-06 05:21:42 +00:00
#include "Shaders/CPhazonSuitFilter.hpp"
#include "CTexture.hpp"
2016-07-25 22:52:02 +00:00
#include "CRandom16.hpp"
2016-07-27 23:06:57 +00:00
#include "CPVSVisSet.hpp"
2016-07-29 17:38:44 +00:00
#include "zeus/CRectangle.hpp"
2016-08-07 00:20:02 +00:00
#include "World/CGameArea.hpp"
#include "zeus/CPlane.hpp"
2016-07-21 05:21:45 +00:00
2016-03-04 23:04:53 +00:00
namespace urde
2015-08-18 05:54:43 +00:00
{
2015-08-22 01:58:41 +00:00
class IObjectStore;
class CMemorySys;
2016-04-15 20:42:40 +00:00
class IFactory;
2016-07-25 22:52:02 +00:00
class CTexture;
2016-07-26 22:05:59 +00:00
class CParticleGen;
class CBooModel;
2015-08-18 05:54:43 +00:00
class Buckets
{
2016-07-25 22:52:02 +00:00
friend class CBooRenderer;
static rstl::reserved_vector<u16, 50> sBucketIndex;
2017-11-12 05:14:57 +00:00
static rstl::reserved_vector<CDrawable, 512>* sData;
2016-07-25 22:52:02 +00:00
static rstl::reserved_vector<rstl::reserved_vector<CDrawable*, 128>, 50>* sBuckets;
static rstl::reserved_vector<CDrawablePlaneObject, 8>* sPlaneObjectData;
static rstl::reserved_vector<u16, 8>* sPlaneObjectBucket;
static const float skWorstMinMaxDistance[2];
static float sMinMaxDistance[2];
public:
static void Clear();
static void Sort();
2017-11-12 05:14:57 +00:00
static void InsertPlaneObject(float dist, float something, const zeus::CAABox& aabb, bool invertTest,
const zeus::CPlane& plane, bool zOnly, EDrawableType dtype, const void* data);
2016-07-25 22:52:02 +00:00
static void Insert(const zeus::CVector3f& pos, const zeus::CAABox& aabb, EDrawableType dtype,
const void* data, const zeus::CPlane& plane, u16 extraSort);
static void Shutdown();
static void Init();
};
2016-07-21 05:21:45 +00:00
class CBooRenderer : public IRenderer
2015-08-18 05:54:43 +00:00
{
2016-07-31 02:06:47 +00:00
friend class CBooModel;
2017-10-17 05:51:53 +00:00
friend class CModel;
friend class CGameArea;
2016-08-20 04:22:13 +00:00
friend class CWorldTransManager;
2017-03-06 06:33:51 +00:00
friend class CMorphBallShadow;
2016-07-31 02:06:47 +00:00
2016-07-26 22:05:59 +00:00
struct CAreaListItem
{
const std::vector<CMetroidModelInstance>* x0_geometry;
2016-08-07 00:20:02 +00:00
const CAreaRenderOctTree* x4_octTree;
/* originally auto_ptrs of vectors */
std::vector<TCachedToken<CTexture>> x8_textures;
2016-07-26 22:05:59 +00:00
std::vector<CBooModel*> x10_models;
2016-07-28 04:55:06 +00:00
int x18_areaIdx;
/* Per-area octree-word major, light bits minor */
std::vector<u32> x1c_lightOctreeWords;
const SShader* m_shaderSet;
2016-07-26 22:05:59 +00:00
CAreaListItem(const std::vector<CMetroidModelInstance>* geom,
const CAreaRenderOctTree* octTree,
std::vector<TCachedToken<CTexture>>&& textures,
std::vector<CBooModel*>&& models, int areaIdx,
const SShader* shaderSet);
2016-07-26 22:05:59 +00:00
~CAreaListItem();
};
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;
}
};
IFactory& x8_factory;
IObjectStore& xc_store;
TLockedToken<CTexture> m_staticEntropy;
// CFont x10_fnt;
u32 x18_ = 0;
2016-07-26 22:05:59 +00:00
std::list<CAreaListItem> x1c_areaListItems;
zeus::CFrustum x44_frustumPlanes;
2016-07-28 04:55:06 +00:00
TDrawableCallback xa8_drawableCallback;
2016-07-25 22:52:02 +00:00
const void* xac_callbackContext;
2016-07-28 04:55:06 +00:00
zeus::CPlane xb0_viewPlane = {0.f, 1.f, 0.f, 0.f};
2016-07-25 22:52:02 +00:00
2016-07-27 23:06:57 +00:00
enum class EPVSMode
{
Mask,
PVS,
PVSAndMask
} xc4_pvsMode = EPVSMode::Mask;
std::experimental::optional<CPVSVisSet> xc8_pvs;
2017-03-06 06:33:51 +00:00
u32 xe0_pvsAreaIdx = 0;
2016-07-27 23:06:57 +00:00
2016-07-25 22:52:02 +00:00
//boo::ITextureS* xe4_blackTex = nullptr;
bool xee_24_ : 1;
boo::ObjToken<boo::ITextureR> x14c_reflectionTex;
2016-07-29 17:38:44 +00:00
//boo::ITextureS* x150_mirrorRamp = nullptr;
boo::ObjToken<boo::ITextureS> x1b8_fogVolumeRamp;
boo::ObjToken<boo::ITextureS> x220_sphereRamp;
2016-07-25 22:52:02 +00:00
TLockedToken<CTexture> m_thermoPaletteTex;
boo::ObjToken<boo::ITexture> x288_thermoPalette;
2017-03-05 07:57:12 +00:00
TLockedToken<CTexture> m_ballFadeTex;
boo::ObjToken<boo::ITexture> m_ballFade;
boo::ObjToken<boo::ITextureR> m_ballShadowId;
boo::ObjToken<boo::IGraphicsBufferS> m_scanLinesEvenVBO;
boo::ObjToken<boo::IGraphicsBufferS> m_scanLinesOddVBO;
2017-03-05 07:57:12 +00:00
int m_ballShadowIdW = 64;
int m_ballShadowIdH = 64;
2016-07-25 22:52:02 +00:00
CRandom16 x2a8_thermalRand;
std::list<CFogVolumeListItem> x2ac_fogVolumes;
std::list<CFogVolumePlaneShader> m_fogVolumePlaneShaders;
std::list<CFogVolumePlaneShader>::iterator m_nextFogVolumePlaneShader;
std::list<CFogVolumeFilter> m_fogVolumeFilters;
std::list<CFogVolumeFilter>::iterator m_nextFogVolumeFilter;
std::list<std::pair<zeus::CVector3f, float>> x2c4_spaceWarps;
2017-03-26 05:53:04 +00:00
u32 x2dc_reflectionAge = 2;
2016-07-25 22:52:02 +00:00
zeus::CColor x2e0_ = zeus::CColor::skWhite;
zeus::CVector3f x2e4_ = {0.f, 1.f, 0.f};
2016-07-31 02:06:47 +00:00
CSpaceWarpFilter m_spaceWarpFilter;
float x2f0_thermalVisorLevel;
2016-07-25 22:52:02 +00:00
zeus::CColor x2f4_thermColor;
float x2f8_thermColdScale = 0.f;
zeus::CColor x2fc_tevReg1Color = {1.f, 0.f, 1.f, 1.f};
CThermalColdFilter m_thermColdFilter;
2016-08-03 21:53:03 +00:00
std::experimental::optional<CThermalHotFilter> m_thermHotFilter;
std::vector<CLight> x300_dynamicLights;
2016-07-28 04:55:06 +00:00
2017-05-06 05:21:42 +00:00
u32 x310_phazonSuitMaskCountdown = 0;
//std::unique_ptr<CTexture> x314_phazonSuitMask;
CPhazonSuitFilter m_phazonSuitFilter;
2016-07-25 22:52:02 +00:00
union
{
struct
{
bool x318_24_refectionDirty : 1;
2016-07-27 23:06:57 +00:00
bool x318_25_drawWireframe : 1;
2017-03-06 06:33:51 +00:00
bool x318_26_requestRGBA6 : 1;
bool x318_27_currentRGBA6 : 1;
2016-08-08 04:48:18 +00:00
bool x318_28_disableFog : 1;
2016-07-31 02:06:47 +00:00
bool x318_29_thermalVisor : 1;
2017-03-06 06:33:51 +00:00
bool x318_30_inAreaDraw : 1;
bool x318_31_persistRGBA6 : 1;
2016-07-25 22:52:02 +00:00
};
u16 dummy = 0;
};
void GenerateFogVolumeRampTex(boo::IGraphicsDataFactory::Context& ctx);
void GenerateSphereRampTex(boo::IGraphicsDataFactory::Context& ctx);
void GenerateScanLinesVBO(boo::IGraphicsDataFactory::Context& ctx);
void LoadThermoPalette();
2017-03-05 07:57:12 +00:00
void LoadBallFade();
2016-07-25 22:52:02 +00:00
2016-07-28 04:55:06 +00:00
void ActivateLightsForModel(CAreaListItem* item, CBooModel& model);
void RenderBucketItems(CAreaListItem* item);
void HandleUnsortedModel(CAreaListItem* item, CBooModel& model);
static void CalcDrawFogFan(const zeus::CPlane* planes, int numPlanes, const zeus::CVector3f* verts,
int numVerts, int iteration, int level, CFogVolumePlaneShader& fogVol);
static void DrawFogSlices(const zeus::CPlane* planes, int numPlanes, int iteration,
const zeus::CVector3f& center, float delta, CFogVolumePlaneShader& fogVol);
static void RenderFogVolumeModel(const zeus::CAABox& aabb, const CModel* model, const zeus::CTransform& modelMtx,
const zeus::CTransform& viewMtx, const CSkinnedModel* sModel, int pass,
CFogVolumePlaneShader* fvs);
2017-04-13 19:28:31 +00:00
void SetupRendererStates() const;
2016-07-25 22:52:02 +00:00
2017-05-06 05:21:42 +00:00
void ReallyDrawPhazonSuitIndirectEffect(const zeus::CColor& vertColor, /*const CTexture& maskTex,*/
const CTexture& indTex, const zeus::CColor& modColor,
float scale, float offX, float offY);
void ReallyDrawPhazonSuitEffect(const zeus::CColor& modColor /*, const CTexture& maskTex*/);
void DoPhazonSuitIndirectAlphaBlur(float blurRadius /*, float f2*/, const TLockedToken<CTexture>& indTex);
2015-08-18 05:54:43 +00:00
public:
CBooRenderer(IObjectStore& store, IFactory& resFac);
2016-07-21 05:21:45 +00:00
2016-07-26 22:05:59 +00:00
void AddWorldSurfaces(CBooModel& model);
std::list<CAreaListItem>::iterator FindStaticGeometry(const std::vector<CMetroidModelInstance>*);
void AddStaticGeometry(const std::vector<CMetroidModelInstance>*, const CAreaRenderOctTree*, int areaIdx,
const SShader* shaderSet);
void EnablePVS(const CPVSVisSet&, u32);
2016-07-27 23:06:57 +00:00
void DisablePVS();
2017-11-12 05:14:57 +00:00
void UpdateAreaUniforms(int areaIdx);
2016-07-26 22:05:59 +00:00
void RemoveStaticGeometry(const std::vector<CMetroidModelInstance>*);
2017-03-06 06:33:51 +00:00
void DrawAreaGeometry(int areaIdx, int mask, int targetMask);
2016-07-28 04:55:06 +00:00
void DrawUnsortedGeometry(int areaIdx, int mask, int targetMask);
void DrawSortedGeometry(int areaIdx, int mask, int targetMask);
void DrawStaticGeometry(int areaIdx, int mask, int targetMask);
2017-05-06 05:21:42 +00:00
void DrawModelFlat(const CModel& model, const CModelFlags& flags, bool unsortedOnly);
2016-07-21 05:21:45 +00:00
void PostRenderFogs();
2016-07-26 22:05:59 +00:00
void AddParticleGen(const CParticleGen&);
2016-07-21 05:21:45 +00:00
void AddPlaneObject(const void*, const zeus::CAABox&, const zeus::CPlane&, int);
void AddDrawable(void const *, const zeus::CVector3f&, const zeus::CAABox&, int, EDrawableSorting);
void SetDrawableCallback(TDrawableCallback, const void*);
2016-07-21 05:21:45 +00:00
void SetWorldViewpoint(const zeus::CTransform&);
void SetPerspective(float, float, float, float, float);
void SetPerspective(float, float, float, float);
2017-06-01 05:34:24 +00:00
std::pair<zeus::CVector2f, zeus::CVector2f> SetViewportOrtho(bool, float, float);
2016-07-26 22:05:59 +00:00
void SetClippingPlanes(const zeus::CFrustum& frustum);
2016-07-21 05:21:45 +00:00
void SetViewport(int, int, int, int);
2016-07-31 02:06:47 +00:00
//void SetDepthReadWrite(bool, bool);
//void SetBlendMode_AdditiveAlpha();
//void SetBlendMode_AlphaBlended();
//void SetBlendMode_NoColorWrite();
//void SetBlendMode_ColorMultiply();
//void SetBlendMode_InvertDst();
//void SetBlendMode_InvertSrc();
//void SetBlendMode_Replace();
//void SetBlendMode_AdditiveDestColor();
2016-07-21 05:21:45 +00:00
void SetDebugOption(EDebugOption, int);
void BeginScene();
void EndScene();
2016-07-31 02:06:47 +00:00
//void BeginPrimitive(EPrimitiveType, int);
//void BeginLines(int);
//void BeginLineStrip(int);
//void BeginTriangles(int);
//void BeginTriangleStrip(int);
//void BeginTriangleFan(int);
//void PrimVertex(const zeus::CVector3f&);
//void PrimNormal(const zeus::CVector3f&);
//void PrimColor(float, float, float, float);
//void PrimColor(const zeus::CColor&);
//void EndPrimitive();
2016-07-21 05:21:45 +00:00
void SetAmbientColor(const zeus::CColor&);
void DrawString(const char*, int, int);
u32 GetFPS();
2017-03-26 05:53:04 +00:00
void CacheReflection(TReflectionCallback, void*, bool);
2016-07-21 05:21:45 +00:00
void DrawSpaceWarp(const zeus::CVector3f&, float);
2016-07-31 02:06:47 +00:00
void DrawThermalModel(const CModel& model, const zeus::CColor& multCol, const zeus::CColor& addCol);
2016-08-07 00:20:02 +00:00
void DrawXRayOutline(const zeus::CAABox&);
2016-07-21 05:21:45 +00:00
void SetWireframeFlags(int);
void SetWorldFog(ERglFogMode, float, float, const zeus::CColor&);
void RenderFogVolume(const zeus::CColor&, const zeus::CAABox&, const TLockedToken<CModel>*, const CSkinnedModel*);
void SetThermal(bool, float, const zeus::CColor&);
void SetThermalColdScale(float scale);
2016-07-21 05:21:45 +00:00
void DoThermalBlendCold();
void DoThermalBlendHot();
u32 GetStaticWorldDataSize();
void PrepareDynamicLights(const std::vector<CLight>& lights);
2017-04-13 19:28:31 +00:00
void SetWorldLightMultiplyColor(const zeus::CColor& color);
void SetWorldLightFadeLevel(float level);
2017-05-06 05:21:42 +00:00
void DrawPhazonSuitIndirectEffect(const zeus::CColor& nonIndirectMod, const TLockedToken<CTexture>& indTex,
const zeus::CColor& indirectMod, float blurRadius,
float indScale, float indOffX, float indOffY);
void AllocatePhazonSuitMaskTexture();
2016-07-25 22:52:02 +00:00
void ReallyRenderFogVolume(const zeus::CColor& color, const zeus::CAABox& aabb,
const CModel* model, const CSkinnedModel* sModel);
const boo::ObjToken<boo::ITexture>& GetThermoPalette() {return x288_thermoPalette;}
const boo::ObjToken<boo::ITextureS>& GetFogRampTex() {return x1b8_fogVolumeRamp;}
const boo::ObjToken<boo::ITexture>& GetRandomStaticEntropyTex() const {return m_staticEntropy->GetBooTexture();}
const boo::ObjToken<boo::IGraphicsBufferS>& GetScanLinesEvenVBO() const {return m_scanLinesEvenVBO;}
const boo::ObjToken<boo::IGraphicsBufferS>& GetScanLinesOddVBO() const {return m_scanLinesOddVBO;}
2016-08-03 21:53:03 +00:00
static void BindMainDrawTarget() {CGraphics::g_BooMainCommandQueue->setRenderTarget(CGraphics::g_SpareTexture);}
2016-07-25 22:52:02 +00:00
void BindReflectionDrawTarget() {CGraphics::g_BooMainCommandQueue->setRenderTarget(x14c_reflectionTex);}
2017-03-05 07:57:12 +00:00
void BindBallShadowIdTarget()
{
CGraphics::g_BooMainCommandQueue->setRenderTarget(m_ballShadowId);
SetViewport(0, 0, m_ballShadowIdW, m_ballShadowIdH);
}
void ResolveBallShadowIdTarget()
{
CGraphics::g_BooMainCommandQueue->resolveBindTexture(m_ballShadowId,
boo::SWindowRect(0, 0,
m_ballShadowIdW,
m_ballShadowIdH),
false, 0, true, false);
2017-03-05 07:57:12 +00:00
}
void FindOverlappingWorldModels(std::vector<u32>& modelBits, const zeus::CAABox& aabb) const;
int DrawOverlappingWorldModelIDs(int alphaVal, const std::vector<u32>& modelBits,
const zeus::CAABox& aabb) const;
2017-03-06 06:33:51 +00:00
void DrawOverlappingWorldModelShadows(int alphaVal, const std::vector<u32>& modelBits,
const zeus::CAABox& aabb, float alpha) const;
2015-08-18 05:54:43 +00:00
};
}
2016-04-13 06:07:23 +00:00
#endif // __URDE_CBOORENDERER_HPP__