]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/resolve.cpp
Convert operands of shift operators to the same vector size
[libs/gl.git] / source / glsl / resolve.cpp
index c5a507a222a96558a7582d72b8725216889d9fa7..fec3cf143130a583c38a961b38b70087309b555e 100644 (file)
@@ -281,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<unsigned>(index, 0x3F);
-       ++r_assignment_target.chain_len;
-}
-
 void VariableResolver::visit(MemberAccess &memacc)
 {
        TraversingVisitor::visit(memacc);
@@ -300,11 +293,12 @@ void VariableResolver::visit(MemberAccess &memacc)
                if(i!=strct->members.variables.end())
                {
                        declaration = i->second;
+                       index = 0;
                        for(NodeList<Statement>::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<BasicTypeDeclaration *>(memacc.left->type))
@@ -349,7 +343,7 @@ void VariableResolver::visit(Swizzle &swizzle)
                unsigned mask = 0;
                for(unsigned i=0; i<swizzle.count; ++i)
                        mask |= 1<<swizzle.components[i];
-               add_to_chain(Assignment::Target::SWIZZLE, mask);
+               add_to_chain(r_assignment_target, Assignment::Target::SWIZZLE, mask);
        }
 }
 
@@ -371,7 +365,7 @@ void VariableResolver::visit(BinaryExpression &binary)
                        if(Literal *literal_subscript = dynamic_cast<Literal *>(binary.right.get()))
                                if(literal_subscript->value.check_type<int>())
                                        index = literal_subscript->value.value<int>();
-                       add_to_chain(Assignment::Target::ARRAY, index);
+                       add_to_chain(r_assignment_target, Assignment::Target::ARRAY, index);
                }
        }
        else
@@ -751,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;
@@ -889,6 +894,8 @@ void ExpressionResolver::visit_constructor(FunctionCall &call)
        map<string, TypeDeclaration *>::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<BasicTypeDeclaration *>(i->second))
        {
                BasicTypeDeclaration *elem = get_element_type(*basic);