2 * Copyright © 2012-2021 VMware, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
31 class BinaryOperator
: public Operator
43 BinaryOperator(bOperator op
, Operator
* left
, Operator
* right
)
44 : Operator(Operator::BINARY
), mOperator(op
), mLeft(left
), mRight(right
)
57 virtual Value
execute(ShaderState
& state
) const
61 return mLeft
->execute(state
) + mRight
->execute(state
);
63 return mLeft
->execute(state
) - mRight
->execute(state
);
65 return mLeft
->execute(state
) * mRight
->execute(state
);
67 return mLeft
->execute(state
) / mRight
->execute(state
);
69 assert(mLeft
->operatorType() == Operator::CONSTANT
);
70 ((Constant
*)mLeft
)->setValue(state
, mRight
->execute(state
));
71 return mLeft
->execute(state
);
77 virtual std::string
toGLSL() const
79 std::string glsl
= mLeft
->toGLSL() + " " + toOperatorString() + " " + mRight
->toGLSL();
81 if (mOperator
!= MOV
&& (mLeft
->operatorType() == Operator::BINARY
|| mRight
->operatorType() == Operator::BINARY
))
82 return std::string("(") + glsl
+ ")";
92 Operator
* left() const
97 Operator
* right() const
103 std::string
toOperatorString() const
105 static const char* names
[] = {
113 return names
[mOperator
];