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

152 lines
6.7 KiB
C
Raw Normal View History

2024-12-05 13:49:44 +08:00
#pragma once
2024-10-22 01:51:25 +08:00
#include<hgl/graph/VK.h>
#include<hgl/graph/VKDevice.h>
#include<hgl/type/IDName.h>
2024-10-22 01:51:25 +08:00
VK_NAMESPACE_BEGIN
class RenderCmdBuffer;
class GraphModule;
class RenderFramework;
class GraphModuleManager
{
GPUDevice *device;
RenderFramework *framework;
List<GraphModule *> module_list; ///<模块列表
Map<AnsiIDName,GraphModule *> graph_module_map; ///<模块映射表
public:
GraphModuleManager(RenderFramework *);
~GraphModuleManager();
2024-11-19 00:20:35 +08:00
GPUDevice * GetDevice ()noexcept {return device;} ///<取得GPU设备
VkDevice GetVkDevice ()const {return device->GetDevice();}
const GPUPhysicalDevice * GetPhysicalDevice ()const {return device->GetPhysicalDevice();} ///<取得物理设备
GPUDeviceAttribute *GetDeviceAttribute () {return device->GetDeviceAttribute();} ///<取得设备属性
RenderFramework * GetFramework () {return framework;} ///<取得渲染框架
/**
*
* @param create
*/
GraphModule *GetModule(const AnsiIDName &name,bool create); ///<获取指定名称的模块
/**
*
* @param create
*/
template<typename T>
T *GetModule(bool create=false){return (T *)GetModule(T::GetModuleName(),create);} ///<获取指定类型的模块
void ReleaseModule(GraphModule *); ///<释放指定模块
const bool IsLoaded(const AnsiIDName &name){return graph_module_map.ContainsKey(name);} ///<是否已经加载了指定类型的模块
template<typename T>
const bool IsLoaded(){return graph_module_map.ContainsKey(T::GetModuleName());} ///<是否已经加载了指定类型的模块
public: //事件
void OnResize(const VkExtent2D &);
};//class GraphModuleManager
GraphModuleManager *GetGraphModuleManager(GPUDevice *);
2024-10-22 01:51:25 +08:00
class GraphModule:public Comparator<GraphModule>
2024-10-22 01:51:25 +08:00
{
GraphModuleManager *module_manager;
AnsiIDName module_name;
2024-10-22 01:51:25 +08:00
2024-12-05 13:49:44 +08:00
SortedSet<AnsiIDName> dependent_module; ///<依赖的模块
bool module_init;
2024-10-22 01:51:25 +08:00
bool module_enable;
bool module_ready;
protected:
virtual void SetModuleEnable(bool e){module_enable=e;}
virtual void SetModuleReady(bool r){module_ready=r;}
public:
2024-11-19 00:20:35 +08:00
virtual const bool IsPerFrame () {return false;} ///<是否每帧运行
2024-11-15 00:11:06 +08:00
virtual const bool IsRender () {return false;} ///<是否为渲染模块
2024-11-15 00:11:06 +08:00
GraphModuleManager *GetManager () {return module_manager;} ///<取得模块管理器
GPUDevice * GetDevice () {return module_manager->GetDevice();} ///<取得GPU设备
VkDevice GetVkDevice ()const {return module_manager->GetVkDevice();} ///<取得VkDevice
const GPUPhysicalDevice * GetPhysicalDevice ()const {return module_manager->GetPhysicalDevice();} ///<取得物理设备
GPUDeviceAttribute *GetDeviceAttribute () {return module_manager->GetDeviceAttribute();} ///<取得设备属性
RenderFramework * GetFramework () {return module_manager->GetFramework();} ///<取得渲染框架
2024-11-15 00:11:06 +08:00
static const AnsiIDName * GetModuleName (){return nullptr;} ///<取得模块名称(标准通用的名称比如Upscale供通用模块使用)
virtual const AnsiIDName * GetName ()const{return &module_name;} ///<取得名称(完整的私有名称比如FSR3Upscale,DLSS3Upscale)
2024-10-22 01:51:25 +08:00
virtual const bool IsRender (){return false;} ///<是否为渲染模块
const bool IsInit ()const{return module_init;} ///<是否已经初始化
2024-11-15 00:11:06 +08:00
const bool IsEnable ()const noexcept{return module_enable;} ///<当前模块是否启用
const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好
2024-10-22 01:51:25 +08:00
public:
NO_COPY_NO_MOVE(GraphModule)
GraphModule(GraphModuleManager *gmm,const AnsiIDName &name);
virtual ~GraphModule();
2024-10-22 01:51:25 +08:00
virtual bool Init(){module_init=true;return true;} ///<初始化当前模块
const int compare(const GraphModule &gm)const override
2024-12-05 13:49:44 +08:00
{
return(dependent_module.Contains(gm.module_name)?1:-1); //如果我依赖于他,那么我比他大
2024-12-05 13:49:44 +08:00
}
public:
GraphModule * GetModule(const AnsiIDName &name,bool create=false){return module_manager->GetModule(name,create);} ///<获取指定名称的模块
template<typename T>
T * GetModule(bool create=false){return module_manager->GetModule<T>(create);} ///<获取指定类型的模块
2024-10-22 01:51:25 +08:00
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
#define GRAPH_MODULE_CONSTRUCT(name) public:\
NO_COPY_NO_MOVE(name) \
static const AnsiIDName &GetModuleName() \
{ \
static const AnsiIDName id_name(#name); \
return id_name; \
} \
\
name(GraphModuleManager *gmm):GraphModule(gmm,GetModuleName()){}
2024-10-22 01:51:25 +08:00
#define RENDER_MODULE_CONSTRUCT(name) public:\
NO_COPY_NO_MOVE(name) \
static const AnsiIDName &GetModuleName() \
{ \
static const AnsiIDName id_name(#name); \
return id_name; \
} \
\
name(GraphModuleManager *gmm):RenderModule(gmm,GetModuleName()){}
VK_NAMESPACE_END