first edition of GraphModule/GraphModuleManager
This commit is contained in:
parent
427d337845
commit
62f2e4f819
@ -24,6 +24,10 @@ constexpr size_t VK_DESCRIPTOR_TYPE_END_RANGE=VK_DESCRIPTOR_TYPE_INPUT_ATTACHMEN
|
|||||||
constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1;
|
constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1;
|
||||||
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
|
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
|
||||||
|
|
||||||
|
class GraphModule;
|
||||||
|
class RenderModule;
|
||||||
|
class GraphModuleManager;
|
||||||
|
|
||||||
using BindingMap =Map<AnsiString,int>;
|
using BindingMap =Map<AnsiString,int>;
|
||||||
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||||
|
|
||||||
|
@ -5,9 +5,12 @@
|
|||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
class RenderCmdBuffer;
|
class RenderCmdBuffer;
|
||||||
|
class GraphModuleManager;
|
||||||
|
|
||||||
class GraphModule
|
class GraphModule
|
||||||
{
|
{
|
||||||
|
GraphModuleManager *module_manager;
|
||||||
|
|
||||||
AnsiString module_name;
|
AnsiString module_name;
|
||||||
|
|
||||||
bool module_enable;
|
bool module_enable;
|
||||||
@ -20,10 +23,14 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const AnsiString &GetModuleName()const{return module_name;}
|
virtual const bool IsRender()=0; ///<是否为渲染模块
|
||||||
|
|
||||||
const bool IsEnable ()const noexcept{return module_enable;}
|
GraphModuleManager *GetManager(){return module_manager;} ///<取得模块管理器
|
||||||
const bool IsReady ()const noexcept{return module_ready;}
|
|
||||||
|
const AnsiString &GetModuleName()const{return module_name;} ///<取得模块名称
|
||||||
|
|
||||||
|
const bool IsEnable ()const noexcept{return module_enable;} ///<当前模块是否启用
|
||||||
|
const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -32,19 +39,37 @@ public:
|
|||||||
GraphModule(const AnsiString &name){module_name=name;}
|
GraphModule(const AnsiString &name){module_name=name;}
|
||||||
virtual ~GraphModule()=default;
|
virtual ~GraphModule()=default;
|
||||||
|
|
||||||
virtual bool Init(){return true;}
|
virtual bool Init(){return true;} ///<初始化当前模块
|
||||||
virtual void Execute(const double,RenderCmdBuffer *){}
|
|
||||||
|
|
||||||
|
public: //回调事件
|
||||||
|
|
||||||
|
virtual void OnRenderTarget(RenderTarget *){} ///<设置渲染目标
|
||||||
|
virtual void OnResize(const VkExtent2D &){} ///<窗口大小改变
|
||||||
|
|
||||||
|
virtual void OnPreFrame(){} ///<帧绘制前回调
|
||||||
|
virtual void OnExecute(const double,RenderCmdBuffer *){}
|
||||||
|
virtual void OnPostFrame(){} ///<帧绘制后回调
|
||||||
};//class GraphModule
|
};//class GraphModule
|
||||||
|
|
||||||
template<typename T> GraphModule *Create()
|
class GraphModuleManager
|
||||||
{
|
{
|
||||||
return new T();
|
GPUDevice *device;
|
||||||
}
|
|
||||||
|
|
||||||
typedef GraphModule *(*GraphModuleCreateFunc)();
|
Map<AnsiString,GraphModule *> graph_module_map;
|
||||||
|
|
||||||
bool RegistryGraphModule(const AnsiString &,GraphModuleCreateFunc);
|
public:
|
||||||
GraphModule *GetGraphModule(const AnsiString &);
|
|
||||||
|
GraphModuleManager(GPUDevice *dev){device=dev;}
|
||||||
|
~GraphModuleManager();
|
||||||
|
|
||||||
|
bool Registry(const AnsiString &name,GraphModule *gm);
|
||||||
|
GraphModule *GetModule(const AnsiString &name);
|
||||||
|
|
||||||
|
public: //事件
|
||||||
|
|
||||||
|
void OnResize(const VkExtent2D &);
|
||||||
|
};//class GraphModuleManager
|
||||||
|
|
||||||
|
GraphModuleManager *GetGraphModuleManager(GPUDevice *);
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
@ -5,35 +5,109 @@ VK_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
using GraphModuleMap=Map<AnsiString,GraphModuleCreateFunc>;
|
using GraphModuleManagerMap=Map<GPUDevice *,GraphModuleManager *>;
|
||||||
|
|
||||||
GraphModuleMap render_module_map;
|
static GraphModuleManagerMap *graph_module_manager_map=nullptr;
|
||||||
}//namespace
|
}
|
||||||
|
|
||||||
bool RegistryGraphModule(const AnsiString &name,GraphModuleCreateFunc func)
|
GraphModuleManager *InitGraphModuleManager(GPUDevice *dev)
|
||||||
{
|
{
|
||||||
if(name.IsEmpty()||!func)
|
if(!dev)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
if(graph_module_manager_map)
|
||||||
|
{
|
||||||
|
if(graph_module_manager_map->ContainsKey(dev))
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
graph_module_manager_map=new GraphModuleManagerMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphModuleManager *gmm=new GraphModuleManager(dev);
|
||||||
|
|
||||||
|
graph_module_manager_map->Add(dev,gmm);
|
||||||
|
|
||||||
|
return gmm;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ClearGraphModuleManager(GPUDevice *dev)
|
||||||
|
{
|
||||||
|
if(!dev)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(render_module_map.ContainsKey(name))
|
if(!graph_module_manager_map)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
render_module_map.Add(name,func);
|
GraphModuleManager *gmm;
|
||||||
|
|
||||||
|
if(!graph_module_manager_map->Get(dev,gmm))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
graph_module_manager_map->DeleteByKey(dev);
|
||||||
|
|
||||||
|
delete gmm;
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
GraphModule *GetGraphModule(const AnsiString &name)
|
GraphModuleManager *GetGraphModuleManager(GPUDevice *dev)
|
||||||
{
|
{
|
||||||
|
if(!dev)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
if(!graph_module_manager_map)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
GraphModuleManager *gmm;
|
||||||
|
|
||||||
|
if(graph_module_manager_map->Get(dev,gmm))
|
||||||
|
return gmm;
|
||||||
|
|
||||||
|
return(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool GraphModuleManager::Registry(const AnsiString &name,GraphModule *gm)
|
||||||
|
{
|
||||||
|
if(!gm)
|
||||||
|
return(false);
|
||||||
if(name.IsEmpty())
|
if(name.IsEmpty())
|
||||||
return(nullptr);
|
return(false);
|
||||||
|
|
||||||
GraphModuleCreateFunc func;
|
if(graph_module_map.ContainsKey(name))
|
||||||
|
return(false);
|
||||||
|
|
||||||
if(!render_module_map.Get(name,func))
|
graph_module_map.Add(name,gm);
|
||||||
return(nullptr);
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
return func();
|
GraphModule *GraphModuleManager::GetModule(const AnsiString &name)
|
||||||
|
{
|
||||||
|
GraphModule *gm;
|
||||||
|
|
||||||
|
if(graph_module_map.Get(name,gm))
|
||||||
|
return gm;
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphModuleManager::~GraphModuleManager()
|
||||||
|
{
|
||||||
|
for(auto *gm:graph_module_map)
|
||||||
|
{
|
||||||
|
delete gm->value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void GraphModuleManager::OnResize(const VkExtent2D &extent)
|
||||||
|
{
|
||||||
|
if(graph_module_map.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
for(auto *gm:graph_module_map)
|
||||||
|
{
|
||||||
|
gm->value->OnResize(extent);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user