支持新的CameraControl,并实现自动绑定,现BillboardTest已可正常渲染。只是鼠标键盘输入尚未接入
This commit is contained in:
parent
c4720e8cdb
commit
0be9cb3f74
2
CMCore
2
CMCore
@ -1 +1 @@
|
||||
Subproject commit fd0dbb00550bf8aee92ae19651fe8a780d8d5205
|
||||
Subproject commit fff021488c9608c2ac4ee06bc544e9a80849c6f0
|
@ -1 +1 @@
|
||||
Subproject commit e1155d0374cd187d3e4b74cfa1905c1e1df21167
|
||||
Subproject commit ffcb2f8fdc46a5dffc04692e4ff9fdcc1512cf3a
|
@ -12,6 +12,7 @@
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/VKVertexInputConfig.h>
|
||||
#include<hgl/graph/module/TextureManager.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@ -32,10 +33,6 @@ class TestApp:public WorkObject
|
||||
|
||||
private:
|
||||
|
||||
AutoDelete<RenderList> render_list =nullptr;
|
||||
|
||||
SceneNode render_root;
|
||||
|
||||
Material * mtl_plane_grid =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
Pipeline * pipeline_plane_grid =nullptr;
|
||||
@ -115,7 +112,7 @@ private:
|
||||
return(true);
|
||||
}
|
||||
|
||||
Mesh *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
SceneNode *CreateSceneNode(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
Mesh *ri=db->CreateMesh(r,mi,p);
|
||||
|
||||
@ -125,9 +122,7 @@ private:
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
render_root.Add(new SceneNode(ri));
|
||||
|
||||
return ri;
|
||||
return(new SceneNode(ri));
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
@ -167,16 +162,24 @@ private:
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
|
||||
SceneNode *scene_root=GetSceneRoot(); //取得缺省场景根节点
|
||||
Camera *cur_camera=GetCamera(); //取得缺省相机
|
||||
|
||||
render_root.Add(new SceneNode(ro_billboard));
|
||||
scene_root->Add(CreateSceneNode(prim_plane_grid,mi_plane_grid,pipeline_plane_grid));
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
camera_control->Refresh();
|
||||
scene_root->Add(new SceneNode(ro_billboard));
|
||||
|
||||
render_root.RefreshMatrix();
|
||||
render_list->Expend(&render_root);
|
||||
cur_camera->pos=Vector3f(32,32,32);
|
||||
|
||||
CameraControl *camera_control=GetCameraControl();
|
||||
|
||||
if(camera_control
|
||||
&&camera_control->GetControlName()==FirstPersonCameraControl::StaticControlName())
|
||||
{
|
||||
FirstPersonCameraControl *fp_cam_ctl=(FirstPersonCameraControl *)camera_control;
|
||||
|
||||
fp_cam_ctl->SetTarget(Vector3f(0,0,0));
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
@ -48,7 +48,8 @@ namespace hgl
|
||||
graph::Scene * GetScene (){return scene;}
|
||||
graph::SceneNode * GetSceneRoot (){return scene->GetRootNode();}
|
||||
graph::Renderer * GetRenderer (){return renderer;}
|
||||
graph::Camera * GetCamera (){return renderer->GetCurCamera();}
|
||||
graph::Camera * GetCamera (){return renderer->GetCamera();}
|
||||
graph::CameraControl * GetCameraControl (){return render_framework->GetDefaultCameraControl();}
|
||||
|
||||
public:
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include<hgl/graph/module/SwapchainModule.h>
|
||||
#include<hgl/graph/module/GraphModuleManager.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/CameraControl.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@ -54,6 +55,7 @@ protected: //RenderContext,未来合并成一个RenderContext结构
|
||||
|
||||
Scene * default_scene =nullptr;
|
||||
Camera * default_camera =nullptr;
|
||||
CameraControl * default_camera_control =nullptr;
|
||||
Renderer * default_renderer =nullptr;
|
||||
|
||||
void CreateDefaultRenderer();
|
||||
@ -83,6 +85,7 @@ public:
|
||||
|
||||
Scene * GetDefaultScene (){return default_scene;}
|
||||
Camera * GetDefaultCamera (){return default_camera;}
|
||||
CameraControl * GetDefaultCameraControl (){return default_camera_control;}
|
||||
Renderer * GetDefaultRenderer (){return default_renderer;}
|
||||
|
||||
public:
|
||||
|
@ -29,12 +29,16 @@ namespace hgl
|
||||
|
||||
virtual bool ExpendNode(SceneNode *);
|
||||
|
||||
public:
|
||||
|
||||
const CameraInfo *GetCameraInfo()const{return camera_info;}
|
||||
|
||||
public:
|
||||
|
||||
RenderList(VulkanDevice *);
|
||||
virtual ~RenderList()=default;
|
||||
|
||||
virtual void SetCamera(CameraInfo *ci){camera_info=ci;} ///<设置相机信息
|
||||
virtual void SetCameraInfo(CameraInfo *ci){camera_info=ci;} ///<设置相机信息
|
||||
virtual bool Expend(SceneNode *); ///<展开场景树到渲染列表
|
||||
|
||||
bool IsEmpty()const{return !renderable_count;} ///<是否是空的
|
||||
|
@ -16,7 +16,7 @@ namespace hgl::graph
|
||||
|
||||
IRenderTarget * render_target;
|
||||
RenderList * render_list;
|
||||
Camera * camera;
|
||||
CameraInfo * camera_info;
|
||||
|
||||
public:
|
||||
|
||||
@ -24,16 +24,16 @@ namespace hgl::graph
|
||||
|
||||
IRenderTarget * GetRenderTarget ()const{return render_target;}
|
||||
RenderList * GetRenderList ()const{return render_list;}
|
||||
Camera * GetCamera ()const{return camera;}
|
||||
CameraInfo * GetCameraInfo ()const{return camera_info;}
|
||||
|
||||
public:
|
||||
|
||||
RenderTask(const RenderTaskName &tn,IRenderTarget *rt=nullptr,Camera *c=nullptr);
|
||||
RenderTask(const RenderTaskName &tn,IRenderTarget *rt=nullptr,CameraInfo *ci=nullptr);
|
||||
|
||||
virtual ~RenderTask();
|
||||
|
||||
bool SetRenderTarget(IRenderTarget *rt);
|
||||
void SetCamera(Camera *c){camera=c;}
|
||||
bool SetRenderTarget(IRenderTarget *);
|
||||
void SetCameraInfo(CameraInfo *);
|
||||
|
||||
bool RebuildRenderList(SceneNode *);
|
||||
|
||||
|
@ -2,16 +2,16 @@
|
||||
|
||||
#include<hgl/graph/RenderTask.h>
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/CameraControl.h>
|
||||
#include<hgl/type/Map.h>
|
||||
|
||||
namespace hgl::graph
|
||||
{
|
||||
class Scene;
|
||||
class CameraControl;
|
||||
|
||||
using RenderTaskNameMap=Map<RenderTaskName,RenderTask *>;
|
||||
|
||||
using UBOCameraInfo=DeviceBufferMap<CameraInfo>;
|
||||
|
||||
/**
|
||||
* 渲染器
|
||||
*/
|
||||
@ -20,9 +20,7 @@ namespace hgl::graph
|
||||
IRenderTarget *render_target;
|
||||
Scene *scene;
|
||||
|
||||
Camera *camera;
|
||||
|
||||
UBOCameraInfo *ubo_camera_info;
|
||||
CameraControl *camera_control;
|
||||
|
||||
//RenderTaskNameMap static_render_task_list; ///<静态渲染任务列表
|
||||
//RenderTaskNameMap dynamic_render_task_list; ///<动态渲染任务列表
|
||||
@ -40,7 +38,7 @@ namespace hgl::graph
|
||||
const VkExtent2D &GetExtent ()const{return render_target->GetExtent();} ///<取得当前渲染器画面尺寸
|
||||
|
||||
Scene * GetScene ()const{return scene;} ///<获取场景世界
|
||||
Camera * GetCurCamera ()const{return camera;} ///<获取当前相机
|
||||
Camera * GetCamera ()const{return camera_control->GetCamera();} ///<获取当前相机
|
||||
|
||||
public:
|
||||
|
||||
@ -48,8 +46,8 @@ namespace hgl::graph
|
||||
virtual ~Renderer();
|
||||
|
||||
bool SetRenderTarget(IRenderTarget *);
|
||||
void SetCurScene(Scene *);
|
||||
void SetCurCamera(Camera *);
|
||||
void SetScene(Scene *);
|
||||
void SetCameraControl(CameraControl *);
|
||||
|
||||
void SetClearColor(const Color4f &c){clear_color=c;}
|
||||
|
||||
|
@ -75,7 +75,7 @@ public:
|
||||
delete dev_buf;
|
||||
}
|
||||
|
||||
operator DeviceBuffer *(){return dev_buf;}
|
||||
DeviceBuffer *GetDeviceBuffer(){return dev_buf;}
|
||||
|
||||
T *data(){return &data_map;}
|
||||
|
||||
@ -84,6 +84,6 @@ public:
|
||||
if(dev_buf)
|
||||
dev_buf->Write(&data_map,sizeof(T));
|
||||
}
|
||||
};
|
||||
};//template<typename T> class DeviceBufferMap
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -43,6 +43,12 @@ public:
|
||||
return ubo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool AddUBO(const AnsiString &name,DeviceBufferMap<T> *dbm)
|
||||
{
|
||||
return AddUBO(name,dbm->GetDeviceBuffer());
|
||||
}
|
||||
|
||||
DeviceBuffer *GetUBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
@ -65,6 +71,12 @@ public:
|
||||
return ssbo_map.Add(name,buf);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool AddSSBO(const AnsiString &name,DeviceBufferMap<T> *dbm)
|
||||
{
|
||||
return AddSSBO(name,dbm->GetDeviceBuffer());
|
||||
}
|
||||
|
||||
DeviceBuffer *GetSSBO(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
@ -73,7 +73,7 @@ public: // Command Buffer
|
||||
|
||||
public:
|
||||
|
||||
virtual const ViewportInfo *GetViewportInfo ()const
|
||||
virtual ViewportInfo * GetViewportInfo ()
|
||||
{
|
||||
return ubo_vp_info->data();
|
||||
}
|
||||
|
@ -67,7 +67,8 @@ SET(GRAPH_MODULE_FILES ${SGM_HEADER_PATH}/GraphModule.h
|
||||
source_group("Framework\\Module" FILES ${GRAPH_MODULE_FILES})
|
||||
|
||||
SET(GRAPH_FRAMEWORK_FILES ${SG_INCLUDE_PATH}/RenderFramework.h
|
||||
RenderFramework.cpp)
|
||||
RenderFramework.cpp
|
||||
CameraControl.cpp)
|
||||
|
||||
source_group("Framework" FILES ${GRAPH_FRAMEWORK_FILES})
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include<hgl/graph/VKCommandBuffer.h>
|
||||
#include<hgl/graph/Scene.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
#include<hgl/graph/Renderer.h>
|
||||
#include<hgl/log/Logger.h>
|
||||
#include<hgl/Time.h>
|
||||
@ -52,6 +53,7 @@ RenderFramework::RenderFramework(const OSString &an)
|
||||
RenderFramework::~RenderFramework()
|
||||
{
|
||||
SAFE_CLEAR(default_renderer)
|
||||
SAFE_CLEAR(default_camera_control)
|
||||
SAFE_CLEAR(default_camera)
|
||||
SAFE_CLEAR(default_scene)
|
||||
SAFE_CLEAR(render_resource)
|
||||
@ -135,13 +137,21 @@ bool RenderFramework::Init(uint w,uint h)
|
||||
|
||||
void RenderFramework::CreateDefaultRenderer()
|
||||
{
|
||||
|
||||
|
||||
SAFE_CLEAR(default_renderer)
|
||||
|
||||
default_renderer=new Renderer(GetSwapchainRenderTarget());
|
||||
default_renderer->SetCurScene(default_scene);
|
||||
default_renderer->SetCurCamera(default_camera);
|
||||
IRenderTarget *rt=GetSwapchainRenderTarget();
|
||||
|
||||
default_renderer=new Renderer(rt);
|
||||
default_renderer->SetScene(default_scene);
|
||||
|
||||
if(!default_camera_control)
|
||||
{
|
||||
auto ubo_camera_info=device->CreateUBO<UBOCameraInfo>();
|
||||
|
||||
default_camera_control=new FirstPersonCameraControl(rt->GetViewportInfo(),default_camera,ubo_camera_info);
|
||||
}
|
||||
|
||||
default_renderer->SetCameraControl(default_camera_control);
|
||||
}
|
||||
|
||||
void RenderFramework::OnResize(uint w,uint h)
|
||||
|
@ -15,7 +15,7 @@ IRenderTarget::IRenderTarget(RenderFramework *rf,const VkExtent2D &ext):desc_bin
|
||||
|
||||
ubo_vp_info=GetDevice()->CreateUBO<UBOViewportInfo>();
|
||||
|
||||
desc_binding.AddUBO(mtl::SBS_ViewportInfo.name,*ubo_vp_info);
|
||||
desc_binding.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
|
||||
|
||||
OnResize(ext);
|
||||
}
|
||||
|
@ -5,11 +5,11 @@
|
||||
|
||||
namespace hgl::graph
|
||||
{
|
||||
RenderTask::RenderTask(const RenderTaskName &tn,IRenderTarget *rt,Camera *c)
|
||||
RenderTask::RenderTask(const RenderTaskName &tn,IRenderTarget *rt,CameraInfo *ci)
|
||||
{
|
||||
task_name=tn;
|
||||
|
||||
camera=c;
|
||||
camera_info=ci;
|
||||
render_target=nullptr;
|
||||
render_list=nullptr;
|
||||
|
||||
@ -37,11 +37,23 @@ namespace hgl::graph
|
||||
if(!render_list)
|
||||
{
|
||||
render_list=new RenderList(rt->GetDevice());
|
||||
|
||||
if(camera_info)
|
||||
render_list->SetCameraInfo(camera_info);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void RenderTask::SetCameraInfo(CameraInfo *ci)
|
||||
{
|
||||
if(camera_info==ci)return;
|
||||
|
||||
camera_info=ci;
|
||||
|
||||
render_list->SetCameraInfo(ci);
|
||||
}
|
||||
|
||||
bool RenderTask::RebuildRenderList(SceneNode *root)
|
||||
{
|
||||
if(!root)
|
||||
@ -50,6 +62,9 @@ namespace hgl::graph
|
||||
if(!render_list)
|
||||
return(false);
|
||||
|
||||
if(!render_list->GetCameraInfo()&&camera_info)
|
||||
render_list->SetCameraInfo(camera_info);
|
||||
|
||||
//记往不需要,也千万不要手动render_list->Clear,因为那会释放内存。再次使用时重新分配
|
||||
//render_list->Expend会自己复位所有数据,且并不会释放内存
|
||||
render_list->Expend(root);
|
||||
|
@ -10,8 +10,8 @@ namespace hgl::graph
|
||||
{
|
||||
render_target=rt;
|
||||
scene=nullptr;
|
||||
camera=nullptr;
|
||||
ubo_camera_info=rt->GetDevice()->CreateUBO<UBOCameraInfo>();
|
||||
camera_control=nullptr;
|
||||
|
||||
render_task=new RenderTask("DefaultRenderTask",rt);
|
||||
|
||||
clear_color.Set(0,0,0,1);
|
||||
@ -19,7 +19,6 @@ namespace hgl::graph
|
||||
|
||||
Renderer::~Renderer()
|
||||
{
|
||||
delete ubo_camera_info;
|
||||
delete render_task;
|
||||
}
|
||||
|
||||
@ -40,12 +39,11 @@ namespace hgl::graph
|
||||
render_target=rt;
|
||||
|
||||
render_task->SetRenderTarget(rt);
|
||||
render_task->SetCamera(camera);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
void Renderer::SetCurScene(Scene *sw)
|
||||
void Renderer::SetScene(Scene *sw)
|
||||
{
|
||||
if(scene==sw)
|
||||
return;
|
||||
@ -63,9 +61,9 @@ namespace hgl::graph
|
||||
//}
|
||||
}
|
||||
|
||||
void Renderer::SetCurCamera(Camera *c)
|
||||
void Renderer::SetCameraControl(CameraControl *cc)
|
||||
{
|
||||
if(!scene||!c)
|
||||
if(!scene||!cc)
|
||||
return;
|
||||
|
||||
//if(camera)
|
||||
@ -76,7 +74,7 @@ namespace hgl::graph
|
||||
// camera->Unjoin(this);
|
||||
//}
|
||||
|
||||
camera=c;
|
||||
camera_control=cc;
|
||||
|
||||
//if(camera)
|
||||
//{
|
||||
@ -86,7 +84,7 @@ namespace hgl::graph
|
||||
// camera->Join(this);
|
||||
//}
|
||||
|
||||
render_task->SetCamera(camera); //它要camera只是为了CPU端算远近
|
||||
render_task->SetCameraInfo(camera_control->GetCameraInfo());
|
||||
}
|
||||
|
||||
bool Renderer::RenderFrame()
|
||||
@ -101,17 +99,25 @@ namespace hgl::graph
|
||||
|
||||
root->RefreshMatrix();
|
||||
|
||||
if(camera)
|
||||
if(camera_control)
|
||||
{
|
||||
RefreshCameraInfo(ubo_camera_info->data(),render_target->GetViewportInfo(),camera);
|
||||
camera_control->SetViewport(render_target->GetViewportInfo());
|
||||
|
||||
camera_control->Refresh();
|
||||
}
|
||||
|
||||
// 这里内部会将Scene tree展开成RenderList,而RenderList排序是需要CameraInfo的
|
||||
render_task->RebuildRenderList(root);
|
||||
|
||||
bool result=false;
|
||||
|
||||
graph::RenderCmdBuffer *cmd=render_target->BeginRender();
|
||||
|
||||
if(camera_control)
|
||||
{
|
||||
cmd->SetDescriptorBinding(camera_control->GetDescriptorBinding());
|
||||
}
|
||||
|
||||
cmd->SetClearColor(0,clear_color);
|
||||
|
||||
cmd->BeginRenderPass();
|
||||
|
@ -25,7 +25,7 @@ bool Std3DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
|
||||
mci->AddStruct(SBS_CameraInfo);
|
||||
|
||||
mci->AddUBO(VK_SHADER_STAGE_ALL_GRAPHICS,
|
||||
DescriptorSetType::Global,
|
||||
DescriptorSetType::Camera,
|
||||
SBS_CameraInfo);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user