to support newly String<>/IDName/Compare

This commit is contained in:
2025-01-15 02:42:04 +08:00
parent d810540b81
commit bd0a3d8be1
33 changed files with 644 additions and 677 deletions

View File

@@ -8,15 +8,48 @@ class RenderAssignBuffer;
class SceneNode;
struct CameraInfo;
struct RenderPipelineIndex:public Comparator<RenderPipelineIndex>
{
Material *material;
Pipeline *pipeline;
public:
const int compare(const RenderPipelineIndex &rli)const override
{
if(material<rli.material)return(-1);
if(material>rli.material)return(1);
if(pipeline<rli.pipeline)return(-1);
if(pipeline>rli.pipeline)return(1);
return(0);
}
public:
RenderPipelineIndex()
{
material=nullptr;
pipeline=nullptr;
}
RenderPipelineIndex(Material *m,Pipeline *p)
{
material=m;
pipeline=p;
}
};//struct RenderPipelineIndex
/**
* 同一材质的对象渲染列表
* 同一材质与管线的渲染列表
*/
class MaterialRenderList
{
GPUDevice *device;
RenderCmdBuffer *cmd_buf;
Material *material;
RenderPipelineIndex rp_index;
CameraInfo *camera_info;
@@ -33,7 +66,6 @@ private:
uint32_t first_instance; ///<第一个绘制实例(和instance渲染无关,对应InstanceRate的VAB)
uint32_t instance_count;
Pipeline * pipeline;
MaterialInstance * mi;
const PrimitiveDataBuffer * pdb;
@@ -60,7 +92,6 @@ protected:
VABList * vab_list;
Pipeline * last_pipeline;
const PrimitiveDataBuffer * last_data_buffer;
const VDM * last_vdm;
const PrimitiveRenderData * last_render_data;
@@ -75,20 +106,14 @@ protected:
public:
MaterialRenderList(GPUDevice *d,bool l2w,Material *m);
MaterialRenderList(GPUDevice *d,bool l2w,const RenderPipelineIndex &rpi);
~MaterialRenderList();
void Add(SceneNode *);
void SetCameraInfo(CameraInfo *ci)
{
camera_info=ci;
}
void SetCameraInfo(CameraInfo *ci){camera_info=ci;}
void Clear()
{
rn_list.Clear();
}
void Clear(){rn_list.Clear();}
void End();

View File

@@ -2,7 +2,7 @@
#include<hgl/graph/MaterialRenderList.h>
VK_NAMESPACE_BEGIN
class MaterialRenderMap:public ObjectMap<Material *,MaterialRenderList>
class MaterialRenderMap:public ObjectMap<RenderPipelineIndex,MaterialRenderList>
{
public:

View File

@@ -11,9 +11,9 @@ namespace hgl
class MaterialInstance;
class SceneNode;
struct RenderNode
struct RenderNode:public Comparator<RenderNode>
{
uint index; ///<在MaterialRenderList中的索引
uint index; ///<在MaterialRenderList中的索引
SceneNode * scene_node;
@@ -22,6 +22,11 @@ namespace hgl
Vector3f world_position;
float to_camera_distance;
public:
//该函数位于MaterialRenderList.cpp
const int compare(const RenderNode &)const override;
};
using RenderNodeList=List<RenderNode>;
@@ -29,5 +34,10 @@ namespace hgl
using MaterialInstanceSets=SortedSet<MaterialInstance *>; ///<材质实例集合
}//namespace graph
template<> inline const int ItemComparator<graph::RenderNode>::compare(const graph::RenderNode &a,const graph::RenderNode &b)
{
return a.compare(b);
}
}//namespace hgl
#endif//HGL_GRAPH_RENDER_NODE_INCLUDE

View File

