2019-12-10 21:52:10 +08:00
|
|
|
|
#ifndef HGL_GRAPH_SHADER_NODE_INCLUDE
|
|
|
|
|
#define HGL_GRAPH_SHADER_NODE_INCLUDE
|
|
|
|
|
|
2019-12-18 20:12:56 +08:00
|
|
|
|
#include<hgl/type/StringList.h>
|
2019-12-10 21:52:10 +08:00
|
|
|
|
#include<hgl/type/List.h>
|
2019-12-13 17:55:20 +08:00
|
|
|
|
#include<hgl/type/Map.h>
|
2019-12-14 20:52:58 +08:00
|
|
|
|
#include<hgl/graph/shader/node/type.h>
|
2019-12-13 11:20:08 +08:00
|
|
|
|
#include<hgl/graph/shader/param/in.h>
|
|
|
|
|
#include<hgl/graph/shader/param/out.h>
|
2019-12-10 21:52:10 +08:00
|
|
|
|
|
|
|
|
|
BEGIN_SHADER_NODE_NAMESPACE
|
2019-12-13 11:20:08 +08:00
|
|
|
|
|
2019-12-13 17:55:20 +08:00
|
|
|
|
#define SHADER_INPUT_PARAM(mj,name,type) AddInput(mj,#name,SHADER_PARAM_NAMESPACE::ParamType::type);
|
2019-12-16 20:35:51 +08:00
|
|
|
|
#define SHADER_OUTPUT_PARAM(name,type) AddOutput(#name,SHADER_PARAM_NAMESPACE::ParamType::type);
|
2019-12-13 11:20:08 +08:00
|
|
|
|
|
|
|
|
|
using InputParamList=ObjectList<param::InputParam>;
|
|
|
|
|
using OutputParamList=ObjectList<param::OutputParam>;
|
2019-12-13 17:55:20 +08:00
|
|
|
|
using InputParamMapByName=Map<UTF8String,param::InputParam *>;
|
|
|
|
|
using OutputParamMapByName=Map<UTF8String,param::OutputParam *>;
|
2019-12-13 11:20:08 +08:00
|
|
|
|
|
2019-12-10 22:12:09 +08:00
|
|
|
|
/**
|
2019-12-13 17:55:20 +08:00
|
|
|
|
* Shader 节点是所有Shader的基础,它可以是一个数据转接(纹理或流),也可以是一个纯粹的计算公式
|
2019-12-10 22:12:09 +08:00
|
|
|
|
*/
|
|
|
|
|
class Node
|
|
|
|
|
{
|
2019-12-16 20:35:51 +08:00
|
|
|
|
NodeType node_type;
|
2019-12-12 22:25:40 +08:00
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
2019-12-16 20:35:51 +08:00
|
|
|
|
UTF8String node_name; ///<节点用户自定义名称
|
2019-12-10 21:52:10 +08:00
|
|
|
|
|
2019-12-13 11:20:08 +08:00
|
|
|
|
InputParamList input_params;
|
|
|
|
|
OutputParamList output_params;
|
2019-12-12 22:25:40 +08:00
|
|
|
|
|
2019-12-13 17:55:20 +08:00
|
|
|
|
InputParamMapByName input_params_by_name;
|
|
|
|
|
OutputParamMapByName output_params_by_name;
|
|
|
|
|
|
2019-12-18 20:12:56 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
|
|
|
|
virtual bool GenInputParamCode(UTF8StringList &);
|
|
|
|
|
virtual bool GenOutputParamCode(UTF8StringList &);
|
|
|
|
|
|
2019-12-13 17:55:20 +08:00
|
|
|
|
protected:
|
|
|
|
|
|
2019-12-16 20:35:51 +08:00
|
|
|
|
param::InputParam * AddInput (bool mj,const UTF8String &n,const param::ParamType &pt);
|
|
|
|
|
param::OutputParam *AddOutput (const UTF8String &n,const param::ParamType &pt);
|
2019-12-13 17:55:20 +08:00
|
|
|
|
|
2019-12-14 13:42:16 +08:00
|
|
|
|
public:
|
|
|
|
|
|
2019-12-13 17:55:20 +08:00
|
|
|
|
param::InputParam * GetInput (const UTF8String &n) ///<根据名称获取输入参数
|
|
|
|
|
{return GetListObject(input_params_by_name,n);}
|
|
|
|
|
|
|
|
|
|
param::OutputParam *GetOutput (const UTF8String &n) ///<根据名称获取输出参数
|
|
|
|
|
{return GetListObject(output_params_by_name,n);}
|
|
|
|
|
|
2019-12-10 22:12:09 +08:00
|
|
|
|
public:
|
2019-12-10 21:52:10 +08:00
|
|
|
|
|
2019-12-16 20:35:51 +08:00
|
|
|
|
Node(const NodeType &nt){node_type=nt;}
|
|
|
|
|
Node(const NodeType &nt,const UTF8String &n){node_type=nt;node_name=n;}
|
2019-12-10 22:12:09 +08:00
|
|
|
|
virtual ~Node()=default;
|
2019-12-12 22:25:40 +08:00
|
|
|
|
|
2019-12-16 20:35:51 +08:00
|
|
|
|
const NodeType GetNodeType ()const{return node_type;}
|
2019-12-13 11:20:08 +08:00
|
|
|
|
|
2019-12-16 20:35:51 +08:00
|
|
|
|
const UTF8String & GetNodeName ()const{return node_name;}
|
|
|
|
|
void SetNodeName (const UTF8String &n){node_name=n;}
|
2019-12-13 17:55:20 +08:00
|
|
|
|
|
|
|
|
|
public: //参数相关
|
2019-12-13 11:20:08 +08:00
|
|
|
|
|
|
|
|
|
InputParamList & GetInputParamList (){return input_params;}
|
|
|
|
|
OutputParamList & GetOutputParamList (){return output_params;}
|
2019-12-12 22:25:40 +08:00
|
|
|
|
|
2019-12-14 13:42:16 +08:00
|
|
|
|
virtual bool JoinInput (const UTF8String &,node::Node *,param::OutputParam *);
|
2019-12-13 17:55:20 +08:00
|
|
|
|
|
2019-12-12 22:25:40 +08:00
|
|
|
|
public: //参数相关
|
|
|
|
|
|
2019-12-18 20:12:56 +08:00
|
|
|
|
virtual bool IsOutput(const param::OutputParam *) const;
|
2019-12-12 22:25:40 +08:00
|
|
|
|
|
2019-12-13 11:20:08 +08:00
|
|
|
|
virtual bool Check(); ///<检测当前节点是否可用
|
2019-12-16 20:35:51 +08:00
|
|
|
|
|
2019-12-18 20:12:56 +08:00
|
|
|
|
virtual bool GetInputParamName(UTF8String &result,const param::InputParam *);
|
|
|
|
|
virtual bool GetOutputParamName(UTF8String &result,const param::OutputParam *);
|
|
|
|
|
|
|
|
|
|
public: //产生代码相关
|
|
|
|
|
|
|
|
|
|
virtual bool GenTempValueDefine(UTF8StringList &); ///<产生临时变量定义
|
|
|
|
|
virtual bool GenCode(UTF8StringList &);
|
2019-12-10 22:12:09 +08:00
|
|
|
|
};//class Node
|
2019-12-10 21:52:10 +08:00
|
|
|
|
END_SHADER_NODE_NAMESPACE
|
|
|
|
|
#endif//HGL_GRAPH_SHADER_NODE_INCLUDE
|