2019-12-12 22:25:40 +08:00
|
|
|
|
#include<hgl/graph/shader/node/node.h>
|
|
|
|
|
|
|
|
|
|
BEGIN_SHADER_NODE_NAMESPACE
|
2019-12-16 20:35:51 +08:00
|
|
|
|
param::InputParam *Node::AddInput(bool mj,const UTF8String &n,const param::ParamType &pt)
|
2019-12-13 17:55:20 +08:00
|
|
|
|
{
|
|
|
|
|
param::InputParam *ip=new param::InputParam(mj,n,pt);
|
|
|
|
|
|
|
|
|
|
input_params.Add(ip);
|
|
|
|
|
|
|
|
|
|
input_params_by_name.Add(n,ip);
|
2019-12-16 20:35:51 +08:00
|
|
|
|
|
|
|
|
|
return ip;
|
2019-12-13 17:55:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-16 20:35:51 +08:00
|
|
|
|
param::OutputParam *Node::AddOutput(const UTF8String &n,const param::ParamType &pt)
|
2019-12-13 17:55:20 +08:00
|
|
|
|
{
|
|
|
|
|
param::OutputParam *op=new param::OutputParam(n,pt);
|
|
|
|
|
|
|
|
|
|
output_params.Add(op);
|
|
|
|
|
|
|
|
|
|
output_params_by_name.Add(n,op);
|
2019-12-16 20:35:51 +08:00
|
|
|
|
|
|
|
|
|
return op;
|
2019-12-13 17:55:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-14 13:42:16 +08:00
|
|
|
|
bool Node::JoinInput(const UTF8String ¶m_name,node::Node *n,param::OutputParam *op)
|
2019-12-13 17:55:20 +08:00
|
|
|
|
{
|
2019-12-16 20:35:51 +08:00
|
|
|
|
if(param_name.IsEmpty()||!n||!op)
|
2019-12-13 17:55:20 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
2019-12-14 13:42:16 +08:00
|
|
|
|
if(!n->IsOutput(op))
|
2019-12-13 17:55:20 +08:00
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
param::InputParam *ip=GetInput(param_name);
|
|
|
|
|
|
|
|
|
|
if(!ip)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return ip->Join(n,op);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-20 22:08:10 +08:00
|
|
|
|
bool Node::JoinInput(const UTF8String ¶m_name,node::Node *n)
|
|
|
|
|
{
|
|
|
|
|
if(param_name.IsEmpty()||!n)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
node::OutputParamList &opl=n->GetOutputParamList();
|
|
|
|
|
|
|
|
|
|
if(opl.GetCount()!=1)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
param::OutputParam *op=*(opl.GetBegin());
|
|
|
|
|
|
|
|
|
|
param::InputParam *ip=GetInput(param_name);
|
|
|
|
|
|
|
|
|
|
if(!ip)
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return ip->Join(n,op);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-18 20:12:56 +08:00
|
|
|
|
bool Node::IsOutput(const param::OutputParam *op) const
|
2019-12-13 11:20:08 +08:00
|
|
|
|
{
|
|
|
|
|
if(!op)return(false);
|
|
|
|
|
|
|
|
|
|
return output_params.IsExist(op);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Node::Check()
|
2019-12-12 22:25:40 +08:00
|
|
|
|
{
|
|
|
|
|
const int count=input_params.GetCount();
|
|
|
|
|
param::InputParam **ip=input_params.GetData();
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<count;i++)
|
|
|
|
|
if(!(*ip)->Check())
|
|
|
|
|
return(false);
|
|
|
|
|
else
|
|
|
|
|
++ip;
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-12-18 20:12:56 +08:00
|
|
|
|
|
|
|
|
|
bool Node::GetInputParamName(UTF8String &result,const param::InputParam *ip)
|
|
|
|
|
{
|
|
|
|
|
if(!ip)return(false);
|
|
|
|
|
|
|
|
|
|
result=node_name+U8_TEXT("_")+ip->GetName();
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Node::GetOutputParamName(UTF8String &result,const param::OutputParam *op)
|
|
|
|
|
{
|
|
|
|
|
if(!op)return(false);
|
|
|
|
|
|
|
|
|
|
result=node_name+U8_TEXT("_")+op->GetName();
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Node::GenInputParamCode(UTF8StringList &sl)
|
|
|
|
|
{
|
|
|
|
|
const int count=input_params.GetCount();
|
|
|
|
|
param::InputParam **ip=input_params.GetData();
|
|
|
|
|
|
|
|
|
|
UTF8String in_name,out_name;
|
|
|
|
|
Node *jin;
|
|
|
|
|
param::OutputParam *jop;
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<count;i++)
|
|
|
|
|
{
|
|
|
|
|
if(!this->GetInputParamName(in_name,*ip))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
jin=(*ip)->GetJoinNode();
|
|
|
|
|
if(jin)
|
|
|
|
|
{
|
|
|
|
|
jop=(*ip)->GetJoinParam();
|
|
|
|
|
|
|
|
|
|
if(!jin->GetOutputParamName(out_name,jop))
|
|
|
|
|
return(false);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
out_name=(*ip)->GetDefaultValue();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
sl.Add(in_name+"="+out_name+";");
|
|
|
|
|
|
|
|
|
|
++ip;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-18 20:33:46 +08:00
|
|
|
|
#define SHADER_NODE_TEMP_VALUE_COMMENT ";\t\t\t// temp value of ["+node_name+"]"
|
|
|
|
|
|
2019-12-18 20:12:56 +08:00
|
|
|
|
bool Node::GenTempValueDefine(UTF8StringList &sl)
|
|
|
|
|
{
|
|
|
|
|
const int count=input_params.GetCount();
|
|
|
|
|
param::InputParam **ip=input_params.GetData();
|
|
|
|
|
param::ParamType pt;
|
|
|
|
|
UTF8String value_name;
|
|
|
|
|
|
|
|
|
|
for(int i=0;i<count;i++)
|
|
|
|
|
{
|
|
|
|
|
if(!GetInputParamName(value_name,*ip))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
pt=(*ip)->GetType();
|
|
|
|
|
|
|
|
|
|
if((*ip)->GetJoinNode())
|
2019-12-18 20:33:46 +08:00
|
|
|
|
sl.Add("\t"+UTF8String(param::GetTypename(pt))+" "+value_name+SHADER_NODE_TEMP_VALUE_COMMENT);
|
2019-12-18 20:12:56 +08:00
|
|
|
|
else
|
2019-12-18 20:33:46 +08:00
|
|
|
|
sl.Add("\t"+UTF8String(param::GetTypename(pt))+" "+value_name+"="+(*ip)->GetDefaultValue()+SHADER_NODE_TEMP_VALUE_COMMENT);
|
2019-12-19 18:08:27 +08:00
|
|
|
|
|
2019-12-18 20:12:56 +08:00
|
|
|
|
++ip;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 18:08:27 +08:00
|
|
|
|
return(true);
|
2019-12-18 20:12:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Node::GenCode(UTF8StringList &sl)
|
|
|
|
|
{
|
|
|
|
|
if(!GenInputParamCode(sl))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
if(!GenOutputParamCode(sl))
|
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
|
}
|
2019-12-12 22:25:40 +08:00
|
|
|
|
END_SHADER_NODE_NAMESPACE
|