added a parse in MaterialFileLoader.cpp that it's UBOParse
This commit is contained in:
parent
775e031422
commit
4aeb28c571
@ -3,7 +3,16 @@ Name BlinnPhong+HalfLambert shading model only color
|
|||||||
Reference https://zhuanlan.zhihu.com/p/442023993
|
Reference https://zhuanlan.zhihu.com/p/442023993
|
||||||
Base Std3D
|
Base Std3D
|
||||||
|
|
||||||
Require LocalToWorld,Camera,Sun
|
//某些Require并不真的存在.ubo文件,写成一行一个是为了方便未来改成带路径的
|
||||||
|
Require LocalToWorld
|
||||||
|
Require Camera
|
||||||
|
|
||||||
|
UBO
|
||||||
|
{
|
||||||
|
File Sun.ubo
|
||||||
|
Name sun
|
||||||
|
Stage Vertex,Fragment
|
||||||
|
}
|
||||||
|
|
||||||
#MaterialInstance
|
#MaterialInstance
|
||||||
|
|
||||||
|
2
ShaderLibrary/Std3D/Sun.ubo
Normal file
2
ShaderLibrary/Std3D/Sun.ubo
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
vec4 direction;
|
||||||
|
vec4 color;
|
@ -34,11 +34,22 @@ namespace material_file
|
|||||||
SamplerType type;
|
SamplerType type;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct UBOData
|
||||||
|
{
|
||||||
|
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
|
||||||
|
|
||||||
|
char filename[HGL_MAX_PATH];
|
||||||
|
|
||||||
|
uint32_t shader_stage_flag_bits;
|
||||||
|
};
|
||||||
|
|
||||||
|
using UBODataList=List<UBOData>;
|
||||||
|
|
||||||
struct ShaderData
|
struct ShaderData
|
||||||
{
|
{
|
||||||
VkShaderStageFlagBits shader_stage;
|
VkShaderStageFlagBits shader_stage;
|
||||||
|
|
||||||
const char *code;
|
const char * code;
|
||||||
uint code_length;
|
uint code_length;
|
||||||
|
|
||||||
List<UniformAttrib> output;
|
List<UniformAttrib> output;
|
||||||
@ -91,6 +102,8 @@ namespace material_file
|
|||||||
|
|
||||||
List<UniformAttrib> vi; ///<Vertex Input
|
List<UniformAttrib> vi; ///<Vertex Input
|
||||||
|
|
||||||
|
UBODataList ubo_list;
|
||||||
|
|
||||||
ShaderDataMap shader;
|
ShaderDataMap shader;
|
||||||
|
|
||||||
uint32_t shader_stage_flag_bit;
|
uint32_t shader_stage_flag_bit;
|
||||||
|
@ -63,19 +63,113 @@ namespace
|
|||||||
return MaterialFileBlock::None;
|
return MaterialFileBlock::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const uint32_t ShaderStageParse(char *text,const char *ep)
|
||||||
|
{
|
||||||
|
uint32_t shader_stage_flag_bits=0;
|
||||||
|
char *sp;
|
||||||
|
|
||||||
|
while(*text==' '||*text=='\t')++text;
|
||||||
|
|
||||||
|
while(text<ep)
|
||||||
|
{
|
||||||
|
sp=text;
|
||||||
|
|
||||||
|
while(hgl::isalpha(*text))
|
||||||
|
++text;
|
||||||
|
|
||||||
|
shader_stage_flag_bits|=GetShaderStageFlagBits(sp,text-sp);
|
||||||
|
|
||||||
|
++text;
|
||||||
|
}
|
||||||
|
|
||||||
|
return shader_stage_flag_bits;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ClipCodeString(char *str,const int max_len,const char *text)
|
||||||
|
{
|
||||||
|
while(*text==' '||*text=='\t')++text;
|
||||||
|
|
||||||
|
const char *sp=text;
|
||||||
|
|
||||||
|
while(hgl::iscodechar(*text))++text;
|
||||||
|
|
||||||
|
hgl::strcpy(str,max_len,sp,text-sp);
|
||||||
|
|
||||||
|
return text-sp;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct UBOParse:public TextParse
|
||||||
|
{
|
||||||
|
UBOData ubo_data;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
void Clear()
|
||||||
|
{
|
||||||
|
hgl_zero(ubo_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool OnLine(char *text,const int len) override
|
||||||
|
{
|
||||||
|
if(!text||!*text||len<=0)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(*text=='{')
|
||||||
|
{
|
||||||
|
++text;
|
||||||
|
while(*text=='\r'||*text=='\n')++text;
|
||||||
|
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(*text=='}')
|
||||||
|
{
|
||||||
|
*text=0;
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
while(*text==' '||*text=='\t')++text;
|
||||||
|
if(text[0]=='/'&&text[1]=='/')
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(hgl::stricmp(text,"File ",5)==0)
|
||||||
|
{
|
||||||
|
ClipCodeString(ubo_data.filename,sizeof(ubo_data.filename),text+5);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(hgl::stricmp(text,"Name ",5)==0)
|
||||||
|
{
|
||||||
|
ClipCodeString(ubo_data.name,sizeof(ubo_data.name),text+5);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(hgl::stricmp(text,"Stage ",6)==0)
|
||||||
|
{
|
||||||
|
ubo_data.shader_stage_flag_bits=ShaderStageParse(text+6,text+len);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(false);
|
||||||
|
}
|
||||||
|
};//struct UBOParse
|
||||||
|
|
||||||
struct MaterialBlockParse:public TextParse
|
struct MaterialBlockParse:public TextParse
|
||||||
{
|
{
|
||||||
MaterialFileBlock state;
|
MaterialFileBlock state;
|
||||||
|
|
||||||
AnsiStringList *require_list=nullptr;
|
AnsiStringList *require_list=nullptr;
|
||||||
|
|
||||||
|
UBODataList *ubo_list=nullptr;
|
||||||
|
|
||||||
|
bool ubo=false;
|
||||||
|
UBOParse ubo_parse;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
MaterialBlockParse(AnsiStringList *asl)
|
MaterialBlockParse(AnsiStringList *asl,UBODataList *udl)
|
||||||
{
|
{
|
||||||
state=MaterialFileBlock::None;
|
state=MaterialFileBlock::None;
|
||||||
|
|
||||||
require_list=asl;
|
require_list=asl;
|
||||||
|
ubo_list=udl;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OnLine(char *text,const int len) override
|
bool OnLine(char *text,const int len) override
|
||||||
@ -85,6 +179,19 @@ namespace
|
|||||||
|
|
||||||
char *ep=text+len;
|
char *ep=text+len;
|
||||||
|
|
||||||
|
if(ubo)
|
||||||
|
{
|
||||||
|
if(ubo_parse.OnLine(text,len))
|
||||||
|
{
|
||||||
|
ubo_list->Add(ubo_parse.ubo_data);
|
||||||
|
|
||||||
|
ubo_parse.Clear();
|
||||||
|
ubo=false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
if(hgl::stricmp(text,"Require ",8)==0)
|
if(hgl::stricmp(text,"Require ",8)==0)
|
||||||
{
|
{
|
||||||
text+=8;
|
text+=8;
|
||||||
@ -102,6 +209,11 @@ namespace
|
|||||||
sp=text;
|
sp=text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
if(hgl::stricmp(text,"UBO",3)==0)
|
||||||
|
{
|
||||||
|
ubo=true;
|
||||||
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
@ -195,24 +307,7 @@ namespace
|
|||||||
else
|
else
|
||||||
if(hgl::stricmp(text,"Stage ",6)==0)
|
if(hgl::stricmp(text,"Stage ",6)==0)
|
||||||
{
|
{
|
||||||
const char *ep=text+len;
|
shader_stage_flag_bits=ShaderStageParse(text+6,text+len);
|
||||||
const char *sp;
|
|
||||||
|
|
||||||
text+=6;
|
|
||||||
|
|
||||||
while(*text==' '||*text=='\t')++text;
|
|
||||||
|
|
||||||
while(text<ep)
|
|
||||||
{
|
|
||||||
sp=text;
|
|
||||||
|
|
||||||
while(hgl::isalpha(*text))
|
|
||||||
++text;
|
|
||||||
|
|
||||||
shader_stage_flag_bits|=GetShaderStageFlagBits(sp,text-sp);
|
|
||||||
|
|
||||||
++text;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
@ -461,7 +556,7 @@ namespace
|
|||||||
state=GetMaterialFileState(text+1,len-1);
|
state=GetMaterialFileState(text+1,len-1);
|
||||||
|
|
||||||
if(state==MaterialFileBlock::Material)
|
if(state==MaterialFileBlock::Material)
|
||||||
parse=new MaterialBlockParse(&(mfd->require_list));
|
parse=new MaterialBlockParse(&(mfd->require_list),&(mfd->ubo_list));
|
||||||
else
|
else
|
||||||
if(state==MaterialFileBlock::MaterialInstance)
|
if(state==MaterialFileBlock::MaterialInstance)
|
||||||
parse=new MaterialInstanceBlockParse(&(mfd->mi));
|
parse=new MaterialInstanceBlockParse(&(mfd->mi));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user