2025-01-18 20:28:14 +08:00
|
|
|
|
#include<hgl/graph/RenderFramework.h>
|
|
|
|
|
#include<hgl/graph/VKInstance.h>
|
|
|
|
|
#include<hgl/graph/VKDeviceCreater.h>
|
|
|
|
|
#include<hgl/graph/module/RenderPassManager.h>
|
2025-01-19 18:13:06 +08:00
|
|
|
|
#include<hgl/graph/module/TextureManager.h>
|
|
|
|
|
#include<hgl/graph/module/RenderTargetManager.h>
|
|
|
|
|
#include<hgl/graph/module/SwapchainModule.h>
|
2025-01-19 19:42:38 +08:00
|
|
|
|
#include<hgl/graph/module/RenderModule.h>
|
2025-01-25 17:17:55 +08:00
|
|
|
|
#include<hgl/graph/VKRenderResource.h>
|
2025-01-19 19:42:38 +08:00
|
|
|
|
#include<hgl/graph/VKCommandBuffer.h>
|
2025-01-18 20:28:14 +08:00
|
|
|
|
#include<hgl/log/Logger.h>
|
2025-01-19 19:42:38 +08:00
|
|
|
|
#include<hgl/Time.h>
|
2025-01-16 02:10:03 +08:00
|
|
|
|
|
|
|
|
|
VK_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
bool InitShaderCompiler();
|
|
|
|
|
void CloseShaderCompiler();
|
|
|
|
|
|
|
|
|
|
namespace
|
|
|
|
|
{
|
|
|
|
|
static int RENDER_FRAMEWORK_COUNT=0;
|
|
|
|
|
|
2025-01-18 20:28:14 +08:00
|
|
|
|
hgl::graph::VulkanInstance *CreateVulkanInstance(const AnsiString &app_name)
|
|
|
|
|
{
|
|
|
|
|
CreateInstanceLayerInfo cili;
|
|
|
|
|
|
|
|
|
|
hgl_zero(cili);
|
|
|
|
|
|
|
|
|
|
cili.lunarg.standard_validation = true;
|
|
|
|
|
cili.khronos.validation = true;
|
|
|
|
|
|
|
|
|
|
InitVulkanInstanceProperties();
|
|
|
|
|
|
|
|
|
|
return CreateInstance(app_name,nullptr,&cili);
|
|
|
|
|
}
|
2025-01-16 02:10:03 +08:00
|
|
|
|
}//namespace
|
|
|
|
|
|
|
|
|
|
RenderFramework::RenderFramework(const OSString &an)
|
|
|
|
|
{
|
|
|
|
|
app_name=an;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RenderFramework::~RenderFramework()
|
|
|
|
|
{
|
2025-01-25 17:17:55 +08:00
|
|
|
|
SAFE_CLEAR(render_resource)
|
2025-01-18 20:28:14 +08:00
|
|
|
|
SAFE_CLEAR(module_manager)
|
|
|
|
|
|
2025-01-16 02:10:03 +08:00
|
|
|
|
--RENDER_FRAMEWORK_COUNT;
|
|
|
|
|
|
|
|
|
|
if(RENDER_FRAMEWORK_COUNT==0)
|
|
|
|
|
{
|
|
|
|
|
CloseShaderCompiler();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RenderFramework::Init(uint w,uint h)
|
|
|
|
|
{
|
|
|
|
|
if(RENDER_FRAMEWORK_COUNT==0)
|
|
|
|
|
{
|
|
|
|
|
if(!InitShaderCompiler())
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
logger::InitLogger(app_name);
|
2025-01-18 20:28:14 +08:00
|
|
|
|
|
|
|
|
|
InitNativeWindowSystem();
|
2025-01-16 02:10:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
++RENDER_FRAMEWORK_COUNT;
|
|
|
|
|
|
2025-01-18 20:28:14 +08:00
|
|
|
|
win=CreateRenderWindow(app_name);
|
|
|
|
|
if(!win)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(!win->Create(w,h))
|
|
|
|
|
{
|
|
|
|
|
delete win;
|
|
|
|
|
win=nullptr;
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
inst=CreateVulkanInstance(ToAnsiString(app_name));
|
|
|
|
|
if(!inst)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
VulkanHardwareRequirement vh_req;
|
|
|
|
|
|
|
|
|
|
device=CreateRenderDevice(inst,win,&vh_req);
|
|
|
|
|
|
|
|
|
|
if(!device)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
win->Join(this);
|
|
|
|
|
|
|
|
|
|
module_manager=new GraphModuleManager(device);
|
|
|
|
|
|
2025-01-25 22:31:48 +08:00
|
|
|
|
rp_manager=module_manager->GetOrCreate<RenderPassManager>();
|
2025-01-16 02:10:03 +08:00
|
|
|
|
|
2025-01-25 22:31:48 +08:00
|
|
|
|
if(!rp_manager)
|
2025-01-18 20:28:14 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2025-01-25 22:31:48 +08:00
|
|
|
|
tex_manager=module_manager->GetOrCreate<TextureManager>();
|
2025-01-19 18:13:06 +08:00
|
|
|
|
|
2025-01-25 22:31:48 +08:00
|
|
|
|
if(!tex_manager)
|
2025-01-19 18:13:06 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2025-01-25 22:31:48 +08:00
|
|
|
|
rt_manager=new RenderTargetManager(device,tex_manager,rp_manager);
|
2025-01-19 18:13:06 +08:00
|
|
|
|
module_manager->Registry(rt_manager);
|
|
|
|
|
|
2025-01-25 22:31:48 +08:00
|
|
|
|
sc_module=new SwapchainModule(device,tex_manager,rt_manager,rp_manager);
|
|
|
|
|
module_manager->Registry(sc_module);
|
2025-01-19 18:13:06 +08:00
|
|
|
|
|
2025-01-19 19:42:38 +08:00
|
|
|
|
OnResize(w,h);
|
|
|
|
|
|
2025-01-25 17:17:55 +08:00
|
|
|
|
render_resource=new RenderResource(device);
|
|
|
|
|
|
2025-01-19 19:42:38 +08:00
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-18 20:28:14 +08:00
|
|
|
|
void RenderFramework::OnResize(uint w,uint h)
|
|
|
|
|
{
|
|
|
|
|
io::WindowEvent::OnResize(w,h);
|
2025-01-19 19:42:38 +08:00
|
|
|
|
|
|
|
|
|
VkExtent2D ext(w,h);
|
|
|
|
|
|
2025-01-25 22:31:48 +08:00
|
|
|
|
sc_module->OnResize(ext); //其实swapchain_module并不需要传递尺寸数据过去
|
2025-01-18 20:28:14 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderFramework::OnActive(bool)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RenderFramework::OnClose()
|
|
|
|
|
{
|
2025-01-16 02:10:03 +08:00
|
|
|
|
}
|
2025-01-19 19:42:38 +08:00
|
|
|
|
|
2025-01-16 02:10:03 +08:00
|
|
|
|
VK_NAMESPACE_END
|