2023-04-25 11:43:15 +08:00
|
|
|
#ifndef HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
|
|
|
|
#define HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
|
2023-03-28 21:52:08 +08:00
|
|
|
|
|
|
|
#include<hgl/graph/VKArrayBuffer.h>
|
|
|
|
VK_NAMESPACE_BEGIN
|
2023-04-25 11:43:15 +08:00
|
|
|
template<typename T> class DynamicBufferAccess
|
2023-03-28 21:52:08 +08:00
|
|
|
{
|
|
|
|
uchar *pointer;
|
|
|
|
uchar *current;
|
|
|
|
|
2023-04-25 11:43:15 +08:00
|
|
|
uint align_size;
|
2023-03-28 21:52:08 +08:00
|
|
|
|
|
|
|
uint count;
|
|
|
|
uint index;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
2023-04-25 11:43:15 +08:00
|
|
|
DynamicBufferAccess()
|
2023-03-28 21:52:08 +08:00
|
|
|
{
|
|
|
|
Restart();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Restart()
|
|
|
|
{
|
|
|
|
pointer=nullptr;
|
|
|
|
current=nullptr;
|
2023-04-25 11:43:15 +08:00
|
|
|
align_size=0;
|
2023-03-28 21:52:08 +08:00
|
|
|
count=0;
|
|
|
|
index=0;
|
|
|
|
}
|
|
|
|
|
2023-04-25 11:43:15 +08:00
|
|
|
void Start(uchar *buf,const uint as,const uint c)
|
2023-03-28 21:52:08 +08:00
|
|
|
{
|
|
|
|
current=pointer=buf;
|
2023-04-25 11:43:15 +08:00
|
|
|
align_size=as;
|
2023-03-28 21:52:08 +08:00
|
|
|
count=c;
|
|
|
|
index=0;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend class GPUArrayBuffer;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
const uint GetCount()const{return count;}
|
|
|
|
const uint GetCurrentIndex()const{return index;}
|
2023-04-25 11:43:15 +08:00
|
|
|
const uint GetOffsetBytes()const{return index*align_size;}
|
2023-03-28 21:52:08 +08:00
|
|
|
|
|
|
|
bool Write(uchar *src)
|
|
|
|
{
|
|
|
|
if(!src)return(false);
|
|
|
|
if(index>=count)return(false);
|
|
|
|
|
|
|
|
memcpy(current,src,sizeof(T));
|
2023-04-25 11:43:15 +08:00
|
|
|
current+=align_size;
|
2023-03-28 21:52:08 +08:00
|
|
|
++index;
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Write(uchar *src,const uint c)
|
|
|
|
{
|
|
|
|
if(!src)return(false);
|
|
|
|
if(c<=0)return(false);
|
|
|
|
if(index+c>count)return(false);
|
|
|
|
|
|
|
|
for(uint i=0;i<c;i++)
|
|
|
|
{
|
|
|
|
memcpy(current,src,sizeof(T));
|
2023-04-25 11:43:15 +08:00
|
|
|
current+=align_size;
|
2023-03-28 21:52:08 +08:00
|
|
|
src+=sizeof(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
index+=c;
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
2023-04-25 11:43:15 +08:00
|
|
|
};//template<typename T> class DynamicBufferAccess
|
2023-03-28 21:52:08 +08:00
|
|
|
VK_NAMESPACE_END
|
2023-04-25 11:43:15 +08:00
|
|
|
#endif//HGL_GRAPH_DYNAMIC_BUFFER_ACCESS_INCLUDE
|