[BIG MILESTONE] render framework first test ok! can draw!
This commit is contained in:
parent
aafdbdd4ea
commit
2e53b48fff
@ -5,6 +5,7 @@
|
|||||||
#include<hgl/graph/VKVertexInputConfig.h>
|
#include<hgl/graph/VKVertexInputConfig.h>
|
||||||
#include<hgl/graph/PrimitiveCreater.h>
|
#include<hgl/graph/PrimitiveCreater.h>
|
||||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||||
|
#include<hgl/graph/VKMaterialInstance.h>
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
@ -37,6 +38,8 @@ class TestApp:public WorkObject
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
|
||||||
|
|
||||||
MaterialInstance * material_instance =nullptr;
|
MaterialInstance * material_instance =nullptr;
|
||||||
Renderable * render_obj =nullptr;
|
Renderable * render_obj =nullptr;
|
||||||
|
|
||||||
@ -46,29 +49,31 @@ private:
|
|||||||
|
|
||||||
bool InitAutoMaterial()
|
bool InitAutoMaterial()
|
||||||
{
|
{
|
||||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
||||||
|
|
||||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||||
cfg.local_to_world=false;
|
cfg.local_to_world=false;
|
||||||
|
|
||||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||||
|
|
||||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
material_instance=db->CreateMaterialInstance(mci);
|
||||||
|
|
||||||
return material_instance;
|
return material_instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitPipeline()
|
bool InitPipeline()
|
||||||
{
|
{
|
||||||
|
RenderPass *sc_render_pass=GetRenderFramework()->GetSwapchainModule()->GetRenderPass();
|
||||||
|
|
||||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||||
pipeline=CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
pipeline=sc_render_pass->CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||||
|
|
||||||
return pipeline;
|
return pipeline;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InitVBO()
|
bool InitVBO()
|
||||||
{
|
{
|
||||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
PrimitiveCreater rpc(GetDevice(),material_instance->GetVIL());
|
||||||
|
|
||||||
rpc.Init("Triangle",VERTEX_COUNT);
|
rpc.Init("Triangle",VERTEX_COUNT);
|
||||||
|
|
||||||
@ -81,11 +86,11 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
bool Init(uint w,uint h)
|
TestApp(RenderFramework *rf):WorkObject(rf)
|
||||||
{
|
{}
|
||||||
if(!VulkanApplicationFramework::Init(w,h))
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
|
bool Init()
|
||||||
|
{
|
||||||
if(!InitAutoMaterial())
|
if(!InitAutoMaterial())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
@ -95,34 +100,77 @@ public:
|
|||||||
if(!InitVBO())
|
if(!InitVBO())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
if(!BuildCommandBuffer(render_obj))
|
// if(!BuildCommandBuffer(render_obj))
|
||||||
return(false);
|
// return(false);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Resize(uint w,uint h)override
|
//void Resize(uint w,uint h)override
|
||||||
{
|
//{
|
||||||
VulkanApplicationFramework::Resize(w,h);
|
// VulkanApplicationFramework::Resize(w,h);
|
||||||
|
|
||||||
BuildCommandBuffer(render_obj);
|
// BuildCommandBuffer(render_obj);
|
||||||
}
|
//}
|
||||||
|
|
||||||
void Tick(double)override
|
void Tick(double)override
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
void Render(RenderCmdBuffer *cb,Renderable *ri)
|
||||||
|
{
|
||||||
|
if(!ri)return;
|
||||||
|
|
||||||
|
cb->BeginRenderPass();
|
||||||
|
cb->BindPipeline(ri->GetPipeline());
|
||||||
|
cb->BindDescriptorSets(ri->GetMaterial());
|
||||||
|
cb->BindDataBuffer(ri->GetDataBuffer());
|
||||||
|
cb->Draw(ri->GetDataBuffer(),ri->GetRenderData());
|
||||||
|
cb->EndRenderPass();
|
||||||
|
}
|
||||||
|
|
||||||
void Render(double)
|
void Render(double)
|
||||||
{}
|
{
|
||||||
|
//WorkObject是工作对象,不是渲染对象,所以不应该直接自动指定RenderTarget,更不能直接指定RenderCmdBuffer
|
||||||
|
|
||||||
|
//目前这里只是为了测试,所以这样写
|
||||||
|
|
||||||
|
RenderFramework *rf=GetRenderFramework();
|
||||||
|
SwapchainModule *sm=rf->GetSwapchainModule();
|
||||||
|
|
||||||
|
sm->BeginFrame(); //这里会有AcquireNextImage操作
|
||||||
|
|
||||||
|
//这个使用完全不合理,录制CMD和推送swapchain是两回事,需要分开操作。
|
||||||
|
//比如场景有的物件分静态和动态
|
||||||
|
|
||||||
|
//可能静态物件就全部一次性录制好,而动态物件则是每帧录制
|
||||||
|
|
||||||
|
RenderCmdBuffer *cb=sm->RecordCmdBuffer(); //这里会获取当前帧的RenderCmdBuffer、开启cmd录制、绑定FBO
|
||||||
|
|
||||||
|
if(cb)
|
||||||
|
{
|
||||||
|
cb->SetClearColor(0,clear_color);
|
||||||
|
|
||||||
|
Render(cb,render_obj);
|
||||||
|
|
||||||
|
cb->End(); //结束cmd录制
|
||||||
|
}
|
||||||
|
sm->EndFrame(); //这里会Submit和PresentBackbuffer
|
||||||
|
}
|
||||||
};//class TestApp:public VulkanApplicationFramework
|
};//class TestApp:public VulkanApplicationFramework
|
||||||
|
|
||||||
int main(int,char **)
|
int main(int,char **)
|
||||||
{
|
{
|
||||||
RenderFramework rf(OS_TEXT("RenderFramework Test"));
|
RenderFramework rf(OS_TEXT("RenderFramework Test"));
|
||||||
|
|
||||||
if(rf.Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
if(!rf.Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
WorkManager wm(&rf);
|
WorkManager wm(&rf);
|
||||||
|
|
||||||
wm.Start(new TestApp);
|
AutoDelete<TestApp> app=new TestApp(&rf);
|
||||||
|
|
||||||
|
if(!app->Init())
|
||||||
|
return(-2);
|
||||||
|
|
||||||
|
wm.Start(app);
|
||||||
}
|
}
|
||||||
|
@ -1,19 +1,30 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include<hgl/graph/RenderFramework.h>
|
#include<hgl/graph/RenderFramework.h>
|
||||||
#include<hgl/graph/module/SwapchainModule.h>
|
#include<hgl/graph/module/SwapchainModule.h>
|
||||||
|
#include<hgl/graph/VKRenderResource.h>
|
||||||
#include<hgl/Time.h>
|
#include<hgl/Time.h>
|
||||||
|
|
||||||
namespace hgl
|
namespace hgl
|
||||||
{
|
{
|
||||||
class WorkObject
|
class WorkObject
|
||||||
{
|
{
|
||||||
RenderFramework *render_framework;
|
graph::RenderFramework *render_framework=nullptr;
|
||||||
|
|
||||||
bool destroy_flag=false;
|
bool destroy_flag=false;
|
||||||
|
|
||||||
bool tickable=true;
|
bool tickable=true;
|
||||||
bool renderable=true;
|
bool renderable=true;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
graph::RenderResource *db=nullptr; //暂时的,未来会被更好的机制替代
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
graph::RenderFramework * GetRenderFramework (){return render_framework;}
|
||||||
|
graph::GPUDevice * GetDevice (){return render_framework->GetDevice();}
|
||||||
|
graph::GPUDeviceAttribute * GetDeviceAttribute (){return render_framework->GetDeviceAttribute();}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const bool IsDestroy()const{return destroy_flag;}
|
const bool IsDestroy()const{return destroy_flag;}
|
||||||
@ -26,11 +37,19 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
WorkObject(graph::RenderFramework *rf)
|
||||||
|
{
|
||||||
|
Join(rf);
|
||||||
|
}
|
||||||
virtual ~WorkObject()=default;
|
virtual ~WorkObject()=default;
|
||||||
|
|
||||||
virtual void Join(RenderFramework *rf)
|
virtual void Join(graph::RenderFramework *rf)
|
||||||
{
|
{
|
||||||
|
if(!rf)return;
|
||||||
|
if(render_framework==rf)return;
|
||||||
|
|
||||||
render_framework=rf;
|
render_framework=rf;
|
||||||
|
db=rf->GetRenderResource();
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Tick(double delta_time)=0;
|
virtual void Tick(double delta_time)=0;
|
||||||
@ -56,6 +75,11 @@ namespace hgl
|
|||||||
render_framework=rf;
|
render_framework=rf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
virtual ~WorkManager()
|
||||||
|
{
|
||||||
|
SAFE_CLEAR(cur_work_object);
|
||||||
|
}
|
||||||
|
|
||||||
void SetFPS(uint f)
|
void SetFPS(uint f)
|
||||||
{
|
{
|
||||||
fps=f;
|
fps=f;
|
||||||
@ -98,6 +122,9 @@ namespace hgl
|
|||||||
while(!cur_work_object->IsDestroy())
|
while(!cur_work_object->IsDestroy())
|
||||||
{
|
{
|
||||||
Update(cur_work_object);
|
Update(cur_work_object);
|
||||||
|
|
||||||
|
render_framework->GetWindow()->Update();
|
||||||
|
render_framework->GetDevice()->WaitIdle();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,8 @@ class RenderFramework:public io::WindowEvent
|
|||||||
|
|
||||||
GPUDevice * device =nullptr;
|
GPUDevice * device =nullptr;
|
||||||
|
|
||||||
|
RenderResource * render_resource =nullptr;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
double last_time =0;
|
double last_time =0;
|
||||||
@ -47,6 +49,8 @@ public:
|
|||||||
GPUDevice * GetDevice (){return device;}
|
GPUDevice * GetDevice (){return device;}
|
||||||
GPUDeviceAttribute * GetDeviceAttribute (){return device->GetDeviceAttribute();}
|
GPUDeviceAttribute * GetDeviceAttribute (){return device->GetDeviceAttribute();}
|
||||||
|
|
||||||
|
RenderResource * GetRenderResource (){return render_resource;}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
GraphModuleManager * GetModuleManager (){return module_manager;}
|
GraphModuleManager * GetModuleManager (){return module_manager;}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/module/GraphModule.h>
|
#include<hgl/graph/module/GraphModule.h>
|
||||||
|
|
||||||
@ -15,7 +15,7 @@ GRAPH_MODULE_CLASS(RenderTargetManager)
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
RenderTargetManager(GPUDevice *,TextureManager *tm,RenderPassManager *rpm);
|
RenderTargetManager(GPUDevice *,TextureManager *tm,RenderPassManager *rpm);
|
||||||
virtual ~RenderTargetManager();
|
virtual ~RenderTargetManager()=default;
|
||||||
|
|
||||||
public: //FrameBuffer相关
|
public: //FrameBuffer相关
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include<hgl/graph/module/GraphModule.h>
|
#include<hgl/graph/module/GraphModule.h>
|
||||||
|
|
||||||
@ -37,9 +37,11 @@ public:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
const VkExtent2D & GetSwapchainSize()const {return swapchain_rt->GetExtent();}
|
RenderPass * GetRenderPass ()const{return swapchain_rt->GetRenderPass();}
|
||||||
|
|
||||||
RenderCmdBuffer *Use();
|
const VkExtent2D & GetSwapchainSize()const{return swapchain_rt->GetExtent();}
|
||||||
|
|
||||||
|
RenderCmdBuffer *RecordCmdBuffer(int frame_index=-1);
|
||||||
|
|
||||||
};//class SwapchainModule:public GraphModule
|
};//class SwapchainModule:public GraphModule
|
||||||
|
|
||||||
|
@ -6,6 +6,7 @@
|
|||||||
#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/module/RenderModule.h>
|
||||||
|
#include<hgl/graph/VKRenderResource.h>
|
||||||
#include<hgl/graph/VKCommandBuffer.h>
|
#include<hgl/graph/VKCommandBuffer.h>
|
||||||
#include<hgl/log/Logger.h>
|
#include<hgl/log/Logger.h>
|
||||||
#include<hgl/Time.h>
|
#include<hgl/Time.h>
|
||||||
@ -41,6 +42,7 @@ RenderFramework::RenderFramework(const OSString &an)
|
|||||||
|
|
||||||
RenderFramework::~RenderFramework()
|
RenderFramework::~RenderFramework()
|
||||||
{
|
{
|
||||||
|
SAFE_CLEAR(render_resource)
|
||||||
SAFE_CLEAR(module_manager)
|
SAFE_CLEAR(module_manager)
|
||||||
|
|
||||||
--RENDER_FRAMEWORK_COUNT;
|
--RENDER_FRAMEWORK_COUNT;
|
||||||
@ -109,6 +111,8 @@ bool RenderFramework::Init(uint w,uint h)
|
|||||||
|
|
||||||
OnResize(w,h);
|
OnResize(w,h);
|
||||||
|
|
||||||
|
render_resource=new RenderResource(device);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,7 +179,7 @@ bool RenderFramework::RunFrame(RenderModule *rm)
|
|||||||
|
|
||||||
swapchain_module->BeginFrame();
|
swapchain_module->BeginFrame();
|
||||||
{
|
{
|
||||||
RenderCmdBuffer *rcb=swapchain_module->Use();
|
RenderCmdBuffer *rcb=swapchain_module->RecordCmdBuffer();
|
||||||
|
|
||||||
if(rcb)
|
if(rcb)
|
||||||
{
|
{
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include<hgl/graph/VKRenderTarget.h>
|
#include<hgl/graph/VKRenderTarget.h>
|
||||||
#include<hgl/graph/VKDevice.h>
|
#include<hgl/graph/VKDevice.h>
|
||||||
#include<hgl/graph/VKSemaphore.h>
|
#include<hgl/graph/VKSemaphore.h>
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#include<hgl/graph/module/SwapchainModule.h>
|
#include<hgl/graph/module/SwapchainModule.h>
|
||||||
#include<hgl/graph/module/RenderPassManager.h>
|
#include<hgl/graph/module/RenderPassManager.h>
|
||||||
#include<hgl/graph/module/TextureManager.h>
|
#include<hgl/graph/module/TextureManager.h>
|
||||||
#include<hgl/graph/module/RenderTargetManager.h>
|
#include<hgl/graph/module/RenderTargetManager.h>
|
||||||
@ -175,6 +175,9 @@ bool SwapchainModule::CreateSwapchain()
|
|||||||
|
|
||||||
bool SwapchainModule::CreateSwapchainRenderTarget()
|
bool SwapchainModule::CreateSwapchainRenderTarget()
|
||||||
{
|
{
|
||||||
|
if(!CreateSwapchain())
|
||||||
|
return(false);
|
||||||
|
|
||||||
GPUDevice *device=GetDevice();
|
GPUDevice *device=GetDevice();
|
||||||
|
|
||||||
DeviceQueue *q=device->CreateQueue(swapchain->image_count,false);
|
DeviceQueue *q=device->CreateQueue(swapchain->image_count,false);
|
||||||
@ -195,16 +198,14 @@ bool SwapchainModule::CreateSwapchainRenderTarget()
|
|||||||
SwapchainModule::~SwapchainModule()
|
SwapchainModule::~SwapchainModule()
|
||||||
{
|
{
|
||||||
SAFE_CLEAR(swapchain_rt);
|
SAFE_CLEAR(swapchain_rt);
|
||||||
SAFE_CLEAR(swapchain);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SwapchainModule::SwapchainModule(GPUDevice *dev,TextureManager *tm,RenderTargetManager *rtm,RenderPassManager *rpm):GraphModuleInherit<SwapchainModule,GraphModule>(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;
|
||||||
|
rp_manager=rpm;
|
||||||
|
|
||||||
if(!CreateSwapchain())
|
|
||||||
return;
|
|
||||||
|
|
||||||
//#ifdef _DEBUG
|
//#ifdef _DEBUG
|
||||||
// if(dev_attr->debug_utils)
|
// if(dev_attr->debug_utils)
|
||||||
@ -218,6 +219,7 @@ SwapchainModule::SwapchainModule(GPUDevice *dev,TextureManager *tm,RenderTargetM
|
|||||||
void SwapchainModule::OnResize(const VkExtent2D &extent)
|
void SwapchainModule::OnResize(const VkExtent2D &extent)
|
||||||
{
|
{
|
||||||
SAFE_CLEAR(swapchain_rt)
|
SAFE_CLEAR(swapchain_rt)
|
||||||
|
swapchain=nullptr;
|
||||||
|
|
||||||
GetDeviceAttribute()->RefreshSurfaceCaps();
|
GetDeviceAttribute()->RefreshSurfaceCaps();
|
||||||
|
|
||||||
@ -246,14 +248,15 @@ void SwapchainModule::EndFrame()
|
|||||||
swapchain_rt->WaitFence();
|
swapchain_rt->WaitFence();
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderCmdBuffer *SwapchainModule::Use()
|
RenderCmdBuffer *SwapchainModule::RecordCmdBuffer(int frame_index)
|
||||||
{
|
{
|
||||||
uint32_t index=swapchain_rt->GetCurrentFrameIndices();
|
if(frame_index<0)
|
||||||
|
frame_index=swapchain_rt->GetCurrentFrameIndices();
|
||||||
|
|
||||||
if(index>=swapchain->image_count)
|
if(frame_index>=swapchain->image_count)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
RenderCmdBuffer *rcb=swapchain->sc_image[index].cmd_buf;
|
RenderCmdBuffer *rcb=swapchain->sc_image[frame_index].cmd_buf;
|
||||||
|
|
||||||
rcb->Begin();
|
rcb->Begin();
|
||||||
rcb->BindFramebuffer(swapchain->render_pass,swapchain_rt->GetFramebuffer());
|
rcb->BindFramebuffer(swapchain->render_pass,swapchain_rt->GetFramebuffer());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user