定义UBOInstance,并将ViewportInfo/CameraInfo两个UBO应用迁移到上面
This commit is contained in:
parent
18d391f01e
commit
3dfb2c65fd
@ -1 +1 @@
|
||||
Subproject commit ffcb2f8fdc46a5dffc04692e4ff9fdcc1512cf3a
|
||||
Subproject commit f866159787c98e29029c2b4dba3de8f6455473da
|
@ -2,6 +2,7 @@
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKMemory.h>
|
||||
#include<hgl/graph/mtl/ShaderBufferSource.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
struct DeviceBufferData
|
||||
@ -53,6 +54,8 @@ public:
|
||||
|
||||
template<typename T> class DeviceBufferMap
|
||||
{
|
||||
protected:
|
||||
|
||||
DeviceBuffer *dev_buf;
|
||||
T data_map;
|
||||
|
||||
@ -86,4 +89,30 @@ public:
|
||||
}
|
||||
};//template<typename T> class DeviceBufferMap
|
||||
|
||||
template<typename T> class UBOInstance:public DeviceBufferMap<T>
|
||||
{
|
||||
DescriptorSetType desc_set_type;
|
||||
AnsiString ubo_name;
|
||||
|
||||
public:
|
||||
|
||||
const DescriptorSetType & set_type()const{return desc_set_type;}
|
||||
const AnsiString & name ()const{return ubo_name;}
|
||||
DeviceBuffer * ubo ()const{return this->dev_buf;}
|
||||
|
||||
public:
|
||||
|
||||
UBOInstance(DeviceBuffer *buf,const DescriptorSetType dst,const AnsiString &n):DeviceBufferMap<T>(buf)
|
||||
{
|
||||
desc_set_type=dst;
|
||||
ubo_name=n;
|
||||
}
|
||||
|
||||
UBOInstance(DeviceBuffer *buf,const ShaderBufferDesc *desc):DeviceBufferMap<T>(buf)
|
||||
{
|
||||
desc_set_type=desc->set_type;
|
||||
ubo_name=desc->name;
|
||||
}
|
||||
};//template<typename T> class UBOInstance:public DeviceBufferMap<T>
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@ -48,7 +48,22 @@ public:
|
||||
if(name.IsEmpty()||!dbm)
|
||||
return(false);
|
||||
|
||||
return AddUBO(name,dbm->GetDeviceBuffer());
|
||||
return ubo_map.Add(name,dbm->GetDeviceBuffer());
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool AddUBO(const UBOInstance<T> *ubo_instance)
|
||||
{
|
||||
if(!ubo_instance)
|
||||
return(false);
|
||||
|
||||
if(ubo_instance->set_type()!=set_type)
|
||||
return(false);
|
||||
|
||||
if(ubo_instance->name().IsEmpty())
|
||||
return(false);
|
||||
|
||||
return ubo_map.Add(ubo_instance->name(),ubo_instance->ubo());
|
||||
}
|
||||
|
||||
DeviceBuffer *GetUBO(const AnsiString &name)
|
||||
|
@ -123,6 +123,18 @@ public: //Buffer相关
|
||||
{ \
|
||||
DeviceBuffer *buf=Create##LargeName(T::GetSize()); \
|
||||
return(buf?new T(buf):nullptr); \
|
||||
} \
|
||||
\
|
||||
template<typename T> T *Create##LargeName(const ShaderBufferDesc *desc) \
|
||||
{ \
|
||||
DeviceBuffer *buf=Create##LargeName(T::GetSize()); \
|
||||
return(buf?new T(buf,desc):nullptr); \
|
||||
} \
|
||||
\
|
||||
template<typename T> T *Create##LargeName(const DescriptorSetType &set_type,const AnsiString &name) \
|
||||
{ \
|
||||
DeviceBuffer *buf=Create##LargeName(T::GetSize()); \
|
||||
return(buf?new T(buf,set_type,name):nullptr); \
|
||||
}
|
||||
|
||||
CREATE_BUFFER_OBJECT(UBO,UNIFORM)
|
||||
|
@ -15,7 +15,7 @@ VK_NAMESPACE_BEGIN
|
||||
|
||||
class RenderFramework;
|
||||
|
||||
using UBOViewportInfo=DeviceBufferMap<graph::ViewportInfo>;
|
||||
using UBOViewportInfo=UBOInstance<graph::ViewportInfo>;
|
||||
|
||||
class IRenderTarget
|
||||
{
|
||||
|
@ -13,7 +13,7 @@ namespace hgl::graph
|
||||
camera_info=ubo_camera_info->data();
|
||||
|
||||
desc_binding_camera=new DescriptorBinding(DescriptorSetType::Camera);
|
||||
desc_binding_camera->AddUBO(mtl::SBS_CameraInfo.name,ubo_camera_info);
|
||||
desc_binding_camera->AddUBO(ubo_camera_info);
|
||||
}
|
||||
|
||||
CameraControl::~CameraControl()
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/FirstPersonCameraControl.h>
|
||||
#include<hgl/graph/Renderer.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
#include<hgl/log/Logger.h>
|
||||
#include<hgl/Time.h>
|
||||
|
||||
@ -146,7 +147,7 @@ void RenderFramework::CreateDefaultRenderer()
|
||||
|
||||
if(!default_camera_control)
|
||||
{
|
||||
auto ubo_camera_info=device->CreateUBO<UBOCameraInfo>();
|
||||
auto ubo_camera_info=device->CreateUBO<UBOCameraInfo>(&mtl::SBS_CameraInfo);
|
||||
|
||||
default_camera_control=new FirstPersonCameraControl(rt->GetViewportInfo(),default_camera,ubo_camera_info);
|
||||
}
|
||||
|
@ -13,9 +13,9 @@ IRenderTarget::IRenderTarget(RenderFramework *rf,const VkExtent2D &ext):desc_bin
|
||||
{
|
||||
render_framework=rf;
|
||||
|
||||
ubo_vp_info=GetDevice()->CreateUBO<UBOViewportInfo>();
|
||||
ubo_vp_info=GetDevice()->CreateUBO<UBOViewportInfo>(&mtl::SBS_ViewportInfo);
|
||||
|
||||
desc_binding.AddUBO(mtl::SBS_ViewportInfo.name,ubo_vp_info);
|
||||
desc_binding.AddUBO(ubo_vp_info);
|
||||
|
||||
OnResize(ext);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user