newly PrimitiveData struct and Primitive class. Can't Run!!!
next step is to support PrimitiveVDM.
This commit is contained in:
parent
e27442a0b4
commit
40ce978f85
@ -169,11 +169,18 @@ private:
|
|||||||
|
|
||||||
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat=Identity4f)
|
Renderable *Add(Primitive *r,MaterialInstance *mi,Pipeline *p,const Matrix4f &mat=Identity4f)
|
||||||
{
|
{
|
||||||
|
if(!r)
|
||||||
|
return(nullptr);
|
||||||
|
if(!mi)
|
||||||
|
return(nullptr);
|
||||||
|
if(!p)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
Renderable *ri=db->CreateRenderable(r,mi,p);
|
Renderable *ri=db->CreateRenderable(r,mi,p);
|
||||||
|
|
||||||
if(!ri)
|
if(!ri)
|
||||||
{
|
{
|
||||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
LOG_ERROR(U8_TEXT("Create Renderable failed! Primitive: ")+r->GetName());
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,9 +7,6 @@
|
|||||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
class VertexDataManager;
|
|
||||||
struct PrimitiveData;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 可绘制图元创建器
|
* 可绘制图元创建器
|
||||||
*/
|
*/
|
||||||
@ -24,34 +21,38 @@ protected:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
PrimitiveData * prim_data;
|
AnsiString prim_name; ///<名称
|
||||||
|
PrimitiveData * prim_data; ///<图元数据
|
||||||
|
|
||||||
void_pointer vab_map_ptr[HGL_MAX_VERTEX_ATTRIB_COUNT];
|
VkDeviceSize vertices_number; ///<顶点数量
|
||||||
|
uint vab_proc_count; ///<操作的vab数量
|
||||||
|
|
||||||
VkDeviceSize vertices_number;
|
VkDeviceSize index_number; ///<索引数量
|
||||||
IndexBuffer * ibo;
|
IndexBuffer * ibo;
|
||||||
void * ibo_map;
|
void * ibo_map;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
template<typename T> friend class VABRawMap;
|
|
||||||
template<typename T> friend class VABMap;
|
|
||||||
|
|
||||||
VABAccess *AcquirePVB(const AnsiString &,const VkFormat &,const void *data); ///<请求一个顶点属性数据区
|
|
||||||
|
|
||||||
void ClearAllData();
|
void ClearAllData();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PrimitiveCreater(GPUDevice *,const VIL *);
|
PrimitiveCreater(GPUDevice *,const VIL *,const AnsiString &name);
|
||||||
//PrimitiveCreater(VertexDataManager *);
|
//PrimitiveCreater(VertexDataManager *);
|
||||||
virtual ~PrimitiveCreater();
|
virtual ~PrimitiveCreater()
|
||||||
|
{
|
||||||
|
ClearAllData();
|
||||||
|
}
|
||||||
|
|
||||||
virtual bool Init(const VkDeviceSize vertices_count,const VkDeviceSize index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
virtual bool Init(const VkDeviceSize vertices_count,const VkDeviceSize index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
||||||
|
|
||||||
const VkDeviceSize GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
const VkDeviceSize GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||||
|
|
||||||
bool WriteVAB(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
VABAccess * AcquirePVB (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);
|
||||||
|
}
|
||||||
|
|
||||||
const IndexType GetIndexType()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引数据类型
|
const IndexType GetIndexType()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引数据类型
|
||||||
|
|
||||||
@ -61,6 +62,9 @@ public:
|
|||||||
if(!ibo)return(nullptr);
|
if(!ibo)return(nullptr);
|
||||||
if(ibo->GetStride()!=sizeof(T))return(nullptr);
|
if(ibo->GetStride()!=sizeof(T))return(nullptr);
|
||||||
|
|
||||||
|
if(!ibo_map)
|
||||||
|
ibo_map=ibo->Map();
|
||||||
|
|
||||||
return (T *)ibo_map;
|
return (T *)ibo_map;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,12 +73,19 @@ public:
|
|||||||
if(!ibo)return(false);
|
if(!ibo)return(false);
|
||||||
if(ibo->GetStride()!=sizeof(T))return(false);
|
if(ibo->GetStride()!=sizeof(T))return(false);
|
||||||
|
|
||||||
|
if(ibo_map)
|
||||||
|
{
|
||||||
hgl_cpy<T>((T *)ibo_map,data,index_number);
|
hgl_cpy<T>((T *)ibo_map,data,index_number);
|
||||||
|
ibo->Unmap();
|
||||||
|
ibo_map=nullptr;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ibo->Write(data);
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Primitive * Finish(RenderResource *,const AnsiString &); ///<结束并创建可渲染对象
|
virtual Primitive * Finish(RenderResource *); ///<结束并创建可渲染对象
|
||||||
};//class PrimitiveCreater
|
};//class PrimitiveCreater
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -87,19 +98,25 @@ template<typename T> class VABRawMap
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
VABRawMap(PrimitiveCreater *pc,const AnsiString &name)
|
VABRawMap(PrimitiveCreater *pc,const VkFormat &format,const AnsiString &name)
|
||||||
{
|
{
|
||||||
vaba=pc->AcquirePVB(name,T::GetVulkanFormat(),nullptr);
|
vaba=pc->AcquirePVB(name,format);
|
||||||
|
|
||||||
|
if(vaba)
|
||||||
map_ptr=(T *)(vaba->vab->Map(vaba->start,vaba->count));
|
map_ptr=(T *)(vaba->vab->Map(vaba->start,vaba->count));
|
||||||
|
else
|
||||||
|
map_ptr=nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
~VABRawMap()
|
~VABRawMap()
|
||||||
{
|
{
|
||||||
|
if(vaba)
|
||||||
vaba->vab->Unmap();
|
vaba->vab->Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
T *operator->(){ return map_ptr; }
|
const bool IsValid()const{ return vaba; }
|
||||||
|
|
||||||
|
operator T *(){ return map_ptr; }
|
||||||
};//template<typename T> class VABRawMap
|
};//template<typename T> class VABRawMap
|
||||||
|
|
||||||
typedef VABRawMap<int8> VABRawMapi8, VABRawMapByte;
|
typedef VABRawMap<int8> VABRawMapi8, VABRawMapByte;
|
||||||
@ -125,23 +142,34 @@ public:
|
|||||||
{
|
{
|
||||||
vaba=pc->AcquirePVB(name,T::GetVulkanFormat(),nullptr);
|
vaba=pc->AcquirePVB(name,T::GetVulkanFormat(),nullptr);
|
||||||
|
|
||||||
|
if(vaba)
|
||||||
|
{
|
||||||
void *map_ptr=vaba->vab->Map(vaba->start,vaba->count);
|
void *map_ptr=vaba->vab->Map(vaba->start,vaba->count);
|
||||||
|
|
||||||
vb=T::Create(pc->GetVertexCount(),map_ptr);
|
vb=T::Create(pc->GetVertexCount(),map_ptr);
|
||||||
|
|
||||||
vb->Begin();
|
vb->Begin();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
vb=nullptr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
~VABMap()
|
~VABMap()
|
||||||
{
|
{
|
||||||
|
if(vaba)
|
||||||
vaba->vab->Unmap();
|
vaba->vab->Unmap();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Restart()
|
void Restart()
|
||||||
{
|
{
|
||||||
|
if(vb)
|
||||||
vb->Begin();
|
vb->Begin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const bool IsValid()const{ return vb; }
|
||||||
|
|
||||||
T *operator->(){ return vb; }
|
T *operator->(){ return vb; }
|
||||||
};//template<typename T> class VABMap
|
};//template<typename T> class VABMap
|
||||||
|
|
||||||
|
@ -122,6 +122,7 @@ struct PrimitiveData;
|
|||||||
class Primitive;
|
class Primitive;
|
||||||
class Renderable;
|
class Renderable;
|
||||||
|
|
||||||
|
class VertexDataManager;
|
||||||
class RenderResource;
|
class RenderResource;
|
||||||
|
|
||||||
enum class SharingMode
|
enum class SharingMode
|
||||||
|
@ -3,10 +3,9 @@
|
|||||||
#include<hgl/type/Map.h>
|
#include<hgl/type/Map.h>
|
||||||
#include<hgl/type/String.h>
|
#include<hgl/type/String.h>
|
||||||
#include<hgl/graph/AABB.h>
|
#include<hgl/graph/AABB.h>
|
||||||
#include<hgl/graph/VKPrimitiveData.h>
|
#include<hgl/graph/VK.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 单一图元数据访问接口<br>
|
* 单一图元数据访问接口<br>
|
||||||
*
|
*
|
||||||
@ -26,31 +25,35 @@ class Primitive
|
|||||||
protected:
|
protected:
|
||||||
|
|
||||||
AnsiString prim_name;
|
AnsiString prim_name;
|
||||||
|
|
||||||
PrimitiveData *prim_data;
|
PrimitiveData *prim_data;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
AABB BoundingBox;
|
AABB BoundingBox;
|
||||||
|
|
||||||
public:
|
protected:
|
||||||
|
|
||||||
Primitive(const AnsiString &n)
|
Primitive(const AnsiString &pn,PrimitiveData *pd)
|
||||||
{
|
{
|
||||||
prim_name=n;
|
prim_name=pn;
|
||||||
|
prim_data=pd;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Primitive()=0;
|
public:
|
||||||
|
|
||||||
|
virtual ~Primitive()=default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual const VkDeviceSize GetVertexCount ()const=0;
|
const AnsiString & GetName ()const{ return prim_name; }
|
||||||
virtual const int GetVACount ()const=0;
|
const VkDeviceSize GetVertexCount ()const;
|
||||||
virtual const bool GetVABAccess (const AnsiString &,VABAccess *)=0;
|
const int GetVACount ()const;
|
||||||
virtual const IBAccess * GetIBAccess ()const=0;
|
VABAccess * GetVABAccess (const AnsiString &);
|
||||||
|
IBAccess * GetIBAccess ();
|
||||||
|
|
||||||
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
||||||
};//class Primitive
|
};//class Primitive
|
||||||
|
|
||||||
Primitive *CreatePrimitive(const PrimitiveData *);
|
Primitive *CreatePrimitivePrivate(const AnsiString &,PrimitiveData *);
|
||||||
|
Primitive *CreatePrimitivePrivate(VertexDataManager *,const AnsiString &,PrimitiveData *);
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -1,40 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include<hgl/graph/VKVertexInputLayout.h>
|
|
||||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
|
||||||
#include<hgl/graph/VKIndexBuffer.h>
|
|
||||||
#include<hgl/graph/AABB.h>
|
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
|
||||||
|
|
||||||
/*
|
|
||||||
1.截止2024.4.27,根据vulkan.gpuinfo.org统计,只有9%的设备maxVertexInputAttributes为16,不存在低于16的设备。
|
|
||||||
9.0%的设备为28 - 31
|
|
||||||
70.7%的设备为32
|
|
||||||
9.6%的设备为64
|
|
||||||
|
|
||||||
由于我们暂时没有发现需要使用16个以上属性的情况,所以这里暂定使用16。
|
|
||||||
(如果时间过去久远,可再次查询此值是否可改成更高的值,以及是否需要)
|
|
||||||
|
|
||||||
2.为何va_name使用char[][]而不是String以及动态分配内存?
|
|
||||||
|
|
||||||
就是为了必避动态分配内存,以及可以直接memcpy处理,所以此处这样定义。
|
|
||||||
*/
|
|
||||||
|
|
||||||
struct PrimitiveData
|
|
||||||
{
|
|
||||||
const VIL * vil;
|
|
||||||
|
|
||||||
VkDeviceSize vertex_count;
|
|
||||||
|
|
||||||
VABAccess vab_access[HGL_MAX_VERTEX_ATTRIB_COUNT];
|
|
||||||
IBAccess ib_access;
|
|
||||||
};//struct PrimitiveData
|
|
||||||
|
|
||||||
bool InitPrimitiveData( PrimitiveData *pd,const VIL *_vil,const VkDeviceSize vc);
|
|
||||||
int GetVABIndex(const PrimitiveData *pd,const AnsiString &name);
|
|
||||||
VABAccess * GetVAB( PrimitiveData *pd,const int);
|
|
||||||
VABAccess * SetVAB( PrimitiveData *pd,const int,VAB *vab,VkDeviceSize start,VkDeviceSize count);
|
|
||||||
void SetIndexBuffer( PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic);
|
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
|
@ -147,7 +147,8 @@ public: //Material
|
|||||||
|
|
||||||
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
||||||
|
|
||||||
Primitive * CreatePrimitive(const AnsiString &,const uint32_t vertex_count=0);
|
Primitive * CreatePrimitive( const AnsiString &,PrimitiveData *);
|
||||||
|
Primitive * CreatePrimitive(VertexDataManager *,const AnsiString &,PrimitiveData *);
|
||||||
|
|
||||||
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
||||||
|
|
||||||
|
@ -9,8 +9,6 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
namespace graph
|
namespace graph
|
||||||
{
|
{
|
||||||
class VertexDataManager;
|
|
||||||
|
|
||||||
struct IBAccessNode:public IBAccess
|
struct IBAccessNode:public IBAccess
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
@ -13,8 +13,7 @@ SET(SG_VDM_SOURCE ${SG_INCLUDE_PATH}/VertexAttribDataAccess.h
|
|||||||
|
|
||||||
SOURCE_GROUP("VertexDataManager" FILES ${SG_VDM_SOURCE})
|
SOURCE_GROUP("VertexDataManager" FILES ${SG_VDM_SOURCE})
|
||||||
|
|
||||||
SET(SG_PRIMITIVE_SOURCE ${SG_INCLUDE_PATH}/VKPrimitiveData.h
|
SET(SG_PRIMITIVE_SOURCE ${SG_INCLUDE_PATH}/VKPrimitive.h
|
||||||
${SG_INCLUDE_PATH}/VKPrimitive.h
|
|
||||||
Vulkan/VKPrimitive.cpp
|
Vulkan/VKPrimitive.cpp
|
||||||
Vulkan/VKPrimitiveData.cpp
|
Vulkan/VKPrimitiveData.cpp
|
||||||
${SG_INCLUDE_PATH}/VKRenderablePrimitiveCreater.h
|
${SG_INCLUDE_PATH}/VKRenderablePrimitiveCreater.h
|
||||||
|
@ -16,19 +16,19 @@ namespace hgl
|
|||||||
{
|
{
|
||||||
Primitive *CreateRectangle(RenderResource *db,const VIL *vil,const RectangleCreateInfo *rci)
|
Primitive *CreateRectangle(RenderResource *db,const VIL *vil,const RectangleCreateInfo *rci)
|
||||||
{
|
{
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Rectangle");
|
||||||
|
|
||||||
if(!rc.Init(4,0))
|
if(!rc.Init(4,0))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB2f> vertex=rc.AccessVAB<VB2f>(VAN::Position);
|
VABMap2f vertex(&rc,VAN::Position);
|
||||||
|
|
||||||
if(!vertex)
|
if(!vertex.IsValid())
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
vertex->WriteRectFan(rci->scope);
|
vertex->WriteRectFan(rci->scope);
|
||||||
|
|
||||||
return rc.Finish(db,"Rectangle");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil)
|
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil)
|
||||||
@ -42,14 +42,14 @@ namespace hgl
|
|||||||
|
|
||||||
Primitive *CreateRoundRectangle(RenderResource *db,const VIL *vil,const RoundRectangleCreateInfo *rci)
|
Primitive *CreateRoundRectangle(RenderResource *db,const VIL *vil,const RoundRectangleCreateInfo *rci)
|
||||||
{
|
{
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"RoundRectangle");
|
||||||
|
|
||||||
if(rci->radius==0||rci->round_per<=1) //这是要画矩形
|
if(rci->radius==0||rci->round_per<=1) //这是要画矩形
|
||||||
{
|
{
|
||||||
if(!rc.Init(4,0))
|
if(!rc.Init(4,0))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB2f> vertex=rc.AccessVAB<VB2f>(VAN::Position);
|
VABMap2f vertex(&rc,VAN::Position);
|
||||||
|
|
||||||
vertex->WriteRectFan(rci->scope);
|
vertex->WriteRectFan(rci->scope);
|
||||||
}
|
}
|
||||||
@ -63,7 +63,7 @@ namespace hgl
|
|||||||
if(!rc.Init(rci->round_per*4,8))
|
if(!rc.Init(rci->round_per*4,8))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB2f> vertex=rc.AccessVAB<VB2f>(VAN::Position);
|
VABMap2f vertex(&rc,VAN::Position);
|
||||||
|
|
||||||
Vector2f *coord=new Vector2f[rci->round_per];
|
Vector2f *coord=new Vector2f[rci->round_per];
|
||||||
|
|
||||||
@ -111,12 +111,12 @@ namespace hgl
|
|||||||
delete[] coord;
|
delete[] coord;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.Finish(db,"RoundRectangle");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci)
|
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci)
|
||||||
{
|
{
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Circle");
|
||||||
|
|
||||||
uint edge;
|
uint edge;
|
||||||
|
|
||||||
@ -131,15 +131,15 @@ namespace hgl
|
|||||||
if(!rc.Init(cci->field_count,0))return(nullptr);
|
if(!rc.Init(cci->field_count,0))return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoDelete<VB2f> vertex=rc.AccessVAB<VB2f>(VAN::Position);
|
VABMap2f vertex(&rc,VAN::Position);
|
||||||
AutoDelete<VB4f> color=rc.AccessVAB<VB4f>(VAN::Color);
|
VABMap4f color(&rc,VAN::Color);
|
||||||
|
|
||||||
if(!vertex)
|
if(!vertex.IsValid())
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
if(cci->has_color)
|
if(cci->has_color)
|
||||||
{
|
{
|
||||||
if(!color)
|
if(!color.IsValid())
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
vertex->Write(cci->center);
|
vertex->Write(cci->center);
|
||||||
@ -159,17 +159,17 @@ namespace hgl
|
|||||||
color->Write(cci->border_color);
|
color->Write(cci->border_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.Finish(db,"Circle");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci)
|
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci)
|
||||||
{
|
{
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"PlaneGrid");
|
||||||
|
|
||||||
if(!rc.Init(((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,0))
|
if(!rc.Init(((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,0))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVAB<VB3f>(VAN::Position);
|
VABMap3f vertex(&rc,VAN::Position);
|
||||||
|
|
||||||
const float right=float(pgci->grid_size.Width())/2.0f;
|
const float right=float(pgci->grid_size.Width())/2.0f;
|
||||||
const float left =-right;
|
const float left =-right;
|
||||||
@ -189,8 +189,9 @@ namespace hgl
|
|||||||
Vector3f(left+col,bottom,0));
|
Vector3f(left+col,bottom,0));
|
||||||
}
|
}
|
||||||
|
|
||||||
AutoDelete<VB1f> lum=rc.AccessVAB<VB1f>(VAN::Luminance);
|
VABMap1f lum(&rc,VAN::Luminance);
|
||||||
if(lum)
|
|
||||||
|
if(lum.IsValid())
|
||||||
{
|
{
|
||||||
for(uint row=0;row<=pgci->grid_size.Height();row++)
|
for(uint row=0;row<=pgci->grid_size.Height();row++)
|
||||||
{
|
{
|
||||||
@ -209,7 +210,7 @@ namespace hgl
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.Finish(db,"PlaneGrid");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil)
|
Primitive *CreatePlane(RenderResource *db,const VIL *vil)
|
||||||
@ -219,33 +220,36 @@ namespace hgl
|
|||||||
const Vector3f xy_normal(0.0f,0.0f,1.0f);
|
const Vector3f xy_normal(0.0f,0.0f,1.0f);
|
||||||
const Vector3f xy_tangent(1.0f,0.0f,0.0f);
|
const Vector3f xy_tangent(1.0f,0.0f,0.0f);
|
||||||
|
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Plane");
|
||||||
|
|
||||||
if(!rc.Init(4,8))
|
if(!rc.Init(4,8))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
rc.WriteVAB(VAN::Position,xy_vertices,sizeof(xy_vertices));
|
if(!rc.WriteVAB(VAN::Position,VF_V3F,xy_vertices,sizeof(xy_vertices)))
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
{
|
{
|
||||||
AutoDelete<VB3f> normal=rc.AccessVAB<VB3f>(VAN::Normal);
|
VABMap3f normal(&rc,VAN::Normal);
|
||||||
|
|
||||||
if(normal)normal->RepeatWrite(xy_normal,4);
|
if(normal.IsValid())
|
||||||
|
normal->RepeatWrite(xy_normal,4);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
AutoDelete<VB3f> tangent=rc.AccessVAB<VB3f>(VAN::Tangent);
|
VABMap3f tangent(&rc,VAN::Tangent);
|
||||||
|
|
||||||
if(tangent)tangent->RepeatWrite(xy_tangent,4);
|
if(tangent.IsValid())
|
||||||
|
tangent->RepeatWrite(xy_tangent,4);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
AutoDelete<VB2f> tex_coord=rc.AccessVAB<VB2f>(VAN::TexCoord);
|
VABMap2f tex_coord(&rc,VAN::TexCoord);
|
||||||
|
|
||||||
if(tex_coord)
|
if(tex_coord.IsValid())
|
||||||
tex_coord->Write(xy_tex_coord,4);
|
tex_coord->Write(xy_tex_coord,4);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.Finish(db,"Plane");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci)
|
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci)
|
||||||
@ -301,29 +305,33 @@ namespace hgl
|
|||||||
16, 17, 18, 16, 18, 19,
|
16, 17, 18, 16, 18, 19,
|
||||||
20, 23, 22, 20, 22, 21};
|
20, 23, 22, 20, 22, 21};
|
||||||
|
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Cube");
|
||||||
|
|
||||||
if(!rc.Init(24,6*2*3,IndexType::U16))
|
if(!rc.Init(24,6*2*3,IndexType::U16))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
rc.WriteVAB(VAN::Position,positions,sizeof(positions));
|
if(!rc.WriteVAB(VAN::Position,VF_V3F,positions,sizeof(positions)))
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
if(cci->normal)
|
if(cci->normal)
|
||||||
rc.WriteVAB(VAN::Normal,normals,sizeof(normals));
|
if(!rc.WriteVAB(VAN::Normal,VF_V3F,normals,sizeof(normals)))
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
if(cci->tangent)
|
if(cci->tangent)
|
||||||
rc.WriteVAB(VAN::Tangent,tangents,sizeof(tangents));
|
if(!rc.WriteVAB(VAN::Tangent,VF_V3F,tangents,sizeof(tangents)))
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
if(cci->tex_coord)
|
if(cci->tex_coord)
|
||||||
rc.WriteVAB(VAN::TexCoord,tex_coords,sizeof(tex_coords));
|
if(!rc.WriteVAB(VAN::TexCoord,VF_V2F,tex_coords,sizeof(tex_coords)))
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
if(cci->color_type!=CubeCreateInfo::ColorType::NoColor)
|
if(cci->color_type!=CubeCreateInfo::ColorType::NoColor)
|
||||||
{
|
{
|
||||||
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
||||||
|
|
||||||
AutoDelete<VB4f> color=rc.AccessVAB<VB4f>(VAN::Color);
|
VABMap4f color(&rc,VAN::Color);
|
||||||
|
|
||||||
if(color)
|
if(color.IsValid())
|
||||||
{
|
{
|
||||||
if(cci->color_type==CubeCreateInfo::ColorType::SameColor)
|
if(cci->color_type==CubeCreateInfo::ColorType::SameColor)
|
||||||
color->RepeatWrite(cci->color[0],24);
|
color->RepeatWrite(cci->color[0],24);
|
||||||
@ -343,7 +351,7 @@ namespace hgl
|
|||||||
|
|
||||||
//rc.CreateIBO16(6*2*3,indices);
|
//rc.CreateIBO16(6*2*3,indices);
|
||||||
rc.WriteIBO(indices);
|
rc.WriteIBO(indices);
|
||||||
return rc.Finish(db,"Cube");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> void CreateSphereIndices(T *tp,uint numberParallels,const uint numberSlices)
|
template<typename T> void CreateSphereIndices(T *tp,uint numberParallels,const uint numberSlices)
|
||||||
@ -443,7 +451,7 @@ namespace hgl
|
|||||||
*/
|
*/
|
||||||
Primitive *CreateSphere(RenderResource *db,const VIL *vil,const uint numberSlices)
|
Primitive *CreateSphere(RenderResource *db,const VIL *vil,const uint numberSlices)
|
||||||
{
|
{
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Sphere");
|
||||||
|
|
||||||
uint numberParallels = (numberSlices+1) / 2;
|
uint numberParallels = (numberSlices+1) / 2;
|
||||||
uint numberVertices = (numberParallels + 1) * (numberSlices + 1);
|
uint numberVertices = (numberParallels + 1) * (numberSlices + 1);
|
||||||
@ -460,15 +468,18 @@ namespace hgl
|
|||||||
if(!rc.Init(numberVertices,numberIndices))
|
if(!rc.Init(numberVertices,numberIndices))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVAB<VB3f>(VAN::Position);
|
VABRawMapFloat vertex (&rc,VF_V3F,VAN::Position);
|
||||||
AutoDelete<VB3f> normal=rc.AccessVAB<VB3f>(VAN::Normal);
|
VABRawMapFloat normal (&rc,VF_V3F,VAN::Normal);
|
||||||
AutoDelete<VB3f> tangent=rc.AccessVAB<VB3f>(VAN::Tangent);
|
VABRawMapFloat tangent (&rc,VF_V3F,VAN::Tangent);
|
||||||
AutoDelete<VB2f> tex_coord=rc.AccessVAB<VB2f>(VAN::TexCoord);
|
VABRawMapFloat tex_coord(&rc,VF_V2F,VAN::TexCoord);
|
||||||
|
|
||||||
float *vp=vertex->Get();
|
float *vp=vertex;
|
||||||
float *np=normal?normal->Get():nullptr;
|
float *np=normal;
|
||||||
float *tp=tangent?tangent->Get():nullptr;
|
float *tp=tangent;
|
||||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
float *tcp=tex_coord;
|
||||||
|
|
||||||
|
if(!vp)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
for (uint i = 0; i < numberParallels + 1; i++)
|
for (uint i = 0; i < numberParallels + 1; i++)
|
||||||
{
|
{
|
||||||
@ -519,12 +530,12 @@ namespace hgl
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.Finish(db,"Sphere");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *CreateDome(RenderResource *db,const VIL *vil,const uint numberSlices)
|
Primitive *CreateDome(RenderResource *db,const VIL *vil,const uint numberSlices)
|
||||||
{
|
{
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Dome");
|
||||||
|
|
||||||
uint i, j;
|
uint i, j;
|
||||||
|
|
||||||
@ -546,15 +557,18 @@ namespace hgl
|
|||||||
if(!rc.Init(numberVertices,numberIndices))
|
if(!rc.Init(numberVertices,numberIndices))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVAB<VB3f>(VAN::Position);
|
VABRawMapFloat vertex (&rc,VF_V3F,VAN::Position);
|
||||||
AutoDelete<VB3f> normal=rc.AccessVAB<VB3f>(VAN::Normal);
|
VABRawMapFloat normal (&rc,VF_V3F,VAN::Normal);
|
||||||
AutoDelete<VB3f> tangent=rc.AccessVAB<VB3f>(VAN::Tangent);
|
VABRawMapFloat tangent (&rc,VF_V3F,VAN::Tangent);
|
||||||
AutoDelete<VB2f> tex_coord=rc.AccessVAB<VB2f>(VAN::TexCoord);
|
VABRawMapFloat tex_coord(&rc,VF_V2F,VAN::TexCoord);
|
||||||
|
|
||||||
float *vp=vertex->Get();
|
float *vp=vertex;
|
||||||
float *np=normal?normal->Get():nullptr;
|
float *np=normal;
|
||||||
float *tp=tangent?tangent->Get():nullptr;
|
float *tp=tangent;
|
||||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
float *tcp=tex_coord;
|
||||||
|
|
||||||
|
if(!vp)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
for (i = 0; i < numberParallels + 1; i++)
|
for (i = 0; i < numberParallels + 1; i++)
|
||||||
{
|
{
|
||||||
@ -610,7 +624,7 @@ namespace hgl
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.Finish(db,"Dome");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -650,7 +664,7 @@ namespace hgl
|
|||||||
|
|
||||||
Primitive *CreateTorus(RenderResource *db,const VIL *vil,const TorusCreateInfo *tci)
|
Primitive *CreateTorus(RenderResource *db,const VIL *vil,const TorusCreateInfo *tci)
|
||||||
{
|
{
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Torus");
|
||||||
|
|
||||||
// s, t = parametric values of the equations, in the range [0,1]
|
// s, t = parametric values of the equations, in the range [0,1]
|
||||||
float s = 0;
|
float s = 0;
|
||||||
@ -688,15 +702,18 @@ namespace hgl
|
|||||||
if(!rc.Init(numberVertices,numberIndices))
|
if(!rc.Init(numberVertices,numberIndices))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVAB<VB3f>(VAN::Position);
|
VABRawMapFloat vertex (&rc,VF_V3F,VAN::Position);
|
||||||
AutoDelete<VB3f> normal=rc.AccessVAB<VB3f>(VAN::Normal);
|
VABRawMapFloat normal (&rc,VF_V3F,VAN::Normal);
|
||||||
AutoDelete<VB3f> tangent=rc.AccessVAB<VB3f>(VAN::Tangent);
|
VABRawMapFloat tangent (&rc,VF_V3F,VAN::Tangent);
|
||||||
AutoDelete<VB2f> tex_coord=rc.AccessVAB<VB2f>(VAN::TexCoord);
|
VABRawMapFloat tex_coord(&rc,VF_V2F,VAN::TexCoord);
|
||||||
|
|
||||||
float *vp=vertex->Get();
|
float *vp=vertex;
|
||||||
float *np=normal?normal->Get():nullptr;
|
float *np=normal;
|
||||||
float *tp=tangent?tangent->Get():nullptr;
|
float *tp=tangent;
|
||||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
float *tcp=tex_coord;
|
||||||
|
|
||||||
|
if(!vp)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
// generate vertices and its attributes
|
// generate vertices and its attributes
|
||||||
for (sideCount = 0; sideCount <= tci->numberSlices; ++sideCount, s += sIncr)
|
for (sideCount = 0; sideCount <= tci->numberSlices; ++sideCount, s += sIncr)
|
||||||
@ -755,7 +772,7 @@ namespace hgl
|
|||||||
if(index_type==IndexType::U8 )CreateTorusIndices<uint8 >(rc.AccessIBO<uint8 >(),tci->numberSlices,tci->numberStacks);else
|
if(index_type==IndexType::U8 )CreateTorusIndices<uint8 >(rc.AccessIBO<uint8 >(),tci->numberSlices,tci->numberStacks);else
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
return rc.Finish(db,"Torus");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -815,7 +832,7 @@ namespace hgl
|
|||||||
if(numberIndices<=0)
|
if(numberIndices<=0)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Cylinder");
|
||||||
|
|
||||||
uint numberVertices = (cci->numberSlices + 2) * 2 + (cci->numberSlices + 1) * 2;
|
uint numberVertices = (cci->numberSlices + 2) * 2 + (cci->numberSlices + 1) * 2;
|
||||||
|
|
||||||
@ -827,15 +844,18 @@ namespace hgl
|
|||||||
if (cci->numberSlices < 3 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
if (cci->numberSlices < 3 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVAB<VB3f>(VAN::Position);
|
VABRawMapFloat vertex (&rc,VF_V3F,VAN::Position);
|
||||||
AutoDelete<VB3f> normal=rc.AccessVAB<VB3f>(VAN::Normal);
|
VABRawMapFloat normal (&rc,VF_V3F,VAN::Normal);
|
||||||
AutoDelete<VB3f> tangent=rc.AccessVAB<VB3f>(VAN::Tangent);
|
VABRawMapFloat tangent (&rc,VF_V3F,VAN::Tangent);
|
||||||
AutoDelete<VB2f> tex_coord=rc.AccessVAB<VB2f>(VAN::TexCoord);
|
VABRawMapFloat tex_coord(&rc,VF_V2F,VAN::TexCoord);
|
||||||
|
|
||||||
float *vp=vertex->Get();
|
float *vp=vertex;
|
||||||
float *np=normal?normal->Get():nullptr;
|
float *np=normal;
|
||||||
float *tp=tangent?tangent->Get():nullptr;
|
float *tp=tangent;
|
||||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
float *tcp=tex_coord;
|
||||||
|
|
||||||
|
if(!vp)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
*vp = 0.0f; ++vp;
|
*vp = 0.0f; ++vp;
|
||||||
*vp = 0.0f; ++vp;
|
*vp = 0.0f; ++vp;
|
||||||
@ -989,7 +1009,7 @@ namespace hgl
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.Finish(db,"Cylinder");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
@ -1034,7 +1054,7 @@ namespace hgl
|
|||||||
|
|
||||||
Primitive *CreateCone(RenderResource *db,const VIL *vil,const ConeCreateInfo *cci)
|
Primitive *CreateCone(RenderResource *db,const VIL *vil,const ConeCreateInfo *cci)
|
||||||
{
|
{
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Cone");
|
||||||
|
|
||||||
uint i, j;
|
uint i, j;
|
||||||
|
|
||||||
@ -1053,15 +1073,18 @@ namespace hgl
|
|||||||
if (cci->numberSlices < 3 || cci->numberStacks < 1 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
if (cci->numberSlices < 3 || cci->numberStacks < 1 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVAB<VB3f>(VAN::Position);
|
VABRawMapFloat vertex (&rc,VF_V3F,VAN::Position);
|
||||||
AutoDelete<VB3f> normal=rc.AccessVAB<VB3f>(VAN::Normal);
|
VABRawMapFloat normal (&rc,VF_V3F,VAN::Normal);
|
||||||
AutoDelete<VB3f> tangent=rc.AccessVAB<VB3f>(VAN::Tangent);
|
VABRawMapFloat tangent (&rc,VF_V3F,VAN::Tangent);
|
||||||
AutoDelete<VB2f> tex_coord=rc.AccessVAB<VB2f>(VAN::TexCoord);
|
VABRawMapFloat tex_coord(&rc,VF_V2F,VAN::TexCoord);
|
||||||
|
|
||||||
float *vp=vertex->Get();
|
float *vp=vertex;
|
||||||
float *np=normal?normal->Get():nullptr;
|
float *np=normal;
|
||||||
float *tp=tangent?tangent->Get():nullptr;
|
float *tp=tangent;
|
||||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
float *tcp=tex_coord;
|
||||||
|
|
||||||
|
if(!vp)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
*vp = 0.0f; ++vp;
|
*vp = 0.0f; ++vp;
|
||||||
*vp = 0.0f; ++vp;
|
*vp = 0.0f; ++vp;
|
||||||
@ -1160,22 +1183,22 @@ namespace hgl
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return rc.Finish(db,"Cone");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci)
|
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci)
|
||||||
{
|
{
|
||||||
if(!db||!vil||!aci)return(nullptr);
|
if(!db||!vil||!aci)return(nullptr);
|
||||||
|
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"Axis");
|
||||||
|
|
||||||
if(!rc.Init(6,0))
|
if(!rc.Init(6,0))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVAB<VB3f>(VAN::Position);
|
VABMap3f vertex(&rc,VAN::Position);
|
||||||
AutoDelete<VB4f> color=rc.AccessVAB<VB4f>(VAN::Color);
|
VABMap4f color(&rc,VAN::Color);
|
||||||
|
|
||||||
if(!vertex||!color)
|
if(!vertex.IsValid()||!color.IsValid())
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
const float s=aci->size;
|
const float s=aci->size;
|
||||||
@ -1187,7 +1210,7 @@ namespace hgl
|
|||||||
vertex->Write(0,0,0);color->Write(aci->color[2]);
|
vertex->Write(0,0,0);color->Write(aci->color[2]);
|
||||||
vertex->Write(0,0,s);color->Write(aci->color[2]);
|
vertex->Write(0,0,s);color->Write(aci->color[2]);
|
||||||
|
|
||||||
return rc.Finish(db,"Axis");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci)
|
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci)
|
||||||
@ -1212,24 +1235,21 @@ namespace hgl
|
|||||||
0,4, 1,5, 2,6, 3,7
|
0,4, 1,5, 2,6, 3,7
|
||||||
};
|
};
|
||||||
|
|
||||||
PrimitiveCreater rc(db->GetDevice(),vil);
|
PrimitiveCreater rc(db->GetDevice(),vil,"BoundingBox");
|
||||||
|
|
||||||
if(!rc.Init(8,24,IndexType::U16))
|
if(!rc.Init(8,24,IndexType::U16))
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
AutoDelete<VB3f> vertex=rc.AccessVAB<VB3f>(VAN::Position);
|
if(!rc.WriteVAB(VAN::Position,VF_V3F,points,sizeof(points)))
|
||||||
|
return(nullptr);
|
||||||
if(!vertex)return(nullptr);
|
|
||||||
|
|
||||||
rc.WriteVAB(VAN::Position,points,sizeof(points));
|
|
||||||
|
|
||||||
if(cci->color_type!=BoundingBoxCreateInfo::ColorType::NoColor)
|
if(cci->color_type!=BoundingBoxCreateInfo::ColorType::NoColor)
|
||||||
{
|
{
|
||||||
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
||||||
|
|
||||||
AutoDelete<VB4f> color=rc.AccessVAB<VB4f>(VAN::Color);
|
VABMap4f color(&rc,VAN::Color);
|
||||||
|
|
||||||
if(color)
|
if(color.IsValid())
|
||||||
{
|
{
|
||||||
if(cci->color_type==BoundingBoxCreateInfo::ColorType::SameColor)
|
if(cci->color_type==BoundingBoxCreateInfo::ColorType::SameColor)
|
||||||
color->RepeatWrite(cci->color[0],8);
|
color->RepeatWrite(cci->color[0],8);
|
||||||
@ -1241,7 +1261,7 @@ namespace hgl
|
|||||||
|
|
||||||
rc.WriteIBO<uint16>(indices);
|
rc.WriteIBO<uint16>(indices);
|
||||||
|
|
||||||
return rc.Finish(db,"BoundingBox");
|
return rc.Finish(db);
|
||||||
}
|
}
|
||||||
}//namespace inline_geometry
|
}//namespace inline_geometry
|
||||||
}//namespace graph
|
}//namespace graph
|
||||||
|
@ -5,16 +5,24 @@
|
|||||||
#include<hgl/graph/VertexDataManager.h>
|
#include<hgl/graph/VertexDataManager.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v)
|
|
||||||
|
PrimitiveData *CreatePrimitiveData(const VIL *_vil,const VkDeviceSize vc);
|
||||||
|
void SetIndexBuffer( PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic);
|
||||||
|
VABAccess * GetVABAccess( PrimitiveData *pd,const int);
|
||||||
|
void Destory( PrimitiveData *pd);
|
||||||
|
|
||||||
|
PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v,const AnsiString &name)
|
||||||
{
|
{
|
||||||
device =dev;
|
device =dev;
|
||||||
phy_device =device->GetPhysicalDevice();
|
phy_device =device->GetPhysicalDevice();
|
||||||
vil =v;
|
vil =v;
|
||||||
|
|
||||||
prim_data =hgl_zero_new<PrimitiveData>();
|
prim_name =name;
|
||||||
|
prim_data =nullptr;
|
||||||
|
|
||||||
vertices_number =0;
|
vertices_number =0;
|
||||||
hgl_zero(vab_ptr);
|
vab_proc_count =0;
|
||||||
|
index_number =0;
|
||||||
|
|
||||||
ibo =nullptr;
|
ibo =nullptr;
|
||||||
ibo_map =nullptr;
|
ibo_map =nullptr;
|
||||||
@ -34,24 +42,15 @@ PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v)
|
|||||||
// ibo_map =nullptr;
|
// ibo_map =nullptr;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
PrimitiveCreater::~PrimitiveCreater()
|
|
||||||
{
|
|
||||||
if(prim_data)
|
|
||||||
{
|
|
||||||
if(ibo_map)
|
|
||||||
ibo->Unmap();
|
|
||||||
|
|
||||||
delete prim_data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool PrimitiveCreater::Init(const VkDeviceSize vertex_count,const VkDeviceSize index_count,IndexType it)
|
bool PrimitiveCreater::Init(const VkDeviceSize vertex_count,const VkDeviceSize index_count,IndexType it)
|
||||||
{
|
{
|
||||||
if(vertex_count<=0)return(false);
|
if(vertex_count<=0)return(false);
|
||||||
|
|
||||||
vertices_number=vertex_count;
|
prim_data=CreatePrimitiveData(vil,vertex_count);
|
||||||
|
|
||||||
InitPrimitiveData(prim_data,vil,vertex_count);
|
if(!prim_data)return(false);
|
||||||
|
|
||||||
|
vertices_number=vertex_count;
|
||||||
|
|
||||||
if(index_count>0)
|
if(index_count>0)
|
||||||
{
|
{
|
||||||
@ -72,15 +71,25 @@ bool PrimitiveCreater::Init(const VkDeviceSize vertex_count,const VkDeviceSize i
|
|||||||
|
|
||||||
if(!ibo)return(false);
|
if(!ibo)return(false);
|
||||||
|
|
||||||
|
index_number=index_count;
|
||||||
|
|
||||||
SetIndexBuffer(prim_data,ibo,index_count);
|
SetIndexBuffer(prim_data,ibo,index_count);
|
||||||
|
|
||||||
ibo_map=ibo->Map();
|
#ifdef _DEBUG
|
||||||
|
DebugUtils *du=device->GetDebugUtils();
|
||||||
|
|
||||||
|
if(du)
|
||||||
|
{
|
||||||
|
du->SetBuffer( ibo->GetBuffer(), prim_name+":IndexBuffer:Buffer");
|
||||||
|
du->SetDeviceMemory(ibo->GetVkMemory(), prim_name+":IndexBuffer:Memory");
|
||||||
|
}
|
||||||
|
#endif//_DEBUG
|
||||||
}
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
VABAccess *PrimitiveCreater::AcquirePVB(const AnsiString &name,const VkFormat &acquire_format,const void *data)
|
VABAccess *PrimitiveCreater::AcquirePVB(const AnsiString &name,const VkFormat &acquire_format,const void *data,const VkDeviceSize bytes)
|
||||||
{
|
{
|
||||||
if(!vil)return(nullptr);
|
if(!vil)return(nullptr);
|
||||||
if(name.IsEmpty())return(nullptr);
|
if(name.IsEmpty())return(nullptr);
|
||||||
@ -98,121 +107,81 @@ VABAccess *PrimitiveCreater::AcquirePVB(const AnsiString &name,const VkFormat &a
|
|||||||
if(vif->format!=acquire_format)
|
if(vif->format!=acquire_format)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
VABAccess *vab=GetVAB(prim_data,index);
|
if(data)
|
||||||
|
if(vif->stride*vertices_number!=bytes)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
if(vab)
|
VABAccess *vab_access=GetVABAccess(prim_data,index);
|
||||||
return vab;
|
|
||||||
|
|
||||||
vad->vab =device->CreateVAB(vif->format,vertices_number,data);
|
if(!vab_access)
|
||||||
|
return(nullptr);
|
||||||
|
|
||||||
if(!data)
|
if(!vab_access->vab)
|
||||||
vad->map_ptr=vad->vab->Map();
|
{
|
||||||
else
|
vab_access->vab=device->CreateVAB(vif->format,vertices_number,data);
|
||||||
vad->map_ptr=nullptr;
|
vab_access->start=0;
|
||||||
|
vab_access->count=vertices_number;
|
||||||
|
|
||||||
vab_map.Add(name,*vad);
|
#ifdef _DEBUG
|
||||||
|
DebugUtils *du=device->GetDebugUtils();
|
||||||
|
|
||||||
return true;
|
if(du)
|
||||||
|
{
|
||||||
|
du->SetBuffer( vab_access->vab->GetBuffer(), prim_name+":VAB:Buffer:"+name);
|
||||||
|
du->SetDeviceMemory(vab_access->vab->GetVkMemory(), prim_name+":VAB:Memory:"+name);
|
||||||
|
}
|
||||||
|
#endif//_DEBUG
|
||||||
|
|
||||||
|
++vab_proc_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PrimitiveCreater::WriteVAB(const AnsiString &name,const void *data,const uint32_t bytes)
|
if(data)
|
||||||
{
|
vab_access->vab->Write(data,bytes);
|
||||||
if(!vil)return(false);
|
|
||||||
if(name.IsEmpty())return(false);
|
|
||||||
if(!data)return(false);
|
|
||||||
if(!bytes)return(false);
|
|
||||||
|
|
||||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
return vab_access;
|
||||||
|
|
||||||
if(!vif)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
if(vif->stride*vertices_number!=bytes)
|
|
||||||
return(false);
|
|
||||||
|
|
||||||
VABAccess vad;
|
|
||||||
|
|
||||||
return AcquirePVB(&vad,name,data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PrimitiveCreater::ClearAllData()
|
void PrimitiveCreater::ClearAllData()
|
||||||
{
|
{
|
||||||
if(vab_map.GetCount()>0)
|
if(ibo_map)
|
||||||
{
|
|
||||||
const auto *sp=vab_map.GetDataList();
|
|
||||||
for(int i=0;i<vab_map.GetCount();i++)
|
|
||||||
{
|
|
||||||
if((*sp)->value.vab)
|
|
||||||
{
|
|
||||||
(*sp)->value.vab->Unmap();
|
|
||||||
delete (*sp)->value.vab;
|
|
||||||
}
|
|
||||||
|
|
||||||
++sp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ibo)
|
|
||||||
{
|
{
|
||||||
ibo->Unmap();
|
ibo->Unmap();
|
||||||
delete ibo;
|
ibo_map=nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
ibo=nullptr;
|
ibo=nullptr;
|
||||||
|
|
||||||
|
if(prim_data)
|
||||||
|
{
|
||||||
|
Destory(prim_data);
|
||||||
|
prim_data=nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *PrimitiveCreater::Finish(RenderResource *rr,const AnsiString &prim_name)
|
Primitive *PrimitiveCreater::Finish(RenderResource *rr)
|
||||||
{
|
{
|
||||||
const uint si_count=vil->GetCount(VertexInputGroup::Basic);
|
const uint si_count=vil->GetCount(VertexInputGroup::Basic);
|
||||||
|
|
||||||
if(vab_map.GetCount()!=si_count)
|
if(vab_proc_count!=si_count)
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
|
|
||||||
Primitive *primitive=rr->CreatePrimitive(prim_name,vertices_number);
|
if(ibo_map)
|
||||||
|
|
||||||
{
|
{
|
||||||
const auto *sp=vab_map.GetDataList();
|
ibo->Unmap();
|
||||||
for(uint i=0;i<si_count;i++)
|
ibo_map=nullptr;
|
||||||
{
|
|
||||||
if((*sp)->value.vab)
|
|
||||||
{
|
|
||||||
if((*sp)->value.map_ptr)
|
|
||||||
(*sp)->value.vab->Unmap();
|
|
||||||
|
|
||||||
primitive->SetVAB((*sp)->key,(*sp)->value.vab);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
Primitive *primitive=rr->CreatePrimitive(prim_name,prim_data);
|
||||||
|
|
||||||
|
if(!primitive)
|
||||||
{
|
{
|
||||||
ClearAllData();
|
ClearAllData();
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
++sp;
|
ibo_map=nullptr;
|
||||||
}
|
ibo=nullptr;
|
||||||
}
|
prim_data=nullptr;
|
||||||
|
|
||||||
{
|
|
||||||
const auto *sp=vab_map.GetDataList();
|
|
||||||
for(uint i=0;i<si_count;i++)
|
|
||||||
{
|
|
||||||
if((*sp)->value.vab)
|
|
||||||
rr->Add((*sp)->value.vab);
|
|
||||||
|
|
||||||
++sp;
|
|
||||||
}
|
|
||||||
|
|
||||||
vab_map.Clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ibo)
|
|
||||||
{
|
|
||||||
ibo->Unmap();
|
|
||||||
primitive->SetIndex(ibo,0,index_number);
|
|
||||||
|
|
||||||
rr->Add(ibo);
|
|
||||||
ibo=nullptr; //避免释构函数删除
|
|
||||||
}
|
|
||||||
|
|
||||||
rr->Add(primitive);
|
|
||||||
|
|
||||||
return primitive;
|
return primitive;
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,66 @@
|
|||||||
#endif//_DEBUG
|
#endif//_DEBUG
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
|
|
||||||
|
const VkDeviceSize GetVertexCount( PrimitiveData *pd);
|
||||||
|
const int GetVABCount( PrimitiveData *pd);
|
||||||
|
VABAccess * GetVABAccess( PrimitiveData *pd,const AnsiString &name);
|
||||||
|
IBAccess * GetIBAccess( PrimitiveData *pd);
|
||||||
|
void Destory( PrimitiveData *pd);
|
||||||
|
void Free( PrimitiveData *pd);
|
||||||
|
|
||||||
|
class PrimitivePrivateBuffer:public Primitive
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
using Primitive::Primitive;
|
||||||
|
|
||||||
|
~PrimitivePrivateBuffer() override
|
||||||
|
{
|
||||||
|
Destory(prim_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend Primitive *CreatePrimitivePrivate(const AnsiString &,PrimitiveData *);
|
||||||
|
};//class PrimitivePrivateBuffer
|
||||||
|
|
||||||
|
class PrimitiveVDM:public Primitive
|
||||||
|
{
|
||||||
|
VertexDataManager *vdm;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
PrimitiveVDM(VertexDataManager *_vdm,const AnsiString &pn,PrimitiveData *pd):Primitive(pn,pd)
|
||||||
|
{
|
||||||
|
vdm=_vdm;
|
||||||
|
}
|
||||||
|
|
||||||
|
~PrimitiveVDM() override
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
Free(prim_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
friend Primitive *CreatePrimitivePrivate(VertexDataManager *,const AnsiString &,PrimitiveData *);
|
||||||
|
};//class PrimitiveVDM;
|
||||||
|
|
||||||
|
Primitive *CreatePrimitivePrivate(const AnsiString &name,PrimitiveData *pd)
|
||||||
|
{
|
||||||
|
if(!pd)return(nullptr);
|
||||||
|
if(name.IsEmpty())return(nullptr);
|
||||||
|
|
||||||
|
return(new PrimitivePrivateBuffer(name,pd));
|
||||||
|
}
|
||||||
|
|
||||||
|
Primitive *CreatePrimitivePrivate(VertexDataManager *vdm,const AnsiString &name,PrimitiveData *pd)
|
||||||
|
{
|
||||||
|
if(!vdm)return(nullptr);
|
||||||
|
if(!pd)return(nullptr);
|
||||||
|
if(name.IsEmpty())return(nullptr);
|
||||||
|
|
||||||
|
return(new PrimitiveVDM(vdm,name,pd));
|
||||||
|
}
|
||||||
|
|
||||||
//bool Renderable::Set(const int stage_input_binding,VIL *vil,VkDeviceSize offset)
|
//bool Renderable::Set(const int stage_input_binding,VIL *vil,VkDeviceSize offset)
|
||||||
//{
|
//{
|
||||||
// if(stage_input_binding<0||stage_input_binding>=buf_count||!vil)return(false);
|
// if(stage_input_binding<0||stage_input_binding>=buf_count||!vil)return(false);
|
||||||
@ -28,56 +88,24 @@ VK_NAMESPACE_BEGIN
|
|||||||
// return(true);
|
// return(true);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
bool Primitive::SetVAB(const AnsiString &name,VAB *vab,VkDeviceSize start)
|
const VkDeviceSize Primitive::GetVertexCount()const
|
||||||
{
|
{
|
||||||
if(!vab)return(false);
|
return VK_NAMESPACE::GetVertexCount(prim_data);
|
||||||
if(vab_access_map.KeyExist(name))return(false);
|
|
||||||
|
|
||||||
VABAccess vad;
|
|
||||||
|
|
||||||
vad.vab=vab;
|
|
||||||
vad.start=start;
|
|
||||||
|
|
||||||
vab_access_map.Add(name,vad);
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
DebugUtils *du=device->GetDebugUtils();
|
|
||||||
|
|
||||||
if(du)
|
|
||||||
{
|
|
||||||
du->SetBuffer(vab->GetBuffer(),prim_name+":VAB:Buffer:"+name);
|
|
||||||
du->SetDeviceMemory(vab->GetVkMemory(),prim_name+":VAB:Memory:"+name);
|
|
||||||
}
|
|
||||||
#endif//_DEBUG
|
|
||||||
|
|
||||||
return(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool Primitive::GetVABAccess(const AnsiString &name,VABAccess *vad)
|
const int Primitive::GetVACount()const
|
||||||
{
|
{
|
||||||
if(name.IsEmpty())return(false);
|
return GetVABCount(prim_data);
|
||||||
if(!vad)return(false);
|
|
||||||
|
|
||||||
return vab_access_map.Get(name,*vad);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Primitive::SetIndex(IndexBuffer *ib,VkDeviceSize start,const VkDeviceSize index_count)
|
VABAccess *Primitive::GetVABAccess(const AnsiString &name)
|
||||||
{
|
{
|
||||||
if(!ib)return(false);
|
return VK_NAMESPACE::GetVABAccess(prim_data,name);
|
||||||
|
}
|
||||||
|
|
||||||
ib_access.buffer=ib;
|
IBAccess *Primitive::GetIBAccess()
|
||||||
ib_access.start=start;
|
|
||||||
ib_access.count=index_count;
|
|
||||||
|
|
||||||
#ifdef _DEBUG
|
|
||||||
DebugUtils *du=device->GetDebugUtils();
|
|
||||||
|
|
||||||
if(du)
|
|
||||||
{
|
{
|
||||||
du->SetBuffer(ib->GetBuffer(),prim_name+":IBO:Buffer");
|
return VK_NAMESPACE::GetIBAccess(prim_data);
|
||||||
du->SetDeviceMemory(ib->GetVkMemory(),prim_name+":IBO:Memory");
|
|
||||||
}
|
|
||||||
#endif//_DEBUG
|
|
||||||
return(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
||||||
|
@ -1,18 +1,65 @@
|
|||||||
#include<hgl/graph/VKPrimitiveData.h>
|
#include<hgl/graph/VKVertexInputLayout.h>
|
||||||
|
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||||
|
#include<hgl/graph/VKIndexBuffer.h>
|
||||||
|
|
||||||
VK_NAMESPACE_BEGIN
|
VK_NAMESPACE_BEGIN
|
||||||
bool InitPrimitiveData(PrimitiveData *pd,const VIL *_vil,const VkDeviceSize vc)
|
struct PrimitiveData
|
||||||
{
|
{
|
||||||
if(!pd)return(false);
|
const VIL * vil;
|
||||||
if(!_vil)return(false);
|
|
||||||
if(vc<=0)return(false);
|
|
||||||
|
|
||||||
hgl_zero(*pd);
|
VkDeviceSize vertex_count;
|
||||||
|
|
||||||
|
/*
|
||||||
|
1.截止2024.4.27,根据vulkan.gpuinfo.org统计,只有9%的设备maxVertexInputAttributes为16,不存在低于16的设备。
|
||||||
|
9.0%的设备为28 - 31
|
||||||
|
70.7%的设备为32
|
||||||
|
9.6%的设备为64
|
||||||
|
|
||||||
|
由于我们暂时没有发现需要使用16个以上属性的情况,所以这里暂定使用16。
|
||||||
|
(如果时间过去久远,可再次查询此值是否可改成更高的值,以及是否需要)
|
||||||
|
|
||||||
|
2.为何va_name使用char[][]而不是String以及动态分配内存?
|
||||||
|
|
||||||
|
就是为了必避动态分配内存,以及可以直接memcpy处理,所以此处这样定义。
|
||||||
|
*/
|
||||||
|
|
||||||
|
VABAccess vab_access[HGL_MAX_VERTEX_ATTRIB_COUNT];
|
||||||
|
IBAccess ib_access;
|
||||||
|
};//struct PrimitiveData
|
||||||
|
|
||||||
|
PrimitiveData *CreatePrimitiveData(const VIL *_vil,const VkDeviceSize vc)
|
||||||
|
{
|
||||||
|
if(!_vil)return(nullptr);
|
||||||
|
if(vc<=0)return(nullptr);
|
||||||
|
|
||||||
|
PrimitiveData *pd=hgl_zero_new<PrimitiveData>();
|
||||||
|
|
||||||
pd->vil =_vil;
|
pd->vil =_vil;
|
||||||
pd->vertex_count=vc;
|
pd->vertex_count=vc;
|
||||||
|
|
||||||
return(true);
|
return(pd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Free(PrimitiveData *pd)
|
||||||
|
{
|
||||||
|
if(!pd)return;
|
||||||
|
|
||||||
|
delete pd;
|
||||||
|
}
|
||||||
|
|
||||||
|
const VkDeviceSize GetVertexCount(PrimitiveData *pd)
|
||||||
|
{
|
||||||
|
if(!pd)return(0);
|
||||||
|
|
||||||
|
return pd->vertex_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int GetVABCount(PrimitiveData *pd)
|
||||||
|
{
|
||||||
|
if(!pd)return(-1);
|
||||||
|
if(!pd->vil)return(-2);
|
||||||
|
|
||||||
|
return pd->vil->GetCount();
|
||||||
}
|
}
|
||||||
|
|
||||||
int GetVABIndex(const PrimitiveData *pd,const AnsiString &name)
|
int GetVABIndex(const PrimitiveData *pd,const AnsiString &name)
|
||||||
@ -24,7 +71,7 @@ int GetVABIndex(const PrimitiveData *pd,const AnsiString &name)
|
|||||||
return pd->vil->GetIndex(name);
|
return pd->vil->GetIndex(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
VABAccess *GetVAB(PrimitiveData *pd,const int index)
|
VABAccess *GetVABAccess(PrimitiveData *pd,const int index)
|
||||||
{
|
{
|
||||||
if(!pd)return(nullptr);
|
if(!pd)return(nullptr);
|
||||||
if(!pd->vil)return(nullptr);
|
if(!pd->vil)return(nullptr);
|
||||||
@ -33,29 +80,66 @@ VABAccess *GetVAB(PrimitiveData *pd,const int index)
|
|||||||
return pd->vab_access+index;
|
return pd->vab_access+index;
|
||||||
}
|
}
|
||||||
|
|
||||||
VABAccess *SetVAB(PrimitiveData *pd,const int index,VAB *vab,VkDeviceSize start,VkDeviceSize count)
|
VABAccess *GetVABAccess(PrimitiveData *pd,const AnsiString &name)
|
||||||
{
|
{
|
||||||
if(!pd)return(nullptr);
|
if(!pd)return(nullptr);
|
||||||
if(!pd->vil)return(nullptr);
|
if(!pd->vil)return(nullptr);
|
||||||
if(index<0||index>=pd->vil->GetCount())return(nullptr);
|
if(name.IsEmpty())return(nullptr);
|
||||||
|
|
||||||
VABAccess *vaba=pd->vab_access+index;
|
const int index=pd->vil->GetIndex(name);
|
||||||
|
|
||||||
vaba->vab=vab;
|
if(index<0)return(nullptr);
|
||||||
vaba->start=start;
|
|
||||||
vaba->count=count;
|
|
||||||
|
|
||||||
//#ifdef _DEBUG
|
return pd->vab_access+index;
|
||||||
// DebugUtils *du=device->GetDebugUtils();
|
}
|
||||||
|
|
||||||
// if(du)
|
//VABAccess *SetVAB(PrimitiveData *pd,const int index,VAB *vab,VkDeviceSize start,VkDeviceSize count)
|
||||||
//{
|
//{
|
||||||
// du->SetBuffer(vab->GetBuffer(),prim_name+":VAB:Buffer:"+name);
|
// if(!pd)return(nullptr);
|
||||||
// du->SetDeviceMemory(vab->GetVkMemory(),prim_name+":VAB:Memory:"+name);
|
// if(!pd->vil)return(nullptr);
|
||||||
|
// if(index<0||index>=pd->vil->GetCount())return(nullptr);
|
||||||
|
//
|
||||||
|
// VABAccess *vaba=pd->vab_access+index;
|
||||||
|
//
|
||||||
|
// vaba->vab=vab;
|
||||||
|
// vaba->start=start;
|
||||||
|
// vaba->count=count;
|
||||||
|
//
|
||||||
|
// //#ifdef _DEBUG
|
||||||
|
// // DebugUtils *du=device->GetDebugUtils();
|
||||||
|
//
|
||||||
|
// // if(du)
|
||||||
|
// // {
|
||||||
|
// // du->SetBuffer(vab->GetBuffer(),prim_name+":VAB:Buffer:"+name);
|
||||||
|
// // du->SetDeviceMemory(vab->GetVkMemory(),prim_name+":VAB:Memory:"+name);
|
||||||
|
// // }
|
||||||
|
// //#endif//_DEBUG
|
||||||
|
//
|
||||||
|
// return vaba;
|
||||||
//}
|
//}
|
||||||
//#endif//_DEBUG
|
|
||||||
|
|
||||||
return vaba;
|
void Destory(PrimitiveData *pd)
|
||||||
|
{
|
||||||
|
if(!pd)return;
|
||||||
|
|
||||||
|
VABAccess *vab=pd->vab_access;
|
||||||
|
|
||||||
|
for(uint32_t i=0;i<pd->vil->GetCount();i++)
|
||||||
|
{
|
||||||
|
if(vab->vab)
|
||||||
|
{
|
||||||
|
delete vab->vab;
|
||||||
|
vab->vab=nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
++vab;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(pd->ib_access.buffer)
|
||||||
|
{
|
||||||
|
delete pd->ib_access.buffer;
|
||||||
|
pd->ib_access.buffer=nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetIndexBuffer(PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic)
|
void SetIndexBuffer(PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic)
|
||||||
@ -67,4 +151,11 @@ void SetIndexBuffer(PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic)
|
|||||||
pd->ib_access.count=ic;
|
pd->ib_access.count=ic;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
IBAccess *GetIBAccess(PrimitiveData *pd)
|
||||||
|
{
|
||||||
|
if(!pd)return(nullptr);
|
||||||
|
|
||||||
|
return &(pd->ib_access);
|
||||||
|
}
|
||||||
|
|
||||||
VK_NAMESPACE_END
|
VK_NAMESPACE_END
|
@ -80,16 +80,34 @@ MaterialInstance *RenderResource::CreateMaterialInstance(const mtl::MaterialCrea
|
|||||||
return CreateMaterialInstance(mtl,vil_cfg);
|
return CreateMaterialInstance(mtl,vil_cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
Primitive *RenderResource::CreatePrimitive(const AnsiString &name,const uint32_t vertex_count)
|
Primitive *CreatePrimitivePrivate(const AnsiString &,PrimitiveData *);
|
||||||
|
|
||||||
|
Primitive *RenderResource::CreatePrimitive(const AnsiString &name,PrimitiveData *pd)
|
||||||
{
|
{
|
||||||
if(!vertex_count)return(nullptr);
|
if(!pd)return(nullptr);
|
||||||
|
|
||||||
Primitive *ro=new Primitive(device,name,vertex_count);
|
Primitive *prim=CreatePrimitivePrivate(name,pd);
|
||||||
|
|
||||||
if(ro)
|
if(prim)
|
||||||
Add(ro);
|
Add(prim);
|
||||||
|
|
||||||
return ro;
|
return prim;
|
||||||
|
}
|
||||||
|
|
||||||
|
Primitive *CreatePrimitivePrivate(VertexDataManager *,const AnsiString &,PrimitiveData *);
|
||||||
|
|
||||||
|
Primitive *RenderResource::CreatePrimitive(VertexDataManager *vdm,const AnsiString &name,PrimitiveData *pd)
|
||||||
|
{
|
||||||
|
if(!vdm)return(nullptr);
|
||||||
|
if(!pd)return(nullptr);
|
||||||
|
if(name.IsEmpty())return(nullptr);
|
||||||
|
|
||||||
|
Primitive *prim=CreatePrimitivePrivate(vdm,name,pd);
|
||||||
|
|
||||||
|
if(prim)
|
||||||
|
Add(prim);
|
||||||
|
|
||||||
|
return prim;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderable *RenderResource::CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
Renderable *RenderResource::CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||||
|
@ -58,48 +58,46 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
|||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
VAB *vab;
|
|
||||||
|
|
||||||
VertexInputData *vid=new VertexInputData(input_count,prim->GetVertexCount(),prim->GetIBAccess());
|
VertexInputData *vid=new VertexInputData(input_count,prim->GetVertexCount(),prim->GetIBAccess());
|
||||||
|
|
||||||
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
||||||
VABAccess vad;
|
VABAccess *vab_access;
|
||||||
|
|
||||||
for(uint i=0;i<input_count;i++)
|
for(uint i=0;i<input_count;i++)
|
||||||
{
|
{
|
||||||
//注: VIF来自于材质,但VAB来自于Primitive。
|
//注: VIF来自于材质,但VAB来自于Primitive。
|
||||||
// 两个并不一定一样,排序也不一定一样。所以不能让PRIMTIVE直接提供BUFFER_LIST/OFFSET来搞一次性绑定。
|
// 两个并不一定一样,排序也不一定一样。所以不能让PRIMTIVE直接提供BUFFER_LIST/OFFSET来搞一次性绑定。
|
||||||
|
|
||||||
if(!prim->GetVABAccess(vif->name,&vad))
|
vab_access=prim->GetVABAccess(vif->name);
|
||||||
|
|
||||||
|
if(!vab_access||!vab_access->vab)
|
||||||
{
|
{
|
||||||
LOG_ERROR("[FATAL ERROR] not found VAB \""+AnsiString(vif->name)+"\" in Material: "+mtl_name);
|
LOG_ERROR("[FATAL ERROR] not found VAB \""+AnsiString(vif->name)+"\" in Material: "+mtl_name);
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
vab=vad.vab;
|
if(vab_access->vab->GetFormat()!=vif->format)
|
||||||
|
|
||||||
if(vab->GetFormat()!=vif->format)
|
|
||||||
{
|
{
|
||||||
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
|
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
|
||||||
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
||||||
UTF8String(") Format(")+GetVulkanFormatName(vif->format)+
|
UTF8String(") Format(")+GetVulkanFormatName(vif->format)+
|
||||||
UTF8String("), VAB Format(")+GetVulkanFormatName(vab->GetFormat())+
|
UTF8String("), VAB Format(")+GetVulkanFormatName(vab_access->vab->GetFormat())+
|
||||||
")");
|
")");
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(vab->GetStride()!=vif->stride)
|
if(vab_access->vab->GetStride()!=vif->stride)
|
||||||
{
|
{
|
||||||
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
|
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
|
||||||
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
||||||
UTF8String(") stride(")+UTF8String::numberOf(vif->stride)+
|
UTF8String(") stride(")+UTF8String::numberOf(vif->stride)+
|
||||||
UTF8String("), VAB stride(")+UTF8String::numberOf(vab->GetStride())+
|
UTF8String("), VAB stride(")+UTF8String::numberOf(vab_access->vab->GetStride())+
|
||||||
")");
|
")");
|
||||||
return(nullptr);
|
return(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
vid->buffer_offset[i]=vad.start;
|
vid->buffer_offset[i]=vab_access->start;
|
||||||
vid->buffer_list[i]=vab->GetBuffer();
|
vid->buffer_list[i]=vab_access->vab->GetBuffer();
|
||||||
++vif;
|
++vif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user