From 7f8fbbd3a030feea1113fe4ef6cb56d78741e307 Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 12 Jun 2024 00:23:09 +0800 Subject: [PATCH] improved VKBufferMap and added newly IBMap/VABMap --- inc/hgl/graph/PrimitiveCreater.h | 166 +----------------- inc/hgl/graph/VKBufferMap.h | 70 ++++++-- inc/hgl/graph/VKIndexBuffer.h | 124 +++++++++----- inc/hgl/graph/VKVertexAttribBuffer.h | 199 ++++++++++++++++++---- src/SceneGraph/CMakeLists.txt | 1 - src/SceneGraph/InlineGeometry.cpp | 76 ++++----- src/SceneGraph/PrimitiveCreater.cpp | 16 +- src/SceneGraph/Vulkan/VKBufferMap.cpp | 63 ------- src/SceneGraph/Vulkan/VKPrimitiveData.cpp | 12 +- src/SceneGraph/Vulkan/VKPrimitiveData.h | 2 +- 10 files changed, 364 insertions(+), 365 deletions(-) delete mode 100644 src/SceneGraph/Vulkan/VKBufferMap.cpp diff --git a/inc/hgl/graph/PrimitiveCreater.h b/inc/hgl/graph/PrimitiveCreater.h index 145a9587..55874085 100644 --- a/inc/hgl/graph/PrimitiveCreater.h +++ b/inc/hgl/graph/PrimitiveCreater.h @@ -3,6 +3,7 @@ #include #include #include +#include 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 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 class VABRawMap - -typedef VABRawMap VABMapI8, VABMapByte; -typedef VABRawMap VABMapI16, VABMapShort; -typedef VABRawMap VABMapI32, VABMapInt; -typedef VABRawMap VABMapU8, VABMapUByte; -typedef VABRawMap VABMapU16, VABMapUShort; -typedef VABRawMap VABMapU32, VABMapUInt; -typedef VABRawMap VABMapFloat; -typedef VABRawMap VABMapDouble; - -/** -* 顶点属性缓冲区数据访问映射 -*/ -template 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 class VABMap - -typedef VABMap VABMap1i8 ,VABMap1b; -typedef VABMap VABMap1i16,VABMap1s; -typedef VABMap VABMap1i32,VABMap1i; -typedef VABMap VABMap1u8 ,VABMap1ub; -typedef VABMap VABMap1u16,VABMap1us; -typedef VABMap VABMap1u32,VABMap1ui; -typedef VABMap VABMap1f; -typedef VABMap VABMap1d; - -typedef VABMap VABMap2i8 ,VABMap2b; -typedef VABMap VABMap2i16,VABMap2s; -typedef VABMap VABMap2i32,VABMap2i; -typedef VABMap VABMap2u8 ,VABMap2ub; -typedef VABMap VABMap2u16,VABMap2us; -typedef VABMap VABMap2u32,VABMap2ui; -typedef VABMap VABMap2f; -typedef VABMap VABMap2d; - -typedef VABMap VABMap3i32,VABMap3i; -typedef VABMap VABMap3u32,VABMap3ui; -typedef VABMap VABMap3f; -typedef VABMap VABMap3d; - -typedef VABMap VABMap4i8 ,VABMap4b; -typedef VABMap VABMap4i16,VABMap4s; -typedef VABMap VABMap4i32,VABMap4i; -typedef VABMap VABMap4u8, VABMap4ub; -typedef VABMap VABMap4u16,VABMap4us; -typedef VABMap VABMap4u32,VABMap4ui; -typedef VABMap VABMap4f; -typedef VABMap VABMap4d; - -/** -* 索引缓冲区数据访问映射 -*/ -template 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 class IBMap - -using IBMapU8 =IBMap; -using IBMapU16=IBMap; -using IBMapU32=IBMap; VK_NAMESPACE_END diff --git a/inc/hgl/graph/VKBufferMap.h b/inc/hgl/graph/VKBufferMap.h index cf3a567b..63c90c79 100644 --- a/inc/hgl/graph/VKBufferMap.h +++ b/inc/hgl/graph/VKBufferMap.h @@ -4,29 +4,75 @@ #include VK_NAMESPACE_BEGIN -class VKBufferMap +template 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 diff --git a/inc/hgl/graph/VKIndexBuffer.h b/inc/hgl/graph/VKIndexBuffer.h index 0a143c1d..bb99dcb6 100644 --- a/inc/hgl/graph/VKIndexBuffer.h +++ b/inc/hgl/graph/VKIndexBuffer.h @@ -1,50 +1,98 @@ -#ifndef HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE -#define HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE +#pragma once #include +#include -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 +{ +public: + + using VKBufferMap::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::Set(ib,index_offset,ib->GetStride(),count); + } +};//class IBMap + +/** +* 索引缓冲区数据访问映射 +*/ +template 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 class IBTypeMap + +using IBMapU8 =IBTypeMap; +using IBMapU16=IBTypeMap; +using IBMapU32=IBTypeMap; + +VK_NAMESPACE_END diff --git a/inc/hgl/graph/VKVertexAttribBuffer.h b/inc/hgl/graph/VKVertexAttribBuffer.h index 9ab4c4bd..f7071d21 100644 --- a/inc/hgl/graph/VKVertexAttribBuffer.h +++ b/inc/hgl/graph/VKVertexAttribBuffer.h @@ -1,50 +1,179 @@ -#ifndef HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE -#define HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE +#pragma once #include +#include -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 +{ +public: + + using VKBufferMap::VKBufferMap; + virtual ~VABMap()=default; + + const VkFormat GetFormat()const { return buffer->GetFormat(); } + + void Set(VAB *vab,const VkDeviceSize off,const uint32_t count) + { + VKBufferMap::Set(vab,off,vab->GetStride(),count); + } +};//class VABMap + +/** +* 顶点属性缓冲区原生数据访问映射 +*/ +template 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 class VABRawMap + +typedef VABRawMap VABMapI8, VABMapByte; +typedef VABRawMap VABMapI16, VABMapShort; +typedef VABRawMap VABMapI32, VABMapInt; +typedef VABRawMap VABMapU8, VABMapUByte; +typedef VABRawMap VABMapU16, VABMapUShort; +typedef VABRawMap VABMapU32, VABMapUInt; +typedef VABRawMap VABMapFloat; +typedef VABRawMap VABMapDouble; + +/** +* 顶点属性缓冲区数据访问映射 +*/ +template 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 class VABFormatMap - ~VertexAttribBuffer()=default; +typedef VABFormatMap VABMap1i8 ,VABMap1b; +typedef VABFormatMap VABMap1i16,VABMap1s; +typedef VABFormatMap VABMap1i32,VABMap1i; +typedef VABFormatMap VABMap1u8 ,VABMap1ub; +typedef VABFormatMap VABMap1u16,VABMap1us; +typedef VABFormatMap VABMap1u32,VABMap1ui; +typedef VABFormatMap VABMap1f; +typedef VABFormatMap VABMap1d; - const VkFormat GetFormat()const { return format; } - const uint32_t GetStride()const { return stride; } - const uint32_t GetCount ()const { return count; } +typedef VABFormatMap VABMap2i8 ,VABMap2b; +typedef VABFormatMap VABMap2i16,VABMap2s; +typedef VABFormatMap VABMap2i32,VABMap2i; +typedef VABFormatMap VABMap2u8 ,VABMap2ub; +typedef VABFormatMap VABMap2u16,VABMap2us; +typedef VABFormatMap VABMap2u32,VABMap2ui; +typedef VABFormatMap VABMap2f; +typedef VABFormatMap VABMap2d; - const VkDeviceSize GetTotalBytes()const { return stride*count; } - - public: +typedef VABFormatMap VABMap3i32,VABMap3i; +typedef VABFormatMap VABMap3u32,VABMap3ui; +typedef VABFormatMap VABMap3f; +typedef VABFormatMap 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 VABMap4i8 ,VABMap4b; +typedef VABFormatMap VABMap4i16,VABMap4s; +typedef VABFormatMap VABMap4i32,VABMap4i; +typedef VABFormatMap VABMap4u8, VABMap4ub; +typedef VABFormatMap VABMap4u16,VABMap4us; +typedef VABFormatMap VABMap4u32,VABMap4ui; +typedef VABFormatMap VABMap4f; +typedef VABFormatMap VABMap4d; - using VAB=VertexAttribBuffer; - }//namespace graph -}//namespace hgl -#endif//HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE +VK_NAMESPACE_END diff --git a/src/SceneGraph/CMakeLists.txt b/src/SceneGraph/CMakeLists.txt index 74e04b00..5f2319e1 100644 --- a/src/SceneGraph/CMakeLists.txt +++ b/src/SceneGraph/CMakeLists.txt @@ -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 ) diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp index dce02482..8e11b191 100644 --- a/src/SceneGraph/InlineGeometry.cpp +++ b/src/SceneGraph/InlineGeometry.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 void CreateSphereIndices(PrimitiveCreater *pc,uint numberParallels,const uint numberSlices) { - IBMap ib_map(pc); + IBTypeMap 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 void CreateTorusIndices(PrimitiveCreater *pc,uint numberSlices,uint numberStacks) { - IBMap ib_map(pc); + IBTypeMap 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 void CreateCylinderIndices(PrimitiveCreater *pc,const uint numberSlices) { - IBMap ib_map(pc); + IBTypeMap 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 void CreateConeIndices(PrimitiveCreater *pc,const uint numberSlices,const uint numberStacks) { - IBMap ib_map(pc); + IBTypeMap 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()) { diff --git a/src/SceneGraph/PrimitiveCreater.cpp b/src/SceneGraph/PrimitiveCreater.cpp index 08ff14bf..a86917a7 100644 --- a/src/SceneGraph/PrimitiveCreater.cpp +++ b/src/SceneGraph/PrimitiveCreater.cpp @@ -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;iGetVertexAttribCount();i++) + for(uint32_t i=0;iGetVertexAttribCount();i++) vab_map_list[i].Clear(); ibo_map.Clear(); diff --git a/src/SceneGraph/Vulkan/VKBufferMap.cpp b/src/SceneGraph/Vulkan/VKBufferMap.cpp deleted file mode 100644 index a1b8e439..00000000 --- a/src/SceneGraph/Vulkan/VKBufferMap.cpp +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include - -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 diff --git a/src/SceneGraph/Vulkan/VKPrimitiveData.cpp b/src/SceneGraph/Vulkan/VKPrimitiveData.cpp index c0e401b6..321bd2a5 100644 --- a/src/SceneGraph/Vulkan/VKPrimitiveData.cpp +++ b/src/SceneGraph/Vulkan/VKPrimitiveData.cpp @@ -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); diff --git a/src/SceneGraph/Vulkan/VKPrimitiveData.h b/src/SceneGraph/Vulkan/VKPrimitiveData.h index b9f91c26..e7e059f8 100644 --- a/src/SceneGraph/Vulkan/VKPrimitiveData.h +++ b/src/SceneGraph/Vulkan/VKPrimitiveData.h @@ -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);