optimized VertexAttribData class
This commit is contained in:
parent
7031270476
commit
30c736b7c8
@ -1 +1 @@
|
||||
Subproject commit 2d8ec257c213376d4c945da7eaf486fe5648e943
|
||||
Subproject commit fbf1e4a625e6ff1efad4258877524b6309382aae
|
@ -89,6 +89,8 @@ struct VAConfig;
|
||||
class VILConfig;
|
||||
class VertexInput;
|
||||
|
||||
struct VertexInputFormat;
|
||||
|
||||
class VertexInputLayout;
|
||||
using VIL=VertexInputLayout;
|
||||
|
||||
|
@ -125,7 +125,7 @@ public: //Buffer相关
|
||||
|
||||
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->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
VBO * CreateVBO (const VAD *vad, SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
|
||||
IndexBuffer * CreateIBO (IndexType type, uint32_t count,const void * data, SharingMode sm=SharingMode::Exclusive);
|
||||
IndexBuffer * CreateIBO16 ( uint32_t count,const uint16 *data, SharingMode sm=SharingMode::Exclusive){return CreateIBO(IndexType::U16, count,(void *)data,sm);}
|
||||
|
@ -74,7 +74,7 @@ public: // VBO/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->GetVulkanFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
VBO *CreateVBO(const VAD *vad,SharingMode sm=SharingMode::Exclusive){return CreateVBO(vad->GetFormat(),vad->GetCount(),vad->GetData(),sm);}
|
||||
|
||||
#define SCENE_DB_CREATE_FUNC(name) DeviceBuffer *Create##name(VkDeviceSize size,void *data,SharingMode sm=SharingMode::Exclusive); \
|
||||
DeviceBuffer *Create##name(VkDeviceSize size,SharingMode sm=SharingMode::Exclusive);
|
||||
|
@ -15,18 +15,19 @@ namespace hgl
|
||||
|
||||
protected:
|
||||
|
||||
const uint32_t vec_size; ///<每个数据成员数(比如二维坐标为2、三维坐标为3)
|
||||
VkFormat format;
|
||||
|
||||
uint32_t count; ///<数据个数
|
||||
|
||||
const uint32_t stride; ///<每组数据字节数
|
||||
const uint32_t total_bytes; ///<字节数
|
||||
|
||||
VkFormat vk_format; ///<在Vulkan中的数据类型
|
||||
uint32_t total_bytes; ///<字节数
|
||||
|
||||
public:
|
||||
|
||||
VertexAttribData(uint32_t c,uint32_t dc,uint32_t cs,VkFormat fmt):count(c),vec_size(dc),stride(cs),total_bytes(cs*c),vk_format(fmt)
|
||||
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分配的内存是对齐的,这样有效率上的提升
|
||||
}
|
||||
|
||||
@ -36,7 +37,7 @@ namespace hgl
|
||||
hgl_free(mem_data);
|
||||
}
|
||||
|
||||
const VkFormat GetVulkanFormat ()const{return vk_format;} ///<取得数据类型
|
||||
const VkFormat GetFormat ()const{return format;} ///<取得数据类型
|
||||
// const uint32_t GetVecSize ()const{return vec_size;} ///<取数缓冲区元数据成份数量
|
||||
const uint32_t GetCount ()const{return count;} ///<取得数据数量
|
||||
// const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数
|
||||
@ -49,11 +50,9 @@ namespace hgl
|
||||
/**
|
||||
* 根据格式要求,创建对应的顶点属性数据区(VAD)
|
||||
* @param vertex_count 顶点数量
|
||||
* @param fmt Vulkan格式
|
||||
* @param vec_size vec数量
|
||||
* @param stride 单个数据字节数
|
||||
* @param vif 格式
|
||||
*/
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VkFormat fmt,const int vec_size,const uint stride);
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VertexInputFormat *vif);
|
||||
//这个函数比较重要,就不搞成CreateVAD的简写了
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
@ -134,7 +134,7 @@ namespace hgl
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetVulkanFormat()!=VKFMT)
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess1<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
@ -227,7 +227,7 @@ namespace hgl
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetVulkanFormat()!=VKFMT)
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess2<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
@ -526,7 +526,7 @@ namespace hgl
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetVulkanFormat()!=VKFMT)
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess3<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
@ -798,7 +798,7 @@ namespace hgl
|
||||
{
|
||||
if(!vad)return(nullptr);
|
||||
|
||||
if(vad->GetVulkanFormat()!=VKFMT)
|
||||
if(vad->GetFormat()!=VKFMT)
|
||||
return(nullptr);
|
||||
|
||||
return(new VertexAttribDataAccess4<T,VKFMT>(vad->GetCount(),(T *)vad->GetData()));
|
||||
|
@ -28,9 +28,9 @@ namespace hgl
|
||||
if(!vil)return(nullptr);
|
||||
if(name.IsEmpty())return(nullptr);
|
||||
|
||||
const auto *va=vil->GetConfig(name);
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
|
||||
if(!va)
|
||||
if(!vif)
|
||||
return(nullptr);
|
||||
|
||||
ShaderStageBind *ssb;
|
||||
@ -38,7 +38,7 @@ namespace hgl
|
||||
if(ssb_map.Get(name,ssb))
|
||||
return ssb->data;
|
||||
|
||||
VAD *vad=hgl::graph::CreateVertexAttribData(vertices_number,va->format,va->vec_size,va->stride);
|
||||
VAD *vad=hgl::graph::CreateVertexAttribData(vertices_number,vif);
|
||||
|
||||
if(!vad)
|
||||
return(nullptr);
|
||||
@ -47,7 +47,7 @@ namespace hgl
|
||||
|
||||
ssb->data =vad;
|
||||
ssb->name =name;
|
||||
ssb->binding=va->binding;
|
||||
ssb->binding=vif->binding;
|
||||
|
||||
ssb->vbo =nullptr;
|
||||
|
||||
@ -68,21 +68,21 @@ namespace hgl
|
||||
if(ssb_map.Get(name,ssb))
|
||||
return false;
|
||||
|
||||
const auto *va=vil->GetConfig(name);
|
||||
const VertexInputFormat *vif=vil->GetConfig(name);
|
||||
|
||||
if(!va)
|
||||
if(!vif)
|
||||
return(false);
|
||||
|
||||
if(va->stride*vertices_number!=bytes)
|
||||
if(vif->stride*vertices_number!=bytes)
|
||||
return(false);
|
||||
|
||||
ssb=new ShaderStageBind;
|
||||
|
||||
ssb->data =nullptr;
|
||||
ssb->name =name;
|
||||
ssb->binding=va->binding;
|
||||
ssb->binding=vif->binding;
|
||||
|
||||
ssb->vbo =db->CreateVBO(va->format,vertices_number,data);
|
||||
ssb->vbo =db->CreateVBO(vif->format,vertices_number,data);
|
||||
|
||||
ssb_map.Add(name,ssb);
|
||||
|
||||
|
@ -1,18 +1,19 @@
|
||||
#include<hgl/graph/VertexAttribData.h>
|
||||
#include<hgl/graph/VKVertexInputFormat.h>
|
||||
|
||||
namespace hgl
|
||||
{
|
||||
namespace graph
|
||||
{
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VkFormat fmt,const int vec_size,const uint stride)
|
||||
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VertexInputFormat *vif)
|
||||
{
|
||||
if(vertex_count<=0
|
||||
||vec_size<1||vec_size>4
|
||||
||stride<1||stride>8*4
|
||||
||!CheckVulkanFormat(fmt))
|
||||
||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,vec_size,stride,fmt));
|
||||
return(new VertexAttribData(vertex_count,vif->format,vif->stride*vertex_count));
|
||||
}
|
||||
}//namespace graph
|
||||
}//namespace hgl
|
||||
|
Loading…
x
Reference in New Issue
Block a user