81 lines
1.7 KiB
C++
81 lines
1.7 KiB
C++
#ifndef FUNNY_MATERIALS_H
|
|
#define FUNNY_MATERIALS_H
|
|
#include "datamap.h"
|
|
#include "stdint.h"
|
|
#include "cglm/mat4.h"
|
|
|
|
#define TEXTURE_INVALID 0
|
|
#define TEXTURE_NO_TEXTURE -1
|
|
|
|
namespace FMat
|
|
{
|
|
typedef int32_t XMTexture;
|
|
struct XMFLOAT2
|
|
{
|
|
float x;
|
|
float y;
|
|
};
|
|
struct XMFLOAT3
|
|
{
|
|
float x;
|
|
float y;
|
|
float z;
|
|
};
|
|
struct XMFLOAT4
|
|
{
|
|
float x;
|
|
float y;
|
|
float z;
|
|
float w;
|
|
};
|
|
struct XMFLOAT4x4
|
|
{
|
|
XMFLOAT4 row1;
|
|
XMFLOAT4 row2;
|
|
XMFLOAT4 row3;
|
|
XMFLOAT4 row4;
|
|
};
|
|
}
|
|
struct MaterialData_t
|
|
{
|
|
FMat::XMFLOAT4 m_vAlbedoColor;
|
|
uint32_t m_uAlbedo;
|
|
};
|
|
|
|
class CBaseMaterial
|
|
{
|
|
public:
|
|
DECLARE_CLASS_NOBASE(CBaseMaterial)
|
|
DECLARE_DATADESC_NOBASE()
|
|
virtual const char *GetShaderPath() { return NULL; };
|
|
virtual void *GetDataPtr() { return 0; };
|
|
virtual size_t GetDataSize() { return 0; };
|
|
virtual void SetUpMesh( MaterialData_t *pData ) {};
|
|
|
|
uint64_t m_uHash;
|
|
};
|
|
|
|
typedef CBaseMaterial *( *InstantiateMaterialFn )( void );
|
|
class CFunnyMaterialRegistry
|
|
{
|
|
public:
|
|
CFunnyMaterialRegistry( InstantiateMaterialFn fn, const char *szName );
|
|
|
|
InstantiateMaterialFn m_CreateFn;
|
|
const char *m_szName;
|
|
|
|
CFunnyMaterialRegistry *m_pNext;
|
|
};
|
|
CBaseMaterial *CreateMaterial( const char *szName );
|
|
|
|
#define DECLARE_SHADER(path) \
|
|
virtual const char *GetShaderPath() override { return path; }; \
|
|
virtual void *GetDataPtr() override { return (char*)this+_class_offsetof(ThisClass, m_uHash); } \
|
|
virtual size_t GetDataSize() override { return sizeof(ThisClass)-_class_offsetof(ThisClass, m_uHash); }
|
|
|
|
#define DEFINE_MATERIAL( className, name ) \
|
|
static CBaseMaterial *__Create##className##_material() { return ( CBaseMaterial* )( new className ); }; \
|
|
static CFunnyMaterialRegistry __CreateMaterail##className##_registry( __Create##className##_material, name );
|
|
|
|
#endif
|