@@ -10,7 +10,7 @@ namespace hgl
namespace graph
{
using SceneNodeID =uint64;
using SceneNodeName =UTF16IDName;
using SceneNodeName =U16IDName;
/**
* 场景节点数据类<br>
@@ -19,6 +19,8 @@ namespace hgl
*/
class SceneNode:public SceneOrient ///场景节点类
{
SceneNode *Owner; ///<上级节点
SceneNodeID NodeID; ///<节点ID
SceneNodeName NodeName; ///<节点名称
@@ -59,6 +61,8 @@ namespace hgl
{
SceneOrient::Clear();
Owner=nullptr;
BoundingBox.SetZero();
LocalBoundingBox.SetZero();
@@ -74,8 +78,13 @@ namespace hgl
return(true);
}
Renderable *GetRenderable(){return render_obj;}
void SetRenderable(Renderable *);
void SetOwner(SceneNode *sn) {Owner=sn;}
SceneNode * GetOwner() noexcept{return Owner;}
const SceneNode * GetOwner()const noexcept{return Owner;}
void SetRenderable(Renderable *);
Renderable *GetRenderable() noexcept{return render_obj;}
const Renderable *GetRenderable()const noexcept{return render_obj;}
SceneNode *Add(SceneNode *sn)
{
@@ -83,6 +92,7 @@ namespace hgl
return(nullptr);
ChildNode.Add(sn);
sn->SetOwner(this);
return sn;
}

View File

@@ -1,12 +1,16 @@
#ifndef HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE
#define HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE
#pragma once
#include<hgl/graph/VK.h>
#include<hgl/type/Map.h>
#include<hgl/util/hash/Hash.h>
VK_NAMESPACE_BEGIN
using RenderPassHASHCode=util::HashCodeSHA1LE;
using RenderPassHASHCode=util::HashCode<128/8>;
inline util::Hash *CreateRenderPassHash()
{
return util::CreateHash(util::HASH::xxH3_128);
}
class DeviceRenderPassManage
{
@@ -34,4 +38,3 @@ private:
RenderPass * AcquireRenderPass( const RenderbufferInfo *,const uint subpass_count=2);
};//class DeviceRenderPassManage
VK_NAMESPACE_END
#endif//HGL_VULKAN_DEVICE_RENDERPASS_MANAGE_INCLUDE

View File

@@ -12,7 +12,7 @@ VK_NAMESPACE_BEGIN
* 原始图元数据缓冲区<Br>
* 提供在渲染之前的数据绑定信息
*/
struct PrimitiveDataBuffer
struct PrimitiveDataBuffer:public Comparator<PrimitiveDataBuffer>
{
uint32_t vab_count;
VkBuffer * vab_list;
@@ -32,14 +32,14 @@ public:
PrimitiveDataBuffer(const uint32_t,IndexBuffer *,VertexDataManager *_v=nullptr);
~PrimitiveDataBuffer();
const bool Comp(const PrimitiveDataBuffer *pdb)const;
const int compare(const PrimitiveDataBuffer &pdb)const override;
};//struct PrimitiveDataBuffer
/**
* 原始图元渲染数据<Br>
* 提供在渲染时的数据
*/
struct PrimitiveRenderData
struct PrimitiveRenderData:public ComparatorData<PrimitiveRenderData>
{
//因为要VAB是流式访问所以我们这个结构会被用做排序依据
//也因此把vertex_offset放在最前面
@@ -59,9 +59,6 @@ public:
vertex_offset =vo;
first_index =fi;
}
CompOperatorMemcmp(const PrimitiveRenderData &);
CompOperatorMemcmpPointer(PrimitiveRenderData);
};
/**

View File

@@ -12,7 +12,7 @@ namespace hgl
/**
* 字体信息
*/
struct Font
struct Font:public ComparatorData<Font>
{
os_char name[MAX_FONT_NAME_LENGTH]; ///<字体名称
@@ -28,8 +28,6 @@ namespace hgl
Font();
Font(const os_char *,int,int,bool b=false,bool i=false,bool=true);
CompOperatorMemcmp(const Font &); ///<比较操作符重载
};//struct Font
}//namespace graph
}//namespace hgl

View File

@@ -100,8 +100,8 @@ namespace hgl
int draw_chars_count; ///<要绘制字符列表
SortedSet<u32char> chars_sets; ///<不重复字符统计缓冲区
SortedSet<u32char> clear_chars_sets; ///<待清除的字符合集
SortedSets<u32char> chars_sets; ///<不重复字符统计缓冲区
SortedSets<u32char> clear_chars_sets; ///<待清除的字符合集
TileUVFloatMap chars_uv; ///<所有要绘制字符的uv
struct CharDrawAttr

View File

@@ -33,7 +33,7 @@ namespace hgl
Color4f color;
DeviceBuffer * ubo_color;
SortedSet<TextPrimitive *> tr_sets;
SortedSets<TextPrimitive *> tr_sets;
private:
@@ -54,9 +54,9 @@ namespace hgl
public:
TextPrimitive *CreatePrimitive();
TextPrimitive *CreatePrimitive(const UTF16String &str);
TextPrimitive *CreatePrimitive(const U16String &str);
bool Layout(TextPrimitive *tr,const UTF16String &str);
bool Layout(TextPrimitive *tr,const U16String &str);
Renderable *CreateRenderable(TextPrimitive *text_primitive);

View File

