2023-03-06 14:06:20 +08:00
|
|
|
#include<hgl/shadergen/ShaderCreater.h>
|
|
|
|
|
|
|
|
SHADERGEN_NAMESPACE_BEGIN
|
|
|
|
int ShaderCreater::AddOutput(const VAT &type,const AnsiString &name)
|
|
|
|
{
|
|
|
|
ShaderStage *ss=new ShaderStage;
|
|
|
|
|
|
|
|
hgl::strcpy(ss->name,sizeof(ss->name),name.c_str());
|
|
|
|
|
|
|
|
ss->basetype=(uint8) type.basetype;
|
|
|
|
ss->vec_size= type.vec_size;
|
|
|
|
|
|
|
|
return sdm.AddOutput(ss);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ShaderCreater::AddOutput(const AnsiString &type,const AnsiString &name)
|
|
|
|
{
|
|
|
|
VAT vat;
|
|
|
|
|
2023-03-08 21:41:57 +08:00
|
|
|
if(name.IsEmpty())
|
|
|
|
return -1;
|
|
|
|
|
2023-03-06 14:06:20 +08:00
|
|
|
if(!ParseVertexAttribType(&vat,type))
|
2023-03-08 21:41:57 +08:00
|
|
|
return -2;
|
2023-03-06 14:06:20 +08:00
|
|
|
|
|
|
|
return AddOutput(vat,name);
|
|
|
|
}
|
|
|
|
|
2023-03-09 23:21:52 +08:00
|
|
|
bool ShaderCreater::ProcSubpassInput()
|
2023-03-08 21:41:57 +08:00
|
|
|
{
|
2023-03-09 23:21:52 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderCreater::ProcInput(ShaderCreater *last_sc)
|
|
|
|
{
|
|
|
|
if(!last_sc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
AnsiString last_output=last_sc->GetOutputStruct();
|
|
|
|
|
|
|
|
if(last_output.IsEmpty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
final_shader+="layout(location=0) in ";
|
|
|
|
final_shader+=last_output;
|
|
|
|
final_shader+="Input;\n\n";
|
2023-03-08 21:41:57 +08:00
|
|
|
}
|
|
|
|
|
2023-03-09 23:21:52 +08:00
|
|
|
bool ShaderCreater::ProcOutput()
|
2023-03-08 21:41:57 +08:00
|
|
|
{
|
|
|
|
final_shader+="layout(location=0) out ";
|
|
|
|
|
|
|
|
output_struct.Clear();
|
|
|
|
|
2023-03-09 23:21:52 +08:00
|
|
|
output_struct=GetShaderStageName(shader_stage);
|
|
|
|
output_struct+="_Output\n{\n";
|
|
|
|
|
2023-03-08 21:41:57 +08:00
|
|
|
for(auto *ss:sdm.GetShaderStageIO().output)
|
|
|
|
{
|
|
|
|
output_struct+="\t";
|
|
|
|
output_struct+=GetShaderStageTypeName(ss);
|
|
|
|
output_struct+=" ";
|
|
|
|
output_struct+=ss->name;
|
|
|
|
output_struct+=";\n";
|
|
|
|
}
|
|
|
|
|
2023-03-09 23:21:52 +08:00
|
|
|
output_struct+="}";
|
|
|
|
|
2023-03-08 21:41:57 +08:00
|
|
|
final_shader+=output_struct;
|
2023-03-09 23:21:52 +08:00
|
|
|
final_shader+="Output;\n\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderCreater::ProcStruct()
|
|
|
|
{
|
|
|
|
const AnsiStringList struct_list=sdm.GetStructList();
|
|
|
|
|
|
|
|
AnsiString codes;
|
|
|
|
|
|
|
|
for(const AnsiString &str:struct_list)
|
|
|
|
{
|
|
|
|
if(!mdm->GetStruct(str,codes))
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderCreater::ProcUBO()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderCreater::ProcSSBO()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderCreater::ProcConst()
|
|
|
|
{
|
2023-03-08 21:41:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ShaderCreater::CreateShader(ShaderCreater *last_sc)
|
|
|
|
{
|
|
|
|
final_shader="#version 460 core\n";
|
|
|
|
|
2023-03-09 23:21:52 +08:00
|
|
|
ProcInput(last_sc);
|
|
|
|
|
|
|
|
ProcOutput();
|
2023-03-08 21:41:57 +08:00
|
|
|
}
|
|
|
|
|
2023-03-06 21:30:32 +08:00
|
|
|
bool ShaderCreater::CompileToSPV()
|
2023-03-06 14:06:20 +08:00
|
|
|
{
|
2023-03-08 14:02:51 +08:00
|
|
|
if(shader_codes.IsEmpty())
|
|
|
|
return(false);
|
|
|
|
|
|
|
|
|
2023-03-06 14:06:20 +08:00
|
|
|
}
|
2023-03-06 21:30:32 +08:00
|
|
|
SHADERGEN_NAMESPACE_END
|