X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fglsl%2Fresolve.cpp;h=fec3cf143130a583c38a961b38b70087309b555e;hb=fe980fbd898645eba1ac06a5061b3a48db4638b0;hp=8bfe635ee73b8d2f3c0dd1bd9dd7414313117263;hpb=3773733011653d67e47768cf031e95f8f68cf714;p=libs%2Fgl.git diff --git a/source/glsl/resolve.cpp b/source/glsl/resolve.cpp index 8bfe635e..fec3cf14 100644 --- a/source/glsl/resolve.cpp +++ b/source/glsl/resolve.cpp @@ -226,28 +226,42 @@ void VariableResolver::visit(VariableReference &var) { const map &blocks = stage->interface_blocks; map::const_iterator i = blocks.find(var.name); + if(i==blocks.end()) + { + // Look for the variable in anonymous interface blocks. + for(i=blocks.begin(); i!=blocks.end(); ++i) + if(i->second->instance_name.empty() && i->second->struct_declaration) + if(i->second->struct_declaration->members.variables.count(var.name)) + break; + } + if(i!=blocks.end()) { - /* The name refers to an interface block with an instance name rather - than a variable. Prepare a new syntax tree node accordingly. */ + /* The name refers to either an interface block with an instance name + or a variable declared inside an anonymous interface block. Prepare + new syntax tree nodes accordingly. */ InterfaceBlockReference *iface_ref = new InterfaceBlockReference; iface_ref->source = var.source; iface_ref->line = var.line; - iface_ref->name = var.name; iface_ref->declaration = i->second; - r_replacement_expr = iface_ref; - } - else - { - // Look for the variable in anonymous interface blocks. - for(i=blocks.begin(); (!declaration && i!=blocks.end()); ++i) - if(i->second->instance_name.empty() && i->second->struct_declaration) - { - const map &iface_vars = i->second->struct_declaration->members.variables; - map::const_iterator j = iface_vars.find(var.name); - if(j!=iface_vars.end()) - declaration = j->second; - } + + if(i->second->instance_name.empty()) + { + iface_ref->name = format("%s %s", i->second->interface, i->second->block_name); + + MemberAccess *memacc = new MemberAccess; + memacc->source = var.source; + memacc->line = var.line; + memacc->left = iface_ref; + memacc->member = var.name; + + r_replacement_expr = memacc; + } + else + { + iface_ref->name = var.name; + r_replacement_expr = iface_ref; + } } } @@ -267,13 +281,6 @@ void VariableResolver::visit(InterfaceBlockReference &iface) check_assignment_target(iface.declaration); } -void VariableResolver::add_to_chain(Assignment::Target::ChainType type, unsigned index) -{ - if(r_assignment_target.chain_len<7) - r_assignment_target.chain[r_assignment_target.chain_len] = type | min(index, 0x3F); - ++r_assignment_target.chain_len; -} - void VariableResolver::visit(MemberAccess &memacc) { TraversingVisitor::visit(memacc); @@ -286,11 +293,12 @@ void VariableResolver::visit(MemberAccess &memacc) if(i!=strct->members.variables.end()) { declaration = i->second; + index = 0; for(NodeList::const_iterator j=strct->members.body.begin(); (j!=strct->members.body.end() && j->get()!=i->second); ++j) ++index; if(record_target) - add_to_chain(Assignment::Target::MEMBER, index); + add_to_chain(r_assignment_target, Assignment::Target::MEMBER, index); } } else if(BasicTypeDeclaration *basic = dynamic_cast(memacc.left->type)) @@ -335,7 +343,7 @@ void VariableResolver::visit(Swizzle &swizzle) unsigned mask = 0; for(unsigned i=0; i(binary.right.get())) if(literal_subscript->value.check_type()) index = literal_subscript->value.value(); - add_to_chain(Assignment::Target::ARRAY, index); + add_to_chain(r_assignment_target, Assignment::Target::ARRAY, index); } } else @@ -737,6 +745,17 @@ void ExpressionResolver::visit(BinaryExpression &binary, bool assign) if(!left_size || (left_size==1 && right_size!=1) || (left_size>1 && right_size!=1 && right_size!=left_size)) return; + /* If the left operand is a vector and right is scalar, convert the right + operand to a vector too. */ + if(left_size>1 && right_size==1) + { + BasicTypeDeclaration *vec_right = find_type(*elem_right, basic_left->kind, basic_left->size); + if(!vec_right) + return; + + convert_to(binary.right, *vec_right); + } + type = basic_left; // Don't perform conversion even if the operands are of different sizes. compat = SAME_TYPE; @@ -875,6 +894,8 @@ void ExpressionResolver::visit_constructor(FunctionCall &call) map::const_iterator i = stage->types.find(call.name); if(i==stage->types.end()) return; + else if(call.arguments.size()==1 && i->second==call.arguments[0]->type) + ; else if(BasicTypeDeclaration *basic = dynamic_cast(i->second)) { BasicTypeDeclaration *elem = get_element_type(*basic);