Added GraphModuleFactory/SwapchainModule, but can't run
This commit is contained in:
parent
c3522da518
commit
7d586182c8
@ -18,6 +18,9 @@
|
|||||||
#include<hgl/graph/VKDescriptorSetType.h>
|
#include<hgl/graph/VKDescriptorSetType.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class SwapchainModule;
|
||||||
|
|
||||||
class TileData;
|
class TileData;
|
||||||
class TileFont;
|
class TileFont;
|
||||||
class FontSource;
|
class FontSource;
|
||||||
@ -30,7 +33,14 @@ struct CopyBufferToImageInfo;
|
|||||||
|
|
||||||
class GPUDevice
|
class GPUDevice
|
||||||
{
|
{
|
||||||
|
private: //module
|
||||||
|
|
||||||
GraphModuleManager *graph_module_manager;
|
GraphModuleManager *graph_module_manager;
|
||||||
|
|
||||||
|
SwapchainModule *swapchain_module;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
GPUDeviceAttribute *attr;
|
GPUDeviceAttribute *attr;
|
||||||
|
|
||||||
DeviceQueue *texture_queue;
|
DeviceQueue *texture_queue;
|
||||||
|
@ -23,11 +23,12 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual const bool IsRender()=0; ///<是否为渲染模块
|
virtual const bool IsRender(){return false;} ///<是否为渲染模块
|
||||||
|
|
||||||
GraphModuleManager *GetManager(){return module_manager;} ///<取得模块管理器
|
GraphModuleManager *GetManager(){return module_manager;} ///<取得模块管理器
|
||||||
|
|
||||||
const AnsiString &GetModuleName()const{return module_name;} ///<取得模块名称
|
static const char *GetModuleName(){return nullptr;} ///<取得模块名称(标准通用的名称,比如Upscale,供通用模块使用)
|
||||||
|
virtual const char *GetName()const{return module_name.c_str();} ///<取得名称(完整的私有名称,比如FSR3Upscale,DLSS3Upscale)
|
||||||
|
|
||||||
const bool IsEnable ()const noexcept{return module_enable;} ///<当前模块是否启用
|
const bool IsEnable ()const noexcept{return module_enable;} ///<当前模块是否启用
|
||||||
const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好
|
const bool IsReady ()const noexcept{return module_ready;} ///<当前模块是否准备好
|
||||||
@ -36,7 +37,11 @@ public:
|
|||||||
|
|
||||||
NO_COPY_NO_MOVE(GraphModule)
|
NO_COPY_NO_MOVE(GraphModule)
|
||||||
|
|
||||||
GraphModule(const AnsiString &name){module_name=name;}
|
GraphModule(GraphModuleManager *gmm,const AnsiString &name)
|
||||||
|
{
|
||||||
|
module_manager=gmm;
|
||||||
|
module_name=name;
|
||||||
|
}
|
||||||
virtual ~GraphModule()=default;
|
virtual ~GraphModule()=default;
|
||||||
|
|
||||||
virtual bool Init(){return true;} ///<初始化当前模块
|
virtual bool Init(){return true;} ///<初始化当前模块
|
||||||
@ -57,13 +62,23 @@ class GraphModuleManager
|
|||||||
|
|
||||||
Map<AnsiString,GraphModule *> graph_module_map;
|
Map<AnsiString,GraphModule *> graph_module_map;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
GraphModule *GetModule(const AnsiString &name,bool create);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GraphModuleManager(GPUDevice *dev){device=dev;}
|
GraphModuleManager(GPUDevice *dev){device=dev;}
|
||||||
~GraphModuleManager();
|
~GraphModuleManager();
|
||||||
|
|
||||||
bool Registry(const AnsiString &name,GraphModule *gm);
|
/**
|
||||||
GraphModule *GetModule(const AnsiString &name);
|
* 获取指定类型的模块
|
||||||
|
* @param create 如果不存在,是否创建新的
|
||||||
|
*/
|
||||||
|
template<typename T> T *GetModule(bool create=false)
|
||||||
|
{
|
||||||
|
return (T *)GetModule(T::GetModuleName(),create);
|
||||||
|
}
|
||||||
|
|
||||||
public: //事件
|
public: //事件
|
||||||
|
|
||||||
|
47
inc/hgl/graph/module/GraphModuleFactory.h
Normal file
47
inc/hgl/graph/module/GraphModuleFactory.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include<hgl/graph/VKNamespace.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class GraphModule;
|
||||||
|
class GraphModuleManager;
|
||||||
|
|
||||||
|
class GraphModuleFactory
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
GraphModuleFactory()=default;
|
||||||
|
virtual ~GraphModuleFactory()=default;
|
||||||
|
|
||||||
|
virtual GraphModule *Create(GraphModuleManager *)=0;
|
||||||
|
};//class GraphModuleFactory
|
||||||
|
|
||||||
|
bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *);
|
||||||
|
|
||||||
|
template<typename T> class RegistryGraphModule:public GraphModuleFactory
|
||||||
|
{
|
||||||
|
bool registry_success;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
RegistryGraphModule()
|
||||||
|
{
|
||||||
|
registry_success=RegistryGraphModuleFactory(T::GetModuleName(),this);
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphModule *Create(GraphModuleManager *gmm) override
|
||||||
|
{
|
||||||
|
if(!registry_success)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
if(!gmm)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
return(new T(gmm));
|
||||||
|
}
|
||||||
|
};//template<typename T> class RegistryGraphModule:public GraphModuleFactory
|
||||||
|
|
||||||
|
#define REGISTRY_GRAPH_MODULE(Class) namespace{static RegistryGraphModule<Class> registry_##Class;}
|
||||||
|
|
||||||
|
VK_NAMESPACE_END
|
@ -11,20 +11,19 @@ VK_NAMESPACE_BEGIN
|
|||||||
class RenderModule:public GraphModule
|
class RenderModule:public GraphModule
|
||||||
{
|
{
|
||||||
VkExtent2D current_extent;
|
VkExtent2D current_extent;
|
||||||
RenderTarget *render_target;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const bool IsRender()const noexcept{return true;}
|
const bool IsRender()const noexcept{return true;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
NO_COPY_NO_MOVE(RenderModule)
|
NO_COPY_NO_MOVE(RenderModule)
|
||||||
|
|
||||||
RenderModule(const AnsiString &name):GraphModule(name){}
|
using GraphModule::GraphModule;
|
||||||
virtual ~RenderModule()=default;
|
virtual ~RenderModule()=default;
|
||||||
|
|
||||||
virtual void OnRenderTarget(RenderTarget *rt)override{render_target=rt;}
|
|
||||||
|
|
||||||
virtual void OnResize(const VkExtent2D &ext)override{current_extent=ext;}
|
virtual void OnResize(const VkExtent2D &ext)override{current_extent=ext;}
|
||||||
};//class RenderModule
|
};//class RenderModule
|
||||||
|
|
||||||
|
VK_NAMESPACE_END
|
||||||
|
22
inc/hgl/graph/module/SwapchainModule.h
Normal file
22
inc/hgl/graph/module/SwapchainModule.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include<hgl/graph/module/RenderModule.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
class SwapchainModule:public GraphModule
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const char *GetModuleName(){return "Swapchain";}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
NO_COPY_NO_MOVE(SwapchainModule);
|
||||||
|
|
||||||
|
SwapchainModule(GraphModuleManager *gmm):GraphModule(gmm,"Swapchain"){}
|
||||||
|
virtual ~SwapchainModule()=default;
|
||||||
|
|
||||||
|
};//class SwapchainModule:public RenderModule
|
||||||
|
|
||||||
|
VK_NAMESPACE_END
|
@ -279,10 +279,14 @@ SOURCE_GROUP("Scene Graph\\Component" FILES ${SG_COMPONENT_HEADER} ${SG_COMPONEN
|
|||||||
SET(SGM_HEADER_PATH ${SG_INCLUDE_PATH}/module)
|
SET(SGM_HEADER_PATH ${SG_INCLUDE_PATH}/module)
|
||||||
|
|
||||||
SET(GRAPH_MODULE_HEADER ${SGM_HEADER_PATH}/GraphModule.h
|
SET(GRAPH_MODULE_HEADER ${SGM_HEADER_PATH}/GraphModule.h
|
||||||
${SGM_HEADER_PATH}/RenderModule.h)
|
${SGM_HEADER_PATH}/GraphModuleFactory.h
|
||||||
|
${SGM_HEADER_PATH}/RenderModule.h
|
||||||
|
${SGM_HEADER_PATH}/SwapchainModule.h)
|
||||||
|
|
||||||
SET(GRAPH_MODULE_SOURCE module/GraphModule.cpp
|
SET(GRAPH_MODULE_SOURCE module/GraphModule.cpp
|
||||||
module/RenderModule.cpp)
|
module/GraphModuleFactory.cpp
|
||||||
|
module/RenderModule.cpp
|
||||||
|
module/SwapchainModule.cpp)
|
||||||
|
|
||||||
SET(RENDER_FRAMEWORK_FILES ${SG_INCLUDE_PATH}/RenderFramework.h
|
SET(RENDER_FRAMEWORK_FILES ${SG_INCLUDE_PATH}/RenderFramework.h
|
||||||
RenderFramework.cpp)
|
RenderFramework.cpp)
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include<hgl/graph/VKDescriptorSet.h>
|
#include<hgl/graph/VKDescriptorSet.h>
|
||||||
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
#include<hgl/graph/VKDeviceRenderPassManage.h>
|
||||||
#include<hgl/graph/module/GraphModule.h>
|
#include<hgl/graph/module/GraphModule.h>
|
||||||
|
#include<hgl/graph/module/SwapchainModule.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -25,6 +26,8 @@ GPUDevice::GPUDevice(GPUDeviceAttribute *da)
|
|||||||
|
|
||||||
graph_module_manager=InitGraphModuleManager(this);
|
graph_module_manager=InitGraphModuleManager(this);
|
||||||
|
|
||||||
|
swapchain_module=graph_module_manager->GetModule<SwapchainModule>(true);
|
||||||
|
|
||||||
InitRenderPassManage();
|
InitRenderPassManage();
|
||||||
|
|
||||||
sc_rt=nullptr;
|
sc_rt=nullptr;
|
||||||
|
@ -67,27 +67,25 @@ GraphModuleManager *GetGraphModuleManager(GPUDevice *dev)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GraphModuleManager::Registry(const AnsiString &name,GraphModule *gm)
|
GraphModule *CreateGraphModule(const AnsiString &name,GraphModuleManager *gmm);
|
||||||
{
|
|
||||||
if(!gm)
|
|
||||||
return(false);
|
|
||||||
if(name.IsEmpty())
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
if(graph_module_map.ContainsKey(name))
|
GraphModule *GraphModuleManager::GetModule(const AnsiString &name,bool create)
|
||||||
return(false);
|
|
||||||
|
|
||||||
graph_module_map.Add(name,gm);
|
|
||||||
return(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
GraphModule *GraphModuleManager::GetModule(const AnsiString &name)
|
|
||||||
{
|
{
|
||||||
GraphModule *gm;
|
GraphModule *gm;
|
||||||
|
|
||||||
if(graph_module_map.Get(name,gm))
|
if(graph_module_map.Get(name,gm))
|
||||||
return gm;
|
return gm;
|
||||||
|
|
||||||
|
if(create)
|
||||||
|
{
|
||||||
|
gm=CreateGraphModule(name,this);
|
||||||
|
|
||||||
|
if(gm)
|
||||||
|
graph_module_map.Add(name,gm);
|
||||||
|
|
||||||
|
return gm;
|
||||||
|
}
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
64
src/SceneGraph/module/GraphModuleFactory.cpp
Normal file
64
src/SceneGraph/module/GraphModuleFactory.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include<hgl/graph/module/GraphModuleFactory.h>
|
||||||
|
#include<hgl/type/Map.h>
|
||||||
|
#include<hgl/type/String.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
using GraphModuleFactoryMap=ObjectMap<AnsiString,GraphModuleFactory>;
|
||||||
|
|
||||||
|
static GraphModuleFactoryMap *gmf_map=nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void InitGraphModuleFactory()
|
||||||
|
{
|
||||||
|
if(gmf_map)
|
||||||
|
return;
|
||||||
|
|
||||||
|
gmf_map=new GraphModuleFactoryMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ClearGraphModuleFactory()
|
||||||
|
{
|
||||||
|
SAFE_CLEAR(gmf_map);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RegistryGraphModuleFactory(const char *module_name,GraphModuleFactory *gmf)
|
||||||
|
{
|
||||||
|
if(!module_name||!gmf)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!gmf_map)
|
||||||
|
InitGraphModuleFactory();
|
||||||
|
|
||||||
|
AnsiString name=module_name;
|
||||||
|
|
||||||
|
if(gmf_map->ContainsKey(name))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
gmf_map->Add(name,gmf);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
GraphModule *CreateGraphModule(const AnsiString &name,GraphModuleManager *gmm)
|
||||||
|
{
|
||||||
|
if(!gmm)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
if(name.IsEmpty())
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
if(!gmf_map)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
GraphModuleFactory *gmf;
|
||||||
|
|
||||||
|
if(!gmf_map->Get(name,gmf))
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
return gmf->Create(gmm);
|
||||||
|
}
|
||||||
|
|
||||||
|
VK_NAMESPACE_END
|
8
src/SceneGraph/module/SwapchainModule.cpp
Normal file
8
src/SceneGraph/module/SwapchainModule.cpp
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#include<hgl/graph/module/SwapchainModule.h>
|
||||||
|
#include<hgl/graph/module/GraphModuleFactory.h>
|
||||||
|
|
||||||
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
REGISTRY_GRAPH_MODULE(SwapchainModule)
|
||||||
|
|
||||||
|
VK_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user