将WorkObject增加bool Init()=0纯虚函数用于负责初始化。
这一分支结束,下一分支基于03_auto_instance范例开发WorldManager用于全局World管理,直接由World提供RenderList/SceneRoot等。
This commit is contained in:
parent
66bb363035
commit
8a99a331c0
@ -1,6 +1,6 @@
|
|||||||
// Billboard
|
// Billboard
|
||||||
|
|
||||||
#include"VulkanAppFramework.h"
|
#include<hgl/WorkManager.h>
|
||||||
#include<hgl/filesystem/FileSystem.h>
|
#include<hgl/filesystem/FileSystem.h>
|
||||||
#include<hgl/graph/InlineGeometry.h>
|
#include<hgl/graph/InlineGeometry.h>
|
||||||
#include<hgl/graph/VKRenderResource.h>
|
#include<hgl/graph/VKRenderResource.h>
|
||||||
@ -11,6 +11,7 @@
|
|||||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||||
#include<hgl/graph/VertexDataManager.h>
|
#include<hgl/graph/VertexDataManager.h>
|
||||||
#include<hgl/graph/VKVertexInputConfig.h>
|
#include<hgl/graph/VKVertexInputConfig.h>
|
||||||
|
#include<hgl/graph/module/TextureManager.h>
|
||||||
|
|
||||||
using namespace hgl;
|
using namespace hgl;
|
||||||
using namespace hgl::graph;
|
using namespace hgl::graph;
|
||||||
@ -25,12 +26,16 @@ static float lumiance_data[2]={1,1};
|
|||||||
static Color4f white_color(1,1,1,1);
|
static Color4f white_color(1,1,1,1);
|
||||||
static Color4f yellow_color(1,1,0,1);
|
static Color4f yellow_color(1,1,0,1);
|
||||||
|
|
||||||
class TestApp:public SceneAppFramework
|
class TestApp:public WorkObject
|
||||||
{
|
{
|
||||||
Color4f color;
|
Color4f color;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
AutoDelete<RenderList> render_list =nullptr;
|
||||||
|
|
||||||
|
SceneNode render_root;
|
||||||
|
|
||||||
Material * mtl_plane_grid =nullptr;
|
Material * mtl_plane_grid =nullptr;
|
||||||
MaterialInstance * mi_plane_grid =nullptr;
|
MaterialInstance * mi_plane_grid =nullptr;
|
||||||
Pipeline * pipeline_plane_grid =nullptr;
|
Pipeline * pipeline_plane_grid =nullptr;
|
||||||
@ -90,7 +95,9 @@ private:
|
|||||||
|
|
||||||
bool InitTexture()
|
bool InitTexture()
|
||||||
{
|
{
|
||||||
texture=db->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
TextureManager *tex_manager=GetTextureManager();
|
||||||
|
|
||||||
|
texture=tex_manager->LoadTexture2D(OS_TEXT("res/image/lena.Tex2D"),true);
|
||||||
if(!texture)return(false);
|
if(!texture)return(false);
|
||||||
|
|
||||||
sampler=db->CreateSampler();
|
sampler=db->CreateSampler();
|
||||||
@ -128,7 +135,7 @@ private:
|
|||||||
using namespace inline_geometry;
|
using namespace inline_geometry;
|
||||||
|
|
||||||
{
|
{
|
||||||
PrimitiveCreater pc(device,mi_plane_grid->GetVIL());
|
PrimitiveCreater pc(GetDevice(),mi_plane_grid->GetVIL());
|
||||||
|
|
||||||
struct PlaneGridCreateInfo pgci;
|
struct PlaneGridCreateInfo pgci;
|
||||||
|
|
||||||
@ -142,7 +149,7 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
PrimitiveCreater pc(device,mi_billboard->GetVIL());
|
PrimitiveCreater pc(GetDevice(),mi_billboard->GetVIL());
|
||||||
|
|
||||||
pc.Init("Billboard",1);
|
pc.Init("Billboard",1);
|
||||||
|
|
||||||
@ -150,6 +157,7 @@ private:
|
|||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
ro_billboard=db->CreateMesh(&pc,mi_billboard,pipeline_billboard);
|
ro_billboard=db->CreateMesh(&pc,mi_billboard,pipeline_billboard);
|
||||||
|
|
||||||
if(!ro_billboard)
|
if(!ro_billboard)
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
@ -175,16 +183,15 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
using WorkObject::WorkObject;
|
||||||
|
|
||||||
~TestApp()
|
~TestApp()
|
||||||
{
|
{
|
||||||
SAFE_CLEAR(prim_plane_grid);
|
SAFE_CLEAR(prim_plane_grid);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Init(uint w,uint h)
|
bool Init()
|
||||||
{
|
{
|
||||||
if(!SceneAppFramework::Init(w,h))
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
if(!InitPlaneGridMP())
|
if(!InitPlaneGridMP())
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
@ -202,9 +209,9 @@ public:
|
|||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
};//class TestApp:public CameraAppFramework
|
};//class TestApp:public WorkObject
|
||||||
|
|
||||||
int main(int,char **)
|
int os_main(int,os_char **)
|
||||||
{
|
{
|
||||||
return RunApp<TestApp>(1920,1080);
|
return RunFramework<TestApp>(OS_TEXT("AutoInstance"),1024,1024);
|
||||||
}
|
}
|
||||||
|
@ -98,15 +98,22 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
using WorkObject::WorkObject;
|
||||||
|
|
||||||
|
bool Init() override
|
||||||
{
|
{
|
||||||
render_list=rf->CreateRenderList();
|
render_list=GetRenderFramework()->CreateRenderList();
|
||||||
|
|
||||||
|
if(!render_list)
|
||||||
|
return(false);
|
||||||
|
|
||||||
if(!InitMaterial())
|
if(!InitMaterial())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
if(!InitVBO())
|
if(!InitVBO())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
||||||
|
@ -111,15 +111,22 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
using WorkObject::WorkObject;
|
||||||
|
|
||||||
|
bool Init() override
|
||||||
{
|
{
|
||||||
render_list=rf->CreateRenderList();
|
render_list=GetRenderFramework()->CreateRenderList();
|
||||||
|
|
||||||
|
if(!render_list)
|
||||||
|
return(false);
|
||||||
|
|
||||||
if(!InitMaterial())
|
if(!InitMaterial())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
if(!InitVBOAndRenderList())
|
if(!InitVBOAndRenderList())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
||||||
@ -130,7 +137,7 @@ public:
|
|||||||
render_list->Render(cmd);
|
render_list->Render(cmd);
|
||||||
cmd->EndRenderPass();
|
cmd->EndRenderPass();
|
||||||
}
|
}
|
||||||
};//class TestApp:public VulkanApplicationFramework
|
};//class TestApp:public WorkObject
|
||||||
|
|
||||||
int os_main(int,os_char **)
|
int os_main(int,os_char **)
|
||||||
{
|
{
|
||||||
|
@ -120,18 +120,22 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
using WorkObject::WorkObject;
|
||||||
|
|
||||||
|
bool Init() override
|
||||||
{
|
{
|
||||||
InitVIL();
|
InitVIL();
|
||||||
|
|
||||||
if(!InitAutoMaterial())
|
if(!InitAutoMaterial())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
if(!InitPipeline())
|
if(!InitPipeline())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
if(!InitVBO())
|
if(!InitVBO())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tick(double)override{}
|
void Tick(double)override{}
|
||||||
|
@ -91,13 +91,17 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
using WorkObject::WorkObject;
|
||||||
|
|
||||||
|
bool Init() override
|
||||||
{
|
{
|
||||||
if(!InitMaterial())
|
if(!InitMaterial())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
if(!InitVBO())
|
if(!InitVBO())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
||||||
|
@ -71,16 +71,20 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
using WorkObject::WorkObject;
|
||||||
|
|
||||||
|
bool Init() override
|
||||||
{
|
{
|
||||||
if(!InitAutoMaterial())
|
if(!InitAutoMaterial())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
if(!InitPipeline())
|
if(!InitPipeline())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
if(!InitVBO())
|
if(!InitVBO())
|
||||||
return;
|
return(false);
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tick(double)override{}
|
void Tick(double)override{}
|
||||||
|
@ -80,7 +80,15 @@ namespace hgl
|
|||||||
|
|
||||||
SwapchainWorkManager wm(&rf);
|
SwapchainWorkManager wm(&rf);
|
||||||
|
|
||||||
wm.Run(new WO(&rf));
|
WO *wo=new WO(&rf);
|
||||||
|
|
||||||
|
if(!wo->Init())
|
||||||
|
{
|
||||||
|
delete wo;
|
||||||
|
return(-2);
|
||||||
|
}
|
||||||
|
|
||||||
|
wm.Run(wo);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,7 @@ namespace hgl
|
|||||||
graph::RenderFramework * GetRenderFramework (){return render_framework;}
|
graph::RenderFramework * GetRenderFramework (){return render_framework;}
|
||||||
graph::VulkanDevice * GetDevice (){return render_framework->GetDevice();}
|
graph::VulkanDevice * GetDevice (){return render_framework->GetDevice();}
|
||||||
graph::VulkanDevAttr * GetDevAttr (){return render_framework->GetDevAttr();}
|
graph::VulkanDevAttr * GetDevAttr (){return render_framework->GetDevAttr();}
|
||||||
|
graph::TextureManager * GetTextureManager (){return render_framework->GetTextureManager();}
|
||||||
|
|
||||||
const VkExtent2D & GetExtent2D (){return cur_render_target->GetExtent();}
|
const VkExtent2D & GetExtent2D (){return cur_render_target->GetExtent();}
|
||||||
|
|
||||||
@ -53,9 +54,11 @@ namespace hgl
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
WorkObject(graph::RenderFramework *,graph::IRenderTarget *);
|
WorkObject(graph::RenderFramework *,graph::IRenderTarget *rt=nullptr);
|
||||||
virtual ~WorkObject()=default;
|
virtual ~WorkObject()=default;
|
||||||
|
|
||||||
|
virtual bool Init()=0;
|
||||||
|
|
||||||
virtual void OnRenderTargetSwitch(graph::RenderFramework *rf,graph::IRenderTarget *rt);
|
virtual void OnRenderTargetSwitch(graph::RenderFramework *rf,graph::IRenderTarget *rt);
|
||||||
|
|
||||||
virtual void OnResize(const VkExtent2D &){}
|
virtual void OnResize(const VkExtent2D &){}
|
||||||
|
@ -33,7 +33,7 @@ public:
|
|||||||
const AnsiString & GetName ()const{ return prim_name; }
|
const AnsiString & GetName ()const{ return prim_name; }
|
||||||
|
|
||||||
const VkDeviceSize GetVertexCount ()const;
|
const VkDeviceSize GetVertexCount ()const;
|
||||||
const int GetVABCount ()const;
|
const uint32_t GetVABCount ()const;
|
||||||
const int GetVABIndex (const AnsiString &name)const;
|
const int GetVABIndex (const AnsiString &name)const;
|
||||||
VAB * GetVAB (const int);
|
VAB * GetVAB (const int);
|
||||||
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
|
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
|
||||||
|
@ -127,9 +127,9 @@ public: //Material
|
|||||||
|
|
||||||
const ShaderModule *CreateShaderModule(const AnsiString &shader_module_name,const ShaderCreateInfo *);
|
const ShaderModule *CreateShaderModule(const AnsiString &shader_module_name,const ShaderCreateInfo *);
|
||||||
|
|
||||||
Material * CreateMaterial(const AnsiString &mtl_name,const mtl::MaterialCreateInfo *);
|
Material * CreateMaterial (const AnsiString &,const mtl::MaterialCreateInfo *);
|
||||||
Material * LoadMaterial(const AnsiString &,mtl::Material2DCreateConfig *);
|
Material * LoadMaterial (const AnsiString &,mtl::Material2DCreateConfig *);
|
||||||
Material * LoadMaterial(const AnsiString &,mtl::Material3DCreateConfig *);
|
Material * LoadMaterial (const AnsiString &,mtl::Material3DCreateConfig *);
|
||||||
|
|
||||||
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
|
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ const VkDeviceSize Primitive::GetVertexCount()const
|
|||||||
return prim_data->GetVertexCount();
|
return prim_data->GetVertexCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
const int Primitive::GetVABCount()const
|
const uint32_t Primitive::GetVABCount()const
|
||||||
{
|
{
|
||||||
return prim_data->GetVABCount();
|
return prim_data->GetVABCount();
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ PrimitiveData::~PrimitiveData()
|
|||||||
delete[] vab_list; //注意:这里并不释放VAB,在派生类中释放
|
delete[] vab_list; //注意:这里并不释放VAB,在派生类中释放
|
||||||
}
|
}
|
||||||
|
|
||||||
const int PrimitiveData::GetVABCount()const
|
const uint32_t PrimitiveData::GetVABCount()const
|
||||||
{
|
{
|
||||||
return vil->GetVertexAttribCount();
|
return vil->GetVertexAttribCount();
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ public:
|
|||||||
public:
|
public:
|
||||||
|
|
||||||
const uint32_t GetVertexCount ()const{return vertex_count;}
|
const uint32_t GetVertexCount ()const{return vertex_count;}
|
||||||
const int GetVABCount ()const;
|
const uint32_t GetVABCount ()const;
|
||||||
const int GetVABIndex (const AnsiString &name)const;
|
const int GetVABIndex (const AnsiString &name)const;
|
||||||
|
|
||||||
VAB * GetVAB (const int index);
|
VAB * GetVAB (const int index);
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
#include<hgl/graph/VKRenderTarget.h>
|
#include<hgl/graph/VKRenderTarget.h>
|
||||||
#include<hgl/graph/VKMaterialInstance.h>
|
#include<hgl/graph/VKMaterialInstance.h>
|
||||||
#include<hgl/graph/PrimitiveCreater.h>
|
#include<hgl/graph/PrimitiveCreater.h>
|
||||||
|
#include<hgl/graph/VKRenderTargetSwapchain.h>
|
||||||
#include<hgl/Time.h>
|
#include<hgl/Time.h>
|
||||||
//#include<iostream>
|
//#include<iostream>
|
||||||
|
|
||||||
@ -12,6 +13,9 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
WorkObject::WorkObject(graph::RenderFramework *rf,graph::IRenderTarget *rt)
|
WorkObject::WorkObject(graph::RenderFramework *rf,graph::IRenderTarget *rt)
|
||||||
{
|
{
|
||||||
|
if(!rt)
|
||||||
|
rt=rf->GetSwapchainRenderTarget();
|
||||||
|
|
||||||
OnRenderTargetSwitch(rf,rt);
|
OnRenderTargetSwitch(rf,rt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user