RenderFramework::RunFrame/Run
This commit is contained in:
parent
414142283b
commit
10fbcfef14
2
CMCore
2
CMCore
@ -1 +1 @@
|
|||||||
Subproject commit 5aad7d81419d02141b3b3f53661e2c8e3e763163
|
Subproject commit 1bcd213b63ed080863fd4a51eaec5fe6205e7589
|
@ -1,6 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/VK.h>
|
#include<hgl/graph/VKDevice.h>
|
||||||
#include<hgl/platform/Window.h>
|
#include<hgl/platform/Window.h>
|
||||||
#include<hgl/graph/module/GraphModuleManager.h>
|
#include<hgl/graph/module/GraphModuleManager.h>
|
||||||
|
|
||||||
@ -13,14 +13,22 @@ class TextureManager;
|
|||||||
class RenderTargetManager;
|
class RenderTargetManager;
|
||||||
class SwapchainModule;
|
class SwapchainModule;
|
||||||
|
|
||||||
|
class RenderModule;
|
||||||
|
|
||||||
class RenderFramework:public io::WindowEvent
|
class RenderFramework:public io::WindowEvent
|
||||||
{
|
{
|
||||||
OSString app_name;
|
OSString app_name;
|
||||||
|
|
||||||
Window * win =nullptr;
|
Window * win =nullptr;
|
||||||
VulkanInstance * inst =nullptr;
|
VulkanInstance * inst =nullptr;
|
||||||
|
|
||||||
GPUDevice * device =nullptr;
|
GPUDevice * device =nullptr;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
double last_time =0;
|
||||||
|
double cur_time =0;
|
||||||
|
int64 frame_count =0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@ -36,10 +44,11 @@ protected:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Window * GetWindow (){return win;}
|
Window * GetWindow (){return win;}
|
||||||
GPUDevice * GetDevice (){return device;}
|
GPUDevice * GetDevice (){return device;}
|
||||||
|
GPUDeviceAttribute * GetDeviceAttribute (){return device->GetDeviceAttribute();}
|
||||||
|
|
||||||
RenderPass * GetRenderPass (){return device_render_pass;}
|
RenderPass * GetRenderPass (){return device_render_pass;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -64,10 +73,20 @@ public:
|
|||||||
|
|
||||||
public: // event
|
public: // event
|
||||||
|
|
||||||
void OnResize(uint w,uint h);
|
virtual void OnResize(uint w,uint h);
|
||||||
void OnActive(bool);
|
virtual void OnActive(bool);
|
||||||
void OnClose();
|
virtual void OnClose();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
virtual void BeginFrame();
|
||||||
|
virtual void EndFrame();
|
||||||
|
|
||||||
|
virtual bool RunFrame(RenderModule *);
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
virtual bool Run(RenderModule *);
|
||||||
};//class RenderFramework
|
};//class RenderFramework
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/module/RenderModule.h>
|
#include<hgl/graph/module/GraphModule.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
class RenderTargetManager;
|
class RenderTargetManager;
|
||||||
|
|
||||||
RENDER_MODULE_CLASS(SwapchainModule)
|
GRAPH_MODULE_CLASS(SwapchainModule)
|
||||||
{
|
{
|
||||||
Swapchain *swapchain=nullptr;
|
Swapchain *swapchain=nullptr;
|
||||||
|
|
||||||
@ -43,13 +43,9 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
RenderPass * GetRenderPass () {return swapchain_rp;}
|
|
||||||
|
|
||||||
RTSwapchain * GetRenderTarget () {return swapchain_rt;}
|
|
||||||
|
|
||||||
const VkExtent2D & GetSwapchainSize()const {return swapchain_rt->GetExtent();}
|
const VkExtent2D & GetSwapchainSize()const {return swapchain_rt->GetExtent();}
|
||||||
|
|
||||||
RenderCmdBuffer *GetRenderCmdBuffer();
|
RenderCmdBuffer *Use();
|
||||||
|
|
||||||
};//class SwapchainModule:public RenderModule
|
};//class SwapchainModule:public RenderModule
|
||||||
|
|
||||||
|
@ -5,7 +5,10 @@
|
|||||||
#include<hgl/graph/module/TextureManager.h>
|
#include<hgl/graph/module/TextureManager.h>
|
||||||
#include<hgl/graph/module/RenderTargetManager.h>
|
#include<hgl/graph/module/RenderTargetManager.h>
|
||||||
#include<hgl/graph/module/SwapchainModule.h>
|
#include<hgl/graph/module/SwapchainModule.h>
|
||||||
|
#include<hgl/graph/module/RenderModule.h>
|
||||||
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
#include<hgl/log/Logger.h>
|
#include<hgl/log/Logger.h>
|
||||||
|
#include<hgl/Time.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
@ -87,8 +90,6 @@ bool RenderFramework::Init(uint w,uint h)
|
|||||||
|
|
||||||
win->Join(this);
|
win->Join(this);
|
||||||
|
|
||||||
OnResize(w,h);
|
|
||||||
|
|
||||||
module_manager=new GraphModuleManager(device);
|
module_manager=new GraphModuleManager(device);
|
||||||
|
|
||||||
render_pass_manager=module_manager->GetOrCreate<RenderPassManager>();
|
render_pass_manager=module_manager->GetOrCreate<RenderPassManager>();
|
||||||
@ -108,7 +109,7 @@ bool RenderFramework::Init(uint w,uint h)
|
|||||||
module_manager->Registry(swapchain_module);
|
module_manager->Registry(swapchain_module);
|
||||||
|
|
||||||
{
|
{
|
||||||
auto *attr=GetDevice()->GetDeviceAttribute();
|
auto *attr=GetDeviceAttribute();
|
||||||
|
|
||||||
SwapchainRenderbufferInfo rbi(attr->surface_format.format,attr->physical_device->GetDepthFormat());
|
SwapchainRenderbufferInfo rbi(attr->surface_format.format,attr->physical_device->GetDepthFormat());
|
||||||
|
|
||||||
@ -123,12 +124,48 @@ bool RenderFramework::Init(uint w,uint h)
|
|||||||
#endif//_DEBUG
|
#endif//_DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OnResize(w,h);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderFramework::Run(RenderModule *rm)
|
||||||
|
{
|
||||||
|
if(!rm)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!win)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(!swapchain_module)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
while(win->Update())
|
||||||
|
{
|
||||||
|
if(win->IsVisible())
|
||||||
|
{
|
||||||
|
++frame_count;
|
||||||
|
last_time=cur_time;
|
||||||
|
|
||||||
|
cur_time=GetDoubleTime();
|
||||||
|
|
||||||
|
if(!RunFrame(rm))
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
device->WaitIdle();
|
||||||
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderFramework::OnResize(uint w,uint h)
|
void RenderFramework::OnResize(uint w,uint h)
|
||||||
{
|
{
|
||||||
io::WindowEvent::OnResize(w,h);
|
io::WindowEvent::OnResize(w,h);
|
||||||
|
|
||||||
|
VkExtent2D ext(w,h);
|
||||||
|
|
||||||
|
swapchain_module->OnResize(ext); //其实swapchain_module并不需要这个
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderFramework::OnActive(bool)
|
void RenderFramework::OnActive(bool)
|
||||||
@ -138,4 +175,37 @@ void RenderFramework::OnActive(bool)
|
|||||||
void RenderFramework::OnClose()
|
void RenderFramework::OnClose()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void RenderFramework::BeginFrame()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void RenderFramework::EndFrame()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RenderFramework::RunFrame(RenderModule *rm)
|
||||||
|
{
|
||||||
|
bool result=true;
|
||||||
|
|
||||||
|
BeginFrame();
|
||||||
|
|
||||||
|
swapchain_module->BeginFrame();
|
||||||
|
{
|
||||||
|
RenderCmdBuffer *rcb=swapchain_module->Use();
|
||||||
|
|
||||||
|
if(rcb)
|
||||||
|
{
|
||||||
|
result=rm->OnFrameRender(cur_time,rcb);
|
||||||
|
|
||||||
|
rcb->End();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
swapchain_module->EndFrame();
|
||||||
|
|
||||||
|
EndFrame();
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -223,7 +223,7 @@ SwapchainModule::~SwapchainModule()
|
|||||||
SAFE_CLEAR(swapchain);
|
SAFE_CLEAR(swapchain);
|
||||||
}
|
}
|
||||||
|
|
||||||
SwapchainModule::SwapchainModule(GPUDevice *dev,TextureManager *tm,RenderTargetManager *rtm,RenderPassManager *rpm):GraphModuleInherit<SwapchainModule,RenderModule>(dev,"SwapchainModule")
|
SwapchainModule::SwapchainModule(GPUDevice *dev,TextureManager *tm,RenderTargetManager *rtm,RenderPassManager *rpm):GraphModuleInherit<SwapchainModule,GraphModule>(dev,"SwapchainModule")
|
||||||
{
|
{
|
||||||
tex_manager=tm;
|
tex_manager=tm;
|
||||||
rt_manager=rtm;
|
rt_manager=rtm;
|
||||||
@ -281,14 +281,18 @@ void SwapchainModule::EndFrame()
|
|||||||
swapchain_rt->WaitFence();
|
swapchain_rt->WaitFence();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderCmdBuffer *SwapchainModule::GetRenderCmdBuffer()
|
RenderCmdBuffer *SwapchainModule::Use()
|
||||||
{
|
{
|
||||||
int index=swapchain_rt->GetCurrentFrameIndices();
|
uint32_t index=swapchain_rt->GetCurrentFrameIndices();
|
||||||
|
|
||||||
if(index>=swapchain->color_count)
|
if(index>=swapchain->color_count)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
return cmd_buf[index];
|
RenderCmdBuffer *rcb=cmd_buf[index];
|
||||||
|
|
||||||
|
rcb->BindFramebuffer(swapchain_rp,swapchain_rt->GetFramebuffer());
|
||||||
|
|
||||||
|
return rcb;
|
||||||
}
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user