• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 The Tint 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/ast/interpolate_decoration.h"
16 
17 #include <string>
18 
19 #include "src/program_builder.h"
20 
21 TINT_INSTANTIATE_TYPEINFO(tint::ast::InterpolateDecoration);
22 
23 namespace tint {
24 namespace ast {
25 
InterpolateDecoration(ProgramID pid,const Source & src,InterpolationType ty,InterpolationSampling smpl)26 InterpolateDecoration::InterpolateDecoration(ProgramID pid,
27                                              const Source& src,
28                                              InterpolationType ty,
29                                              InterpolationSampling smpl)
30     : Base(pid, src), type(ty), sampling(smpl) {}
31 
32 InterpolateDecoration::~InterpolateDecoration() = default;
33 
Name() const34 std::string InterpolateDecoration::Name() const {
35   return "interpolate";
36 }
37 
Clone(CloneContext * ctx) const38 const InterpolateDecoration* InterpolateDecoration::Clone(
39     CloneContext* ctx) const {
40   // Clone arguments outside of create() call to have deterministic ordering
41   auto src = ctx->Clone(source);
42   return ctx->dst->create<InterpolateDecoration>(src, type, sampling);
43 }
44 
operator <<(std::ostream & out,InterpolationType type)45 std::ostream& operator<<(std::ostream& out, InterpolationType type) {
46   switch (type) {
47     case InterpolationType::kPerspective: {
48       out << "perspective";
49       break;
50     }
51     case InterpolationType::kLinear: {
52       out << "linear";
53       break;
54     }
55     case InterpolationType::kFlat: {
56       out << "flat";
57       break;
58     }
59   }
60   return out;
61 }
62 
operator <<(std::ostream & out,InterpolationSampling sampling)63 std::ostream& operator<<(std::ostream& out, InterpolationSampling sampling) {
64   switch (sampling) {
65     case InterpolationSampling::kNone: {
66       out << "none";
67       break;
68     }
69     case InterpolationSampling::kCenter: {
70       out << "center";
71       break;
72     }
73     case InterpolationSampling::kCentroid: {
74       out << "centroid";
75       break;
76     }
77     case InterpolationSampling::kSample: {
78       out << "sample";
79       break;
80     }
81   }
82   return out;
83 }
84 
85 }  // namespace ast
86 }  // namespace tint
87