metaforce/Runtime/Graphics/CModel.hpp

163 lines
4.8 KiB
C++
Raw Normal View History

2016-02-13 09:02:47 +00:00
#ifndef __PSHAG_CMODEL_HPP__
#define __PSHAG_CMODEL_HPP__
2016-02-13 00:57:09 +00:00
#include "RetroTypes.hpp"
2016-03-04 23:04:53 +00:00
#include "zeus/CColor.hpp"
2016-03-29 23:14:14 +00:00
#include "CFactoryMgr.hpp"
#include "CToken.hpp"
#include "zeus/CAABox.hpp"
2016-03-31 02:44:43 +00:00
#include "DNACommon/CMDL.hpp"
#include "DNAMP1/CMDLMaterials.hpp"
2016-02-13 00:57:09 +00:00
2016-03-30 19:16:01 +00:00
#include "boo/graphicsdev/IGraphicsDataFactory.hpp"
2016-03-04 23:04:53 +00:00
namespace urde
2016-02-13 00:57:09 +00:00
{
2016-03-29 23:14:14 +00:00
class IObjectStore;
class CTexture;
2016-02-13 00:57:09 +00:00
struct CModelFlags
{
2016-03-31 06:18:56 +00:00
u8 m_blendMode = 0; /* Blend state 3/5 enable additive */
u8 m_matSetIdx = 0;
u16 m_flags = 0; /* Flags */
2016-03-17 02:18:01 +00:00
zeus::CColor color; /* Set into kcolor slot specified by material */
2016-03-31 06:18:56 +00:00
/* Flags
2016-03-31 02:44:43 +00:00
0x4: render without texture lock
2016-03-31 06:18:56 +00:00
0x8: depth greater
0x10: depth non-inclusive
2016-03-17 02:18:01 +00:00
*/
2016-02-13 00:57:09 +00:00
};
2016-03-31 02:44:43 +00:00
/* urde addition: doesn't require hacky stashing of
* pointers within loaded CMDL buffer */
struct CBooSurface
2016-03-30 19:16:01 +00:00
{
2016-03-31 02:44:43 +00:00
DataSpec::DNACMDL::SurfaceHeader_1 m_data;
class CBooModel* m_parent = nullptr;
CBooSurface* m_next = nullptr;
2016-03-30 19:16:01 +00:00
};
2016-03-31 06:18:56 +00:00
struct SUnskinnedXf
{
zeus::CMatrix4f mv;
zeus::CMatrix4f mvinv;
zeus::CMatrix4f proj;
};
2016-03-29 23:14:14 +00:00
class CBooModel
{
2016-03-31 06:18:56 +00:00
friend class CModel;
2016-03-29 23:14:14 +00:00
public:
2016-03-31 06:18:56 +00:00
using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;
using UVAnimation = DataSpec::DNAMP1::MaterialSet::Material::UVAnimation;
2016-03-31 02:44:43 +00:00
struct SShader
2016-03-29 23:14:14 +00:00
{
2016-03-31 02:44:43 +00:00
std::vector<TCachedToken<CTexture>> x0_textures;
std::vector<boo::IShaderPipeline*> m_shaders;
2016-03-31 06:18:56 +00:00
MaterialSet m_matSet;
2016-03-31 02:44:43 +00:00
void UnlockTextures();
2016-03-29 23:14:14 +00:00
};
2016-03-31 02:44:43 +00:00
2016-03-29 23:14:14 +00:00
private:
2016-03-31 02:44:43 +00:00
std::vector<CBooSurface>* x0_surfaces;
2016-03-31 06:18:56 +00:00
const MaterialSet* x4_matSet;
2016-03-31 02:44:43 +00:00
const std::vector<boo::IShaderPipeline*>* m_pipelines;
boo::IVertexFormat* m_vtxFmt;
2016-03-30 19:16:01 +00:00
boo::IGraphicsBufferS* x8_vbo;
boo::IGraphicsBufferS* xc_ibo;
2016-03-31 02:44:43 +00:00
std::vector<TCachedToken<CTexture>>* x1c_textures;
2016-03-29 23:14:14 +00:00
zeus::CAABox x20_aabb;
2016-03-31 02:44:43 +00:00
CBooSurface* x38_firstUnsortedSurface = nullptr;
CBooSurface* x3c_firstSortedSurface = nullptr;
bool x40_24_texturesLoaded : 1;
2016-03-29 23:14:14 +00:00
bool x40_25_ : 1;
u8 x41_shortNormals;
2016-03-30 19:16:01 +00:00
2016-03-31 06:18:56 +00:00
struct UVAnimationBuffer
{
std::vector<zeus::CMatrix4f> m_buffer;
std::vector<std::pair<size_t,size_t>> m_ranges;
void ProcessAnimation(const UVAnimation& anim);
void PadOutBuffer();
void Update(const MaterialSet* matSet);
2016-03-31 21:06:41 +00:00
operator bool() const {return m_buffer.size() != 0;}
2016-03-31 06:18:56 +00:00
} m_uvAnimBuffer;
2016-03-30 19:16:01 +00:00
/* urde addition: boo! */
boo::GraphicsDataToken m_gfxToken;
2016-03-31 06:18:56 +00:00
boo::IGraphicsBufferD* m_unskinnedXfBuffer;
boo::IGraphicsBufferD* m_uvMtxBuffer;
2016-03-31 02:44:43 +00:00
std::vector<boo::IShaderDataBinding*> m_shaderDataBindings;
2016-03-30 19:16:01 +00:00
2016-03-31 06:18:56 +00:00
void BuildGfxToken();
void UpdateUniformData() const;
2016-03-30 19:16:01 +00:00
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;
2016-03-29 23:14:14 +00:00
public:
2016-03-31 02:44:43 +00:00
CBooModel(std::vector<CBooSurface>* surfaces, SShader& shader,
boo::IVertexFormat* vtxFmt, boo::IGraphicsBufferS* vbo, boo::IGraphicsBufferS* ibo,
2016-03-30 19:16:01 +00:00
const zeus::CAABox& aabb,
2016-03-31 02:44:43 +00:00
u8 shortNormals, bool texturesLoaded);
2016-03-29 23:14:14 +00:00
2016-03-31 06:18:56 +00:00
static void MakeTexuresFromMats(const MaterialSet& matSet,
2016-03-31 02:44:43 +00:00
std::vector<TCachedToken<CTexture>>& toksOut,
2016-03-29 23:14:14 +00:00
IObjectStore& store);
2016-03-31 02:44:43 +00:00
void RemapMaterialData(SShader& shader);
bool TryLockTextures() const;
2016-03-30 19:16:01 +00:00
void UnlockTextures() const;
void DrawAlpha(const CModelFlags& flags) const;
void DrawNormal(const CModelFlags& flags) const;
void Draw(const CModelFlags& flags) const;
2016-03-31 06:18:56 +00:00
const MaterialSet::Material& GetMaterialByIndex(int idx) const
2016-03-31 02:44:43 +00:00
{
return x4_matSet->materials.at(idx);
}
2016-03-30 19:16:01 +00:00
static bool g_DrawingOccluders;
static void SetDrawingOccluders(bool occ) {g_DrawingOccluders = occ;}
2016-03-29 23:14:14 +00:00
};
2016-02-13 00:57:09 +00:00
class CModel
{
2016-03-29 23:14:14 +00:00
std::unique_ptr<u8[]> x0_data;
u32 x4_dataLen;
2016-03-31 02:44:43 +00:00
std::vector<CBooSurface> x8_surfaces;
std::vector<CBooModel::SShader> x18_matSets;
2016-03-29 23:14:14 +00:00
std::unique_ptr<CBooModel> x28_modelInst;
CModel* x30_next = nullptr;
CModel* x34_prev = nullptr;
2016-03-30 19:16:01 +00:00
/* urde addition: boo! */
boo::GraphicsDataToken m_gfxToken;
boo::IGraphicsBufferS* m_vbo;
boo::IGraphicsBufferS* m_ibo;
2016-03-31 02:44:43 +00:00
boo::IVertexFormat* m_vtxFmt;
void VerifyCurrentShader(int shaderIdx) const;
2016-03-30 19:16:01 +00:00
2016-03-29 23:14:14 +00:00
public:
2016-03-31 06:18:56 +00:00
using MaterialSet = DataSpec::DNAMP1::HMDLMaterialSet;
2016-03-29 23:14:14 +00:00
CModel(std::unique_ptr<u8[]>&& in, u32 dataLen, IObjectStore* store);
2016-03-31 02:44:43 +00:00
void DrawSortedParts(const CModelFlags& flags) const;
void DrawUnsortedParts(const CModelFlags& flags) const;
2016-02-13 00:57:09 +00:00
void Draw(const CModelFlags& flags) const;
2016-03-31 02:44:43 +00:00
void Touch(int shaderIdx) const;
bool IsLoaded(int shaderIdx) const;
2016-02-13 00:57:09 +00:00
};
2016-03-29 23:14:14 +00:00
CFactoryFnReturn FModelFactory(const urde::SObjectTag& tag,
std::unique_ptr<u8[]>&& in, u32 len,
const urde::CVParamTransfer& vparms);
2016-02-13 00:57:09 +00:00
}
2016-02-13 09:02:47 +00:00
#endif // __PSHAG_CMODEL_HPP__