@@ -37,7 +37,7 @@ namespace hgl
TileFont(TileData *td,FontSource *fs);
virtual ~TileFont();
bool Registry(TileUVFloatMap &,SortedSet<u32char> &chars_sets); ///<注册要使用的字符
bool Registry(TileUVFloatMap &,SortedSet<u32char> &chars_sets); ///<注册要使用的字符
void Unregistry(const List<u32char> &); ///<注销要使用的字符
};//class TileFont
}//namespace graph

View File

@@ -6,7 +6,7 @@
#include<hgl/graph/VertexAttrib.h>
STD_MTL_NAMESPACE_BEGIN
struct Material2DCreateConfig:public MaterialCreateConfig
struct Material2DCreateConfig:public MaterialCreateConfig,public Comparator<Material2DCreateConfig>
{
CoordinateSystem2D coordinate_system; ///<使用的坐标系
@@ -32,9 +32,9 @@ public:
position_format=VAT_VEC2;
}
int Comp(const Material2DCreateConfig &cfg)const
const int compare(const Material2DCreateConfig &cfg)const override
{
int off=MaterialCreateConfig::Comp(cfg);
int off=MaterialCreateConfig::compare(cfg);
if(off)return off;
@@ -48,8 +48,6 @@ public:
return off;
}
CompOperator(const Material2DCreateConfig &,Comp)
};//struct Material2DCreateConfig:public MaterialCreateConfig
MaterialCreateInfo *CreateVertexColor2D(const Material2DCreateConfig *);

View File

@@ -5,58 +5,8 @@
#include<hgl/graph/VertexAttrib.h>
STD_MTL_NAMESPACE_BEGIN
enum class LightingModel:uint8
{
Unlit,
Gizmo, ///<Gizmo专用(Blinnphong的特定版本内置假的太阳光方向、高光系数等使其不需要外部UBO传入)
Blinnphong, ///<Blinnphong光照模型
FakePBR, ///<假PBR(使用Blinnphong+HalfLambert模拟)
MicroPBR, ///<微型PBR(只有BaseColor/Normal/Metallic/Roughness四个基础数据的PBR)
WebPBR, ///<Khronos为WebGL提供的PBR
FilamentPBR, ///<Filament引擎所使用的PBR
AMDPBR, ///<AMD Caulrdon框架所使用的PBR
BlenderPBR, ///<Blender所使用的PBR
ENUM_CLASS_RANGE(Unlit,BlenderPBR)
};
constexpr const char *LightingModelName[]=
{
"Unlit",
"Gizmo",
"Blinnphong",
"FakePBR",
"MicroPBR",
"WebPBR",
"FilamentPBR",
"AMDPBR",
"BlenderPBR"
};
/**
* 天光来源
*/
enum class SkyLightSource:uint8
{
PureColor, ///<纯色
Simplest, ///<极简(一行代码)
Cubemap, ///<立方体贴图
IBL, ///<IBL立方体贴图
ENUM_CLASS_RANGE(PureColor,IBL)
};
struct Material3DCreateConfig:public MaterialCreateConfig
struct Material3DCreateConfig:public MaterialCreateConfig,public Comparator<Material3DCreateConfig>
{
bool camera; ///<包含摄像机矩阵信息
@@ -82,9 +32,9 @@ public:
// reverse_depth=false;
}
int Comp(const Material3DCreateConfig &cfg)const
const int compare(const Material3DCreateConfig &cfg)const override
{
int off=MaterialCreateConfig::Comp(cfg);
int off=MaterialCreateConfig::compare(cfg);
if(off)return off;
@@ -98,8 +48,6 @@ public:
return off;
}
CompOperator(const Material3DCreateConfig &,Comp)
};//struct Material3DCreateConfig:public MaterialCreateConfig
MaterialCreateInfo *CreateVertexColor3D(const Material3DCreateConfig *);

View File

@@ -13,7 +13,7 @@ class MaterialCreateInfo;
/**
* 材质配置结构
*/
struct MaterialCreateConfig
struct MaterialCreateConfig:public Comparator<MaterialCreateConfig>
{
const GPUDeviceAttribute *dev_attr;
@@ -42,7 +42,7 @@ public:
prim=p;
}
virtual int Comp(const MaterialCreateConfig &cfg)const
const int compare(const MaterialCreateConfig &cfg)const override
{
int off;
@@ -59,8 +59,6 @@ public:
return off;
}
CompOperator(const MaterialCreateConfig &,Comp)
};//struct MaterialCreateConfig
STD_MTL_NAMESPACE_END
#endif//HGL_GRAPH_MTL_CONFIG_INCLUDE

View File

