[BIG MILESTONE] render framework first test ok! can draw!
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@@ -37,6 +38,8 @@ class TestApp:public WorkObject
|
||||
{
|
||||
private:
|
||||
|
||||
Color4f clear_color =Color4f(0.2f,0.2f,0.2f,1.0f);
|
||||
|
||||
MaterialInstance * material_instance =nullptr;
|
||||
Renderable * render_obj =nullptr;
|
||||
|
||||
@@ -46,29 +49,31 @@ private:
|
||||
|
||||
bool InitAutoMaterial()
|
||||
{
|
||||
mtl::Material2DCreateConfig cfg(device->GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
||||
mtl::Material2DCreateConfig cfg(GetDeviceAttribute(),"VertexColor2d",Prim::Triangles);
|
||||
|
||||
cfg.coordinate_system=CoordinateSystem2D::NDC;
|
||||
cfg.local_to_world=false;
|
||||
|
||||
AutoDelete<mtl::MaterialCreateInfo> mci=mtl::CreateVertexColor2D(&cfg);
|
||||
|
||||
material_instance=db->CreateMaterialInstance(mci,&vil_config);
|
||||
material_instance=db->CreateMaterialInstance(mci);
|
||||
|
||||
return material_instance;
|
||||
}
|
||||
|
||||
bool InitPipeline()
|
||||
{
|
||||
// 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
|
||||
RenderPass *sc_render_pass=GetRenderFramework()->GetSwapchainModule()->GetRenderPass();
|
||||
|
||||
return pipeline;
|
||||
// pipeline=db->CreatePipeline(material_instance,sc_render_target,OS_TEXT("res/pipeline/solid2d"));
|
||||
pipeline=sc_render_pass->CreatePipeline(material_instance,InlinePipeline::Solid2D,Prim::Triangles); //等同上一行,为Framework重载,默认使用swapchain的render target
|
||||
|
||||
return pipeline;
|
||||
}
|
||||
|
||||
bool InitVBO()
|
||||
{
|
||||
PrimitiveCreater rpc(device,material_instance->GetVIL());
|
||||
PrimitiveCreater rpc(GetDevice(),material_instance->GetVIL());
|
||||
|
||||
rpc.Init("Triangle",VERTEX_COUNT);
|
||||
|
||||
@@ -81,11 +86,11 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
{
|
||||
if(!VulkanApplicationFramework::Init(w,h))
|
||||
return(false);
|
||||
TestApp(RenderFramework *rf):WorkObject(rf)
|
||||
{}
|
||||
|
||||
bool Init()
|
||||
{
|
||||
if(!InitAutoMaterial())
|
||||
return(false);
|
||||
|
||||
@@ -95,34 +100,77 @@ public:
|
||||
if(!InitVBO())
|
||||
return(false);
|
||||
|
||||
if(!BuildCommandBuffer(render_obj))
|
||||
return(false);
|
||||
// if(!BuildCommandBuffer(render_obj))
|
||||
// return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Resize(uint w,uint h)override
|
||||
{
|
||||
VulkanApplicationFramework::Resize(w,h);
|
||||
//void Resize(uint w,uint h)override
|
||||
//{
|
||||
// VulkanApplicationFramework::Resize(w,h);
|
||||
|
||||
BuildCommandBuffer(render_obj);
|
||||
}
|
||||
// BuildCommandBuffer(render_obj);
|
||||
//}
|
||||
|
||||
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)
|
||||
{}
|
||||
{
|
||||
//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
|
||||
|
||||
int main(int,char **)
|
||||
{
|
||||
RenderFramework rf(OS_TEXT("RenderFramework Test"));
|
||||
|
||||
if(rf.Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
if(!rf.Init(SCREEN_WIDTH,SCREEN_HEIGHT))
|
||||
return(-1);
|
||||
|
||||
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
|
||||
#include<hgl/graph/RenderFramework.h>
|
||||
#include<hgl/graph/module/SwapchainModule.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/Time.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
class WorkObject
|
||||
{
|
||||
RenderFramework *render_framework;
|
||||
graph::RenderFramework *render_framework=nullptr;
|
||||
|
||||
bool destroy_flag=false;
|
||||
|
||||
bool tickable=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:
|
||||
|
||||
const bool IsDestroy()const{return destroy_flag;}
|
||||
@@ -26,11 +37,19 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
WorkObject(graph::RenderFramework *rf)
|
||||
{
|
||||
Join(rf);
|
||||
}
|
||||
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;
|
||||
db=rf->GetRenderResource();
|
||||
}
|
||||
|
||||
virtual void Tick(double delta_time)=0;
|
||||
@@ -56,6 +75,11 @@ namespace hgl
|
||||
render_framework=rf;
|
||||
}
|
||||
|
||||
virtual ~WorkManager()
|
||||
{
|
||||
SAFE_CLEAR(cur_work_object);
|
||||
}
|
||||
|
||||
void SetFPS(uint f)
|
||||
{
|
||||
fps=f;
|
||||
@@ -98,6 +122,9 @@ namespace hgl
|
||||
while(!cur_work_object->IsDestroy())
|
||||
{
|
||||
Update(cur_work_object);
|
||||
|
||||
render_framework->GetWindow()->Update();
|
||||
render_framework->GetDevice()->WaitIdle();
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user