ULRE/src/SceneGraph/Vulkan/VKArrayBuffer.cpp

61 lines
1.3 KiB
C++
Raw Normal View History

2021-03-25 20:00:19 +08:00
#include<hgl/graph/VKArrayBuffer.h>
2021-02-10 18:53:07 +08:00
namespace hgl
{
namespace graph
{
/**
2021-03-25 20:00:19 +08:00
*
* @param d
* @param s
* @param c
2021-02-10 18:53:07 +08:00
*/
2021-03-25 20:00:19 +08:00
GPUArrayBuffer::GPUArrayBuffer(GPUDevice *d,const uint32_t s,const uint32_t c)
2021-02-10 18:53:07 +08:00
{
2021-03-25 20:00:19 +08:00
device=d;
2021-02-10 18:53:07 +08:00
item_size=s;
count=c;
alloc_count=power_to_2(c);
buf_gpu=nullptr;
buf_cpu=nullptr;
offset=nullptr;
}
GPUArrayBuffer::~GPUArrayBuffer()
{
2021-03-25 20:00:19 +08:00
SAFE_CLEAR_ARRAY(offset);
2021-02-10 18:53:07 +08:00
SAFE_CLEAR(buf_gpu);
}
void GPUArrayBuffer::Clear()
{
count=0;
}
2021-03-25 20:00:19 +08:00
bool GPUArrayBuffer::Init(const uint32_t c)
{
if(c<=0)return(false);
if(!buf_gpu)
{
count=c;
alloc_count=power_to_2(count);
total_bytes=item_size*alloc_count;
2021-02-10 18:53:07 +08:00
2021-03-25 20:00:19 +08:00
if(total_bytes<=0)return(false);
buf_gpu=device->CreateUBO(total_bytes);
buf_cpu=(uint8 *)(buf_gpu->Map());
offset=new uint32_t[alloc_count];
}
else
{
}
}
2021-02-10 18:53:07 +08:00
}//namespace graph
}//namespace hgl