Added DeviceBufferMap, first used in ViewportInfo
This commit is contained in:
parent
c5e9f151fc
commit
55765cf112
@ -70,6 +70,7 @@ class TileData;
|
|||||||
class DeviceMemory;
|
class DeviceMemory;
|
||||||
class DeviceBuffer;
|
class DeviceBuffer;
|
||||||
struct DeviceBufferData;
|
struct DeviceBufferData;
|
||||||
|
template<typename T> class DeviceBufferMap;
|
||||||
|
|
||||||
struct PrimitiveDataBuffer;
|
struct PrimitiveDataBuffer;
|
||||||
struct PrimitiveRenderData;
|
struct PrimitiveRenderData;
|
||||||
|
@ -51,4 +51,39 @@ public:
|
|||||||
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
|
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
|
||||||
};//class DeviceBuffer
|
};//class DeviceBuffer
|
||||||
|
|
||||||
|
template<typename T> class DeviceBufferMap
|
||||||
|
{
|
||||||
|
DeviceBuffer *dev_buf;
|
||||||
|
T data_map;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
static const VkDeviceSize GetSize()
|
||||||
|
{
|
||||||
|
return sizeof(T);
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
DeviceBufferMap(DeviceBuffer *buf)
|
||||||
|
{
|
||||||
|
dev_buf=buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~DeviceBufferMap()
|
||||||
|
{
|
||||||
|
delete dev_buf;
|
||||||
|
}
|
||||||
|
|
||||||
|
operator DeviceBuffer *(){return dev_buf;}
|
||||||
|
|
||||||
|
T *data(){return &data_map;}
|
||||||
|
|
||||||
|
void Update()
|
||||||
|
{
|
||||||
|
if(dev_buf)
|
||||||
|
dev_buf->Write(&data_map,sizeof(T));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -126,6 +126,17 @@ public: //Buffer相关
|
|||||||
|
|
||||||
#undef CREATE_BUFFER_OBJECT
|
#undef CREATE_BUFFER_OBJECT
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T *CreateUBO()
|
||||||
|
{
|
||||||
|
DeviceBuffer *buf=CreateUBO(T::GetSize());
|
||||||
|
|
||||||
|
if(!buf)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
|
return(new T(buf));
|
||||||
|
}
|
||||||
|
|
||||||
GPUArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
|
GPUArrayBuffer *CreateArrayInUBO(const VkDeviceSize &uint_size);
|
||||||
GPUArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
|
GPUArrayBuffer *CreateArrayInSSBO(const VkDeviceSize &uint_size);
|
||||||
|
|
||||||
|
@ -14,6 +14,8 @@ VK_NAMESPACE_BEGIN
|
|||||||
|
|
||||||
class RenderFramework;
|
class RenderFramework;
|
||||||
|
|
||||||
|
using UBOViewportInfo=DeviceBufferMap<graph::ViewportInfo>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RenderTarget 存在几种情况:
|
* RenderTarget 存在几种情况:
|
||||||
*
|
*
|
||||||
@ -29,8 +31,8 @@ class IRenderTarget
|
|||||||
RenderFramework *render_framework;
|
RenderFramework *render_framework;
|
||||||
|
|
||||||
VkExtent2D extent;
|
VkExtent2D extent;
|
||||||
graph::ViewportInfo vp_info;
|
|
||||||
graph::DeviceBuffer *ubo_vp_info;
|
UBOViewportInfo *ubo_vp_info;
|
||||||
|
|
||||||
DescriptorBinding desc_binding;
|
DescriptorBinding desc_binding;
|
||||||
|
|
||||||
|
@ -16,9 +16,9 @@ IRenderTarget::IRenderTarget(RenderFramework *rf,const VkExtent2D &ext):desc_bin
|
|||||||
{
|
{
|
||||||
render_framework=rf;
|
render_framework=rf;
|
||||||
|
|
||||||
ubo_vp_info=GetDevice()->CreateUBO(sizeof(ViewportInfo),&vp_info);
|
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);
|
OnResize(ext);
|
||||||
}
|
}
|
||||||
@ -31,8 +31,10 @@ IRenderTarget::~IRenderTarget()
|
|||||||
void IRenderTarget::OnResize(const VkExtent2D &ext)
|
void IRenderTarget::OnResize(const VkExtent2D &ext)
|
||||||
{
|
{
|
||||||
extent=ext;
|
extent=ext;
|
||||||
vp_info.Set(ext.width,ext.height);
|
|
||||||
ubo_vp_info->Write(&vp_info);
|
ubo_vp_info->data()->Set(ext.width,ext.height);
|
||||||
|
|
||||||
|
ubo_vp_info->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderTargetData::Clear()
|
void RenderTargetData::Clear()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user