@@ -6,551 +6,436 @@
#include<hgl/graph/VKInterpolation.h>
#include<hgl/graph/VKSamplerType.h>
#include<hgl/graph/VKImageType.h>
#include<hgl/CompOperator.h>
#include<hgl/Comparator.h>
namespace hgl
VK_NAMESPACE_BEGIN
enum class ShaderVariableBaseType:uint8
{
namespace graph
{
enum class ShaderVariableBaseType:uint8
{
Scalar=0,
Vector,
Matrix,
Sampler,
Image,
AtomicCounter,
Scalar=0,
Vector,
Matrix,
Sampler,
Image,
AtomicCounter,
ENUM_CLASS_RANGE(Scalar,AtomicCounter)
};//enum class ShaderVariableBaseType
ENUM_CLASS_RANGE(Scalar,AtomicCounter)
};//enum class ShaderVariableBaseType
using SVBaseType=ShaderVariableBaseType;
using SVBaseType=ShaderVariableBaseType;
#pragma pack(push,1)
#pragma pack(push,1)
struct ShaderVariableType
struct ShaderVariableType:public Comparator<ShaderVariableType>
{
union
{
struct
{
union
{
struct
{
SVBaseType base_type;
union
{
struct
struct Scalar
{
SVBaseType base_type;
VABaseType type;
}scalar;
union
{
struct Scalar
{
VABaseType type;
}scalar;
struct Vector
{
VABaseType type;
uint8 vec_size;
}vector;
struct Vector
{
VABaseType type;
uint8 vec_size;
}vector;
struct Matrix
{
VABaseType type;
uint8 n;
uint8 m;
}matrix;
struct Matrix
{
VABaseType type;
uint8 n;
uint8 m;
}matrix;
struct Sampler
{
SamplerType type;
}sampler;
struct Sampler
{
SamplerType type;
}sampler;
struct Image
{
ShaderImageType type;
}image;
};
};
uint32 type_code;
struct Image
{
ShaderImageType type;
}image;
};
uint32 array_size;
};
uint64 svt_code;
uint32 type_code;
};
public:
ShaderVariableType()
{
svt_code=0;
}
ShaderVariableType(const ShaderVariableType &svt)
{
svt_code=svt.svt_code;
}
ShaderVariableType(const VAType &vat,const uint count)
{
From(vat,count);
}
ShaderVariableType(const VABaseType &vabt,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Scalar;
scalar.type=vabt;
array_size=count;
}
ShaderVariableType(const VABaseType &vabt,const uint8 size,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Vector;
vector.type=vabt;
vector.vec_size=size;
array_size=count;
}
ShaderVariableType(const VABaseType &vabt,const uint8 row,const uint8 col,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Matrix;
matrix.type=vabt;
matrix.n=col;
matrix.m=row;
array_size=count;
}
ShaderVariableType(const SamplerType &st,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Sampler;
sampler.type=st;
array_size=count;
}
ShaderVariableType(const ShaderImageType &sit,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Image;
image.type=sit;
array_size=count;
}
const bool Check()const
{
if(!RangeCheck(base_type))return(false);
RANGE_CHECK_RETURN_FALSE(base_type)
if(base_type==SVBaseType::Scalar)
return(true);
if(base_type==SVBaseType::Vector)
{
if(vector.vec_size<2||vector.vec_size>4)return(false);
return(true);
}
if(base_type==SVBaseType::Matrix)
{
if(matrix.m==0)
{
if(matrix.n<2||matrix.n>4)return(false);
}
else
{
if(matrix.n<2||matrix.n>4)return(false);
if(matrix.m<2||matrix.m>4)return(false);
}
return(true);
}
if(base_type==SVBaseType::Sampler)
return RangeCheck(sampler.type);
if(base_type==SVBaseType::Image)
return RangeCheck(image.type);
return(true);
}
int Comp(const ShaderVariableType &svt)const
{
int off=(int)base_type-(int)svt.base_type;
if(off)return(off);
if(base_type==SVBaseType::Scalar)
return int(scalar.type)-int(svt.scalar.type);
if(base_type==SVBaseType::Vector)
{
off=int(vector.type)-int(svt.vector.type);
if(off)return(off);
off=vector.vec_size-svt.vector.vec_size;
if(off)return(off);
return int(vector.type)-int(svt.vector.type);
}
if(base_type==SVBaseType::Matrix)
{
off=int(matrix.type)-int(svt.matrix.type);
if(off)return(off);
off=matrix.n-svt.matrix.n;
if(off)return(off);
return matrix.m-svt.matrix.m;
}
if(base_type==SVBaseType::Sampler)
return int(sampler.type)-int(svt.sampler.type);
if(base_type==SVBaseType::Image)
return int(image.type)-int(svt.image.type);
return 0;
}
CompOperator(const ShaderVariableType &,Comp)
const char *GetTypename()const;
bool ParseTypeString(const char *str);
const uint64 ToCode()const{return svt_code;}
const bool FromCode(const uint64 code)
{
svt_code=code;
return Check();
}
const bool From(const VAType &vat,const uint16 count=1)
{
array_size=count;
if(vat.vec_size==1)
{
base_type=SVBaseType::Scalar;
scalar.type=vat.basetype;
return(true);
}
else if(vat.vec_size<=4)
{
base_type=SVBaseType::Vector;
vector.type=vat.basetype;
vector.vec_size=vat.vec_size;
return(true);
}
return(false);
}
static const ShaderVariableType Scalar(const VABaseType &vabt,const uint count=1)
{
ShaderVariableType svt;
svt.base_type =SVBaseType::Scalar;
svt.scalar.type =vabt;
svt.array_size =count;
return svt;
}
};//struct ShaderVariableType
#pragma pack(pop)
using SVType=ShaderVariableType;
const SVType SVT_BOOL (VABaseType::Bool, 1);
const SVType SVT_INT (VABaseType::Int, 1);
const SVType SVT_UINT (VABaseType::UInt, 1);
const SVType SVT_FLOAT (VABaseType::Float, 1);
const SVType SVT_DOUBLE(VABaseType::Double, 1);
const SVType SVT_BVEC2 (VABaseType::Bool, 2,1);
const SVType SVT_BVEC3 (VABaseType::Bool, 3,1);
const SVType SVT_BVEC4 (VABaseType::Bool, 4,1);
const SVType SVT_IVEC2 (VABaseType::Int, 2,1);
const SVType SVT_IVEC3 (VABaseType::Int, 3,1);
const SVType SVT_IVEC4 (VABaseType::Int, 4,1);
const SVType SVT_UVEC2 (VABaseType::UInt, 2,1);
const SVType SVT_UVEC3 (VABaseType::UInt, 3,1);
const SVType SVT_UVEC4 (VABaseType::UInt, 4,1);
const SVType SVT_VEC2 (VABaseType::Float, 2,1);
const SVType SVT_VEC3 (VABaseType::Float, 3,1);
const SVType SVT_VEC4 (VABaseType::Float, 4,1);
const SVType SVT_DVEC2 (VABaseType::Double, 2,1);
const SVType SVT_DVEC3 (VABaseType::Double, 3,1);
const SVType SVT_DVEC4 (VABaseType::Double, 4,1);
const SVType SVT_MAT2 (VABaseType::Float, 2,2,1);
const SVType SVT_MAT3 (VABaseType::Float, 3,3,1);
const SVType SVT_MAT4 (VABaseType::Float, 4,4,1);
const SVType SVT_MAT2x3(VABaseType::Float, 2,3,1);
const SVType SVT_MAT2x4(VABaseType::Float, 2,4,1);
const SVType SVT_MAT3x2(VABaseType::Float, 3,2,1);
const SVType SVT_MAT3x4(VABaseType::Float, 3,4,1);
const SVType SVT_MAT4x2(VABaseType::Float, 4,2,1);
const SVType SVT_MAT4x3(VABaseType::Float, 4,3,1);
const SVType SVT_Sampler1D(SamplerType::Sampler1D, 1);
const SVType SVT_Sampler2D(SamplerType::Sampler2D, 1);
const SVType SVT_Sampler3D(SamplerType::Sampler3D, 1);
const SVType SVT_SamplerCube(SamplerType::SamplerCube, 1);
const SVType SVT_Sampler2DRect(SamplerType::Sampler2DRect, 1);
const SVType SVT_Sampler1DArray(SamplerType::Sampler1DArray,1);
const SVType SVT_Sampler2DArray(SamplerType::Sampler2DArray,1);
const SVType SVT_SamplerCubeArray(SamplerType::SamplerCubeArray,1);
const SVType SVT_SamplerBuffer(SamplerType::SamplerBuffer,1);
const SVType SVT_Sampler2DMS(SamplerType::Sampler2DMS,1);
const SVType SVT_Sampler2DMSArray(SamplerType::Sampler2DMSArray,1);
const SVType SVT_Sampler1DShadow(SamplerType::Sampler1DShadow,1);
const SVType SVT_Sampler2DShadow(SamplerType::Sampler2DShadow,1);
const SVType SVT_SamplerCubeShadow(SamplerType::SamplerCubeShadow,1);
const SVType SVT_Sampler2DRectShadow(SamplerType::Sampler2DRectShadow,1);
const SVType SVT_Sampler1DArrayShadow(SamplerType::Sampler1DArrayShadow,1);
const SVType SVT_Sampler2DArrayShadow(SamplerType::Sampler2DArrayShadow,1);
const SVType SVT_SamplerCubeArrayShadow(SamplerType::SamplerCubeArrayShadow,1);
const SVType SVT_Image1D(ShaderImageType::Image1D,1);
const SVType SVT_Image2D(ShaderImageType::Image2D,1);
const SVType SVT_Image3D(ShaderImageType::Image3D,1);
const SVType SVT_ImageCube(ShaderImageType::ImageCube,1);
const SVType SVT_Image2DRect(ShaderImageType::Image2DRect,1);
const SVType SVT_Image1DArray(ShaderImageType::Image1DArray,1);
const SVType SVT_Image2DArray(ShaderImageType::Image2DArray,1);
const SVType SVT_ImageCubeArray(ShaderImageType::ImageCubeArray,1);
const SVType SVT_ImageBuffer(ShaderImageType::ImageBuffer,1);
const SVType SVT_Image2DMS(ShaderImageType::Image2DMS,1);
const SVType SVT_Image2DMSArray(ShaderImageType::Image2DMSArray,1);
struct ShaderVariable
{
char name[VERTEX_ATTRIB_NAME_MAX_LENGTH];
uint location;
SVType type;
Interpolation interpolation; //插值方式
uint32 array_size;
};
using SVList=List<ShaderVariable>;
uint64 svt_code;
};
struct ShaderVariableArray
public:
ShaderVariableType()
{
svt_code=0;
}
ShaderVariableType(const ShaderVariableType &svt)
{
svt_code=svt.svt_code;
}
ShaderVariableType(const VAType &vat,const uint count)
{
From(vat,count);
}
ShaderVariableType(const VABaseType &vabt,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Scalar;
scalar.type=vabt;
array_size=count;
}
ShaderVariableType(const VABaseType &vabt,const uint8 size,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Vector;
vector.type=vabt;
vector.vec_size=size;
array_size=count;
}
ShaderVariableType(const VABaseType &vabt,const uint8 row,const uint8 col,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Matrix;
matrix.type=vabt;
matrix.n=col;
matrix.m=row;
array_size=count;
}
ShaderVariableType(const SamplerType &st,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Sampler;
sampler.type=st;
array_size=count;
}
ShaderVariableType(const ShaderImageType &sit,const uint32 count)
{
svt_code=0;
base_type=SVBaseType::Image;
image.type=sit;
array_size=count;
}
const bool Check()const;
const int compare(const ShaderVariableType &svt)const override;
const char *GetTypename()const;
bool ParseTypeString(const char *str);
const uint64 ToCode()const{return svt_code;}
const bool FromCode(const uint64 code)
{
svt_code=code;
return Check();
}
const bool From(const VAType &vat,const uint16 count=1);
static const ShaderVariableType Scalar(const VABaseType &vabt,const uint count=1)
{
ShaderVariableType svt;
svt.base_type =SVBaseType::Scalar;
svt.scalar.type =vabt;
svt.array_size =count;
return svt;
}
};//struct ShaderVariableType
#pragma pack(pop)
using SVType=ShaderVariableType;
const SVType SVT_BOOL (VABaseType::Bool, 1);
const SVType SVT_INT (VABaseType::Int, 1);
const SVType SVT_UINT (VABaseType::UInt, 1);
const SVType SVT_FLOAT (VABaseType::Float, 1);
const SVType SVT_DOUBLE(VABaseType::Double, 1);
const SVType SVT_BVEC2 (VABaseType::Bool, 2,1);
const SVType SVT_BVEC3 (VABaseType::Bool, 3,1);
const SVType SVT_BVEC4 (VABaseType::Bool, 4,1);
const SVType SVT_IVEC2 (VABaseType::Int, 2,1);
const SVType SVT_IVEC3 (VABaseType::Int, 3,1);
const SVType SVT_IVEC4 (VABaseType::Int, 4,1);
const SVType SVT_UVEC2 (VABaseType::UInt, 2,1);
const SVType SVT_UVEC3 (VABaseType::UInt, 3,1);
const SVType SVT_UVEC4 (VABaseType::UInt, 4,1);
const SVType SVT_VEC2 (VABaseType::Float, 2,1);
const SVType SVT_VEC3 (VABaseType::Float, 3,1);
const SVType SVT_VEC4 (VABaseType::Float, 4,1);
const SVType SVT_DVEC2 (VABaseType::Double, 2,1);
const SVType SVT_DVEC3 (VABaseType::Double, 3,1);
const SVType SVT_DVEC4 (VABaseType::Double, 4,1);
const SVType SVT_MAT2 (VABaseType::Float, 2,2,1);
const SVType SVT_MAT3 (VABaseType::Float, 3,3,1);
const SVType SVT_MAT4 (VABaseType::Float, 4,4,1);
const SVType SVT_MAT2x3(VABaseType::Float, 2,3,1);
const SVType SVT_MAT2x4(VABaseType::Float, 2,4,1);
const SVType SVT_MAT3x2(VABaseType::Float, 3,2,1);
const SVType SVT_MAT3x4(VABaseType::Float, 3,4,1);
const SVType SVT_MAT4x2(VABaseType::Float, 4,2,1);
const SVType SVT_MAT4x3(VABaseType::Float, 4,3,1);
const SVType SVT_Sampler1D(SamplerType::Sampler1D, 1);
const SVType SVT_Sampler2D(SamplerType::Sampler2D, 1);
const SVType SVT_Sampler3D(SamplerType::Sampler3D, 1);
const SVType SVT_SamplerCube(SamplerType::SamplerCube, 1);
const SVType SVT_Sampler2DRect(SamplerType::Sampler2DRect, 1);
const SVType SVT_Sampler1DArray(SamplerType::Sampler1DArray,1);
const SVType SVT_Sampler2DArray(SamplerType::Sampler2DArray,1);
const SVType SVT_SamplerCubeArray(SamplerType::SamplerCubeArray,1);
const SVType SVT_SamplerBuffer(SamplerType::SamplerBuffer,1);
const SVType SVT_Sampler2DMS(SamplerType::Sampler2DMS,1);
const SVType SVT_Sampler2DMSArray(SamplerType::Sampler2DMSArray,1);
const SVType SVT_Sampler1DShadow(SamplerType::Sampler1DShadow,1);
const SVType SVT_Sampler2DShadow(SamplerType::Sampler2DShadow,1);
const SVType SVT_SamplerCubeShadow(SamplerType::SamplerCubeShadow,1);
const SVType SVT_Sampler2DRectShadow(SamplerType::Sampler2DRectShadow,1);
const SVType SVT_Sampler1DArrayShadow(SamplerType::Sampler1DArrayShadow,1);
const SVType SVT_Sampler2DArrayShadow(SamplerType::Sampler2DArrayShadow,1);
const SVType SVT_SamplerCubeArrayShadow(SamplerType::SamplerCubeArrayShadow,1);
const SVType SVT_Image1D(ShaderImageType::Image1D,1);
const SVType SVT_Image2D(ShaderImageType::Image2D,1);
const SVType SVT_Image3D(ShaderImageType::Image3D,1);
const SVType SVT_ImageCube(ShaderImageType::ImageCube,1);
const SVType SVT_Image2DRect(ShaderImageType::Image2DRect,1);
const SVType SVT_Image1DArray(ShaderImageType::Image1DArray,1);
const SVType SVT_Image2DArray(ShaderImageType::Image2DArray,1);
const SVType SVT_ImageCubeArray(ShaderImageType::ImageCubeArray,1);
const SVType SVT_ImageBuffer(ShaderImageType::ImageBuffer,1);
const SVType SVT_Image2DMS(ShaderImageType::Image2DMS,1);
const SVType SVT_Image2DMSArray(ShaderImageType::Image2DMSArray,1);
struct ShaderVariable
{
char name[VERTEX_ATTRIB_NAME_MAX_LENGTH];
uint location;
SVType type;
Interpolation interpolation; //插值方式
};
using SVList=List<ShaderVariable>;
struct ShaderVariableArray:public Comparator<ShaderVariableArray>
{
uint count;
ShaderVariable *items;
public:
const bool IsEmpty()const{return !items||count<=0;}
public:
ShaderVariableArray()
{
count=0;
items=nullptr;
}
~ShaderVariableArray()
{
Clear();
}
const int compare(const ShaderVariableArray &sva)const override
{
int off=count-sva.count;
if(off)return off;
for(uint i=0;i<count;i++)
{
uint count;
off=items[i].location-sva.items[i].location;
if(off)
return off;
ShaderVariable *items;
if(items[i].type.ToCode()>sva.items[i].type.ToCode())
return 1;
public:
//ToCode返回的是uint64可能差值超大所以不能直接用-的结果
const bool IsEmpty()const{return !items||count<=0;}
if(items[i].type.ToCode()<sva.items[i].type.ToCode())
return -1;
public:
off=int(items[i].interpolation)-int(sva.items[i].interpolation);
if(off)
return off;
ShaderVariableArray()
{
count=0;
items=nullptr;
}
off=hgl::strcmp(items[i].name,sva.items[i].name);
if(off)
return off;
}
~ShaderVariableArray()
{
Clear();
}
int Comp(const ShaderVariableArray *sva)const
{
if(!sva)
return 1;
int off=count-sva->count;
if(off)return off;
for(uint i=0;i<count;i++)
{
off=items[i].location-sva->items[i].location;
if(off)
return off;
if(items[i].type.ToCode()>sva->items[i].type.ToCode())
return 1;
//ToCode返回的是uint64可能差值超大所以不能直接用-的结果
if(items[i].type.ToCode()<sva->items[i].type.ToCode())
return -1;
off=int(items[i].interpolation)-int(sva->items[i].interpolation);
if(off)
return off;
off=hgl::strcmp(items[i].name,sva->items[i].name);
if(off)
return off;
}
return 0;
}
int Comp(const ShaderVariableArray &sva)const{return Comp(&sva);}
CompOperator(const ShaderVariableArray *,Comp)
CompOperator(const ShaderVariableArray &,Comp)
return 0;
}
bool Init(const uint c=0)
{
if(items)
return(false);
bool Init(const uint c=0)
{
if(items)
return(false);
if(c>0)
{
count=c;
items=array_alloc<ShaderVariable>(count);
}
else
{
count=0;
items=nullptr;
}
if(c>0)
{
count=c;
items=array_alloc<ShaderVariable>(count);
}
else
{
count=0;
items=nullptr;
}
return(true);
}
bool Contains(const char *name)const
{
if(count<=0)
return(false);
for(uint i=0;i<count;i++)
if(hgl::strcmp(items[i].name,name)==0)
return(true);
}
bool Contains(const char *name)const
{
if(count<=0)
return(false);
return(false);
}
for(uint i=0;i<count;i++)
if(hgl::strcmp(items[i].name,name)==0)
return(true);
bool Add(ShaderVariable &sv)
{
if(Contains(sv.name))
return(false);
return(false);
}
sv.location=count;
bool Add(ShaderVariable &sv)
{
if(Contains(sv.name))
return(false);
sv.location=count;
if(!items)
{
items=array_alloc<ShaderVariable>(1);
count=1;
}
else
{
++count;
items=array_realloc(items,count);
}
if(!items)
{
items=array_alloc<ShaderVariable>(1);
count=1;
}
else
{
++count;
items=array_realloc(items,count);
}
hgl_cpy(items[count-1],sv);
return(true);
}
hgl_cpy(items[count-1],sv);
return(true);
}
void Clear()
{
if(items)
{
array_free(items);
items=nullptr;
}
void Clear()
{
if(items)
{
array_free(items);
items=nullptr;
}
count=0;
}
count=0;
}
bool Clone(const ShaderVariableArray *src)
{
if(!src)
return(false);
bool Clone(const ShaderVariableArray *src)
{
if(!src)
return(false);
if(!Init(src->count))
return(false);
if(!Init(src->count))
return(false);
hgl_cpy(items,src->items,src->count);
return(true);
}
hgl_cpy(items,src->items,src->count);
return(true);
}
void ToString(AnsiString &output_string)
void ToString(AnsiString &output_string)
{
if(IsEmpty())
return;
const ShaderVariable *sv=items;
for(uint i=0;i<count;i++)
{
output_string+=" ";
if(sv->interpolation!=Interpolation::Smooth)
{
if(IsEmpty())
return;
const ShaderVariable *sv=items;
for(uint i=0;i<count;i++)
if(RangeCheck(sv->interpolation))
{
output_string+=" ";
if(sv->interpolation!=Interpolation::Smooth)
{
if(RangeCheck(sv->interpolation))
{
output_string+=InterpolationName[size_t(sv->interpolation)];
output_string+=" ";
}
}
output_string+=sv->type.GetTypename();
output_string+=InterpolationName[size_t(sv->interpolation)];
output_string+=" ";
output_string+=sv->name;
output_string+=";\n";
++sv;
}
}
};//struct ShaderVariableArray
using SVArray=ShaderVariableArray;
}//namespace graph
}//namespace hgl
output_string+=sv->type.GetTypename();
output_string+=" ";
output_string+=sv->name;
output_string+=";\n";
++sv;
}
}
};//struct ShaderVariableArray
using SVArray=ShaderVariableArray;
VK_NAMESPACE_END

View File

@@ -96,7 +96,7 @@ public:
void SetMain(const AnsiString &str){main_function=str;}
void SetMain(const char *str,const int len)
{
main_function.SetString(str,len);
main_function.fromString(str,len);
}
const AnsiString &GetOutputStruct()const{return output_struct;}