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_LAYOUT | 8 #ifndef SKSL_LAYOUT |
9 #define SKSL_LAYOUT | 9 #define SKSL_LAYOUT |
10 | 10 |
11 namespace SkSL { | 11 namespace SkSL { |
12 | 12 |
13 /** | 13 /** |
14 * Represents a layout block appearing before a variable declaration, as in: | 14 * Represents a layout block appearing before a variable declaration, as in: |
15 * | 15 * |
16 * layout (location = 0) int x; | 16 * layout (location = 0) int x; |
17 */ | 17 */ |
18 struct Layout { | 18 struct Layout { |
19 Layout(const ASTLayout& layout) | 19 Layout(const ASTLayout& layout) |
20 : fLocation(layout.fLocation) | 20 : fLocation(layout.fLocation) |
21 , fBinding(layout.fBinding) | 21 , fBinding(layout.fBinding) |
22 , fIndex(layout.fIndex) | 22 , fIndex(layout.fIndex) |
23 , fSet(layout.fSet) | 23 , fSet(layout.fSet) |
24 , fBuiltin(layout.fBuiltin) | 24 , fBuiltin(layout.fBuiltin) |
25 , fOriginUpperLeft(layout.fOriginUpperLeft) | 25 , fOriginUpperLeft(layout.fOriginUpperLeft) {} |
26 , fOverrideCoverage(layout.fOverrideCoverage) | |
27 , fBlendSupportAllEquations(layout.fBlendSupportAllEquations) {} | |
28 | 26 |
29 Layout(int location, int binding, int index, int set, int builtin, bool orig
inUpperLeft, | 27 Layout(int location, int binding, int index, int set, int builtin, bool orig
inUpperLeft) |
30 bool overrideCoverage, bool blendSupportAllEquations) | |
31 : fLocation(location) | 28 : fLocation(location) |
32 , fBinding(binding) | 29 , fBinding(binding) |
33 , fIndex(index) | 30 , fIndex(index) |
34 , fSet(set) | 31 , fSet(set) |
35 , fBuiltin(builtin) | 32 , fBuiltin(builtin) |
36 , fOriginUpperLeft(originUpperLeft) | 33 , fOriginUpperLeft(originUpperLeft) {} |
37 , fOverrideCoverage(overrideCoverage) | |
38 , fBlendSupportAllEquations(blendSupportAllEquations) {} | |
39 | 34 |
40 std::string description() const { | 35 std::string description() const { |
41 std::string result; | 36 std::string result; |
42 std::string separator; | 37 std::string separator; |
43 if (fLocation >= 0) { | 38 if (fLocation >= 0) { |
44 result += separator + "location = " + to_string(fLocation); | 39 result += separator + "location = " + to_string(fLocation); |
45 separator = ", "; | 40 separator = ", "; |
46 } | 41 } |
47 if (fBinding >= 0) { | 42 if (fBinding >= 0) { |
48 result += separator + "binding = " + to_string(fBinding); | 43 result += separator + "binding = " + to_string(fBinding); |
49 separator = ", "; | 44 separator = ", "; |
50 } | 45 } |
51 if (fIndex >= 0) { | 46 if (fIndex >= 0) { |
52 result += separator + "index = " + to_string(fIndex); | 47 result += separator + "index = " + to_string(fIndex); |
53 separator = ", "; | 48 separator = ", "; |
54 } | 49 } |
55 if (fSet >= 0) { | 50 if (fSet >= 0) { |
56 result += separator + "set = " + to_string(fSet); | 51 result += separator + "set = " + to_string(fSet); |
57 separator = ", "; | 52 separator = ", "; |
58 } | 53 } |
59 if (fBuiltin >= 0) { | 54 if (fBuiltin >= 0) { |
60 result += separator + "builtin = " + to_string(fBuiltin); | 55 result += separator + "builtin = " + to_string(fBuiltin); |
61 separator = ", "; | 56 separator = ", "; |
62 } | 57 } |
63 if (fOriginUpperLeft) { | 58 if (fOriginUpperLeft) { |
64 result += separator + "origin_upper_left"; | 59 result += separator + "origin_upper_left"; |
65 separator = ", "; | 60 separator = ", "; |
66 } | 61 } |
67 if (fOverrideCoverage) { | |
68 result += separator + "override_coverage"; | |
69 separator = ", "; | |
70 } | |
71 if (fBlendSupportAllEquations) { | |
72 result += separator + "blend_support_all_equations"; | |
73 separator = ", "; | |
74 } | |
75 if (result.length() > 0) { | 62 if (result.length() > 0) { |
76 result = "layout (" + result + ")"; | 63 result = "layout (" + result + ")"; |
77 } | 64 } |
78 return result; | 65 return result; |
79 } | 66 } |
80 | 67 |
81 bool operator==(const Layout& other) const { | 68 bool operator==(const Layout& other) const { |
82 return fLocation == other.fLocation && | 69 return fLocation == other.fLocation && |
83 fBinding == other.fBinding && | 70 fBinding == other.fBinding && |
84 fIndex == other.fIndex && | 71 fIndex == other.fIndex && |
85 fSet == other.fSet && | 72 fSet == other.fSet && |
86 fBuiltin == other.fBuiltin && | 73 fBuiltin == other.fBuiltin; |
87 fOriginUpperLeft == other.fOriginUpperLeft && | |
88 fOverrideCoverage == other.fOverrideCoverage && | |
89 fBlendSupportAllEquations == other.fBlendSupportAllEquations; | |
90 } | 74 } |
91 | 75 |
92 bool operator!=(const Layout& other) const { | 76 bool operator!=(const Layout& other) const { |
93 return !(*this == other); | 77 return !(*this == other); |
94 } | 78 } |
95 | 79 |
96 // everything but builtin is in the GLSL spec; builtin comes from SPIR-V and
identifies which | 80 // everything but builtin is in the GLSL spec; builtin comes from SPIR-V and
identifies which |
97 // particular builtin value this object represents. | 81 // particular builtin value this object represents. |
98 int fLocation; | 82 int fLocation; |
99 int fBinding; | 83 int fBinding; |
100 int fIndex; | 84 int fIndex; |
101 int fSet; | 85 int fSet; |
102 int fBuiltin; | 86 int fBuiltin; |
103 bool fOriginUpperLeft; | 87 bool fOriginUpperLeft; |
104 bool fOverrideCoverage; | |
105 bool fBlendSupportAllEquations; | |
106 }; | 88 }; |
107 | 89 |
108 } // namespace | 90 } // namespace |
109 | 91 |
110 #endif | 92 #endif |
OLD | NEW |