2025-05-16 09:12:33 +08:00
|
|
|
|
#pragma once
|
2023-05-15 21:52:57 +08:00
|
|
|
|
|
2025-05-17 20:01:17 +08:00
|
|
|
|
#include<hgl/graph/mtl/MaterialLibrary.h>
|
2023-05-15 21:52:57 +08:00
|
|
|
|
#include<hgl/graph/mtl/MaterialConfig.h>
|
|
|
|
|
#include<hgl/graph/CoordinateSystem.h>
|
2023-09-26 21:49:37 +08:00
|
|
|
|
#include<hgl/graph/VertexAttrib.h>
|
2023-05-15 21:52:57 +08:00
|
|
|
|
|
|
|
|
|
STD_MTL_NAMESPACE_BEGIN
|
2025-01-15 02:42:04 +08:00
|
|
|
|
struct Material2DCreateConfig:public MaterialCreateConfig,public Comparator<Material2DCreateConfig>
|
2023-05-15 21:52:57 +08:00
|
|
|
|
{
|
|
|
|
|
CoordinateSystem2D coordinate_system; ///<使用的坐标系
|
|
|
|
|
|
|
|
|
|
bool local_to_world; ///<包含LocalToWorld矩阵
|
|
|
|
|
|
2024-06-18 01:28:53 +08:00
|
|
|
|
VAType position_format; ///<position格式
|
2023-09-26 21:16:00 +08:00
|
|
|
|
|
2023-05-15 21:52:57 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2025-05-16 09:12:33 +08:00
|
|
|
|
Material2DCreateConfig(const AnsiString &name,const PrimitiveType &p):MaterialCreateConfig(name,p)
|
2023-05-15 21:52:57 +08:00
|
|
|
|
{
|
2023-05-15 22:05:21 +08:00
|
|
|
|
rt_output.color=1; //输出一个颜色
|
|
|
|
|
rt_output.depth=false; //不输出深度
|
|
|
|
|
rt_output.stencil=false; //不输出stencil
|
2023-05-15 21:52:57 +08:00
|
|
|
|
|
|
|
|
|
coordinate_system=CoordinateSystem2D::NDC;
|
|
|
|
|
local_to_world=false;
|
2023-09-26 21:49:37 +08:00
|
|
|
|
|
2025-05-04 23:36:28 +08:00
|
|
|
|
if(prim==PrimitiveType::SolidRectangles
|
|
|
|
|
||prim==PrimitiveType::WireRectangles)
|
2023-09-26 21:49:37 +08:00
|
|
|
|
position_format=VAT_VEC4;
|
|
|
|
|
else
|
|
|
|
|
position_format=VAT_VEC2;
|
2023-05-15 21:52:57 +08:00
|
|
|
|
}
|
2023-10-12 14:59:39 +08:00
|
|
|
|
|
2025-01-15 02:42:04 +08:00
|
|
|
|
const int compare(const Material2DCreateConfig &cfg)const override
|
2023-10-12 14:59:39 +08:00
|
|
|
|
{
|
2025-01-15 02:42:04 +08:00
|
|
|
|
int off=MaterialCreateConfig::compare(cfg);
|
2023-10-12 14:59:39 +08:00
|
|
|
|
|
|
|
|
|
if(off)return off;
|
|
|
|
|
|
|
|
|
|
off=(int)coordinate_system-(int)cfg.coordinate_system;
|
|
|
|
|
if(off)return off;
|
|
|
|
|
|
|
|
|
|
off=local_to_world-cfg.local_to_world;
|
|
|
|
|
if(off)return off;
|
|
|
|
|
|
|
|
|
|
off=position_format.Comp(cfg.position_format);
|
2024-05-25 22:47:26 +08:00
|
|
|
|
|
2023-10-12 14:59:39 +08:00
|
|
|
|
return off;
|
|
|
|
|
}
|
2023-06-02 20:45:19 +08:00
|
|
|
|
};//struct Material2DCreateConfig:public MaterialCreateConfig
|
2023-05-16 15:27:51 +08:00
|
|
|
|
|
2025-05-17 20:47:39 +08:00
|
|
|
|
DEFINE_MATERIAL_FACTORY_CLASS(VertexColor2D, const Material2DCreateConfig)
|
|
|
|
|
DEFINE_MATERIAL_FACTORY_CLASS(PureColor2D, const Material2DCreateConfig)
|
|
|
|
|
//DEFINE_MATERIAL_FACTORY_CLASS(LerpLine2D, const Material2DCreateConfig);
|
2025-05-17 20:01:17 +08:00
|
|
|
|
|
2025-05-17 20:47:39 +08:00
|
|
|
|
DEFINE_MATERIAL_FACTORY_CLASS(PureTexture2D, const Material2DCreateConfig);
|
|
|
|
|
DEFINE_MATERIAL_FACTORY_CLASS(RectTexture2D, Material2DCreateConfig);
|
|
|
|
|
DEFINE_MATERIAL_FACTORY_CLASS(RectTexture2DArray, Material2DCreateConfig);
|
2023-10-08 20:00:46 +08:00
|
|
|
|
|
2023-10-10 10:57:29 +08:00
|
|
|
|
// 为什么有了LoadMaterialFromFile,还需要保留以上Create系列函数?
|
|
|
|
|
|
|
|
|
|
// 1.LoadMaterialFromFile载的材质,是从文件中加载的。但我们要考虑文件损坏不能加载的情况。
|
|
|
|
|
// 2.从文件加载材质过于复杂,而且不利于调试。所以我们需要保留Create系列函数,以便于调试以及测试一些新的情况。同时让开发人员知道材质具体是如何创建的。
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 从文件加载材质
|
2025-05-16 09:12:33 +08:00
|
|
|
|
* @param dev_attr 设备属性
|
2023-10-10 10:57:29 +08:00
|
|
|
|
* @param mtl_name 材质名称
|
|
|
|
|
* @param cfg 材质创建参数
|
|
|
|
|
* @return 材质创建信息
|
|
|
|
|
*/
|
2025-05-17 20:26:36 +08:00
|
|
|
|
MaterialCreateInfo *LoadMaterialFromFile(const VulkanDevAttr *dev_attr,const AnsiString &mtl_name,Material2DCreateConfig *cfg); ///<从文件加载材质
|
2025-05-16 09:12:33 +08:00
|
|
|
|
|
2023-05-15 21:52:57 +08:00
|
|
|
|
STD_MTL_NAMESPACE_END
|