coded PrimitiveDataVDM, next step is test.
This commit is contained in:
parent
6de3cf789a
commit
9a4e495027
@ -14,6 +14,7 @@ class PrimitiveCreater
|
||||
protected:
|
||||
|
||||
GPUDevice * device;
|
||||
VertexDataManager * vdm;
|
||||
|
||||
const VIL * vil;
|
||||
|
||||
@ -31,6 +32,7 @@ protected:
|
||||
public:
|
||||
|
||||
PrimitiveCreater(GPUDevice *,const VIL *,const AnsiString &name);
|
||||
PrimitiveCreater(VertexDataManager *,const VIL *,const AnsiString &name);
|
||||
virtual ~PrimitiveCreater();
|
||||
|
||||
virtual bool Init(const VkDeviceSize vertices_count,const VkDeviceSize index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
||||
@ -39,10 +41,10 @@ public: //顶点缓冲区
|
||||
|
||||
const VkDeviceSize GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||
|
||||
VABAccess * AcquirePVB (const AnsiString &name,const VkFormat &format,const void *data=nullptr,const VkDeviceSize bytes=0); ///<请求一个顶点属性数据区
|
||||
VABAccess * AcquireVAB (const AnsiString &name,const VkFormat &format,const void *data=nullptr,const VkDeviceSize bytes=0); ///<请求一个顶点属性数据区
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data,const uint32_t bytes) ///<直接写入顶点属性数据
|
||||
{
|
||||
return AcquirePVB(name,format,data,bytes);
|
||||
return AcquireVAB(name,format,data,bytes);
|
||||
}
|
||||
|
||||
public: //索引缓冲区
|
||||
@ -52,10 +54,10 @@ public: //索引缓冲区
|
||||
void * MapIBO();
|
||||
void UnmapIBO();
|
||||
|
||||
bool WriteIBO(const void *data,const VkDeviceSize bytes);
|
||||
bool WriteIBO(const void *data,const VkDeviceSize count);
|
||||
|
||||
template<typename T>
|
||||
bool WriteIBO(const T *data){return WriteIBO(data,index_number*sizeof(T));}
|
||||
bool WriteIBO(const T *data){return WriteIBO(data,index_number);}
|
||||
|
||||
public: //创建可渲染对象
|
||||
|
||||
@ -74,7 +76,7 @@ public:
|
||||
|
||||
VABRawMap(PrimitiveCreater *pc,const VkFormat &format,const AnsiString &name)
|
||||
{
|
||||
vaba=pc->AcquirePVB(name,format);
|
||||
vaba=pc->AcquireVAB(name,format);
|
||||
|
||||
if(vaba)
|
||||
map_ptr=(T *)(vaba->vab->Map(vaba->start,vaba->count));
|
||||
@ -114,7 +116,7 @@ public:
|
||||
|
||||
VABMap(PrimitiveCreater *pc,const AnsiString &name)
|
||||
{
|
||||
vaba=pc->AcquirePVB(name,T::GetVulkanFormat(),nullptr);
|
||||
vaba=pc->AcquireVAB(name,T::GetVulkanFormat(),nullptr);
|
||||
|
||||
if(vaba)
|
||||
{
|
||||
|
@ -1,51 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/type/DataChain.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class VDMAccess
|
||||
{
|
||||
protected:
|
||||
|
||||
VertexDataManager *vdm;
|
||||
DataChain::UserNode *dc_node;
|
||||
const VIL *vil;
|
||||
|
||||
public:
|
||||
|
||||
VDMAccess(VertexDataManager *_vdm,const VIL *_vil)
|
||||
{
|
||||
vdm=_vdm;
|
||||
vil=_vil;
|
||||
dc_node=nullptr;
|
||||
}
|
||||
|
||||
virtual ~VDMAccess()=default;
|
||||
|
||||
const VIL * GetVIL ()const{ return vil; }
|
||||
const DataChain::UserNode * GetDCNode ()const{ return dc_node; }
|
||||
};//class VDMAccess
|
||||
|
||||
class VABAccessVDM:public VDMAccess
|
||||
{
|
||||
VABAccess **vab;
|
||||
|
||||
public:
|
||||
|
||||
~VABAccessVDM() override
|
||||
{
|
||||
vdm->ReleaseVAB(dc_node);
|
||||
}
|
||||
|
||||
};//class VABAccessVDM:public VDMAccess
|
||||
|
||||
class IBAccessVDM:public VDMAccess
|
||||
{
|
||||
IBAccess *iba;
|
||||
|
||||
public:
|
||||
|
||||
};//class IBAccessVDM:public VDMAccess
|
||||
VK_NAMESPACE_END
|
@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/graph/VDMAccess.h>
|
||||
#include<hgl/type/DataChain.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@ -28,20 +28,12 @@ protected:
|
||||
DataChain vbo_data_chain; ///<数据链
|
||||
DataChain ibo_data_chain; ///<数据链
|
||||
|
||||
protected:
|
||||
|
||||
friend struct IBAccessVDM;
|
||||
friend struct VABAccessVDM;
|
||||
|
||||
bool ReleaseIB(DataChain::UserNode *);
|
||||
bool ReleaseVAB(DataChain::UserNode *);
|
||||
|
||||
public:
|
||||
|
||||
VertexDataManager(GPUDevice *dev,const VIL *_vil);
|
||||
~VertexDataManager();
|
||||
|
||||
GPUDevice * GetDevice ()const{return device;} ///<取得GPU设备
|
||||
GPUDevice * GetDevice ()const{return device;} ///<取得GPU设备
|
||||
|
||||
const VIL * GetVIL ()const{return vil;} ///<取得顶点输入格式列表
|
||||
|
||||
@ -56,10 +48,13 @@ public:
|
||||
|
||||
bool Init(const VkDeviceSize vbo_size,const VkDeviceSize ibo_size,const IndexType index_type);
|
||||
|
||||
IBAccessVDM *AcquireIB(const VkDeviceSize count);
|
||||
VABAccessVDM *AcquireVAB(const VkDeviceSize count);
|
||||
DataChain::UserNode *AcquireIB(const VkDeviceSize count);
|
||||
DataChain::UserNode *AcquireVAB(const VkDeviceSize count);
|
||||
|
||||
void Release(VABAccessVDM *);
|
||||
void Release(IBAccessVDM *);
|
||||
bool ReleaseIB(DataChain::UserNode *);
|
||||
bool ReleaseVAB(DataChain::UserNode *);
|
||||
|
||||
IndexBuffer *GetIBO(){return ibo;}
|
||||
VAB *GetVAB(const uint index){return vab[index];}
|
||||
};//class VertexDataManager
|
||||
VK_NAMESPACE_END
|
||||
|
@ -9,7 +9,6 @@ SOURCE_GROUP("Texture" FILES ${SG_TEXTURE_SOURCE})
|
||||
|
||||
SET(SG_VDM_SOURCE ${SG_INCLUDE_PATH}/VertexAttribDataAccess.h
|
||||
${SG_INCLUDE_PATH}/VertexDataManager.h
|
||||
${SG_INCLUDE_PATH}/VDMAccess.h
|
||||
VertexDataManager.cpp)
|
||||
|
||||
SOURCE_GROUP("VertexDataManager" FILES ${SG_VDM_SOURCE})
|
||||
@ -309,7 +308,7 @@ add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
|
||||
|
||||
${SG_TEXTURE_SOURCE}
|
||||
${TILE_SOURCE}
|
||||
#${SG_VDM_SOURCE}
|
||||
${SG_VDM_SOURCE}
|
||||
|
||||
# ${FONT_MANAGE_SOURCE}
|
||||
# ${FONT_SOURCE}
|
||||
|
@ -3,12 +3,14 @@
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKPrimitive.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include"vulkan/VKPrimitiveData.h"
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v,const AnsiString &name)
|
||||
{
|
||||
device =dev;
|
||||
vdm =nullptr;
|
||||
vil =v;
|
||||
|
||||
prim_name =name;
|
||||
@ -21,6 +23,12 @@ PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v,const AnsiString
|
||||
iba =nullptr;
|
||||
}
|
||||
|
||||
PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm,const VIL *v,const AnsiString &name)
|
||||
:PrimitiveCreater(_vdm->GetDevice(),v,name)
|
||||
{
|
||||
vdm=_vdm;
|
||||
}
|
||||
|
||||
PrimitiveCreater::~PrimitiveCreater()
|
||||
{
|
||||
SAFE_CLEAR(prim_data);
|
||||
@ -30,7 +38,10 @@ bool PrimitiveCreater::Init(const VkDeviceSize vertex_count,const VkDeviceSize i
|
||||
{
|
||||
if(vertex_count<=0)return(false);
|
||||
|
||||
prim_data=CreatePrimitiveData(device,vil,vertex_count);
|
||||
if(vdm)
|
||||
prim_data=CreatePrimitiveData(vdm,vil,vertex_count);
|
||||
else
|
||||
prim_data=CreatePrimitiveData(device,vil,vertex_count);
|
||||
|
||||
if(!prim_data)return(false);
|
||||
|
||||
@ -73,7 +84,7 @@ bool PrimitiveCreater::Init(const VkDeviceSize vertex_count,const VkDeviceSize i
|
||||
return(true);
|
||||
}
|
||||
|
||||
VABAccess *PrimitiveCreater::AcquirePVB(const AnsiString &name,const VkFormat &acquire_format,const void *data,const VkDeviceSize bytes)
|
||||
VABAccess *PrimitiveCreater::AcquireVAB(const AnsiString &name,const VkFormat &acquire_format,const void *data,const VkDeviceSize bytes)
|
||||
{
|
||||
if(!prim_data)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
@ -114,17 +125,17 @@ void PrimitiveCreater::UnmapIBO()
|
||||
iba->buffer->Unmap();
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteIBO(const void *data,const VkDeviceSize bytes)
|
||||
bool PrimitiveCreater::WriteIBO(const void *data,const VkDeviceSize count)
|
||||
{
|
||||
if(!data)return(false);
|
||||
if(!prim_data)return(false);
|
||||
|
||||
IBAccess *iba=prim_data->GetIBAccess();
|
||||
|
||||
if(bytes>0)
|
||||
if(iba->buffer->GetStride()*index_number<bytes)return(false);
|
||||
if(count>0&&count>index_number)
|
||||
return(false);
|
||||
|
||||
return iba->buffer->Write(data,bytes);
|
||||
return iba->buffer->Write(data,iba->start,count);
|
||||
}
|
||||
|
||||
Primitive *PrimitiveCreater::Create()
|
||||
|
@ -6,33 +6,6 @@
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class IBAccessVDM:public VDMAccess
|
||||
{
|
||||
IBAccess *iba;
|
||||
|
||||
public:
|
||||
|
||||
~IBAccessVDM() override
|
||||
{
|
||||
vdm->ReleaseIB(dc_node);
|
||||
}
|
||||
};//struct IBAccessVDM
|
||||
|
||||
class VABAccessVDM:public VDMAccess
|
||||
{
|
||||
VABAccess **vab;
|
||||
|
||||
public:
|
||||
|
||||
~VABAccessVDM() override
|
||||
{
|
||||
vdm->ReleaseVAB(dc_node);
|
||||
}
|
||||
};//struct VABAccessVDM
|
||||
}//namespace graph
|
||||
|
||||
namespace graph
|
||||
{
|
||||
VertexDataManager::VertexDataManager(GPUDevice *dev,const VIL *_vil)
|
||||
@ -98,26 +71,17 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
IBAccessVDM *VertexDataManager::AcquireIB(const VkDeviceSize count)
|
||||
DataChain::UserNode *VertexDataManager::AcquireIB(const VkDeviceSize count)
|
||||
{
|
||||
if(count<=0)return(false);
|
||||
if(count<=0)return(nullptr);
|
||||
|
||||
DataChain::UserNode *un=ibo_data_chain.Acquire(count);
|
||||
|
||||
if(!un)return(false);
|
||||
|
||||
IBAccessVDM *node=new IBAccessVDM;
|
||||
|
||||
node->vdm=this;
|
||||
node->dc_node=un;
|
||||
|
||||
node->buffer=ibo;
|
||||
node->start=un->GetStart();
|
||||
node->count=un->GetCount();
|
||||
|
||||
ibo_cur_size+=count;
|
||||
|
||||
return(node);
|
||||
return(un);
|
||||
}
|
||||
|
||||
bool VertexDataManager::ReleaseIB(DataChain::UserNode *un)
|
||||
@ -133,27 +97,17 @@ namespace hgl
|
||||
return(true);
|
||||
}
|
||||
|
||||
VABAccessVDM *VertexDataManager::AcquireVAB(const VkDeviceSize count)
|
||||
DataChain::UserNode *VertexDataManager::AcquireVAB(const VkDeviceSize count)
|
||||
{
|
||||
if(count<=0)return(false);
|
||||
if(count<=0)return(nullptr);
|
||||
|
||||
DataChain::UserNode *un=vbo_data_chain.Acquire(count);
|
||||
|
||||
if(!un)return(false);
|
||||
|
||||
VABAccessVDM *node=new VABAccessVDM;
|
||||
|
||||
node->vdm=this;
|
||||
node->dc_node=un;
|
||||
node->vil=vil;
|
||||
|
||||
//node->buffer=vab[0];
|
||||
//node->start=un->GetStart();
|
||||
//node->count=un->GetCount();
|
||||
if(!un)return(nullptr);
|
||||
|
||||
vab_cur_size+=count;
|
||||
|
||||
return(node);
|
||||
return(un);
|
||||
}
|
||||
|
||||
bool VertexDataManager::ReleaseVAB(DataChain::UserNode *un)
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
@ -195,8 +196,93 @@ namespace
|
||||
*/
|
||||
class PrimitiveDataVDM:public PrimitiveData
|
||||
{
|
||||
VertexDataManager *vdm;
|
||||
|
||||
};
|
||||
DataChain::UserNode *ib_node;
|
||||
DataChain::UserNode *vab_node;
|
||||
|
||||
public:
|
||||
|
||||
PrimitiveDataVDM(VertexDataManager *_vdm,const VIL *_vil,const VkDeviceSize vc):PrimitiveData(_vil,vc)
|
||||
{
|
||||
vdm=_vdm;
|
||||
|
||||
ib_node=nullptr;
|
||||
vab_node=vdm->AcquireVAB(vc);
|
||||
}
|
||||
|
||||
~PrimitiveDataVDM()
|
||||
{
|
||||
if(ib_node)
|
||||
vdm->ReleaseIB(ib_node);
|
||||
|
||||
if(vab_node)
|
||||
vdm->ReleaseVAB(vab_node);
|
||||
}
|
||||
|
||||
IBAccess *InitIBO(const VkDeviceSize index_count,IndexType it) override
|
||||
{
|
||||
if(index_count<=0)return(nullptr);
|
||||
if(!vdm)return(nullptr);
|
||||
|
||||
if(!ib_node)
|
||||
{
|
||||
ib_node=vdm->AcquireIB(index_count);
|
||||
|
||||
if(!ib_node)
|
||||
return(nullptr);
|
||||
|
||||
ib_access.buffer=vdm->GetIBO();
|
||||
ib_access.start =ib_node->GetStart();
|
||||
ib_access.count =ib_node->GetCount();
|
||||
}
|
||||
|
||||
return &ib_access;
|
||||
}
|
||||
|
||||
VABAccess *InitVAB(const AnsiString &name,const VkFormat &format,const void *data,const VkDeviceSize bytes)
|
||||
{
|
||||
if(!vdm)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const int index=vil->GetIndex(name);
|
||||
|
||||
if(index<0||index>=vil->GetCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(index);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(nullptr);
|
||||
|
||||
if(data)
|
||||
{
|
||||
if(vif->stride*vertex_count!=bytes)
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
VABAccess *vaba=vab_access+index;
|
||||
|
||||
if(!vaba->vab)
|
||||
{
|
||||
vaba->vab=vdm->GetVAB(index);
|
||||
|
||||
if(!vaba->vab)
|
||||
return(nullptr);
|
||||
|
||||
vaba->start=vab_node->GetStart();
|
||||
vaba->count=vab_node->GetCount();
|
||||
}
|
||||
|
||||
if(vaba->vab)
|
||||
vaba->vab->Write(data,vaba->start,vaba->count);
|
||||
|
||||
return vaba;
|
||||
}
|
||||
};//class PrimitiveDataVDM:public PrimitiveData
|
||||
}//namespace
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const VkDeviceSize vc)
|
||||
@ -207,4 +293,13 @@ PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const VkDevice
|
||||
|
||||
return(new PrimitiveDataPrivateBuffer(dev,_vil,vc));
|
||||
}
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(VertexDataManager *vdm,const VIL *_vil,const VkDeviceSize vc)
|
||||
{
|
||||
if(!vdm)return(nullptr);
|
||||
if(!_vil)return(nullptr);
|
||||
if(vc<=0)return(nullptr);
|
||||
|
||||
return(new PrimitiveDataVDM(vdm,_vil,vc));
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@ -47,4 +47,5 @@ public:
|
||||
};//class PrimitiveData
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const VkDeviceSize vc);
|
||||
PrimitiveData *CreatePrimitiveData(VertexDataManager *vdm,const VIL *_vil,const VkDeviceSize vc);
|
||||
VK_NAMESPACE_END
|
Loading…
x
Reference in New Issue
Block a user