ULRE/inc/hgl/graph/module/GraphModule.h

119 lines
4.8 KiB
C
Raw Normal View History

2024-12-05 13:49:44 +08:00
#pragma once
2024-10-22 01:51:25 +08:00
2025-01-09 00:48:15 +08:00
#include<hgl/graph/RenderFramework.h>
#include<initializer_list>
2024-10-22 01:51:25 +08:00
VK_NAMESPACE_BEGIN
class RenderCmdBuffer;
class RenderFramework;
2025-01-09 00:48:15 +08:00
using GraphModuleHashList=std::initializer_list<size_t>;
2024-12-18 08:26:01 +08:00
2025-01-09 00:48:15 +08:00
class GraphModule
{
2025-01-09 00:48:15 +08:00
RenderFramework *render_framework;
AnsiIDName module_name;
2024-10-22 01:51:25 +08:00
bool module_inited;
bool module_enabled;
2024-10-22 01:51:25 +08:00
bool module_ready;
protected:
2025-01-08 13:26:27 +08:00
template<typename T>
2025-01-09 00:48:15 +08:00
T * GetModule(bool create=false){return render_framework->GetModule<T>(create);} ///<获取指定类型的模块
GraphModule * GetModule(const AnsiIDName &name,bool create=false); ///<获取指定名称的模块
2024-10-22 01:51:25 +08:00
protected:
virtual void SetModuleEnabled(bool e){module_enabled=e;}
2024-10-22 01:51:25 +08:00
virtual void SetModuleReady(bool r){module_ready=r;}
public:
2025-01-09 00:48:15 +08:00
GPUDevice * GetDevice () {return render_framework->GetDevice();} ///<取得GPU设备
VkDevice GetVkDevice ()const {return render_framework->GetVkDevice();} ///<取得VkDevice
const GPUPhysicalDevice * GetPhysicalDevice ()const {return render_framework->GetPhysicalDevice();} ///<取得物理设备
GPUDeviceAttribute *GetDeviceAttribute () {return render_framework->GetDeviceAttribute();} ///<取得设备属性
2024-10-22 01:51:25 +08:00
2025-01-09 00:48:15 +08:00
RenderFramework * GetFramework () {return render_framework;} ///<取得渲染框架
2024-12-18 08:26:01 +08:00
const AnsiIDName & GetName ()const {return module_name;} ///<取得模块名称(标准通用的名称比如Upscale供通用模块使用)
virtual const AnsiIDName & GetFullName ()const {return module_name;} ///<取得名称(完整的私有名称比如FSR3Upscale,DLSS3Upscale)
2024-10-22 01:51:25 +08:00
virtual const bool IsPerFrame () {return false;} ///<是否每帧运行
virtual const bool IsRender () {return false;} ///<是否为渲染模块
const bool IsInited ()const {return module_inited;} ///<是否已经初始化
const bool IsEnabled ()const noexcept{return module_enabled;} ///<当前模块是否启用
const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好
2024-10-22 01:51:25 +08:00
public:
NO_COPY_NO_MOVE(GraphModule)
2025-01-09 00:48:15 +08:00
protected:
2025-01-09 00:48:15 +08:00
GraphModule(RenderFramework *rf,const AnsiIDName &name);
2024-12-24 02:45:02 +08:00
2025-01-09 00:48:15 +08:00
public:
2024-12-24 02:45:02 +08:00
2025-01-09 00:48:15 +08:00
virtual ~GraphModule();
2024-12-24 02:45:02 +08:00
2025-01-09 00:48:15 +08:00
virtual const size_t GetTypeHash()const=0;
2025-01-09 00:48:15 +08:00
static const GraphModuleHashList GetDependentModules(){return {};} ///<取得依赖的模块列表
public: //回调事件
virtual void OnRenderTarget(RenderTarget *){} ///<设置渲染目标
virtual void OnResize(const VkExtent2D &){} ///<窗口大小改变
virtual void OnPreFrame(){} ///<帧绘制前回调
virtual void OnPostFrame(){} ///<帧绘制后回调
2024-10-22 01:51:25 +08:00
};//class GraphModule
2025-01-09 00:48:15 +08:00
using GraphModuleMapByIDName=Map<AnsiIDName,GraphModule *>;
//template<typename T,typename BASE> class GraphModuleInherit:public BASE
//{
//public:
//
// GraphModuleInherit(RenderFramework *rf):BASE(rf,typeid(T))
// {}
//
// static const size_t StaticHash()
// {
// return typeid(T).hash_code();
// }
//
//};//class GraphModuleInherit
#define GRAPH_MODULE_CREATE_FUNC(name) name *name::CreateModule(RenderFramework *rf,GraphModuleMapByIDName &dep_modules)
#define GRAPH_BASE_MODULE_CONSTRUCT(name,base_class) public:\
NO_COPY_NO_MOVE(name) \
2024-12-18 08:26:01 +08:00
static const size_t StaticHash(){return typeid(name).hash_code();} \
const size_t GetTypeHash()const override{return name::StaticHash();} \
static const AnsiIDName &GetModuleName() \
{ \
static const AnsiIDName id_name(#name); \
return id_name; \
} \
\
2025-01-09 00:48:15 +08:00
private: \
name(RenderFramework *rf):base_class(rf,GetModuleName()){} \
\
2025-01-09 00:48:15 +08:00
public: \
static name *CreateModule(RenderFramework *rf,GraphModuleMapByIDName &); \
static const GraphModuleHashList GetDependentModules();
#define GRAPH_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,GraphModule)
#define RENDER_MODULE_CONSTRUCT(name) GRAPH_BASE_MODULE_CONSTRUCT(name,RenderModule)
VK_NAMESPACE_END