将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
|
||||
|
||||
#include"VulkanAppFramework.h"
|
||||
#include<hgl/WorkManager.h>
|
||||
#include<hgl/filesystem/FileSystem.h>
|
||||
#include<hgl/graph/InlineGeometry.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
@ -11,6 +11,7 @@
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
|
||||
using namespace hgl;
|
||||
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 yellow_color(1,1,0,1);
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
class TestApp:public WorkObject
|
||||
{
|
||||
Color4f color;
|
||||
|
||||
private:
|
||||
|
||||
AutoDelete<RenderList> render_list =nullptr;
|
||||
|
||||
SceneNode render_root;
|
||||
|
||||
Material * mtl_plane_grid =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_plane_grid =nullptr;
|
||||
@ -90,7 +95,9 @@ private:
|
||||
|
||||
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);
|
||||
|
||||
sampler=db->CreateSampler();
|
||||
@ -107,7 +114,7 @@ private:
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
|
||||
Mesh *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Mesh *ri=db->CreateMesh(r,mi,p);
|
||||
@ -126,9 +133,9 @@ private:
|
||||
bool CreateRenderObject()
|
||||
{
|
||||
using namespace inline_geometry;
|
||||
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mi_plane_grid->GetVIL());
|
||||
PrimitiveCreater pc(GetDevice(),mi_plane_grid->GetVIL());
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
@ -142,7 +149,7 @@ private:
|
||||
}
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mi_billboard->GetVIL());
|
||||
PrimitiveCreater pc(GetDevice(),mi_billboard->GetVIL());
|
||||
|
||||
pc.Init("Billboard",1);
|
||||
|
||||
@ -150,6 +157,7 @@ private:
|
||||
return(false);
|
||||
|
||||
ro_billboard=db->CreateMesh(&pc,mi_billboard,pipeline_billboard);
|
||||
|
||||
if(!ro_billboard)
|
||||
return(false);
|
||||
}
|
||||
@ -175,16 +183,15 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
}
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
bool Init()
|
||||
{
|
||||
if(!SceneAppFramework::Init(w,h))
|
||||
return(false);
|
||||
|
||||
if(!InitPlaneGridMP())
|
||||
return(false);
|
||||
|
||||
@ -202,9 +209,9 @@ public:
|
||||
|
||||
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:
|
||||
|
||||
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())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
||||
|
@ -111,15 +111,22 @@ private:
|
||||
|
||||
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())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
if(!InitVBOAndRenderList())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
||||
@ -130,7 +137,7 @@ public:
|
||||
render_list->Render(cmd);
|
||||
cmd->EndRenderPass();
|
||||
}
|
||||
};//class TestApp:public VulkanApplicationFramework
|
||||
};//class TestApp:public WorkObject
|
||||
|
||||
int os_main(int,os_char **)
|
||||
{
|
||||
|
@ -119,19 +119,23 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
InitVIL();
|
||||
|
||||
if(!InitAutoMaterial())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
if(!InitPipeline())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Tick(double)override{}
|
||||
|
@ -90,14 +90,18 @@ private:
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitMaterial())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Render(double delta_time,graph::RenderCmdBuffer *cmd)override
|
||||
|
@ -71,16 +71,20 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
TestApp(RenderFramework *rf):WorkObject(rf,rf->GetSwapchainRenderTarget())
|
||||
using WorkObject::WorkObject;
|
||||
|
||||
bool Init() override
|
||||
{
|
||||
if(!InitAutoMaterial())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
if(!InitPipeline())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
if(!InitVBO())
|
||||
return;
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Tick(double)override{}
|
||||
|
@ -80,7 +80,15 @@ namespace hgl
|
||||
|
||||
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;
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ namespace hgl
|
||||
graph::RenderFramework * GetRenderFramework (){return render_framework;}
|
||||
graph::VulkanDevice * GetDevice (){return render_framework->GetDevice();}
|
||||
graph::VulkanDevAttr * GetDevAttr (){return render_framework->GetDevAttr();}
|
||||
graph::TextureManager * GetTextureManager (){return render_framework->GetTextureManager();}
|
||||
|
||||
const VkExtent2D & GetExtent2D (){return cur_render_target->GetExtent();}
|
||||
|
||||
@ -53,9 +54,11 @@ namespace hgl
|
||||
|
||||
public:
|
||||
|
||||
WorkObject(graph::RenderFramework *,graph::IRenderTarget *);
|
||||
WorkObject(graph::RenderFramework *,graph::IRenderTarget *rt=nullptr);
|
||||
virtual ~WorkObject()=default;
|
||||
|
||||
virtual bool Init()=0;
|
||||
|
||||
virtual void OnRenderTargetSwitch(graph::RenderFramework *rf,graph::IRenderTarget *rt);
|
||||
|
||||
virtual void OnResize(const VkExtent2D &){}
|
||||
|
@ -33,7 +33,7 @@ public:
|
||||
const AnsiString & GetName ()const{ return prim_name; }
|
||||
|
||||
const VkDeviceSize GetVertexCount ()const;
|
||||
const int GetVABCount ()const;
|
||||
const uint32_t GetVABCount ()const;
|
||||
const int GetVABIndex (const AnsiString &name)const;
|
||||
VAB * GetVAB (const int);
|
||||
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 *);
|
||||
|
||||
Material * CreateMaterial(const AnsiString &mtl_name,const mtl::MaterialCreateInfo *);
|
||||
Material * LoadMaterial(const AnsiString &,mtl::Material2DCreateConfig *);
|
||||
Material * LoadMaterial(const AnsiString &,mtl::Material3DCreateConfig *);
|
||||
Material * CreateMaterial (const AnsiString &,const mtl::MaterialCreateInfo *);
|
||||
Material * LoadMaterial (const AnsiString &,mtl::Material2DCreateConfig *);
|
||||
Material * LoadMaterial (const AnsiString &,mtl::Material3DCreateConfig *);
|
||||
|
||||
MaterialInstance * CreateMaterialInstance(Material *,const VILConfig *vil_cfg=nullptr);
|
||||
|
||||
@ -143,31 +143,31 @@ public: //Material
|
||||
|
||||
MaterialInstance * CreateMaterialInstance(const AnsiString &mtl_name,const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
||||
|
||||
Mesh * CreateMesh(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
||||
Mesh * CreateMesh(PrimitiveCreater *pc,MaterialInstance *mi,Pipeline *p);
|
||||
Mesh * CreateMesh(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
||||
Mesh * CreateMesh(PrimitiveCreater *pc,MaterialInstance *mi,Pipeline *p);
|
||||
|
||||
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||
Sampler * CreateSampler(Texture *);
|
||||
|
||||
public: //Get
|
||||
|
||||
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
|
||||
MaterialInstance * GetMaterialInstance (const MaterialInstanceID &id){return rm_material_instance.Get(id);}
|
||||
DescriptorSet * GetDescSets (const DescriptorSetID &id){return rm_desc_sets.Get(id);}
|
||||
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);}
|
||||
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
|
||||
Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);}
|
||||
Mesh * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
||||
Material * GetMaterial (const MaterialID &id){return rm_material.Get(id);}
|
||||
MaterialInstance * GetMaterialInstance (const MaterialInstanceID &id){return rm_material_instance.Get(id);}
|
||||
DescriptorSet * GetDescSets (const DescriptorSetID &id){return rm_desc_sets.Get(id);}
|
||||
Primitive * GetPrimitive (const PrimitiveID &id){return rm_primitives.Get(id);}
|
||||
DeviceBuffer * GetBuffer (const BufferID &id){return rm_buffers.Get(id);}
|
||||
Sampler * GetSampler (const SamplerID &id){return rm_samplers.Get(id);}
|
||||
Mesh * GetRenderable (const RenderableID &id){return rm_renderables.Get(id);}
|
||||
|
||||
public: //Release
|
||||
|
||||
void Release(Material * mtl ){rm_material.Release(mtl);}
|
||||
void Release(MaterialInstance * mi ){rm_material_instance.Release(mi);}
|
||||
void Release(DescriptorSet * ds ){rm_desc_sets.Release(ds);}
|
||||
void Release(Primitive * p ){rm_primitives.Release(p);}
|
||||
void Release(DeviceBuffer * buf ){rm_buffers.Release(buf);}
|
||||
void Release(Sampler * s ){rm_samplers.Release(s);}
|
||||
void Release(Mesh * r ){rm_renderables.Release(r);}
|
||||
void Release(Material * mtl ){rm_material.Release(mtl);}
|
||||
void Release(MaterialInstance * mi ){rm_material_instance.Release(mi);}
|
||||
void Release(DescriptorSet * ds ){rm_desc_sets.Release(ds);}
|
||||
void Release(Primitive * p ){rm_primitives.Release(p);}
|
||||
void Release(DeviceBuffer * buf ){rm_buffers.Release(buf);}
|
||||
void Release(Sampler * s ){rm_samplers.Release(s);}
|
||||
void Release(Mesh * r ){rm_renderables.Release(r);}
|
||||
};//class RenderResource
|
||||
|
||||
/**
|
||||
|
@ -46,7 +46,7 @@ const VkDeviceSize Primitive::GetVertexCount()const
|
||||
return prim_data->GetVertexCount();
|
||||
}
|
||||
|
||||
const int Primitive::GetVABCount()const
|
||||
const uint32_t Primitive::GetVABCount()const
|
||||
{
|
||||
return prim_data->GetVABCount();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ PrimitiveData::~PrimitiveData()
|
||||
delete[] vab_list; //注意:这里并不释放VAB,在派生类中释放
|
||||
}
|
||||
|
||||
const int PrimitiveData::GetVABCount()const
|
||||
const uint32_t PrimitiveData::GetVABCount()const
|
||||
{
|
||||
return vil->GetVertexAttribCount();
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
public:
|
||||
|
||||
const uint32_t GetVertexCount ()const{return vertex_count;}
|
||||
const int GetVABCount ()const;
|
||||
const uint32_t GetVABCount ()const;
|
||||
const int GetVABIndex (const AnsiString &name)const;
|
||||
|
||||
VAB * GetVAB (const int index);
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/VKRenderTargetSwapchain.h>
|
||||
#include<hgl/Time.h>
|
||||
//#include<iostream>
|
||||
|
||||
@ -12,6 +13,9 @@ namespace hgl
|
||||
{
|
||||
WorkObject::WorkObject(graph::RenderFramework *rf,graph::IRenderTarget *rt)
|
||||
{
|
||||
if(!rt)
|
||||
rt=rf->GetSwapchainRenderTarget();
|
||||
|
||||
OnRenderTargetSwitch(rf,rt);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user