X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fsyntax.cpp;h=c54a82979081cc03e3a2c4bbb66e55cb9b2aa934;hb=03d9003072e85c934f5624329fb4a34db8763db2;hp=e7a3990e5c1478b3fcdf8e5727226b05ba688582;hpb=22d5405729048ee2677a1e45e309e6328de64a26;p=libs%2Fgl.git diff --git a/source/glsl/syntax.cpp b/source/glsl/syntax.cpp index e7a3990e..c54a8297 100644 --- a/source/glsl/syntax.cpp +++ b/source/glsl/syntax.cpp @@ -138,14 +138,16 @@ void InterfaceBlockReference::visit(NodeVisitor &visitor) MemberAccess::MemberAccess(): - declaration(0) + declaration(0), + index(-1) { } MemberAccess::MemberAccess(const MemberAccess &other): Expression(other), left(other.left), member(other.member), - declaration(0) + declaration(0), + index(-1) { } void MemberAccess::visit(NodeVisitor &visitor) @@ -369,7 +371,7 @@ InterfaceBlock::InterfaceBlock(): InterfaceBlock::InterfaceBlock(const InterfaceBlock &other): Statement(other), interface(other.interface), - name(other.name), + block_name(other.block_name), members(other.members), instance_name(other.instance_name), array(other.array), @@ -485,6 +487,74 @@ string get_unused_variable_name(const Block &block, const string &base) } } +bool is_same_type(const TypeDeclaration &type1, const TypeDeclaration &type2) +{ + if(const BasicTypeDeclaration *basic1 = dynamic_cast(&type1)) + { + const BasicTypeDeclaration *basic2 = dynamic_cast(&type2); + if(!basic2) + return false; + + if(basic1->kind!=basic2->kind || basic1->size!=basic2->size) + return false; + + if(basic1->base_type && basic2->base_type) + return is_same_type(*basic1->base_type, *basic2->base_type); + else + return (!basic1->base_type && !basic2->base_type); + } + else if(const ImageTypeDeclaration *image1 = dynamic_cast(&type1)) + { + const ImageTypeDeclaration *image2 = dynamic_cast(&type2); + if(!image2) + return false; + + if(image1->dimensions!=image2->dimensions || image1->array!=image2->array) + return false; + if(image1->sampled!=image2->sampled || image1->shadow!=image2->shadow) + return false; + + if(image1->base_type && image2->base_type) + return is_same_type(*image1->base_type, *image2->base_type); + else + return (!image1->base_type && !image2->base_type); + } + else if(const StructDeclaration *strct1 = dynamic_cast(&type1)) + { + const StructDeclaration *strct2 = dynamic_cast(&type2); + if(!strct2) + return false; + + NodeList::const_iterator i = strct1->members.body.begin(); + NodeList::const_iterator j = strct2->members.body.begin(); + for(; (i!=strct1->members.body.end() && j!=strct2->members.body.end()); ++i, ++j) + { + const VariableDeclaration *var1 = dynamic_cast(i->get()); + const VariableDeclaration *var2 = dynamic_cast(j->get()); + if(!var1 || !var1->type_declaration || !var2 || !var2->type_declaration) + return false; + if(!is_same_type(*var1->type_declaration, *var2->type_declaration)) + return false; + if(var1->name!=var2->name || var1->array!=var2->array) + return false; + // TODO Compare array sizes + // TODO Compare layout qualifiers for interface block members + } + + return (i==strct1->members.body.end() && j==strct2->members.body.end()); + } + else + return false; +} + +int get_layout_value(const Layout &layout, const string &name, int def_value) +{ + for(vector::const_iterator i=layout.qualifiers.begin(); i!=layout.qualifiers.end(); ++i) + if(i->name==name) + return i->value; + return def_value; +} + } // namespace SL } // namespace GL } // namespace Msp