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]=
|
constexpr uint8 color_data[VERTEX_COUNT][4]=
|
||||||
{ {255,0,0,255},
|
{
|
||||||
|
{255,0,0,255},
|
||||||
{0,255,0,255},
|
{0,255,0,255},
|
||||||
{0,0,255,255}
|
{0,0,255,255}
|
||||||
};
|
};
|
||||||
|
@ -15,14 +15,6 @@ namespace hgl
|
|||||||
*/
|
*/
|
||||||
class PrimitiveCreater
|
class PrimitiveCreater
|
||||||
{
|
{
|
||||||
struct PrimitiveVertexBuffer
|
|
||||||
{
|
|
||||||
VBO * vbo;
|
|
||||||
void * map_data;
|
|
||||||
};//struct PrimitiveVertexBuffer
|
|
||||||
|
|
||||||
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
GPUDevice *device;
|
GPUDevice *device;
|
||||||
@ -40,11 +32,11 @@ namespace hgl
|
|||||||
|
|
||||||
IndexBuffer * ibo;
|
IndexBuffer * ibo;
|
||||||
void * ibo_map;
|
void * ibo_map;
|
||||||
PVBMap vbo_map;
|
VBOAccessMap vbo_map;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
PrimitiveVertexBuffer *AcquirePVB(const AnsiString &,const void *data); ///<请求一个顶点属性数据区
|
bool AcquirePVB(VBOAccessData *,const AnsiString &,const void *data); ///<请求一个顶点属性数据区
|
||||||
|
|
||||||
void ClearAllData();
|
void ClearAllData();
|
||||||
|
|
||||||
@ -64,12 +56,11 @@ namespace hgl
|
|||||||
if(format!=T::GetVulkanFormat())
|
if(format!=T::GetVulkanFormat())
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
PrimitiveVertexBuffer *pvb=this->AcquirePVB(name,nullptr);
|
VBOAccessData vad;
|
||||||
|
if(!this->AcquirePVB(&vad,name,nullptr))
|
||||||
if(!pvb)
|
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
T *access=T::Create(vertices_number,pvb->map_data);
|
T *access=T::Create(vertices_number,vad.map_ptr);
|
||||||
|
|
||||||
access->Begin();
|
access->Begin();
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@ namespace hgl
|
|||||||
VkDeviceSize offset;
|
VkDeviceSize offset;
|
||||||
VkDeviceSize size;
|
VkDeviceSize size;
|
||||||
|
|
||||||
|
void *map_ptr;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
CompOperatorMemcmp(const VBOAccessData &);
|
CompOperatorMemcmp(const VBOAccessData &);
|
||||||
|
@ -58,7 +58,6 @@ namespace hgl
|
|||||||
|
|
||||||
if(vdm)
|
if(vdm)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -69,24 +68,10 @@ namespace hgl
|
|||||||
if(!IsIndexType(it))
|
if(!IsIndexType(it))
|
||||||
return(false);
|
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
|
else
|
||||||
{
|
{
|
||||||
return(false);
|
if(!device->CheckIndexType(it,vertex_count))
|
||||||
|
return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ibo=device->CreateIBO(it,index_count);
|
ibo=device->CreateIBO(it,index_count);
|
||||||
@ -100,33 +85,30 @@ namespace hgl
|
|||||||
return(true);
|
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(!vad)return(false);
|
||||||
if(name.IsEmpty())return(nullptr);
|
if(!vil)return(false);
|
||||||
|
if(name.IsEmpty())return(false);
|
||||||
|
|
||||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||||
|
|
||||||
if(!vif)
|
if(!vif)
|
||||||
return(nullptr);
|
return(false);
|
||||||
|
|
||||||
PrimitiveVertexBuffer *pvb;
|
if(vbo_map.Get(name,*vad))
|
||||||
|
return true;
|
||||||
|
|
||||||
if(vbo_map.Get(name,pvb))
|
vad->vbo =db->CreateVBO(vif->format,vertices_number,data);
|
||||||
return pvb;
|
|
||||||
|
|
||||||
pvb=new PrimitiveVertexBuffer;
|
|
||||||
|
|
||||||
pvb->vbo =db->CreateVBO(vif->format,vertices_number,data);
|
|
||||||
|
|
||||||
if(!data)
|
if(!data)
|
||||||
pvb->map_data=pvb->vbo->Map();
|
vad->map_ptr=vad->vbo->Map();
|
||||||
else
|
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)
|
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)
|
if(vif->stride*vertices_number!=bytes)
|
||||||
return(false);
|
return(false);
|
||||||
|
|
||||||
return AcquirePVB(name,data);
|
VBOAccessData vad;
|
||||||
|
|
||||||
|
return AcquirePVB(&vad,name,data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimitiveCreater::ClearAllData()
|
void PrimitiveCreater::ClearAllData()
|
||||||
@ -154,10 +138,10 @@ namespace hgl
|
|||||||
const auto *sp=vbo_map.GetDataList();
|
const auto *sp=vbo_map.GetDataList();
|
||||||
for(uint i=0;i<vbo_map.GetCount();i++)
|
for(uint i=0;i<vbo_map.GetCount();i++)
|
||||||
{
|
{
|
||||||
if((*sp)->value->vbo)
|
if((*sp)->value.vbo)
|
||||||
{
|
{
|
||||||
(*sp)->value->vbo->Unmap();
|
(*sp)->value.vbo->Unmap();
|
||||||
delete (*sp)->value->vbo;
|
delete (*sp)->value.vbo;
|
||||||
}
|
}
|
||||||
|
|
||||||
++sp;
|
++sp;
|
||||||
@ -184,12 +168,12 @@ namespace hgl
|
|||||||
const auto *sp=vbo_map.GetDataList();
|
const auto *sp=vbo_map.GetDataList();
|
||||||
for(uint i=0;i<si_count;i++)
|
for(uint i=0;i<si_count;i++)
|
||||||
{
|
{
|
||||||
if((*sp)->value->vbo)
|
if((*sp)->value.vbo)
|
||||||
{
|
{
|
||||||
if((*sp)->value->map_data)
|
if((*sp)->value.map_ptr)
|
||||||
(*sp)->value->vbo->Unmap();
|
(*sp)->value.vbo->Unmap();
|
||||||
|
|
||||||
primitive->Set((*sp)->key,(*sp)->value->vbo);
|
primitive->Set((*sp)->key,(*sp)->value.vbo);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user