X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fglsl%2Freflect.cpp;h=258244e88b4e2457b441a75bfe9ecbed24fcc2b8;hp=91e8fa55dde940020c5255e97e48eb69abbf7afb;hb=38712d8ecc57d043a2419ffbaeeb57f7a6586f14;hpb=36569927a57a59bf0bfadb653c97395dbf8356f7 diff --git a/source/glsl/reflect.cpp b/source/glsl/reflect.cpp index 91e8fa55..258244e8 100644 --- a/source/glsl/reflect.cpp +++ b/source/glsl/reflect.cpp @@ -1,3 +1,4 @@ +#include #include "reflect.h" using namespace std; @@ -48,13 +49,6 @@ bool can_convert(const BasicTypeDeclaration &from, const BasicTypeDeclaration &t unsigned TypeComparer::next_tag = 1; -TypeComparer::TypeComparer(): - first(0), - second(0), - first_tag(0), - r_result(false) -{ } - void TypeComparer::compare(Node &node1, Node &node2) { if(&node1==&node2) @@ -121,6 +115,49 @@ void TypeComparer::visit(VariableReference &var) } } +void TypeComparer::visit(UnaryExpression &unary) +{ + if(UnaryExpression *unary1 = multi_visit(unary)) + { + if(unary1->oper!=unary.oper) + r_result = false; + else + compare(*unary1->expression, *unary.expression); + } +} + +void TypeComparer::visit(BinaryExpression &binary) +{ + if(BinaryExpression *binary1 = multi_visit(binary)) + { + if(binary1->oper!=binary.oper) + r_result = false; + else + { + compare(*binary1->left, *binary.left); + if(r_result) + compare(*binary1->right, *binary.right); + } + } +} + +void TypeComparer::visit(TernaryExpression &ternary) +{ + if(TernaryExpression *ternary1 = multi_visit(ternary)) + { + if(ternary1->oper!=ternary.oper) + r_result = false; + else + { + compare(*ternary1->condition, *ternary.condition); + if(r_result) + compare(*ternary1->true_expr, *ternary.true_expr); + if(r_result) + compare(*ternary1->false_expr, *ternary.false_expr); + } + } +} + void TypeComparer::visit(BasicTypeDeclaration &basic) { if(BasicTypeDeclaration *basic1 = multi_visit(basic)) @@ -158,8 +195,8 @@ void TypeComparer::visit(StructDeclaration &strct) else { r_result = true; - NodeList::const_iterator i = strct1->members.body.begin(); - NodeList::const_iterator j = strct.members.body.begin(); + auto i = strct1->members.body.begin(); + auto j = strct.members.body.begin(); for(; (r_result && i!=strct1->members.body.end()); ++i, ++j) compare(**i, **j); } @@ -190,10 +227,6 @@ void TypeComparer::visit(VariableDeclaration &var) } -LocationCounter::LocationCounter(): - r_count(0) -{ } - void LocationCounter::visit(BasicTypeDeclaration &basic) { r_count = basic.kind==BasicTypeDeclaration::MATRIX ? basic.size>>16 : 1; @@ -207,10 +240,10 @@ void LocationCounter::visit(ImageTypeDeclaration &) void LocationCounter::visit(StructDeclaration &strct) { unsigned total = 0; - for(NodeList::const_iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i) + for(const RefPtr &s: strct.members.body) { r_count = 1; - (*i)->visit(*this); + s->visit(*this); total += r_count; } r_count = total; @@ -256,12 +289,12 @@ void MemoryRequirementsCalculator::visit(StructDeclaration &strct) { unsigned total = 0; unsigned max_align = 1; - for(NodeList::iterator i=strct.members.body.begin(); i!=strct.members.body.end(); ++i) + for(const RefPtr &s: strct.members.body) { r_size = 0; r_alignment = 1; r_offset = -1; - (*i)->visit(*this); + s->visit(*this); if(r_offset) total = r_offset; total += r_alignment-1; @@ -277,10 +310,9 @@ void MemoryRequirementsCalculator::visit(VariableDeclaration &var) { if(var.layout) { - const vector qualifiers = var.layout->qualifiers; - for(vector::const_iterator i=qualifiers.begin(); (r_offset<0 && i!=qualifiers.end()); ++i) - if(i->name=="offset") - r_offset = i->value; + auto i = find_member(var.layout->qualifiers, string("offset"), &Layout::Qualifier::name); + if(i!=var.layout->qualifiers.end()) + r_offset = i->value; } if(var.type_declaration)