OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SKSL_SWIZZLE | 8 #ifndef SKSL_SWIZZLE |
9 #define SKSL_SWIZZLE | 9 #define SKSL_SWIZZLE |
10 | 10 |
11 #include "SkSLExpression.h" | 11 #include "SkSLExpression.h" |
12 #include "SkSLUtil.h" | 12 #include "SkSLUtil.h" |
13 | 13 |
14 namespace SkSL { | 14 namespace SkSL { |
15 | 15 |
16 /** | 16 /** |
17 * Given a type and a swizzle component count, returns the type that will result
from swizzling. For | 17 * Given a type and a swizzle component count, returns the type that will result
from swizzling. For |
18 * instance, swizzling a vec3 with two components will result in a vec2. It is p
ossible to swizzle | 18 * instance, swizzling a vec3 with two components will result in a vec2. It is p
ossible to swizzle |
19 * with more components than the source vector, as in 'vec2(1).xxxx'. | 19 * with more components than the source vector, as in 'vec2(1).xxxx'. |
20 */ | 20 */ |
21 static const Type& get_type(Expression& value, size_t count) { | 21 static std::shared_ptr<Type> get_type(Expression& value, |
22 const Type& base = value.fType.componentType(); | 22 size_t count) { |
| 23 std::shared_ptr<Type> base = value.fType->componentType(); |
23 if (count == 1) { | 24 if (count == 1) { |
24 return base; | 25 return base; |
25 } | 26 } |
26 if (base == *kFloat_Type) { | 27 if (base == kFloat_Type) { |
27 switch (count) { | 28 switch (count) { |
28 case 2: return *kVec2_Type; | 29 case 2: return kVec2_Type; |
29 case 3: return *kVec3_Type; | 30 case 3: return kVec3_Type; |
30 case 4: return *kVec4_Type; | 31 case 4: return kVec4_Type; |
31 } | 32 } |
32 } else if (base == *kDouble_Type) { | 33 } else if (base == kDouble_Type) { |
33 switch (count) { | 34 switch (count) { |
34 case 2: return *kDVec2_Type; | 35 case 2: return kDVec2_Type; |
35 case 3: return *kDVec3_Type; | 36 case 3: return kDVec3_Type; |
36 case 4: return *kDVec4_Type; | 37 case 4: return kDVec4_Type; |
37 } | 38 } |
38 } else if (base == *kInt_Type) { | 39 } else if (base == kInt_Type) { |
39 switch (count) { | 40 switch (count) { |
40 case 2: return *kIVec2_Type; | 41 case 2: return kIVec2_Type; |
41 case 3: return *kIVec3_Type; | 42 case 3: return kIVec3_Type; |
42 case 4: return *kIVec4_Type; | 43 case 4: return kIVec4_Type; |
43 } | 44 } |
44 } else if (base == *kUInt_Type) { | 45 } else if (base == kUInt_Type) { |
45 switch (count) { | 46 switch (count) { |
46 case 2: return *kUVec2_Type; | 47 case 2: return kUVec2_Type; |
47 case 3: return *kUVec3_Type; | 48 case 3: return kUVec3_Type; |
48 case 4: return *kUVec4_Type; | 49 case 4: return kUVec4_Type; |
49 } | 50 } |
50 } else if (base == *kBool_Type) { | 51 } else if (base == kBool_Type) { |
51 switch (count) { | 52 switch (count) { |
52 case 2: return *kBVec2_Type; | 53 case 2: return kBVec2_Type; |
53 case 3: return *kBVec3_Type; | 54 case 3: return kBVec3_Type; |
54 case 4: return *kBVec4_Type; | 55 case 4: return kBVec4_Type; |
55 } | 56 } |
56 } | 57 } |
57 ABORT("cannot swizzle %s\n", value.description().c_str()); | 58 ABORT("cannot swizzle %s\n", value.description().c_str()); |
58 } | 59 } |
59 | 60 |
60 /** | 61 /** |
61 * Represents a vector swizzle operation such as 'vec2(1, 2, 3).zyx'. | 62 * Represents a vector swizzle operation such as 'vec2(1, 2, 3).zyx'. |
62 */ | 63 */ |
63 struct Swizzle : public Expression { | 64 struct Swizzle : public Expression { |
64 Swizzle(std::unique_ptr<Expression> base, std::vector<int> components) | 65 Swizzle(std::unique_ptr<Expression> base, std::vector<int> components) |
(...skipping 13 matching lines...) Expand all Loading... |
78 | 79 |
79 const std::unique_ptr<Expression> fBase; | 80 const std::unique_ptr<Expression> fBase; |
80 const std::vector<int> fComponents; | 81 const std::vector<int> fComponents; |
81 | 82 |
82 typedef Expression INHERITED; | 83 typedef Expression INHERITED; |
83 }; | 84 }; |
84 | 85 |
85 } // namespace | 86 } // namespace |
86 | 87 |
87 #endif | 88 #endif |
OLD | NEW |