improved VKBufferMap and added newly IBMap/VABMap
This commit is contained in:
parent
cd4733a491
commit
7f8fbbd3a0
@ -3,6 +3,7 @@
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
@ -24,17 +25,17 @@ protected:
|
||||
|
||||
uint32_t vertices_number; ///<顶点数量
|
||||
|
||||
VKBufferMap * vab_map_list;
|
||||
VABMap * vab_map_list;
|
||||
|
||||
uint32_t index_number; ///<索引数量
|
||||
IndexType index_type; ///<索引类型
|
||||
IndexBuffer * ibo; ///<索引缓冲区
|
||||
|
||||
VKBufferMap ibo_map;
|
||||
IBMap ibo_map;
|
||||
|
||||
protected:
|
||||
|
||||
const int GetVABIndex (const AnsiString &name,const VkFormat &format); ///<取得顶点属性索引
|
||||
const int GetVABIndex (const AnsiString &name); ///<取得顶点属性索引
|
||||
|
||||
public:
|
||||
|
||||
@ -59,7 +60,7 @@ public: //顶点缓冲区
|
||||
|
||||
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||
|
||||
VKBufferMap * MapVAB (const AnsiString &name,const VkFormat &format);
|
||||
VABMap * MapVAB (const AnsiString &name);
|
||||
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data); ///<直接写入顶点属性数据
|
||||
|
||||
@ -68,7 +69,7 @@ public: //索引缓冲区
|
||||
const IndexType GetIndexType()const{return index_type;} ///<取得索引类型
|
||||
const uint32_t GetIndexCount()const{return index_number;} ///<取得索引数量
|
||||
|
||||
VKBufferMap * MapIBO();
|
||||
IBMap * MapIBO();
|
||||
|
||||
bool WriteIBO(const void *data,const uint32_t count);
|
||||
|
||||
@ -79,159 +80,4 @@ public: //创建可渲染对象
|
||||
|
||||
Primitive * Create(); ///<创建一个可渲染对象,并清除创建器数据
|
||||
};//class PrimitiveCreater
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区原生数据访问映射
|
||||
*/
|
||||
template<typename T> class VABRawMap
|
||||
{
|
||||
VKBufferMap *buf_map;
|
||||
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABRawMap(PrimitiveCreater *pc,const VkFormat &format,const AnsiString &name)
|
||||
{
|
||||
buf_map=pc->MapVAB(name,format);
|
||||
|
||||
if(buf_map)
|
||||
map_ptr=(T *)(buf_map->Map());
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
~VABRawMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
buf_map->Unmap();
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return buf_map?buf_map->IsValid():false; }
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class VABRawMap
|
||||
|
||||
typedef VABRawMap<int8> VABMapI8, VABMapByte;
|
||||
typedef VABRawMap<int16> VABMapI16, VABMapShort;
|
||||
typedef VABRawMap<int32> VABMapI32, VABMapInt;
|
||||
typedef VABRawMap<uint8> VABMapU8, VABMapUByte;
|
||||
typedef VABRawMap<uint16> VABMapU16, VABMapUShort;
|
||||
typedef VABRawMap<uint32> VABMapU32, VABMapUInt;
|
||||
typedef VABRawMap<float> VABMapFloat;
|
||||
typedef VABRawMap<double> VABMapDouble;
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> class VABMap
|
||||
{
|
||||
VKBufferMap *buf_map;
|
||||
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABMap(PrimitiveCreater *pc,const AnsiString &name)
|
||||
{
|
||||
buf_map=pc->MapVAB(name,T::GetVulkanFormat());
|
||||
|
||||
if(buf_map)
|
||||
{
|
||||
map_ptr=T::Create(buf_map->GetSize(),buf_map->Map());
|
||||
map_ptr->Begin();
|
||||
}
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
~VABMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
{
|
||||
buf_map->Unmap();
|
||||
delete map_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return map_ptr; }
|
||||
|
||||
void Restart()
|
||||
{
|
||||
if(map_ptr)
|
||||
map_ptr->Begin();
|
||||
}
|
||||
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class VABMap
|
||||
|
||||
typedef VABMap<VB1i8> VABMap1i8 ,VABMap1b;
|
||||
typedef VABMap<VB1i16> VABMap1i16,VABMap1s;
|
||||
typedef VABMap<VB1i32> VABMap1i32,VABMap1i;
|
||||
typedef VABMap<VB1u8> VABMap1u8 ,VABMap1ub;
|
||||
typedef VABMap<VB1u16> VABMap1u16,VABMap1us;
|
||||
typedef VABMap<VB1u32> VABMap1u32,VABMap1ui;
|
||||
typedef VABMap<VB1f> VABMap1f;
|
||||
typedef VABMap<VB1d> VABMap1d;
|
||||
|
||||
typedef VABMap<VB2i8> VABMap2i8 ,VABMap2b;
|
||||
typedef VABMap<VB2i16> VABMap2i16,VABMap2s;
|
||||
typedef VABMap<VB2i32> VABMap2i32,VABMap2i;
|
||||
typedef VABMap<VB2u8> VABMap2u8 ,VABMap2ub;
|
||||
typedef VABMap<VB2u16> VABMap2u16,VABMap2us;
|
||||
typedef VABMap<VB2u32> VABMap2u32,VABMap2ui;
|
||||
typedef VABMap<VB2f> VABMap2f;
|
||||
typedef VABMap<VB2d> VABMap2d;
|
||||
|
||||
typedef VABMap<VB3i32> VABMap3i32,VABMap3i;
|
||||
typedef VABMap<VB3u32> VABMap3u32,VABMap3ui;
|
||||
typedef VABMap<VB3f> VABMap3f;
|
||||
typedef VABMap<VB3d> VABMap3d;
|
||||
|
||||
typedef VABMap<VB4i8> VABMap4i8 ,VABMap4b;
|
||||
typedef VABMap<VB4i16> VABMap4i16,VABMap4s;
|
||||
typedef VABMap<VB4i32> VABMap4i32,VABMap4i;
|
||||
typedef VABMap<VB4u8> VABMap4u8, VABMap4ub;
|
||||
typedef VABMap<VB4u16> VABMap4u16,VABMap4us;
|
||||
typedef VABMap<VB4u32> VABMap4u32,VABMap4ui;
|
||||
typedef VABMap<VB4f> VABMap4f;
|
||||
typedef VABMap<VB4d> VABMap4d;
|
||||
|
||||
/**
|
||||
* 索引缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> class IBMap
|
||||
{
|
||||
VKBufferMap *buf_map;
|
||||
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
IBMap(PrimitiveCreater *pc)
|
||||
{
|
||||
buf_map=pc->MapIBO();
|
||||
|
||||
if(buf_map)
|
||||
map_ptr=(T *)(buf_map->Map());
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
~IBMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
buf_map->Unmap();
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return map_ptr; }
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class IBMap
|
||||
|
||||
using IBMapU8 =IBMap<uint8>;
|
||||
using IBMapU16=IBMap<uint16>;
|
||||
using IBMapU32=IBMap<uint32>;
|
||||
VK_NAMESPACE_END
|
||||
|
@ -4,29 +4,75 @@
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VKBufferMap
|
||||
template<typename T> class VKBufferMap
|
||||
{
|
||||
protected:
|
||||
|
||||
DeviceBuffer *buffer;
|
||||
VkDeviceSize offset;
|
||||
VkDeviceSize size;
|
||||
T *buffer;
|
||||
int32_t offset;
|
||||
uint32_t stride;
|
||||
uint32_t count;
|
||||
|
||||
void *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VKBufferMap();
|
||||
VKBufferMap(DeviceBuffer *buf,VkDeviceSize off,VkDeviceSize s);
|
||||
~VKBufferMap();
|
||||
VKBufferMap()
|
||||
{
|
||||
buffer=nullptr;
|
||||
offset=0;
|
||||
stride=count=0;
|
||||
}
|
||||
|
||||
void Set(DeviceBuffer *buf_ptr,VkDeviceSize off,VkDeviceSize s);
|
||||
virtual ~VKBufferMap()
|
||||
{
|
||||
Unmap();
|
||||
}
|
||||
|
||||
void Set(T *buf,const int32_t off,const uint32_t s,const uint32_t c)
|
||||
{
|
||||
buffer=buf;
|
||||
offset=off;
|
||||
stride=s;
|
||||
count=c;
|
||||
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
const int32_t GetOffset ()const{ return offset;}
|
||||
const uint32_t GetStride ()const{ return stride;}
|
||||
const uint32_t GetCount ()const{ return count; }
|
||||
|
||||
const VkDeviceSize GetSize()const{ return size; }
|
||||
const bool IsValid()const{ return buffer; }
|
||||
void Clear();
|
||||
|
||||
void *Map();
|
||||
void Unmap();
|
||||
void Clear()
|
||||
{
|
||||
Unmap();
|
||||
|
||||
buffer=nullptr;
|
||||
offset=0;
|
||||
stride=count=0;
|
||||
}
|
||||
|
||||
void *Map()
|
||||
{
|
||||
if(map_ptr)
|
||||
return(map_ptr);
|
||||
|
||||
if(!buffer)
|
||||
return(nullptr);
|
||||
|
||||
map_ptr=buffer->Map(offset,count);
|
||||
return map_ptr;
|
||||
}
|
||||
|
||||
void Unmap()
|
||||
{
|
||||
if(buffer&&map_ptr)
|
||||
{
|
||||
buffer->Unmap();
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
}
|
||||
};//class VKBufferMap
|
||||
VK_NAMESPACE_END
|
||||
|
@ -1,50 +1,98 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
|
||||
namespace hgl
|
||||
VK_NAMESPACE_BEGIN
|
||||
class IndexBuffer:public DeviceBuffer
|
||||
{
|
||||
namespace graph
|
||||
IndexType index_type;
|
||||
uint stride;
|
||||
uint32_t count;
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
IndexBuffer(VkDevice d,const DeviceBufferData &vb,IndexType it,uint32_t _count):DeviceBuffer(d,vb)
|
||||
{
|
||||
class IndexBuffer:public DeviceBuffer
|
||||
{
|
||||
IndexType index_type;
|
||||
uint stride;
|
||||
uint32_t count;
|
||||
index_type=it;
|
||||
count=_count;
|
||||
|
||||
private:
|
||||
if(index_type==IndexType::U16)stride=2;else
|
||||
if(index_type==IndexType::U32)stride=4;else
|
||||
if(index_type==IndexType::U8)stride=1;else
|
||||
stride=0;
|
||||
}
|
||||
|
||||
friend class GPUDevice;
|
||||
public:
|
||||
|
||||
IndexBuffer(VkDevice d,const DeviceBufferData &vb,IndexType it,uint32_t _count):DeviceBuffer(d,vb)
|
||||
{
|
||||
index_type=it;
|
||||
count=_count;
|
||||
~IndexBuffer()=default;
|
||||
|
||||
if(index_type==IndexType::U16)stride=2;else
|
||||
if(index_type==IndexType::U32)stride=4;else
|
||||
if(index_type==IndexType::U8)stride=1;else
|
||||
stride=0;
|
||||
}
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint GetStride ()const{return stride;}
|
||||
const uint32 GetCount ()const{return count;}
|
||||
|
||||
public:
|
||||
public:
|
||||
|
||||
~IndexBuffer()=default;
|
||||
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint GetStride ()const{return stride;}
|
||||
const uint32 GetCount ()const{return count;}
|
||||
|
||||
public:
|
||||
|
||||
void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride); }
|
||||
void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);}
|
||||
void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride); }
|
||||
void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) override {return DeviceBuffer::Write(ptr,start*stride,size*stride);}
|
||||
bool Write (const void *ptr,uint32_t size) override {return DeviceBuffer::Write(ptr,0,size*stride);}
|
||||
};//class IndexBuffer:public DeviceBuffer
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) override {return DeviceBuffer::Write(ptr,start*stride,size*stride);}
|
||||
bool Write (const void *ptr,uint32_t size) override {return DeviceBuffer::Write(ptr,0,size*stride);}
|
||||
};//class IndexBuffer:public DeviceBuffer
|
||||
|
||||
class IBMap:public VKBufferMap<IndexBuffer>
|
||||
{
|
||||
public:
|
||||
|
||||
using VKBufferMap<IndexBuffer>::VKBufferMap;
|
||||
virtual ~IBMap()=default;
|
||||
|
||||
const IndexType GetType()const{return buffer->GetType();}
|
||||
|
||||
void Set(IndexBuffer *ib,const int32_t index_offset,const uint32_t count)
|
||||
{
|
||||
VKBufferMap<IndexBuffer>::Set(ib,index_offset,ib->GetStride(),count);
|
||||
}
|
||||
};//class IBMap
|
||||
|
||||
/**
|
||||
* 索引缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> class IBTypeMap
|
||||
{
|
||||
IBMap *ib_map;
|
||||
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
IBTypeMap(IBMap *ibm)
|
||||
{
|
||||
ib_map=ibm;
|
||||
|
||||
if(ib_map&&ib_map->GetStride()==sizeof(T))
|
||||
map_ptr=(T *)(ib_map->Map());
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
~IBTypeMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
ib_map->Unmap();
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return map_ptr; }
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class IBTypeMap
|
||||
|
||||
using IBMapU8 =IBTypeMap<uint8>;
|
||||
using IBMapU16=IBTypeMap<uint16>;
|
||||
using IBMapU32=IBTypeMap<uint32>;
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -1,50 +1,179 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
|
||||
namespace hgl
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VertexAttribBuffer:public DeviceBuffer
|
||||
{
|
||||
namespace graph
|
||||
VkFormat format; ///<数据格式
|
||||
uint32_t stride; ///<单个数据字节数
|
||||
uint32_t count; ///<数据数量
|
||||
|
||||
private:
|
||||
|
||||
friend class GPUDevice;
|
||||
|
||||
VertexAttribBuffer(VkDevice d,const DeviceBufferData &vb,VkFormat fmt,uint32_t _stride,uint32_t _count):DeviceBuffer(d,vb)
|
||||
{
|
||||
class VertexAttribBuffer:public DeviceBuffer
|
||||
format=fmt;
|
||||
stride=_stride;
|
||||
count=_count;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~VertexAttribBuffer()=default;
|
||||
|
||||
const VkFormat GetFormat()const { return format; }
|
||||
const uint32_t GetStride()const { return stride; }
|
||||
const uint32_t GetCount ()const { return count; }
|
||||
|
||||
const VkDeviceSize GetTotalBytes()const { return stride*count; }
|
||||
|
||||
public:
|
||||
|
||||
void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) override {return DeviceBuffer::Write(ptr,start*stride,size*stride);}
|
||||
bool Write (const void *ptr,uint32_t size) override {return DeviceBuffer::Write(ptr,0,size*stride);}
|
||||
};//class VertexAttribBuffer:public DeviceBuffer
|
||||
|
||||
using VAB=VertexAttribBuffer;
|
||||
|
||||
class VABMap:public VKBufferMap<VAB>
|
||||
{
|
||||
public:
|
||||
|
||||
using VKBufferMap<VAB>::VKBufferMap;
|
||||
virtual ~VABMap()=default;
|
||||
|
||||
const VkFormat GetFormat()const { return buffer->GetFormat(); }
|
||||
|
||||
void Set(VAB *vab,const VkDeviceSize off,const uint32_t count)
|
||||
{
|
||||
VKBufferMap<VAB>::Set(vab,off,vab->GetStride(),count);
|
||||
}
|
||||
};//class VABMap
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区原生数据访问映射
|
||||
*/
|
||||
template<typename T> class VABRawMap
|
||||
{
|
||||
VABMap *vab_map;
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABRawMap(VABMap *map,const VkFormat check_format=VK_FORMAT_UNDEFINED)
|
||||
{
|
||||
vab_map=map;
|
||||
map_ptr=nullptr;
|
||||
|
||||
if(vab_map)
|
||||
if(check_format==VK_FORMAT_UNDEFINED
|
||||
||check_format==vab_map->GetFormat())
|
||||
map_ptr=(T *)(vab_map->Map());
|
||||
}
|
||||
|
||||
~VABRawMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
vab_map->Unmap();
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return vab_map?vab_map->IsValid():false; }
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class VABRawMap
|
||||
|
||||
typedef VABRawMap<int8> VABMapI8, VABMapByte;
|
||||
typedef VABRawMap<int16> VABMapI16, VABMapShort;
|
||||
typedef VABRawMap<int32> VABMapI32, VABMapInt;
|
||||
typedef VABRawMap<uint8> VABMapU8, VABMapUByte;
|
||||
typedef VABRawMap<uint16> VABMapU16, VABMapUShort;
|
||||
typedef VABRawMap<uint32> VABMapU32, VABMapUInt;
|
||||
typedef VABRawMap<float> VABMapFloat;
|
||||
typedef VABRawMap<double> VABMapDouble;
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> class VABFormatMap
|
||||
{
|
||||
VABMap *vab_map;
|
||||
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABFormatMap(VABMap *map)
|
||||
{
|
||||
vab_map=map;
|
||||
|
||||
if(vab_map&&vab_map->GetFormat()==T::GetVulkanFormat())
|
||||
{
|
||||
VkFormat format; ///<数据格式
|
||||
uint32_t stride; ///<单个数据字节数
|
||||
uint32_t count; ///<数据数量
|
||||
map_ptr=T::Create(vab_map->GetCount(),vab_map->Map());
|
||||
map_ptr->Begin();
|
||||
}
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
private:
|
||||
~VABFormatMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
{
|
||||
vab_map->Unmap();
|
||||
delete map_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
friend class GPUDevice;
|
||||
const bool IsValid()const{ return map_ptr; }
|
||||
|
||||
VertexAttribBuffer(VkDevice d,const DeviceBufferData &vb,VkFormat fmt,uint32_t _stride,uint32_t _count):DeviceBuffer(d,vb)
|
||||
{
|
||||
format=fmt;
|
||||
stride=_stride;
|
||||
count=_count;
|
||||
}
|
||||
void Restart()
|
||||
{
|
||||
if(map_ptr)
|
||||
vab_map->Begin();
|
||||
}
|
||||
|
||||
public:
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class VABFormatMap
|
||||
|
||||
~VertexAttribBuffer()=default;
|
||||
typedef VABFormatMap<VB1i8> VABMap1i8 ,VABMap1b;
|
||||
typedef VABFormatMap<VB1i16> VABMap1i16,VABMap1s;
|
||||
typedef VABFormatMap<VB1i32> VABMap1i32,VABMap1i;
|
||||
typedef VABFormatMap<VB1u8> VABMap1u8 ,VABMap1ub;
|
||||
typedef VABFormatMap<VB1u16> VABMap1u16,VABMap1us;
|
||||
typedef VABFormatMap<VB1u32> VABMap1u32,VABMap1ui;
|
||||
typedef VABFormatMap<VB1f> VABMap1f;
|
||||
typedef VABFormatMap<VB1d> VABMap1d;
|
||||
|
||||
const VkFormat GetFormat()const { return format; }
|
||||
const uint32_t GetStride()const { return stride; }
|
||||
const uint32_t GetCount ()const { return count; }
|
||||
typedef VABFormatMap<VB2i8> VABMap2i8 ,VABMap2b;
|
||||
typedef VABFormatMap<VB2i16> VABMap2i16,VABMap2s;
|
||||
typedef VABFormatMap<VB2i32> VABMap2i32,VABMap2i;
|
||||
typedef VABFormatMap<VB2u8> VABMap2u8 ,VABMap2ub;
|
||||
typedef VABFormatMap<VB2u16> VABMap2u16,VABMap2us;
|
||||
typedef VABFormatMap<VB2u32> VABMap2u32,VABMap2ui;
|
||||
typedef VABFormatMap<VB2f> VABMap2f;
|
||||
typedef VABFormatMap<VB2d> VABMap2d;
|
||||
|
||||
const VkDeviceSize GetTotalBytes()const { return stride*count; }
|
||||
|
||||
public:
|
||||
typedef VABFormatMap<VB3i32> VABMap3i32,VABMap3i;
|
||||
typedef VABFormatMap<VB3u32> VABMap3u32,VABMap3ui;
|
||||
typedef VABFormatMap<VB3f> VABMap3f;
|
||||
typedef VABFormatMap<VB3d> VABMap3d;
|
||||
|
||||
void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) override {return DeviceBuffer::Write(ptr,start*stride,size*stride);}
|
||||
bool Write (const void *ptr,uint32_t size) override {return DeviceBuffer::Write(ptr,0,size*stride);}
|
||||
};//class VertexAttribBuffer:public DeviceBuffer
|
||||
typedef VABFormatMap<VB4i8> VABMap4i8 ,VABMap4b;
|
||||
typedef VABFormatMap<VB4i16> VABMap4i16,VABMap4s;
|
||||
typedef VABFormatMap<VB4i32> VABMap4i32,VABMap4i;
|
||||
typedef VABFormatMap<VB4u8> VABMap4u8, VABMap4ub;
|
||||
typedef VABFormatMap<VB4u16> VABMap4u16,VABMap4us;
|
||||
typedef VABFormatMap<VB4u32> VABMap4u32,VABMap4ui;
|
||||
typedef VABFormatMap<VB4f> VABMap4f;
|
||||
typedef VABFormatMap<VB4d> VABMap4d;
|
||||
|
||||
using VAB=VertexAttribBuffer;
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
VK_NAMESPACE_END
|
||||
|
@ -125,7 +125,6 @@ SET(VK_MEMORY_SOURCE ${SG_INCLUDE_PATH}/VKMemory.h
|
||||
Vulkan/VKMemory.cpp
|
||||
Vulkan/VKMemoryAllocator.cpp
|
||||
Vulkan/VKBuffer.cpp
|
||||
Vulkan/VKBufferMap.cpp
|
||||
Vulkan/VKArrayBuffer.cpp
|
||||
)
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace hgl
|
||||
if(!pc->Init("Rectangle",4,0))
|
||||
return(nullptr);
|
||||
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
VABMap2f vertex(pc->MapVAB(VAN::Position));
|
||||
|
||||
if(!vertex.IsValid())
|
||||
return(nullptr);
|
||||
@ -48,7 +48,7 @@ namespace hgl
|
||||
if(!pc->Init("RoundRectangle",4,0))
|
||||
return(nullptr);
|
||||
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
VABMap2f vertex(pc->MapVAB(VAN::Position));
|
||||
|
||||
vertex->WriteRectFan(rci->scope);
|
||||
}
|
||||
@ -62,7 +62,7 @@ namespace hgl
|
||||
if(!pc->Init("RoundRectangle",rci->round_per*4,8))
|
||||
return(nullptr);
|
||||
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
VABMap2f vertex(pc->MapVAB(VAN::Position));
|
||||
|
||||
Vector2f *coord=new Vector2f[rci->round_per];
|
||||
|
||||
@ -133,8 +133,8 @@ namespace hgl
|
||||
|
||||
if(!pc->Init("Circle",vertex_count,0))return(nullptr);
|
||||
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
VABMap4f color(pc,VAN::Color);
|
||||
VABMap2f vertex(pc->MapVAB(VAN::Position));
|
||||
VABMap4f color(pc->MapVAB(VAN::Color));
|
||||
|
||||
if(!vertex.IsValid())
|
||||
return(nullptr);
|
||||
@ -169,7 +169,7 @@ namespace hgl
|
||||
if(!pc->Init("PlaneGrid",((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,0))
|
||||
return(nullptr);
|
||||
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
VABMap2f vertex(pc->MapVAB(VAN::Position));
|
||||
|
||||
if(!vertex.IsValid())
|
||||
return(nullptr);
|
||||
@ -192,7 +192,7 @@ namespace hgl
|
||||
Vector2f(left+col,bottom));
|
||||
}
|
||||
|
||||
VABMap1f lum(pc,VAN::Luminance);
|
||||
VABMap1f lum(pc->MapVAB(VAN::Luminance));
|
||||
|
||||
if(lum.IsValid())
|
||||
{
|
||||
@ -232,21 +232,21 @@ namespace hgl
|
||||
return(nullptr);
|
||||
|
||||
{
|
||||
VABMap3f normal(pc,VAN::Normal);
|
||||
VABMap3f normal(pc->MapVAB(VAN::Normal));
|
||||
|
||||
if(normal.IsValid())
|
||||
normal->RepeatWrite(xy_normal,4);
|
||||
}
|
||||
|
||||
{
|
||||
VABMap3f tangent(pc,VAN::Tangent);
|
||||
VABMap3f tangent(pc->MapVAB(VAN::Tangent));
|
||||
|
||||
if(tangent.IsValid())
|
||||
tangent->RepeatWrite(xy_tangent,4);
|
||||
}
|
||||
|
||||
{
|
||||
VABMap2f tex_coord(pc,VAN::TexCoord);
|
||||
VABMap2f tex_coord(pc->MapVAB(VAN::TexCoord));
|
||||
|
||||
if(tex_coord.IsValid())
|
||||
tex_coord->Write(xy_tex_coord,4);
|
||||
@ -332,7 +332,7 @@ namespace hgl
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
||||
|
||||
VABMap4f color(pc,VAN::Color);
|
||||
VABMap4f color(pc->MapVAB(VAN::Color));
|
||||
|
||||
if(color.IsValid())
|
||||
{
|
||||
@ -360,7 +360,7 @@ namespace hgl
|
||||
template<typename T>
|
||||
void CreateSphereIndices(PrimitiveCreater *pc,uint numberParallels,const uint numberSlices)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
IBTypeMap<T> ib_map(pc->MapIBO());
|
||||
T *tp=ib_map;
|
||||
|
||||
for (uint i = 0; i < numberParallels; i++)
|
||||
@ -473,10 +473,10 @@ namespace hgl
|
||||
if(!pc->Init("Sphere",numberVertices,numberIndices))
|
||||
return(nullptr);
|
||||
|
||||
VABMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
VABMapFloat vertex (pc->MapVAB(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->MapVAB(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->MapVAB(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->MapVAB(VAN::TexCoord),VF_V2F);
|
||||
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
@ -562,10 +562,10 @@ namespace hgl
|
||||
if(!pc->Init("Dome",numberVertices,numberIndices))
|
||||
return(nullptr);
|
||||
|
||||
VABMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
VABMapFloat vertex (pc->MapVAB(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->MapVAB(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->MapVAB(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->MapVAB(VAN::TexCoord),VF_V2F);
|
||||
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
@ -637,7 +637,7 @@ namespace hgl
|
||||
template<typename T>
|
||||
void CreateTorusIndices(PrimitiveCreater *pc,uint numberSlices,uint numberStacks)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
IBTypeMap<T> ib_map(pc->MapIBO());
|
||||
T *tp=ib_map;
|
||||
|
||||
// loop counters
|
||||
@ -710,10 +710,10 @@ namespace hgl
|
||||
if(!pc->Init("Torus",numberVertices,numberIndices))
|
||||
return(nullptr);
|
||||
|
||||
VABMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
VABMapFloat vertex (pc->MapVAB(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->MapVAB(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->MapVAB(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->MapVAB(VAN::TexCoord),VF_V2F);
|
||||
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
@ -788,7 +788,7 @@ namespace hgl
|
||||
template<typename T>
|
||||
void CreateCylinderIndices(PrimitiveCreater *pc,const uint numberSlices)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
IBTypeMap<T> ib_map(pc->MapIBO());
|
||||
T *tp=ib_map;
|
||||
uint i;
|
||||
|
||||
@ -852,10 +852,10 @@ namespace hgl
|
||||
if (cci->numberSlices < 3 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
||||
return nullptr;
|
||||
|
||||
VABMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
VABMapFloat vertex (pc->MapVAB(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->MapVAB(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->MapVAB(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->MapVAB(VAN::TexCoord),VF_V2F);
|
||||
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
@ -1025,7 +1025,7 @@ namespace hgl
|
||||
template<typename T>
|
||||
void CreateConeIndices(PrimitiveCreater *pc,const uint numberSlices,const uint numberStacks)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
IBTypeMap<T> ib_map(pc->MapIBO());
|
||||
T *tp=ib_map;
|
||||
|
||||
// Bottom
|
||||
@ -1082,10 +1082,10 @@ namespace hgl
|
||||
if (cci->numberSlices < 3 || cci->numberStacks < 1 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
||||
return nullptr;
|
||||
|
||||
VABMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
VABMapFloat vertex (pc->MapVAB(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->MapVAB(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->MapVAB(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->MapVAB(VAN::TexCoord),VF_V2F);
|
||||
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
@ -1204,8 +1204,8 @@ namespace hgl
|
||||
if(!pc->Init("Axis",6,0))
|
||||
return(nullptr);
|
||||
|
||||
VABMap3f vertex(pc,VAN::Position);
|
||||
VABMap4f color(pc,VAN::Color);
|
||||
VABMap3f vertex(pc->MapVAB(VAN::Position));
|
||||
VABMap4f color(pc->MapVAB(VAN::Color));
|
||||
|
||||
if(!vertex.IsValid()||!color.IsValid())
|
||||
return(nullptr);
|
||||
@ -1256,7 +1256,7 @@ namespace hgl
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
||||
|
||||
VABMap4f color(pc,VAN::Color);
|
||||
VABMap4f color(pc->MapVAB(VAN::Color));
|
||||
|
||||
if(color.IsValid())
|
||||
{
|
||||
|
@ -15,7 +15,7 @@ PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v)
|
||||
|
||||
prim_data =nullptr;
|
||||
|
||||
vab_map_list =new VKBufferMap[v->GetVertexAttribCount()];
|
||||
vab_map_list =new VABMap[v->GetVertexAttribCount()];
|
||||
|
||||
Clear();
|
||||
}
|
||||
@ -116,7 +116,7 @@ bool PrimitiveCreater::Init(const AnsiString &pname,const uint32_t vertex_count,
|
||||
return(true);
|
||||
}
|
||||
|
||||
const int PrimitiveCreater::GetVABIndex(const AnsiString &name,const VkFormat &acquire_format)
|
||||
const int PrimitiveCreater::GetVABIndex(const AnsiString &name)
|
||||
{
|
||||
if(!prim_data)return(-1);
|
||||
|
||||
@ -129,7 +129,7 @@ const int PrimitiveCreater::GetVABIndex(const AnsiString &name,const VkFormat &a
|
||||
|
||||
if(!vab)
|
||||
{
|
||||
vab=prim_data->InitVAB(vab_index,acquire_format,nullptr);
|
||||
vab=prim_data->InitVAB(vab_index,nullptr);
|
||||
|
||||
if(vab)
|
||||
vab_map_list[vab_index].Set(vab,
|
||||
@ -156,9 +156,9 @@ const int PrimitiveCreater::GetVABIndex(const AnsiString &name,const VkFormat &a
|
||||
return(vab_index);
|
||||
}
|
||||
|
||||
VKBufferMap *PrimitiveCreater::MapVAB(const AnsiString &name,const VkFormat &format)
|
||||
VABMap *PrimitiveCreater::MapVAB(const AnsiString &name)
|
||||
{
|
||||
const int vab_index=GetVABIndex(name,format);
|
||||
const int vab_index=GetVABIndex(name);
|
||||
|
||||
if(vab_index<0)return nullptr;
|
||||
|
||||
@ -169,7 +169,7 @@ bool PrimitiveCreater::WriteVAB(const AnsiString &name,const VkFormat &format, c
|
||||
{
|
||||
if(!prim_data)return(false);
|
||||
|
||||
const int vab_index=GetVABIndex(name,format);
|
||||
const int vab_index=GetVABIndex(name);
|
||||
|
||||
VAB *vab=prim_data->GetVAB(vab_index);
|
||||
|
||||
@ -179,7 +179,7 @@ bool PrimitiveCreater::WriteVAB(const AnsiString &name,const VkFormat &format, c
|
||||
return vab->Write(data,prim_data->GetVertexOffset(),vertices_number);
|
||||
}
|
||||
|
||||
VKBufferMap *PrimitiveCreater::MapIBO()
|
||||
IBMap *PrimitiveCreater::MapIBO()
|
||||
{
|
||||
if(!ibo)
|
||||
return(nullptr);
|
||||
@ -205,7 +205,7 @@ Primitive *PrimitiveCreater::Create()
|
||||
if(!prim_data)
|
||||
return(nullptr);
|
||||
|
||||
for(int i=0;i<vil->GetVertexAttribCount();i++)
|
||||
for(uint32_t i=0;i<vil->GetVertexAttribCount();i++)
|
||||
vab_map_list[i].Clear();
|
||||
|
||||
ibo_map.Clear();
|
||||
|
@ -1,63 +0,0 @@
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
void VKBufferMap::Set(DeviceBuffer *buf,VkDeviceSize off,VkDeviceSize s)
|
||||
{
|
||||
buffer=buf;
|
||||
offset=off;
|
||||
size=s;
|
||||
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
void VKBufferMap::Clear()
|
||||
{
|
||||
if(buffer&&map_ptr)
|
||||
buffer->Unmap();
|
||||
|
||||
buffer=nullptr;
|
||||
offset=0;
|
||||
size=0;
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
VKBufferMap::VKBufferMap()
|
||||
{
|
||||
Set(nullptr,0,0);
|
||||
}
|
||||
|
||||
VKBufferMap::VKBufferMap(DeviceBuffer *buf,VkDeviceSize off,VkDeviceSize s)
|
||||
{
|
||||
Set(buf,off,s);
|
||||
}
|
||||
|
||||
VKBufferMap::~VKBufferMap()
|
||||
{
|
||||
if(buffer&&map_ptr)
|
||||
buffer->Unmap();
|
||||
}
|
||||
|
||||
void *VKBufferMap::Map()
|
||||
{
|
||||
if(map_ptr)
|
||||
return(map_ptr);
|
||||
|
||||
if(!buffer)
|
||||
return(nullptr);
|
||||
|
||||
map_ptr=buffer->Map(offset,size);
|
||||
return map_ptr;
|
||||
}
|
||||
|
||||
void VKBufferMap::Unmap()
|
||||
{
|
||||
if(buffer&&map_ptr)
|
||||
{
|
||||
buffer->Unmap();
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
@ -97,7 +97,7 @@ namespace
|
||||
return(ibo);
|
||||
}
|
||||
|
||||
VAB *InitVAB(const int vab_index,const VkFormat &format,const void *data)
|
||||
VAB *InitVAB(const int vab_index,const void *data)
|
||||
{
|
||||
if(!device)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
@ -109,12 +109,9 @@ namespace
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(nullptr);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
{
|
||||
vab_list[vab_index]=device->CreateVAB(format,vertex_count,data);
|
||||
vab_list[vab_index]=device->CreateVAB(vif->format,vertex_count,data);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
@ -184,7 +181,7 @@ namespace
|
||||
return ibo;
|
||||
}
|
||||
|
||||
VAB *InitVAB(const int vab_index,const VkFormat &format,const void *data)
|
||||
VAB *InitVAB(const int vab_index,const void *data)
|
||||
{
|
||||
if(!vdm)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
@ -196,9 +193,6 @@ namespace
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(nullptr);
|
||||
|
||||
if (!vab_list[vab_index])
|
||||
{
|
||||
vab_list[vab_index]=vdm->GetVAB(vab_index);
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
public:
|
||||
|
||||
virtual IndexBuffer * InitIBO(const uint32_t index_count,IndexType it)=0;
|
||||
virtual VAB * InitVAB(const int vab_index,const VkFormat &format,const void *data)=0;
|
||||
virtual VAB * InitVAB(const int vab_index,const void *data)=0;
|
||||
};//class PrimitiveData
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const uint32_t vc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user