]> git.tdb.fi Git - libs/gl.git/blobdiff - source/glsl/generate.cpp
Additional rules for bit shift operators
[libs/gl.git] / source / glsl / generate.cpp
index f29d65f58bfeeaf4fe837fa2222226473c6d3c66..1e57ed649041cacdfaa58b56fa0a56dee5642dc9 100644 (file)
@@ -657,11 +657,17 @@ void ExpressionResolver::visit(BinaryExpression &binary, bool assign)
        }
        else if((oper=='<' || oper=='>') && oper2==oper)
        {
-               // Shifts only apply to integers.
-               if(basic_left->kind!=BasicTypeDeclaration::INT || basic_right->kind!=BasicTypeDeclaration::INT)
+               // Shifts apply to integer scalars and vectors, with some restrictions.
+               if(elem_left->kind!=BasicTypeDeclaration::INT || elem_right->kind!=BasicTypeDeclaration::INT)
+                       return;
+               unsigned left_size = (basic_left->kind==BasicTypeDeclaration::INT ? 1 : basic_left->kind==BasicTypeDeclaration::VECTOR ? basic_left->size : 0);
+               unsigned right_size = (basic_right->kind==BasicTypeDeclaration::INT ? 1 : basic_right->kind==BasicTypeDeclaration::VECTOR ? basic_right->size : 0);
+               if(!left_size || (left_size==1 && right_size!=1) || (left_size>1 && right_size!=1 && right_size!=left_size))
                        return;
 
                type = basic_left;
+               // Don't perform conversion even if the operands are of different sizes.
+               compat = SAME_TYPE;
        }
        else if(oper=='+' || oper=='-' || oper=='*' || oper=='/')
        {