skia2/resources/sksl/dslfp/GrDSLFPTest_Ternary.fp
John Stiles b9fc6e45c2 Support 'layout(when)' expressions in DSL C++.
This required some changes to how we name variables in DSL.
When-expressions are designed to expect a local C++ variable with the
same name as the layout key. This constraint means our DSLVar variables
CANNOT have the same name as the layout key. Now, all DSL variables are
given a prefix. We try to keep the code tidy by using just a leading
underscore as the prefix, where it's safe to do so. (The C++ naming
rules put some underscore-names out of bounds, but underscore followed
by a lowercase letter is safe.)

Change-Id: Iaa8878042329b9909096f05712d5cf636ea01822
Bug: skia:11854
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/400623
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
2021-04-26 15:17:38 +00:00

16 lines
696 B
GLSL

layout(key) in bool primaryColors;
layout(ctype=SkPMColor4f, when=primaryColors) in uniform half4 colorGreen, colorRed;
layout(ctype=SkPMColor4f, when=!primaryColors) in uniform half4 colorOrange, colorPurple;
half4 main() {
half4 green = primaryColors ? colorGreen : colorOrange;
half4 red = primaryColors ? colorRed : colorPurple;
bool t = true;
bool f = false;
return half4(t ? green.r : red.r, // true -> green.r
f ? red.g : green.g, // false -> green.g
(green.g == red.r) ? green.b : red.r, // true -> green.b
(green.a != red.a) ? red.g : green.a); // false -> green.a
}