diff --git a/example/Basic/first_app.cpp b/example/Basic/first_app.cpp index 57ba909e..9890b85c 100644 --- a/example/Basic/first_app.cpp +++ b/example/Basic/first_app.cpp @@ -17,7 +17,7 @@ public: LOG_INFO(OS_TEXT("Resize: ")+OSString::numberOf(size.width)+OS_TEXT("x")+OSString::numberOf(size.height)); } - void OnExecute(const double,RenderCmdBuffer *cmd) + void OnFrameRender(const double,RenderCmdBuffer *cmd) override { LOG_INFO(OS_TEXT("Execute")); diff --git a/inc/hgl/graph/RenderFramework.h b/inc/hgl/graph/RenderFramework.h index 02d2047f..4c0e6a14 100644 --- a/inc/hgl/graph/RenderFramework.h +++ b/inc/hgl/graph/RenderFramework.h @@ -38,6 +38,9 @@ protected: ObjectList module_list; + List per_frame_module_list; + List render_module_list; + protected: SwapchainModule * swapchain_module =nullptr; @@ -73,6 +76,12 @@ public: //module module_list.Add(tm); + if(tm->IsPerFrame()) + per_frame_module_list.Add(tm); + + if(tm->IsRender()) + render_module_list.Add(tm); + return tm; } diff --git a/inc/hgl/graph/manager/MaterialManager.h b/inc/hgl/graph/manager/MaterialManager.h new file mode 100644 index 00000000..96fad6d7 --- /dev/null +++ b/inc/hgl/graph/manager/MaterialManager.h @@ -0,0 +1,11 @@ +#pragma once + +#include + +VK_NAMESPACE_BEGIN + +class MaterialManager:public GraphModule +{ +};// + +VK_NAMESPACE_END \ No newline at end of file diff --git a/inc/hgl/graph/module/GraphModule.h b/inc/hgl/graph/module/GraphModule.h index e7598911..324794c0 100644 --- a/inc/hgl/graph/module/GraphModule.h +++ b/inc/hgl/graph/module/GraphModule.h @@ -22,10 +22,10 @@ public: GraphModuleManager(GPUDevice *dev){device=dev;} ~GraphModuleManager(); - GPUDevice * GetDevice ()noexcept{return device;} ///<取得GPU设备 - VkDevice GetVkDevice ()const{return device->GetDevice();} - const GPUPhysicalDevice * GetPhysicalDevice ()const{return device->GetPhysicalDevice();} ///<取得物理设备 - GPUDeviceAttribute *GetDeviceAttribute (){return device->GetDeviceAttribute();} ///<取得设备属性 + GPUDevice * GetDevice ()noexcept {return device;} ///<取得GPU设备 + VkDevice GetVkDevice ()const {return device->GetDevice();} + const GPUPhysicalDevice * GetPhysicalDevice ()const {return device->GetPhysicalDevice();} ///<取得物理设备 + GPUDeviceAttribute *GetDeviceAttribute () {return device->GetDeviceAttribute();} ///<取得设备属性 /** * 获取指定名称的模块 @@ -70,6 +70,7 @@ protected: public: + virtual const bool IsPerFrame () {return false;} ///<是否每帧运行 virtual const bool IsRender () {return false;} ///<是否为渲染模块 GraphModuleManager *GetManager () {return module_manager;} ///<取得模块管理器 @@ -106,7 +107,6 @@ public: //回调事件 virtual void OnResize(const VkExtent2D &){} ///<窗口大小改变 virtual void OnPreFrame(){} ///<帧绘制前回调 - virtual void OnExecute(const double,RenderCmdBuffer *){} virtual void OnPostFrame(){} ///<帧绘制后回调 };//class GraphModule diff --git a/inc/hgl/graph/module/RenderModule.h b/inc/hgl/graph/module/RenderModule.h index 674cfbef..fbb9171d 100644 --- a/inc/hgl/graph/module/RenderModule.h +++ b/inc/hgl/graph/module/RenderModule.h @@ -14,7 +14,8 @@ class RenderModule:public GraphModule public: - const bool IsRender()const noexcept{return true;} + const bool IsPerFrame ()const noexcept{return true;} ///<每帧运行 + const bool IsRender ()const noexcept{return true;} ///<渲染模块 public: @@ -25,7 +26,7 @@ public: virtual void OnResize(const VkExtent2D &ext)override{current_extent=ext;} - virtual void OnExecute(const double,RenderCmdBuffer *){} + virtual void OnFrameRender(const double,RenderCmdBuffer *)=0; ///<帧绘制回调 };//class RenderModule VK_NAMESPACE_END diff --git a/inc/hgl/graph/module/SwapchainModule.h b/inc/hgl/graph/module/SwapchainModule.h index 361502f0..9aac6bdb 100644 --- a/inc/hgl/graph/module/SwapchainModule.h +++ b/inc/hgl/graph/module/SwapchainModule.h @@ -26,8 +26,6 @@ protected: public: virtual void OnResize(const VkExtent2D &)override; ///<窗口大小改变 - - //virtual void OnExecute(const double,RenderCmdBuffer *); public: diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 7e1a8e3b..6ef3aa43 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -296,10 +296,14 @@ SOURCE_GROUP("Render Framework\\Module" FILES ${GRAPH_MODULE_HEADER} SET(SG_MANAGER_HEADER_PATH ${SG_INCLUDE_PATH}/manager) SET(GRAPH_MANAGER_HEADER ${SG_MANAGER_HEADER_PATH}/TextureManager.h - ${SG_MANAGER_HEADER_PATH}/RenderPassManager.h) + ${SG_MANAGER_HEADER_PATH}/RenderPassManager.h + ${SG_MANAGER_HEADER_PATH}/MaterialManager.h +) SET(GRAPH_MANAGER_SOURCE manager/TextureManager.cpp - manager/RenderPassManager.cpp) + manager/RenderPassManager.cpp + manager/MaterialManager.cpp +) SOURCE_GROUP("Render Framework\\Manager" FILES ${GRAPH_MANAGER_HEADER} ${GRAPH_MANAGER_SOURCE}) diff --git a/src/SceneGraph/RenderFramework.cpp b/src/SceneGraph/RenderFramework.cpp index 878fcf48..a5097a9a 100644 --- a/src/SceneGraph/RenderFramework.cpp +++ b/src/SceneGraph/RenderFramework.cpp @@ -52,7 +52,13 @@ void RenderFramework::StartTime() void RenderFramework::BeginFrame() { - cur_time=GetDoubleTime(); + cur_time=GetDoubleTime(); + + for(GraphModule *rm:per_frame_module_list) + { + if(rm->IsEnable()) + rm->OnPreFrame(); + } swapchain_module->BeginFrame(); } @@ -60,6 +66,12 @@ void RenderFramework::BeginFrame() void RenderFramework::EndFrame() { swapchain_module->EndFrame(); + + for(GraphModule *rm:per_frame_module_list) + { + if(rm->IsEnable()) + rm->OnPostFrame(); + } last_time=cur_time; ++frame_count; @@ -69,12 +81,6 @@ void RenderFramework::MainLoop() { const double delta_time=cur_time-last_time; - for(auto rm:module_list) - { - if(rm->IsEnable()) - rm->OnPreFrame(); - } - BeginFrame(); RenderCmdBuffer *rcb=swapchain_module->GetRenderCmdBuffer(); @@ -84,22 +90,16 @@ void RenderFramework::MainLoop() rcb->Begin(); rcb->BindFramebuffer(swapchain_module->GetRenderPass(),swapchain_module->GetRenderTarget()->GetFramebuffer()); - for(auto rm:module_list) + for(RenderModule *rm:render_module_list) { if(rm->IsEnable()) - rm->OnExecute(delta_time,rcb); + rm->OnFrameRender(delta_time,rcb); } rcb->End(); } EndFrame(); - - for(auto rm:module_list) - { - if(rm->IsEnable()) - rm->OnPostFrame(); - } } void RenderFramework::Run() diff --git a/src/SceneGraph/manager/MaterialManager.cpp b/src/SceneGraph/manager/MaterialManager.cpp new file mode 100644 index 00000000..e69de29b diff --git a/src/SceneGraph/module/SwapchainModule.cpp b/src/SceneGraph/module/SwapchainModule.cpp index bbe34640..4c6763c3 100644 --- a/src/SceneGraph/module/SwapchainModule.cpp +++ b/src/SceneGraph/module/SwapchainModule.cpp @@ -101,10 +101,14 @@ bool SwapchainModule::CreateSwapchainFBO() if(!tex_manager) return(false); - swapchain->sc_depth =tex_manager->CreateTexture2D(new SwapchainDepthTextureCreateInfo(GetPhysicalDevice()->GetDepthFormat(),swapchain->extent)); + { + auto sc_depth_tci=new SwapchainDepthTextureCreateInfo(GetPhysicalDevice()->GetDepthFormat(),swapchain->extent); - if(!swapchain->sc_depth) - return(false); + swapchain->sc_depth =tex_manager->CreateTexture2D(sc_depth_tci); + + if(!swapchain->sc_depth) + return(false); + } //#ifdef _DEBUG // if(dev_attr->debug_utils) @@ -120,14 +124,16 @@ bool SwapchainModule::CreateSwapchainFBO() for(uint32_t i=0;iimage_count;i++) { - swapchain->sc_color[i]=tex_manager->CreateTexture2D(new SwapchainColorTextureCreateInfo(swapchain->surface_format.format,swapchain->extent,sc_images[i])); + auto sc_color_tci=new SwapchainColorTextureCreateInfo(swapchain->surface_format.format,swapchain->extent,sc_images[i]); + + swapchain->sc_color[i]=tex_manager->CreateTexture2D(sc_color_tci); if(!swapchain->sc_color[i]) return(false); - swapchain->sc_fbo[i]=tex_manager->CreateFBO( swapchain_rp, - swapchain->sc_color[i]->GetImageView(), - swapchain->sc_depth->GetImageView()); + swapchain->sc_fbo[i]=tex_manager->CreateFBO(swapchain_rp, + swapchain->sc_color[i]->GetImageView(), + swapchain->sc_depth->GetImageView()); //#ifdef _DEBUG // if(dev_attr->debug_utils)