mirror of
https://github.com/AxioDL/metaforce.git
synced 2025-05-14 00:31:21 +00:00
140 lines
4.1 KiB
C++
140 lines
4.1 KiB
C++
#ifndef __PSHAG_CMODEL_HPP__
|
|
#define __PSHAG_CMODEL_HPP__
|
|
|
|
#include "RetroTypes.hpp"
|
|
#include "zeus/CColor.hpp"
|
|
#include "CFactoryMgr.hpp"
|
|
#include "CToken.hpp"
|
|
#include "zeus/CAABox.hpp"
|
|
#include "DNACommon/CMDL.hpp"
|
|
#include "DNAMP1/CMDLMaterials.hpp"
|
|
|
|
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
|
|
|
|
namespace urde
|
|
{
|
|
class IObjectStore;
|
|
class CTexture;
|
|
|
|
struct CModelFlags
|
|
{
|
|
u8 f1; /* Blend state 3/5 enable additive */
|
|
u8 f2;
|
|
u16 f3; /* Depth state */
|
|
zeus::CColor color; /* Set into kcolor slot specified by material */
|
|
|
|
/* depth flags
|
|
0x4: render without texture lock
|
|
0x8: greater
|
|
0x10: non-inclusive
|
|
*/
|
|
};
|
|
|
|
/* urde addition: doesn't require hacky stashing of
|
|
* pointers within loaded CMDL buffer */
|
|
struct CBooSurface
|
|
{
|
|
DataSpec::DNACMDL::SurfaceHeader_1 m_data;
|
|
class CBooModel* m_parent = nullptr;
|
|
CBooSurface* m_next = nullptr;
|
|
};
|
|
|
|
class CBooModel
|
|
{
|
|
public:
|
|
struct SShader
|
|
{
|
|
std::vector<TCachedToken<CTexture>> x0_textures;
|
|
std::vector<boo::IShaderPipeline*> m_shaders;
|
|
DataSpec::DNAMP1::HMDLMaterialSet m_matSet;
|
|
void UnlockTextures();
|
|
};
|
|
|
|
private:
|
|
std::vector<CBooSurface>* x0_surfaces;
|
|
const DataSpec::DNAMP1::HMDLMaterialSet* x4_matSet;
|
|
const std::vector<boo::IShaderPipeline*>* m_pipelines;
|
|
boo::IVertexFormat* m_vtxFmt;
|
|
boo::IGraphicsBufferS* x8_vbo;
|
|
boo::IGraphicsBufferS* xc_ibo;
|
|
std::vector<TCachedToken<CTexture>>* x1c_textures;
|
|
zeus::CAABox x20_aabb;
|
|
CBooSurface* x38_firstUnsortedSurface = nullptr;
|
|
CBooSurface* x3c_firstSortedSurface = nullptr;
|
|
bool x40_24_texturesLoaded : 1;
|
|
bool x40_25_ : 1;
|
|
u8 x41_shortNormals;
|
|
|
|
/* urde addition: boo! */
|
|
boo::GraphicsDataToken m_gfxToken;
|
|
boo::IGraphicsBufferD* m_uniformBuffer;
|
|
std::vector<boo::IShaderDataBinding*> m_shaderDataBindings;
|
|
|
|
void DrawAlphaSurfaces(const CModelFlags& flags) const;
|
|
void DrawNormalSurfaces(const CModelFlags& flags) const;
|
|
void DrawSurfaces(const CModelFlags& flags) const;
|
|
void DrawSurface(const CBooSurface& surf, const CModelFlags& flags) const;
|
|
|
|
void BuildGfxToken();
|
|
|
|
public:
|
|
CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
|
|
boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo,
|
|
const zeus::CAABox& aabb,
|
|
u8 shortNormals, bool texturesLoaded);
|
|
|
|
static void MakeTexuresFromMats(const DataSpec::DNAMP1::HMDLMaterialSet& matSet,
|
|
std::vector<TCachedToken<CTexture>>& toksOut,
|
|
IObjectStore& store);
|
|
|
|
void RemapMaterialData(SShader& shader);
|
|
bool TryLockTextures() const;
|
|
void UnlockTextures() const;
|
|
void DrawAlpha(const CModelFlags& flags) const;
|
|
void DrawNormal(const CModelFlags& flags) const;
|
|
void Draw(const CModelFlags& flags) const;
|
|
|
|
const DataSpec::DNAMP1::HMDLMaterialSet::Material& GetMaterialByIndex(int idx) const
|
|
{
|
|
return x4_matSet->materials.at(idx);
|
|
}
|
|
|
|
static bool g_DrawingOccluders;
|
|
static void SetDrawingOccluders(bool occ) {g_DrawingOccluders = occ;}
|
|
};
|
|
|
|
class CModel
|
|
{
|
|
std::unique_ptr<u8[]> x0_data;
|
|
u32 x4_dataLen;
|
|
std::vector<CBooSurface> x8_surfaces;
|
|
std::vector<CBooModel::SShader> x18_matSets;
|
|
std::unique_ptr<CBooModel> x28_modelInst;
|
|
CModel* x30_next = nullptr;
|
|
CModel* x34_prev = nullptr;
|
|
|
|
/* urde addition: boo! */
|
|
boo::GraphicsDataToken m_gfxToken;
|
|
boo::IGraphicsBufferS* m_vbo;
|
|
boo::IGraphicsBufferS* m_ibo;
|
|
boo::IVertexFormat* m_vtxFmt;
|
|
|
|
void VerifyCurrentShader(int shaderIdx) const;
|
|
|
|
public:
|
|
CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store);
|
|
void DrawSortedParts(const CModelFlags& flags) const;
|
|
void DrawUnsortedParts(const CModelFlags& flags) const;
|
|
void Draw(const CModelFlags& flags) const;
|
|
void Touch(int shaderIdx) const;
|
|
bool IsLoaded(int shaderIdx) const;
|
|
};
|
|
|
|
CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag,
|
|
std::unique_ptr<u8[]>&& in, u32 len,
|
|
const urde::CVParamTransfer& vparms);
|
|
|
|
}
|
|
|
|
#endif // __PSHAG_CMODEL_HPP__
|