Merge branch 'devel_31_VDMMergeRender' of http://www.hyzgame.com:3000/hyzboy/ULRE into devel_31_VDMMergeRender
This commit is contained in:
commit
cd01c45980
@ -33,20 +33,16 @@ class TestApp:public SceneAppFramework
|
||||
|
||||
private:
|
||||
|
||||
Material * material =nullptr;
|
||||
Material * mtl_plane_grid =nullptr;
|
||||
MaterialInstance * mi_plane_grid =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
VertexDataManager * vdm =nullptr;
|
||||
PrimitiveCreater * prim_creater =nullptr;
|
||||
|
||||
Pipeline * pipeline_plane_grid =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
Material * mtl_line =nullptr;
|
||||
MaterialInstance * mi_line =nullptr;
|
||||
Pipeline * pipeline_line =nullptr;
|
||||
Primitive * prim_line =nullptr;
|
||||
|
||||
VAB * vab_pos =nullptr;
|
||||
VABMap * prim_line_vab_map =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
@ -54,48 +50,45 @@ private:
|
||||
|
||||
bool InitMaterialAndPipeline()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance2D",Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
material=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!material)return(false);
|
||||
{
|
||||
cfg.position_format=VAT_VEC2;
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(material,nullptr,&white_color);
|
||||
mtl_plane_grid=db->LoadMaterial("Std3D/VertexLum2D",&cfg);
|
||||
if(!mtl_plane_grid)return(false);
|
||||
|
||||
mi_plane_grid=db->CreateMaterialInstance(mtl_plane_grid,nullptr,&white_color);
|
||||
if(!mi_plane_grid)return(false);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(material,nullptr,&yellow_color);
|
||||
pipeline_plane_grid=CreatePipeline(mtl_plane_grid,InlinePipeline::Solid3D,Prim::Lines);
|
||||
if(!pipeline_plane_grid)return(false);
|
||||
}
|
||||
|
||||
{
|
||||
cfg.mtl_name="VertexLuminance3D"; //注意必须用不同名字,未来改名材质文件名+cfg hash名
|
||||
cfg.position_format=VAT_VEC3;
|
||||
|
||||
mtl_line=db->LoadMaterial("Std3D/VertexLum3D",&cfg);
|
||||
if(!mtl_line)return(false);
|
||||
|
||||
mi_line=db->CreateMaterialInstance(mtl_line,nullptr,&yellow_color);
|
||||
if(!mi_line)return(false);
|
||||
|
||||
pipeline=CreatePipeline(material,InlinePipeline::Solid3D,Prim::Lines);
|
||||
pipeline_line=CreatePipeline(mtl_line,InlinePipeline::Solid3D,Prim::Lines);
|
||||
|
||||
if(!pipeline)
|
||||
if(!pipeline_line)
|
||||
return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVDMAndPC()
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
vdm=new VertexDataManager(device,material->GetDefaultVIL());
|
||||
if(!vdm->Init( 1024*1024, //VAB最大容量
|
||||
1024*1024, //索引最大容量
|
||||
IndexType::U16)) //索引类型
|
||||
{
|
||||
delete vdm;
|
||||
vdm=nullptr;
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
prim_creater=new PrimitiveCreater(vdm);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
Renderable *Add(Primitive *r,MaterialInstance *mi)
|
||||
{
|
||||
Renderable *ri=db->CreateRenderable(r,mi,pipeline);
|
||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
@ -113,6 +106,8 @@ private:
|
||||
using namespace inline_geometry;
|
||||
|
||||
{
|
||||
PrimitiveCreater pc(device,mtl_plane_grid->GetDefaultVIL());
|
||||
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
@ -121,19 +116,21 @@ private:
|
||||
pgci.lum=0.5;
|
||||
pgci.sub_lum=0.75;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(prim_creater,&pgci);
|
||||
prim_plane_grid=CreatePlaneGrid(&pc,&pgci);
|
||||
}
|
||||
|
||||
{
|
||||
if(!prim_creater->Init("Line",2))
|
||||
PrimitiveCreater pc(device,mtl_line->GetDefaultVIL());
|
||||
|
||||
if(!pc.Init("Line",2))
|
||||
return(false);
|
||||
|
||||
if(!prim_creater->WriteVAB(VAN::Position, VF_V3F,position_data))return(false);
|
||||
if(!prim_creater->WriteVAB(VAN::Luminance,VF_V1F,lumiance_data))return(false);
|
||||
if(!pc.WriteVAB(VAN::Position, VF_V3F,position_data))return(false);
|
||||
if(!pc.WriteVAB(VAN::Luminance,VF_V1F,lumiance_data))return(false);
|
||||
|
||||
prim_line=prim_creater->Create();
|
||||
prim_line=pc.Create();
|
||||
|
||||
prim_line->Getv
|
||||
prim_line_vab_map=prim_line->GetVABMap(VAN::Position);
|
||||
}
|
||||
|
||||
return(true);
|
||||
@ -141,8 +138,8 @@ private:
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid);
|
||||
Add(prim_line,mi_line);
|
||||
Add(prim_plane_grid,mi_plane_grid,pipeline_plane_grid);
|
||||
Add(prim_line,mi_line,pipeline_line);
|
||||
|
||||
camera->pos=Vector3f(32,32,32);
|
||||
camera_control->SetTarget(Vector3f(0,0,0));
|
||||
@ -158,8 +155,8 @@ public:
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_creater)
|
||||
SAFE_CLEAR(vdm)
|
||||
SAFE_CLEAR(prim_plane_grid);
|
||||
SAFE_CLEAR(prim_line);
|
||||
}
|
||||
|
||||
bool Init(uint w,uint h)
|
||||
@ -170,9 +167,6 @@ public:
|
||||
if(!InitMaterialAndPipeline())
|
||||
return(false);
|
||||
|
||||
if(!InitVDMAndPC())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
@ -191,7 +185,8 @@ public:
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
vab_pos->Write(&pos,3*sizeof(float)); //更新VAB上这个点的位置
|
||||
prim_line_vab_map->Write(&pos, //更新VAB上这个点的位置
|
||||
1); //这里的1代表的数据数量,不是字节数
|
||||
|
||||
SceneAppFramework::BuildCommandBuffer(index);
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
@ -24,17 +25,13 @@ protected:
|
||||
|
||||
uint32_t vertices_number; ///<顶点数量
|
||||
|
||||
VKBufferMap * vab_map_list;
|
||||
|
||||
uint32_t index_number; ///<索引数量
|
||||
IndexType index_type; ///<索引类型
|
||||
IndexBuffer * ibo; ///<索引缓冲区
|
||||
|
||||
VKBufferMap ibo_map;
|
||||
|
||||
protected:
|
||||
|
||||
const int GetVABIndex (const AnsiString &name,const VkFormat &format); ///<取得顶点属性索引
|
||||
const int InitVAB(const AnsiString &name,const VkFormat format,const void *data); ///<取得顶点属性索引
|
||||
|
||||
public:
|
||||
|
||||
@ -59,16 +56,16 @@ public: //顶点缓冲区
|
||||
|
||||
const uint32_t GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||
|
||||
VKBufferMap * MapVAB (const AnsiString &name,const VkFormat &format);
|
||||
VABMap * GetVABMap (const AnsiString &name,const VkFormat format=VK_FORMAT_UNDEFINED);
|
||||
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data); ///<直接写入顶点属性数据
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat format,const void *data); ///<直接写入顶点属性数据
|
||||
|
||||
public: //索引缓冲区
|
||||
|
||||
const IndexType GetIndexType()const{return index_type;} ///<取得索引类型
|
||||
const uint32_t GetIndexCount()const{return index_number;} ///<取得索引数量
|
||||
|
||||
VKBufferMap * MapIBO();
|
||||
IBMap * GetIBMap();
|
||||
|
||||
bool WriteIBO(const void *data,const uint32_t count);
|
||||
|
||||
@ -79,159 +76,4 @@ public: //创建可渲染对象
|
||||
|
||||
Primitive * Create(); ///<创建一个可渲染对象,并清除创建器数据
|
||||
};//class PrimitiveCreater
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区原生数据访问映射
|
||||
*/
|
||||
template<typename T> 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<typename T> class VABRawMap
|
||||
|
||||
typedef VABRawMap<int8> VABMapI8, VABMapByte;
|
||||
typedef VABRawMap<int16> VABMapI16, VABMapShort;
|
||||
typedef VABRawMap<int32> VABMapI32, VABMapInt;
|
||||
typedef VABRawMap<uint8> VABMapU8, VABMapUByte;
|
||||
typedef VABRawMap<uint16> VABMapU16, VABMapUShort;
|
||||
typedef VABRawMap<uint32> VABMapU32, VABMapUInt;
|
||||
typedef VABRawMap<float> VABMapFloat;
|
||||
typedef VABRawMap<double> VABMapDouble;
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> 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<typename T> class VABMap
|
||||
|
||||
typedef VABMap<VB1i8> VABMap1i8 ,VABMap1b;
|
||||
typedef VABMap<VB1i16> VABMap1i16,VABMap1s;
|
||||
typedef VABMap<VB1i32> VABMap1i32,VABMap1i;
|
||||
typedef VABMap<VB1u8> VABMap1u8 ,VABMap1ub;
|
||||
typedef VABMap<VB1u16> VABMap1u16,VABMap1us;
|
||||
typedef VABMap<VB1u32> VABMap1u32,VABMap1ui;
|
||||
typedef VABMap<VB1f> VABMap1f;
|
||||
typedef VABMap<VB1d> VABMap1d;
|
||||
|
||||
typedef VABMap<VB2i8> VABMap2i8 ,VABMap2b;
|
||||
typedef VABMap<VB2i16> VABMap2i16,VABMap2s;
|
||||
typedef VABMap<VB2i32> VABMap2i32,VABMap2i;
|
||||
typedef VABMap<VB2u8> VABMap2u8 ,VABMap2ub;
|
||||
typedef VABMap<VB2u16> VABMap2u16,VABMap2us;
|
||||
typedef VABMap<VB2u32> VABMap2u32,VABMap2ui;
|
||||
typedef VABMap<VB2f> VABMap2f;
|
||||
typedef VABMap<VB2d> VABMap2d;
|
||||
|
||||
typedef VABMap<VB3i32> VABMap3i32,VABMap3i;
|
||||
typedef VABMap<VB3u32> VABMap3u32,VABMap3ui;
|
||||
typedef VABMap<VB3f> VABMap3f;
|
||||
typedef VABMap<VB3d> VABMap3d;
|
||||
|
||||
typedef VABMap<VB4i8> VABMap4i8 ,VABMap4b;
|
||||
typedef VABMap<VB4i16> VABMap4i16,VABMap4s;
|
||||
typedef VABMap<VB4i32> VABMap4i32,VABMap4i;
|
||||
typedef VABMap<VB4u8> VABMap4u8, VABMap4ub;
|
||||
typedef VABMap<VB4u16> VABMap4u16,VABMap4us;
|
||||
typedef VABMap<VB4u32> VABMap4u32,VABMap4ui;
|
||||
typedef VABMap<VB4f> VABMap4f;
|
||||
typedef VABMap<VB4d> VABMap4d;
|
||||
|
||||
/**
|
||||
* 索引缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> 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<typename T> class IBMap
|
||||
|
||||
using IBMapU8 =IBMap<uint8>;
|
||||
using IBMapU16=IBMap<uint16>;
|
||||
using IBMapU32=IBMap<uint32>;
|
||||
VK_NAMESPACE_END
|
||||
|
@ -62,6 +62,9 @@ using VAB=VertexAttribBuffer;
|
||||
|
||||
class IndexBuffer;
|
||||
|
||||
class VABMap;
|
||||
class IBMap;
|
||||
|
||||
class GPUCmdBuffer;
|
||||
class RenderCmdBuffer;
|
||||
class TextureCmdBuffer;
|
||||
|
@ -4,29 +4,91 @@
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VKBufferMap
|
||||
template<typename T> 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;
|
||||
}
|
||||
}
|
||||
|
||||
bool Write(const void *data,const uint32_t c)
|
||||
{
|
||||
if(!data||c==0||c>count)return(false);
|
||||
|
||||
if(!map_ptr)
|
||||
{
|
||||
if(!buffer)
|
||||
return(false);
|
||||
|
||||
return buffer->Write(data,offset,c);
|
||||
}
|
||||
|
||||
memcpy(map_ptr,data,stride*c);
|
||||
return(true);
|
||||
}
|
||||
};//class VKBufferMap
|
||||
VK_NAMESPACE_END
|
||||
|
@ -1,12 +1,9 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
VK_NAMESPACE_BEGIN
|
||||
class IndexBuffer:public DeviceBuffer
|
||||
{
|
||||
IndexType index_type;
|
||||
@ -45,6 +42,57 @@ namespace hgl
|
||||
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
|
||||
|
||||
class IBMap:public VKBufferMap<IndexBuffer>
|
||||
{
|
||||
public:
|
||||
|
||||
using VKBufferMap<IndexBuffer>::VKBufferMap;
|
||||
virtual ~IBMap()=default;
|
||||
|
||||
const IndexType GetType()const{return buffer->GetType();}
|
||||
|
||||
void SetIBO(IndexBuffer *ib,const int32_t index_offset,const uint32_t count)
|
||||
{
|
||||
VKBufferMap<IndexBuffer>::Set(ib,index_offset,ib->GetStride(),count);
|
||||
}
|
||||
};//class IBMap
|
||||
|
||||
/**
|
||||
* 索引缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> 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<typename T> class IBTypeMap
|
||||
|
||||
using IBMapU8 =IBTypeMap<uint8>;
|
||||
using IBMapU16=IBTypeMap<uint16>;
|
||||
using IBMapU32=IBTypeMap<uint32>;
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 原始图元数据访问接口<br>
|
||||
* Primitive的存为是为了屏蔽PrimitiveData的初始化之类的访问接口,以便于更好的管理和使用
|
||||
@ -37,10 +38,13 @@ public:
|
||||
VAB * GetVAB (const int);
|
||||
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
|
||||
const int32_t GetVertexOffset ()const; ///<取得顶点偏移(注意是顶点不是字节)
|
||||
VABMap * GetVABMap (const int); ///<取得VAB映射器
|
||||
VABMap * GetVABMap (const AnsiString &name){return GetVABMap(GetVABIndex(name));}
|
||||
|
||||
const uint32_t GetIndexCount ()const;
|
||||
IndexBuffer * GetIBO ();
|
||||
const uint32_t GetFirstIndex ()const; ///<取得第一个索引
|
||||
IBMap * GetIBMap (); ///<取得索引缓冲区映射器
|
||||
|
||||
VertexDataManager * GetVDM (); ///<取得顶点数据管理器
|
||||
|
||||
|
@ -1,12 +1,9 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
VK_NAMESPACE_BEGIN
|
||||
class VertexAttribBuffer:public DeviceBuffer
|
||||
{
|
||||
VkFormat format; ///<数据格式
|
||||
@ -45,6 +42,207 @@ namespace hgl
|
||||
};//class VertexAttribBuffer:public DeviceBuffer
|
||||
|
||||
using VAB=VertexAttribBuffer;
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
|
||||
class VABMap:public VKBufferMap<VAB>
|
||||
{
|
||||
public:
|
||||
|
||||
using VKBufferMap<VAB>::VKBufferMap;
|
||||
virtual ~VABMap()=default;
|
||||
|
||||
const VkFormat GetFormat()const { return buffer->GetFormat(); }
|
||||
|
||||
void SetVAB(VAB *vab,const VkDeviceSize off,const uint32_t count)
|
||||
{
|
||||
VKBufferMap<VAB>::Set(vab,off,vab->GetStride(),count);
|
||||
}
|
||||
};//class VABMap
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区原生数据访问映射
|
||||
*/
|
||||
template<typename T> class VABRawMap
|
||||
{
|
||||
VABMap *vab_map;
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABRawMap(VABMap *map,const VkFormat check_format=VK_FORMAT_UNDEFINED,bool now_map=true)
|
||||
{
|
||||
vab_map=map;
|
||||
map_ptr=nullptr;
|
||||
|
||||
if(vab_map)
|
||||
{
|
||||
if(check_format==VK_FORMAT_UNDEFINED
|
||||
||check_format==vab_map->GetFormat())
|
||||
{
|
||||
if(now_map)
|
||||
map_ptr=(T *)(vab_map->Map());
|
||||
}
|
||||
else
|
||||
{
|
||||
vab_map=nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
~VABRawMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
vab_map->Unmap();
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return vab_map?vab_map->IsValid():false; }
|
||||
|
||||
T *Map()
|
||||
{
|
||||
if(!vab_map)
|
||||
return(nullptr);
|
||||
|
||||
if(!map_ptr)
|
||||
map_ptr=(T *)(vab_map->Map());
|
||||
|
||||
return map_ptr;
|
||||
}
|
||||
|
||||
void Unmap()
|
||||
{
|
||||
if(vab_map)
|
||||
{
|
||||
if(map_ptr)
|
||||
vab_map->Unmap();
|
||||
}
|
||||
}
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
T *operator->(){ return map_ptr; }
|
||||
};//template<typename T> class VABRawMap
|
||||
|
||||
typedef VABRawMap<int8> VABMapI8, VABMapByte;
|
||||
typedef VABRawMap<int16> VABMapI16, VABMapShort;
|
||||
typedef VABRawMap<int32> VABMapI32, VABMapInt;
|
||||
typedef VABRawMap<uint8> VABMapU8, VABMapUByte;
|
||||
typedef VABRawMap<uint16> VABMapU16, VABMapUShort;
|
||||
typedef VABRawMap<uint32> VABMapU32, VABMapUInt;
|
||||
typedef VABRawMap<float> VABMapFloat;
|
||||
typedef VABRawMap<double> VABMapDouble;
|
||||
|
||||
/**
|
||||
* 顶点属性缓冲区数据访问映射
|
||||
*/
|
||||
template<typename T> class VABFormatMap
|
||||
{
|
||||
VABMap *vab_map;
|
||||
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABFormatMap(VABMap *map,bool now_map=true)
|
||||
{
|
||||
vab_map=map;
|
||||
|
||||
if(vab_map&&vab_map->GetFormat()==T::GetVulkanFormat())
|
||||
{
|
||||
if(now_map)
|
||||
{
|
||||
map_ptr=T::Create(vab_map->GetCount(),vab_map->Map());
|
||||
map_ptr->Begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
map_ptr=T::Create(vab_map->GetCount(),nullptr);
|
||||
}
|
||||
}
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
~VABFormatMap()
|
||||
{
|
||||
if(map_ptr)
|
||||
{
|
||||
vab_map->Unmap();
|
||||
delete map_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return map_ptr?map_ptr->IsValid():false; }
|
||||
|
||||
T *Map()
|
||||
{
|
||||
if(!vab_map)
|
||||
return(nullptr);
|
||||
|
||||
if(!map_ptr)
|
||||
{
|
||||
map_ptr=T::Create(vab_map->GetCount(),vab_map->Map());
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!map_ptr->IsValid())
|
||||
map_ptr->SetData(vab_map->Map());
|
||||
}
|
||||
|
||||
map_ptr->Begin();
|
||||
return map_ptr;
|
||||
}
|
||||
|
||||
void Unmap()
|
||||
{
|
||||
if(vab_map)
|
||||
{
|
||||
if(map_ptr&&map_ptr->IsValid())
|
||||
{
|
||||
vab_map->Unmap();
|
||||
map_ptr->SetData(nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Restart()
|
||||
{
|
||||
return Map();
|
||||
}
|
||||
|
||||
T *operator->()
|
||||
{
|
||||
return map_ptr;
|
||||
}
|
||||
};//template<typename T> class VABFormatMap
|
||||
|
||||
typedef VABFormatMap<VB1i8> VABMap1i8 ,VABMap1b;
|
||||
typedef VABFormatMap<VB1i16> VABMap1i16,VABMap1s;
|
||||
typedef VABFormatMap<VB1i32> VABMap1i32,VABMap1i;
|
||||
typedef VABFormatMap<VB1u8> VABMap1u8 ,VABMap1ub;
|
||||
typedef VABFormatMap<VB1u16> VABMap1u16,VABMap1us;
|
||||
typedef VABFormatMap<VB1u32> VABMap1u32,VABMap1ui;
|
||||
typedef VABFormatMap<VB1f> VABMap1f;
|
||||
typedef VABFormatMap<VB1d> VABMap1d;
|
||||
|
||||
typedef VABFormatMap<VB2i8> VABMap2i8 ,VABMap2b;
|
||||
typedef VABFormatMap<VB2i16> VABMap2i16,VABMap2s;
|
||||
typedef VABFormatMap<VB2i32> VABMap2i32,VABMap2i;
|
||||
typedef VABFormatMap<VB2u8> VABMap2u8 ,VABMap2ub;
|
||||
typedef VABFormatMap<VB2u16> VABMap2u16,VABMap2us;
|
||||
typedef VABFormatMap<VB2u32> VABMap2u32,VABMap2ui;
|
||||
typedef VABFormatMap<VB2f> VABMap2f;
|
||||
typedef VABFormatMap<VB2d> VABMap2d;
|
||||
|
||||
typedef VABFormatMap<VB3i32> VABMap3i32,VABMap3i;
|
||||
typedef VABFormatMap<VB3u32> VABMap3u32,VABMap3ui;
|
||||
typedef VABFormatMap<VB3f> VABMap3f;
|
||||
typedef VABFormatMap<VB3d> VABMap3d;
|
||||
|
||||
typedef VABFormatMap<VB4i8> VABMap4i8 ,VABMap4b;
|
||||
typedef VABFormatMap<VB4i16> VABMap4i16,VABMap4s;
|
||||
typedef VABFormatMap<VB4i32> VABMap4i32,VABMap4i;
|
||||
typedef VABFormatMap<VB4u8> VABMap4u8, VABMap4ub;
|
||||
typedef VABFormatMap<VB4u16> VABMap4u16,VABMap4us;
|
||||
typedef VABFormatMap<VB4u32> VABMap4u32,VABMap4ui;
|
||||
typedef VABFormatMap<VB4f> VABMap4f;
|
||||
typedef VABFormatMap<VB4d> VABMap4d;
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
@ -44,6 +44,17 @@ namespace hgl
|
||||
|
||||
virtual ~VertexAttribDataAccess()=default;
|
||||
|
||||
void SetData(T *_data)
|
||||
{
|
||||
data =_data;
|
||||
data_end=_data+count*C;
|
||||
}
|
||||
|
||||
const bool IsValid()const
|
||||
{
|
||||
return data;
|
||||
}
|
||||
|
||||
void Write(const T *ptr)
|
||||
{
|
||||
if(!ptr)return;
|
||||
|
@ -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
|
||||
)
|
||||
|
||||
|
@ -20,7 +20,7 @@ namespace hgl
|
||||
if(!pc->Init("Rectangle",4,0))
|
||||
return(nullptr);
|
||||
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
VABMap2f vertex(pc->GetVABMap(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->GetVABMap(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->GetVABMap(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->GetVABMap(VAN::Position));
|
||||
VABMap4f color(pc->GetVABMap(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->GetVABMap(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->GetVABMap(VAN::Luminance));
|
||||
|
||||
if(lum.IsValid())
|
||||
{
|
||||
@ -232,21 +232,21 @@ namespace hgl
|
||||
return(nullptr);
|
||||
|
||||
{
|
||||
VABMap3f normal(pc,VAN::Normal);
|
||||
VABMap3f normal(pc->GetVABMap(VAN::Normal));
|
||||
|
||||
if(normal.IsValid())
|
||||
normal->RepeatWrite(xy_normal,4);
|
||||
}
|
||||
|
||||
{
|
||||
VABMap3f tangent(pc,VAN::Tangent);
|
||||
VABMap3f tangent(pc->GetVABMap(VAN::Tangent));
|
||||
|
||||
if(tangent.IsValid())
|
||||
tangent->RepeatWrite(xy_tangent,4);
|
||||
}
|
||||
|
||||
{
|
||||
VABMap2f tex_coord(pc,VAN::TexCoord);
|
||||
VABMap2f tex_coord(pc->GetVABMap(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->GetVABMap(VAN::Color));
|
||||
|
||||
if(color.IsValid())
|
||||
{
|
||||
@ -360,7 +360,7 @@ namespace hgl
|
||||
template<typename T>
|
||||
void CreateSphereIndices(PrimitiveCreater *pc,uint numberParallels,const uint numberSlices)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
IBTypeMap<T> ib_map(pc->GetIBMap());
|
||||
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->GetVABMap(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->GetVABMap(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->GetVABMap(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->GetVABMap(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->GetVABMap(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->GetVABMap(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->GetVABMap(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->GetVABMap(VAN::TexCoord),VF_V2F);
|
||||
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
@ -637,7 +637,7 @@ namespace hgl
|
||||
template<typename T>
|
||||
void CreateTorusIndices(PrimitiveCreater *pc,uint numberSlices,uint numberStacks)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
IBTypeMap<T> ib_map(pc->GetIBMap());
|
||||
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->GetVABMap(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->GetVABMap(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->GetVABMap(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->GetVABMap(VAN::TexCoord),VF_V2F);
|
||||
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
@ -788,7 +788,7 @@ namespace hgl
|
||||
template<typename T>
|
||||
void CreateCylinderIndices(PrimitiveCreater *pc,const uint numberSlices)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
IBTypeMap<T> ib_map(pc->GetIBMap());
|
||||
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->GetVABMap(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->GetVABMap(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->GetVABMap(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->GetVABMap(VAN::TexCoord),VF_V2F);
|
||||
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
@ -1025,7 +1025,7 @@ namespace hgl
|
||||
template<typename T>
|
||||
void CreateConeIndices(PrimitiveCreater *pc,const uint numberSlices,const uint numberStacks)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
IBTypeMap<T> ib_map(pc->GetIBMap());
|
||||
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->GetVABMap(VAN::Position),VF_V3F);
|
||||
VABMapFloat normal (pc->GetVABMap(VAN::Normal),VF_V3F);
|
||||
VABMapFloat tangent (pc->GetVABMap(VAN::Tangent),VF_V3F);
|
||||
VABMapFloat tex_coord(pc->GetVABMap(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->GetVABMap(VAN::Position));
|
||||
VABMap4f color(pc->GetVABMap(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->GetVABMap(VAN::Color));
|
||||
|
||||
if(color.IsValid())
|
||||
{
|
||||
|
@ -15,8 +15,6 @@ PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v)
|
||||
|
||||
prim_data =nullptr;
|
||||
|
||||
vab_map_list =new VKBufferMap[v->GetVertexAttribCount()];
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
@ -30,7 +28,6 @@ PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
||||
|
||||
PrimitiveCreater::~PrimitiveCreater()
|
||||
{
|
||||
delete[] vab_map_list;
|
||||
SAFE_CLEAR(prim_data);
|
||||
}
|
||||
|
||||
@ -95,8 +92,6 @@ bool PrimitiveCreater::Init(const AnsiString &pname,const uint32_t vertex_count,
|
||||
return(false);
|
||||
}
|
||||
|
||||
ibo_map.Set(ibo,prim_data->GetFirstIndex(),index_number);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(!vdm)
|
||||
{
|
||||
@ -116,26 +111,28 @@ 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::InitVAB(const AnsiString &name,const VkFormat format,const void *data)
|
||||
{
|
||||
if(!prim_data)return(-1);
|
||||
|
||||
const int vab_index=prim_data->GetVABIndex(name);
|
||||
|
||||
if(vab_index<0)
|
||||
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(-1);
|
||||
|
||||
if(format!=VK_FORMAT_UNDEFINED)
|
||||
{
|
||||
const VIF *vif=vil->GetConfig(vab_index);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(-2);
|
||||
}
|
||||
|
||||
VAB *vab=prim_data->GetVAB(vab_index);
|
||||
|
||||
if(!vab)
|
||||
{
|
||||
vab=prim_data->InitVAB(vab_index,acquire_format,nullptr);
|
||||
|
||||
if(vab)
|
||||
vab_map_list[vab_index].Set(vab,
|
||||
prim_data->GetVertexOffset(),
|
||||
vertices_number);
|
||||
}
|
||||
vab=prim_data->InitVAB(vab_index,data);
|
||||
|
||||
if(!vab)
|
||||
return(-1);
|
||||
@ -152,39 +149,34 @@ const int PrimitiveCreater::GetVABIndex(const AnsiString &name,const VkFormat &a
|
||||
}
|
||||
}
|
||||
#endif//_DEBUG
|
||||
}
|
||||
|
||||
return(vab_index);
|
||||
}
|
||||
|
||||
VKBufferMap *PrimitiveCreater::MapVAB(const AnsiString &name,const VkFormat &format)
|
||||
VABMap *PrimitiveCreater::GetVABMap(const AnsiString &name,const VkFormat format)
|
||||
{
|
||||
const int vab_index=GetVABIndex(name,format);
|
||||
const int vab_index=InitVAB(name,format,nullptr);
|
||||
|
||||
if(vab_index<0)return nullptr;
|
||||
|
||||
return vab_map_list+vab_index;
|
||||
return prim_data->GetVABMap(vab_index);
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteVAB(const AnsiString &name,const VkFormat &format, const void *data)
|
||||
bool PrimitiveCreater::WriteVAB(const AnsiString &name,const VkFormat format,const void *data)
|
||||
{
|
||||
if(!prim_data)return(false);
|
||||
if(!data)return(false);
|
||||
|
||||
const int vab_index=GetVABIndex(name,format);
|
||||
|
||||
VAB *vab=prim_data->GetVAB(vab_index);
|
||||
|
||||
if(!vab)
|
||||
return(false);
|
||||
|
||||
return vab->Write(data,prim_data->GetVertexOffset(),vertices_number);
|
||||
return InitVAB(name,format,data)>=0;
|
||||
}
|
||||
|
||||
VKBufferMap *PrimitiveCreater::MapIBO()
|
||||
IBMap *PrimitiveCreater::GetIBMap()
|
||||
{
|
||||
if(!ibo)
|
||||
if(!prim_data)
|
||||
return(nullptr);
|
||||
|
||||
return &ibo_map;
|
||||
return prim_data->GetIBMap();
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteIBO(const void *data,const uint32_t count)
|
||||
@ -205,10 +197,7 @@ Primitive *PrimitiveCreater::Create()
|
||||
if(!prim_data)
|
||||
return(nullptr);
|
||||
|
||||
for(int i=0;i<vil->GetVertexAttribCount();i++)
|
||||
vab_map_list[i].Clear();
|
||||
|
||||
ibo_map.Clear();
|
||||
prim_data->UnmapAll();
|
||||
|
||||
Primitive *primitive=new Primitive(prim_name,prim_data);
|
||||
|
||||
|
@ -1,63 +0,0 @@
|
||||
#include<hgl/graph/VKBufferMap.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
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
|
@ -66,6 +66,11 @@ const int32_t Primitive::GetVertexOffset()const
|
||||
return prim_data->GetVertexOffset();
|
||||
}
|
||||
|
||||
VABMap *Primitive::GetVABMap(const int vab_index)
|
||||
{
|
||||
return prim_data->GetVABMap(vab_index);
|
||||
}
|
||||
|
||||
const uint32_t Primitive::GetIndexCount()const
|
||||
{
|
||||
return prim_data->GetIndexCount();
|
||||
@ -81,6 +86,11 @@ const uint32_t Primitive::GetFirstIndex()const
|
||||
return prim_data->GetFirstIndex();
|
||||
}
|
||||
|
||||
IBMap *Primitive::GetIBMap()
|
||||
{
|
||||
return prim_data->GetIBMap();
|
||||
}
|
||||
|
||||
VertexDataManager *Primitive::GetVDM()
|
||||
{
|
||||
return prim_data->GetVDM();
|
||||
|
@ -14,12 +14,14 @@ PrimitiveData::PrimitiveData(const VIL *_vil,const uint32_t vc)
|
||||
vertex_count=vc;
|
||||
|
||||
vab_list=hgl_zero_new<VAB *>(_vil->GetVertexAttribCount());
|
||||
vab_map_list=new VABMap[_vil->GetVertexAttribCount()];
|
||||
|
||||
ibo=nullptr;
|
||||
}
|
||||
|
||||
PrimitiveData::~PrimitiveData()
|
||||
{
|
||||
delete[] vab_map_list;
|
||||
delete[] vab_list; //注意:这里并不释放VAB,在派生类中释放
|
||||
}
|
||||
|
||||
@ -42,6 +44,73 @@ VAB *PrimitiveData::GetVAB(const int index)
|
||||
return vab_list[index];
|
||||
}
|
||||
|
||||
VAB *PrimitiveData::InitVAB(const int vab_index,const void *data)
|
||||
{
|
||||
if(!vil)return(nullptr);
|
||||
|
||||
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
{
|
||||
vab_list[vab_index]=CreateVAB(vab_index,vif->format,data);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
}
|
||||
else
|
||||
{
|
||||
vab_map_list[vab_index].Write(data,vertex_count);
|
||||
}
|
||||
|
||||
return vab_list[vab_index];
|
||||
}
|
||||
|
||||
VABMap *PrimitiveData::GetVABMap(const int vab_index)
|
||||
{
|
||||
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())return nullptr;
|
||||
|
||||
VABMap *vab_map=vab_map_list+vab_index;
|
||||
|
||||
if(!vab_map->IsValid())
|
||||
{
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
|
||||
vab_map->SetVAB(vab_list[vab_index],GetVertexOffset(),vertex_count);
|
||||
}
|
||||
|
||||
return vab_map;
|
||||
}
|
||||
|
||||
IndexBuffer *PrimitiveData::InitIBO(const uint32_t ic,IndexType it)
|
||||
{
|
||||
if(ibo)delete ibo;
|
||||
|
||||
ibo=CreateIBO(ic,it);
|
||||
|
||||
if(!ibo)
|
||||
return(nullptr);
|
||||
|
||||
index_count=ic;
|
||||
|
||||
ibo_map.SetIBO(ibo,GetFirstIndex(),index_count);
|
||||
|
||||
return(ibo);
|
||||
}
|
||||
|
||||
void PrimitiveData::UnmapAll()
|
||||
{
|
||||
for(int i=0;i<vil->GetVertexAttribCount();i++)
|
||||
vab_map_list[i].Unmap();
|
||||
|
||||
ibo_map.Unmap();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
@ -81,51 +150,18 @@ namespace
|
||||
delete ibo;
|
||||
}
|
||||
|
||||
IndexBuffer *InitIBO(const uint32_t ic,IndexType it) override
|
||||
IndexBuffer *CreateIBO(const uint32_t ic,const IndexType &it) override
|
||||
{
|
||||
if(!device)return(nullptr);
|
||||
|
||||
if(ibo)delete ibo;
|
||||
|
||||
ibo=device->CreateIBO(it,ic);
|
||||
|
||||
if(!ibo)
|
||||
return(nullptr);
|
||||
|
||||
index_count=ic;
|
||||
|
||||
return(ibo);
|
||||
return device->CreateIBO(it,ic);
|
||||
}
|
||||
|
||||
VAB *InitVAB(const int vab_index,const VkFormat &format,const void *data)
|
||||
VAB *CreateVAB(const int vab_index,const VkFormat format,const void *data) override
|
||||
{
|
||||
if(!device)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
|
||||
if(vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
|
||||
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);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vab_list[vab_index]&&data)
|
||||
{
|
||||
vab_list[vab_index]->Write(data,vertex_count);
|
||||
}
|
||||
|
||||
return vab_list[vab_index];
|
||||
return device->CreateVAB(format,vertex_count,data);
|
||||
}
|
||||
};//class PrimitiveDataPrivateBuffer:public PrimitiveData
|
||||
|
||||
@ -164,10 +200,10 @@ namespace
|
||||
vdm->ReleaseVAB(vab_node);
|
||||
}
|
||||
|
||||
IndexBuffer *InitIBO(const uint32_t ic,IndexType it) override
|
||||
IndexBuffer *CreateIBO(const uint32_t ic,const IndexType &it) override
|
||||
{
|
||||
if(ic<=0)return(nullptr);
|
||||
if(!vdm)return(nullptr);
|
||||
if(!vdm)
|
||||
return(nullptr);
|
||||
|
||||
if(!ib_node)
|
||||
{
|
||||
@ -175,42 +211,21 @@ namespace
|
||||
|
||||
if(!ib_node)
|
||||
return(nullptr);
|
||||
|
||||
ibo=vdm->GetIBO();
|
||||
}
|
||||
|
||||
index_count=ic;
|
||||
|
||||
return ibo;
|
||||
return vdm->GetIBO();
|
||||
}
|
||||
|
||||
VAB *InitVAB(const int vab_index,const VkFormat &format,const void *data)
|
||||
VAB *CreateVAB(const int vab_index,const VkFormat format,const void *data) override
|
||||
{
|
||||
if(!vdm)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
VAB *vab=vdm->GetVAB(vab_index);
|
||||
|
||||
if (vab_index<0||vab_index>=vil->GetVertexAttribCount())
|
||||
return(nullptr);
|
||||
if(!vab)return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(vab_index);
|
||||
if(data)
|
||||
vab->Write(data,vab_node->GetStart(),vertex_count);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(nullptr);
|
||||
|
||||
if (!vab_list[vab_index])
|
||||
{
|
||||
vab_list[vab_index]=vdm->GetVAB(vab_index);
|
||||
|
||||
if(!vab_list[vab_index])
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vab_list[vab_index]&&data)
|
||||
vab_list[vab_index]->Write(data,vab_node->GetStart(),vertex_count);
|
||||
|
||||
return vab_list[vab_index];
|
||||
return vab;
|
||||
}
|
||||
};//class PrimitiveDataVDM:public PrimitiveData
|
||||
}//namespace
|
||||
|
@ -1,4 +1,7 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/*
|
||||
@ -25,7 +28,16 @@ protected:
|
||||
uint32_t index_count;
|
||||
|
||||
VAB ** vab_list;
|
||||
VABMap * vab_map_list;
|
||||
|
||||
virtual VAB * CreateVAB(const int vab_index,const VkFormat format,const void *data)=0;
|
||||
|
||||
protected:
|
||||
|
||||
IndexBuffer * ibo;
|
||||
IBMap ibo_map;
|
||||
|
||||
virtual IndexBuffer *CreateIBO(const uint32_t ic,const IndexType &it)=0;
|
||||
|
||||
public:
|
||||
|
||||
@ -37,10 +49,14 @@ public:
|
||||
const uint32_t GetVertexCount ()const{return vertex_count;}
|
||||
const int GetVABCount ()const;
|
||||
const int GetVABIndex (const AnsiString &name)const;
|
||||
VAB * GetVAB (const int index);
|
||||
VAB * GetVAB (const AnsiString &name){return GetVAB(GetVABIndex(name));}
|
||||
|
||||
VAB * GetVAB (const int index);
|
||||
VAB * InitVAB (const int vab_index,const void *data);
|
||||
VABMap * GetVABMap (const int vab_index);
|
||||
|
||||
IndexBuffer * InitIBO(const uint32_t index_count,IndexType it);
|
||||
IndexBuffer * GetIBO (){return ibo;}
|
||||
IBMap * GetIBMap (){return &ibo_map;}
|
||||
uint32_t GetIndexCount ()const{return index_count;}
|
||||
|
||||
virtual int32_t GetVertexOffset ()const=0; ///<取得顶点偏移(注意是顶点不是字节)
|
||||
@ -48,10 +64,8 @@ public:
|
||||
|
||||
virtual VertexDataManager * GetVDM()const=0; ///<取得顶点数据管理器
|
||||
|
||||
public:
|
||||
void UnmapAll();
|
||||
|
||||
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;
|
||||
};//class PrimitiveData
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const uint32_t vc);
|
||||
|
Loading…
x
Reference in New Issue
Block a user