• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2018 The Amber Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #include "src/command_data.h"
16 
17 namespace amber {
18 
NameToTopology(const std::string & name)19 Topology NameToTopology(const std::string& name) {
20   static const struct {
21     const char* name;
22     Topology val;
23   } topologies[] = {
24       {"PATCH_LIST", Topology::kPatchList},
25       {"POINT_LIST", Topology::kPointList},
26       {"GL_LINE_STRIP_ADJACENCY", Topology::kLineStripWithAdjacency},
27       {"GL_LINE_STRIP", Topology::kLineStrip},
28       {"GL_LINES", Topology::kLineList},
29       {"GL_LINES_ADJACENCY", Topology::kLineListWithAdjacency},
30       {"GL_PATCHES", Topology::kPatchList},
31       {"GL_POINTS", Topology::kPointList},
32       {"GL_TRIANGLE_STRIP", Topology::kTriangleStrip},
33       {"GL_TRIANGLE_FAN", Topology::kTriangleFan},
34       {"GL_TRIANGLES", Topology::kTriangleList},
35       {"GL_TRIANGLES_ADJACENCY", Topology::kTriangleListWithAdjacency},
36       {"GL_TRIANGLE_STRIP_ADJACENCY", Topology::kTriangleStripWithAdjacency},
37       {"LINE_LIST", Topology::kLineList},
38       {"LINE_LIST_WITH_ADJACENCY", Topology::kLineListWithAdjacency},
39       {"LINE_STRIP", Topology::kLineStrip},
40       {"LINE_STRIP_WITH_ADJACENCY", Topology::kLineStripWithAdjacency},
41       {"TRIANGLE_FAN", Topology::kTriangleFan},
42       {"TRIANGLE_LIST", Topology::kTriangleList},
43       {"TRIANGLE_LIST_WITH_ADJACENCY", Topology::kTriangleListWithAdjacency},
44       {"TRIANGLE_STRIP", Topology::kTriangleStrip},
45       {"TRIANGLE_STRIP_WITH_ADJACENCY", Topology::kTriangleStripWithAdjacency},
46   };
47 
48   // TODO(dsinclair): Make smarter if needed
49   for (auto& topo : topologies) {
50     if (topo.name == name)
51       return topo.val;
52   }
53 
54   return Topology::kUnknown;
55 }
56 
NameToBlendFactor(const std::string & name)57 BlendFactor NameToBlendFactor(const std::string& name) {
58   if (name == "zero")
59     return BlendFactor::kZero;
60   else if (name == "one")
61     return BlendFactor::kOne;
62   else if (name == "src_color")
63     return BlendFactor::kSrcColor;
64   else if (name == "one_minus_src_color")
65     return BlendFactor::kOneMinusSrcColor;
66   else if (name == "dst_color")
67     return BlendFactor::kDstColor;
68   else if (name == "one_minus_dst_color")
69     return BlendFactor::kOneMinusDstColor;
70   else if (name == "src_alpha")
71     return BlendFactor::kSrcAlpha;
72   else if (name == "one_minus_src_alpha")
73     return BlendFactor::kOneMinusSrcAlpha;
74   else if (name == "dst_alpha")
75     return BlendFactor::kDstAlpha;
76   else if (name == "one_minus_dst_alpha")
77     return BlendFactor::kOneMinusDstAlpha;
78   else if (name == "constant_color")
79     return BlendFactor::kConstantColor;
80   else if (name == "one_minus_constant_color")
81     return BlendFactor::kOneMinusConstantColor;
82   else if (name == "costant_alpha")
83     return BlendFactor::kConstantAlpha;
84   else if (name == "one_minus_constant_alpha")
85     return BlendFactor::kOneMinusConstantAlpha;
86   else if (name == "src_alpha_saturate")
87     return BlendFactor::kSrcAlphaSaturate;
88   else if (name == "src1_color")
89     return BlendFactor::kSrc1Color;
90   else if (name == "one_minus_src1_color")
91     return BlendFactor::kOneMinusSrc1Color;
92   else if (name == "src1_alpha")
93     return BlendFactor::kSrc1Alpha;
94   else if (name == "one_minus_src1_alpha")
95     return BlendFactor::kOneMinusSrc1Alpha;
96   else
97     return BlendFactor::kUnknown;
98 }
99 
NameToBlendOp(const std::string & name)100 BlendOp NameToBlendOp(const std::string& name) {
101   if (name == "add")
102     return BlendOp::kAdd;
103   else if (name == "substract")
104     return BlendOp::kSubtract;
105   else if (name == "reverse_substract")
106     return BlendOp::kReverseSubtract;
107   else if (name == "min")
108     return BlendOp::kMin;
109   else if (name == "max")
110     return BlendOp::kMax;
111   else if (name == "zero")
112     return BlendOp::kZero;
113   else if (name == "src")
114     return BlendOp::kSrc;
115   else if (name == "dst")
116     return BlendOp::kDst;
117   else if (name == "src_over")
118     return BlendOp::kSrcOver;
119   else if (name == "dst_over")
120     return BlendOp::kDstOver;
121   else if (name == "src_in")
122     return BlendOp::kSrcIn;
123   else if (name == "dst_in")
124     return BlendOp::kDstIn;
125   else if (name == "src_out")
126     return BlendOp::kSrcOut;
127   else if (name == "dst_out")
128     return BlendOp::kDstOut;
129   else if (name == "src_atop")
130     return BlendOp::kSrcAtop;
131   else if (name == "dst_atop")
132     return BlendOp::kDstAtop;
133   else if (name == "xor")
134     return BlendOp::kXor;
135   else if (name == "multiply")
136     return BlendOp::kMultiply;
137   else if (name == "screen")
138     return BlendOp::kScreen;
139   else if (name == "overlay")
140     return BlendOp::kOverlay;
141   else if (name == "darken")
142     return BlendOp::kDarken;
143   else if (name == "lighten")
144     return BlendOp::kLighten;
145   else if (name == "color_dodge")
146     return BlendOp::kColorDodge;
147   else if (name == "color_burn")
148     return BlendOp::kColorBurn;
149   else if (name == "hard_light")
150     return BlendOp::kHardLight;
151   else if (name == "soft_light")
152     return BlendOp::kSoftLight;
153   else if (name == "difference")
154     return BlendOp::kDifference;
155   else if (name == "exclusion")
156     return BlendOp::kExclusion;
157   else if (name == "invert")
158     return BlendOp::kInvert;
159   else if (name == "invert_rgb")
160     return BlendOp::kInvertRGB;
161   else if (name == "linear_dodge")
162     return BlendOp::kLinearDodge;
163   else if (name == "linear_burn")
164     return BlendOp::kLinearBurn;
165   else if (name == "vivid_light")
166     return BlendOp::kVividLight;
167   else if (name == "linear_light")
168     return BlendOp::kLinearLight;
169   else if (name == "pin_light")
170     return BlendOp::kPinLight;
171   else if (name == "hard_mix")
172     return BlendOp::kHardMix;
173   else if (name == "hsl_hue")
174     return BlendOp::kHslHue;
175   else if (name == "hsl_saturation")
176     return BlendOp::kHslSaturation;
177   else if (name == "hsl_color")
178     return BlendOp::kHslColor;
179   else if (name == "hsl_luminosity")
180     return BlendOp::kHslLuminosity;
181   else if (name == "plus")
182     return BlendOp::kPlus;
183   else if (name == "plus_clamped")
184     return BlendOp::kPlusClamped;
185   else if (name == "plus_clamped_alpha")
186     return BlendOp::kPlusClampedAlpha;
187   else if (name == "plus_darker")
188     return BlendOp::kPlusDarker;
189   else if (name == "minus")
190     return BlendOp::kMinus;
191   else if (name == "minus_clamped")
192     return BlendOp::kMinusClamped;
193   else if (name == "contrast")
194     return BlendOp::kContrast;
195   else if (name == "invert_ovg")
196     return BlendOp::kInvertOvg;
197   else if (name == "red")
198     return BlendOp::kRed;
199   else if (name == "green")
200     return BlendOp::kGreen;
201   else if (name == "blue")
202     return BlendOp::kBlue;
203   else
204     return BlendOp::kUnknown;
205 }
206 
207 }  // namespace amber
208