2020-07-16 17:08:13 +08:00
|
|
|
|
#ifndef HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
|
|
|
|
|
#define HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
|
2019-05-22 18:10:13 +08:00
|
|
|
|
|
2020-10-21 11:43:18 +08:00
|
|
|
|
#include<hgl/graph/VK.h>
|
2019-05-22 18:10:13 +08:00
|
|
|
|
namespace hgl
|
|
|
|
|
{
|
|
|
|
|
namespace graph
|
|
|
|
|
{
|
2020-08-08 20:12:37 +08:00
|
|
|
|
/**
|
|
|
|
|
* 预定义一些顶点属性名称,可用可不用。但一般默认shader会使用这些名称
|
|
|
|
|
*/
|
|
|
|
|
namespace VertexAttribName
|
|
|
|
|
{
|
|
|
|
|
#define VAN_DEFINE(name) constexpr char name[]=#name;
|
2020-09-05 18:56:49 +08:00
|
|
|
|
VAN_DEFINE(Position)
|
2020-08-08 20:12:37 +08:00
|
|
|
|
VAN_DEFINE(Normal)
|
|
|
|
|
VAN_DEFINE(Color)
|
|
|
|
|
VAN_DEFINE(Tangent)
|
|
|
|
|
VAN_DEFINE(Bitangent)
|
|
|
|
|
VAN_DEFINE(TexCoord)
|
|
|
|
|
VAN_DEFINE(Metallic)
|
|
|
|
|
VAN_DEFINE(Specular)
|
|
|
|
|
VAN_DEFINE(Roughness)
|
|
|
|
|
VAN_DEFINE(Emission)
|
|
|
|
|
#undef VAN_DEFINE
|
|
|
|
|
}//namespace VertexAttribName
|
|
|
|
|
|
|
|
|
|
#define VAN VertexAttribName
|
|
|
|
|
|
2020-07-14 14:03:26 +08:00
|
|
|
|
/**
|
2020-07-16 17:08:13 +08:00
|
|
|
|
* 顶点属性数据
|
2020-07-14 14:03:26 +08:00
|
|
|
|
*/
|
2020-07-16 20:36:54 +08:00
|
|
|
|
class VertexAttribData ///顶点属性数据
|
2019-05-22 18:10:13 +08:00
|
|
|
|
{
|
|
|
|
|
void *mem_data; ///<内存中的数据
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
2020-08-25 18:12:42 +08:00
|
|
|
|
const uint32_t vec_size; ///<每个数据成员数(比如二维坐标为2、三维坐标为3)
|
2019-05-22 18:10:13 +08:00
|
|
|
|
uint32_t count; ///<数据个数
|
|
|
|
|
|
|
|
|
|
const uint32_t stride; ///<每组数据字节数
|
|
|
|
|
const uint32_t total_bytes; ///<字节数
|
|
|
|
|
|
2020-07-16 20:36:54 +08:00
|
|
|
|
VkFormat vk_format; ///<在Vulkan中的数据类型
|
|
|
|
|
|
2019-05-22 18:10:13 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2020-08-25 18:12:42 +08:00
|
|
|
|
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)
|
2019-05-22 18:10:13 +08:00
|
|
|
|
{
|
|
|
|
|
mem_data = hgl_malloc(total_bytes); //在很多情况下,hgl_malloc分配的内存是对齐的,这样有效率上的提升
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-16 17:02:24 +08:00
|
|
|
|
virtual ~VertexAttribData()
|
2019-05-22 18:10:13 +08:00
|
|
|
|
{
|
|
|
|
|
if(mem_data)
|
|
|
|
|
hgl_free(mem_data);
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-16 20:36:54 +08:00
|
|
|
|
const VkFormat GetVulkanFormat ()const{return vk_format;} ///<取得数据类型
|
2020-08-25 18:12:42 +08:00
|
|
|
|
const uint32_t GetVecSize ()const{return vec_size;} ///<取数缓冲区元数据成份数量
|
2020-07-16 20:36:54 +08:00
|
|
|
|
const uint32_t GetCount ()const{return count;} ///<取得数据数量
|
2019-05-22 18:10:13 +08:00
|
|
|
|
const uint32_t GetStride ()const{return stride;} ///<取得每一组数据字节数
|
|
|
|
|
void * GetData ()const{return mem_data;} ///<取得数据指针
|
2020-07-16 20:36:54 +08:00
|
|
|
|
const uint32_t GetTotalBytes ()const{return total_bytes;} ///<取得数据字节数
|
2020-07-16 17:02:24 +08:00
|
|
|
|
};//class VertexAttribData
|
2020-07-14 14:08:34 +08:00
|
|
|
|
|
2020-07-16 17:02:24 +08:00
|
|
|
|
using VAD=VertexAttribData;
|
2020-07-20 17:33:13 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据格式要求,创建对应的顶点属性数据区(VAD)
|
2021-11-29 20:12:10 +08:00
|
|
|
|
* @param vertex_count 顶点数量
|
|
|
|
|
* @param fmt Vulkan格式
|
|
|
|
|
* @param vec_size vec数量
|
|
|
|
|
* @param stride 单个数据字节数
|
2020-07-20 17:33:13 +08:00
|
|
|
|
*/
|
2021-11-29 20:12:10 +08:00
|
|
|
|
VAD *CreateVertexAttribData(const uint32_t vertex_count,const VkFormat fmt,const int vec_size,const uint stride);
|
2020-08-07 21:59:20 +08:00
|
|
|
|
//这个函数比较重要,就不搞成CreateVAD的简写了
|
2019-05-22 18:10:13 +08:00
|
|
|
|
}//namespace graph
|
|
|
|
|
}//namespace hgl
|
2020-07-16 17:08:13 +08:00
|
|
|
|
#endif//HGL_GRAPH_VERTEX_ATTRIB_DATA_INCLUDE
|