MaterialTextParse completed VertexShader/FragmentShader parse.
This commit is contained in:
parent
46781b9627
commit
5ede824522
@ -2,6 +2,7 @@
|
|||||||
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
#include<hgl/graph/mtl/Material2DCreateConfig.h>
|
||||||
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
#include<hgl/graph/mtl/Material3DCreateConfig.h>
|
||||||
#include<hgl/graph/VKShaderStage.h>
|
#include<hgl/graph/VKShaderStage.h>
|
||||||
|
#include<hgl/graph/VertexAttrib.h>
|
||||||
|
|
||||||
#include<hgl/io/TextInputStream.h>
|
#include<hgl/io/TextInputStream.h>
|
||||||
#include<hgl/io/FileInputStream.h>
|
#include<hgl/io/FileInputStream.h>
|
||||||
@ -18,25 +19,13 @@ namespace
|
|||||||
|
|
||||||
Material,
|
Material,
|
||||||
MaterialInstance,
|
MaterialInstance,
|
||||||
MaterialInstanceCode,
|
VertexInput,
|
||||||
|
|
||||||
Vertex,
|
Vertex,
|
||||||
VertexInput,
|
|
||||||
VertexOutput,
|
|
||||||
VertexCode,
|
|
||||||
|
|
||||||
Geometry,
|
Geometry,
|
||||||
GeometryInput,
|
|
||||||
GeometryOutput,
|
|
||||||
GeometryCode,
|
|
||||||
|
|
||||||
Fragment,
|
Fragment,
|
||||||
FragmentInput,
|
|
||||||
FragmentOutput,
|
|
||||||
FragmentCode,
|
|
||||||
|
|
||||||
|
ENUM_CLASS_RANGE(None,Fragment)
|
||||||
ENUM_CLASS_RANGE(None,FragmentCode)
|
|
||||||
};//enum class State
|
};//enum class State
|
||||||
|
|
||||||
struct MaterialFileStateInfo
|
struct MaterialFileStateInfo
|
||||||
@ -52,11 +41,14 @@ namespace
|
|||||||
{
|
{
|
||||||
MFS(Material)
|
MFS(Material)
|
||||||
MFS(MaterialInstance)
|
MFS(MaterialInstance)
|
||||||
|
MFS(VertexInput)
|
||||||
MFS(Vertex)
|
MFS(Vertex)
|
||||||
MFS(Geometry)
|
MFS(Geometry)
|
||||||
MFS(Fragment)
|
MFS(Fragment)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#undef MFS
|
||||||
|
|
||||||
const MaterialFileState GetMaterialFileState(const char *str,const int len)
|
const MaterialFileState GetMaterialFileState(const char *str,const int len)
|
||||||
{
|
{
|
||||||
for(const MaterialFileStateInfo &info:state_list)
|
for(const MaterialFileStateInfo &info:state_list)
|
||||||
@ -114,7 +106,7 @@ namespace
|
|||||||
|
|
||||||
return(false);
|
return(false);
|
||||||
}
|
}
|
||||||
};
|
};//struct CodeParse
|
||||||
|
|
||||||
struct MaterialInstanceStateParse:public MaterialFileParse
|
struct MaterialInstanceStateParse:public MaterialFileParse
|
||||||
{
|
{
|
||||||
@ -135,6 +127,8 @@ namespace
|
|||||||
{
|
{
|
||||||
if(code_parse.OnLine(text,len))
|
if(code_parse.OnLine(text,len))
|
||||||
code=false;
|
code=false;
|
||||||
|
|
||||||
|
return(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(hgl::stricmp(text,"Code",4)==0)
|
if(hgl::stricmp(text,"Code",4)==0)
|
||||||
@ -174,8 +168,107 @@ namespace
|
|||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
}
|
}
|
||||||
|
};//struct MaterialInstanceStateParse
|
||||||
|
|
||||||
|
struct UniformAttrib
|
||||||
|
{
|
||||||
|
VAT vat;
|
||||||
|
|
||||||
|
char name[SHADER_RESOURCE_NAME_MAX_LENGTH];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool ParseUniformAttrib(UniformAttrib *ua,const char *str)
|
||||||
|
{
|
||||||
|
const char *sp;
|
||||||
|
|
||||||
|
while(*str==' '||*str=='\t')++str;
|
||||||
|
|
||||||
|
if(!ParseVertexAttribType(&(ua->vat),str))
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
while(*str!=' '&&*str!='\t')++str;
|
||||||
|
while(*str==' '||*str=='\t')++str;
|
||||||
|
|
||||||
|
sp=str;
|
||||||
|
|
||||||
|
while(hgl::iscodechar(*str))++str;
|
||||||
|
|
||||||
|
hgl::strcpy(ua->name,SHADER_RESOURCE_NAME_MAX_LENGTH,sp,str-sp);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct VertexInputStateParse:public MaterialFileParse
|
||||||
|
{
|
||||||
|
List<UniformAttrib> input_list;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
bool OnLine(const char *text,const int len) override
|
||||||
|
{
|
||||||
|
if(!text||!*text||len<=0)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
UniformAttrib ua;
|
||||||
|
|
||||||
|
if(ParseUniformAttrib(&ua,text))
|
||||||
|
input_list.Add(ua);
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
};//struct VertexInputStateParse
|
||||||
|
|
||||||
|
struct ShaderStateParse:public MaterialFileParse
|
||||||
|
{
|
||||||
|
bool output=false;
|
||||||
|
List<UniformAttrib> output_list;
|
||||||
|
|
||||||
|
bool code=false;
|
||||||
|
CodeParse code_parse;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
bool OnLine(const char *text,const int len) override
|
||||||
|
{
|
||||||
|
if(!text||!*text||len<=0)
|
||||||
|
return(false);
|
||||||
|
|
||||||
|
if(code)
|
||||||
|
{
|
||||||
|
if(code_parse.OnLine(text,len))
|
||||||
|
code=false;
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(output)
|
||||||
|
{
|
||||||
|
if(*text=='}')
|
||||||
|
{
|
||||||
|
output=false;
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
UniformAttrib ua;
|
||||||
|
|
||||||
|
if(ParseUniformAttrib(&ua,text))
|
||||||
|
output_list.Add(ua);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(hgl::stricmp(text,"Code",4)==0)
|
||||||
|
{
|
||||||
|
code=true;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
if(hgl::stricmp(text,"Output",6)==0)
|
||||||
|
{
|
||||||
|
output=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return(true);
|
||||||
|
}
|
||||||
|
};//struct ShaderStateParse
|
||||||
|
|
||||||
struct MaterialTextParse:public MaterialFileParse
|
struct MaterialTextParse:public MaterialFileParse
|
||||||
{
|
{
|
||||||
MaterialFileState state;
|
MaterialFileState state;
|
||||||
@ -208,13 +301,15 @@ namespace
|
|||||||
|
|
||||||
switch(state)
|
switch(state)
|
||||||
{
|
{
|
||||||
case MaterialFileState::Material: parse=new MaterialStateParse;break;
|
case MaterialFileState::Material: parse=new MaterialStateParse;break;
|
||||||
case MaterialFileState::MaterialInstance: parse=new MaterialInstanceStateParse;break;
|
case MaterialFileState::MaterialInstance: parse=new MaterialInstanceStateParse;break;
|
||||||
// case MaterialFileState::Vertex: parse=new VertexStateParse;break;
|
case MaterialFileState::VertexInput: parse=new VertexInputStateParse;break;
|
||||||
// case MaterialFileState::Geometry: parse=new GeometryStateParse;break;
|
case MaterialFileState::Vertex:
|
||||||
// case MaterialFileState::Fragment: parse=new FragmentStateParse;break;
|
case MaterialFileState::Fragment: parse=new ShaderStateParse;break;
|
||||||
|
|
||||||
default: state=MaterialFileState::None;return(false);
|
// case MaterialFileState::Geometry: parse=new GeometryStateParse;break;
|
||||||
|
|
||||||
|
default: state=MaterialFileState::None;return(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(true);
|
return(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user