use VBOAccessData instead of PrimitiveVertexBuffer, use VBOAccessMap instead of PVBMap
This commit is contained in:
parent
f0c47cd4f1
commit
acb69d3bf5
@ -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}
|
||||
};
|
||||
|
@ -15,14 +15,6 @@ namespace hgl
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
struct PrimitiveVertexBuffer
|
||||
{
|
||||
VBO * vbo;
|
||||
void * map_data;
|
||||
};//struct PrimitiveVertexBuffer
|
||||
|
||||
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
|
||||
|
||||
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();
|
||||
|
||||
|
@ -43,6 +43,8 @@ namespace hgl
|
||||
VkDeviceSize offset;
|
||||
VkDeviceSize size;
|
||||
|
||||
void *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
CompOperatorMemcmp(const VBOAccessData &);
|
||||
|
@ -58,7 +58,6 @@ namespace hgl
|
||||
|
||||
if(vdm)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -69,23 +68,9 @@ 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
|
||||
{
|
||||
if(!device->CheckIndexType(it,vertex_count))
|
||||
return(false);
|
||||
}
|
||||
|
||||
@ -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;i<vbo_map.GetCount();i++)
|
||||
{
|
||||
if((*sp)->value->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;i<si_count;i++)
|
||||
{
|
||||
if((*sp)->value->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
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user