Compare commits
70 Commits
Resume_L2W
...
devel_30_R
Author | SHA1 | Date | |
---|---|---|---|
a5e76988c7 | |||
08a348392d | |||
0dfb7220b5 | |||
4a94d78c1f | |||
9a4e495027 | |||
6de3cf789a | |||
299d3bd019 | |||
78b1982849 | |||
8a0215aee6 | |||
419e0e2574 | |||
cfd67e1a42 | |||
c49feac2e6 | |||
bf50333f5b | |||
40ce978f85 | |||
e27442a0b4 | |||
ecb47dae4d | |||
6892a64393 | |||
3af753ee36 | |||
f31437bf67 | |||
14fbbd6fa6 | |||
4e6adcd765 | |||
ead4ba65c1 | |||
310cc151fa | |||
03491dbed8 | |||
40094a7529 | |||
6ad3b9edb7 | |||
21a63f4a9b | |||
11ebb841be | |||
ad330f3a42 | |||
bbf94767fe | |||
6dba761a80 | |||
5391f0f4aa | |||
a1bf9336a3 | |||
9c6c37c07a | |||
3bbbe18c40 | |||
d8140ae64e | |||
acb69d3bf5 | |||
f0c47cd4f1 | |||
0b1a0cadae | |||
8633a18e01 | |||
2bc6246dc0 | |||
0a752446b0 | |||
c32f56fbe2 | |||
b100b4b9cb | |||
d20e9cf1e3 | |||
621e056315 | |||
4fc74d38ba | |||
f00cb0b815 | |||
e1d45a7c83 | |||
c5b8dbe8f6 | |||
172ee7bb7b | |||
d41530dad3 | |||
6efb50c977 | |||
f4493b09e5 | |||
af8f62ddb4 | |||
fff7fd3af0 | |||
2fdd7e7bd5 | |||
4ebc8a3260 | |||
5892b075c3 | |||
07a478a2ac | |||
8c51d3a52b | |||
c1183d351d | |||
d4c1dd312e | |||
3c22b48f3c | |||
02169963de | |||
ac81e4f8f0 | |||
1d3bec4098 | |||
3252d1581c | |||
01bf8b3dd2 | |||
1c03e838e5 |
2
CMCore
2
CMCore
Submodule CMCore updated: cf13064cea...d70d31288f
Submodule CMSceneGraph updated: d395ee152f...a6a3680312
@@ -116,7 +116,7 @@ private:
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V2F,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
|
@@ -138,7 +138,7 @@ private:
|
||||
Primitive *primitive=db->CreatePrimitive(VERTEX_COUNT);
|
||||
if(!primitive)return(false);
|
||||
|
||||
if(!primitive->Set(VAN::Position, db->CreateVBO(VF_V4I16,VERTEX_COUNT,position_data)))return(false);
|
||||
if(!primitive->Set(VAN::Position, db->CreateVAB(VF_V4I16,VERTEX_COUNT,position_data)))return(false);
|
||||
|
||||
render_obj=db->CreateRenderable(primitive,material_instance,pipeline);
|
||||
return(true);
|
||||
|
@@ -24,7 +24,8 @@ constexpr float position_data[VERTEX_COUNT*2]=
|
||||
};
|
||||
|
||||
constexpr uint8 color_data[VERTEX_COUNT][4]=
|
||||
{ {255,0,0,255},
|
||||
{
|
||||
{255,0,0,255},
|
||||
{0,255,0,255},
|
||||
{0,0,255,255}
|
||||
};
|
||||
@@ -73,8 +74,8 @@ private:
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
|
||||
|
@@ -86,7 +86,7 @@ private:
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
|
||||
for(uint i=0;i<DRAW_OBJECT_COUNT;i++)
|
||||
{
|
||||
|
@@ -114,8 +114,8 @@ private:
|
||||
Float32toFloat16(position_data_hf,position_data_float,VERTEX_COUNT*2);
|
||||
#endif//USE_HALF_FLOAT_POSITION
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
if(!rpc.SetVAB(VAN::Position, PositionFormat, position_data))return(false);
|
||||
if(!rpc.SetVAB(VAN::Color, ColorFormat, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(render_obj);
|
||||
|
@@ -57,10 +57,10 @@ private:
|
||||
// ^
|
||||
// + 这上下两种格式要配套,否则会出错
|
||||
// v
|
||||
vil_config.Add(VAN::Position,VF_V2U16); //这里指定VBO中使用RG16U当做顶点数据格式
|
||||
vil_config.Add(VAN::Position,VF_V2U16); //这里指定VAB中使用RG16U当做顶点数据格式
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
vil_config.Add(VAN::Color,VF_V4UN8); //这里指定VBO中使用RGBA8UNorm当做颜色数据格式
|
||||
vil_config.Add(VAN::Color,VF_V4UN8); //这里指定VAB中使用RGBA8UNorm当做颜色数据格式
|
||||
|
||||
cfg.local_to_world=false;
|
||||
|
||||
@@ -82,12 +82,12 @@ private:
|
||||
RenderablePrimitiveCreater rpc(db,"Triangle",VERTEX_COUNT);
|
||||
|
||||
#ifdef USE_ZERO2ONE_COORD //使用0 to 1坐标系
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data_float ))return(false);
|
||||
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data_float ))return(false);
|
||||
#else //使用ortho坐标系
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2U16, position_data_u16 ))return(false);
|
||||
if(!rpc.SetVAB(VAN::Position, VF_V2U16, position_data_u16 ))return(false);
|
||||
#endif//USE_ZERO2ONE_COORD
|
||||
|
||||
if(!rpc.SetVBO(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
if(!rpc.SetVAB(VAN::Color, VF_V4UN8, color_data ))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(true);
|
||||
|
@@ -180,8 +180,8 @@ private:
|
||||
for(Color4f &c:color_data[1])c=Color4f(0,1,0,1);
|
||||
for(Color4f &c:color_data[2])c=Color4f(0,0,1,1);
|
||||
|
||||
if(!ro_line->Set(VAN::Position, db->CreateVBO(VF_V3F,AXIS_MAX_VERTICES,position_data)))return(false);
|
||||
if(!ro_line->Set(VAN::Color, db->CreateVBO(VF_V4F,AXIS_MAX_VERTICES,color_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Position, db->CreateVAB(VF_V3F,AXIS_MAX_VERTICES,position_data)))return(false);
|
||||
if(!ro_line->Set(VAN::Color, db->CreateVAB(VF_V4F,AXIS_MAX_VERTICES,color_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
|
@@ -6,7 +6,6 @@
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/RenderList.h>
|
||||
#include<hgl/graph/Camera.h>
|
||||
#include<hgl/graph/VKRenderablePrimitiveCreater.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
|
||||
using namespace hgl;
|
||||
|
@@ -38,11 +38,11 @@ private:
|
||||
|
||||
Pipeline * pipeline =nullptr;
|
||||
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
Primitive * prim_plane_grid =nullptr;
|
||||
|
||||
Primitive * ro_line =nullptr;
|
||||
|
||||
VBO * vbo_pos =nullptr;
|
||||
VAB * vab_pos =nullptr;
|
||||
|
||||
Ray ray;
|
||||
|
||||
@@ -106,8 +106,8 @@ private:
|
||||
ro_line=db->CreatePrimitive("Line",2);
|
||||
if(!ro_line)return(false);
|
||||
|
||||
if(!ro_line->Set(VAN::Position, vbo_pos= db->CreateVBO(VF_V3F,2,position_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Luminance, db->CreateVBO(VF_V1F,2,lumiance_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Position, vab_pos= db->CreateVAB(VF_V3F,2,position_data )))return(false);
|
||||
if(!ro_line->Set(VAN::Luminance, db->CreateVAB(VF_V1F,2,lumiance_data )))return(false);
|
||||
}
|
||||
|
||||
return(true);
|
||||
@@ -156,7 +156,7 @@ public:
|
||||
|
||||
const Vector3f pos=ray.ClosestPoint(Vector3f(0,0,0)); //求射线上与点(0,0,0)最近的点的坐标
|
||||
|
||||
vbo_pos->Write(&pos,3*sizeof(float)); //更新VBO上这个点的位置
|
||||
vab_pos->Write(&pos,3*sizeof(float)); //更新VAB上这个点的位置
|
||||
|
||||
SceneAppFramework::BuildCommandBuffer(index);
|
||||
}
|
||||
|
@@ -10,7 +10,8 @@
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/BlinnPhong.h>
|
||||
#include<hgl/color/Color.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
@@ -33,50 +34,6 @@ constexpr const COLOR AxisColor[4]=
|
||||
COLOR::White //全局颜色
|
||||
};
|
||||
|
||||
class VertexDataManager
|
||||
{
|
||||
uint vi_count; ///<顶点输入流数量
|
||||
const VertexInputFormat * vif_list; ///<顶点输入格式列表
|
||||
|
||||
VkDeviceSize vbo_max_size; ///<顶点缓冲区分配空间大小
|
||||
VkDeviceSize vbo_cur_size; ///<顶点缓冲区当前使用大小
|
||||
VBO ** vbo; ///<顶点缓冲区列表
|
||||
|
||||
VkDeviceSize ibo_cur_size; ///<索引缓冲区当前使用大小
|
||||
IndexBuffer * ibo; ///<索引缓冲区
|
||||
|
||||
struct DataOffset
|
||||
{
|
||||
VkDeviceSize vbo_start;
|
||||
VkDeviceSize vbo_size;
|
||||
|
||||
VkDeviceSize ibo_start;
|
||||
VkDeviceSize ibo_size;
|
||||
};
|
||||
|
||||
public:
|
||||
|
||||
VertexDataManager(const VIL &_vil)
|
||||
{
|
||||
vi_count=_vil.GetCount();
|
||||
vif_list=_vil.GetVIFList();
|
||||
|
||||
vbo_max_size=0;
|
||||
vbo_cur_size=0;
|
||||
vbo=hgl_zero_new<VBO *>(vi_count);
|
||||
|
||||
ibo_cur_size=0;
|
||||
ibo=nullptr;
|
||||
}
|
||||
|
||||
const VkDeviceSize GetVBOMaxCount()const{return vbo_max_size;} ///<取得顶点缓冲区分配的空间最大数量
|
||||
const VkDeviceSize GetVBOCurCount()const{return vbo_cur_size;} ///<取得顶点缓冲区当前数量
|
||||
|
||||
const IndexType GetIBOType ()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引缓冲区类型
|
||||
const VkDeviceSize GetIBOMaxCount ()const{return ibo?ibo->GetCount():-1;} ///<取得索引缓冲区分配的空间最大数量
|
||||
const VkDeviceSize GetIBOCurCount ()const{return ibo?ibo_cur_size:-1;} ///<取得索引缓冲区当前数量
|
||||
};//class VertexDataManager
|
||||
|
||||
class TestApp:public SceneAppFramework
|
||||
{
|
||||
private: //plane grid
|
||||
@@ -93,6 +50,9 @@ private:
|
||||
private: //sphere
|
||||
|
||||
Material * mtl_blinnphong =nullptr;
|
||||
PrimitiveCreater * pc_blinnphong =nullptr;
|
||||
VertexDataManager * vdm_blinnphong =nullptr;
|
||||
|
||||
MaterialInstance * mi_blinnphong[4]{};
|
||||
Pipeline * p_blinnphong =nullptr;
|
||||
|
||||
@@ -104,7 +64,7 @@ private:
|
||||
|
||||
bool InitVertexLumMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",Prim::Lines);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"VertexLuminance3D",false,Prim::Lines);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
@@ -132,7 +92,7 @@ private:
|
||||
|
||||
bool InitBlinnPhongSunLightMP()
|
||||
{
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"BlinnPhong3D",Prim::Triangles);
|
||||
mtl::Material3DCreateConfig cfg(device->GetDeviceAttribute(),"BlinnPhong3D",true,Prim::Triangles);
|
||||
|
||||
cfg.local_to_world=true;
|
||||
|
||||
@@ -147,7 +107,9 @@ private:
|
||||
{
|
||||
mi_data=GetColor4f(AxisColor[i],4);
|
||||
|
||||
mi_blinnphong[i]=db->CreateMaterialInstance(mtl_blinnphong,nullptr,&mi_data);
|
||||
mi_blinnphong[i]=db->CreateMaterialInstance(mtl_blinnphong, //材质
|
||||
nullptr, //顶点输入配置,这里使用nullptr,即代表会使用默认配置,那么结果将等同于上面的mtl_blinnphong->GetDefaultVIL()
|
||||
&mi_data); //材质实例参数
|
||||
if(!mi_blinnphong[i])return(false);
|
||||
}
|
||||
|
||||
@@ -156,7 +118,26 @@ private:
|
||||
if(!p_blinnphong)
|
||||
return(false);
|
||||
|
||||
return(true);
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool InitVDMAndPC()
|
||||
{
|
||||
vdm_blinnphong=new VertexDataManager(device,mtl_blinnphong->GetDefaultVIL());
|
||||
if(!vdm_blinnphong->Init( 1024*1024, //VAB最大容量
|
||||
1024*1024, //索引最大容量
|
||||
IndexType::U16)) //索引类型
|
||||
{
|
||||
delete vdm_blinnphong;
|
||||
vdm_blinnphong=nullptr;
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
pc_blinnphong=new PrimitiveCreater(vdm_blinnphong);
|
||||
//pc_blinnphong=new PrimitiveCreater(device,mtl_blinnphong->GetDefaultVIL());
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
bool CreateRenderObject()
|
||||
@@ -164,20 +145,20 @@ private:
|
||||
using namespace inline_geometry;
|
||||
|
||||
//Plane Grid
|
||||
{
|
||||
struct PlaneGridCreateInfo pgci;
|
||||
//{
|
||||
// struct PlaneGridCreateInfo pgci;
|
||||
|
||||
pgci.grid_size.Set(32,32);
|
||||
pgci.sub_count.Set(8,8);
|
||||
// pgci.grid_size.Set(32,32);
|
||||
// pgci.sub_count.Set(8,8);
|
||||
|
||||
pgci.lum=0.5;
|
||||
pgci.sub_lum=0.75;
|
||||
// pgci.lum=0.5;
|
||||
// pgci.sub_lum=0.75;
|
||||
|
||||
prim_plane_grid=CreatePlaneGrid(db,mtl_vertex_lum->GetDefaultVIL(),&pgci);
|
||||
}
|
||||
// prim_plane_grid=CreatePlaneGrid(pc_blinnphong,mtl_vertex_lum->GetDefaultVIL(),&pgci);
|
||||
//}
|
||||
|
||||
//Sphere
|
||||
prim_sphere=CreateSphere(db,mi_blinnphong[0]->GetVIL(),16);
|
||||
prim_sphere=CreateSphere(pc_blinnphong,16);
|
||||
|
||||
//Cone
|
||||
{
|
||||
@@ -188,7 +169,7 @@ private:
|
||||
cci.numberSlices=16; //圆锥底部分割数
|
||||
cci.numberStacks=8; //圆锥高度分割数
|
||||
|
||||
prim_cone=CreateCone(db,mi_blinnphong[1]->GetVIL(),&cci);
|
||||
prim_cone=CreateCone(pc_blinnphong,&cci);
|
||||
}
|
||||
|
||||
//Cyliner
|
||||
@@ -199,7 +180,7 @@ private:
|
||||
cci.numberSlices=16; //圆柱底部分割数
|
||||
cci.radius =0.25f; //圆柱半径
|
||||
|
||||
prim_cylinder=CreateCylinder(db,mi_blinnphong[2]->GetVIL(),&cci);
|
||||
prim_cylinder=CreateCylinder(pc_blinnphong,&cci);
|
||||
}
|
||||
|
||||
return(true);
|
||||
@@ -207,11 +188,18 @@ private:
|
||||
|
||||
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);
|
||||
|
||||
if(!ri)
|
||||
{
|
||||
LOG_ERROR(OS_TEXT("Create Renderable failed."));
|
||||
LOG_ERROR(U8_TEXT("Create Renderable failed! Primitive: ")+r->GetName());
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
@@ -222,7 +210,7 @@ private:
|
||||
|
||||
bool InitScene()
|
||||
{
|
||||
Add(prim_plane_grid,mi_plane_grid,p_line,Identity4f);
|
||||
//Add(prim_plane_grid,mi_plane_grid,p_line,Identity4f);
|
||||
|
||||
Add(prim_sphere, mi_blinnphong[0],p_blinnphong,translate(Vector3f(0,0,2)));
|
||||
|
||||
@@ -255,6 +243,9 @@ public:
|
||||
if(!InitBlinnPhongSunLightMP())
|
||||
return(false);
|
||||
|
||||
if(!InitVDMAndPC())
|
||||
return(false);
|
||||
|
||||
if(!CreateRenderObject())
|
||||
return(false);
|
||||
|
||||
@@ -263,6 +254,17 @@ public:
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
~TestApp()
|
||||
{
|
||||
SAFE_CLEAR(prim_cone)
|
||||
SAFE_CLEAR(prim_cylinder)
|
||||
SAFE_CLEAR(prim_sphere)
|
||||
SAFE_CLEAR(prim_plane_grid)
|
||||
|
||||
SAFE_CLEAR(pc_blinnphong)
|
||||
SAFE_CLEAR(vdm_blinnphong)
|
||||
}
|
||||
};//class TestApp:public CameraAppFramework
|
||||
|
||||
int main(int,char **)
|
||||
|
@@ -87,8 +87,8 @@ private:
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Quad",VERTEX_COUNT);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||
if(!rpc.SetVAB(VAN::Position, VF_V2F, position_data))return(false);
|
||||
if(!rpc.SetVAB(VAN::TexCoord, VF_V2F, tex_coord_data))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(render_obj);
|
||||
|
@@ -83,8 +83,8 @@ private:
|
||||
{
|
||||
RenderablePrimitiveCreater rpc(db,"Rectangle",1);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
if(!rpc.SetVAB(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.SetVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
render_obj=rpc.Create(material_instance,pipeline);
|
||||
return(render_obj);
|
||||
|
@@ -132,8 +132,8 @@ private:
|
||||
|
||||
position_data[2]=1.0f/float(TexCount);
|
||||
|
||||
if(!rpc.SetVBO(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.SetVBO(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
if(!rpc.SetVAB(VAN::Position,VF_V4F,position_data))return(false);
|
||||
if(!rpc.SetVAB(VAN::TexCoord,VF_V4F,tex_coord_data))return(false);
|
||||
|
||||
Vector3f offset(1.0f/float(TexCount),0,0);
|
||||
|
||||
|
@@ -132,7 +132,7 @@ public:
|
||||
{
|
||||
VulkanHardwareRequirement vh_req;
|
||||
|
||||
vh_req.wide_lines=true;
|
||||
vh_req.wideLines=VulkanHardwareRequirement::SupportLevel::Want;
|
||||
|
||||
device=CreateRenderDevice(inst,win,&vh_req);
|
||||
|
||||
@@ -225,12 +225,7 @@ public:
|
||||
cb->BindPipeline(ri->GetPipeline());
|
||||
cb->BindDescriptorSets(ri->GetMaterial());
|
||||
cb->BindVBO(ri);
|
||||
|
||||
if (vid->index_buffer->buffer)
|
||||
cb->DrawIndexed(vid->index_buffer->buffer->GetCount());
|
||||
else
|
||||
cb->Draw(vid->vertex_count);
|
||||
|
||||
cb->Draw(vid);
|
||||
cb->EndRenderPass();
|
||||
cb->End();
|
||||
|
||||
|
@@ -11,6 +11,8 @@ namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
class PrimitiveCreater;
|
||||
|
||||
namespace inline_geometry
|
||||
{
|
||||
/**
|
||||
@@ -21,12 +23,12 @@ namespace hgl
|
||||
RectScope2f scope;
|
||||
};//struct RectangleCreateInfo
|
||||
|
||||
Primitive *CreateRectangle(RenderResource *db,const VIL *vil,const RectangleCreateInfo *rci);
|
||||
Primitive *CreateRectangle(PrimitiveCreater *pc,const RectangleCreateInfo *rci);
|
||||
|
||||
/**
|
||||
* 创建延迟渲染用全屏平面
|
||||
*/
|
||||
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil);
|
||||
Primitive *CreateGBufferCompositionRectangle(PrimitiveCreater *pc);
|
||||
|
||||
/**
|
||||
* 圆角矩形创建信息(扇形/线圈)
|
||||
@@ -37,7 +39,7 @@ namespace hgl
|
||||
uint32_t round_per; ///<圆角精度
|
||||
};//struct RoundRectangleCreateInfo:public RectangleCreateInfo
|
||||
|
||||
Primitive *CreateRoundRectangle(RenderResource *db,const VIL *vil,const RoundRectangleCreateInfo *rci);
|
||||
Primitive *CreateRoundRectangle(PrimitiveCreater *pc,const RoundRectangleCreateInfo *rci);
|
||||
|
||||
/**
|
||||
* 圆形创建信息
|
||||
@@ -57,7 +59,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个2D圆形(扇形/线圈)
|
||||
*/
|
||||
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci);
|
||||
Primitive *CreateCircle(PrimitiveCreater *pc,const CircleCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 平面网格创建信息<br>
|
||||
@@ -76,12 +78,12 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个平面网格(线条)
|
||||
*/
|
||||
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci);
|
||||
Primitive *CreatePlaneGrid(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci);
|
||||
|
||||
/**
|
||||
* 创建一个平面(三角形)
|
||||
*/
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil);
|
||||
Primitive *CreatePlane(PrimitiveCreater *pc);
|
||||
|
||||
struct CubeCreateInfo
|
||||
{
|
||||
@@ -117,7 +119,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个立方体(三角形)
|
||||
*/
|
||||
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci);
|
||||
Primitive *CreateCube(PrimitiveCreater *pc,const CubeCreateInfo *cci);
|
||||
|
||||
struct BoundingBoxCreateInfo
|
||||
{
|
||||
@@ -148,17 +150,17 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个绑定盒(线条)
|
||||
*/
|
||||
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci);
|
||||
Primitive *CreateBoundingBox(PrimitiveCreater *pc,const BoundingBoxCreateInfo *cci);
|
||||
|
||||
/**
|
||||
* 创建一个球心坐标为0,0,0,半径为1的球体(三角形)
|
||||
*/
|
||||
Primitive *CreateSphere(RenderResource *db,const VIL *vil,const uint numberSlices);
|
||||
Primitive *CreateSphere(PrimitiveCreater *,const uint numberSlices);
|
||||
|
||||
/**
|
||||
* 创建一个穹顶(三角形)
|
||||
*/
|
||||
Primitive *CreateDome(RenderResource *db,const VIL *vil, const uint numberSlices);
|
||||
Primitive *CreateDome(PrimitiveCreater *pc, const uint numberSlices);
|
||||
|
||||
struct TorusCreateInfo
|
||||
{
|
||||
@@ -174,7 +176,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆环(三角形)
|
||||
*/
|
||||
Primitive *CreateTorus(RenderResource *db,const VIL *vil,const TorusCreateInfo *tci);
|
||||
Primitive *CreateTorus(PrimitiveCreater *pc,const TorusCreateInfo *tci);
|
||||
|
||||
struct CylinderCreateInfo
|
||||
{
|
||||
@@ -186,7 +188,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆柱(三角形)
|
||||
*/
|
||||
Primitive *CreateCylinder(RenderResource *db,const VIL *vil,const CylinderCreateInfo *cci);
|
||||
Primitive *CreateCylinder(PrimitiveCreater *,const CylinderCreateInfo *cci);
|
||||
|
||||
struct ConeCreateInfo
|
||||
{
|
||||
@@ -199,7 +201,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个圆锥(三角形)
|
||||
*/
|
||||
Primitive *CreateCone(RenderResource *db,const VIL *vil,const ConeCreateInfo *cci);
|
||||
Primitive *CreateCone(PrimitiveCreater *,const ConeCreateInfo *cci);
|
||||
|
||||
struct AxisCreateInfo
|
||||
{
|
||||
@@ -220,7 +222,7 @@ namespace hgl
|
||||
/**
|
||||
* 创建一个坐标线(线条)
|
||||
*/
|
||||
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci);
|
||||
Primitive *CreateAxis(PrimitiveCreater *pc,const AxisCreateInfo *aci);
|
||||
}//namespace inline_geometry
|
||||
}//namespace graph
|
||||
};//namespace hgl
|
||||
|
@@ -4,7 +4,7 @@
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
class RenderL2WBuffer;
|
||||
class RenderMIBuffer;
|
||||
class RenderAssignBuffer;
|
||||
|
||||
/**
|
||||
* 同一材质的对象渲染列表
|
||||
@@ -20,8 +20,7 @@ class MaterialRenderList
|
||||
|
||||
private:
|
||||
|
||||
RenderL2WBuffer *l2w_buffer;
|
||||
RenderMIBuffer *mi_buffer;
|
||||
RenderAssignBuffer *assign_buffer;
|
||||
|
||||
struct RenderItem
|
||||
{
|
||||
@@ -37,13 +36,9 @@ private:
|
||||
void Set(Renderable *);
|
||||
};
|
||||
|
||||
MaterialInstanceSets mi_set;
|
||||
DataArray<RenderItem> ri_array;
|
||||
uint ri_count;
|
||||
|
||||
VkDeviceSize l2w_buffer_size[4];
|
||||
|
||||
void StatMI();
|
||||
void Stat();
|
||||
|
||||
protected:
|
||||
|
@@ -1,85 +1,221 @@
|
||||
#ifndef HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
#define HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
namespace hgl
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
/**
|
||||
* 可绘制图元创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 可绘制图元创建器
|
||||
*/
|
||||
class PrimitiveCreater
|
||||
{
|
||||
struct PrimitiveVertexBuffer
|
||||
{
|
||||
AnsiString name;
|
||||
uint binding;
|
||||
VAD * data =nullptr;
|
||||
VBO * vbo =nullptr;
|
||||
protected:
|
||||
|
||||
public:
|
||||
GPUDevice * device;
|
||||
VertexDataManager * vdm;
|
||||
|
||||
~PrimitiveVertexBuffer()
|
||||
{
|
||||
SAFE_CLEAR(data);
|
||||
}
|
||||
};//struct PrimitiveVertexBuffer
|
||||
const VIL * vil;
|
||||
|
||||
using PVBMap=ObjectMap<AnsiString,PrimitiveVertexBuffer>;
|
||||
protected:
|
||||
|
||||
protected:
|
||||
AnsiString prim_name;
|
||||
PrimitiveData * prim_data;
|
||||
|
||||
VkDeviceSize vertices_number; ///<顶点数量
|
||||
|
||||
RenderResource *db;
|
||||
Material *mtl;
|
||||
VkDeviceSize index_number; ///<索引数量
|
||||
IndexType index_type; ///<索引类型
|
||||
IBAccess * iba; ///<索引缓冲区
|
||||
|
||||
const VIL *vil;
|
||||
public:
|
||||
|
||||
protected:
|
||||
PrimitiveCreater(GPUDevice *,const VIL *);
|
||||
PrimitiveCreater(VertexDataManager *);
|
||||
virtual ~PrimitiveCreater();
|
||||
|
||||
uint32 vertices_number;
|
||||
virtual bool Init(const AnsiString &name,const VkDeviceSize vertices_count,const VkDeviceSize index_count,IndexType it=IndexType::AUTO); ///<初始化,参数为顶点数量
|
||||
|
||||
IndexBuffer * ibo;
|
||||
PVBMap vbo_map;
|
||||
void Clear(); ///<清除创建器数据
|
||||
|
||||
public: //顶点缓冲区
|
||||
|
||||
public:
|
||||
const VkDeviceSize GetVertexCount()const{ return vertices_number; } ///<取得顶点数量
|
||||
|
||||
PrimitiveCreater(RenderResource *sdb,const VIL *);
|
||||
virtual ~PrimitiveCreater()=default;
|
||||
|
||||
virtual bool Init(const uint32 vertices_count); ///<初始化,参数为顶点数量
|
||||
|
||||
VAD * CreateVAD(const AnsiString &name); ///<创建一个顶点属性缓冲区
|
||||
|
||||
template<typename T>
|
||||
T * AccessVAD(const AnsiString &name) ///<创建一个顶点属性缓冲区以及访问器
|
||||
VABAccess * AcquireVAB (const AnsiString &name,const VkFormat &format,const void *data=nullptr); ///<请求一个顶点属性数据区
|
||||
bool WriteVAB (const AnsiString &name,const VkFormat &format,const void *data) ///<直接写入顶点属性数据
|
||||
{
|
||||
const VkFormat format=vil->GetVulkanFormat(name);
|
||||
|
||||
if(format!=T::GetVulkanFormat())
|
||||
return(nullptr);
|
||||
|
||||
VAD *vad=this->CreateVAD(name);
|
||||
|
||||
if(!vad)
|
||||
return(nullptr);
|
||||
|
||||
T *access=T::Create(vad);
|
||||
|
||||
access->Begin();
|
||||
|
||||
return access;
|
||||
return AcquireVAB(name,format,data);
|
||||
}
|
||||
|
||||
bool WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes); ///<直接写入顶点属性数据
|
||||
public: //索引缓冲区
|
||||
|
||||
uint16 * CreateIBO16(uint count,const uint16 *data=nullptr); ///<创建16位的索引缓冲区
|
||||
uint32 * CreateIBO32(uint count,const uint32 *data=nullptr); ///<创建32位的索引缓冲区
|
||||
const IndexType GetIndexType()const{return index_type;}
|
||||
|
||||
virtual Primitive * Finish(const AnsiString &); ///<结束并创建可渲染对象
|
||||
};//class PrimitiveCreater
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_PRIMITIVE_CREATER_INCLUDE
|
||||
void * MapIBO();
|
||||
void UnmapIBO();
|
||||
|
||||
bool WriteIBO(const void *data,const VkDeviceSize count);
|
||||
|
||||
template<typename T>
|
||||
bool WriteIBO(const T *data){return WriteIBO(data,index_number);}
|
||||
|
||||
public: //创建可渲染对象
|
||||
|
||||
virtual Primitive * Create(); ///<创建一个可渲染对象,并清除创建器数据
|
||||
};//class PrimitiveCreater
|
||||
|
||||
/**
|
||||
* VAB原生数据访问映射
|
||||
*/
|
||||
template<typename T> class VABRawMap
|
||||
{
|
||||
VABAccess *vaba;
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
VABRawMap(PrimitiveCreater *pc,const VkFormat &format,const AnsiString &name)
|
||||
{
|
||||
vaba=pc->AcquireVAB(name,format);
|
||||
|
||||
if(vaba)
|
||||
map_ptr=(T *)(vaba->vab->Map(vaba->start,vaba->count));
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
~VABRawMap()
|
||||
{
|
||||
if(vaba)
|
||||
vaba->vab->Unmap();
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return vaba; }
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
};//template<typename T> class VABRawMap
|
||||
|
||||
typedef VABRawMap<int8> VABRawMapi8, VABRawMapByte;
|
||||
typedef VABRawMap<int16> VABRawMapi16,VABRawMapShort;
|
||||
typedef VABRawMap<int32> VABRawMapi32,VABRawMapInt;
|
||||
typedef VABRawMap<uint8> VABRawMapu8, VABRawMapUByte;
|
||||
typedef VABRawMap<uint16> VABRawMapu16,VABRawMapUShort;
|
||||
typedef VABRawMap<uint32> VABRawMapu32,VABRawMapUInt;
|
||||
typedef VABRawMap<float> VABRawMapFloat;
|
||||
typedef VABRawMap<double> VABRawMapDouble;
|
||||
|
||||
/**
|
||||
* VAB VertexAttribDataAccess数据访问映射
|
||||
*/
|
||||
template<typename T> class VABMap
|
||||
{
|
||||
VABAccess *vaba;
|
||||
T *vb;
|
||||
|
||||
public:
|
||||
|
||||
VABMap(PrimitiveCreater *pc,const AnsiString &name)
|
||||
{
|
||||
vaba=pc->AcquireVAB(name,T::GetVulkanFormat(),nullptr);
|
||||
|
||||
if(vaba)
|
||||
{
|
||||
void *map_ptr=vaba->vab->Map(vaba->start,vaba->count);
|
||||
|
||||
vb=T::Create(pc->GetVertexCount(),map_ptr);
|
||||
|
||||
vb->Begin();
|
||||
}
|
||||
else
|
||||
{
|
||||
vb=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
~VABMap()
|
||||
{
|
||||
if(vaba)
|
||||
vaba->vab->Unmap();
|
||||
}
|
||||
|
||||
void Restart()
|
||||
{
|
||||
if(vb)
|
||||
vb->Begin();
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return vb; }
|
||||
|
||||
T *operator->(){ return vb; }
|
||||
};//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
|
||||
{
|
||||
PrimitiveCreater *pc;
|
||||
T *map_ptr;
|
||||
|
||||
public:
|
||||
|
||||
IBMap(PrimitiveCreater *c)
|
||||
{
|
||||
pc=c;
|
||||
|
||||
if(pc)
|
||||
map_ptr=(T *)(pc->MapIBO());
|
||||
else
|
||||
map_ptr=nullptr;
|
||||
}
|
||||
|
||||
~IBMap()
|
||||
{
|
||||
if(map_ptr&&pc)
|
||||
pc->UnmapIBO();
|
||||
}
|
||||
|
||||
const bool IsValid()const{ return map_ptr; }
|
||||
|
||||
operator T *(){ return map_ptr; }
|
||||
};//template<typename T> class IBMap
|
||||
|
||||
using IBMapU8=IBMap<uint8>;
|
||||
using IBMapU16=IBMap<uint16>;
|
||||
using IBMapU32=IBMap<uint32>;
|
||||
|
||||
VK_NAMESPACE_END
|
@@ -8,11 +8,7 @@ namespace hgl
|
||||
namespace graph
|
||||
{
|
||||
class Renderable;
|
||||
class Material;
|
||||
class MaterialInstance;
|
||||
class GPUDevice;
|
||||
struct VertexInputData;
|
||||
struct IndexBufferData;
|
||||
|
||||
struct RenderNode
|
||||
{
|
||||
|
@@ -20,7 +20,7 @@ namespace hgl
|
||||
|
||||
AABB BoundingBox; ///<绑定盒
|
||||
AABB LocalBoundingBox; ///<本地坐标绑定盒
|
||||
AABB WorldBoundingBox; ///<世界坐标绑定盒
|
||||
//AABB WorldBoundingBox; ///<世界坐标绑定盒
|
||||
|
||||
Vector4f Center; ///<中心点
|
||||
Vector4f LocalCenter; ///<本地坐标中心点
|
||||
@@ -97,7 +97,7 @@ namespace hgl
|
||||
|
||||
virtual const AABB & GetBoundingBox ()const{return BoundingBox;} ///<取得绑定盒
|
||||
virtual const AABB & GetLocalBoundingBox ()const{return LocalBoundingBox;} ///<取得本地坐标绑定盒
|
||||
virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
||||
// virtual const AABB & GetWorldBoundingBox ()const{return WorldBoundingBox;} ///<取得世界坐标绑定盒
|
||||
|
||||
virtual const Vector4f & GetCenter ()const{return Center;} ///<取得中心点
|
||||
virtual const Vector4f & GetLocalCenter ()const{return LocalCenter;} ///<取得本地坐标中心点
|
||||
|
@@ -25,8 +25,6 @@ constexpr size_t VK_DESCRIPTOR_TYPE_END_RANGE=VK_DESCRIPTOR_TYPE_INPUT_ATTACHMEN
|
||||
constexpr size_t VK_DESCRIPTOR_TYPE_RANGE_SIZE=VK_DESCRIPTOR_TYPE_END_RANGE-VK_DESCRIPTOR_TYPE_BEGIN_RANGE+1;
|
||||
#endif//VK_DESCRIPTOR_TYPE_RANGE_SIZE
|
||||
|
||||
using CharPointerList=hgl::List<const char *>;
|
||||
|
||||
using BindingMap =Map<AnsiString,int>;
|
||||
using BindingMapArray =BindingMap[VK_DESCRIPTOR_TYPE_RANGE_SIZE];
|
||||
|
||||
@@ -56,17 +54,33 @@ class DeviceMemory;
|
||||
class DeviceBuffer;
|
||||
struct DeviceBufferData;
|
||||
|
||||
struct VertexInputData;
|
||||
|
||||
class VertexAttribBuffer;
|
||||
using VBO=VertexAttribBuffer;
|
||||
using VAB=VertexAttribBuffer;
|
||||
|
||||
struct VABAccess
|
||||
{
|
||||
VAB *vab;
|
||||
VkDeviceSize start;
|
||||
VkDeviceSize count;
|
||||
|
||||
public:
|
||||
|
||||
CompOperatorMemcmp(const VABAccess &);
|
||||
};//class VABAccess
|
||||
|
||||
class IndexBuffer;
|
||||
|
||||
struct IndexBufferData
|
||||
struct IndexBufferAccess
|
||||
{
|
||||
IndexBuffer *buffer=nullptr;
|
||||
VkDeviceSize offset=0;
|
||||
IndexBuffer *buffer;
|
||||
VkDeviceSize start;
|
||||
VkDeviceSize count;
|
||||
};
|
||||
|
||||
using IBAccess=IndexBufferAccess;
|
||||
|
||||
class GPUCmdBuffer;
|
||||
class RenderCmdBuffer;
|
||||
class TextureCmdBuffer;
|
||||
@@ -99,13 +113,16 @@ class VILConfig;
|
||||
class VertexInput;
|
||||
|
||||
struct VertexInputFormat;
|
||||
using VIF=VertexInputFormat;
|
||||
|
||||
class VertexInputLayout;
|
||||
using VIL=VertexInputLayout;
|
||||
|
||||
class PrimitiveData;
|
||||
class Primitive;
|
||||
class Renderable;
|
||||
|
||||
class VertexDataManager;
|
||||
class RenderResource;
|
||||
|
||||
enum class SharingMode
|
||||
@@ -139,8 +156,9 @@ inline const uint32_t GetMipLevel(const VkExtent3D &ext)
|
||||
/**
|
||||
* 索引类型,等同于VkIndexType
|
||||
*/
|
||||
enum IndexType:uint
|
||||
enum IndexType:int
|
||||
{
|
||||
AUTO=-1,
|
||||
U16=0,
|
||||
U32,
|
||||
U8=VK_INDEX_TYPE_UINT8_EXT,
|
||||
@@ -148,6 +166,11 @@ enum IndexType:uint
|
||||
ERR=VK_INDEX_TYPE_MAX_ENUM
|
||||
};
|
||||
|
||||
inline const bool IsIndexType(const IndexType it)
|
||||
{
|
||||
return it>=U16&&it<=U8;
|
||||
}
|
||||
|
||||
//Push Constant max-lengths:
|
||||
//
|
||||
// 256 bytes: nvidia,arm
|
||||
|
@@ -42,11 +42,11 @@ public:
|
||||
void * Map () {return buf.memory->Map();}
|
||||
virtual void * Map (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Map(start,size);}
|
||||
void Unmap () {return buf.memory->Unmap();}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Flush(start,size);}
|
||||
void Flush (VkDeviceSize size) {return buf.memory->Flush(size);}
|
||||
virtual void Flush (VkDeviceSize start,VkDeviceSize size) {return buf.memory->Flush(start,size);}
|
||||
virtual void Flush (VkDeviceSize size) {return buf.memory->Flush(size);}
|
||||
|
||||
bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);}
|
||||
bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
|
||||
virtual bool Write (const void *ptr,uint32_t start,uint32_t size) {return buf.memory->Write(ptr,start,size);}
|
||||
virtual bool Write (const void *ptr,uint32_t size) {return buf.memory->Write(ptr,0,size);}
|
||||
bool Write (const void *ptr) {return buf.memory->Write(ptr);}
|
||||
};//class DeviceBuffer
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -154,9 +154,9 @@ public:
|
||||
void PushConstants(const void *data,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,0, size,data);}
|
||||
void PushConstants(const void *data,const uint32_t offset,const uint32_t size) {vkCmdPushConstants(cmd_buf,pipeline_layout,VK_SHADER_STAGE_VERTEX_BIT,offset, size,data);}
|
||||
|
||||
void BindVBO(const uint32_t first,const uint32_t count,const VkBuffer *vbo,const VkDeviceSize *offsets)
|
||||
void BindVBO(const uint32_t first,const uint32_t count,const VkBuffer *vab,const VkDeviceSize *offsets)
|
||||
{
|
||||
vkCmdBindVertexBuffers(cmd_buf,first,count,vbo,offsets);
|
||||
vkCmdBindVertexBuffers(cmd_buf,first,count,vab,offsets);
|
||||
}
|
||||
|
||||
bool BindVBO(VBOList *vbo_list)
|
||||
@@ -170,7 +170,7 @@ public:
|
||||
return(true);
|
||||
}
|
||||
|
||||
void BindIBO(const IndexBufferData *);
|
||||
// void BindIBO(const IBAccess *);
|
||||
|
||||
bool BindVBO(Renderable *);
|
||||
|
||||
@@ -192,14 +192,17 @@ public: //draw
|
||||
void Draw (const uint32_t vertex_count,const uint32_t instance_count) {vkCmdDraw(cmd_buf,vertex_count,instance_count,0,0);}
|
||||
void DrawIndexed (const uint32_t index_count ,const uint32_t instance_count) {vkCmdDrawIndexed(cmd_buf,index_count,instance_count,0,0,0);}
|
||||
|
||||
template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
||||
template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
||||
// template<typename ...ARGS> void Draw (ARGS...args) {vkCmdDraw(cmd_buf,args...);}
|
||||
// template<typename ...ARGS> void DrawIndexed (ARGS...args) {vkCmdDrawIndexed(cmd_buf,args...);}
|
||||
|
||||
void DrawIndirect (VkBuffer,VkDeviceSize, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand ));
|
||||
void DrawIndexedIndirect(VkBuffer,VkDeviceSize, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand ));
|
||||
void DrawIndirect (VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndirectCommand )){return DrawIndirect( buf,0,drawCount,stride);}
|
||||
void DrawIndexedIndirect(VkBuffer buf, uint32_t drawCount,uint32_t stride=sizeof(VkDrawIndexedIndirectCommand )){return DrawIndexedIndirect( buf,0,drawCount,stride);}
|
||||
|
||||
void Draw (const VertexInputData *vid);
|
||||
void DrawIndexed (const IBAccess *iba,const uint32_t instance_count);
|
||||
|
||||
public: //dynamic state
|
||||
};//class RenderCmdBuffer:public GPUCmdBuffer
|
||||
|
||||
|
@@ -13,7 +13,6 @@
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
#include<hgl/graph/VKSwapchain.h>
|
||||
#include<hgl/graph/VKRenderTarget.h>
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKShaderModuleMap.h>
|
||||
#include<hgl/graph/VKArrayBuffer.h>
|
||||
#include<hgl/graph/VKDescriptorSetType.h>
|
||||
@@ -115,9 +114,11 @@ public: //Buffer相关
|
||||
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size,const void *data, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,data,sm);}
|
||||
DeviceBuffer * CreateBuffer(VkBufferUsageFlags buf_usage, VkDeviceSize size, SharingMode sm=SharingMode::Exclusive){return CreateBuffer(buf_usage,size,size,nullptr,sm);}
|
||||
|
||||
VBO * CreateVBO (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VBO * CreateVBO (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format,count,nullptr,sm);}
|
||||
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
VAB * CreateVAB (VkFormat format, uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VAB * CreateVAB (VkFormat format, uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVAB(format,count,nullptr,sm);}
|
||||
|
||||
const IndexType ChooseIndexType (const VkDeviceSize &vertex_count)const; ///<求一个合适的索引类型
|
||||
const bool CheckIndexType (const IndexType,const VkDeviceSize &vertex_count)const; ///<检测一个索引类型是否合适
|
||||
|
||||
IndexBuffer * CreateIBO (IndexType type, uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
|
||||
IndexBuffer * CreateIBO8 ( uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U8, count,(void *)data,sm);}
|
||||
|
@@ -39,6 +39,9 @@ struct GPUDeviceAttribute
|
||||
VkSurfaceTransformFlagBitsKHR preTransform;
|
||||
VkCompositeAlphaFlagBitsKHR compositeAlpha =VK_COMPOSITE_ALPHA_OPAQUE_BIT_KHR;
|
||||
|
||||
bool uint8_index_type=false;
|
||||
bool uint32_index_type=false;
|
||||
|
||||
VkDevice device =VK_NULL_HANDLE;
|
||||
VkCommandPool cmd_pool =VK_NULL_HANDLE;
|
||||
|
||||
|
@@ -4,41 +4,54 @@
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
struct VulkanHardwareRequirement
|
||||
{
|
||||
uint min_1d_image_size;
|
||||
uint min_2d_image_size;
|
||||
uint min_3d_image_size;
|
||||
uint min_cube_image_size;
|
||||
uint min_array_image_layers;
|
||||
enum class SupportLevel
|
||||
{
|
||||
DontCare=0, ///<不介意
|
||||
Want, ///<希望支持
|
||||
Must, ///<必须支持
|
||||
};
|
||||
|
||||
uint min_vertex_input_attribute; ///<最小顶点输入属性数量需求
|
||||
uint min_color_attachments; ///<最小颜色输出成份数量需求
|
||||
//这里使用这种大小写是为了和VulkanSDK中的定义保持一致,cpp中使用宏比较和复制时只使用一个名字即可
|
||||
|
||||
uint min_push_constant_size; ///<最小push constant大小
|
||||
uint min_ubo_range; ///<最小ubo range需求
|
||||
uint min_ssbo_range; ///<最小ssbo range需求
|
||||
uint maxImageDimension1D;
|
||||
uint maxImageDimension2D;
|
||||
uint maxImageDimension3D;
|
||||
uint maxImageDimensionCube;
|
||||
uint maxImageArrayLayers;
|
||||
|
||||
uint min_draw_indirect_count; ///<最小间接绘制次数需求
|
||||
uint maxVertexInputAttributes; ///<最大顶点输入属性数量需求
|
||||
uint maxColorAttachments; ///<最大颜色输出成份数量需求
|
||||
|
||||
bool geometry_shader; ///<要求支持几何着色器
|
||||
bool tessellation_shader; ///<要求支持细分着色器
|
||||
// bool compute_shader; ///<要求支持计算着色器
|
||||
uint maxPushConstantsSize; ///<最大push constant大小
|
||||
uint maxUniformBufferRange; ///<最大ubo range需求
|
||||
uint maxStorageBufferRange; ///<最大ssbo range需求
|
||||
|
||||
bool multi_draw_indirect; ///<要求支持MultiDrawIndirect
|
||||
uint maxDrawIndirectCount; ///<最大间接绘制次数需求
|
||||
|
||||
bool wide_lines; ///<要求支持宽线条
|
||||
bool line_rasterization; ///<要支持线条特性(这功能mac/ios平台不支持)
|
||||
bool large_points; ///<要求支持绘制大点
|
||||
SupportLevel geometryShader; ///<要求支持几何着色器
|
||||
SupportLevel tessellationShader; ///<要求支持细分着色器
|
||||
|
||||
bool texture_cube_array; ///<要求支持立方体数组纹理
|
||||
SupportLevel sampleRateShading; ///<要求支持采样率着色
|
||||
|
||||
bool uint8_draw_index; ///<要求支持8位索引
|
||||
bool uint32_draw_index; ///<要求支持32位索引(不建议使用)
|
||||
SupportLevel multiDrawIndirect; ///<要求支持MultiDrawIndirect
|
||||
|
||||
SupportLevel fillModeNonSolid; ///<要求支持非实体填充模式
|
||||
|
||||
SupportLevel wideLines; ///<要求支持宽线条
|
||||
SupportLevel lineRasterization; ///<要支持线条特性(这功能mac/ios平台不支持)
|
||||
SupportLevel largePoints; ///<要求支持绘制大点
|
||||
|
||||
SupportLevel imageCubeArray; ///<要求支持立方体数组纹理
|
||||
|
||||
SupportLevel fullDrawIndexUint8; ///<要求支持8位索引
|
||||
SupportLevel fullDrawIndexUint32; ///<要求支持32位索引
|
||||
|
||||
struct
|
||||
{
|
||||
bool bc,etc2,astc_ldr,astc_hdr,pvrtc; ///<要求支持的压缩纹理格式
|
||||
SupportLevel BC,ETC2,ASTC_LDR,ASTC_HDR,PVRTC; ///<要求支持的压缩纹理格式
|
||||
}texture_compression;
|
||||
|
||||
//dynamic_state VK_EXT_extended_dynamic_state
|
||||
@@ -47,7 +60,7 @@ struct VulkanHardwareRequirement
|
||||
// primitive topology
|
||||
// viewport
|
||||
// scissor
|
||||
// bind vbo
|
||||
// bind vab
|
||||
// depth test
|
||||
// depth write
|
||||
// depth compare op
|
||||
@@ -78,12 +91,12 @@ struct VulkanHardwareRequirement
|
||||
// line stipple
|
||||
// depth clip -1 to 1
|
||||
// shading rate image enable
|
||||
bool dynamic_state[3]; ///<要求支持动态状态
|
||||
SupportLevel dynamicState[3]; ///<要求支持动态状态
|
||||
|
||||
// 1.3 特性
|
||||
bool dynamic_rendering; ///<要求支持动态渲染
|
||||
SupportLevel dynamicRendering; ///<要求支持动态渲染
|
||||
|
||||
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
|
||||
uint32_t descriptor_pool; ///<描述符池大小(默认1024)
|
||||
|
||||
public:
|
||||
|
||||
@@ -93,7 +106,10 @@ public:
|
||||
|
||||
descriptor_pool=1024;
|
||||
|
||||
geometry_shader=true;
|
||||
geometryShader=SupportLevel::Want;
|
||||
|
||||
fullDrawIndexUint8=SupportLevel::Want;
|
||||
fullDrawIndexUint32=SupportLevel::Want;
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_INDEX_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
@@ -9,8 +9,9 @@ namespace hgl
|
||||
{
|
||||
class IndexBuffer:public DeviceBuffer
|
||||
{
|
||||
IndexType index_type;
|
||||
uint32_t count;
|
||||
IndexType index_type;
|
||||
uint stride;
|
||||
uint32_t count;
|
||||
|
||||
private:
|
||||
|
||||
@@ -20,14 +21,29 @@ namespace hgl
|
||||
{
|
||||
index_type=it;
|
||||
count=_count;
|
||||
|
||||
if(index_type==IndexType::U16)stride=2;else
|
||||
if(index_type==IndexType::U32)stride=4;else
|
||||
if(index_type==IndexType::U8)stride=1;else
|
||||
stride=0;
|
||||
}
|
||||
|
||||
public:
|
||||
|
||||
~IndexBuffer()=default;
|
||||
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint32 GetCount()const{return count;}
|
||||
const IndexType GetType ()const{return index_type;}
|
||||
const uint GetStride ()const{return stride;}
|
||||
const uint32 GetCount ()const{return count;}
|
||||
|
||||
public:
|
||||
|
||||
void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride); }
|
||||
void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);}
|
||||
|
||||
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
|
||||
|
@@ -27,6 +27,7 @@ class GPUPhysicalDevice
|
||||
|
||||
private:
|
||||
|
||||
bool support_u8_index=false;
|
||||
bool dynamic_state=false;
|
||||
|
||||
public:
|
||||
@@ -141,8 +142,13 @@ public:
|
||||
public:
|
||||
|
||||
const VkBool32 SupportGeometryShader ()const{return features.geometryShader;}
|
||||
const VkBool32 SupportTessellationShader ()const{return features.tessellationShader;}
|
||||
|
||||
const VkBool32 SupportCubeMapArray ()const{return features.imageCubeArray;}
|
||||
|
||||
const VkBool32 SupportU32Index ()const{return features.fullDrawIndexUint32;}
|
||||
const VkBool32 SupportU8Index ()const{return support_u8_index;}
|
||||
|
||||
// support != open, so please don't direct use GetFeatures().
|
||||
// open any features in CreateDevice()&SetDeviceFeatures() functions.
|
||||
const bool SupportMDI ()const
|
||||
|
@@ -1,80 +1,50 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/type/Map.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/math/Math.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* 单一图元数据
|
||||
* 单一图元数据访问接口<br>
|
||||
*
|
||||
* 这个只是单纯的提供原始VAB/IB数据,派生为两类
|
||||
*
|
||||
* 一类是传统的,使用独统的独立VAB的
|
||||
* 一类是使用VDM的
|
||||
*
|
||||
*
|
||||
*
|
||||
* WIP: *** 1.将数据全部转移到PrimitiveData,完成旧的渲染测试
|
||||
* 2.改成抽象类,将独立VAB的做成一个实现
|
||||
* 3.实现VDM支持
|
||||
*/
|
||||
class Primitive
|
||||
{
|
||||
GPUDevice *device;
|
||||
AnsiString prim_name;
|
||||
|
||||
struct VBOData
|
||||
{
|
||||
VBO *buf;
|
||||
VkDeviceSize offset;
|
||||
|
||||
public:
|
||||
|
||||
CompOperatorMemcmp(const VBOData &);
|
||||
};
|
||||
|
||||
Map<AnsiString,VBOData> buffer_list;
|
||||
|
||||
protected:
|
||||
|
||||
uint32_t vertex_count;
|
||||
AnsiString prim_name;
|
||||
|
||||
IndexBufferData index_buffer_data;
|
||||
PrimitiveData * prim_data;
|
||||
|
||||
protected:
|
||||
|
||||
AABB BoundingBox;
|
||||
|
||||
public:
|
||||
|
||||
protected:
|
||||
|
||||
friend class RenderableNode;
|
||||
|
||||
uint ref_count=0;
|
||||
|
||||
uint RefInc(){return ++ref_count;}
|
||||
uint RefDec(){return --ref_count;}
|
||||
Primitive(const AnsiString &pn,PrimitiveData *pd);
|
||||
virtual ~Primitive();
|
||||
|
||||
public:
|
||||
|
||||
Primitive(GPUDevice *dev,const AnsiString &n,const uint32_t vc=0)
|
||||
{
|
||||
device=dev;
|
||||
prim_name=n;
|
||||
vertex_count=vc;
|
||||
}
|
||||
const AnsiString & GetName ()const{ return prim_name; }
|
||||
const VkDeviceSize GetVertexCount ()const;
|
||||
const int GetVABCount ()const;
|
||||
VABAccess * GetVABAccess (const AnsiString &);
|
||||
IBAccess * GetIBAccess ();
|
||||
|
||||
virtual ~Primitive()=default;
|
||||
|
||||
const uint GetRefCount()const{return ref_count;}
|
||||
|
||||
void SetBoundingBox(const AABB &aabb){BoundingBox=aabb;}
|
||||
const AABB & GetBoundingBox()const {return BoundingBox;}
|
||||
|
||||
bool Set(const AnsiString &name,VBO *vb,VkDeviceSize offset=0);
|
||||
|
||||
bool Set(IndexBuffer *ib,VkDeviceSize offset=0);
|
||||
|
||||
public:
|
||||
|
||||
const uint32_t GetVertexCount ()const {return vertex_count;}
|
||||
|
||||
VBO * GetVBO (const AnsiString &,VkDeviceSize *);
|
||||
VkBuffer GetBuffer (const AnsiString &,VkDeviceSize *);
|
||||
const int GetBufferCount ()const {return buffer_list.GetCount();}
|
||||
|
||||
const IndexBufferData * GetIndexBufferData ()const {return &index_buffer_data;}
|
||||
const AABB & GetBoundingBox ()const{return BoundingBox;}
|
||||
};//class Primitive
|
||||
VK_NAMESPACE_END
|
||||
#endif//HGL_GRAPH_VULKAN_PRIMITIVE_INCLUDE
|
||||
|
@@ -10,7 +10,6 @@
|
||||
#include<hgl/graph/VKTexture.h>
|
||||
#include<hgl/graph/VKMaterialParameters.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/font/TextPrimitive.h>
|
||||
#include<hgl/type/ObjectManage.h>
|
||||
@@ -79,6 +78,8 @@ private:
|
||||
|
||||
public:
|
||||
|
||||
GPUDevice *GetDevice(){return device;}
|
||||
|
||||
//注:并非一定要走这里,这里只是提供一个注册和自动绑定的机制
|
||||
DescriptorBinding static_descriptor; ///<静态属性描述符绑定管理
|
||||
DescriptorBinding global_descriptor; ///<全局属性描述符绑定管理
|
||||
@@ -91,7 +92,7 @@ public:
|
||||
{}
|
||||
virtual ~RenderResource()=default;
|
||||
|
||||
public: //Add
|
||||
public: //添加数据到管理器(如果指针为nullptr会返回-1)
|
||||
|
||||
MaterialID Add(Material * mtl ){return rm_material.Add(mtl);}
|
||||
MaterialInstanceID Add(MaterialInstance * mi ){return rm_material_instance.Add(mi);}
|
||||
@@ -102,11 +103,10 @@ public: //Add
|
||||
TextureID Add(Texture * t ){return rm_textures.Add(t);}
|
||||
RenderableID Add(Renderable * r ){return rm_renderables.Add(r);}
|
||||
|
||||
public: // VBO/VAO
|
||||
public: // VAB/VAO
|
||||
|
||||
VBO *CreateVBO(VkFormat format,uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VBO *CreateVBO(VkFormat format,uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVBO(format, count, nullptr, sm);}
|
||||
VBO *CreateVBO(const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(), vad->GetCount(),vad->GetData(), sm);}
|
||||
VAB *CreateVAB(VkFormat format,uint32_t count,const void *data, SharingMode sm=SharingMode::Exclusive);
|
||||
VAB *CreateVAB(VkFormat format,uint32_t count, SharingMode sm=SharingMode::Exclusive){return CreateVAB(format, count, nullptr, sm);}
|
||||
|
||||
#define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
|
||||
DeviceBuffer *Create##name(const AnsiString &buf_name,VkDeviceSize size,SharingMode sm=SharingMode::Exclusive){return Create##name(buf_name,size,nullptr,sm);}
|
||||
@@ -147,8 +147,6 @@ public: //Material
|
||||
|
||||
MaterialInstance * CreateMaterialInstance(const mtl::MaterialCreateInfo *,const VILConfig *vil_cfg=nullptr);
|
||||
|
||||
Primitive * CreatePrimitive(const AnsiString &,const uint32_t vertex_count=0);
|
||||
|
||||
Renderable * CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p);
|
||||
|
||||
Sampler * CreateSampler(VkSamplerCreateInfo *sci=nullptr);
|
||||
|
@@ -17,11 +17,11 @@ struct VertexInputData
|
||||
|
||||
uint32_t vertex_count;
|
||||
|
||||
const IndexBufferData *index_buffer;
|
||||
const IBAccess *ib_access;
|
||||
|
||||
public:
|
||||
|
||||
VertexInputData(const uint32_t,const uint32_t,const IndexBufferData *);
|
||||
VertexInputData(const uint32_t,const uint32_t,const IBAccess *);
|
||||
~VertexInputData();
|
||||
|
||||
const bool Comp(const VertexInputData *vid)const
|
||||
@@ -38,7 +38,7 @@ public:
|
||||
|
||||
if(vertex_count!=vid->vertex_count)return(false);
|
||||
|
||||
if(index_buffer!=vid->index_buffer)return(false);
|
||||
if(ib_access!=vid->ib_access)return(false);
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
@@ -1,20 +1,23 @@
|
||||
#ifndef HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
||||
#ifndef HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
||||
#define HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
/**
|
||||
* 可绘制图元创建器
|
||||
*/
|
||||
class RenderablePrimitiveCreater
|
||||
{
|
||||
RenderResource *rr;
|
||||
|
||||
uint32_t vertex_count;
|
||||
VkDeviceSize vertex_count;
|
||||
|
||||
Primitive *prim;
|
||||
|
||||
public:
|
||||
|
||||
RenderablePrimitiveCreater(RenderResource *_rr,const AnsiString &name,uint32_t vc)
|
||||
RenderablePrimitiveCreater(RenderResource *_rr,const AnsiString &name,VkDeviceSize vc)
|
||||
{
|
||||
rr=_rr;
|
||||
vertex_count=vc;
|
||||
@@ -22,25 +25,25 @@ public:
|
||||
prim=rr->CreatePrimitive(name,vertex_count);
|
||||
}
|
||||
|
||||
VBO *SetVBO(const AnsiString &name,const VkFormat &fmt,const void *buf)
|
||||
VAB *SetVAB(const AnsiString &name,const VkFormat &fmt,const void *buf)
|
||||
{
|
||||
VBO *vbo=rr->CreateVBO(fmt,vertex_count,buf);
|
||||
VAB *vab=rr->CreateVAB(fmt,vertex_count,buf);
|
||||
|
||||
if(!vbo)
|
||||
if(!vab)
|
||||
return(nullptr);
|
||||
|
||||
prim->Set(name,vbo);
|
||||
return(vbo);
|
||||
prim->SetVAB(name,vab);
|
||||
return(vab);
|
||||
}
|
||||
|
||||
IndexBuffer *SetIBO(const IndexType &it,const void *buf,const uint32_t index_count)
|
||||
IndexBuffer *SetIndex(const IndexType &it,const void *buf,const VkDeviceSize index_count)
|
||||
{
|
||||
IndexBuffer *ibo=rr->CreateIBO(it,index_count,buf);
|
||||
|
||||
if(!ibo)
|
||||
return(nullptr);
|
||||
|
||||
prim->Set(ibo);
|
||||
prim->SetIndex(ibo,0,index_count);
|
||||
return(ibo);
|
||||
}
|
||||
|
||||
@@ -50,4 +53,4 @@ public:
|
||||
}
|
||||
};//class RenderablePrimitiveCreater
|
||||
VK_NAMESPACE_END
|
||||
#endif // HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
||||
#endif // HGL_VK_RENDERABLE_PRIMITIVE_CREATER_INCLUDE
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#ifndef HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
#ifndef HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
#define HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
@@ -9,9 +9,9 @@ namespace hgl
|
||||
{
|
||||
class VertexAttribBuffer:public DeviceBuffer
|
||||
{
|
||||
VkFormat format; ///<<EFBFBD><EFBFBD><EFBFBD>ݸ<EFBFBD>ʽ
|
||||
uint32_t stride; ///<<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><EFBFBD><EFBFBD>
|
||||
uint32_t count; ///<<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
VkFormat format; ///<数据格式
|
||||
uint32_t stride; ///<单个数据字节数
|
||||
uint32_t count; ///<数据数量
|
||||
|
||||
private:
|
||||
|
||||
@@ -31,9 +31,20 @@ namespace hgl
|
||||
const VkFormat GetFormat()const { return format; }
|
||||
const uint32_t GetStride()const { return stride; }
|
||||
const uint32_t GetCount ()const { return count; }
|
||||
|
||||
const VkDeviceSize GetBytes()const { return stride*count; }
|
||||
|
||||
public:
|
||||
|
||||
void * Map (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Map(start*stride,size*stride);}
|
||||
void Flush (VkDeviceSize start,VkDeviceSize size) override {return DeviceBuffer::Flush(start*stride,size*stride); }
|
||||
void Flush (VkDeviceSize size) override {return DeviceBuffer::Flush(size*stride);}
|
||||
|
||||
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 VertexAttribBuffer:public DeviceBuffer
|
||||
|
||||
using VBO=VertexAttribBuffer;
|
||||
using VAB=VertexAttribBuffer;
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_VULKAN_VERTEX_ATTRIB_BUFFER_INCLUDE
|
||||
|
@@ -1,57 +0,0 @@
|
||||
#ifndef HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
|
||||
#define HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
/**
|
||||
* 顶点属性数据
|
||||
*/
|
||||
class VertexAttribData ///顶点属性数据
|
||||
{
|
||||
void *mem_data; ///<内存中的数据
|
||||
|
||||
protected:
|
||||
|
||||
VkFormat format;
|
||||
|
||||
uint32_t count; ///<数据个数
|
||||
uint32_t total_bytes; ///<字节数
|
||||
|
||||
public:
|
||||
|
||||
VertexAttribData(uint32_t c,const VkFormat vf,const uint32_t t)
|
||||
{
|
||||
count=c;
|
||||
format=vf;
|
||||
total_bytes=t;
|
||||
|
||||
mem_data = hgl_malloc(total_bytes); //在很多情况下,hgl_malloc分配的内存是对齐的,这样有效率上的提升
|
||||
}
|
||||
|
||||
virtual ~VertexAttribData()
|
||||
{
|
||||
if(mem_data)
|
||||
hgl_free(mem_data);
|
||||
}
|
||||
|
||||
const VkFormat GetFormat ()const{return format;} ///<取得数据类型
|
||||
const uint32_t GetCount ()const{return count;} ///<取得数据数量
|
||||
void * GetData ()const{return mem_data;} ///<取得数据指针
|
||||
const uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据字节数
|
||||
};//class VertexAttribData
|
||||
|
||||
using VAD=VertexAttribData;
|
||||
|
||||
/**
|
||||
* 根据格式要求,创建对应的顶点属性数据区(VAD)
|
||||
* @param vertex_count 顶点数量
|
||||
* @param vif 格式
|
||||
*/
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VertexInputFormat *vif);
|
||||
//这个函数比较重要,就不搞成CreateVAD的简写了
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
|
@@ -5,8 +5,9 @@
|
||||
#include<hgl/color/Color4f.h>
|
||||
#include<hgl/type/RectScope.h>
|
||||
#include<hgl/type/String.h>
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/log/LogInfo.h>
|
||||
#include<hgl/graph/VKFormat.h>
|
||||
#include<hgl/graph/AABB.h>
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
@@ -39,7 +40,6 @@ namespace hgl
|
||||
|
||||
access =nullptr;
|
||||
start_access=nullptr;
|
||||
|
||||
}
|
||||
|
||||
virtual ~VertexAttribDataAccess()=default;
|
||||
@@ -53,14 +53,14 @@ namespace hgl
|
||||
|
||||
/**
|
||||
* 取得数据区地址
|
||||
* @param offset 从第几个数据开始访问
|
||||
* @param start 从第几个数据开始访问
|
||||
* @return 访问地址
|
||||
*/
|
||||
T *Get(uint32_t offset=0)
|
||||
{
|
||||
if(!data||offset>=count)
|
||||
{
|
||||
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Get() out,offset:")+OSString::numberOf(offset));
|
||||
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Get() out,start:")+OSString::numberOf(offset));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
@@ -69,14 +69,14 @@ namespace hgl
|
||||
|
||||
/**
|
||||
* 开始访问数据区
|
||||
* @param offset 从第几个数据开始访问
|
||||
* @param start 从第几个数据开始访问
|
||||
* @return 访问地址
|
||||
*/
|
||||
T *Begin(uint32_t offset=0)
|
||||
{
|
||||
if(access)
|
||||
{
|
||||
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Begin() access!=0,offset:")+OSString::numberOf(offset));
|
||||
LOG_HINT(OS_TEXT("VertexAttribDataAccess::Begin() access!=0,start:")+OSString::numberOf(offset));
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
@@ -130,14 +130,9 @@ namespace hgl
|
||||
|
||||
static VkFormat GetVulkanFormat(){return VKFMT;}
|
||||
|
||||
static VertexAttribDataAccess1<T,VKFMT> * Create(VAD *vad)
|
||||
static VertexAttribDataAccess1<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess1<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
return(new VertexAttribDataAccess1<T,VKFMT>(vertices_number,(T *)vbo_data));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -223,14 +218,9 @@ namespace hgl
|
||||
|
||||
static VkFormat GetVulkanFormat(){return VKFMT;}
|
||||
|
||||
static VertexAttribDataAccess2<T,VKFMT> * Create(VAD *vad)
|
||||
static VertexAttribDataAccess2<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess2<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
return(new VertexAttribDataAccess2<T,VKFMT>(vertices_number,(T *)vbo_data));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -539,14 +529,9 @@ namespace hgl
|
||||
|
||||
static VkFormat GetVulkanFormat(){return VKFMT;}
|
||||
|
||||
static VertexAttribDataAccess3<T,VKFMT> * Create(VAD *vad)
|
||||
static VertexAttribDataAccess3<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess3<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
return(new VertexAttribDataAccess3<T,VKFMT>(vertices_number,(T *)vbo_data));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -811,14 +796,9 @@ namespace hgl
|
||||
|
||||
static VkFormat GetVulkanFormat(){return VKFMT;}
|
||||
|
||||
static VertexAttribDataAccess4<T,VKFMT> * Create(VAD *vad)
|
||||
static VertexAttribDataAccess4<T,VKFMT> * Create(const VkDeviceSize vertices_number,void *vbo_data)
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess4<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
return(new VertexAttribDataAccess4<T,VKFMT>(vertices_number,(T *)vbo_data));
|
||||
}
|
||||
|
||||
/**
|
||||
|
60
inc/hgl/graph/VertexDataManager.h
Normal file
60
inc/hgl/graph/VertexDataManager.h
Normal file
@@ -0,0 +1,60 @@
|
||||
#pragma once
|
||||
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/type/DataChain.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
class VertexDataManager
|
||||
{
|
||||
GPUDevice *device;
|
||||
|
||||
protected:
|
||||
|
||||
const VIL * vil; ///<顶点输入格式列表
|
||||
uint vi_count; ///<顶点输入流数量
|
||||
const VIF * vif_list; ///<顶点输入格式列表
|
||||
|
||||
VkDeviceSize vab_max_size; ///<顶点缓冲区分配空间大小(顶点数)
|
||||
VkDeviceSize vab_cur_size; ///<顶点缓冲区当前使用大小
|
||||
VAB ** vab; ///<顶点缓冲区列表
|
||||
|
||||
VkDeviceSize ibo_cur_size; ///<索引缓冲区当前使用大小
|
||||
IndexBuffer * ibo; ///<索引缓冲区
|
||||
|
||||
protected:
|
||||
|
||||
DataChain vbo_data_chain; ///<数据链
|
||||
DataChain ibo_data_chain; ///<数据链
|
||||
|
||||
public:
|
||||
|
||||
VertexDataManager(GPUDevice *dev,const VIL *_vil);
|
||||
~VertexDataManager();
|
||||
|
||||
GPUDevice * GetDevice ()const{return device;} ///<取得GPU设备
|
||||
|
||||
const VIL * GetVIL ()const{return vil;} ///<取得顶点输入格式列表
|
||||
|
||||
const VkDeviceSize GetVABMaxCount ()const{return vab_max_size;} ///<取得顶点属性缓冲区分配的空间最大数量
|
||||
const VkDeviceSize GetVABCurCount ()const{return vab_cur_size;} ///<取得顶点属性缓冲区当前数量
|
||||
|
||||
const IndexType GetIndexType ()const{return ibo?ibo->GetType():IndexType::ERR;} ///<取得索引缓冲区类型
|
||||
const VkDeviceSize GetIndexMaxCount ()const{return ibo?ibo->GetCount():-1;} ///<取得索引缓冲区分配的空间最大数量
|
||||
const VkDeviceSize GetIndexCurCount ()const{return ibo?ibo_cur_size:-1;} ///<取得索引缓冲区当前数量
|
||||
|
||||
public:
|
||||
|
||||
bool Init(const VkDeviceSize vbo_size,const VkDeviceSize ibo_size,const IndexType index_type);
|
||||
|
||||
DataChain::UserNode *AcquireIB(const VkDeviceSize count);
|
||||
DataChain::UserNode *AcquireVAB(const VkDeviceSize count);
|
||||
|
||||
bool ReleaseIB(DataChain::UserNode *);
|
||||
bool ReleaseVAB(DataChain::UserNode *);
|
||||
|
||||
IndexBuffer *GetIBO(){return ibo;}
|
||||
VAB *GetVAB(const uint index){return vab[index];}
|
||||
};//class VertexDataManager
|
||||
VK_NAMESPACE_END
|
@@ -16,8 +16,8 @@ namespace hgl
|
||||
|
||||
uint max_count; ///<缓冲区最大容量
|
||||
|
||||
VBO * vbo_position;
|
||||
VBO * vbo_tex_coord;
|
||||
VAB * vab_position;
|
||||
VAB * vab_tex_coord;
|
||||
|
||||
protected:
|
||||
|
||||
|
@@ -16,7 +16,7 @@ struct Material2DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
public:
|
||||
|
||||
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p):MaterialCreateConfig(da,name,p)
|
||||
Material2DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const bool &mi,const Prim &p):MaterialCreateConfig(da,name,mi,p)
|
||||
{
|
||||
rt_output.color=1; //输出一个颜色
|
||||
rt_output.depth=false; //不输出深度
|
||||
|
@@ -17,7 +17,7 @@ struct Material3DCreateConfig:public MaterialCreateConfig
|
||||
|
||||
public:
|
||||
|
||||
Material3DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p):MaterialCreateConfig(da,name,p)
|
||||
Material3DCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const bool &mi,const Prim &p):MaterialCreateConfig(da,name,mi,p)
|
||||
{
|
||||
rt_output.color=1; //输出一个颜色
|
||||
rt_output.depth=true; //不输出深度
|
||||
|
@@ -19,6 +19,8 @@ struct MaterialCreateConfig
|
||||
|
||||
AnsiString mtl_name; ///<材质名称
|
||||
|
||||
bool material_instance; ///<是否包含材质实例
|
||||
|
||||
RenderTargetOutputConfig rt_output; ///<渲染目标输出配置
|
||||
|
||||
uint32 shader_stage_flag_bit; ///<需要的shader
|
||||
@@ -27,12 +29,14 @@ struct MaterialCreateConfig
|
||||
|
||||
public:
|
||||
|
||||
MaterialCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const Prim &p)
|
||||
MaterialCreateConfig(const GPUDeviceAttribute *da,const AnsiString &name,const bool mi,const Prim &p)
|
||||
{
|
||||
dev_attr=da;
|
||||
|
||||
mtl_name=name;
|
||||
|
||||
material_instance=mi;
|
||||
|
||||
shader_stage_flag_bit=VK_SHADER_STAGE_VERTEX_BIT|VK_SHADER_STAGE_FRAGMENT_BIT;
|
||||
|
||||
prim=p;
|
||||
|
@@ -5,12 +5,14 @@
|
||||
#define STD_MTL_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{
|
||||
#define STD_MTL_NAMESPACE_END }}}
|
||||
|
||||
#define STD_MTL_NAMESPACE_USING using namespace hgl::graph::mtl;
|
||||
#define STD_MTL_NAMESPACE hgl::graph::mtl
|
||||
#define STD_MTL_NAMESPACE_USING using namespace STD_MTL_NAMESPACE;
|
||||
|
||||
#define STD_MTL_FUNC_NAMESPACE_BEGIN namespace hgl{namespace graph{namespace mtl{namespace func{
|
||||
#define STD_MTL_FUNC_NAMESPACE_END }}}}
|
||||
|
||||
#define STD_MTL_FUNC NAMESPACE_USING using namespace hgl::graph::mtl::func;
|
||||
#define STD_MTL_FUNC_NAMESPACE hgl::graph::mtl::func
|
||||
#define STD_MTL_FUNC_NAMESPACE_USING using namespace STD_MTL_FUNC_NAMESPACE;
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
|
@@ -42,10 +42,24 @@ constexpr const ShaderBufferSource SBS_CameraInfo=
|
||||
float znear,zfar;)"
|
||||
};
|
||||
|
||||
constexpr const char LocalToWorldStruct[]="LocalToWorld";
|
||||
constexpr const DescriptorSetType DST_LocalToWorld=DescriptorSetType::PerFrame;
|
||||
|
||||
constexpr const ShaderBufferSource SBS_LocalToWorld=
|
||||
{
|
||||
"LocalToWorldData",
|
||||
"l2w",
|
||||
|
||||
R"(
|
||||
mat4 mats[L2W_MAX_COUNT];
|
||||
)"
|
||||
};
|
||||
|
||||
// UBO必须严格指定数组的大小
|
||||
// SSBO则不需要,使用[]方式指定为动态大小数组
|
||||
|
||||
constexpr const char MaterialInstanceStruct[]="MaterialInstance";
|
||||
constexpr const DescriptorSetType DST_MaterialInstance=DescriptorSetType::PerMaterial;
|
||||
|
||||
constexpr const ShaderBufferSource SBS_MaterialInstance=
|
||||
{
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
#pragma once
|
||||
|
||||
#include<hgl/shadergen/MaterialDescriptorInfo.h>
|
||||
#include<hgl/shadergen/ShaderCreateInfoVertex.h>
|
||||
@@ -33,7 +33,9 @@ namespace hgl{namespace graph
|
||||
uint32_t mi_max_count;
|
||||
UBODescriptor *mi_ubo;
|
||||
|
||||
uint32_t l2w_max_count;
|
||||
uint32_t l2w_shader_stage;
|
||||
UBODescriptor *l2w_ubo;
|
||||
|
||||
ShaderCreateInfoMap shader_map; ///<着色器列表
|
||||
|
||||
|
@@ -21,8 +21,8 @@ namespace hgl
|
||||
|
||||
int hasInput(const char *);
|
||||
|
||||
void AddLocalToWorld();
|
||||
void AddMaterialInstanceID();
|
||||
void AddAssign();
|
||||
|
||||
void AddJoint();
|
||||
};//class ShaderCreateInfoVertex:public ShaderCreateInfo
|
||||
}//namespace graph
|
||||
|
2
res
2
res
Submodule res updated: 008dbd5353...5e5814c15e
@@ -7,11 +7,21 @@ SET(SG_TEXTURE_SOURCE ${SG_INCLUDE_PATH}/TextureLoader.h
|
||||
|
||||
SOURCE_GROUP("Texture" FILES ${SG_TEXTURE_SOURCE})
|
||||
|
||||
SET(SG_VAD_SOURCE ${SG_INCLUDE_PATH}/VertexAttribData.h
|
||||
${SG_INCLUDE_PATH}/VertexAttribDataAccess.h
|
||||
VertexAttribData.cpp)
|
||||
SET(SG_VDM_SOURCE ${SG_INCLUDE_PATH}/VertexAttribDataAccess.h
|
||||
${SG_INCLUDE_PATH}/VertexDataManager.h
|
||||
VertexDataManager.cpp)
|
||||
|
||||
SOURCE_GROUP("VertexAttribData" FILES ${SG_VAD_SOURCE})
|
||||
SOURCE_GROUP("VertexDataManager" FILES ${SG_VDM_SOURCE})
|
||||
|
||||
SET(SG_PRIMITIVE_SOURCE ${SG_INCLUDE_PATH}/VKPrimitive.h
|
||||
Vulkan/VKPrimitive.cpp
|
||||
Vulkan/VKPrimitiveData.cpp
|
||||
Vulkan/VKPrimitiveData.h
|
||||
${SG_INCLUDE_PATH}/VKRenderablePrimitiveCreater.h
|
||||
${SG_INCLUDE_PATH}/PrimitiveCreater.h
|
||||
PrimitiveCreater.cpp)
|
||||
|
||||
SOURCE_GROUP("Primitive" FILES ${SG_PRIMITIVE_SOURCE})
|
||||
|
||||
SET(TILE_SOURCE ${SG_INCLUDE_PATH}/TileData.h
|
||||
TileData.cpp)
|
||||
@@ -22,9 +32,7 @@ SET(GEOMETRY_FILES ${SG_INCLUDE_PATH}/InlineGeometry.h
|
||||
#${SG_INCLUDE_PATH}/Mesh.h
|
||||
#${SG_INCLUDE_PATH}/Spline.h
|
||||
InlineGeometry.cpp
|
||||
#Mesh.cpp
|
||||
${SG_INCLUDE_PATH}/PrimitiveCreater.h
|
||||
PrimitiveCreater.cpp
|
||||
#Mesh.cpp
|
||||
)
|
||||
|
||||
SOURCE_GROUP("Geometry" FILES ${GEOMETRY_FILES})
|
||||
@@ -86,7 +94,6 @@ IF(WIN32)
|
||||
ENDIF(WIN32)
|
||||
|
||||
SET(VK_RR_SOURCE ${SG_INCLUDE_PATH}/VKRenderResource.h
|
||||
${SG_INCLUDE_PATH}/VKRenderablePrimitiveCreater.h
|
||||
Vulkan/VKRenderResource.cpp
|
||||
Vulkan/VKRenderResourceMaterial.cpp)
|
||||
|
||||
@@ -235,9 +242,7 @@ SET(VK_CMD_BUFFER_SOURCE ${SG_INCLUDE_PATH}/VKCommandBuffer.h
|
||||
|
||||
SOURCE_GROUP("Vulkan\\Command Buffer" FILES ${VK_CMD_BUFFER_SOURCE})
|
||||
|
||||
SET(VK_RENDERABLE_SOURCE ${SG_INCLUDE_PATH}/VKPrimitive.h
|
||||
${SG_INCLUDE_PATH}/VKRenderable.h
|
||||
Vulkan/VKPrimitive.cpp
|
||||
SET(VK_RENDERABLE_SOURCE ${SG_INCLUDE_PATH}/VKRenderable.h
|
||||
Vulkan/VKRenderable.cpp
|
||||
Vulkan/VKTileData.cpp
|
||||
Vulkan/VKTileFont.cpp)
|
||||
@@ -297,12 +302,13 @@ SET(VULKAN_RENDER_SOURCE ${VK_RR_SOURCE}
|
||||
|
||||
add_cm_library(ULRE.SceneGraph "ULRE" ${SCENE_GRAPH_HEADER}
|
||||
${SCENE_GRAPH_SOURCE}
|
||||
${SG_PRIMITIVE_SOURCE}
|
||||
${GEOMETRY_FILES}
|
||||
${LIGHT_FILES}
|
||||
|
||||
${SG_TEXTURE_SOURCE}
|
||||
${TILE_SOURCE}
|
||||
${SG_VAD_SOURCE}
|
||||
${SG_VDM_SOURCE}
|
||||
|
||||
# ${FONT_MANAGE_SOURCE}
|
||||
# ${FONT_SOURCE}
|
||||
|
@@ -5,7 +5,6 @@
|
||||
#include<hgl/graph/VertexAttribDataAccess.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
#include<hgl/graph/VKRenderResource.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
|
||||
namespace hgl
|
||||
@@ -14,42 +13,42 @@ namespace hgl
|
||||
{
|
||||
namespace inline_geometry
|
||||
{
|
||||
Primitive *CreateRectangle(RenderResource *db,const VIL *vil,const RectangleCreateInfo *rci)
|
||||
Primitive *CreateRectangle(PrimitiveCreater *pc,const RectangleCreateInfo *rci)
|
||||
{
|
||||
PrimitiveCreater rc(db,vil);
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
if(!rc.Init(4))
|
||||
if(!pc->Init("Rectangle",4,0))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB2f> vertex=rc.AccessVAD<VB2f>(VAN::Position);
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
|
||||
if(!vertex)
|
||||
if(!vertex.IsValid())
|
||||
return(nullptr);
|
||||
|
||||
vertex->WriteRectFan(rci->scope);
|
||||
|
||||
return rc.Finish("Rectangle");
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreateGBufferCompositionRectangle(RenderResource *db,const VIL *vil)
|
||||
Primitive *CreateGBufferCompositionRectangle(PrimitiveCreater *pc)
|
||||
{
|
||||
RectangleCreateInfo rci;
|
||||
|
||||
rci.scope.Set(-1,-1,2,2);
|
||||
|
||||
return CreateRectangle(db,vil,&rci);
|
||||
return CreateRectangle(pc,&rci);
|
||||
}
|
||||
|
||||
Primitive *CreateRoundRectangle(RenderResource *db,const VIL *vil,const RoundRectangleCreateInfo *rci)
|
||||
Primitive *CreateRoundRectangle(PrimitiveCreater *pc,const RoundRectangleCreateInfo *rci)
|
||||
{
|
||||
PrimitiveCreater rc(db,vil);
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
if(rci->radius==0||rci->round_per<=1) //这是要画矩形
|
||||
{
|
||||
if(!rc.Init(4))
|
||||
if(!pc->Init("RoundRectangle",4,0))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB2f> vertex=rc.AccessVAD<VB2f>(VAN::Position);
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
|
||||
vertex->WriteRectFan(rci->scope);
|
||||
}
|
||||
@@ -60,10 +59,10 @@ namespace hgl
|
||||
if(radius>rci->scope.GetWidth()/2.0f)radius=rci->scope.GetWidth()/2.0f;
|
||||
if(radius>rci->scope.GetHeight()/2.0f)radius=rci->scope.GetHeight()/2.0f;
|
||||
|
||||
if(!rc.Init(rci->round_per*4))
|
||||
if(!pc->Init("RoundRectangle",rci->round_per*4,8))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB2f> vertex=rc.AccessVAD<VB2f>(VAN::Position);
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
|
||||
Vector2f *coord=new Vector2f[rci->round_per];
|
||||
|
||||
@@ -111,35 +110,38 @@ namespace hgl
|
||||
delete[] coord;
|
||||
}
|
||||
|
||||
return rc.Finish("RoundRectangle");
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreateCircle(RenderResource *db,const VIL *vil,const CircleCreateInfo *cci)
|
||||
Primitive *CreateCircle(PrimitiveCreater *pc,const CircleCreateInfo *cci)
|
||||
{
|
||||
PrimitiveCreater rc(db,vil);
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
uint edge;
|
||||
uint vertex_count;
|
||||
|
||||
if(cci->has_color)
|
||||
{
|
||||
edge=cci->field_count+1;
|
||||
if(!rc.Init(cci->field_count+2))return(nullptr);
|
||||
vertex_count=cci->field_count+2;
|
||||
}
|
||||
else
|
||||
{
|
||||
edge=cci->field_count;
|
||||
if(!rc.Init(cci->field_count))return(nullptr);
|
||||
vertex_count=cci->field_count;
|
||||
}
|
||||
|
||||
AutoDelete<VB2f> vertex=rc.AccessVAD<VB2f>(VAN::Position);
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
if(!pc->Init("Circle",vertex_count,0))return(nullptr);
|
||||
|
||||
if(!vertex)
|
||||
VABMap2f vertex(pc,VAN::Position);
|
||||
VABMap4f color(pc,VAN::Color);
|
||||
|
||||
if(!vertex.IsValid())
|
||||
return(nullptr);
|
||||
|
||||
if(cci->has_color)
|
||||
{
|
||||
if(!color)
|
||||
if(!color.IsValid())
|
||||
return(nullptr);
|
||||
|
||||
vertex->Write(cci->center);
|
||||
@@ -159,17 +161,15 @@ namespace hgl
|
||||
color->Write(cci->border_color);
|
||||
}
|
||||
|
||||
return rc.Finish("Circle");
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreatePlaneGrid(RenderResource *db,const VIL *vil,const PlaneGridCreateInfo *pgci)
|
||||
Primitive *CreatePlaneGrid(PrimitiveCreater *pc,const PlaneGridCreateInfo *pgci)
|
||||
{
|
||||
PrimitiveCreater rc(db,vil);
|
||||
|
||||
if(!rc.Init(((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2))
|
||||
if(!pc->Init("PlaneGrid",((pgci->grid_size.Width()+1)+(pgci->grid_size.Height()+1))*2,0))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
VABMap3f vertex(pc,VAN::Position);
|
||||
|
||||
const float right=float(pgci->grid_size.Width())/2.0f;
|
||||
const float left =-right;
|
||||
@@ -177,22 +177,23 @@ namespace hgl
|
||||
const float bottom=float(pgci->grid_size.Height())/2.0f;
|
||||
const float top =-bottom;
|
||||
|
||||
for(int row=0;row<=pgci->grid_size.Height();row++)
|
||||
for(uint row=0;row<=pgci->grid_size.Height();row++)
|
||||
{
|
||||
vertex->WriteLine( Vector3f(left ,top+row,0),
|
||||
Vector3f(right,top+row,0));
|
||||
}
|
||||
|
||||
for(int col=0;col<=pgci->grid_size.Width();col++)
|
||||
for(uint col=0;col<=pgci->grid_size.Width();col++)
|
||||
{
|
||||
vertex->WriteLine(Vector3f(left+col,top, 0),
|
||||
Vector3f(left+col,bottom,0));
|
||||
}
|
||||
|
||||
AutoDelete<VB1f> lum=rc.AccessVAD<VB1f>(VAN::Luminance);
|
||||
if(lum)
|
||||
VABMap1f lum(pc,VAN::Luminance);
|
||||
|
||||
if(lum.IsValid())
|
||||
{
|
||||
for(int row=0;row<=pgci->grid_size.Height();row++)
|
||||
for(uint row=0;row<=pgci->grid_size.Height();row++)
|
||||
{
|
||||
if((row%pgci->sub_count.Height())==0)
|
||||
lum->RepeatWrite(pgci->sub_lum,2);
|
||||
@@ -200,7 +201,7 @@ namespace hgl
|
||||
lum->RepeatWrite(pgci->lum,2);
|
||||
}
|
||||
|
||||
for(int col=0;col<=pgci->grid_size.Width();col++)
|
||||
for(uint col=0;col<=pgci->grid_size.Width();col++)
|
||||
{
|
||||
if((col%pgci->sub_count.Width())==0)
|
||||
lum->RepeatWrite(pgci->sub_lum,2);
|
||||
@@ -209,46 +210,49 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
return rc.Finish("PlaneGrid");
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreatePlane(RenderResource *db,const VIL *vil)
|
||||
Primitive *CreatePlane(PrimitiveCreater *pc)
|
||||
{
|
||||
const float xy_vertices [] = { -0.5f,-0.5f,0.0f, +0.5f,-0.5f,0.0f, +0.5f,+0.5f,0.0f, -0.5f,+0.5f,0.0f };
|
||||
float xy_tex_coord[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.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);
|
||||
|
||||
PrimitiveCreater rc(db,vil);
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
if(!rc.Init(4))
|
||||
if(!pc->Init("Plane",4,8))
|
||||
return(nullptr);
|
||||
|
||||
rc.WriteVAD(VAN::Position,xy_vertices,sizeof(xy_vertices));
|
||||
|
||||
if(!pc->WriteVAB(VAN::Position,VF_V3F,xy_vertices))
|
||||
return(nullptr);
|
||||
|
||||
{
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
VABMap3f normal(pc,VAN::Normal);
|
||||
|
||||
if(normal)normal->RepeatWrite(xy_normal,4);
|
||||
if(normal.IsValid())
|
||||
normal->RepeatWrite(xy_normal,4);
|
||||
}
|
||||
|
||||
{
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
VABMap3f tangent(pc,VAN::Tangent);
|
||||
|
||||
if(tangent)tangent->RepeatWrite(xy_tangent,4);
|
||||
if(tangent.IsValid())
|
||||
tangent->RepeatWrite(xy_tangent,4);
|
||||
}
|
||||
|
||||
{
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
VABMap2f tex_coord(pc,VAN::TexCoord);
|
||||
|
||||
if(tex_coord)
|
||||
if(tex_coord.IsValid())
|
||||
tex_coord->Write(xy_tex_coord,4);
|
||||
}
|
||||
|
||||
return rc.Finish("Plane");
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreateCube(RenderResource *db,const VIL *vil,const CubeCreateInfo *cci)
|
||||
Primitive *CreateCube(PrimitiveCreater *pc,const CubeCreateInfo *cci)
|
||||
{
|
||||
/**
|
||||
* 4 5
|
||||
@@ -301,29 +305,33 @@ namespace hgl
|
||||
16, 17, 18, 16, 18, 19,
|
||||
20, 23, 22, 20, 22, 21};
|
||||
|
||||
PrimitiveCreater rc(db,vil);
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
if(!rc.Init(24))
|
||||
if(!pc->Init("Cube",24,6*2*3,IndexType::U16))
|
||||
return(nullptr);
|
||||
|
||||
rc.WriteVAD(VAN::Position,positions,sizeof(positions));
|
||||
if(!pc->WriteVAB(VAN::Position,VF_V3F,positions))
|
||||
return(nullptr);
|
||||
|
||||
if(cci->normal)
|
||||
rc.WriteVAD(VAN::Normal,normals,sizeof(normals));
|
||||
if(!pc->WriteVAB(VAN::Normal,VF_V3F,normals))
|
||||
return(nullptr);
|
||||
|
||||
if(cci->tangent)
|
||||
rc.WriteVAD(VAN::Tangent,tangents,sizeof(tangents));
|
||||
if(!pc->WriteVAB(VAN::Tangent,VF_V3F,tangents))
|
||||
return(nullptr);
|
||||
|
||||
if(cci->tex_coord)
|
||||
rc.WriteVAD(VAN::TexCoord,tex_coords,sizeof(tex_coords));
|
||||
if(!pc->WriteVAB(VAN::TexCoord,VF_V2F,tex_coords))
|
||||
return(nullptr);
|
||||
|
||||
if(cci->color_type!=CubeCreateInfo::ColorType::NoColor)
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
||||
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
VABMap4f color(pc,VAN::Color);
|
||||
|
||||
if(color)
|
||||
if(color.IsValid())
|
||||
{
|
||||
if(cci->color_type==CubeCreateInfo::ColorType::SameColor)
|
||||
color->RepeatWrite(cci->color[0],24);
|
||||
@@ -341,12 +349,17 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
rc.CreateIBO16(6*2*3,indices);
|
||||
return rc.Finish("Cube");
|
||||
//pc->CreateIBO16(6*2*3,indices);
|
||||
pc->WriteIBO(indices);
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
template<typename T> void CreateSphereIndices(T *tp,uint numberParallels,const uint numberSlices)
|
||||
template<typename T>
|
||||
void CreateSphereIndices(PrimitiveCreater *pc,uint numberParallels,const uint numberSlices)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
T *tp=ib_map;
|
||||
|
||||
for (uint i = 0; i < numberParallels; i++)
|
||||
{
|
||||
for (uint j = 0; j < numberSlices; j++)
|
||||
@@ -440,10 +453,8 @@ namespace hgl
|
||||
* @param numberSlices 切片数
|
||||
* @return 可渲染数据
|
||||
*/
|
||||
Primitive *CreateSphere(RenderResource *db,const VIL *vil,const uint numberSlices)
|
||||
Primitive *CreateSphere(PrimitiveCreater *pc,const uint numberSlices)
|
||||
{
|
||||
PrimitiveCreater rc(db,vil);
|
||||
|
||||
uint numberParallels = (numberSlices+1) / 2;
|
||||
uint numberVertices = (numberParallels + 1) * (numberSlices + 1);
|
||||
uint numberIndices = numberParallels * numberSlices * 6;
|
||||
@@ -456,18 +467,21 @@ namespace hgl
|
||||
float helpMatrix[16];
|
||||
float tex_x;
|
||||
|
||||
if(!rc.Init(numberVertices))
|
||||
if(!pc->Init("Sphere",numberVertices,numberIndices))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
VABRawMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABRawMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABRawMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABRawMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
float *tp=tangent?tangent->Get():nullptr;
|
||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
float *tp=tangent;
|
||||
float *tcp=tex_coord;
|
||||
|
||||
if(!vp)
|
||||
return(nullptr);
|
||||
|
||||
for (uint i = 0; i < numberParallels + 1; i++)
|
||||
{
|
||||
@@ -508,17 +522,22 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
if(numberVertices<=0xffff)
|
||||
CreateSphereIndices<uint16>(rc.CreateIBO16(numberIndices),numberParallels,numberSlices);
|
||||
else
|
||||
CreateSphereIndices<uint32>(rc.CreateIBO32(numberIndices),numberParallels,numberSlices);
|
||||
//索引
|
||||
{
|
||||
const IndexType index_type=pc->GetIndexType();
|
||||
|
||||
return rc.Finish("Sphere");
|
||||
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(pc,numberParallels,numberSlices);else
|
||||
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(pc,numberParallels,numberSlices);else
|
||||
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(pc,numberParallels,numberSlices);else
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreateDome(RenderResource *db,const VIL *vil,const uint numberSlices)
|
||||
Primitive *CreateDome(PrimitiveCreater *pc,const uint numberSlices)
|
||||
{
|
||||
PrimitiveCreater rc(db,vil);
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
uint i, j;
|
||||
|
||||
@@ -537,18 +556,21 @@ namespace hgl
|
||||
if (numberSlices < 3 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
||||
return nullptr;
|
||||
|
||||
if(!rc.Init(numberVertices))
|
||||
if(!pc->Init("Dome",numberVertices,numberIndices))
|
||||
return(nullptr);
|
||||
|
||||
VABRawMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABRawMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABRawMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABRawMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
float *tp=tangent?tangent->Get():nullptr;
|
||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
float *tp=tangent;
|
||||
float *tcp=tex_coord;
|
||||
|
||||
if(!vp)
|
||||
return(nullptr);
|
||||
|
||||
for (i = 0; i < numberParallels + 1; i++)
|
||||
{
|
||||
@@ -594,19 +616,27 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
if(numberVertices<=0xffff)
|
||||
CreateSphereIndices<uint16>(rc.CreateIBO16(numberIndices),numberParallels,numberSlices);
|
||||
else
|
||||
CreateSphereIndices<uint32>(rc.CreateIBO32(numberIndices),numberParallels,numberSlices);
|
||||
//索引
|
||||
{
|
||||
const IndexType index_type=pc->GetIndexType();
|
||||
|
||||
return rc.Finish("Dome");
|
||||
if(index_type==IndexType::U16)CreateSphereIndices<uint16>(pc,numberParallels,numberSlices);else
|
||||
if(index_type==IndexType::U32)CreateSphereIndices<uint32>(pc,numberParallels,numberSlices);else
|
||||
if(index_type==IndexType::U8 )CreateSphereIndices<uint8 >(pc,numberParallels,numberSlices);else
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
void CreateTorusIndices(T *tp,uint numberSlices,uint numberStacks)
|
||||
void CreateTorusIndices(PrimitiveCreater *pc,uint numberSlices,uint numberStacks)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
T *tp=ib_map;
|
||||
|
||||
// loop counters
|
||||
uint sideCount, faceCount;
|
||||
|
||||
@@ -637,9 +667,9 @@ namespace hgl
|
||||
}
|
||||
}//namespace
|
||||
|
||||
Primitive *CreateTorus(RenderResource *db,const VIL *vil,const TorusCreateInfo *tci)
|
||||
Primitive *CreateTorus(PrimitiveCreater *pc,const TorusCreateInfo *tci)
|
||||
{
|
||||
PrimitiveCreater rc(db,vil);
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
// s, t = parametric values of the equations, in the range [0,1]
|
||||
float s = 0;
|
||||
@@ -674,19 +704,22 @@ namespace hgl
|
||||
sIncr = 1.0f / (float) tci->numberSlices;
|
||||
tIncr = 1.0f / (float) tci->numberStacks;
|
||||
|
||||
if(!rc.Init(numberVertices))
|
||||
if(!pc->Init("Torus",numberVertices,numberIndices))
|
||||
return(nullptr);
|
||||
|
||||
VABRawMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABRawMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABRawMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABRawMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
float *tp=tangent;
|
||||
float *tcp=tex_coord;
|
||||
|
||||
if(!vp)
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
float *tp=tangent?tangent->Get():nullptr;
|
||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
||||
|
||||
// generate vertices and its attributes
|
||||
for (sideCount = 0; sideCount <= tci->numberSlices; ++sideCount, s += sIncr)
|
||||
{
|
||||
@@ -735,19 +768,25 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
if(numberVertices<=0xffff)
|
||||
CreateTorusIndices<uint16>(rc.CreateIBO16(numberIndices),tci->numberSlices,tci->numberStacks);
|
||||
else
|
||||
CreateTorusIndices<uint32>(rc.CreateIBO32(numberIndices),tci->numberSlices,tci->numberStacks);
|
||||
//索引
|
||||
{
|
||||
const IndexType index_type=pc->GetIndexType();
|
||||
|
||||
return rc.Finish("Torus");
|
||||
if(index_type==IndexType::U16)CreateTorusIndices<uint16>(pc,tci->numberSlices,tci->numberStacks);else
|
||||
if(index_type==IndexType::U32)CreateTorusIndices<uint32>(pc,tci->numberSlices,tci->numberStacks);else
|
||||
if(index_type==IndexType::U8 )CreateTorusIndices<uint8 >(pc,tci->numberSlices,tci->numberStacks);else
|
||||
return(nullptr);
|
||||
}
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
void CreateCylinderIndices(T *tp,const uint numberSlices)
|
||||
void CreateCylinderIndices(PrimitiveCreater *pc,const uint numberSlices)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
T *tp=ib_map;
|
||||
uint i;
|
||||
|
||||
T centerIndex = 0;
|
||||
@@ -793,34 +832,35 @@ namespace hgl
|
||||
}
|
||||
}//namespace
|
||||
|
||||
Primitive *CreateCylinder(RenderResource *db,const VIL *vil,const CylinderCreateInfo *cci)
|
||||
Primitive *CreateCylinder(PrimitiveCreater *pc,const CylinderCreateInfo *cci)
|
||||
{
|
||||
uint numberIndices = cci->numberSlices * 3 * 2 + cci->numberSlices * 6;
|
||||
|
||||
if(numberIndices<=0)
|
||||
return(nullptr);
|
||||
|
||||
PrimitiveCreater rc(db,vil);
|
||||
|
||||
uint numberVertices = (cci->numberSlices + 2) * 2 + (cci->numberSlices + 1) * 2;
|
||||
|
||||
if(!rc.Init(numberVertices))
|
||||
if(!pc->Init("Cylinder",numberVertices,numberIndices))
|
||||
return(nullptr);
|
||||
|
||||
float angleStep = (2.0f * HGL_PI) / ((float) cci->numberSlices);
|
||||
|
||||
if (cci->numberSlices < 3 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
||||
return nullptr;
|
||||
|
||||
VABRawMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABRawMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABRawMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABRawMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
float *tp=tangent;
|
||||
float *tcp=tex_coord;
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
float *tp=tangent?tangent->Get():nullptr;
|
||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
||||
if(!vp)
|
||||
return(nullptr);
|
||||
|
||||
*vp = 0.0f; ++vp;
|
||||
*vp = 0.0f; ++vp;
|
||||
@@ -964,19 +1004,27 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
if(numberVertices<=0xffff)
|
||||
CreateCylinderIndices<uint16>(rc.CreateIBO16(numberIndices),cci->numberSlices);
|
||||
else
|
||||
CreateCylinderIndices<uint32>(rc.CreateIBO32(numberIndices),cci->numberSlices);
|
||||
//索引
|
||||
{
|
||||
const IndexType index_type=pc->GetIndexType();
|
||||
|
||||
return rc.Finish("Cylinder");
|
||||
if(index_type==IndexType::U16)CreateCylinderIndices<uint16>(pc,cci->numberSlices);else
|
||||
if(index_type==IndexType::U32)CreateCylinderIndices<uint32>(pc,cci->numberSlices);else
|
||||
if(index_type==IndexType::U8 )CreateCylinderIndices<uint8 >(pc,cci->numberSlices);else
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
namespace
|
||||
{
|
||||
template<typename T>
|
||||
void CreateConeIndices(T *tp,const uint numberSlices,const uint numberStacks)
|
||||
void CreateConeIndices(PrimitiveCreater *pc,const uint numberSlices,const uint numberStacks)
|
||||
{
|
||||
IBMap<T> ib_map(pc);
|
||||
T *tp=ib_map;
|
||||
|
||||
// Bottom
|
||||
uint centerIndex = 0;
|
||||
uint indexCounter = 1;
|
||||
@@ -1012,19 +1060,16 @@ namespace hgl
|
||||
}
|
||||
}//namespace
|
||||
|
||||
Primitive *CreateCone(RenderResource *db,const VIL *vil,const ConeCreateInfo *cci)
|
||||
Primitive *CreateCone(PrimitiveCreater *pc,const ConeCreateInfo *cci)
|
||||
{
|
||||
PrimitiveCreater rc(db,vil);
|
||||
|
||||
uint i, j;
|
||||
|
||||
uint numberVertices = (cci->numberSlices + 2) + (cci->numberSlices + 1) * (cci->numberStacks + 1);
|
||||
|
||||
if(!rc.Init(numberVertices))
|
||||
return(nullptr);
|
||||
|
||||
uint numberIndices = cci->numberSlices * 3 + cci->numberSlices * 6 * cci->numberStacks;
|
||||
|
||||
if(!pc->Init("Cone",numberVertices,numberIndices))
|
||||
return(nullptr);
|
||||
|
||||
float angleStep = (2.0f * HGL_PI) / ((float) cci->numberSlices);
|
||||
|
||||
float h = 2.0f * cci->halfExtend;
|
||||
@@ -1033,16 +1078,19 @@ namespace hgl
|
||||
|
||||
if (cci->numberSlices < 3 || cci->numberStacks < 1 || numberVertices > GLUS_MAX_VERTICES || numberIndices > GLUS_MAX_INDICES)
|
||||
return nullptr;
|
||||
|
||||
VABRawMapFloat vertex (pc,VF_V3F,VAN::Position);
|
||||
VABRawMapFloat normal (pc,VF_V3F,VAN::Normal);
|
||||
VABRawMapFloat tangent (pc,VF_V3F,VAN::Tangent);
|
||||
VABRawMapFloat tex_coord(pc,VF_V2F,VAN::TexCoord);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB3f> normal=rc.AccessVAD<VB3f>(VAN::Normal);
|
||||
AutoDelete<VB3f> tangent=rc.AccessVAD<VB3f>(VAN::Tangent);
|
||||
AutoDelete<VB2f> tex_coord=rc.AccessVAD<VB2f>(VAN::TexCoord);
|
||||
float *vp=vertex;
|
||||
float *np=normal;
|
||||
float *tp=tangent;
|
||||
float *tcp=tex_coord;
|
||||
|
||||
float *vp=vertex->Get();
|
||||
float *np=normal?normal->Get():nullptr;
|
||||
float *tp=tangent?tangent->Get():nullptr;
|
||||
float *tcp=tex_coord?tex_coord->Get():nullptr;
|
||||
if(!vp)
|
||||
return(nullptr);
|
||||
|
||||
*vp = 0.0f; ++vp;
|
||||
*vp = 0.0f; ++vp;
|
||||
@@ -1131,27 +1179,32 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
if(numberVertices<=0xffff)
|
||||
CreateConeIndices<uint16>(rc.CreateIBO16(numberIndices),cci->numberSlices,cci->numberStacks);
|
||||
else
|
||||
CreateConeIndices<uint32>(rc.CreateIBO32(numberIndices),cci->numberSlices,cci->numberStacks);
|
||||
//索引
|
||||
{
|
||||
const IndexType index_type=pc->GetIndexType();
|
||||
|
||||
return rc.Finish("Cone");
|
||||
if(index_type==IndexType::U16)CreateConeIndices<uint16>(pc,cci->numberSlices,cci->numberStacks);else
|
||||
if(index_type==IndexType::U32)CreateConeIndices<uint32>(pc,cci->numberSlices,cci->numberStacks);else
|
||||
if(index_type==IndexType::U8 )CreateConeIndices<uint8 >(pc,cci->numberSlices,cci->numberStacks);else
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreateAxis(RenderResource *db,const VIL *vil,const AxisCreateInfo *aci)
|
||||
Primitive *CreateAxis(PrimitiveCreater *pc,const AxisCreateInfo *aci)
|
||||
{
|
||||
if(!db||!vil||!aci)return(nullptr);
|
||||
if(!pc||!aci)return(nullptr);
|
||||
|
||||
PrimitiveCreater rc(db,vil);
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
if(!rc.Init(6))
|
||||
if(!pc->Init("Axis",6,0))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
VABMap3f vertex(pc,VAN::Position);
|
||||
VABMap4f color(pc,VAN::Color);
|
||||
|
||||
if(!vertex||!color)
|
||||
if(!vertex.IsValid()||!color.IsValid())
|
||||
return(nullptr);
|
||||
|
||||
const float s=aci->size;
|
||||
@@ -1163,10 +1216,10 @@ namespace hgl
|
||||
vertex->Write(0,0,0);color->Write(aci->color[2]);
|
||||
vertex->Write(0,0,s);color->Write(aci->color[2]);
|
||||
|
||||
return rc.Finish("Axis");
|
||||
return pc->Create();
|
||||
}
|
||||
|
||||
Primitive *CreateBoundingBox(RenderResource *db,const VIL *vil,const BoundingBoxCreateInfo *cci)
|
||||
Primitive *CreateBoundingBox(PrimitiveCreater *pc,const BoundingBoxCreateInfo *cci)
|
||||
{
|
||||
// Points of a cube.
|
||||
/* 4 5 */ const float points[]={ -0.5,-0.5, 0.5, 0.5,-0.5,0.5, 0.5,-0.5,-0.5, -0.5,-0.5,-0.5,
|
||||
@@ -1188,24 +1241,21 @@ namespace hgl
|
||||
0,4, 1,5, 2,6, 3,7
|
||||
};
|
||||
|
||||
PrimitiveCreater rc(db,vil);
|
||||
if(!pc)return(nullptr);
|
||||
|
||||
if(!rc.Init(8))
|
||||
if(!pc->Init("BoundingBox",8,24,IndexType::U16))
|
||||
return(nullptr);
|
||||
|
||||
AutoDelete<VB3f> vertex=rc.AccessVAD<VB3f>(VAN::Position);
|
||||
|
||||
if(!vertex)return(nullptr);
|
||||
|
||||
rc.WriteVAD(VAN::Position,points,sizeof(points));
|
||||
if(!pc->WriteVAB(VAN::Position,VF_V3F,points))
|
||||
return(nullptr);
|
||||
|
||||
if(cci->color_type!=BoundingBoxCreateInfo::ColorType::NoColor)
|
||||
{
|
||||
RANGE_CHECK_RETURN_NULLPTR(cci->color_type);
|
||||
|
||||
AutoDelete<VB4f> color=rc.AccessVAD<VB4f>(VAN::Color);
|
||||
VABMap4f color(pc,VAN::Color);
|
||||
|
||||
if(color)
|
||||
if(color.IsValid())
|
||||
{
|
||||
if(cci->color_type==BoundingBoxCreateInfo::ColorType::SameColor)
|
||||
color->RepeatWrite(cci->color[0],8);
|
||||
@@ -1215,9 +1265,9 @@ namespace hgl
|
||||
}
|
||||
}
|
||||
|
||||
rc.CreateIBO16(24,indices);
|
||||
pc->WriteIBO<uint16>(indices);
|
||||
|
||||
return rc.Finish("BoundingBox");
|
||||
return pc->Create();
|
||||
}
|
||||
}//namespace inline_geometry
|
||||
}//namespace graph
|
||||
|
@@ -14,7 +14,7 @@
|
||||
* for(material)
|
||||
* for(pipeline)
|
||||
* for(material_instance)
|
||||
* for(vbo)
|
||||
* for(vab)
|
||||
*/
|
||||
|
||||
template<>
|
||||
@@ -53,15 +53,7 @@ MaterialRenderList::MaterialRenderList(GPUDevice *d,bool l2w,Material *m)
|
||||
cmd_buf=nullptr;
|
||||
material=m;
|
||||
|
||||
if(l2w)
|
||||
l2w_buffer=new RenderL2WBuffer(device);
|
||||
else
|
||||
l2w_buffer=nullptr;
|
||||
|
||||
if(material->HasMI())
|
||||
mi_buffer=new RenderMIBuffer(device,material->GetMIDataBytes());
|
||||
else
|
||||
mi_buffer=nullptr;
|
||||
assign_buffer=new RenderAssignBuffer(device,material);
|
||||
|
||||
vbo_list=new VBOList(material->GetVertexInput()->GetCount());
|
||||
}
|
||||
@@ -69,8 +61,7 @@ MaterialRenderList::MaterialRenderList(GPUDevice *d,bool l2w,Material *m)
|
||||
MaterialRenderList::~MaterialRenderList()
|
||||
{
|
||||
SAFE_CLEAR(vbo_list);
|
||||
SAFE_CLEAR(mi_buffer);
|
||||
SAFE_CLEAR(l2w_buffer);
|
||||
SAFE_CLEAR(assign_buffer);
|
||||
}
|
||||
|
||||
void MaterialRenderList::Add(Renderable *ri,const Matrix4f &mat)
|
||||
@@ -94,16 +85,8 @@ void MaterialRenderList::End()
|
||||
|
||||
Stat();
|
||||
|
||||
if(l2w_buffer)
|
||||
{
|
||||
l2w_buffer->WriteNode(rn_list.GetData(),node_count);
|
||||
}
|
||||
|
||||
if(mi_buffer)
|
||||
{
|
||||
StatMI();
|
||||
mi_buffer->WriteNode(rn_list.GetData(),node_count,mi_set);
|
||||
}
|
||||
if(assign_buffer)
|
||||
assign_buffer->WriteNode(rn_list);
|
||||
}
|
||||
|
||||
void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
||||
@@ -113,19 +96,6 @@ void MaterialRenderList::RenderItem::Set(Renderable *ri)
|
||||
vid =ri->GetVertexInputData();
|
||||
}
|
||||
|
||||
void MaterialRenderList::StatMI()
|
||||
{
|
||||
mi_set.Clear();
|
||||
|
||||
for(RenderNode &rn:rn_list)
|
||||
mi_set.Add(rn.ri->GetMaterialInstance());
|
||||
|
||||
if(mi_set.GetCount()>material->GetMIMaxCount())
|
||||
{
|
||||
//超出最大数量了怎么办???
|
||||
}
|
||||
}
|
||||
|
||||
void MaterialRenderList::Stat()
|
||||
{
|
||||
const uint count=rn_list.GetCount();
|
||||
@@ -182,21 +152,13 @@ bool MaterialRenderList::Bind(const VertexInputData *vid,const uint ri_index)
|
||||
|
||||
vbo_list->Restart();
|
||||
|
||||
//Basic组,它所有的VBO信息均来自于Primitive,由vid参数传递进来
|
||||
//Basic组,它所有的VAB信息均来自于Primitive,由vid参数传递进来
|
||||
{
|
||||
vbo_list->Add(vid->buffer_list,vid->buffer_offset,vid->binding_count);
|
||||
}
|
||||
|
||||
if(l2w_buffer)//LocalToWorld组,由RenderList合成
|
||||
{
|
||||
for(uint i=0;i<4;i++)
|
||||
l2w_buffer_size[i]=ri_index*16; //mat4每列都是rgba32f,自然是16字节
|
||||
|
||||
vbo_list->Add(l2w_buffer->GetVBO(),l2w_buffer_size,4);
|
||||
}
|
||||
|
||||
if(mi_buffer) //材质实例组
|
||||
vbo_list->Add(mi_buffer->GetVBO(),MI_VBO_STRIDE_BYTES*ri_index);
|
||||
if(assign_buffer) //L2W/MI分发组
|
||||
vbo_list->Add(assign_buffer->GetVAB(),ASSIGN_VAB_STRIDE_BYTES*ri_index);
|
||||
|
||||
//if(!vbo_list.IsFull()) //Joint组,暂未支持
|
||||
//{
|
||||
@@ -256,13 +218,9 @@ void MaterialRenderList::Render(RenderItem *ri)
|
||||
last_vid=ri->vid;
|
||||
}
|
||||
|
||||
const IndexBufferData *ibd=last_vid->index_buffer;
|
||||
|
||||
if(ibd->buffer)
|
||||
if(last_vid->ib_access)
|
||||
{
|
||||
cmd_buf->BindIBO(ibd);
|
||||
|
||||
cmd_buf->DrawIndexed(ibd->buffer->GetCount(),ri->count);
|
||||
cmd_buf->DrawIndexed(last_vid->ib_access,ri->count);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -286,8 +244,8 @@ void MaterialRenderList::Render(RenderCmdBuffer *rcb)
|
||||
last_pipeline =nullptr;
|
||||
last_vid =nullptr;
|
||||
|
||||
if(mi_buffer)
|
||||
mi_buffer->Bind(material);
|
||||
if(assign_buffer)
|
||||
assign_buffer->Bind(material);
|
||||
|
||||
cmd_buf->BindDescriptorSets(material);
|
||||
|
||||
|
@@ -1,139 +1,184 @@
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
#include<hgl/graph/PrimitiveCreater.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKPrimitive.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include"vulkan/VKPrimitiveData.h"
|
||||
|
||||
namespace hgl
|
||||
VK_NAMESPACE_BEGIN
|
||||
PrimitiveCreater::PrimitiveCreater(GPUDevice *dev,const VIL *v)
|
||||
{
|
||||
namespace graph
|
||||
device =dev;
|
||||
vdm =nullptr;
|
||||
vil =v;
|
||||
|
||||
prim_data =nullptr;
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
PrimitiveCreater::PrimitiveCreater(VertexDataManager *_vdm)
|
||||
:PrimitiveCreater(_vdm->GetDevice(),_vdm->GetVIL())
|
||||
{
|
||||
vdm=_vdm;
|
||||
|
||||
index_type=vdm->GetIndexType();
|
||||
}
|
||||
|
||||
PrimitiveCreater::~PrimitiveCreater()
|
||||
{
|
||||
SAFE_CLEAR(prim_data);
|
||||
}
|
||||
|
||||
void PrimitiveCreater::Clear()
|
||||
{
|
||||
SAFE_CLEAR(prim_data);
|
||||
|
||||
vertices_number =0;
|
||||
|
||||
index_number =0;
|
||||
index_type =IndexType::ERR;
|
||||
iba =nullptr;
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::Init(const AnsiString &pname,const VkDeviceSize vertex_count,const VkDeviceSize index_count,IndexType it)
|
||||
{
|
||||
if(prim_data) //已经初始化过了
|
||||
return(false);
|
||||
|
||||
if(pname.IsEmpty())return(false);
|
||||
if(vertex_count<=0)return(false);
|
||||
|
||||
if(index_count>0)
|
||||
{
|
||||
PrimitiveCreater::PrimitiveCreater(RenderResource *sdb,const VIL *v)
|
||||
if(it==IndexType::AUTO)
|
||||
{
|
||||
db =sdb;
|
||||
vil =v;
|
||||
it=device->ChooseIndexType(vertex_count);
|
||||
|
||||
vertices_number =0;
|
||||
ibo =nullptr;
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::Init(const uint32 count)
|
||||
{
|
||||
if(count<=0)return(false);
|
||||
|
||||
vertices_number=count;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
VAD *PrimitiveCreater::CreateVAD(const AnsiString &name)
|
||||
{
|
||||
if(!vil)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
|
||||
if(!vif)
|
||||
return(nullptr);
|
||||
|
||||
PrimitiveVertexBuffer *pvb;
|
||||
|
||||
if(vbo_map.Get(name,pvb))
|
||||
return pvb->data;
|
||||
|
||||
VAD *vad=hgl::graph::CreateVertexAttribData(vertices_number,vif);
|
||||
|
||||
if(!vad)
|
||||
return(nullptr);
|
||||
|
||||
pvb=new PrimitiveVertexBuffer;
|
||||
|
||||
pvb->data =vad;
|
||||
pvb->name =name;
|
||||
pvb->binding=vif->binding;
|
||||
|
||||
pvb->vbo =nullptr;
|
||||
|
||||
vbo_map.Add(name,pvb);
|
||||
|
||||
return pvb->data;
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteVAD(const AnsiString &name,const void *data,const uint32_t bytes)
|
||||
{
|
||||
if(!vil)return(false);
|
||||
if(name.IsEmpty())return(false);
|
||||
if(!data)return(false);
|
||||
if(!bytes)return(false);
|
||||
|
||||
PrimitiveVertexBuffer *pvb;
|
||||
|
||||
if(vbo_map.Get(name,pvb))
|
||||
return false;
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
|
||||
if(!vif)
|
||||
if(!IsIndexType(it))
|
||||
return(false);
|
||||
|
||||
if(vif->stride*vertices_number!=bytes)
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!device->CheckIndexType(it,vertex_count))
|
||||
return(false);
|
||||
|
||||
pvb=new PrimitiveVertexBuffer;
|
||||
|
||||
pvb->data =nullptr;
|
||||
pvb->name =name;
|
||||
pvb->binding=vif->binding;
|
||||
|
||||
pvb->vbo =db->CreateVBO(vif->format,vertices_number,data);
|
||||
|
||||
vbo_map.Add(name,pvb);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
uint16 *PrimitiveCreater::CreateIBO16(uint count,const uint16 *data)
|
||||
{
|
||||
if(ibo)return(nullptr);
|
||||
index_type=it;
|
||||
index_number=index_count;
|
||||
}
|
||||
|
||||
ibo=db->CreateIBO16(count,data);
|
||||
return (uint16 *)ibo->Map();
|
||||
vertices_number=vertex_count;
|
||||
|
||||
if(vdm)
|
||||
{
|
||||
prim_data=CreatePrimitiveData(vdm,vertices_number);
|
||||
|
||||
index_type=vdm->GetIndexType();
|
||||
}
|
||||
else
|
||||
prim_data=CreatePrimitiveData(device,vil,vertices_number);
|
||||
|
||||
if(!prim_data)return(false);
|
||||
|
||||
if(index_number>0)
|
||||
{
|
||||
iba=prim_data->InitIBO(index_number,index_type);
|
||||
|
||||
if(!iba)
|
||||
{
|
||||
delete prim_data;
|
||||
return(false);
|
||||
}
|
||||
|
||||
uint32 *PrimitiveCreater::CreateIBO32(uint count,const uint32 *data)
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(!vdm)
|
||||
{
|
||||
if(ibo)return(nullptr);
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
ibo=db->CreateIBO32(count,data);
|
||||
return (uint32 *)ibo->Map();
|
||||
}
|
||||
|
||||
Primitive *PrimitiveCreater::Finish(const AnsiString &prim_name)
|
||||
{
|
||||
const uint si_count=vil->GetCount(VertexInputGroup::Basic);
|
||||
|
||||
if(vbo_map.GetCount()!=si_count)
|
||||
return(nullptr);
|
||||
|
||||
Primitive *primitive=db->CreatePrimitive(prim_name,vertices_number);
|
||||
|
||||
const auto *sp=vbo_map.GetDataList();
|
||||
for(uint i=0;i<si_count;i++)
|
||||
if(du)
|
||||
{
|
||||
if((*sp)->value->vbo)
|
||||
primitive->Set((*sp)->key,(*sp)->value->vbo);
|
||||
else
|
||||
primitive->Set((*sp)->key,db->CreateVBO((*sp)->value->data));
|
||||
|
||||
++sp;
|
||||
du->SetBuffer( iba->buffer->GetBuffer(), prim_name+":IndexBuffer:Buffer");
|
||||
du->SetDeviceMemory(iba->buffer->GetVkMemory(), prim_name+":IndexBuffer:Memory");
|
||||
}
|
||||
|
||||
if(ibo)
|
||||
{
|
||||
ibo->Unmap();
|
||||
primitive->Set(ibo);
|
||||
}
|
||||
|
||||
db->Add(primitive);
|
||||
|
||||
return primitive;
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
#endif//_DEBUG
|
||||
}
|
||||
|
||||
prim_name=pname;
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
VABAccess *PrimitiveCreater::AcquireVAB(const AnsiString &name,const VkFormat &acquire_format,const void *data)
|
||||
{
|
||||
if(!prim_data)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
VABAccess *vab_access=prim_data->InitVAB(name,acquire_format,data);
|
||||
|
||||
if(!vab_access)
|
||||
return(nullptr);
|
||||
|
||||
#ifdef _DEBUG
|
||||
if(!vdm&&vab_access->vab)
|
||||
{
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
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
|
||||
|
||||
return vab_access;
|
||||
}
|
||||
|
||||
|
||||
void *PrimitiveCreater::MapIBO()
|
||||
{
|
||||
if(!prim_data)return(nullptr);
|
||||
if(!iba)return(nullptr);
|
||||
|
||||
return iba->buffer->Map(iba->start,iba->count);
|
||||
}
|
||||
|
||||
void PrimitiveCreater::UnmapIBO()
|
||||
{
|
||||
if(iba)
|
||||
iba->buffer->Unmap();
|
||||
}
|
||||
|
||||
bool PrimitiveCreater::WriteIBO(const void *data,const VkDeviceSize count)
|
||||
{
|
||||
if(!data)return(false);
|
||||
if(!prim_data)return(false);
|
||||
|
||||
IBAccess *iba=prim_data->GetIBAccess();
|
||||
|
||||
if(count>0&&count>index_number)
|
||||
return(false);
|
||||
|
||||
return iba->buffer->Write(data,iba->start,count);
|
||||
}
|
||||
|
||||
Primitive *PrimitiveCreater::Create()
|
||||
{
|
||||
if(!prim_data)
|
||||
return(nullptr);
|
||||
|
||||
Primitive *primitive=new Primitive(prim_name,prim_data);
|
||||
|
||||
if(!primitive)
|
||||
return(nullptr);
|
||||
|
||||
prim_data=nullptr; //带入Primitive后,不在这里删除
|
||||
|
||||
Clear();
|
||||
|
||||
return primitive;
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -8,184 +8,186 @@
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
RenderL2WBuffer::RenderL2WBuffer(GPUDevice *dev)
|
||||
{
|
||||
hgl_zero(*this);
|
||||
|
||||
device=dev;
|
||||
}
|
||||
|
||||
void RenderL2WBuffer::Clear()
|
||||
{
|
||||
SAFE_CLEAR(l2w_vbo[0])
|
||||
SAFE_CLEAR(l2w_vbo[1])
|
||||
SAFE_CLEAR(l2w_vbo[2])
|
||||
SAFE_CLEAR(l2w_vbo[3])
|
||||
|
||||
node_count=0;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
namespace
|
||||
{
|
||||
constexpr const char *l2w_buffer_name[]=
|
||||
{
|
||||
"VBO:Buffer:LocalToWorld:0",
|
||||
"VBO:Buffer:LocalToWorld:1",
|
||||
"VBO:Buffer:LocalToWorld:2",
|
||||
"VBO:Buffer:LocalToWorld:3"
|
||||
};
|
||||
|
||||
constexpr const char *l2w_memory_name[]=
|
||||
{
|
||||
"VBO:Memory:LocalToWorld:0",
|
||||
"VBO:Memory:LocalToWorld:1",
|
||||
"VBO:Memory:LocalToWorld:2",
|
||||
"VBO:Memory:LocalToWorld:3"
|
||||
};
|
||||
}
|
||||
#endif//_DEBUG
|
||||
|
||||
void RenderL2WBuffer::Alloc(const uint nc)
|
||||
{
|
||||
Clear();
|
||||
|
||||
{
|
||||
node_count=nc;
|
||||
|
||||
for(uint i=0;i<4;i++)
|
||||
{
|
||||
l2w_vbo[i]=device->CreateVBO(VF_V4F,node_count);
|
||||
l2w_buffer[i]=l2w_vbo[i]->GetBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
{
|
||||
for(int i=0;i<4;i++)
|
||||
{
|
||||
du->SetBuffer(l2w_buffer[i],l2w_buffer_name[i]);
|
||||
du->SetDeviceMemory(l2w_vbo[i]->GetVkMemory(),l2w_memory_name[i]);
|
||||
}
|
||||
}
|
||||
#endif//_DEBUG
|
||||
}
|
||||
|
||||
void RenderL2WBuffer::WriteNode(RenderNode *render_node,const uint count)
|
||||
{
|
||||
RenderNode *rn;
|
||||
|
||||
Alloc(count);
|
||||
|
||||
glm::vec4 *tp;
|
||||
|
||||
for(uint col=0;col<4;col++)
|
||||
{
|
||||
tp=(glm::vec4 *)(l2w_vbo[col]->Map());
|
||||
|
||||
rn=render_node;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
{
|
||||
*tp=rn->local_to_world[col];
|
||||
++tp;
|
||||
++rn;
|
||||
}
|
||||
|
||||
l2w_vbo[col]->Unmap();
|
||||
}
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
RenderMIBuffer::RenderMIBuffer(GPUDevice *dev,const uint mi_bytes)
|
||||
RenderAssignBuffer::RenderAssignBuffer(GPUDevice *dev,Material *mtl)
|
||||
{
|
||||
hgl_zero(*this);
|
||||
|
||||
device=dev;
|
||||
|
||||
mi_data_bytes=mi_bytes;
|
||||
material=mtl;
|
||||
|
||||
mi_data_bytes=mtl->GetMIDataBytes();
|
||||
|
||||
LW2_MAX_COUNT=dev->GetUBORange()/sizeof(Matrix4f);
|
||||
|
||||
l2w_buffer_max_count=0;
|
||||
l2w_buffer=nullptr;
|
||||
mi_buffer=nullptr;
|
||||
}
|
||||
|
||||
void RenderMIBuffer::Bind(Material *mtl)const
|
||||
void RenderAssignBuffer::Bind(Material *mtl)const
|
||||
{
|
||||
if(!mtl)return;
|
||||
|
||||
mtl->BindUBO(DescriptorSetType::PerMaterial,mtl::SBS_MaterialInstance.name,ubo_mi);
|
||||
mtl->BindUBO(mtl::DST_LocalToWorld, mtl::SBS_LocalToWorld.name, l2w_buffer);
|
||||
mtl->BindUBO(mtl::DST_MaterialInstance, mtl::SBS_MaterialInstance.name, mi_buffer);
|
||||
}
|
||||
|
||||
void RenderMIBuffer::Clear()
|
||||
void RenderAssignBuffer::Clear()
|
||||
{
|
||||
SAFE_CLEAR(ubo_mi);
|
||||
SAFE_CLEAR(vbo_mi);
|
||||
|
||||
mi_count=0;
|
||||
node_count=0;
|
||||
SAFE_CLEAR(l2w_buffer);
|
||||
SAFE_CLEAR(mi_buffer);
|
||||
SAFE_CLEAR(assign_vab);
|
||||
}
|
||||
|
||||
void RenderMIBuffer::Alloc(const uint nc,const uint mc)
|
||||
void RenderAssignBuffer::StatL2W(const RenderNodeList &rn_list)
|
||||
{
|
||||
Clear();
|
||||
|
||||
node_count=nc;
|
||||
|
||||
if(mi_data_bytes>0&&mc>0)
|
||||
if(!l2w_buffer)
|
||||
{
|
||||
mi_count=mc;
|
||||
|
||||
ubo_mi=device->CreateUBO(mi_data_bytes*mi_count);
|
||||
l2w_buffer_max_count=power_to_2(rn_list.GetCount());
|
||||
}
|
||||
else if(rn_list.GetCount()>l2w_buffer_max_count)
|
||||
{
|
||||
l2w_buffer_max_count=power_to_2(rn_list.GetCount());
|
||||
SAFE_CLEAR(l2w_buffer);
|
||||
}
|
||||
|
||||
vbo_mi=device->CreateVBO(MI_VBO_FMT,node_count);
|
||||
mi_buffer=vbo_mi->GetBuffer();
|
||||
|
||||
if(!l2w_buffer)
|
||||
{
|
||||
l2w_buffer=device->CreateUBO(sizeof(Matrix4f)*l2w_buffer_max_count);
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
{
|
||||
du->SetBuffer(ubo_mi->GetBuffer(),"UBO:Buffer:MaterialInstance");
|
||||
du->SetDeviceMemory(ubo_mi->GetVkMemory(),"UBO:Memory:MaterialInstance");
|
||||
|
||||
du->SetBuffer(vbo_mi->GetBuffer(),"VBO:Buffer:MaterialInstanceID");
|
||||
du->SetDeviceMemory(vbo_mi->GetVkMemory(),"VBO:Memory:MaterialInstanceID");
|
||||
du->SetBuffer(l2w_buffer->GetBuffer(),"UBO:Buffer:LocalToWorld");
|
||||
du->SetDeviceMemory(l2w_buffer->GetVkMemory(),"UBO:Memory:LocalToWorld");
|
||||
}
|
||||
#endif//_DEBUG
|
||||
}
|
||||
|
||||
void RenderMIBuffer::WriteNode(RenderNode *render_node,const uint count,const MaterialInstanceSets &mi_set)
|
||||
{
|
||||
RenderNode *rn;
|
||||
|
||||
Alloc(count,mi_set.GetCount());
|
||||
|
||||
uint8 *mip=(uint8 *)(ubo_mi->Map());
|
||||
|
||||
for(MaterialInstance *mi:mi_set)
|
||||
{
|
||||
memcpy(mip,mi->GetMIData(),mi_data_bytes);
|
||||
mip+=mi_data_bytes;
|
||||
}
|
||||
|
||||
ubo_mi->Unmap();
|
||||
RenderNode *rn=rn_list.GetData();
|
||||
Matrix4f *l2wp=(Matrix4f *)(l2w_buffer->DeviceBuffer::Map());
|
||||
|
||||
uint16 *idp=(uint16 *)(vbo_mi->Map());
|
||||
for(uint i=0;i<rn_list.GetCount();i++)
|
||||
{
|
||||
*l2wp=rn->local_to_world;
|
||||
++l2wp;
|
||||
++rn;
|
||||
}
|
||||
|
||||
l2w_buffer->Unmap();
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::StatMI(const RenderNodeList &rn_list)
|
||||
{
|
||||
mi_set.Clear();
|
||||
|
||||
if(mi_data_bytes<=0) //没有材质实例数据
|
||||
return;
|
||||
|
||||
if(!mi_buffer)
|
||||
{
|
||||
mi_set.PreAlloc(power_to_2(rn_list.GetCount()));
|
||||
}
|
||||
else if(rn_list.GetCount()>mi_set.GetAllocCount())
|
||||
{
|
||||
mi_set.PreAlloc(power_to_2(rn_list.GetCount()));
|
||||
SAFE_CLEAR(mi_buffer);
|
||||
}
|
||||
|
||||
if(!mi_buffer)
|
||||
{
|
||||
mi_buffer=device->CreateUBO(mi_data_bytes*mi_set.GetAllocCount());
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
{
|
||||
du->SetBuffer(mi_buffer->GetBuffer(),"UBO:Buffer:MaterialInstanceData");
|
||||
du->SetDeviceMemory(mi_buffer->GetVkMemory(),"UBO:Memory:MaterialInstanceData");
|
||||
}
|
||||
#endif//_DEBUG
|
||||
}
|
||||
|
||||
mi_set.PreAlloc(rn_list.GetCount());
|
||||
|
||||
for(RenderNode &rn:rn_list)
|
||||
mi_set.Add(rn.ri->GetMaterialInstance());
|
||||
|
||||
if(mi_set.GetCount()>material->GetMIMaxCount())
|
||||
{
|
||||
//超出最大数量了怎么办???
|
||||
}
|
||||
|
||||
//合并材质实例数据
|
||||
{
|
||||
uint8 *mip=(uint8 *)(mi_buffer->Map());
|
||||
|
||||
for(MaterialInstance *mi:mi_set)
|
||||
{
|
||||
memcpy(mip,mi->GetMIData(),mi_data_bytes);
|
||||
mip+=mi_data_bytes;
|
||||
}
|
||||
|
||||
mi_buffer->Unmap();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderAssignBuffer::WriteNode(const RenderNodeList &rn_list)
|
||||
{
|
||||
if(rn_list.GetCount()<=0)
|
||||
return;
|
||||
|
||||
StatL2W(rn_list);
|
||||
StatMI(rn_list);
|
||||
|
||||
{
|
||||
rn=render_node;
|
||||
|
||||
for(uint i=0;i<count;i++)
|
||||
if(!assign_vab)
|
||||
{
|
||||
*idp=mi_set.Find(rn->ri->GetMaterialInstance());
|
||||
++idp;
|
||||
node_count=power_to_2(rn_list.GetCount());
|
||||
}
|
||||
else if(node_count<rn_list.GetCount())
|
||||
{
|
||||
node_count=power_to_2(rn_list.GetCount());
|
||||
SAFE_CLEAR(assign_vab);
|
||||
}
|
||||
|
||||
if(!assign_vab)
|
||||
{
|
||||
assign_vab=device->CreateVAB(ASSIGN_VAB_FMT,node_count);
|
||||
assign_buffer=assign_vab->GetBuffer();
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
{
|
||||
du->SetBuffer(assign_vab->GetBuffer(),"VAB:Buffer:AssignData");
|
||||
du->SetDeviceMemory(assign_vab->GetVkMemory(),"VAB:Memory:AssignData");
|
||||
}
|
||||
#endif//_DEBUG
|
||||
}
|
||||
}
|
||||
|
||||
//生成材质实例ID列表
|
||||
{
|
||||
RenderNode *rn=rn_list.GetData();
|
||||
|
||||
AssignData *adp=(AssignData *)(assign_vab->DeviceBuffer::Map());
|
||||
|
||||
for(uint i=0;i<rn_list.GetCount();i++)
|
||||
{
|
||||
adp->l2w=i;
|
||||
adp->mi=mi_set.Find(rn->ri->GetMaterialInstance());
|
||||
++adp;
|
||||
|
||||
++rn;
|
||||
}
|
||||
}
|
||||
|
||||
vbo_mi->Unmap();
|
||||
assign_vab->Unmap();
|
||||
}
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -16,6 +16,7 @@ VK_NAMESPACE_BEGIN
|
||||
// 如果一定要使用超过16K/64K硬件限制的容量,有两种办法
|
||||
// 一、分多次渲染,使用UBO Offset偏移UBO数据区。
|
||||
// 二、使用SSBO,但这样会导致性能下降,所以不推荐使用。
|
||||
// 三、使用纹理保存材质实例数据,但这样会导致性能下降,所以不推荐使用。
|
||||
|
||||
// 但我们不解决这个问题
|
||||
// 我们天然要求将材质实例数据分为两个等级,同时要求一次渲染不能超过256种材质实例。
|
||||
@@ -25,73 +26,71 @@ VK_NAMESPACE_BEGIN
|
||||
struct RenderNode;
|
||||
class MaterialInstance;
|
||||
|
||||
class RenderL2WBuffer
|
||||
{
|
||||
GPUDevice *device;
|
||||
|
||||
uint node_count; ///<渲染节点数量
|
||||
|
||||
VBO *l2w_vbo[4];
|
||||
VkBuffer l2w_buffer[4];
|
||||
|
||||
private:
|
||||
|
||||
void Alloc(const uint nc);
|
||||
|
||||
void Clear();
|
||||
|
||||
public:
|
||||
|
||||
const VkBuffer *GetVBO()const{return l2w_buffer;}
|
||||
|
||||
public:
|
||||
|
||||
RenderL2WBuffer(GPUDevice *dev);
|
||||
~RenderL2WBuffer(){Clear();}
|
||||
|
||||
void WriteNode(RenderNode *render_node,const uint count);
|
||||
};//class RenderL2WBuffer
|
||||
|
||||
/*
|
||||
* 渲染节点额外提供的数据
|
||||
*/
|
||||
class RenderMIBuffer
|
||||
class RenderAssignBuffer
|
||||
{
|
||||
struct AssignData
|
||||
{
|
||||
uint16 l2w;
|
||||
uint16 mi;
|
||||
};
|
||||
|
||||
uint LW2_MAX_COUNT;
|
||||
|
||||
private:
|
||||
|
||||
GPUDevice *device;
|
||||
|
||||
uint node_count; ///<渲染节点数量
|
||||
Material *material;
|
||||
|
||||
uint32_t mi_data_bytes; ///<材质实例数据字节数
|
||||
uint32_t mi_count; ///<材质实例数量
|
||||
DeviceBuffer *ubo_mi; ///<材质实例数据
|
||||
private: //LocalToWorld矩阵数据
|
||||
|
||||
uint32 l2w_buffer_max_count; ///<LocalToWorld矩阵最大数量
|
||||
DeviceBuffer *l2w_buffer; ///<LocalToWorld矩阵数据(UBO/SSBO)
|
||||
|
||||
void StatL2W(const RenderNodeList &);
|
||||
|
||||
private: //材质实例数据
|
||||
|
||||
VBO *vbo_mi; ///<材质实例ID(R16UI格式)
|
||||
VkBuffer mi_buffer;
|
||||
MaterialInstanceSets mi_set;
|
||||
|
||||
uint32_t mi_data_bytes; ///<单个材质实例数据字节数
|
||||
DeviceBuffer *mi_buffer; ///<材质实例数据(UBO/SSBO)
|
||||
|
||||
void StatMI(const RenderNodeList &);
|
||||
|
||||
private: //分发数据
|
||||
|
||||
uint32 node_count; ///<节点数量
|
||||
|
||||
VAB *assign_vab; ///<分发数据VAB(RG16UI格式,R存L2W ID,G存材质实例ID)
|
||||
VkBuffer assign_buffer; ///<分发数据Buffer
|
||||
|
||||
private:
|
||||
|
||||
void Alloc(const uint nc,const uint mc);
|
||||
|
||||
void Clear();
|
||||
|
||||
public:
|
||||
|
||||
const VkBuffer GetVBO()const{return mi_buffer;}
|
||||
const VkBuffer GetVAB()const{return assign_buffer;}
|
||||
|
||||
void Bind(Material *)const;
|
||||
|
||||
public:
|
||||
|
||||
RenderMIBuffer(GPUDevice *dev,const uint32_t mi_bytes);
|
||||
~RenderMIBuffer(){Clear();}
|
||||
RenderAssignBuffer(GPUDevice *dev,Material *);
|
||||
~RenderAssignBuffer(){Clear();}
|
||||
|
||||
//下一代,将MaterialInstanceSets使用提前化,这样不用每一次绘制都重新写入MI DATA,可以提升效率。
|
||||
//虽然这样就不自动化了,但我们要的就是不自动化。
|
||||
//必须在外部全部准备好MaterialInstanceSets,然后一次性写入。
|
||||
//渲染时找不到就直接用0号材质实例
|
||||
|
||||
void WriteNode(RenderNode *render_node,const uint nc,const MaterialInstanceSets &mi_set);
|
||||
};//struct RenderMIBuffer
|
||||
//同样的LocalToWorld矩阵也可以提前化处理,这样对于静态物体,就只需要写入一次LocalToWorld矩阵了。
|
||||
|
||||
void WriteNode(const RenderNodeList &);
|
||||
|
||||
};//struct RenderAssignBuffer
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -16,7 +16,8 @@ namespace hgl
|
||||
{
|
||||
BoundingBox.SetZero();
|
||||
|
||||
WorldBoundingBox=LocalBoundingBox=BoundingBox;
|
||||
//WorldBoundingBox=
|
||||
LocalBoundingBox=BoundingBox;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1,19 +0,0 @@
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKVertexInputFormat.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VertexInputFormat *vif)
|
||||
{
|
||||
if(vertex_count<=0
|
||||
||vif->vec_size<1||vif->vec_size>4
|
||||
||vif->stride<1||vif->stride>8*4
|
||||
||!CheckVulkanFormat(vif->format))
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribData(vertex_count,vif->format,vif->stride*vertex_count));
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
126
src/SceneGraph/VertexDataManager.cpp
Normal file
126
src/SceneGraph/VertexDataManager.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKVertexInputFormat.h>
|
||||
#include<hgl/graph/VKVertexInputLayout.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
VertexDataManager::VertexDataManager(GPUDevice *dev,const VIL *_vil)
|
||||
{
|
||||
device=dev;
|
||||
|
||||
vil=_vil;
|
||||
vi_count=_vil->GetCount();
|
||||
vif_list=_vil->GetVIFList(); //来自于Material,不会被释放,所以指针有效
|
||||
|
||||
vab_max_size=0;
|
||||
vab_cur_size=0;
|
||||
vab=hgl_zero_new<VAB *>(vi_count);
|
||||
|
||||
ibo_cur_size=0;
|
||||
ibo=nullptr;
|
||||
}
|
||||
|
||||
VertexDataManager::~VertexDataManager()
|
||||
{
|
||||
SAFE_CLEAR_OBJECT_ARRAY(vab,vi_count);
|
||||
SAFE_CLEAR(ibo);
|
||||
}
|
||||
|
||||
/**
|
||||
* 初始化顶点数据管理器
|
||||
* @param vbo_size VAB大小
|
||||
* @param ibo_size IBO大小
|
||||
* @param index_type 索引类型
|
||||
*/
|
||||
bool VertexDataManager::Init(const VkDeviceSize vbo_size,const VkDeviceSize ibo_size,const IndexType index_type)
|
||||
{
|
||||
if(vab[0]||ibo) //已经初始化过了
|
||||
return(false);
|
||||
|
||||
if(vbo_size<=0)
|
||||
return(false);
|
||||
|
||||
vab_max_size=vbo_size;
|
||||
ibo_cur_size=ibo_size;
|
||||
|
||||
vab_cur_size=0;
|
||||
ibo_cur_size=0;
|
||||
|
||||
for(uint i=0;i<vi_count;i++)
|
||||
{
|
||||
vab[i]=device->CreateVAB(vif_list[i].format,vab_max_size);
|
||||
if(!vab[i])
|
||||
return(false);
|
||||
}
|
||||
|
||||
vbo_data_chain.Init(vab_max_size);
|
||||
|
||||
if(ibo_size>0)
|
||||
{
|
||||
ibo=device->CreateIBO(index_type,ibo_size);
|
||||
if(!ibo)
|
||||
return(false);
|
||||
|
||||
ibo_data_chain.Init(ibo_size);
|
||||
}
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
||||
DataChain::UserNode *VertexDataManager::AcquireIB(const VkDeviceSize count)
|
||||
{
|
||||
if(count<=0)return(nullptr);
|
||||
|
||||
DataChain::UserNode *un=ibo_data_chain.Acquire(hgl_align<int>(count,4));
|
||||
|
||||
if(!un)return(false);
|
||||
|
||||
ibo_cur_size+=un->GetCount();
|
||||
|
||||
return(un);
|
||||
}
|
||||
|
||||
bool VertexDataManager::ReleaseIB(DataChain::UserNode *un)
|
||||
{
|
||||
if(!un)return(false);
|
||||
|
||||
const auto count=un->GetCount();
|
||||
|
||||
if(!ibo_data_chain.Release(un))
|
||||
return(false);
|
||||
|
||||
ibo_cur_size-=count;
|
||||
return(true);
|
||||
}
|
||||
|
||||
DataChain::UserNode *VertexDataManager::AcquireVAB(const VkDeviceSize count)
|
||||
{
|
||||
if(count<=0)return(nullptr);
|
||||
|
||||
DataChain::UserNode *un=vbo_data_chain.Acquire(hgl_align<int>(count,4));
|
||||
|
||||
if(!un)return(nullptr);
|
||||
|
||||
vab_cur_size+=un->GetCount();
|
||||
|
||||
return(un);
|
||||
}
|
||||
|
||||
bool VertexDataManager::ReleaseVAB(DataChain::UserNode *un)
|
||||
{
|
||||
if(!un)return(false);
|
||||
|
||||
const auto count=un->GetCount();
|
||||
|
||||
if(!vbo_data_chain.Release(un))
|
||||
return(false);
|
||||
|
||||
vab_cur_size-=count;
|
||||
return(true);
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
@@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VK.h>
|
||||
#include<hgl/graph/VKUUID.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
|
||||
@@ -306,6 +306,37 @@ namespace
|
||||
constexpr size_t VK_PHYSICAL_DEVICE_TYPE_RANGE_SIZE=VK_PHYSICAL_DEVICE_TYPE_END_RANGE-VK_PHYSICAL_DEVICE_TYPE_BEGIN_RANGE+1;
|
||||
#endif//VK_PHYSICAL_DEVICE_TYPE_RANGE_SIZE
|
||||
|
||||
namespace
|
||||
{
|
||||
struct VulkanDeviceVendor
|
||||
{
|
||||
VkVendorId id;
|
||||
const char *name;
|
||||
};
|
||||
|
||||
constexpr const VulkanDeviceVendor vulkan_vendor[]=
|
||||
{
|
||||
{VK_VENDOR_ID_VIV,"VIV"},
|
||||
{VK_VENDOR_ID_VSI,"VSI"},
|
||||
{VK_VENDOR_ID_KAZAN,"KAZAN"},
|
||||
{VK_VENDOR_ID_CODEPLAY,"CODEPLAY"},
|
||||
{VK_VENDOR_ID_MESA,"MESA"},
|
||||
{VK_VENDOR_ID_POCL,"POCL"},
|
||||
{VK_VENDOR_ID_MOBILEYE,"Mobileye"}
|
||||
};
|
||||
|
||||
const char *GetVendorName(const uint32_t id)
|
||||
{
|
||||
for(const VulkanDeviceVendor &vdv:vulkan_vendor)
|
||||
{
|
||||
if(vdv.id==id)
|
||||
return vdv.name;
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
void DebugOut(const VkPhysicalDeviceProperties &pdp)
|
||||
{
|
||||
constexpr char DeviceTypeString[VK_PHYSICAL_DEVICE_TYPE_RANGE_SIZE][16]=
|
||||
@@ -319,7 +350,7 @@ namespace
|
||||
|
||||
std::cout<<" apiVersion: ";DebugOutVersion(pdp.apiVersion);
|
||||
std::cout<<" driverVersion: ";DebugOutVersion(pdp.driverVersion);
|
||||
std::cout<<" vendorID: 0x"<<HexToString<char>(pdp.vendorID).c_str()<<std::endl;
|
||||
std::cout<<" vendor: "<<GetVendorName(pdp.vendorID)<<std::endl;
|
||||
std::cout<<" deviceID: 0x"<<HexToString<char>(pdp.deviceID).c_str()<<std::endl;
|
||||
std::cout<<" deviceType: "<<DeviceTypeString[pdp.deviceType]<<std::endl;
|
||||
std::cout<<" deviceName: "<<pdp.deviceName<<std::endl;
|
||||
|
@@ -4,6 +4,7 @@
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKDeviceAttribute.h>
|
||||
#include<hgl/graph/VKPhysicalDevice.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
RenderCmdBuffer::RenderCmdBuffer(const GPUDeviceAttribute *attr,VkCommandBuffer cb):GPUCmdBuffer(attr,cb)
|
||||
@@ -129,13 +130,13 @@ bool RenderCmdBuffer::BindDescriptorSets(Material *mtl)
|
||||
return(true);
|
||||
}
|
||||
|
||||
void RenderCmdBuffer::BindIBO(const IndexBufferData *ibd)
|
||||
{
|
||||
vkCmdBindIndexBuffer( cmd_buf,
|
||||
ibd->buffer->GetBuffer(),
|
||||
ibd->offset,
|
||||
VkIndexType(ibd->buffer->GetType()));
|
||||
}
|
||||
//void RenderCmdBuffer::BindIBO(const IBAccess *iba)
|
||||
//{
|
||||
// vkCmdBindIndexBuffer( cmd_buf,
|
||||
// iba->buffer->GetBuffer(),
|
||||
// iba->start,
|
||||
// VkIndexType(iba->buffer->GetType()));
|
||||
//}
|
||||
|
||||
bool RenderCmdBuffer::BindVBO(Renderable *ri)
|
||||
{
|
||||
@@ -149,10 +150,13 @@ bool RenderCmdBuffer::BindVBO(Renderable *ri)
|
||||
|
||||
vkCmdBindVertexBuffers(cmd_buf,0,vid->binding_count,vid->buffer_list,vid->buffer_offset);
|
||||
|
||||
IndexBuffer *indices_buffer=vid->index_buffer->buffer;
|
||||
IndexBuffer *indices_buffer=vid->ib_access->buffer;
|
||||
|
||||
if(indices_buffer)
|
||||
vkCmdBindIndexBuffer(cmd_buf,indices_buffer->GetBuffer(),vid->index_buffer->offset,VkIndexType(indices_buffer->GetType()));
|
||||
vkCmdBindIndexBuffer(cmd_buf,
|
||||
indices_buffer->GetBuffer(),
|
||||
vid->ib_access->start,
|
||||
VkIndexType(indices_buffer->GetType()));
|
||||
|
||||
return(true);
|
||||
}
|
||||
@@ -180,4 +184,24 @@ void RenderCmdBuffer::DrawIndexedIndirect( VkBuffer buffer,
|
||||
for(uint32_t i=0;i<drawCount;i++)
|
||||
vkCmdDrawIndexedIndirect(cmd_buf,buffer,offset+i*stride,1,stride);
|
||||
}
|
||||
|
||||
void RenderCmdBuffer::Draw(const VertexInputData *vid)
|
||||
{
|
||||
if (vid->ib_access->buffer)
|
||||
DrawIndexed(vid->ib_access->count);
|
||||
else
|
||||
Draw(vid->vertex_count);
|
||||
}
|
||||
|
||||
void RenderCmdBuffer::DrawIndexed(const IBAccess *iba,const uint32_t instance_count)
|
||||
{
|
||||
if(!iba||instance_count<=0)return;
|
||||
|
||||
vkCmdBindIndexBuffer(cmd_buf,
|
||||
iba->buffer->GetBuffer(),
|
||||
iba->start*iba->buffer->GetStride(),
|
||||
VkIndexType(iba->buffer->GetType()));
|
||||
|
||||
vkCmdDrawIndexed(cmd_buf,iba->count,instance_count,0,0,0);
|
||||
}
|
||||
VK_NAMESPACE_END
|
||||
|
@@ -55,7 +55,7 @@ bool GPUDevice::CreateBuffer(DeviceBufferData *buf,VkBufferUsageFlags buf_usage,
|
||||
return(false);
|
||||
}
|
||||
|
||||
VBO *GPUDevice::CreateVBO(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
|
||||
VAB *GPUDevice::CreateVAB(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
|
||||
{
|
||||
if(count==0)return(nullptr);
|
||||
|
||||
@@ -77,6 +77,30 @@ VBO *GPUDevice::CreateVBO(VkFormat format,uint32_t count,const void *data,Sharin
|
||||
return(new VertexAttribBuffer(attr->device,buf,format,stride,count));
|
||||
}
|
||||
|
||||
const IndexType GPUDevice::ChooseIndexType(const VkDeviceSize &vertex_count)const
|
||||
{
|
||||
if(vertex_count<=0)return(IndexType::ERR);
|
||||
|
||||
if(attr->uint8_index_type&& vertex_count<=0xFF )return IndexType::U8; else
|
||||
if( vertex_count<=0xFFFF)return IndexType::U16; else
|
||||
if(attr->uint32_index_type )return IndexType::U32; else
|
||||
|
||||
return IndexType::ERR;
|
||||
}
|
||||
|
||||
const bool GPUDevice::CheckIndexType(const IndexType it,const VkDeviceSize &vertex_count)const
|
||||
{
|
||||
if(vertex_count<=0)return(false);
|
||||
|
||||
if(it==IndexType::U16&&vertex_count<=0xFFFF)return(true);
|
||||
|
||||
if(it==IndexType::U32&& attr->uint32_index_type)return(true);
|
||||
|
||||
if(it==IndexType::U8 &&vertex_count<=0xFF&& attr->uint8_index_type)return(true);
|
||||
|
||||
return(false);
|
||||
}
|
||||
|
||||
IndexBuffer *GPUDevice::CreateIBO(IndexType index_type,uint32_t count,const void *data,SharingMode sharing_mode)
|
||||
{
|
||||
if(count==0)return(nullptr);
|
||||
|
@@ -77,36 +77,43 @@ namespace
|
||||
if(physical_device->CheckExtensionSupport(ext_name))
|
||||
ext_list->Add(ext_name);
|
||||
|
||||
if(require.line_rasterization)
|
||||
if(require.lineRasterization>=VulkanHardwareRequirement::SupportLevel::Want)
|
||||
ext_list->Add(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME);
|
||||
|
||||
if(require.texture_compression.pvrtc) //前面检测过了,所以这里不用再次检测是否支持
|
||||
if(require.texture_compression.PVRTC>=VulkanHardwareRequirement::SupportLevel::Want) //前面检测过了,所以这里不用再次检测是否支持
|
||||
ext_list->Add(VK_IMG_FORMAT_PVRTC_EXTENSION_NAME);
|
||||
|
||||
if(require.uint8_draw_index)
|
||||
if(require.fullDrawIndexUint8>=VulkanHardwareRequirement::SupportLevel::Want)
|
||||
ext_list->Add(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME);
|
||||
}
|
||||
|
||||
void SetDeviceFeatures(VkPhysicalDeviceFeatures *features,const VkPhysicalDeviceFeatures &pdf,const VulkanHardwareRequirement &require)
|
||||
{
|
||||
#define FEATURE_COPY(name) features->name=pdf.name;
|
||||
#define REQURE_FEATURE_COPY(name) if(require.name>=VulkanHardwareRequirement::SupportLevel::Want)features->name=pdf.name;
|
||||
#define REQURE_TEXTURE_FEATURE_COPY(name) if(require.texture_compression.name>=VulkanHardwareRequirement::SupportLevel::Want)features->textureCompression##name=pdf.textureCompression##name;
|
||||
|
||||
if(require.geometry_shader) FEATURE_COPY(geometryShader);
|
||||
// if(require.compute_shader) FEATURE_COPY(computeShader);
|
||||
FEATURE_COPY(multiDrawIndirect);
|
||||
FEATURE_COPY(samplerAnisotropy);
|
||||
|
||||
FEATURE_COPY(multiDrawIndirect);
|
||||
REQURE_FEATURE_COPY(geometryShader);
|
||||
|
||||
FEATURE_COPY(samplerAnisotropy);
|
||||
REQURE_FEATURE_COPY(imageCubeArray);
|
||||
|
||||
if(require.texture_cube_array) FEATURE_COPY(imageCubeArray);
|
||||
if(require.uint32_draw_index) FEATURE_COPY(fullDrawIndexUint32);
|
||||
if(require.wide_lines) FEATURE_COPY(wideLines)
|
||||
if(require.large_points) FEATURE_COPY(largePoints)
|
||||
REQURE_FEATURE_COPY(fullDrawIndexUint32);
|
||||
REQURE_FEATURE_COPY(sampleRateShading);
|
||||
|
||||
if(require.texture_compression.bc)FEATURE_COPY(textureCompressionBC);
|
||||
if(require.texture_compression.etc2)FEATURE_COPY(textureCompressionETC2);
|
||||
if(require.texture_compression.astc_ldr)FEATURE_COPY(textureCompressionASTC_LDR);
|
||||
REQURE_FEATURE_COPY(fillModeNonSolid);
|
||||
|
||||
REQURE_FEATURE_COPY(wideLines)
|
||||
REQURE_FEATURE_COPY(largePoints)
|
||||
|
||||
REQURE_TEXTURE_FEATURE_COPY(BC);
|
||||
REQURE_TEXTURE_FEATURE_COPY(ETC2);
|
||||
REQURE_TEXTURE_FEATURE_COPY(ASTC_LDR);
|
||||
|
||||
#undef REQURE_TEXTURE_FEATURE_COPY
|
||||
#undef REQURE_FEATURE_COPY
|
||||
#undef FEATURE_COPY
|
||||
}
|
||||
|
||||
@@ -222,6 +229,18 @@ VkDevice VulkanDeviceCreater::CreateDevice(const uint32_t graphics_family)
|
||||
create_info.ppEnabledLayerNames =nullptr;
|
||||
create_info.pEnabledFeatures =&features;
|
||||
|
||||
VkPhysicalDeviceIndexTypeUint8FeaturesEXT index_type_uint8_features;
|
||||
|
||||
if(physical_device->SupportU8Index()
|
||||
&&require.fullDrawIndexUint8>=VulkanHardwareRequirement::SupportLevel::Want)
|
||||
{
|
||||
create_info.pNext=&index_type_uint8_features;
|
||||
|
||||
index_type_uint8_features.sType =VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_INDEX_TYPE_UINT8_FEATURES_EXT;
|
||||
index_type_uint8_features.pNext =nullptr;
|
||||
index_type_uint8_features.indexTypeUint8=VK_TRUE;
|
||||
}
|
||||
|
||||
VkDevice device;
|
||||
|
||||
if(vkCreateDevice(*physical_device,&create_info,nullptr,&device)==VK_SUCCESS)
|
||||
@@ -293,6 +312,18 @@ GPUDevice *VulkanDeviceCreater::CreateRenderDevice()
|
||||
|
||||
ChooseSurfaceFormat();
|
||||
|
||||
if(physical_device->SupportU8Index()
|
||||
&&require.fullDrawIndexUint8>=VulkanHardwareRequirement::SupportLevel::Want)
|
||||
{
|
||||
device_attr->uint8_index_type=true;
|
||||
}
|
||||
|
||||
if(physical_device->SupportU32Index()
|
||||
&&require.fullDrawIndexUint32>=VulkanHardwareRequirement::SupportLevel::Want)
|
||||
{
|
||||
device_attr->uint32_index_type=true;
|
||||
}
|
||||
|
||||
device_attr->surface_format=surface_format;
|
||||
|
||||
GetDeviceQueue(device_attr);
|
||||
@@ -366,49 +397,74 @@ bool VulkanDeviceCreater::RequirementCheck()
|
||||
{
|
||||
const VkPhysicalDeviceLimits &limits=physical_device->GetLimits();
|
||||
|
||||
if(require.min_1d_image_size >0&&require.min_1d_image_size >limits.maxImageDimension1D )return(false);
|
||||
if(require.min_2d_image_size >0&&require.min_2d_image_size >limits.maxImageDimension2D )return(false);
|
||||
if(require.min_3d_image_size >0&&require.min_3d_image_size >limits.maxImageDimension3D )return(false);
|
||||
if(require.min_cube_image_size >0&&require.min_cube_image_size >limits.maxImageDimensionCube )return(false);
|
||||
if(require.min_array_image_layers >0&&require.min_array_image_layers >limits.maxImageArrayLayers )return(false);
|
||||
#define VHR_MINCHECK(name) if(require.name>0&&require.name>limits.name)return(false);
|
||||
|
||||
if(require.min_vertex_input_attribute >0&&require.min_vertex_input_attribute >limits.maxVertexInputAttributes)return(false);
|
||||
if(require.min_color_attachments >0&&require.min_color_attachments >limits.maxColorAttachments )return(false);
|
||||
VHR_MINCHECK(maxImageDimension1D )
|
||||
VHR_MINCHECK(maxImageDimension2D )
|
||||
VHR_MINCHECK(maxImageDimension3D )
|
||||
VHR_MINCHECK(maxImageDimensionCube )
|
||||
VHR_MINCHECK(maxImageArrayLayers )
|
||||
|
||||
if(require.min_push_constant_size >0&&require.min_push_constant_size >limits.maxPushConstantsSize )return(false);
|
||||
if(require.min_ubo_range >0&&require.min_ubo_range >limits.maxUniformBufferRange )return(false);
|
||||
if(require.min_ssbo_range >0&&require.min_ssbo_range >limits.maxStorageBufferRange )return(false);
|
||||
VHR_MINCHECK(maxVertexInputAttributes)
|
||||
VHR_MINCHECK(maxColorAttachments )
|
||||
|
||||
if(require.min_draw_indirect_count >0&&require.min_draw_indirect_count >limits.maxDrawIndirectCount )return(false);
|
||||
VHR_MINCHECK(maxPushConstantsSize )
|
||||
VHR_MINCHECK(maxUniformBufferRange )
|
||||
VHR_MINCHECK(maxStorageBufferRange )
|
||||
|
||||
VHR_MINCHECK(maxDrawIndirectCount )
|
||||
|
||||
#undef VHR_MINCHECK
|
||||
|
||||
const VkPhysicalDeviceFeatures &features10=physical_device->GetFeatures10();
|
||||
const VkPhysicalDeviceVulkan13Features &features13=physical_device->GetFeatures13();
|
||||
|
||||
if(require.geometry_shader &&(!features10.geometryShader ))return(false);
|
||||
if(require.tessellation_shader &&(!features10.tessellationShader ))return(false);
|
||||
#define VHRC(name,check) if(require.name>=VulkanHardwareRequirement::SupportLevel::Must&&(!check))return(false);
|
||||
|
||||
if(require.multi_draw_indirect &&(!features10.multiDrawIndirect ))return(false);
|
||||
#define VHRC_F10(name) VHRC(name,features10.name)
|
||||
#define VHRC_F13(name) VHRC(name,features13.name)
|
||||
#define VHRC_PDE(name,pdename) VHRC(name,physical_device->CheckExtensionSupport(VK_##pdename##_EXTENSION_NAME))
|
||||
#define VHRC_TC10(name) VHRC(texture_compression.name,features10.textureCompression##name)
|
||||
#define VHRC_TC13(name) VHRC(texture_compression.name,features13.textureCompression##name)
|
||||
|
||||
if(require.wide_lines &&(!features10.wideLines ))return(false);
|
||||
if(require.large_points &&(!features10.largePoints ))return(false);
|
||||
if(require.texture_cube_array &&(!features10.imageCubeArray ))return(false);
|
||||
VHRC_F10(geometryShader);
|
||||
VHRC_F10(tessellationShader);
|
||||
|
||||
if(require.uint8_draw_index &&(!physical_device->CheckExtensionSupport(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME)))return(false);
|
||||
if(require.uint32_draw_index &&(!features10.fullDrawIndexUint32 ))return(false);
|
||||
VHRC_F10(multiDrawIndirect);
|
||||
|
||||
if(require.texture_compression.bc &&(!features10.textureCompressionBC))return(false);
|
||||
if(require.texture_compression.etc2 &&(!features10.textureCompressionETC2))return(false);
|
||||
if(require.texture_compression.astc_ldr &&(!features10.textureCompressionASTC_LDR))return(false);
|
||||
if(require.texture_compression.astc_hdr &&(!features13.textureCompressionASTC_HDR))return(false);
|
||||
if(require.texture_compression.pvrtc &&(!physical_device->CheckExtensionSupport(VK_IMG_FORMAT_PVRTC_EXTENSION_NAME)))return(false);
|
||||
VHRC_F10(sampleRateShading);
|
||||
|
||||
if(require.dynamic_rendering&&(!features13.dynamicRendering))return(false);
|
||||
VHRC_F10(fillModeNonSolid);
|
||||
|
||||
if(require.dynamic_state[0]&&(!physical_device->CheckExtensionSupport(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME )))return(false);
|
||||
if(require.dynamic_state[1]&&(!physical_device->CheckExtensionSupport(VK_EXT_EXTENDED_DYNAMIC_STATE_2_EXTENSION_NAME )))return(false);
|
||||
if(require.dynamic_state[2]&&(!physical_device->CheckExtensionSupport(VK_EXT_EXTENDED_DYNAMIC_STATE_3_EXTENSION_NAME )))return(false);
|
||||
VHRC_F10(wideLines);
|
||||
|
||||
if(require.line_rasterization&&(!physical_device->CheckExtensionSupport(VK_EXT_LINE_RASTERIZATION_EXTENSION_NAME)))return(false);
|
||||
#ifndef __APPLE__
|
||||
VHRC_PDE(lineRasterization, EXT_LINE_RASTERIZATION);
|
||||
#endif//__APPLE__
|
||||
|
||||
VHRC_F10(largePoints);
|
||||
|
||||
VHRC_F10(imageCubeArray);
|
||||
|
||||
VHRC_PDE(fullDrawIndexUint8, EXT_INDEX_TYPE_UINT8);
|
||||
VHRC_F10(fullDrawIndexUint32);
|
||||
|
||||
VHRC_TC10(BC);
|
||||
VHRC_TC10(ETC2);
|
||||
VHRC_TC10(ASTC_LDR);
|
||||
VHRC_TC13(ASTC_HDR);
|
||||
VHRC_PDE(texture_compression.PVRTC, IMG_FORMAT_PVRTC);
|
||||
|
||||
VHRC_F13(dynamicRendering);
|
||||
|
||||
VHRC_PDE(dynamicState[0], EXT_EXTENDED_DYNAMIC_STATE);
|
||||
VHRC_PDE(dynamicState[1], EXT_EXTENDED_DYNAMIC_STATE_2);
|
||||
VHRC_PDE(dynamicState[2], EXT_EXTENDED_DYNAMIC_STATE_3);
|
||||
|
||||
#undef VHRC_PDE
|
||||
#undef VHRC_F13
|
||||
#undef VHRC_F10
|
||||
#undef VHRC
|
||||
|
||||
return(true);
|
||||
}
|
||||
|
@@ -51,7 +51,7 @@ void *DeviceMemory::Map()
|
||||
|
||||
void *DeviceMemory::Map(const VkDeviceSize offset,const VkDeviceSize size)
|
||||
{
|
||||
if(offset<0||offset+size>=req.size)
|
||||
if(offset<0||offset+size>req.size)
|
||||
return(nullptr);
|
||||
|
||||
void *result;
|
||||
|
@@ -163,6 +163,7 @@ GPUPhysicalDevice::GPUPhysicalDevice(VkInstance inst,VkPhysicalDevice pd)
|
||||
debug_queue_family_properties_out(debug_front.c_str(),queue_family_properties);
|
||||
}
|
||||
|
||||
support_u8_index=CheckExtensionSupport(VK_EXT_INDEX_TYPE_UINT8_EXTENSION_NAME);
|
||||
dynamic_state=CheckExtensionSupport(VK_EXT_EXTENDED_DYNAMIC_STATE_EXTENSION_NAME);
|
||||
}
|
||||
|
||||
|
@@ -2,6 +2,8 @@
|
||||
#include<hgl/graph/VKBuffer.h>
|
||||
#include<hgl/graph/VKShaderModule.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include"VKPrimitiveData.h"
|
||||
|
||||
#ifdef _DEBUG
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
@@ -9,6 +11,7 @@
|
||||
#endif//_DEBUG
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
//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);
|
||||
@@ -27,72 +30,35 @@ VK_NAMESPACE_BEGIN
|
||||
// return(true);
|
||||
//}
|
||||
|
||||
bool Primitive::Set(const AnsiString &name,VBO *vbo,VkDeviceSize offset)
|
||||
Primitive::Primitive(const AnsiString &pn,PrimitiveData *pd)
|
||||
{
|
||||
if(!vbo)return(false);
|
||||
if(buffer_list.KeyExist(name))return(false);
|
||||
|
||||
VBOData bd;
|
||||
|
||||
bd.buf=vbo;
|
||||
bd.offset=offset;
|
||||
|
||||
buffer_list.Add(name,bd);
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
{
|
||||
du->SetBuffer(vbo->GetBuffer(),prim_name+":VBO:Buffer:"+name);
|
||||
du->SetDeviceMemory(vbo->GetVkMemory(),prim_name+":VBO:Memory:"+name);
|
||||
}
|
||||
#endif//_DEBUG
|
||||
|
||||
return(true);
|
||||
prim_name=pn;
|
||||
prim_data=pd;
|
||||
}
|
||||
|
||||
VBO *Primitive::GetVBO(const AnsiString &name,VkDeviceSize *offset)
|
||||
Primitive::~Primitive()
|
||||
{
|
||||
if(!offset)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
VBOData bd;
|
||||
|
||||
if(buffer_list.Get(name,bd))
|
||||
{
|
||||
*offset=bd.offset;
|
||||
return bd.buf;
|
||||
}
|
||||
|
||||
return(nullptr);
|
||||
SAFE_CLEAR(prim_data);
|
||||
}
|
||||
|
||||
VkBuffer Primitive::GetBuffer(const AnsiString &name,VkDeviceSize *offset)
|
||||
const VkDeviceSize Primitive::GetVertexCount()const
|
||||
{
|
||||
VBO *vbo=GetVBO(name,offset);
|
||||
|
||||
if(vbo)return vbo->GetBuffer();
|
||||
|
||||
return(VK_NULL_HANDLE);
|
||||
return prim_data->GetVertexCount();
|
||||
}
|
||||
|
||||
bool Primitive::Set(IndexBuffer *ib,VkDeviceSize offset)
|
||||
const int Primitive::GetVABCount()const
|
||||
{
|
||||
if(!ib)return(false);
|
||||
|
||||
index_buffer_data.buffer=ib;
|
||||
index_buffer_data.offset=offset;
|
||||
|
||||
#ifdef _DEBUG
|
||||
DebugUtils *du=device->GetDebugUtils();
|
||||
|
||||
if(du)
|
||||
{
|
||||
du->SetBuffer(ib->GetBuffer(),prim_name+":IBO:Buffer");
|
||||
du->SetDeviceMemory(ib->GetVkMemory(),prim_name+":IBO:Memory");
|
||||
}
|
||||
#endif//_DEBUG
|
||||
return(true);
|
||||
return prim_data->GetVABCount();
|
||||
}
|
||||
|
||||
VABAccess *Primitive::GetVABAccess(const AnsiString &name)
|
||||
{
|
||||
return prim_data->GetVABAccess(name);
|
||||
}
|
||||
|
||||
IBAccess *Primitive::GetIBAccess()
|
||||
{
|
||||
return prim_data->GetIBAccess();
|
||||
}
|
||||
|
||||
VK_NAMESPACE_END
|
||||
|
296
src/SceneGraph/Vulkan/VKPrimitiveData.cpp
Normal file
296
src/SceneGraph/Vulkan/VKPrimitiveData.cpp
Normal file
@@ -0,0 +1,296 @@
|
||||
#include"VKPrimitiveData.h"
|
||||
#include<hgl/graph/VKVertexInputLayout.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
#include<hgl/graph/VKDevice.h>
|
||||
#include<hgl/graph/VertexDataManager.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
|
||||
PrimitiveData::PrimitiveData(const VIL *_vil,const VkDeviceSize vc)
|
||||
{
|
||||
vil=_vil;
|
||||
|
||||
vertex_count=vc;
|
||||
|
||||
vab_access=hgl_zero_new<VABAccess>(_vil->GetCount());
|
||||
|
||||
hgl_zero(ib_access);
|
||||
}
|
||||
|
||||
PrimitiveData::~PrimitiveData()
|
||||
{
|
||||
SAFE_CLEAR_ARRAY(vab_access); //注意:这里并不释放VAB,在派生类中释放
|
||||
}
|
||||
|
||||
const int PrimitiveData::GetVABCount()const
|
||||
{
|
||||
return vil->GetCount();
|
||||
}
|
||||
|
||||
const int PrimitiveData::GetVABIndex(const AnsiString &name) const
|
||||
{
|
||||
if(name.IsEmpty())return(-1);
|
||||
|
||||
return vil->GetIndex(name);
|
||||
}
|
||||
|
||||
VABAccess *PrimitiveData::GetVABAccess(const int index)
|
||||
{
|
||||
if(index<0||index>=vil->GetCount())return(nullptr);
|
||||
|
||||
return vab_access+index;
|
||||
}
|
||||
|
||||
VABAccess *PrimitiveData::GetVABAccess(const AnsiString &name)
|
||||
{
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const int index=vil->GetIndex(name);
|
||||
|
||||
if(index<0)return(nullptr);
|
||||
|
||||
return vab_access+index;
|
||||
}
|
||||
|
||||
//VABAccess *SetVAB(PrimitiveData *pd,const int index,VAB *vab,VkDeviceSize start,VkDeviceSize count)
|
||||
//{
|
||||
// if(!pd)return(nullptr);
|
||||
// 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;
|
||||
//}
|
||||
|
||||
//void SetIndexBuffer(PrimitiveData *pd,IndexBuffer *ib,const VkDeviceSize ic)
|
||||
//{
|
||||
// if(!pd)return;
|
||||
//
|
||||
// pd->ib_access.buffer=ib;
|
||||
// pd->ib_access.start=0;
|
||||
// pd->ib_access.count=ic;
|
||||
//}
|
||||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
* 直接使用GPUDevice创建VAB/IBO,并在释构时释放
|
||||
*/
|
||||
class PrimitiveDataPrivateBuffer:public PrimitiveData
|
||||
{
|
||||
GPUDevice *device;
|
||||
|
||||
public:
|
||||
|
||||
VertexDataManager *GetVDM(){return nullptr;}
|
||||
|
||||
PrimitiveDataPrivateBuffer(GPUDevice *dev,const VIL *_vil,const VkDeviceSize vc):PrimitiveData(_vil,vc)
|
||||
{
|
||||
device=dev;
|
||||
}
|
||||
|
||||
~PrimitiveDataPrivateBuffer() override
|
||||
{
|
||||
VABAccess *vab=vab_access;
|
||||
|
||||
for(uint i=0;i<vil->GetCount();i++)
|
||||
{
|
||||
if(vab->vab)
|
||||
{
|
||||
delete vab->vab;
|
||||
vab->vab=nullptr;
|
||||
}
|
||||
|
||||
++vab;
|
||||
}
|
||||
|
||||
if(ib_access.buffer)
|
||||
{
|
||||
delete ib_access.buffer;
|
||||
ib_access.buffer=nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
IBAccess *InitIBO(const VkDeviceSize index_count,IndexType it) override
|
||||
{
|
||||
if(!device)return(nullptr);
|
||||
|
||||
if(ib_access.buffer)
|
||||
{
|
||||
delete ib_access.buffer;
|
||||
ib_access.buffer=nullptr;
|
||||
}
|
||||
|
||||
ib_access.buffer=device->CreateIBO(it,index_count);
|
||||
|
||||
if(!ib_access.buffer)
|
||||
return(nullptr);
|
||||
|
||||
ib_access.start=0;
|
||||
ib_access.count=index_count;
|
||||
|
||||
return(&ib_access);
|
||||
}
|
||||
|
||||
VABAccess *InitVAB(const AnsiString &name,const VkFormat &format,const void *data)
|
||||
{
|
||||
if(!device)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const int index=vil->GetIndex(name);
|
||||
|
||||
if(index<0||index>=vil->GetCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(index);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(nullptr);
|
||||
|
||||
VABAccess *vaba=vab_access+index;
|
||||
|
||||
if(!vaba->vab)
|
||||
{
|
||||
vaba->vab=device->CreateVAB(format,vertex_count,data);
|
||||
|
||||
if(!vaba->vab)
|
||||
return(nullptr);
|
||||
|
||||
vaba->start=0;
|
||||
vaba->count=vertex_count;
|
||||
}
|
||||
else
|
||||
{
|
||||
vaba->vab->Write(data,vertex_count);
|
||||
}
|
||||
|
||||
return vaba;
|
||||
}
|
||||
};//class PrimitiveDataPrivateBuffer:public PrimitiveData
|
||||
|
||||
/**
|
||||
* 使用VertexDataBuffer分配VAB/IBO,在本类析构时归还数据
|
||||
*/
|
||||
class PrimitiveDataVDM:public PrimitiveData
|
||||
{
|
||||
VertexDataManager *vdm;
|
||||
|
||||
DataChain::UserNode *ib_node;
|
||||
DataChain::UserNode *vab_node;
|
||||
|
||||
public:
|
||||
|
||||
VertexDataManager *GetVDM(){return vdm;}
|
||||
|
||||
PrimitiveDataVDM(VertexDataManager *_vdm,const VkDeviceSize vc):PrimitiveData(_vdm->GetVIL(),vc)
|
||||
{
|
||||
vdm=_vdm;
|
||||
|
||||
ib_node=nullptr;
|
||||
vab_node=vdm->AcquireVAB(vc);
|
||||
}
|
||||
|
||||
~PrimitiveDataVDM() override
|
||||
{
|
||||
if(ib_node)
|
||||
vdm->ReleaseIB(ib_node);
|
||||
|
||||
if(vab_node)
|
||||
vdm->ReleaseVAB(vab_node);
|
||||
}
|
||||
|
||||
IBAccess *InitIBO(const VkDeviceSize index_count,IndexType it) override
|
||||
{
|
||||
if(index_count<=0)return(nullptr);
|
||||
if(!vdm)return(nullptr);
|
||||
|
||||
if(!ib_node)
|
||||
{
|
||||
ib_node=vdm->AcquireIB(index_count);
|
||||
|
||||
if(!ib_node)
|
||||
return(nullptr);
|
||||
|
||||
ib_access.buffer=vdm->GetIBO();
|
||||
ib_access.start =ib_node->GetStart();
|
||||
ib_access.count =ib_node->GetCount();
|
||||
}
|
||||
|
||||
return &ib_access;
|
||||
}
|
||||
|
||||
VABAccess *InitVAB(const AnsiString &name,const VkFormat &format,const void *data)
|
||||
{
|
||||
if(!vdm)return(nullptr);
|
||||
if(!vil)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const int index=vil->GetIndex(name);
|
||||
|
||||
if(index<0||index>=vil->GetCount())
|
||||
return(nullptr);
|
||||
|
||||
const VertexInputFormat *vif=vil->GetConfig(index);
|
||||
|
||||
if(!vif)return(nullptr);
|
||||
|
||||
if(vif->format!=format)
|
||||
return(nullptr);
|
||||
|
||||
VABAccess *vaba=vab_access+index;
|
||||
|
||||
if(!vaba->vab)
|
||||
{
|
||||
vaba->vab=vdm->GetVAB(index);
|
||||
|
||||
if(!vaba->vab)
|
||||
return(nullptr);
|
||||
|
||||
vaba->start=vab_node->GetStart();
|
||||
vaba->count=vab_node->GetCount();
|
||||
}
|
||||
|
||||
if(vaba->vab&&data)
|
||||
vaba->vab->Write(data,vaba->start,vaba->count);
|
||||
|
||||
return vaba;
|
||||
}
|
||||
};//class PrimitiveDataVDM:public PrimitiveData
|
||||
}//namespace
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const VkDeviceSize vc)
|
||||
{
|
||||
if(!dev)return(nullptr);
|
||||
if(!_vil)return(nullptr);
|
||||
if(vc<=0)return(nullptr);
|
||||
|
||||
return(new PrimitiveDataPrivateBuffer(dev,_vil,vc));
|
||||
}
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(VertexDataManager *vdm,const VkDeviceSize vc)
|
||||
{
|
||||
if(!vdm)return(nullptr);
|
||||
if(vc<=0)return(nullptr);
|
||||
|
||||
return(new PrimitiveDataVDM(vdm,vc));
|
||||
}
|
||||
VK_NAMESPACE_END
|
55
src/SceneGraph/Vulkan/VKPrimitiveData.h
Normal file
55
src/SceneGraph/Vulkan/VKPrimitiveData.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#include<hgl/graph/VK.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处理,所以此处这样定义。
|
||||
*/
|
||||
|
||||
class PrimitiveData
|
||||
{
|
||||
protected:
|
||||
|
||||
const VIL * vil;
|
||||
|
||||
VkDeviceSize vertex_count;
|
||||
|
||||
VABAccess *vab_access;
|
||||
IBAccess ib_access;
|
||||
|
||||
public:
|
||||
|
||||
PrimitiveData(const VIL *_vil,const VkDeviceSize vc);
|
||||
virtual ~PrimitiveData();
|
||||
|
||||
public:
|
||||
|
||||
const VkDeviceSize GetVertexCount ()const{return vertex_count;}
|
||||
const int GetVABCount ()const;
|
||||
const int GetVABIndex (const AnsiString &name)const;
|
||||
VABAccess * GetVABAccess (const int index);
|
||||
VABAccess * GetVABAccess (const AnsiString &name);
|
||||
IBAccess * GetIBAccess (){return &ib_access;}
|
||||
|
||||
public:
|
||||
|
||||
virtual VertexDataManager *GetVDM()=0;
|
||||
|
||||
public:
|
||||
|
||||
virtual IBAccess * InitIBO(const VkDeviceSize index_count,IndexType it)=0;
|
||||
virtual VABAccess *InitVAB(const AnsiString &name,const VkFormat &format,const void *data)=0;
|
||||
};//class PrimitiveData
|
||||
|
||||
PrimitiveData *CreatePrimitiveData(GPUDevice *dev,const VIL *_vil,const VkDeviceSize vc);
|
||||
PrimitiveData *CreatePrimitiveData(VertexDataManager *vdm,const VkDeviceSize vc);
|
||||
VK_NAMESPACE_END
|
@@ -3,11 +3,12 @@
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKInlinePipeline.h>
|
||||
#include<hgl/graph/VKVertexAttribBuffer.h>
|
||||
#include<hgl/graph/VKIndexBuffer.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
VBO *RenderResource::CreateVBO(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
|
||||
VAB *RenderResource::CreateVAB(VkFormat format,uint32_t count,const void *data,SharingMode sharing_mode)
|
||||
{
|
||||
VBO *vb=device->CreateVBO(format,count,data,sharing_mode);
|
||||
VAB *vb=device->CreateVAB(format,count,data,sharing_mode);
|
||||
|
||||
if(!vb)
|
||||
return(nullptr);
|
||||
@@ -79,18 +80,6 @@ MaterialInstance *RenderResource::CreateMaterialInstance(const mtl::MaterialCrea
|
||||
return CreateMaterialInstance(mtl,vil_cfg);
|
||||
}
|
||||
|
||||
Primitive *RenderResource::CreatePrimitive(const AnsiString &name,const uint32_t vertex_count)
|
||||
{
|
||||
if(!vertex_count)return(nullptr);
|
||||
|
||||
Primitive *ro=new Primitive(device,name,vertex_count);
|
||||
|
||||
if(ro)
|
||||
Add(ro);
|
||||
|
||||
return ro;
|
||||
}
|
||||
|
||||
Renderable *RenderResource::CreateRenderable(Primitive *r,MaterialInstance *mi,Pipeline *p)
|
||||
{
|
||||
if(!p||!mi||!r)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKRenderable.h>
|
||||
#include<hgl/graph/VKMaterialInstance.h>
|
||||
#include<hgl/graph/VKMaterialParameters.h>
|
||||
#include<hgl/graph/VKMaterial.h>
|
||||
@@ -6,7 +6,7 @@
|
||||
#include<hgl/log/LogInfo.h>
|
||||
|
||||
VK_NAMESPACE_BEGIN
|
||||
VertexInputData::VertexInputData(const uint32_t c,const uint32_t vc,const IndexBufferData *ibd)
|
||||
VertexInputData::VertexInputData(const uint32_t c,const uint32_t vc,const IBAccess *iba)
|
||||
{
|
||||
binding_count=c;
|
||||
|
||||
@@ -15,7 +15,10 @@ VertexInputData::VertexInputData(const uint32_t c,const uint32_t vc,const IndexB
|
||||
|
||||
vertex_count=vc;
|
||||
|
||||
index_buffer=ibd;
|
||||
if(!iba||!iba->buffer)
|
||||
ib_access=nullptr;
|
||||
else
|
||||
ib_access=iba;
|
||||
}
|
||||
|
||||
VertexInputData::~VertexInputData()
|
||||
@@ -48,50 +51,53 @@ Renderable *CreateRenderable(Primitive *prim,MaterialInstance *mi,Pipeline *p)
|
||||
const uint32_t input_count=vil->GetCount(VertexInputGroup::Basic); //不统计Bone/LocalToWorld组的
|
||||
const UTF8String &mtl_name=mi->GetMaterial()->GetName();
|
||||
|
||||
if(prim->GetBufferCount()<input_count) //小于材质要求的数量?那自然是不行的
|
||||
if(prim->GetVABCount()<input_count) //小于材质要求的数量?那自然是不行的
|
||||
{
|
||||
LOG_ERROR("[FATAL ERROR] input buffer count of Renderable lesser than Material, Material name: "+mtl_name);
|
||||
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
VBO *vbo;
|
||||
VertexInputData *vid=new VertexInputData(input_count,prim->GetVertexCount(),prim->GetIBAccess());
|
||||
|
||||
VertexInputData *vid=new VertexInputData(input_count,prim->GetVertexCount(),prim->GetIndexBufferData());
|
||||
|
||||
const VertexInputFormat *vif=vil->GetFormatList(VertexInputGroup::Basic);
|
||||
const VertexInputFormat *vif=vil->GetVIFList(VertexInputGroup::Basic);
|
||||
VABAccess *vab_access;
|
||||
|
||||
for(uint i=0;i<input_count;i++)
|
||||
{
|
||||
vbo=prim->GetVBO(vif->name,vid->buffer_offset+i);
|
||||
//注: VIF来自于材质,但VAB来自于Primitive。
|
||||
// 两个并不一定一样,排序也不一定一样。所以不能让PRIMTIVE直接提供BUFFER_LIST/OFFSET来搞一次性绑定。
|
||||
|
||||
if(!vbo)
|
||||
vab_access=prim->GetVABAccess(vif->name);
|
||||
|
||||
if(!vab_access||!vab_access->vab)
|
||||
{
|
||||
LOG_ERROR("[FATAL ERROR] not found VBO \""+AnsiString(vif->name)+"\" in Material: "+mtl_name);
|
||||
LOG_ERROR("[FATAL ERROR] not found VAB \""+AnsiString(vif->name)+"\" in Material: "+mtl_name);
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vbo->GetFormat()!=vif->format)
|
||||
if(vab_access->vab->GetFormat()!=vif->format)
|
||||
{
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(vif->name)+
|
||||
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
|
||||
UTF8String("\" format can't match Renderable, Material(")+mtl_name+
|
||||
UTF8String(") Format(")+GetVulkanFormatName(vif->format)+
|
||||
UTF8String("), VBO Format(")+GetVulkanFormatName(vbo->GetFormat())+
|
||||
UTF8String("), VAB Format(")+GetVulkanFormatName(vab_access->vab->GetFormat())+
|
||||
")");
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
if(vbo->GetStride()!=vif->stride)
|
||||
if(vab_access->vab->GetStride()!=vif->stride)
|
||||
{
|
||||
LOG_ERROR( "[FATAL ERROR] VBO \""+UTF8String(vif->name)+
|
||||
LOG_ERROR( "[FATAL ERROR] VAB \""+UTF8String(vif->name)+
|
||||
UTF8String("\" stride can't match Renderable, Material(")+mtl_name+
|
||||
UTF8String(") stride(")+UTF8String::numberOf(vif->stride)+
|
||||
UTF8String("), VBO stride(")+UTF8String::numberOf(vbo->GetStride())+
|
||||
UTF8String("), VAB stride(")+UTF8String::numberOf(vab_access->vab->GetStride())+
|
||||
")");
|
||||
return(nullptr);
|
||||
}
|
||||
|
||||
vid->buffer_list[i]=vbo->GetBuffer();
|
||||
vid->buffer_offset[i]=vab_access->start*vif->stride;
|
||||
vid->buffer_list[i]=vab_access->vab->GetBuffer();
|
||||
++vif;
|
||||
}
|
||||
|
||||
|
@@ -39,7 +39,7 @@ void main()
|
||||
if(!Std2DMaterial::CustomVertexShader(vsc))
|
||||
return(false);
|
||||
|
||||
vsc->AddMaterialInstanceID();
|
||||
vsc->AddAssign();
|
||||
vsc->SetMain(vs_main);
|
||||
return(true);
|
||||
}
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include"Std2DMaterial.h"
|
||||
#include"Std2DMaterial.h"
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
@@ -13,10 +13,18 @@ bool Std2DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
|
||||
vsc->AddInput(cfg->position_format,VAN::Position);
|
||||
|
||||
const bool is_rect=(cfg->prim==Prim::SolidRectangles||cfg->prim==Prim::WireRectangles);
|
||||
|
||||
if(cfg->local_to_world||cfg->material_instance)
|
||||
{
|
||||
mci->AddStruct(SBS_LocalToWorld);
|
||||
|
||||
mci->AddUBO(VK_SHADER_STAGE_ALL_GRAPHICS,DescriptorSetType::PerFrame,SBS_LocalToWorld);
|
||||
|
||||
vsc->AddAssign();
|
||||
}
|
||||
|
||||
if(cfg->local_to_world)
|
||||
{
|
||||
vsc->AddLocalToWorld();
|
||||
mci->SetLocalToWorld(VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
|
||||
if(is_rect)
|
||||
|
@@ -16,7 +16,7 @@ namespace
|
||||
|
||||
public:
|
||||
|
||||
Std2DMaterialLoader(material_file::MaterialFileData *data,const Material2DCreateConfig *cfg):Std2DMaterial(cfg)
|
||||
Std2DMaterialLoader(material_file::MaterialFileData *data,const Material2DCreateConfig *c):Std2DMaterial(c)
|
||||
{
|
||||
mfd=data;
|
||||
}
|
||||
@@ -76,9 +76,6 @@ namespace
|
||||
for(auto &ua:mfd->vi)
|
||||
vsc->AddInput(ua.vat,ua.name);
|
||||
|
||||
if(mfd->mi.mi_bytes>0)
|
||||
vsc->AddMaterialInstanceID();
|
||||
|
||||
if(!Std2DMaterial::CustomVertexShader(vsc))
|
||||
return(false);
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include"Std3DMaterial.h"
|
||||
#include"Std3DMaterial.h"
|
||||
#include<hgl/shadergen/MaterialCreateInfo.h>
|
||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||
#include<hgl/graph/mtl/UBOCommon.h>
|
||||
@@ -10,6 +10,15 @@ STD_MTL_NAMESPACE_BEGIN
|
||||
bool Std3DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
|
||||
{
|
||||
vsc->AddInput(cfg->position_format,VAN::Position);
|
||||
|
||||
if(cfg->camera||cfg->local_to_world||cfg->material_instance)
|
||||
{
|
||||
mci->AddStruct(SBS_LocalToWorld);
|
||||
|
||||
mci->AddUBO(VK_SHADER_STAGE_ALL_GRAPHICS,DescriptorSetType::PerFrame,SBS_LocalToWorld);
|
||||
|
||||
vsc->AddAssign();
|
||||
}
|
||||
|
||||
if(cfg->camera)
|
||||
{
|
||||
@@ -24,7 +33,6 @@ bool Std3DMaterial::CustomVertexShader(ShaderCreateInfoVertex *vsc)
|
||||
{
|
||||
mci->SetLocalToWorld(VK_SHADER_STAGE_ALL_GRAPHICS);
|
||||
|
||||
vsc->AddLocalToWorld();
|
||||
vsc->AddFunction(cfg->camera?func::GetPosition3DL2WCamera:func::GetPosition3DL2W);
|
||||
}
|
||||
else
|
||||
|
@@ -16,8 +16,8 @@ namespace
|
||||
|
||||
public:
|
||||
|
||||
Std3DMaterialLoader(material_file::MaterialFileData *data,const Material3DCreateConfig *cfg)
|
||||
: Std3DMaterial(cfg)
|
||||
Std3DMaterialLoader(material_file::MaterialFileData *data,const Material3DCreateConfig *c)
|
||||
: Std3DMaterial(c)
|
||||
{
|
||||
mfd=data;
|
||||
}
|
||||
@@ -77,9 +77,6 @@ namespace
|
||||
for(auto &ua:mfd->vi)
|
||||
vsc->AddInput(ua.vat,ua.name);
|
||||
|
||||
if(mfd->mi.mi_bytes>0)
|
||||
vsc->AddMaterialInstanceID();
|
||||
|
||||
if(!Std3DMaterial::CustomVertexShader(vsc))
|
||||
return (false);
|
||||
|
||||
|
@@ -172,9 +172,9 @@ bool MaterialCreateInfo::SetMaterialInstance(const AnsiString &glsl_codes,const
|
||||
|
||||
mi_ubo=CreateUBODescriptor(SBS_MaterialInstance,shader_stage_flag_bits);
|
||||
|
||||
mdi.AddUBO(shader_stage_flag_bits,DescriptorSetType::PerMaterial,mi_ubo);
|
||||
mdi.AddUBO(shader_stage_flag_bits,DST_MaterialInstance,mi_ubo);
|
||||
|
||||
const AnsiString MI_MAX_COUNT=AnsiString::numberOf(mi_max_count);
|
||||
const AnsiString MI_MAX_COUNT_STRING=AnsiString::numberOf(mi_max_count);
|
||||
|
||||
auto *it=shader_map.GetDataList();
|
||||
|
||||
@@ -182,7 +182,7 @@ bool MaterialCreateInfo::SetMaterialInstance(const AnsiString &glsl_codes,const
|
||||
{
|
||||
if((*it)->key&shader_stage_flag_bits)
|
||||
{
|
||||
(*it)->value->AddDefine("MI_MAX_COUNT",MI_MAX_COUNT);
|
||||
(*it)->value->AddDefine("MI_MAX_COUNT",MI_MAX_COUNT_STRING);
|
||||
(*it)->value->SetMaterialInstance(mi_ubo,mi_codes);
|
||||
}
|
||||
|
||||
@@ -198,6 +198,28 @@ bool MaterialCreateInfo::SetLocalToWorld(const uint32_t shader_stage_flag_bits)
|
||||
{
|
||||
if(shader_stage_flag_bits==0)return(false);
|
||||
|
||||
l2w_max_count=hgl_min<uint32_t>(ubo_range/sizeof(Matrix4f),HGL_U16_MAX);
|
||||
|
||||
mdi.AddStruct(SBS_LocalToWorld);
|
||||
|
||||
l2w_ubo=CreateUBODescriptor(SBS_LocalToWorld,shader_stage_flag_bits);
|
||||
|
||||
mdi.AddUBO(shader_stage_flag_bits,DST_LocalToWorld,l2w_ubo);
|
||||
|
||||
const AnsiString L2W_MAX_COUNT_STRING=AnsiString::numberOf(l2w_max_count);
|
||||
|
||||
auto *it=shader_map.GetDataList();
|
||||
|
||||
for(int i=0;i<shader_map.GetCount();i++)
|
||||
{
|
||||
if((*it)->key&shader_stage_flag_bits)
|
||||
{
|
||||
(*it)->value->AddDefine("L2W_MAX_COUNT",L2W_MAX_COUNT_STRING);
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
|
||||
l2w_shader_stage=shader_stage_flag_bits;
|
||||
|
||||
return(true);
|
||||
|
@@ -12,11 +12,13 @@ namespace material_file
|
||||
using namespace hgl;
|
||||
using namespace hgl::graph;
|
||||
|
||||
constexpr size_t SHADER_RESOURCE_NAME_MAX_LENGTH=VERTEX_ATTRIB_NAME_MAX_LENGTH;
|
||||
|
||||
struct ShaderIOAttrib
|
||||
{
|
||||
VAT vat;
|
||||
|
||||
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
|
||||
char name[VERTEX_ATTRIB_NAME_MAX_LENGTH];
|
||||
};
|
||||
|
||||
struct MaterialInstanceData
|
||||
|
@@ -156,10 +156,11 @@ bool ShaderCreateInfo::ProcSubpassInput()
|
||||
|
||||
namespace
|
||||
{
|
||||
constexpr const char MF_GetMI_VS []="\nMaterialInstance GetMI(){return mtl.mi[MaterialInstanceID];}\n";
|
||||
constexpr const char MI_ID_OUTPUT[]="MaterialInstanceID";
|
||||
constexpr const char MF_GetMI_VS []="\nMaterialInstance GetMI(){return mtl.mi[Assign.y];}\n";
|
||||
constexpr const char MF_GetMI_Other []="\nMaterialInstance GetMI(){return mtl.mi[Input.MaterialInstanceID];}\n";
|
||||
|
||||
constexpr const char MF_HandoverMI_VS[]= "\nvoid HandoverMI(){Output.MaterialInstanceID=MaterialInstanceID;}\n";
|
||||
constexpr const char MF_HandoverMI_VS[]= "\nvoid HandoverMI(){Output.MaterialInstanceID=Assign.y;}\n";
|
||||
constexpr const char MF_HandoverMI_GS[]= "\nvoid HandoverMI(){Output.MaterialInstanceID=Input[0].MaterialInstanceID;}\n";
|
||||
constexpr const char MF_HandoverMI_OTHER[]= "\nvoid HandoverMI(){Output.MaterialInstanceID=Input.MaterialInstanceID;}\n";
|
||||
}//namespace
|
||||
@@ -176,7 +177,7 @@ void ShaderCreateInfo::SetMaterialInstance(UBODescriptor *ubo,const AnsiString &
|
||||
|
||||
void ShaderCreateInfo::AddMaterialInstanceOutput()
|
||||
{
|
||||
AddOutput(VAT_UINT,mtl::func::MaterialInstanceID,Interpolation::Flat);
|
||||
AddOutput(VAT_UINT,MI_ID_OUTPUT,Interpolation::Flat);
|
||||
|
||||
if(shader_stage==VK_SHADER_STAGE_VERTEX_BIT) AddFunction(MF_HandoverMI_VS);else
|
||||
if(shader_stage==VK_SHADER_STAGE_GEOMETRY_BIT) AddFunction(MF_HandoverMI_GS);else
|
||||
|
@@ -1,4 +1,4 @@
|
||||
#include<hgl/shadergen/ShaderCreateInfoVertex.h>
|
||||
#include<hgl/shadergen/ShaderCreateInfoVertex.h>
|
||||
#include<hgl/shadergen/ShaderDescriptorInfo.h>
|
||||
#include<hgl/graph/VertexAttrib.h>
|
||||
#include<hgl/graph/VKShaderStage.h>
|
||||
@@ -48,39 +48,14 @@ void ShaderCreateInfoVertex::AddJoint()
|
||||
AddInput(VAT_VEC4, VAN::JointWeight,VK_VERTEX_INPUT_RATE_VERTEX,VertexInputGroup::JointWeight);
|
||||
}
|
||||
|
||||
namespace
|
||||
void ShaderCreateInfoVertex::AddAssign()
|
||||
{
|
||||
constexpr const char MF_GetLocalToWorld[]=R"(
|
||||
mat4 GetLocalToWorld()
|
||||
{
|
||||
return mat4(LocalToWorld_0,
|
||||
LocalToWorld_1,
|
||||
LocalToWorld_2,
|
||||
LocalToWorld_3);
|
||||
}
|
||||
)";
|
||||
}
|
||||
|
||||
void ShaderCreateInfoVertex::AddLocalToWorld()
|
||||
{
|
||||
char name[]= "LocalToWorld_?";
|
||||
|
||||
for(uint i=0;i<4;i++)
|
||||
{
|
||||
name[sizeof(name)-2]='0'+i;
|
||||
|
||||
AddInput(VAT_VEC4,name,VK_VERTEX_INPUT_RATE_INSTANCE,VertexInputGroup::LocalToWorld);
|
||||
}
|
||||
|
||||
AddFunction(MF_GetLocalToWorld);
|
||||
}
|
||||
|
||||
void ShaderCreateInfoVertex::AddMaterialInstanceID()
|
||||
{
|
||||
AddInput( MI_VAT_FMT,
|
||||
MI_VIS_NAME,
|
||||
AddInput( ASSIGN_VAT_FMT,
|
||||
ASSIGN_VIS_NAME,
|
||||
VK_VERTEX_INPUT_RATE_INSTANCE,
|
||||
VertexInputGroup::MaterialInstanceID);
|
||||
VertexInputGroup::Assign);
|
||||
|
||||
AddFunction(STD_MTL_FUNC_NAMESPACE::MF_GetLocalToWorld_ByAssign);
|
||||
}
|
||||
|
||||
bool ShaderCreateInfoVertex::ProcInput(ShaderCreateInfo *)
|
||||
|
@@ -2,21 +2,11 @@
|
||||
|
||||
#include<hgl/graph/mtl/StdMaterial.h>
|
||||
|
||||
STD_MTL_NAMESPACE_BEGIN
|
||||
namespace func
|
||||
{
|
||||
STD_MTL_FUNC_NAMESPACE_BEGIN
|
||||
//C++端使用一个RG8UI或RGB16UI格式的顶点输入流来传递Assign数据,其中x为LocalToWorld ID,y为MaterialInstance ID
|
||||
|
||||
constexpr const char MF_GetLocalToWorld_ByAssign[]= "\nmat4 GetLocalToWorld(){return l2w.mats[Assign.x];}\n";
|
||||
|
||||
constexpr const char MaterialInstanceID[]="MaterialInstanceID";
|
||||
constexpr const char MF_GetMaterialInstance_ByAssign[]= "\nMaterialInstance GetMaterialInstance(){return mi_set[Assign.y];}\n";
|
||||
|
||||
constexpr const char GetLocalToWorld[]=R"(
|
||||
mat4 GetLocalToWorld()
|
||||
{
|
||||
return mat4(LocalToWorld_0,
|
||||
LocalToWorld_1,
|
||||
LocalToWorld_2,
|
||||
LocalToWorld_3);
|
||||
}
|
||||
)";
|
||||
}//namespace func
|
||||
STD_MTL_NAMESPACE_END
|
||||
STD_MTL_FUNC_NAMESPACE_END
|
||||
|
Reference in New Issue
Block a user