diff --git a/example/Basic/auto_instance.cpp b/example/Basic/auto_instance.cpp index 86a33b99..5aa07fe6 100644 --- a/example/Basic/auto_instance.cpp +++ b/example/Basic/auto_instance.cpp @@ -24,7 +24,8 @@ constexpr float position_data[VERTEX_COUNT*2]= }; constexpr uint8 color_data[VERTEX_COUNT][4]= -{ {255,0,0,255}, +{ + {255,0,0,255}, {0,255,0,255}, {0,0,255,255} }; diff --git a/inc/hgl/graph/PrimitiveCreater.h b/inc/hgl/graph/PrimitiveCreater.h index 7f5780c8..73b5d325 100644 --- a/inc/hgl/graph/PrimitiveCreater.h +++ b/inc/hgl/graph/PrimitiveCreater.h @@ -15,14 +15,6 @@ namespace hgl */ class PrimitiveCreater { - struct PrimitiveVertexBuffer - { - VBO * vbo; - void * map_data; - };//struct PrimitiveVertexBuffer - - using PVBMap=ObjectMap; - protected: GPUDevice *device; @@ -40,11 +32,11 @@ namespace hgl IndexBuffer * ibo; void * ibo_map; - PVBMap vbo_map; + VBOAccessMap vbo_map; protected: - PrimitiveVertexBuffer *AcquirePVB(const AnsiString &,const void *data); ///<请求一个顶点属性数据区 + bool AcquirePVB(VBOAccessData *,const AnsiString &,const void *data); ///<请求一个顶点属性数据区 void ClearAllData(); @@ -64,12 +56,11 @@ namespace hgl if(format!=T::GetVulkanFormat()) return(nullptr); - PrimitiveVertexBuffer *pvb=this->AcquirePVB(name,nullptr); - - if(!pvb) + VBOAccessData vad; + if(!this->AcquirePVB(&vad,name,nullptr)) return(nullptr); - T *access=T::Create(vertices_number,pvb->map_data); + T *access=T::Create(vertices_number,vad.map_ptr); access->Begin(); diff --git a/inc/hgl/graph/VKVertexAttribBuffer.h b/inc/hgl/graph/VKVertexAttribBuffer.h index 7e320381..e57bddc3 100644 --- a/inc/hgl/graph/VKVertexAttribBuffer.h +++ b/inc/hgl/graph/VKVertexAttribBuffer.h @@ -43,6 +43,8 @@ namespace hgl VkDeviceSize offset; VkDeviceSize size; + void *map_ptr; + public: CompOperatorMemcmp(const VBOAccessData &); diff --git a/src/SceneGraph/InlineGeometry.cpp b/src/SceneGraph/InlineGeometry.cpp index 644c679a..cb55e2e9 100644 --- a/src/SceneGraph/InlineGeometry.cpp +++ b/src/SceneGraph/InlineGeometry.cpp @@ -223,7 +223,7 @@ namespace hgl if(!rc.Init(4,8)) return(nullptr); - + rc.WriteVBO(VAN::Position,xy_vertices,sizeof(xy_vertices)); { diff --git a/src/SceneGraph/PrimitiveCreater.cpp b/src/SceneGraph/PrimitiveCreater.cpp index 6676523e..12bd6617 100644 --- a/src/SceneGraph/PrimitiveCreater.cpp +++ b/src/SceneGraph/PrimitiveCreater.cpp @@ -58,7 +58,6 @@ namespace hgl if(vdm) { - } else { @@ -69,24 +68,10 @@ namespace hgl if(!IsIndexType(it)) return(false); } - else if(it==IndexType::U8) - { - if(!phy_device->SupportU8Index()||vertex_count>0xFF) - return(false); - } - else if(it==IndexType::U16) - { - if(vertex_count>0xFFFF) - return(false); - } - else if(it==IndexType::U32) - { - if(!phy_device->SupportU32Index()) - return(false); - } else { - return(false); + if(!device->CheckIndexType(it,vertex_count)) + return(false); } ibo=device->CreateIBO(it,index_count); @@ -100,33 +85,30 @@ namespace hgl return(true); } - PrimitiveCreater::PrimitiveVertexBuffer *PrimitiveCreater::AcquirePVB(const AnsiString &name,const void *data) + bool PrimitiveCreater::AcquirePVB(VBOAccessData *vad,const AnsiString &name,const void *data) { - if(!vil)return(nullptr); - if(name.IsEmpty())return(nullptr); + if(!vad)return(false); + if(!vil)return(false); + if(name.IsEmpty())return(false); const VertexInputFormat *vif=vil->GetConfig(name); if(!vif) - return(nullptr); + return(false); - PrimitiveVertexBuffer *pvb; + if(vbo_map.Get(name,*vad)) + return true; - if(vbo_map.Get(name,pvb)) - return pvb; - - pvb=new PrimitiveVertexBuffer; - - pvb->vbo =db->CreateVBO(vif->format,vertices_number,data); + vad->vbo =db->CreateVBO(vif->format,vertices_number,data); if(!data) - pvb->map_data=pvb->vbo->Map(); + vad->map_ptr=vad->vbo->Map(); else - pvb->map_data=nullptr; + vad->map_ptr=nullptr; - vbo_map.Add(name,pvb); + vbo_map.Add(name,*vad); - return pvb; + return true; } bool PrimitiveCreater::WriteVBO(const AnsiString &name,const void *data,const uint32_t bytes) @@ -144,7 +126,9 @@ namespace hgl if(vif->stride*vertices_number!=bytes) return(false); - return AcquirePVB(name,data); + VBOAccessData vad; + + return AcquirePVB(&vad,name,data); } void PrimitiveCreater::ClearAllData() @@ -154,10 +138,10 @@ namespace hgl const auto *sp=vbo_map.GetDataList(); for(uint i=0;ivalue->vbo) + if((*sp)->value.vbo) { - (*sp)->value->vbo->Unmap(); - delete (*sp)->value->vbo; + (*sp)->value.vbo->Unmap(); + delete (*sp)->value.vbo; } ++sp; @@ -184,12 +168,12 @@ namespace hgl const auto *sp=vbo_map.GetDataList(); for(uint i=0;ivalue->vbo) + if((*sp)->value.vbo) { - if((*sp)->value->map_data) - (*sp)->value->vbo->Unmap(); + if((*sp)->value.map_ptr) + (*sp)->value.vbo->Unmap(); - primitive->Set((*sp)->key,(*sp)->value->vbo); + primitive->Set((*sp)->key,(*sp)->value.vbo); } else {